artdaq  v3_04_01
PortManager.hh
1 #ifndef ARTDAQ_DAQDATA_PORTMANAGER_HH
2 #define ARTDAQ_DAQDATA_PORTMANAGER_HH
3 
4 #include <string>
5 #include <fhiclcpp/fwd.h>
6 #include "fhiclcpp/types/Atom.h"
7 #include "fhiclcpp/types/ConfigurationTable.h"
8 #include <netinet/in.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 {
24  class PortManager {
25  public:
29  struct Config
30  {
32  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 };
34  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 };
36  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"},"" };
38  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" };
40  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 };
42  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 };
44  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 };
46  fhicl::Atom<int> xmlrpc_port_offset{ fhicl::Name{ "xmlrpc_port_offset" }, fhicl::Comment{"Offset from partition base port for XMLRPC ports"},DEFAULT_XMLRPC_OFFSET };
48  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 };
50  fhicl::Atom<int> request_port{ fhicl::Name{ "request_port" }, fhicl::Comment{"Port to use for request messages (multicast)"},DEFAULT_REQUEST_PORT };
52  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" };
54  fhicl::Atom<int> routing_table_port{ fhicl::Name{ "routing_table_port" }, fhicl::Comment{"Port to use for routing tables (multicast)"},DEFAULT_ROUTING_TABLE_PORT };
56  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" };
58  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 };
60  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" };
61 
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 
152  private:
153  bool base_configured_;
154  bool multicasts_configured_;
155 
156  bool routing_tokens_configured_;
157  bool routing_acks_configured_;
158  bool xmlrpc_configured_;
159  bool tcpsocket_configured_;
160  bool request_port_configured_;
161  bool request_pattern_configured_;
162  bool routing_table_port_configured_;
163  bool routing_table_pattern_configured_;
164  bool multicast_transfer_port_configued_;
165  bool multicast_transfer_pattern_configured_;
166 
167  int base_port_;
168  int ports_per_partition_;
169 
170  in_addr multicast_interface_address_;
171  int multicast_group_offset_;
172 
173  int routing_token_offset_;
174  int routing_ack_offset_;
175  int xmlrpc_offset_;
176  int tcp_socket_offset_;
177  int request_message_port_;
178  int routing_table_port_;
179  int multicast_transfer_offset_;
180  std::string request_message_group_pattern_;
181  std::string routing_table_group_pattern_;
182  std::string multicast_transfer_group_pattern_;
183 
184 
185  std::string parse_pattern_(std::string pattern, int subsystemID = 0, int rank = 0);
186  };
187 }
188 
189 #endif //ARTDAQ_DAQDATA_PORTMANAGER_HH
int GetRequestMessagePort()
Get the port that should be used for multicast request messages.
Definition: PortManager.cc:309
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:56
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:40
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:38
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:36
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:52
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:44
fhicl::Atom< int > request_port
&quot;request_port&quot; (Default: 3001): Port to use for request messages (multicast)
Definition: PortManager.hh:50
int GetMulticastTransferPort(int rank)
Get the multicast transfer port for the given rank.
Definition: PortManager.cc:353
int GetRoutingAckPort(int subsystemID=0)
Get the port that should be used for Routing Acknowledgements.
Definition: PortManager.cc:279
std::string GetRequestMessageGroupAddress(int subsystemID=0)
Get the multicast address for request messages.
Definition: PortManager.cc:320
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:58
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:54
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:268
in_addr GetMulticastOutputAddress(std::string interface_name="", std::string interface_address="")
Determine the output interface address, using the hints provided.
Definition: PortManager.cc:375
Configuration of PortManager. May be used for parameter validation
Definition: PortManager.hh:29
std::string GetMulticastTransferGroupAddress()
Get the multicast address for multicast transfers.
Definition: PortManager.cc:364
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:34
int GetXMLRPCPort(int rank)
Get the XMLRPC port for the given rank.
Definition: PortManager.cc:289
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:60
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:32
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:46
int GetRoutingTablePort()
Get the port that should be used for multicast Routing Tables.
Definition: PortManager.cc:331
int GetTCPSocketTransferPort(int rank)
Get the TCP Socket transfer port for the given rank.
Definition: PortManager.cc:299
std::string GetRoutingTableGroupAddress(int subsystemID=0)
Get the multicast address for Routing Tables.
Definition: PortManager.cc:342
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:48
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:42