artdaq  v3_03_00
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 {
21  class PortManager {
22  public:
26  struct Config
27  {
29  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 };
31  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 };
33  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"},"" };
35  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" };
37  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 };
39  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 };
41  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 };
43  fhicl::Atom<int> xmlrpc_port_offset{ fhicl::Name{ "xmlrpc_port_offset" }, fhicl::Comment{"Offset from partition base port for XMLRPC ports"},DEFAULT_XMLRPC_OFFSET };
45  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 };
47  fhicl::Atom<int> request_port{ fhicl::Name{ "request_port" }, fhicl::Comment{"Port to use for request messages (multicast)"},DEFAULT_REQUEST_PORT };
49  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" };
51  fhicl::Atom<int> routing_table_port{ fhicl::Name{ "routing_table_port" }, fhicl::Comment{"Port to use for routing tables (multicast)"},DEFAULT_ROUTING_TABLE_PORT };
53  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" };
55  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 };
57  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" };
58 
59  };
60  using Parameters = fhicl::WrappedTable<Config>;
61 
62  PortManager();
63  void UpdateConfiguration(fhicl::ParameterSet const& ps);
64 
65  int GetRoutingTokenPort(int subsystemID = 0);
66  int GetRoutingAckPort(int subsystemID = 0);
67  int GetXMLRPCPort(int rank);
68  int GetTCPSocketTransferPort(int rank);
69  int GetRequestMessagePort();
70  std::string GetRequestMessageGroupAddress(int subsystemID = 0);
71  int GetRoutingTablePort();
72  std::string GetRoutingTableGroupAddress(int subsystemID = 0);
73  int GetMulticastTransferPort(int rank);
74  std::string GetMulticastTransferGroupAddress();
75 
76  in_addr GetMulticastOutputAddress(std::string interface_name = "", std::string interface_address = "");
77 
78 
79  private:
80  bool base_configured_;
81  bool multicasts_configured_;
82 
83  bool routing_tokens_configured_;
84  bool routing_acks_configured_;
85  bool xmlrpc_configured_;
86  bool tcpsocket_configured_;
87  bool request_port_configured_;
88  bool request_pattern_configured_;
89  bool routing_table_port_configured_;
90  bool routing_table_pattern_configured_;
91  bool multicast_transfer_port_configued_;
92  bool multicast_transfer_pattern_configured_;
93 
94  int base_port_;
95  int ports_per_partition_;
96 
97  in_addr multicast_interface_address_;
98  int multicast_group_offset_;
99 
100  int routing_token_offset_;
101  int routing_ack_offset_;
102  int xmlrpc_offset_;
103  int tcp_socket_offset_;
104  int request_message_port_;
105  int routing_table_port_;
106  int multicast_transfer_offset_;
107  std::string request_message_group_pattern_;
108  std::string routing_table_group_pattern_;
109  std::string multicast_transfer_group_pattern_;
110 
111 
112  std::string parse_pattern_(std::string pattern, int subsystemID = 0, int rank = 0);
113  };
114 }
115 
116 #endif //ARTDAQ_DAQDATA_PORTMANAGER_HH
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:53
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:37
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:35
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:33
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:49
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:41
fhicl::Atom< int > request_port
&quot;request_port&quot; (Default: 3001): Port to use for request messages (multicast)
Definition: PortManager.hh:47
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:55
fhicl::Atom< int > routing_table_port
&quot;routing_table_port&quot; (Default: 3001): Port to use for routing tables (multicast)
Definition: PortManager.hh:51
Configuration of PortManager. May be used for parameter validation
Definition: PortManager.hh:26
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:31
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:57
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:29
fhicl::Atom< int > xmlrpc_port_offset
&quot;xmlrpc_port_offset&quot; (Default: 100): Offset from partition base port for XMLRPC ports ...
Definition: PortManager.hh:43
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:45
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:39