Skip to content

Commit

Permalink
[bfdorch] add default TOS value for BFD session (#2689)
Browse files Browse the repository at this point in the history
What I did
Add default TOS value when create BFD session, default DSCP value is 46, default ECN is 0. The BFD session configuration will override this default value.

Why I did it
Higher DSCP value is preferred for BFD packet.

How I verified it
Set different TOS value in BFD session configuration, and create BFD session in DUT.
Load the test image with the design change, connect a traffic generator (with BFD protocol support), capture the packet sent out by DUT, check the DSCP and ECN field in the captured packet.
  • Loading branch information
baorliu authored and yxieca committed Mar 8, 2023
1 parent 95d3f6d commit 641c65c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
11 changes: 11 additions & 0 deletions orchagent/bfdorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ using namespace swss;
#define BFD_SESSION_DEFAULT_TX_INTERVAL 1000
#define BFD_SESSION_DEFAULT_RX_INTERVAL 1000
#define BFD_SESSION_DEFAULT_DETECT_MULTIPLIER 10
// TOS: default 6-bit DSCP value 48, default 2-bit ecn value 0. 48<<2 = 192
#define BFD_SESSION_DEFAULT_TOS 192
#define BFD_SESSION_MILLISECOND_TO_MICROSECOND 1000
#define BFD_SRCPORTINIT 49152
#define BFD_SRCPORTMAX 65536
Expand Down Expand Up @@ -243,6 +245,7 @@ bool BfdOrch::create_bfd_session(const string& key, const vector<FieldValueTuple
uint32_t tx_interval = BFD_SESSION_DEFAULT_TX_INTERVAL;
uint32_t rx_interval = BFD_SESSION_DEFAULT_RX_INTERVAL;
uint8_t multiplier = BFD_SESSION_DEFAULT_DETECT_MULTIPLIER;
uint8_t tos = BFD_SESSION_DEFAULT_TOS;
bool multihop = false;
MacAddress dst_mac;
bool dst_mac_provided = false;
Expand Down Expand Up @@ -291,6 +294,10 @@ bool BfdOrch::create_bfd_session(const string& key, const vector<FieldValueTuple
dst_mac = MacAddress(value);
dst_mac_provided = true;
}
else if (fvField(i) == "tos")
{
tos = to_uint<uint8_t>(value);
}
else
SWSS_LOG_ERROR("Unsupported BFD attribute %s\n", fvField(i).c_str());
}
Expand Down Expand Up @@ -352,6 +359,10 @@ bool BfdOrch::create_bfd_session(const string& key, const vector<FieldValueTuple
attrs.emplace_back(attr);
fvVector.emplace_back("multiplier", to_string(multiplier));

attr.id = SAI_BFD_SESSION_ATTR_TOS;
attr.value.u8 = tos;
attrs.emplace_back(attr);

if (multihop)
{
attr.id = SAI_BFD_SESSION_ATTR_MULTIHOP;
Expand Down
13 changes: 12 additions & 1 deletion tests/test_bfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_addRemoveBfdSession(self, dvs):
bfdSessions = self.get_exist_bfd_session()

# Create BFD session
fieldValues = {"local_addr": "10.0.0.1"}
fieldValues = {"local_addr": "10.0.0.1","tos":"64"}
self.create_bfd_session("default:default:10.0.0.2", fieldValues)
self.adb.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_BFD_SESSION", len(bfdSessions) + 1)

Expand All @@ -62,6 +62,7 @@ def test_addRemoveBfdSession(self, dvs):
"SAI_BFD_SESSION_ATTR_SRC_IP_ADDRESS": "10.0.0.1",
"SAI_BFD_SESSION_ATTR_DST_IP_ADDRESS": "10.0.0.2",
"SAI_BFD_SESSION_ATTR_TYPE": "SAI_BFD_SESSION_TYPE_ASYNC_ACTIVE",
"SAI_BFD_SESSION_ATTR_TOS": "64",
"SAI_BFD_SESSION_ATTR_IPHDR_VERSION": "4"
}
self.check_asic_bfd_session_value(session, expected_adb_values)
Expand Down Expand Up @@ -102,6 +103,7 @@ def test_addRemoveBfdSession_ipv6(self, dvs):
"SAI_BFD_SESSION_ATTR_SRC_IP_ADDRESS": "2000::1",
"SAI_BFD_SESSION_ATTR_DST_IP_ADDRESS": "2000::2",
"SAI_BFD_SESSION_ATTR_TYPE": "SAI_BFD_SESSION_TYPE_ASYNC_ACTIVE",
"SAI_BFD_SESSION_ATTR_TOS": "192",
"SAI_BFD_SESSION_ATTR_IPHDR_VERSION": "6"
}
self.check_asic_bfd_session_value(session, expected_adb_values)
Expand Down Expand Up @@ -142,6 +144,7 @@ def test_addRemoveBfdSession_interface(self, dvs):
"SAI_BFD_SESSION_ATTR_SRC_IP_ADDRESS": "10.0.0.1",
"SAI_BFD_SESSION_ATTR_DST_IP_ADDRESS": "10.0.0.2",
"SAI_BFD_SESSION_ATTR_TYPE": "SAI_BFD_SESSION_TYPE_ASYNC_ACTIVE",
"SAI_BFD_SESSION_ATTR_TOS": "192",
"SAI_BFD_SESSION_ATTR_IPHDR_VERSION": "4",
"SAI_BFD_SESSION_ATTR_HW_LOOKUP_VALID": "false",
"SAI_BFD_SESSION_ATTR_DST_MAC_ADDRESS": "00:02:03:04:05:06"
Expand Down Expand Up @@ -184,6 +187,7 @@ def test_addRemoveBfdSession_txrx_interval(self, dvs):
"SAI_BFD_SESSION_ATTR_SRC_IP_ADDRESS": "10.0.0.1",
"SAI_BFD_SESSION_ATTR_DST_IP_ADDRESS": "10.0.0.2",
"SAI_BFD_SESSION_ATTR_TYPE": "SAI_BFD_SESSION_TYPE_ASYNC_ACTIVE",
"SAI_BFD_SESSION_ATTR_TOS": "192",
"SAI_BFD_SESSION_ATTR_IPHDR_VERSION": "4",
"SAI_BFD_SESSION_ATTR_MIN_TX": "300000",
"SAI_BFD_SESSION_ATTR_MIN_RX": "500000",
Expand Down Expand Up @@ -226,6 +230,7 @@ def test_addRemoveBfdSession_multiplier(self, dvs):
"SAI_BFD_SESSION_ATTR_SRC_IP_ADDRESS": "10.0.0.1",
"SAI_BFD_SESSION_ATTR_DST_IP_ADDRESS": "10.0.0.2",
"SAI_BFD_SESSION_ATTR_TYPE": "SAI_BFD_SESSION_TYPE_ASYNC_ACTIVE",
"SAI_BFD_SESSION_ATTR_TOS": "192",
"SAI_BFD_SESSION_ATTR_IPHDR_VERSION": "4",
"SAI_BFD_SESSION_ATTR_MULTIPLIER": "5"
}
Expand Down Expand Up @@ -267,6 +272,7 @@ def test_addRemoveBfdSession_multihop(self, dvs):
"SAI_BFD_SESSION_ATTR_SRC_IP_ADDRESS": "10.0.0.1",
"SAI_BFD_SESSION_ATTR_DST_IP_ADDRESS": "10.0.0.2",
"SAI_BFD_SESSION_ATTR_TYPE": "SAI_BFD_SESSION_TYPE_ASYNC_ACTIVE",
"SAI_BFD_SESSION_ATTR_TOS": "192",
"SAI_BFD_SESSION_ATTR_IPHDR_VERSION": "4",
"SAI_BFD_SESSION_ATTR_MULTIHOP": "true"
}
Expand Down Expand Up @@ -308,6 +314,7 @@ def test_addRemoveBfdSession_type(self, dvs):
"SAI_BFD_SESSION_ATTR_SRC_IP_ADDRESS": "10.0.0.1",
"SAI_BFD_SESSION_ATTR_DST_IP_ADDRESS": "10.0.0.2",
"SAI_BFD_SESSION_ATTR_TYPE": "SAI_BFD_SESSION_TYPE_DEMAND_ACTIVE",
"SAI_BFD_SESSION_ATTR_TOS": "192",
"SAI_BFD_SESSION_ATTR_IPHDR_VERSION": "4"
}
self.check_asic_bfd_session_value(session, expected_adb_values)
Expand Down Expand Up @@ -350,6 +357,7 @@ def test_multipleBfdSessions(self, dvs):
"SAI_BFD_SESSION_ATTR_SRC_IP_ADDRESS": "10.0.0.1",
"SAI_BFD_SESSION_ATTR_DST_IP_ADDRESS": "10.0.0.2",
"SAI_BFD_SESSION_ATTR_TYPE": "SAI_BFD_SESSION_TYPE_ASYNC_ACTIVE",
"SAI_BFD_SESSION_ATTR_TOS": "192",
"SAI_BFD_SESSION_ATTR_IPHDR_VERSION": "4"
}
self.check_asic_bfd_session_value(session1, expected_adb_values)
Expand All @@ -376,6 +384,7 @@ def test_multipleBfdSessions(self, dvs):
"SAI_BFD_SESSION_ATTR_SRC_IP_ADDRESS": "10.0.0.1",
"SAI_BFD_SESSION_ATTR_DST_IP_ADDRESS": "10.0.1.2",
"SAI_BFD_SESSION_ATTR_TYPE": "SAI_BFD_SESSION_TYPE_ASYNC_ACTIVE",
"SAI_BFD_SESSION_ATTR_TOS": "192",
"SAI_BFD_SESSION_ATTR_IPHDR_VERSION": "4",
"SAI_BFD_SESSION_ATTR_MIN_TX": "300000",
"SAI_BFD_SESSION_ATTR_MIN_RX": "500000",
Expand Down Expand Up @@ -404,6 +413,7 @@ def test_multipleBfdSessions(self, dvs):
"SAI_BFD_SESSION_ATTR_SRC_IP_ADDRESS": "2000::1",
"SAI_BFD_SESSION_ATTR_DST_IP_ADDRESS": "2000::2",
"SAI_BFD_SESSION_ATTR_TYPE": "SAI_BFD_SESSION_TYPE_DEMAND_ACTIVE",
"SAI_BFD_SESSION_ATTR_TOS": "192",
"SAI_BFD_SESSION_ATTR_IPHDR_VERSION": "6"
}
self.check_asic_bfd_session_value(session3, expected_adb_values)
Expand All @@ -430,6 +440,7 @@ def test_multipleBfdSessions(self, dvs):
"SAI_BFD_SESSION_ATTR_SRC_IP_ADDRESS": "3000::1",
"SAI_BFD_SESSION_ATTR_DST_IP_ADDRESS": "3000::2",
"SAI_BFD_SESSION_ATTR_TYPE": "SAI_BFD_SESSION_TYPE_ASYNC_ACTIVE",
"SAI_BFD_SESSION_ATTR_TOS": "192",
"SAI_BFD_SESSION_ATTR_IPHDR_VERSION": "6"
}
self.check_asic_bfd_session_value(session4, expected_adb_values)
Expand Down

0 comments on commit 641c65c

Please sign in to comment.