Skip to content

Commit

Permalink
Add DSCP to network flow endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Ananya Muddukrishna <ananya.x.muddukrishna@ericsson.com>
  • Loading branch information
Ananya Muddukrishna committed Feb 26, 2021
1 parent 56a8a1d commit 9302ef6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
19 changes: 18 additions & 1 deletion rmw/include/rmw/network_flow_endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ typedef struct RMW_PUBLIC_TYPE rmw_network_flow_endpoint_t
// TODO(anamud): Consider specializing since flow_label is set only at publisher
// ... side.
uint32_t flow_label;
// TODO(anemud): Consider adding the DSCP parameter
// DSCP (Diff. Services Code Point)
// TODO(anamud): Consider specializing since DSCP is set only at publisher
// ... side.
uint8_t dscp;
// Internet address
char internet_address[RMW_INET_ADDRSTRLEN];
} rmw_network_flow_endpoint_t;
Expand Down Expand Up @@ -140,6 +143,20 @@ rmw_network_flow_endpoint_set_flow_label(
rmw_network_flow_endpoint_t * network_flow_endpoint,
const uint32_t flow_label);

/// Set DSCP (Diff. Services Code Point) in given rmw_network_flow_endpoint_t instance
/**
* \param[in] network_flow_endpoint network_flow_endpoint_t to be initialized
* \param[in] dscp the DSCP
* \returns `RMW_RET_OK` on successfull initilization, or
* \returns `RMW_RET_INVALID_ARGUMENT` if `network_flow_endpoint` is NULL, or
* \returns `RMW_RET_ERROR` when an unspecified error occurs.
*/
RMW_PUBLIC
rmw_ret_t
rmw_network_flow_endpoint_set_dscp(
rmw_network_flow_endpoint_t * network_flow_endpoint,
const uint8_t dscp);

/// Set internet address in the rmw_network_flow_endpoint_t struct
/**
* \param[in] network_flow_endpoint network_flow_endpoint_t to be initialized
Expand Down
14 changes: 14 additions & 0 deletions rmw/src/network_flow_endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ rmw_network_flow_endpoint_set_flow_label(
return RMW_RET_OK;
}

rmw_ret_t
rmw_network_flow_endpoint_set_dscp(
rmw_network_flow_endpoint_t * network_flow_endpoint,
const uint8_t dscp)
{
if (!network_flow_endpoint) {
RMW_SET_ERROR_MSG("network_flow_endpoint is null");
return RMW_RET_INVALID_ARGUMENT;
}

network_flow_endpoint->dscp = dscp;
return RMW_RET_OK;
}

rmw_ret_t
rmw_network_flow_endpoint_set_internet_address(
rmw_network_flow_endpoint_t * network_flow_endpoint,
Expand Down
16 changes: 16 additions & 0 deletions rmw/test/test_network_flow_endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ TEST(test_network_flow_endpoint, zero_init) {
EXPECT_EQ(network_flow_endpoint.internet_protocol, 0) << "Non-zero internet protocol";
EXPECT_EQ(network_flow_endpoint.transport_port, 0u) << "Non-zero transport_port";
EXPECT_EQ(network_flow_endpoint.flow_label, 0u) << "Non-zero flow label";
EXPECT_EQ(network_flow_endpoint.dscp, 0u) << "Non-zero DSCP";
for (uint8_t i = 0; i < RMW_INET_ADDRSTRLEN; i++) {
EXPECT_EQ(network_flow_endpoint.internet_address[i], 0) << "Non-zero internet address";
}
Expand Down Expand Up @@ -168,6 +169,21 @@ TEST(test_network_flow_endpoint, set_flow_label) {
EXPECT_EQ(network_flow_endpoint.flow_label, flow_label) << "flow_label value is not as expected";
}

TEST(test_network_flow_endpoint, set_dscp) {
rmw_network_flow_endpoint_t network_flow_endpoint =
rmw_get_zero_initialized_network_flow_endpoint();
uint8_t dscp = 0x2e;

rmw_ret_t ret = rmw_network_flow_endpoint_set_dscp(nullptr, dscp);
EXPECT_EQ(ret, RMW_RET_INVALID_ARGUMENT) <<
"Expected invalid argument for null network_flow_endpoint";
rmw_reset_error();

ret = rmw_network_flow_endpoint_set_dscp(&network_flow_endpoint, dscp);
EXPECT_EQ(ret, RMW_RET_OK) << "Expected OK for valid arguments";
EXPECT_EQ(network_flow_endpoint.dscp, dscp) << "dscp value is not as expected";
}

TEST(test_network_flow_endpoint, set_internet_address) {
rmw_network_flow_endpoint_t network_flow_endpoint =
rmw_get_zero_initialized_network_flow_endpoint();
Expand Down

0 comments on commit 9302ef6

Please sign in to comment.