Skip to content

Commit f08baaa

Browse files
committed
Merge branch 'master' of https://github.com/sonic-net/sonic-swss into state_activated_rq
2 parents 2f1749a + 398161b commit f08baaa

File tree

7 files changed

+184
-26
lines changed

7 files changed

+184
-26
lines changed

cfgmgr/buffer_pool_mellanox.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ local function iterate_all_items(all_items, check_lossless)
6969
if string.len(range) == 1 then
7070
size = 1
7171
else
72-
size = 1 + tonumber(string.sub(range, -1)) - tonumber(string.sub(range, 1, 1))
72+
-- Extract start and end numbers from the range (e.g., "8-15")
73+
local start_num, end_num = string.match(range, "(%d+)-(%d+)")
74+
size = tonumber(end_num) - tonumber(start_num) + 1
7375
end
7476
profiles[profile_name] = profile_ref_count + size
7577
if port_set_8lanes[port] and ingress_profile_is_lossless[profile_name] == false then

cfgmgr/macsecmgr.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -503,14 +503,11 @@ task_process_status MACsecMgr::enableMACsec(
503503
return task_need_retry;
504504
}
505505

506-
// Create MKA Session object
507-
auto port = m_macsec_ports.emplace(
508-
std::piecewise_construct,
509-
std::make_tuple(port_name),
510-
std::make_tuple());
511-
if (!port.second)
506+
// Handle existing macsec profile
507+
auto port_itr = m_macsec_ports.find(port_name);
508+
if (port_itr != m_macsec_ports.end())
512509
{
513-
if (port.first->second.profile_name == profile_name)
510+
if (port_itr->second.profile_name == profile_name)
514511
{
515512
SWSS_LOG_NOTICE(
516513
"The MACsec profile '%s' on the port '%s' has been loaded",
@@ -523,7 +520,7 @@ task_process_status MACsecMgr::enableMACsec(
523520
SWSS_LOG_NOTICE(
524521
"The MACsec profile '%s' on the port '%s' "
525522
"will be replaced by the MACsec profile '%s'",
526-
port.first->second.profile_name.c_str(),
523+
port_itr->second.profile_name.c_str(),
527524
port_name.c_str(),
528525
profile_name.c_str());
529526
auto result = disableMACsec(port_name, port_attr);
@@ -533,6 +530,11 @@ task_process_status MACsecMgr::enableMACsec(
533530
}
534531
}
535532
}
533+
// Create MKA Session object
534+
auto port = m_macsec_ports.emplace(
535+
std::piecewise_construct,
536+
std::make_tuple(port_name),
537+
std::make_tuple());
536538
auto & session = port.first->second;
537539
session.profile_name = profile_name;
538540
ostringstream ostream;

fpmsyncd/routesync.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,9 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
16361636
{
16371637
sendOffloadReply(route_obj);
16381638
}
1639+
auto proto_num = rtnl_route_get_protocol(route_obj);
1640+
auto proto_str = getProtocolString(proto_num);
1641+
FieldValueTuple proto("protocol", proto_str);
16391642

16401643
switch (rtnl_route_get_type(route_obj))
16411644
{
@@ -1644,6 +1647,7 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
16441647
vector<FieldValueTuple> fvVector;
16451648
FieldValueTuple fv("blackhole", "true");
16461649
fvVector.push_back(fv);
1650+
fvVector.push_back(proto);
16471651
m_routeTable.set(destipprefix, fvVector);
16481652
return;
16491653
}
@@ -1699,9 +1703,6 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
16991703
installNextHopGroup(nhg_id);
17001704
}
17011705

1702-
auto proto_num = rtnl_route_get_protocol(route_obj);
1703-
auto proto_str = getProtocolString(proto_num);
1704-
FieldValueTuple proto("protocol", proto_str);
17051706
fvVector.push_back(proto);
17061707

17071708
}
@@ -1766,11 +1767,7 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
17661767
}
17671768
}
17681769

1769-
auto proto_num = rtnl_route_get_protocol(route_obj);
1770-
auto proto_str = getProtocolString(proto_num);
1771-
17721770

1773-
FieldValueTuple proto("protocol", proto_str);
17741771
FieldValueTuple gw("nexthop", gw_list);
17751772
FieldValueTuple intf("ifname", intf_list);
17761773

@@ -1983,13 +1980,18 @@ void RouteSync::onLabelRouteMsg(int nlmsg_type, struct nl_object *obj)
19831980
return;
19841981
}
19851982

1983+
auto proto_num = rtnl_route_get_protocol(route_obj);
1984+
auto proto_str = getProtocolString(proto_num);
1985+
FieldValueTuple proto("protocol", proto_str);
1986+
19861987
switch (rtnl_route_get_type(route_obj))
19871988
{
19881989
case RTN_BLACKHOLE:
19891990
{
19901991
vector<FieldValueTuple> fvVector;
19911992
FieldValueTuple fv("blackhole", "true");
19921993
fvVector.push_back(fv);
1994+
fvVector.push_back(proto);
19931995
m_label_routeTable.set(destaddr, fvVector);
19941996
return;
19951997
}
@@ -2388,14 +2390,12 @@ string RouteSync::getNextHopWt(struct rtnl_route *route_obj)
23882390
struct rtnl_nexthop *nexthop = rtnl_route_nexthop_n(route_obj, i);
23892391
/* Get the weight of next hop */
23902392
uint8_t weight = rtnl_route_nh_get_weight(nexthop);
2391-
if (weight)
2393+
if (weight == 0)
23922394
{
2393-
result += to_string(weight);
2394-
}
2395-
else
2396-
{
2397-
return "";
2395+
SWSS_LOG_INFO("Using default weight of 1 for nexthop");
2396+
weight = 1; // default weight is 1
23982397
}
2398+
result += to_string(weight);
23992399

24002400
if (i + 1 < rtnl_route_get_nnexthops(route_obj))
24012401
{
@@ -2747,4 +2747,4 @@ void RouteSync::getNextHopGroupFields(const NextHopGroup& nhg, string& nexthops,
27472747
++i;
27482748
}
27492749
}
2750-
}
2750+
}

orchagent/bfdorch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ bool BgpGlobalStateOrch::offload_supported(bool get_ipv6)
750750
}
751751
if (!capability.get_implemented)
752752
{
753-
SWSS_LOG_ERROR("BFD offload type not implemented");
753+
SWSS_LOG_NOTICE("BFD offload type not implemented");
754754
return false;
755755
}
756756

orchagent/routeorch.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ struct NhgBase;
3737

3838
struct NextHopGroupEntry
3939
{
40+
NextHopGroupEntry() :
41+
next_hop_group_id(SAI_NULL_OBJECT_ID),
42+
ref_count(0),
43+
nh_member_install_count(0),
44+
eligible_for_default_route_nh_swap(false),
45+
is_default_route_nh_swap(false)
46+
{
47+
}
48+
4049
sai_object_id_t next_hop_group_id; // next hop group id
4150
int ref_count; // reference count
4251
NextHopGroupMembers nhopgroup_members; // ids of members indexed by <ip_address, if_alias>

tests/mock_tests/fpmsyncd/test_routesync.cpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,3 +904,108 @@ TEST_F(FpmSyncdResponseTest, TestRouteMsgWithNHG)
904904

905905
rtnl_route_put(test_route);
906906
}
907+
908+
TEST_F(FpmSyncdResponseTest, TestBlackholeRoute)
909+
{
910+
Table route_table(m_db.get(), APP_ROUTE_TABLE_NAME);
911+
Table label_route_table(m_db.get(), APP_LABEL_ROUTE_TABLE_NAME);
912+
auto createRoute = [](const char* prefix, uint8_t prefixlen) -> rtnl_route* {
913+
rtnl_route* route = rtnl_route_alloc();
914+
nl_addr* dst_addr;
915+
nl_addr_parse(prefix, AF_INET, &dst_addr);
916+
rtnl_route_set_dst(route, dst_addr);
917+
rtnl_route_set_type(route, RTN_BLACKHOLE);
918+
rtnl_route_set_protocol(route, RTPROT_STATIC);
919+
rtnl_route_set_family(route, AF_INET);
920+
rtnl_route_set_scope(route, RT_SCOPE_UNIVERSE);
921+
rtnl_route_set_table(route, RT_TABLE_UNSPEC);
922+
nl_addr_put(dst_addr);
923+
return route;
924+
};
925+
926+
// create a route
927+
const char* test_destipprefix = "10.1.1.0";
928+
rtnl_route* test_route = createRoute(test_destipprefix, 24);
929+
930+
const char* test_destipprefix2 = "20.1.1.0";
931+
rtnl_route* test_route2 = createRoute(test_destipprefix2, 24);
932+
{
933+
934+
m_mockRouteSync.onRouteMsg(RTM_NEWROUTE, (nl_object*)test_route, nullptr);
935+
936+
// verify the blackhole route has protocol programmed
937+
vector<FieldValueTuple> fvs;
938+
EXPECT_TRUE(route_table.get(test_destipprefix, fvs));
939+
940+
bool proto_found = false;
941+
for (const auto& fv : fvs) {
942+
if (fvField(fv) == "protocol") {
943+
proto_found = true;
944+
EXPECT_EQ(fvValue(fv), "static");
945+
}
946+
}
947+
EXPECT_TRUE(proto_found);
948+
949+
m_mockRouteSync.onLabelRouteMsg(RTM_NEWROUTE, (nl_object*)test_route2);
950+
951+
// verify the blackhole route has protocol programmed
952+
EXPECT_TRUE(label_route_table.get(test_destipprefix2, fvs));
953+
954+
proto_found = false;
955+
for (const auto& fv : fvs) {
956+
if (fvField(fv) == "protocol") {
957+
proto_found = true;
958+
EXPECT_EQ(fvValue(fv), "static");
959+
}
960+
}
961+
EXPECT_TRUE(proto_found);
962+
}
963+
}
964+
auto create_nl_addr(const char* addr_str)
965+
{
966+
nl_addr* addr;
967+
nl_addr_parse(addr_str, AF_INET, &addr);
968+
return unique_ptr<nl_addr, decltype(nl_addr_put)*>(addr, nl_addr_put);
969+
}
970+
971+
auto create_route(const char* dst_addr_str)
972+
{
973+
rtnl_route* route = rtnl_route_alloc();
974+
auto dst_addr = create_nl_addr(dst_addr_str);
975+
rtnl_route_set_dst(route, dst_addr.get());
976+
rtnl_route_set_type(route, RTN_UNICAST);
977+
rtnl_route_set_protocol(route, RTPROT_STATIC);
978+
rtnl_route_set_family(route, AF_INET);
979+
rtnl_route_set_scope(route, RT_SCOPE_UNIVERSE);
980+
rtnl_route_set_table(route, RT_TABLE_MAIN);
981+
return unique_ptr<rtnl_route, decltype(rtnl_route_put)*>(route, rtnl_route_put);
982+
}
983+
984+
rtnl_nexthop* create_nexthop(const char* gateway_str)
985+
{
986+
static int idx = 1; // interface index
987+
++idx;
988+
// Create a nexthop with 0 weight
989+
rtnl_nexthop* nh = rtnl_route_nh_alloc();
990+
rtnl_route_nh_set_weight(nh, 0);
991+
rtnl_route_nh_set_ifindex(nh, idx);
992+
auto gateway_addr = create_nl_addr(gateway_str);
993+
rtnl_route_nh_set_gateway(nh, gateway_addr.get());
994+
return nh;
995+
}
996+
997+
// Checks that when a nexthop is not assigned a weight, the default weight of 1 is used.
998+
TEST_F(FpmSyncdResponseTest, TestGetNextHopWt)
999+
{
1000+
auto test_route = create_route("10.1.1.0");
1001+
1002+
// Create two nexthops with 0 weight
1003+
rtnl_nexthop* nh1 = create_nexthop(test_gateway);
1004+
rtnl_nexthop* nh2 = create_nexthop(test_gateway_);
1005+
1006+
// Add new nexthops to the route
1007+
rtnl_route_add_nexthop(test_route.get(), nh1);
1008+
rtnl_route_add_nexthop(test_route.get(), nh2);
1009+
1010+
EXPECT_EQ(m_mockRouteSync.getNextHopWt(test_route.get()), "1,1");
1011+
}

tests/test_buffer_dynamic.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ def test_bufferPoolInitWithSHP(self, dvs, testlog):
905905
dvs.runcmd("kill -s SIGCONT {}".format(oa_pid))
906906

907907

908-
def test_bufferPoolPercentage(self, dvs, testlog):
908+
def test_bufferPoolCalculation(self, dvs, testlog):
909909
self.setup_db(dvs)
910910

911911
try:
@@ -914,6 +914,7 @@ def test_bufferPoolPercentage(self, dvs, testlog):
914914
pass
915915

916916
try:
917+
# Test 1: Test the buffer pool calculation with a percentage
917918
percentage = 75
918919
margin = 1
919920

@@ -931,6 +932,45 @@ def test_bufferPoolPercentage(self, dvs, testlog):
931932

932933
real_percentage = percentage_size * 100 / original_size
933934
assert abs(percentage - real_percentage) < margin
935+
936+
# Test 2: Test the buffer pool calculation with a port with multiple queues
937+
# Store existing Ethernet0 entries for restoration
938+
original_eth0_entries = {}
939+
eth0_keys = self.config_db.get_keys('BUFFER_QUEUE')
940+
for key in eth0_keys:
941+
if key.startswith('Ethernet0|'):
942+
original_eth0_entries[key] = self.config_db.get_entry('BUFFER_QUEUE', key)
943+
self.config_db.delete_entry('BUFFER_QUEUE', key)
944+
945+
# Startup port
946+
dvs.port_admin_set('Ethernet0', 'up')
947+
948+
# Create buffer profile
949+
self.config_db.update_entry('BUFFER_PROFILE', 'egress_test_profile',
950+
{'dynamic_th': '0',
951+
'pool': 'egress_lossy_pool',
952+
'size': '16384'})
953+
954+
# Create buffer queue entries
955+
self.config_db.update_entry('BUFFER_QUEUE', 'Ethernet0|0-7', {'profile': 'egress_test_profile'})
956+
self.config_db.update_entry('BUFFER_QUEUE', 'Ethernet0|8-12', {'profile': 'egress_test_profile'})
957+
self.config_db.update_entry('BUFFER_QUEUE', 'Ethernet0|13-19', {'profile': 'egress_test_profile'})
958+
959+
# Run lua script and check output
960+
_, output = dvs.runcmd("redis-cli --eval /usr/share/swss/buffer_pool_vs.lua")
961+
assert re.search(r"debug:BUFFER_PROFILE_TABLE:egress_test_profile:16384:20", output), "Profile reference count not found in output"
962+
934963
finally:
964+
# Remove objects in reverse order
965+
self.config_db.delete_entry('BUFFER_QUEUE', 'Ethernet0|13-19')
966+
self.config_db.delete_entry('BUFFER_QUEUE', 'Ethernet0|8-12')
967+
self.config_db.delete_entry('BUFFER_QUEUE', 'Ethernet0|0-7')
968+
self.config_db.delete_entry('BUFFER_PROFILE', 'egress_test_profile')
969+
dvs.port_admin_set('Ethernet0', 'down')
970+
971+
# Restore original Ethernet0 entries
972+
for key, value in original_eth0_entries.items():
973+
self.config_db.update_entry('BUFFER_QUEUE', key, value)
974+
935975
self.config_db.delete_entry('BUFFER_POOL', 'ingress_lossless_pool')
936-
self.config_db.update_entry('BUFFER_POOL', 'ingress_lossless_pool', original_ingress_lossless_pool)
976+
self.config_db.update_entry('BUFFER_POOL', 'ingress_lossless_pool', original_ingress_lossless_pool)

0 commit comments

Comments
 (0)