helics  3.0.1
NetworkBrokerData.hpp
1 /*
2 Copyright (c) 2017-2021,
3 Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
4 Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
5 SPDX-License-Identifier: BSD-3-Clause
6 */
7 #pragma once
8 
9 #include <memory>
10 #include <string>
11 #include <utility>
12 #include <vector>
13 
14 namespace helics {
16 enum class InterfaceNetworks : char {
17  LOCAL = 0,
18  IPV4 = 4,
19  IPV6 = 6,
20  ALL = 10,
21 };
22 
24 enum class InterfaceTypes : char {
25  TCP = 0,
26  UDP = 1,
27  IP = 2,
28  IPC = 3,
29  INPROC = 4,
30 };
31 
32 class helicsCLI11App;
33 
37  public:
38  enum class ServerModeOptions : char {
39  UNSPECIFIED = 0,
40  SERVER_DEFAULT_ACTIVE = 1,
41  SERVER_DEFAULT_DEACTIVATED = 2,
42  SERVER_ACTIVE = 3,
43  SERVER_DEACTIVATED = 4,
44  };
45 
46  std::string brokerName;
47  std::string brokerAddress;
48  std::string localInterface;
49  std::string brokerInitString;
50  std::string connectionAddress;
51  int portNumber{-1};
52  int brokerPort{-1};
53  int connectionPort{-1};
54 
55  int portStart{-1};
56  int maxMessageSize{16 * 256};
57  int maxMessageCount{256};
58  int maxRetries{5};
60  bool reuse_address{false};
61  bool use_os_port{false};
62  bool autobroker{false};
65  false};
66  bool noAckConnection{false};
67  bool useJsonSerialization{false};
69  bool observer{false};
70  ServerModeOptions server_mode{ServerModeOptions::UNSPECIFIED};
71  public:
72  NetworkBrokerData() = default;
74  explicit NetworkBrokerData(InterfaceTypes type): allowedType(type) {}
75 
79  std::shared_ptr<helicsCLI11App> commandLineParser(const std::string& localAddress,
80  bool enableConfig = true);
83  void setInterfaceType(InterfaceTypes type) { allowedType = type; }
84 
85  private:
87  void checkAndUpdateBrokerAddress(const std::string& localAddress);
88  InterfaceTypes allowedType = InterfaceTypes::IP;
89 };
90 
98 std::string makePortAddress(const std::string& networkInterface, int portNumber);
99 
107 std::pair<std::string, int> extractInterfaceandPort(const std::string& address);
108 
116 std::pair<std::string, std::string> extractInterfaceandPortString(const std::string& address);
117 
120 std::string stripProtocol(const std::string& networkAddress);
122 void removeProtocol(std::string& networkAddress);
123 
125 std::string addProtocol(const std::string& networkAddress, InterfaceTypes interfaceT);
126 
128 void insertProtocol(std::string& networkAddress, InterfaceTypes interfaceT);
129 
133 bool isipv6(const std::string& address);
134 
142 std::vector<std::string> prioritizeExternalAddresses(std::vector<std::string> high,
143  std::vector<std::string> low);
144 
147 std::string getLocalExternalAddressV4();
148 
151 std::string getLocalExternalAddress(const std::string& server);
152 
155 std::string getLocalExternalAddressV4(const std::string& server);
156 
159 std::string getLocalExternalAddressV6();
160 
163 std::string getLocalExternalAddressV6(const std::string& server);
164 
167 std::string generateMatchingInterfaceAddress(const std::string& server,
169 } // namespace helics
helics::InterfaceNetworks
InterfaceNetworks
Definition: NetworkBrokerData.hpp:16
helics::InterfaceNetworks::ALL
@ ALL
use all external ports
helics::InterfaceNetworks::IPV6
@ IPV6
use external ipv6 ports
helics::removeProtocol
void removeProtocol(std::string &networkAddress)
Definition: NetworkBrokerData.cpp:266
helics::extractInterfaceandPortString
std::pair< std::string, std::string > extractInterfaceandPortString(const std::string &address)
Definition: NetworkBrokerData.cpp:251
helics::NetworkBrokerData::connectionPort
int connectionPort
the port number for connecting
Definition: NetworkBrokerData.hpp:53
helics::NetworkBrokerData::use_os_port
bool use_os_port
Definition: NetworkBrokerData.hpp:61
AsioContextManager::getContextPointer
static std::shared_ptr< AsioContextManager > getContextPointer(const std::string &contextName=std::string())
Definition: AsioContextManager.cpp:38
helics::NetworkBrokerData::maxMessageSize
int maxMessageSize
maximum message size
Definition: NetworkBrokerData.hpp:56
helics::getLocalExternalAddress
std::string getLocalExternalAddress(const std::string &server)
Definition: NetworkBrokerData.cpp:575
helics::extractInterfaceandPort
std::pair< std::string, int > extractInterfaceandPort(const std::string &address)
Definition: NetworkBrokerData.cpp:227
helics::BrokerFactory::findBroker
std::shared_ptr< Broker > findBroker(const std::string &brokerName)
Definition: BrokerFactory.cpp:182
helics::NetworkBrokerData::localInterface
std::string localInterface
the interface to use for the local connection
Definition: NetworkBrokerData.hpp:48
helics::prioritizeExternalAddresses
std::vector< std::string > prioritizeExternalAddresses(std::vector< std::string > high, std::vector< std::string > low)
Definition: NetworkBrokerData.cpp:330
helics::NetworkBrokerData::maxMessageCount
int maxMessageCount
maximum message count
Definition: NetworkBrokerData.hpp:57
helics::NetworkBrokerData::appendNameToAddress
bool appendNameToAddress
flag indicating that the name should be appended to the address
Definition: NetworkBrokerData.hpp:64
helics::InterfaceTypes::UDP
@ UDP
using udp ports for communication
helics::NetworkBrokerData::autobroker
bool autobroker
flag for specifying an automatic broker generation
Definition: NetworkBrokerData.hpp:63
helics::NetworkBrokerData
Definition: NetworkBrokerData.hpp:36
helics::InterfaceTypes::IP
@ IP
using both types of ports (tcp/or udp) for communication
helics::NetworkBrokerData::observer
bool observer
specify that the network connection is used for observation only
Definition: NetworkBrokerData.hpp:69
helics::NetworkBrokerData::brokerPort
int brokerPort
the port number to use for the main broker interface
Definition: NetworkBrokerData.hpp:52
helics::InterfaceTypes::TCP
@ TCP
using tcp ports for communication
helics::addProtocol
std::string addProtocol(const std::string &networkAddress, InterfaceTypes interfaceT)
Definition: NetworkBrokerData.cpp:274
helics::generateMatchingInterfaceAddress
std::string generateMatchingInterfaceAddress(const std::string &server, InterfaceNetworks network)
Definition: NetworkBrokerData.cpp:583
helics::NetworkBrokerData::brokerInitString
std::string brokerInitString
a string containing arguments for the broker initialization
Definition: NetworkBrokerData.hpp:49
helics::InterfaceNetworks::IPV4
@ IPV4
use external ipv4 ports
helics::NetworkBrokerData::brokerAddress
std::string brokerAddress
the address or domain name of the broker
Definition: NetworkBrokerData.hpp:47
helics::NetworkBrokerData::noAckConnection
bool noAckConnection
Definition: NetworkBrokerData.hpp:66
helics::NetworkBrokerData::reuse_address
bool reuse_address
allow reuse of binding address
Definition: NetworkBrokerData.hpp:60
helics::InterfaceTypes::INPROC
@ INPROC
using inproc sockets for communications
helics::NetworkBrokerData::portStart
int portStart
the starting port for automatic port definitions
Definition: NetworkBrokerData.hpp:55
helics::insertProtocol
void insertProtocol(std::string &networkAddress, InterfaceTypes interfaceT)
Definition: NetworkBrokerData.cpp:292
helics::InterfaceTypes::IPC
@ IPC
using ipc locations
helics::getLocalExternalAddressV6
std::string getLocalExternalAddressV6()
Definition: NetworkBrokerData.cpp:481
helics::NetworkBrokerData::NetworkBrokerData
NetworkBrokerData(InterfaceTypes type)
Definition: NetworkBrokerData.hpp:74
helics::NetworkBrokerData::commandLineParser
std::shared_ptr< helicsCLI11App > commandLineParser(const std::string &localAddress, bool enableConfig=true)
Definition: NetworkBrokerData.cpp:28
helics::getLocalExternalAddressV4
std::string getLocalExternalAddressV4()
Definition: NetworkBrokerData.cpp:371
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::isipv6
bool isipv6(const std::string &address)
Definition: NetworkBrokerData.cpp:313
helics::makePortAddress
std::string makePortAddress(const std::string &networkInterface, int portNumber)
Definition: NetworkBrokerData.cpp:217
helics::NetworkBrokerData::server_mode
ServerModeOptions server_mode
setup a server mode
Definition: NetworkBrokerData.hpp:70
helics::NetworkBrokerData::connectionAddress
std::string connectionAddress
the address for connecting
Definition: NetworkBrokerData.hpp:50
helics::NetworkBrokerData::setInterfaceType
void setInterfaceType(InterfaceTypes type)
Definition: NetworkBrokerData.hpp:83
helics::stripProtocol
std::string stripProtocol(const std::string &networkAddress)
Definition: NetworkBrokerData.cpp:257
helics::NetworkBrokerData::portNumber
int portNumber
the port number for the local interface
Definition: NetworkBrokerData.hpp:51
helics::NetworkBrokerData::useJsonSerialization
bool useJsonSerialization
for message serialization use JSON
Definition: NetworkBrokerData.hpp:68
helics::NetworkBrokerData::maxRetries
int maxRetries
the maximum number of retries to establish a network connection
Definition: NetworkBrokerData.hpp:58
helics::InterfaceTypes
InterfaceTypes
Definition: NetworkBrokerData.hpp:24
helics::NetworkBrokerData::brokerName
std::string brokerName
the identifier for the broker
Definition: NetworkBrokerData.hpp:46
helics::addJsonConfig
HelicsConfigJSON * addJsonConfig(CLI::App *app)
Add the HELICS JSON configuration processor to the app.
Definition: helicsCLI11JsonConfig.cpp:96
helics::InterfaceNetworks::LOCAL
@ LOCAL
just open local ports