-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get network flows of publishers and subscriptions
Signed-off-by: Ananya Muddukrishna <ananya.x.muddukrishna@ericsson.com>
- Loading branch information
Ananya Muddukrishna
committed
Dec 14, 2020
1 parent
fc6c364
commit 56798e9
Showing
9 changed files
with
322 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright 2020 Ericsson AB | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef RCLCPP__NETWORK_FLOW_HPP_ | ||
#define RCLCPP__NETWORK_FLOW_HPP_ | ||
|
||
#include <cstdint> | ||
#include <string> | ||
#include <iostream> | ||
|
||
#include "rcl/network_flow.h" | ||
|
||
#include "rclcpp/visibility_control.hpp" | ||
|
||
namespace rclcpp | ||
{ | ||
|
||
/** | ||
* Class describes endpoints of network flow such as transport protocol, | ||
* internet protocol, transport port, flow label, and internet address | ||
*/ | ||
class NetworkFlow | ||
{ | ||
public: | ||
/// Construct from rcl_network_flow_t | ||
RCLCPP_PUBLIC | ||
explicit NetworkFlow(const rcl_network_flow_t & network_flow) | ||
: transport_protocol_( | ||
rcl_network_flow_get_transport_protocol_string(network_flow.transport_protocol)), | ||
internet_protocol_( | ||
rcl_network_flow_get_internet_protocol_string(network_flow.internet_protocol)), | ||
transport_port_(network_flow.transport_port), | ||
flow_label_(network_flow.flow_label), | ||
internet_address_(network_flow.internet_address) | ||
{ | ||
} | ||
|
||
/// Get transport protocol | ||
RCLCPP_PUBLIC | ||
const std::string & transport_protocol() const; | ||
|
||
/// Get internet protocol | ||
RCLCPP_PUBLIC | ||
const std::string & internet_protocol() const; | ||
|
||
/// Get transport port | ||
RCLCPP_PUBLIC | ||
uint16_t transport_port() const; | ||
|
||
/// Get flow label | ||
RCLCPP_PUBLIC | ||
uint32_t flow_label() const; | ||
|
||
/// Get internet address | ||
RCLCPP_PUBLIC | ||
const std::string & internet_address() const; | ||
|
||
/// Compare two NetworkFlow instances | ||
friend bool operator==(const NetworkFlow & left, const NetworkFlow & right); | ||
friend bool operator!=(const NetworkFlow & left, const NetworkFlow & right); | ||
|
||
/// Streaming helper | ||
friend std::ostream & operator<<(std::ostream & os, const NetworkFlow & network_flow); | ||
|
||
private: | ||
std::string transport_protocol_; | ||
std::string internet_protocol_; | ||
uint16_t transport_port_; | ||
uint32_t flow_label_; | ||
std::string internet_address_; | ||
}; | ||
|
||
/// Check if two NetworkFlow instances are equal | ||
RCLCPP_PUBLIC | ||
bool operator==(const NetworkFlow & left, const NetworkFlow & right); | ||
|
||
/// Check if two NetworkFlow instances are not equal | ||
RCLCPP_PUBLIC | ||
bool operator!=(const NetworkFlow & left, const NetworkFlow & right); | ||
|
||
/// Streaming helper | ||
RCLCPP_PUBLIC | ||
std::ostream & operator<<(std::ostream & os, const NetworkFlow & network_flow); | ||
|
||
} // namespace rclcpp | ||
|
||
#endif // RCLCPP__NETWORK_FLOW_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2020 Ericsson AB | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <string> | ||
|
||
#include "rclcpp/network_flow.hpp" | ||
|
||
namespace rclcpp | ||
{ | ||
|
||
const std::string & | ||
NetworkFlow::transport_protocol() const | ||
{ | ||
return transport_protocol_; | ||
} | ||
|
||
const std::string & | ||
NetworkFlow::internet_protocol() const | ||
{ | ||
return internet_protocol_; | ||
} | ||
|
||
uint16_t NetworkFlow::transport_port() const | ||
{ | ||
return transport_port_; | ||
} | ||
|
||
uint32_t NetworkFlow::flow_label() const | ||
{ | ||
return flow_label_; | ||
} | ||
|
||
const std::string & | ||
NetworkFlow::internet_address() const | ||
{ | ||
return internet_address_; | ||
} | ||
|
||
bool operator==(const NetworkFlow & left, const NetworkFlow & right) | ||
{ | ||
return left.transport_protocol_ == right.transport_protocol_ && | ||
left.internet_protocol_ == right.internet_protocol_ && | ||
left.transport_port_ == right.transport_port_ && | ||
left.flow_label_ == right.flow_label_ && | ||
left.internet_address_ == right.internet_address_; | ||
} | ||
|
||
bool operator!=(const NetworkFlow & left, const NetworkFlow & right) | ||
{ | ||
return !(left == right); | ||
} | ||
|
||
std::ostream & operator<<(std::ostream & os, const NetworkFlow & network_flow) | ||
{ | ||
os << '{' << | ||
"\"transportProtocol\": " << network_flow.transport_protocol_ << ", " << | ||
"\"transportPort\": " << network_flow.transport_port_ << ", " << | ||
"\"internetProtocol\": " << network_flow.internet_protocol_ << ", " << | ||
"\"internetAddress\": " << network_flow.internet_address_ << ", " << | ||
"\"flowLabel\": " << network_flow.flow_label_ << ", " << | ||
'}'; | ||
return os; | ||
} | ||
|
||
} // namespace rclcpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters