artdaq  v3_07_01
PortManager.hh
1 #ifndef ARTDAQ_DAQDATA_PORTMANAGER_HH
2 #define ARTDAQ_DAQDATA_PORTMANAGER_HH
3 
4 #include <fhiclcpp/fwd.h>
5 #include <netinet/in.h>
6 #include <string>
7 #include "fhiclcpp/types/Atom.h"
8 #include "fhiclcpp/types/ConfigurationTable.h"
9 
10 #define DEFAULT_BASE 10000
11 #define DEFAULT_PORTS_PER_PARTITION 1000
12 #define DEFAULT_ROUTING_TOKEN_OFFSET 10
13 #define DEFAULT_ROUTING_TABLE_ACK_OFFSET 30
14 #define DEFAULT_XMLRPC_OFFSET 100
15 #define DEFAULT_TCPSOCKET_OFFSET 500
16 #define DEFAULT_REQUEST_PORT 3001
17 #define DEFAULT_ROUTING_TABLE_PORT 3001
18 #define DEFAULT_MULTICAST_GROUP_OFFSET 128
19 
20 namespace artdaq {
25 {
26 public:
30  struct Config
31  {
33  fhicl::Atom<int> artdaq_base_port{fhicl::Name{"artdaq_base_port"}, fhicl::Comment{"Base port for all artdaq partitions. Should be the same across all running systems. Overridden by environment variable ARTDAQ_BASE_PORT."}, DEFAULT_BASE};
35  fhicl::Atom<int> ports_per_partition{fhicl::Name{"ports_per_partition"}, fhicl::Comment{"Number of ports to reserve for each partition. Should be the same across all running systems. Overridden by environment variable ARTDAQ_PORTS_PER_PARTITION."}, DEFAULT_PORTS_PER_PARTITION};
37  fhicl::Atom<std::string> multicast_output_interface{fhicl::Name{"multicast_output_interface"}, fhicl::Comment{"Name of the interface to be used for all multicasts. Has precedence over \"multicast_output_network\". OPTIONAL"}, ""};
39  fhicl::Atom<std::string> multicast_output_network{fhicl::Name{"multicast_output_network"}, fhicl::Comment{"Address in network to be used for all multicasts. OPTIONAL"}, "0.0.0.0"};
41  fhicl::Atom<int> multicast_group_offset{fhicl::Name{"multicast_group_offset"}, fhicl::Comment{"Number to add to last byte of multicast groups, to avoid problematic 0s."}, DEFAULT_MULTICAST_GROUP_OFFSET};
43  fhicl::Atom<int> routing_token_port_offset{fhicl::Name{"routing_token_port_offset"}, fhicl::Comment{"Offset from partition base port for routing token ports"}, DEFAULT_ROUTING_TOKEN_OFFSET};
45  fhicl::Atom<int> routing_table_ack_port_offset{fhicl::Name{"routing_table_ack_port_offset"}, fhicl::Comment{"Offset from partition base port for routing table ack ports"}, DEFAULT_ROUTING_TABLE_ACK_OFFSET};
47  fhicl::Atom<int> xmlrpc_port_offset{fhicl::Name{"xmlrpc_port_offset"}, fhicl::Comment{"Offset from partition base port for XMLRPC ports"}, DEFAULT_XMLRPC_OFFSET};
49  fhicl::Atom<int> tcp_socket_port_offset{fhicl::Name{"tcp_socket_port_offset"}, fhicl::Comment{"Offset from partition base port for TCP Socket ports"}, DEFAULT_TCPSOCKET_OFFSET};
51  fhicl::Atom<int> request_port{fhicl::Name{"request_port"}, fhicl::Comment{"Port to use for request messages (multicast)"}, DEFAULT_REQUEST_PORT};
53  fhicl::Atom<std::string> request_pattern{fhicl::Name{"request_pattern"}, fhicl::Comment{"Pattern to use to generate request multicast group. PPP => Partition number, SSS => Subsystem ID (default 0)"}, "227.128.PPP.SSS"};
55  fhicl::Atom<int> routing_table_port{fhicl::Name{"routing_table_port"}, fhicl::Comment{"Port to use for routing tables (multicast)"}, DEFAULT_ROUTING_TABLE_PORT};
57  fhicl::Atom<std::string> routing_table_pattern{fhicl::Name{"routing_table_pattern"}, fhicl::Comment{"Pattern to use to generate routing table multicast group. PPP => Partition number, SSS => Subsystem ID (default 0)."}, "227.129.PPP.SSS"};
59  fhicl::Atom<int> multicast_transfer_port_offset{fhicl::Name{"multicast_transfer_port_offset"}, fhicl::Comment{"Offset to use for MulticastTransfer ports (port = offset + rank)"}, 1024};
61  fhicl::Atom<std::string> multicast_transfer_pattern{fhicl::Name{"multicast_transfer_pattern"}, fhicl::Comment{"Pattern to use to generate Multicast Transfer group address. PPP => Partition Number, SSS => Subsystem ID (default 0), RRR => Rank"}, "227.130.14.PPP"};
62  };
64  using Parameters = fhicl::WrappedTable<Config>;
65 
66  PortManager();
67 
72  void UpdateConfiguration(fhicl::ParameterSet const& ps);
73 
79  int GetRoutingTokenPort(int subsystemID = 0);
80 
86  int GetRoutingAckPort(int subsystemID = 0);
87 
93  int GetXMLRPCPort(int rank);
94 
100  int GetTCPSocketTransferPort(int rank);
101 
106  int GetRequestMessagePort();
107 
113  std::string GetRequestMessageGroupAddress(int subsystemID = 0);
114 
119  int GetRoutingTablePort();
120 
126  std::string GetRoutingTableGroupAddress(int subsystemID = 0);
127 
133  int GetMulticastTransferPort(int rank);
134 
139  std::string GetMulticastTransferGroupAddress();
140 
149  in_addr GetMulticastOutputAddress(std::string interface_name = "", std::string interface_address = "");
150 
151 private:
152  bool base_configured_;
153  bool multicasts_configured_;
154 
155  bool routing_tokens_configured_;
156  bool routing_acks_configured_;
157  bool xmlrpc_configured_;
158  bool tcpsocket_configured_;
159  bool request_port_configured_;
160  bool request_pattern_configured_;
161  bool routing_table_port_configured_;
162  bool routing_table_pattern_configured_;
163  bool multicast_transfer_port_configued_;
164  bool multicast_transfer_pattern_configured_;
165 
166  int base_port_;
167  int ports_per_partition_;
168 
169  in_addr multicast_interface_address_;
170  int multicast_group_offset_;
171 
172  int routing_token_offset_;
173  int routing_ack_offset_;
174  int xmlrpc_offset_;
175  int tcp_socket_offset_;
176  int request_message_port_;
177  int routing_table_port_;
178  int multicast_transfer_offset_;
179  std::string request_message_group_pattern_;
180  std::string routing_table_group_pattern_;
181  std::string multicast_transfer_group_pattern_;
182 
183  std::string parse_pattern_(std::string pattern, int subsystemID = 0, int rank = 0);
184 };
185 } // namespace artdaq
186 
187 #endif //ARTDAQ_DAQDATA_PORTMANAGER_HH
int GetRequestMessagePort()
Get the port that should be used for multicast request messages.
Definition: PortManager.cc:306
fhicl::Atom< std::string > routing_table_pattern
&quot;routing_table_pattern&quot; (Default: &quot;227.129.PPP.SSS&quot;): Pattern to use to generate routing table multic...
Definition: PortManager.hh:57
fhicl::Atom< int > multicast_group_offset
&quot;multicast_group_offset&quot; (Default: 128): Number to add to last byte of multicast groups, to avoid problematic 0s.
Definition: PortManager.hh:41
fhicl::Atom< std::string > multicast_output_network
&quot;multicast_output_network&quot; (Default: &quot;0.0.0.0&quot;): Address in network to be used for all multicasts...
Definition: PortManager.hh:39
fhicl::Atom< std::string > multicast_output_interface
&quot;multicast_output_interface&quot; (Default: &quot;&quot;): Name of the interface to be used for all multicasts...
Definition: PortManager.hh:37
fhicl::Atom< std::string > request_pattern
&quot;request_pattern&quot; (Default: &quot;227.128.PPP.SSS&quot;): Pattern to use to generate request multicast group...
Definition: PortManager.hh:53
fhicl::Atom< int > routing_table_ack_port_offset
&quot;routing_table_ack_port_offset&quot; (Default: 30): Offset from partition base port for routing table ack ...
Definition: PortManager.hh:45
fhicl::Atom< int > request_port
&quot;request_port&quot; (Default: 3001): Port to use for request messages (multicast)
Definition: PortManager.hh:51
int GetMulticastTransferPort(int rank)
Get the multicast transfer port for the given rank.
Definition: PortManager.cc:349
int GetRoutingAckPort(int subsystemID=0)
Get the port that should be used for Routing Acknowledgements.
Definition: PortManager.cc:276
std::string GetRequestMessageGroupAddress(int subsystemID=0)
Get the multicast address for request messages.
Definition: PortManager.cc:316
fhicl::Atom< int > multicast_transfer_port_offset
&quot;multicast_transfer_port_offset&quot; (Default: 1024): Offset to use for MulticastTransfer ports (port = o...
Definition: PortManager.hh:59
PortManager attempts to automatically detect interfaces and ports used for the various TCP and UDP so...
Definition: PortManager.hh:24
fhicl::WrappedTable< Config > Parameters
Used for ParameterSet validation (if desired)
Definition: PortManager.hh:64
fhicl::Atom< int > routing_table_port
&quot;routing_table_port&quot; (Default: 3001): Port to use for routing tables (multicast)
Definition: PortManager.hh:55
PortManager()
PortManager Construator.
Definition: PortManager.cc:7
int GetRoutingTokenPort(int subsystemID=0)
Get the port that should be used for Routing Tokens.
Definition: PortManager.cc:265
in_addr GetMulticastOutputAddress(std::string interface_name="", std::string interface_address="")
Determine the output interface address, using the hints provided.
Definition: PortManager.cc:371
Configuration of PortManager. May be used for parameter validation
Definition: PortManager.hh:30
std::string GetMulticastTransferGroupAddress()
Get the multicast address for multicast transfers.
Definition: PortManager.cc:360
fhicl::Atom< int > ports_per_partition
&quot;ports_per_partition&quot; (Default: 1000): Number of ports to reserve for each partition. Should be the same across all running systems. Overridden by environment variable ARTDAQ_PORTS_PER_PARTITION.
Definition: PortManager.hh:35
int GetXMLRPCPort(int rank)
Get the XMLRPC port for the given rank.
Definition: PortManager.cc:286
fhicl::Atom< std::string > multicast_transfer_pattern
&quot;multicast_transfer_pattern&quot; (Default: &quot;227.130.14.PPP&quot;): Pattern to use to generate Multicast Transf...
Definition: PortManager.hh:61
fhicl::Atom< int > artdaq_base_port
&quot;artdaq_base_port&quot; (Default: 10000): Base port for all artdaq partitions. Should be the same across a...
Definition: PortManager.hh:33
void UpdateConfiguration(fhicl::ParameterSet const &ps)
Override the default configuration.
Definition: PortManager.cc:37
fhicl::Atom< int > xmlrpc_port_offset
&quot;xmlrpc_port_offset&quot; (Default: 100): Offset from partition base port for XMLRPC ports ...
Definition: PortManager.hh:47
int GetRoutingTablePort()
Get the port that should be used for multicast Routing Tables.
Definition: PortManager.cc:327
int GetTCPSocketTransferPort(int rank)
Get the TCP Socket transfer port for the given rank.
Definition: PortManager.cc:296
std::string GetRoutingTableGroupAddress(int subsystemID=0)
Get the multicast address for Routing Tables.
Definition: PortManager.cc:338
fhicl::Atom< int > tcp_socket_port_offset
&quot;tcp_socket_port_offset&quot; (Default: 500): Offset from partition base port for TCP Socket ports ...
Definition: PortManager.hh:49
fhicl::Atom< int > routing_token_port_offset
&quot;routing_token_port_offset&quot; (Default: 10): Offset from partition base port for routing token ports ...
Definition: PortManager.hh:43