00001 #ifndef ARTDAQ_DAQDATA_PORTMANAGER_HH 00002 #define ARTDAQ_DAQDATA_PORTMANAGER_HH 00003 00004 #include <string> 00005 #include <fhiclcpp/fwd.h> 00006 #include "fhiclcpp/types/Atom.h" 00007 #include "fhiclcpp/types/ConfigurationTable.h" 00008 #include <netinet/in.h> 00009 00010 #define DEFAULT_BASE 10000 00011 #define DEFAULT_PORTS_PER_PARTITION 1000 00012 #define DEFAULT_ROUTING_TOKEN_OFFSET 10 00013 #define DEFAULT_ROUTING_TABLE_ACK_OFFSET 30 00014 #define DEFAULT_XMLRPC_OFFSET 100 00015 #define DEFAULT_TCPSOCKET_OFFSET 500 00016 #define DEFAULT_REQUEST_PORT 3001 00017 #define DEFAULT_ROUTING_TABLE_PORT 3001 00018 #define DEFAULT_MULTICAST_GROUP_OFFSET 128 00019 00020 namespace artdaq { 00021 class PortManager { 00022 public: 00026 struct Config 00027 { 00029 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 }; 00031 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 }; 00033 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"},"" }; 00035 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" }; 00037 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 }; 00039 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 }; 00041 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 }; 00043 fhicl::Atom<int> xmlrpc_port_offset{ fhicl::Name{ "xmlrpc_port_offset" }, fhicl::Comment{"Offset from partition base port for XMLRPC ports"},DEFAULT_XMLRPC_OFFSET }; 00045 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 }; 00047 fhicl::Atom<int> request_port{ fhicl::Name{ "request_port" }, fhicl::Comment{"Port to use for request messages (multicast)"},DEFAULT_REQUEST_PORT }; 00049 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" }; 00051 fhicl::Atom<int> routing_table_port{ fhicl::Name{ "routing_table_port" }, fhicl::Comment{"Port to use for routing tables (multicast)"},DEFAULT_ROUTING_TABLE_PORT }; 00053 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" }; 00055 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 }; 00057 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" }; 00058 00059 }; 00060 using Parameters = fhicl::WrappedTable<Config>; 00061 00062 PortManager(); 00063 void UpdateConfiguration(fhicl::ParameterSet const& ps); 00064 00065 int GetRoutingTokenPort(int subsystemID = 0); 00066 int GetRoutingAckPort(int subsystemID = 0); 00067 int GetXMLRPCPort(int rank); 00068 int GetTCPSocketTransferPort(int rank); 00069 int GetRequestMessagePort(); 00070 std::string GetRequestMessageGroupAddress(int subsystemID = 0); 00071 int GetRoutingTablePort(); 00072 std::string GetRoutingTableGroupAddress(int subsystemID = 0); 00073 int GetMulticastTransferPort(int rank); 00074 std::string GetMulticastTransferGroupAddress(); 00075 00076 in_addr GetMulticastOutputAddress(std::string interface_name = "", std::string interface_address = ""); 00077 00078 00079 private: 00080 bool base_configured_; 00081 bool multicasts_configured_; 00082 00083 bool routing_tokens_configured_; 00084 bool routing_acks_configured_; 00085 bool xmlrpc_configured_; 00086 bool tcpsocket_configured_; 00087 bool request_port_configured_; 00088 bool request_pattern_configured_; 00089 bool routing_table_port_configured_; 00090 bool routing_table_pattern_configured_; 00091 bool multicast_transfer_port_configued_; 00092 bool multicast_transfer_pattern_configured_; 00093 00094 int base_port_; 00095 int ports_per_partition_; 00096 00097 in_addr multicast_interface_address_; 00098 int multicast_group_offset_; 00099 00100 int routing_token_offset_; 00101 int routing_ack_offset_; 00102 int xmlrpc_offset_; 00103 int tcp_socket_offset_; 00104 int request_message_port_; 00105 int routing_table_port_; 00106 int multicast_transfer_offset_; 00107 std::string request_message_group_pattern_; 00108 std::string routing_table_group_pattern_; 00109 std::string multicast_transfer_group_pattern_; 00110 00111 00112 std::string parse_pattern_(std::string pattern, int subsystemID = 0, int rank = 0); 00113 }; 00114 } 00115 00116 #endif //ARTDAQ_DAQDATA_PORTMANAGER_HH