helics  2.8.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 interface_networks : char {
17  local = 0,
18  ipv4 = 4,
19  ipv6 = 6,
20  all = 10,
21 };
22 
24 enum class interface_type : 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 server_mode_options : 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  server_mode_options server_mode{server_mode_options::unspecified};
70  public:
71  NetworkBrokerData() = default;
73  explicit NetworkBrokerData(interface_type type): allowedType(type) {}
74 
78  std::shared_ptr<helicsCLI11App> commandLineParser(const std::string& localAddress,
79  bool enableConfig = true);
82  void setInterfaceType(interface_type type) { allowedType = type; }
83 
84  private:
86  void checkAndUpdateBrokerAddress(const std::string& localAddress);
87  interface_type allowedType = interface_type::ip;
88 };
89 
97 std::string makePortAddress(const std::string& networkInterface, int portNumber);
98 
106 std::pair<std::string, int> extractInterfaceandPort(const std::string& address);
107 
115 std::pair<std::string, std::string> extractInterfaceandPortString(const std::string& address);
116 
119 std::string stripProtocol(const std::string& networkAddress);
121 void removeProtocol(std::string& networkAddress);
122 
124 std::string addProtocol(const std::string& networkAddress, interface_type interfaceT);
125 
127 void insertProtocol(std::string& networkAddress, interface_type interfaceT);
128 
132 bool isipv6(const std::string& address);
133 
141 std::vector<std::string> prioritizeExternalAddresses(std::vector<std::string> high,
142  std::vector<std::string> low);
143 
146 std::string getLocalExternalAddressV4();
147 
150 std::string getLocalExternalAddress(const std::string& server);
151 
154 std::string getLocalExternalAddressV4(const std::string& server);
155 
158 std::string getLocalExternalAddressV6();
159 
162 std::string getLocalExternalAddressV6(const std::string& server);
163 
166 std::string
167  generateMatchingInterfaceAddress(const std::string& server,
169 } // namespace helics
helics::interface_type::udp
@ udp
using udp ports for communication
helics::insertProtocol
void insertProtocol(std::string &networkAddress, interface_type interfaceT)
Definition: NetworkBrokerData.cpp:291
helics::addProtocol
std::string addProtocol(const std::string &networkAddress, interface_type interfaceT)
Definition: NetworkBrokerData.cpp:273
helics::removeProtocol
void removeProtocol(std::string &networkAddress)
Definition: NetworkBrokerData.cpp:265
helics::NetworkBrokerData::server_mode
server_mode_options server_mode
setup a server mode
Definition: NetworkBrokerData.hpp:69
helics::extractInterfaceandPortString
std::pair< std::string, std::string > extractInterfaceandPortString(const std::string &address)
Definition: NetworkBrokerData.cpp:250
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:574
helics::extractInterfaceandPort
std::pair< std::string, int > extractInterfaceandPort(const std::string &address)
Definition: NetworkBrokerData.cpp:226
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:329
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::interface_networks::local
@ local
just open local ports
helics::interface_type::ipc
@ ipc
using ipc locations
helics::NetworkBrokerData::autobroker
bool autobroker
flag for specifying an automatic broker generation
Definition: NetworkBrokerData.hpp:63
helics::NetworkBrokerData
Definition: NetworkBrokerData.hpp:36
helics::NetworkBrokerData::NetworkBrokerData
NetworkBrokerData(interface_type type)
Definition: NetworkBrokerData.hpp:73
helics::NetworkBrokerData::brokerPort
int brokerPort
the port number to use for the main broker interface
Definition: NetworkBrokerData.hpp:52
helics::interface_networks
interface_networks
Definition: NetworkBrokerData.hpp:16
helics::BrokerFactory::findBroker
std::shared_ptr< Broker > findBroker(const std::string &brokerName)
Definition: BrokerFactory.cpp:185
helics::generateMatchingInterfaceAddress
std::string generateMatchingInterfaceAddress(const std::string &server, interface_networks network)
Definition: NetworkBrokerData.cpp:582
helics::NetworkBrokerData::brokerInitString
std::string brokerInitString
a string containing arguments for the broker initialization
Definition: NetworkBrokerData.hpp:49
helics::interface_networks::ipv6
@ ipv6
use external ipv6 ports
helics::interface_networks::all
@ all
use all external 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::NetworkBrokerData::portStart
int portStart
the starting port for automatic port definitions
Definition: NetworkBrokerData.hpp:55
helics::interface_type::tcp
@ tcp
using tcp ports for communication
helics::getLocalExternalAddressV6
std::string getLocalExternalAddressV6()
Definition: NetworkBrokerData.cpp:480
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:370
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::interface_type
interface_type
Definition: NetworkBrokerData.hpp:24
helics::isipv6
bool isipv6(const std::string &address)
Definition: NetworkBrokerData.cpp:312
helics::makePortAddress
std::string makePortAddress(const std::string &networkInterface, int portNumber)
Definition: NetworkBrokerData.cpp:216
helics::interface_networks::ipv4
@ ipv4
use external ipv4 ports
helics::NetworkBrokerData::connectionAddress
std::string connectionAddress
the address for connecting
Definition: NetworkBrokerData.hpp:50
helics::stripProtocol
std::string stripProtocol(const std::string &networkAddress)
Definition: NetworkBrokerData.cpp:256
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::NetworkBrokerData::setInterfaceType
void setInterfaceType(interface_type type)
Definition: NetworkBrokerData.hpp:82
helics::NetworkBrokerData::brokerName
std::string brokerName
the identifier for the broker
Definition: NetworkBrokerData.hpp:46
helics::interface_type::inproc
@ inproc
using inproc sockets for communications
helics::addJsonConfig
HelicsConfigJSON * addJsonConfig(CLI::App *app)
Add the HELICS JSON configuration processor to the app.
Definition: helicsCLI11JsonConfig.cpp:96
helics::interface_type::ip
@ ip
using both types of ports (tcp/or udp) for communication