From 5b5fb105071dfaaad697ca9a47e8d76579457ae2 Mon Sep 17 00:00:00 2001 From: Tejaswini Chadaga Date: Tue, 26 Nov 2024 23:56:47 +0000 Subject: [PATCH 01/12] oa change to program sai --- orchagent/routeorch.cpp | 227 +++++++++++++++++++++++----------------- orchagent/routeorch.h | 5 +- 2 files changed, 134 insertions(+), 98 deletions(-) diff --git a/orchagent/routeorch.cpp b/orchagent/routeorch.cpp index 803f71bb1e..c4cb237a7e 100644 --- a/orchagent/routeorch.cpp +++ b/orchagent/routeorch.cpp @@ -403,47 +403,55 @@ bool RouteOrch::validnexthopinNextHopGroup(const NextHopKey &nexthop, uint32_t& /* get updated nhkey with possible weight */ auto nhkey = nhopgroup->first.getNextHops().find(nexthop); - - nhgm_attr.id = SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID; - nhgm_attr.value.oid = nhopgroup->second.next_hop_group_id; - nhgm_attrs.push_back(nhgm_attr); - - nhgm_attr.id = SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID; - nhgm_attr.value.oid = m_neighOrch->getNextHopId(nexthop); - nhgm_attrs.push_back(nhgm_attr); - - if (nhkey->weight) + auto entry_count = 1; + + if(nhkey->weight) { - nhgm_attr.id = SAI_NEXT_HOP_GROUP_MEMBER_ATTR_WEIGHT; - nhgm_attr.value.s32 = nhkey->weight; - nhgm_attrs.push_back(nhgm_attr); + entry_count = nhkey->weight/nhopgroup->second.weight_gcd; } - - if (m_switchOrch->checkOrderedEcmpEnable()) + for(size_t j = 0; j < entry_count; j++) { - nhgm_attr.id = SAI_NEXT_HOP_GROUP_MEMBER_ATTR_SEQUENCE_ID; - nhgm_attr.value.u32 = nhopgroup->second.nhopgroup_members[nexthop].seq_id; + nhgm_attr.id = SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID; + nhgm_attr.value.oid = nhopgroup->second.next_hop_group_id; nhgm_attrs.push_back(nhgm_attr); - } - status = sai_next_hop_group_api->create_next_hop_group_member(&nexthop_id, gSwitchId, - (uint32_t)nhgm_attrs.size(), - nhgm_attrs.data()); + nhgm_attr.id = SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID; + nhgm_attr.value.oid = m_neighOrch->getNextHopId(nexthop); + nhgm_attrs.push_back(nhgm_attr); - if (status != SAI_STATUS_SUCCESS) - { - SWSS_LOG_ERROR("Failed to add next hop member to group %" PRIx64 ": %d\n", - nhopgroup->second.next_hop_group_id, status); - task_process_status handle_status = handleSaiCreateStatus(SAI_API_NEXT_HOP_GROUP, status); - if (handle_status != task_success) + if (nhkey->weight) { - return parseHandleSaiStatusFailure(handle_status); + nhgm_attr.id = SAI_NEXT_HOP_GROUP_MEMBER_ATTR_WEIGHT; + nhgm_attr.value.s32 = 1; + nhgm_attrs.push_back(nhgm_attr); + } + + if (m_switchOrch->checkOrderedEcmpEnable()) + { + nhgm_attr.id = SAI_NEXT_HOP_GROUP_MEMBER_ATTR_SEQUENCE_ID; + nhgm_attr.value.u32 = nhopgroup->second.nhopgroup_members[nexthop][j].seq_id; + nhgm_attrs.push_back(nhgm_attr); } - } - ++count; - gCrmOrch->incCrmResUsedCounter(CrmResourceType::CRM_NEXTHOP_GROUP_MEMBER); - nhopgroup->second.nhopgroup_members[nexthop].next_hop_id = nexthop_id; + status = sai_next_hop_group_api->create_next_hop_group_member(&nexthop_id, gSwitchId, + (uint32_t)nhgm_attrs.size(), + nhgm_attrs.data()); + + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR("Failed to add next hop member to group %" PRIx64 ": %d\n", + nhopgroup->second.next_hop_group_id, status); + task_process_status handle_status = handleSaiCreateStatus(SAI_API_NEXT_HOP_GROUP, status); + if (handle_status != task_success) + { + return parseHandleSaiStatusFailure(handle_status); + } + } + + ++count; + gCrmOrch->incCrmResUsedCounter(CrmResourceType::CRM_NEXTHOP_GROUP_MEMBER); + nhopgroup->second.nhopgroup_members[nexthop][j].next_hop_id = nexthop_id; + } } if (!m_fgNhgOrch->validNextHopInNextHopGroup(nexthop)) @@ -471,22 +479,25 @@ bool RouteOrch::invalidnexthopinNextHopGroup(const NextHopKey &nexthop, uint32_t continue; } - nexthop_id = nhopgroup->second.nhopgroup_members[nexthop].next_hop_id; - status = sai_next_hop_group_api->remove_next_hop_group_member(nexthop_id); - - if (status != SAI_STATUS_SUCCESS) + for(size_t j = 0 ; j < nhopgroup->second.nhopgroup_members[nexthop].size(); j++) { - SWSS_LOG_ERROR("Failed to remove next hop member %" PRIx64 " from group %" PRIx64 ": %d\n", - nexthop_id, nhopgroup->second.next_hop_group_id, status); - task_process_status handle_status = handleSaiRemoveStatus(SAI_API_NEXT_HOP_GROUP, status); - if (handle_status != task_success) + nexthop_id = nhopgroup->second.nhopgroup_members[nexthop][j].next_hop_id; + status = sai_next_hop_group_api->remove_next_hop_group_member(nexthop_id); + + if (status != SAI_STATUS_SUCCESS) { - return parseHandleSaiStatusFailure(handle_status); + SWSS_LOG_ERROR("Failed to remove next hop member %" PRIx64 " from group %" PRIx64 ": %d\n", + nexthop_id, nhopgroup->second.next_hop_group_id, status); + task_process_status handle_status = handleSaiRemoveStatus(SAI_API_NEXT_HOP_GROUP, status); + if (handle_status != task_success) + { + return parseHandleSaiStatusFailure(handle_status); + } } - } - ++count; - gCrmOrch->decCrmResUsedCounter(CrmResourceType::CRM_NEXTHOP_GROUP_MEMBER); + ++count; + gCrmOrch->decCrmResUsedCounter(CrmResourceType::CRM_NEXTHOP_GROUP_MEMBER); + } } if (!m_fgNhgOrch->invalidNextHopInNextHopGroup(nexthop)) @@ -1324,7 +1335,7 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) next_hop_ids.push_back(next_hop_id); if (nhopgroup_members_set.find(next_hop_id) == nhopgroup_members_set.end()) { - nhopgroup_members_set[next_hop_id] = it; + nhopgroup_members_set[next_hop_id] = it; } else { @@ -1365,74 +1376,96 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) next_hop_group_entry.next_hop_group_id = next_hop_group_id; size_t npid_count = next_hop_ids.size(); - vector nhgm_ids(npid_count); + size_t weight_gcd = 1; + if(npid_count && nhopgroup_members_set[0].weight) + { + weight_gcd = nhopgroup_members_set[0].weight; + for(size_t i = 1; i < nhopgroup_members_set.size(); i++) + { + weight_gcd = __gcd(weight_gcd, nhopgroup_members_set[i].weight); + if (weight_gcd == 1) + break; + } + } + SWSS_LOG_ERROR("GCD computed: %u\n", weight_gcd); + next_hop_group_entry.weight_gcd = weight_gcd; + + NextHopGroupMembers nhgm_ids; + size_t seq_id = 0; for (size_t i = 0; i < npid_count; i++) { auto nhid = next_hop_ids[i]; - auto weight = nhopgroup_members_set[nhid].weight; + auto weight = nhopgroup_members_set[nhid].weight/weight_gcd; + sai_object_id_t nhgm_id; + SWSS_LOG_ERROR("Weight: %u\n", weight); + for(size_t j = 0; j < weight; j++) + { + // Create a next hop group member + vector nhgm_attrs; - // Create a next hop group member - vector nhgm_attrs; + sai_attribute_t nhgm_attr; + nhgm_attr.id = SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID; + nhgm_attr.value.oid = next_hop_group_id; + nhgm_attrs.push_back(nhgm_attr); - sai_attribute_t nhgm_attr; - nhgm_attr.id = SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID; - nhgm_attr.value.oid = next_hop_group_id; - nhgm_attrs.push_back(nhgm_attr); + nhgm_attr.id = SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID; + nhgm_attr.value.oid = nhid; + nhgm_attrs.push_back(nhgm_attr); - nhgm_attr.id = SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID; - nhgm_attr.value.oid = nhid; - nhgm_attrs.push_back(nhgm_attr); + if (weight) + { + nhgm_attr.id = SAI_NEXT_HOP_GROUP_MEMBER_ATTR_WEIGHT; + nhgm_attr.value.s32 = 1; + nhgm_attrs.push_back(nhgm_attr); + } - if (weight) - { - nhgm_attr.id = SAI_NEXT_HOP_GROUP_MEMBER_ATTR_WEIGHT; - nhgm_attr.value.s32 = weight; - nhgm_attrs.push_back(nhgm_attr); - } + if (m_switchOrch->checkOrderedEcmpEnable()) + { + nhgm_attr.id = SAI_NEXT_HOP_GROUP_MEMBER_ATTR_SEQUENCE_ID; + nhgm_attr.value.u32 = ((uint32_t)seq_id) + 1; // To make non-zero sequence id + nhgm_attrs.push_back(nhgm_attr); + } - if (m_switchOrch->checkOrderedEcmpEnable()) - { - nhgm_attr.id = SAI_NEXT_HOP_GROUP_MEMBER_ATTR_SEQUENCE_ID; - nhgm_attr.value.u32 = ((uint32_t)i) + 1; // To make non-zero sequence id - nhgm_attrs.push_back(nhgm_attr); + gNextHopGroupMemberBulker.create_entry(&nhgm_id, + (uint32_t)nhgm_attrs.size(), + nhgm_attrs.data()); + nhgm_ids[nhid].insert({nhgm_id, seq_id}); } - - gNextHopGroupMemberBulker.create_entry(&nhgm_ids[i], - (uint32_t)nhgm_attrs.size(), - nhgm_attrs.data()); } gNextHopGroupMemberBulker.flush(); for (size_t i = 0; i < npid_count; i++) { auto nhid = next_hop_ids[i]; - auto nhgm_id = nhgm_ids[i]; - if (nhgm_id == SAI_NULL_OBJECT_ID) + for(size_t j = 0; j < nhgm_ids.size(); j++) { - // TODO: do we need to clean up? - SWSS_LOG_ERROR("Failed to create next hop group %" PRIx64 " member %" PRIx64 ": %d\n", - next_hop_group_id, nhgm_ids[i], status); - return false; - } + auto nhgm_id = nhgm_ids[nhid][j].next_hop_id; + auto seq_id = nhgm_ids[nhid][j].seq_id; + if (nhgm_id == SAI_NULL_OBJECT_ID) + { + // TODO: do we need to clean up? + SWSS_LOG_ERROR("Failed to create next hop group %" PRIx64 " member %" PRIx64 ": %d\n", + next_hop_group_id, nhgm_ids[i], status); + return false; + } - gCrmOrch->incCrmResUsedCounter(CrmResourceType::CRM_NEXTHOP_GROUP_MEMBER); + gCrmOrch->incCrmResUsedCounter(CrmResourceType::CRM_NEXTHOP_GROUP_MEMBER); - // Save the membership into next hop structure - if (nhopgroup_shared_set.find(nhid) != nhopgroup_shared_set.end()) - { - auto it = nhopgroup_shared_set[nhid].begin(); - next_hop_group_entry.nhopgroup_members[*it].next_hop_id = nhgm_id; - next_hop_group_entry.nhopgroup_members[*it].seq_id = (uint32_t)i + 1; - nhopgroup_shared_set[nhid].erase(it); - if (nhopgroup_shared_set[nhid].empty()) + // Save the membership into next hop structure + if (nhopgroup_shared_set.find(nhid) != nhopgroup_shared_set.end()) { - nhopgroup_shared_set.erase(nhid); + auto it = nhopgroup_shared_set[nhid].begin(); + next_hop_group_entry.nhopgroup_members[*it].insert({nhgm_id, seq_id}); + nhopgroup_shared_set[nhid].erase(it); + if (nhopgroup_shared_set[nhid].empty()) + { + nhopgroup_shared_set.erase(nhid); + } + } + else + { + next_hop_group_entry.nhopgroup_members[nhopgroup_members_set.find(nhid)->second].insert({nhgm_id, seq_id}); } - } - else - { - next_hop_group_entry.nhopgroup_members[nhopgroup_members_set.find(nhid)->second].next_hop_id = nhgm_id; - next_hop_group_entry.nhopgroup_members[nhopgroup_members_set.find(nhid)->second].seq_id = ((uint32_t)i) + 1; } } @@ -1476,13 +1509,15 @@ bool RouteOrch::removeNextHopGroup(const NextHopGroupKey &nexthops) { if (m_neighOrch->isNextHopFlagSet(nhop->first, NHFLAGS_IFDOWN)) { - SWSS_LOG_WARN("NHFLAGS_IFDOWN set for next hop group member %s with next_hop_id %" PRIx64, - nhop->first.to_string().c_str(), nhop->second.next_hop_id); + for(size_t i =0 ; i < nhop->second.size(); i++) + SWSS_LOG_WARN("NHFLAGS_IFDOWN set for next hop group member %s with next_hop_ids %" PRIx64, + nhop->first.to_string().c_str(), nhop->second[i].next_hop_id); nhop = nhgm.erase(nhop); continue; } - next_hop_ids.push_back(nhop->second.next_hop_id); + for(size_t i =0 ; i < nhop->second.size(); i++) + next_hop_ids.push_back(nhop->second[i].next_hop_id); nhop = nhgm.erase(nhop); } diff --git a/orchagent/routeorch.h b/orchagent/routeorch.h index 577d966a26..9c9ee78cfa 100644 --- a/orchagent/routeorch.h +++ b/orchagent/routeorch.h @@ -28,10 +28,10 @@ struct NextHopGroupMemberEntry { sai_object_id_t next_hop_id; // next hop sai oid - uint32_t seq_id; // Sequence Id of nexthop in the group + uint32_t seq_id; // Sequence Id of nexthop in the group }; -typedef std::map NextHopGroupMembers; +typedef std::map> NextHopGroupMembers; struct NhgBase; @@ -40,6 +40,7 @@ struct NextHopGroupEntry sai_object_id_t next_hop_group_id; // next hop group id int ref_count; // reference count NextHopGroupMembers nhopgroup_members; // ids of members indexed by + int weight_gcd; }; struct NextHopUpdate From a3dde2d204beb65a6dd4bb597e1ddc17983bda82 Mon Sep 17 00:00:00 2001 From: Tejaswini Chadaga <85581939+tjchadaga@users.noreply.github.com> Date: Mon, 2 Dec 2024 23:19:34 +0000 Subject: [PATCH 02/12] Build fix --- orchagent/routeorch.cpp | 22 +++++++++++----------- orchagent/routeorch.h | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/orchagent/routeorch.cpp b/orchagent/routeorch.cpp index c4cb237a7e..93832f0455 100644 --- a/orchagent/routeorch.cpp +++ b/orchagent/routeorch.cpp @@ -403,13 +403,13 @@ bool RouteOrch::validnexthopinNextHopGroup(const NextHopKey &nexthop, uint32_t& /* get updated nhkey with possible weight */ auto nhkey = nhopgroup->first.getNextHops().find(nexthop); - auto entry_count = 1; + size_t member_ratio = 1; if(nhkey->weight) { - entry_count = nhkey->weight/nhopgroup->second.weight_gcd; + member_ratio = nhkey->weight/nhopgroup->second.weight_offset; } - for(size_t j = 0; j < entry_count; j++) + for(size_t j = 0; j < member_ratio; j++) { nhgm_attr.id = SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID; nhgm_attr.value.oid = nhopgroup->second.next_hop_group_id; @@ -1376,26 +1376,26 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) next_hop_group_entry.next_hop_group_id = next_hop_group_id; size_t npid_count = next_hop_ids.size(); - size_t weight_gcd = 1; + int weight_offset = 1; if(npid_count && nhopgroup_members_set[0].weight) { - weight_gcd = nhopgroup_members_set[0].weight; + weight_offset = nhopgroup_members_set[0].weight; for(size_t i = 1; i < nhopgroup_members_set.size(); i++) { - weight_gcd = __gcd(weight_gcd, nhopgroup_members_set[i].weight); - if (weight_gcd == 1) + weight_offset = std::__gcd(weight_offset, nhopgroup_members_set[i].weight); + if (weight_offset == 1) break; } } - SWSS_LOG_ERROR("GCD computed: %u\n", weight_gcd); - next_hop_group_entry.weight_gcd = weight_gcd; + SWSS_LOG_ERROR("GCD computed: %d\n", weight_offset); + next_hop_group_entry.weight_offset = weight_offset; NextHopGroupMembers nhgm_ids; size_t seq_id = 0; for (size_t i = 0; i < npid_count; i++) { auto nhid = next_hop_ids[i]; - auto weight = nhopgroup_members_set[nhid].weight/weight_gcd; + auto weight = nhopgroup_members_set[nhid].weight/weight_offset; sai_object_id_t nhgm_id; SWSS_LOG_ERROR("Weight: %u\n", weight); for(size_t j = 0; j < weight; j++) @@ -1429,7 +1429,7 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) gNextHopGroupMemberBulker.create_entry(&nhgm_id, (uint32_t)nhgm_attrs.size(), nhgm_attrs.data()); - nhgm_ids[nhid].insert({nhgm_id, seq_id}); + nhgm_ids[nhid].insert({nhgm_id, seq_id}); } } diff --git a/orchagent/routeorch.h b/orchagent/routeorch.h index 9c9ee78cfa..490dcaa76c 100644 --- a/orchagent/routeorch.h +++ b/orchagent/routeorch.h @@ -31,7 +31,7 @@ struct NextHopGroupMemberEntry uint32_t seq_id; // Sequence Id of nexthop in the group }; -typedef std::map> NextHopGroupMembers; +typedef std::map> NextHopGroupMembers; struct NhgBase; @@ -40,7 +40,7 @@ struct NextHopGroupEntry sai_object_id_t next_hop_group_id; // next hop group id int ref_count; // reference count NextHopGroupMembers nhopgroup_members; // ids of members indexed by - int weight_gcd; + int weight_offset; }; struct NextHopUpdate From bdbe3cf3d338c2b99b5408928088d520c40be876 Mon Sep 17 00:00:00 2001 From: Tejaswini Chadaga <85581939+tjchadaga@users.noreply.github.com> Date: Tue, 3 Dec 2024 08:37:08 +0000 Subject: [PATCH 03/12] Fixes --- orchagent/routeorch.cpp | 14 ++++++++------ orchagent/routeorch.h | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/orchagent/routeorch.cpp b/orchagent/routeorch.cpp index 93832f0455..0177fdeedf 100644 --- a/orchagent/routeorch.cpp +++ b/orchagent/routeorch.cpp @@ -1376,7 +1376,7 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) next_hop_group_entry.next_hop_group_id = next_hop_group_id; size_t npid_count = next_hop_ids.size(); - int weight_offset = 1; + uint32_t weight_offset = 1; if(npid_count && nhopgroup_members_set[0].weight) { weight_offset = nhopgroup_members_set[0].weight; @@ -1387,10 +1387,10 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) break; } } - SWSS_LOG_ERROR("GCD computed: %d\n", weight_offset); + SWSS_LOG_ERROR("GCD computed: %u\n", weight_offset); next_hop_group_entry.weight_offset = weight_offset; - NextHopGroupMembers nhgm_ids; + std::map> nhgm_ids; size_t seq_id = 0; for (size_t i = 0; i < npid_count; i++) { @@ -1429,7 +1429,8 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) gNextHopGroupMemberBulker.create_entry(&nhgm_id, (uint32_t)nhgm_attrs.size(), nhgm_attrs.data()); - nhgm_ids[nhid].insert({nhgm_id, seq_id}); + NextHopGroupMemberEntry entry = {nhgm_id, seq_id}; + nhgm_ids[nhid].insert(entry); } } @@ -1441,6 +1442,7 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) { auto nhgm_id = nhgm_ids[nhid][j].next_hop_id; auto seq_id = nhgm_ids[nhid][j].seq_id; + NextHopGroupMemberEntry entry = {nhgm_id, seq_id}; if (nhgm_id == SAI_NULL_OBJECT_ID) { // TODO: do we need to clean up? @@ -1455,7 +1457,7 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) if (nhopgroup_shared_set.find(nhid) != nhopgroup_shared_set.end()) { auto it = nhopgroup_shared_set[nhid].begin(); - next_hop_group_entry.nhopgroup_members[*it].insert({nhgm_id, seq_id}); + next_hop_group_entry.nhopgroup_members[*it].insert(entry); nhopgroup_shared_set[nhid].erase(it); if (nhopgroup_shared_set[nhid].empty()) { @@ -1464,7 +1466,7 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) } else { - next_hop_group_entry.nhopgroup_members[nhopgroup_members_set.find(nhid)->second].insert({nhgm_id, seq_id}); + next_hop_group_entry.nhopgroup_members[nhopgroup_members_set.find(nhid)->second].insert(entry); } } } diff --git a/orchagent/routeorch.h b/orchagent/routeorch.h index 490dcaa76c..8eee61fe9c 100644 --- a/orchagent/routeorch.h +++ b/orchagent/routeorch.h @@ -40,7 +40,7 @@ struct NextHopGroupEntry sai_object_id_t next_hop_group_id; // next hop group id int ref_count; // reference count NextHopGroupMembers nhopgroup_members; // ids of members indexed by - int weight_offset; + uint32_t weight_offset; }; struct NextHopUpdate From 8714ac2bd1f9878b43352841c12942759ccdc0fe Mon Sep 17 00:00:00 2001 From: Tejaswini Chadaga <85581939+tjchadaga@users.noreply.github.com> Date: Tue, 3 Dec 2024 19:37:15 +0000 Subject: [PATCH 04/12] Minor fixes --- orchagent/routeorch.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/orchagent/routeorch.cpp b/orchagent/routeorch.cpp index 0177fdeedf..cec147e6d3 100644 --- a/orchagent/routeorch.cpp +++ b/orchagent/routeorch.cpp @@ -1391,7 +1391,7 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) next_hop_group_entry.weight_offset = weight_offset; std::map> nhgm_ids; - size_t seq_id = 0; + uint32_t seq_id = 0; for (size_t i = 0; i < npid_count; i++) { auto nhid = next_hop_ids[i]; @@ -1430,7 +1430,7 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) (uint32_t)nhgm_attrs.size(), nhgm_attrs.data()); NextHopGroupMemberEntry entry = {nhgm_id, seq_id}; - nhgm_ids[nhid].insert(entry); + nhgm_ids[nhid].push_back(entry); } } @@ -1457,7 +1457,7 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) if (nhopgroup_shared_set.find(nhid) != nhopgroup_shared_set.end()) { auto it = nhopgroup_shared_set[nhid].begin(); - next_hop_group_entry.nhopgroup_members[*it].insert(entry); + next_hop_group_entry.nhopgroup_members[*it].push_back(entry); nhopgroup_shared_set[nhid].erase(it); if (nhopgroup_shared_set[nhid].empty()) { @@ -1466,7 +1466,7 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) } else { - next_hop_group_entry.nhopgroup_members[nhopgroup_members_set.find(nhid)->second].insert(entry); + next_hop_group_entry.nhopgroup_members[nhopgroup_members_set.find(nhid)->second].push_back(entry); } } } From 28829a157f80e9230958e50f0c13dca467492442 Mon Sep 17 00:00:00 2001 From: Tejaswini Chadaga <85581939+tjchadaga@users.noreply.github.com> Date: Tue, 3 Dec 2024 22:56:43 +0000 Subject: [PATCH 05/12] Minor fix --- orchagent/routeorch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orchagent/routeorch.cpp b/orchagent/routeorch.cpp index cec147e6d3..02070788a7 100644 --- a/orchagent/routeorch.cpp +++ b/orchagent/routeorch.cpp @@ -1447,7 +1447,7 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) { // TODO: do we need to clean up? SWSS_LOG_ERROR("Failed to create next hop group %" PRIx64 " member %" PRIx64 ": %d\n", - next_hop_group_id, nhgm_ids[i], status); + next_hop_group_id, nhgm_id, status); return false; } From ecbf5d631d93bd60d9da7eda1f5b4e296c9641de Mon Sep 17 00:00:00 2001 From: Tejaswini Chadaga <85581939+tjchadaga@users.noreply.github.com> Date: Thu, 5 Dec 2024 09:29:08 +0000 Subject: [PATCH 06/12] Offset calculation fix --- orchagent/nexthopgroupkey.h | 3 ++- orchagent/routeorch.cpp | 26 ++++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/orchagent/nexthopgroupkey.h b/orchagent/nexthopgroupkey.h index d012cbe41a..e75801268d 100644 --- a/orchagent/nexthopgroupkey.h +++ b/orchagent/nexthopgroupkey.h @@ -49,6 +49,7 @@ class NextHopGroupKey NextHopGroupKey(const std::string &nexthops, const std::string &weights) { + SWSS_LOG_ERROR("Received weights in NextHopGroupKey: %s", weights); m_overlay_nexthops = false; m_srv6_nexthops = false; std::vector nhv = tokenize(nexthops, NHG_DELIMITER); @@ -56,7 +57,7 @@ class NextHopGroupKey bool set_weight = wtv.size() == nhv.size(); for (uint32_t i = 0; i < nhv.size(); i++) { - NextHopKey nh(nhv[i]); + NextHopKey nh(nhv[i]); nh.weight = set_weight? (uint32_t)std::stoi(wtv[i]) : 0; m_nexthops.insert(nh); } diff --git a/orchagent/routeorch.cpp b/orchagent/routeorch.cpp index 02070788a7..8e999d0f31 100644 --- a/orchagent/routeorch.cpp +++ b/orchagent/routeorch.cpp @@ -408,6 +408,7 @@ bool RouteOrch::validnexthopinNextHopGroup(const NextHopKey &nexthop, uint32_t& if(nhkey->weight) { member_ratio = nhkey->weight/nhopgroup->second.weight_offset; + SWSS_LOG_ERROR("Weight %u, offset %u, ratio %u", nhkey->weight, nhopgroup->second.weight_offset, member_ratio); } for(size_t j = 0; j < member_ratio; j++) { @@ -666,9 +667,10 @@ void RouteOrch::doTask(Consumer& consumer) if (fvField(i) == "blackhole") blackhole = fvValue(i) == "true"; - if (fvField(i) == "weight") + if (fvField(i) == "weight") { weights = fvValue(i); - + SWSS_LOG_ERROR("Weight %s received", weights); + } if (fvField(i) == "nexthop_group") nhg_index = fvValue(i); @@ -850,6 +852,7 @@ void RouteOrch::doTask(Consumer& consumer) } nhg = NextHopGroupKey(nhg_str, weights); + SWSS_LOG_ERROR("UCMP: weights: %s", weights); } else { @@ -1302,6 +1305,7 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) set next_hop_set = nexthops.getNextHops(); std::map nhopgroup_members_set; std::map> nhopgroup_shared_set; + vector weights; /* Assert each IP address exists in m_syncdNextHops table, * and add the corresponding next_hop_id to next_hop_ids. */ @@ -1335,7 +1339,12 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) next_hop_ids.push_back(next_hop_id); if (nhopgroup_members_set.find(next_hop_id) == nhopgroup_members_set.end()) { - nhopgroup_members_set[next_hop_id] = it; + nhopgroup_members_set[next_hop_id] = it; + if(nhopgroup_members_set[next_hop_id].weight) + { + weights.push_back(nhopgroup_members_set[next_hop_id].weight); + SWSS_LOG_ERROR("Next hop member weight: %u", nhopgroup_members_set[next_hop_id].weight); + } } else { @@ -1377,17 +1386,18 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) size_t npid_count = next_hop_ids.size(); uint32_t weight_offset = 1; - if(npid_count && nhopgroup_members_set[0].weight) + + if(weights.size() > 0) { - weight_offset = nhopgroup_members_set[0].weight; - for(size_t i = 1; i < nhopgroup_members_set.size(); i++) + weight_offset = weights[0]; + for(size_t i = 1; i < weights.size(); i++) { - weight_offset = std::__gcd(weight_offset, nhopgroup_members_set[i].weight); + weight_offset = std::__gcd(weight_offset, weights[i]); if (weight_offset == 1) break; } } - SWSS_LOG_ERROR("GCD computed: %u\n", weight_offset); + SWSS_LOG_ERROR("Weights size: %u, GCD computed: %u\n", weights.size(), weight_offset); next_hop_group_entry.weight_offset = weight_offset; std::map> nhgm_ids; From b7a13ec06edb09ec3976567dc92cc2040f1e0ee5 Mon Sep 17 00:00:00 2001 From: Tejaswini Chadaga <85581939+tjchadaga@users.noreply.github.com> Date: Fri, 6 Dec 2024 00:47:42 +0000 Subject: [PATCH 07/12] Bug fix --- orchagent/nexthopgroupkey.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orchagent/nexthopgroupkey.h b/orchagent/nexthopgroupkey.h index e75801268d..8f0916b666 100644 --- a/orchagent/nexthopgroupkey.h +++ b/orchagent/nexthopgroupkey.h @@ -49,7 +49,7 @@ class NextHopGroupKey NextHopGroupKey(const std::string &nexthops, const std::string &weights) { - SWSS_LOG_ERROR("Received weights in NextHopGroupKey: %s", weights); + SWSS_LOG_ERROR("Received weights in NextHopGroupKey: %s", weights.c_str()); m_overlay_nexthops = false; m_srv6_nexthops = false; std::vector nhv = tokenize(nexthops, NHG_DELIMITER); From 86c24bc0f5611747c2d634389fed5c7f194effe9 Mon Sep 17 00:00:00 2001 From: Tejaswini Chadaga <85581939+tjchadaga@users.noreply.github.com> Date: Fri, 6 Dec 2024 08:49:56 +0000 Subject: [PATCH 08/12] . --- orchagent/routeorch.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/orchagent/routeorch.cpp b/orchagent/routeorch.cpp index 8e999d0f31..a7436720ca 100644 --- a/orchagent/routeorch.cpp +++ b/orchagent/routeorch.cpp @@ -408,7 +408,7 @@ bool RouteOrch::validnexthopinNextHopGroup(const NextHopKey &nexthop, uint32_t& if(nhkey->weight) { member_ratio = nhkey->weight/nhopgroup->second.weight_offset; - SWSS_LOG_ERROR("Weight %u, offset %u, ratio %u", nhkey->weight, nhopgroup->second.weight_offset, member_ratio); + SWSS_LOG_ERROR("Weight %u, offset %u, ratio %lu", nhkey->weight, nhopgroup->second.weight_offset, member_ratio); } for(size_t j = 0; j < member_ratio; j++) { @@ -669,7 +669,7 @@ void RouteOrch::doTask(Consumer& consumer) if (fvField(i) == "weight") { weights = fvValue(i); - SWSS_LOG_ERROR("Weight %s received", weights); + SWSS_LOG_ERROR("Weight %s received", weights.c_str()); } if (fvField(i) == "nexthop_group") nhg_index = fvValue(i); @@ -852,7 +852,7 @@ void RouteOrch::doTask(Consumer& consumer) } nhg = NextHopGroupKey(nhg_str, weights); - SWSS_LOG_ERROR("UCMP: weights: %s", weights); + SWSS_LOG_ERROR("UCMP: weights: %s", weights.c_str()); } else { @@ -1397,7 +1397,7 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) break; } } - SWSS_LOG_ERROR("Weights size: %u, GCD computed: %u\n", weights.size(), weight_offset); + SWSS_LOG_ERROR("Weights size: %lu, GCD computed: %u\n", weights.size(), weight_offset); next_hop_group_entry.weight_offset = weight_offset; std::map> nhgm_ids; @@ -1817,7 +1817,7 @@ bool RouteOrch::addRoute(RouteBulkContext& ctx, const NextHopGroupKey &nextHops) auto it_route = m_syncdRoutes.at(vrf_id).find(ipPrefix); - if (m_fgNhgOrch->isRouteFineGrained(vrf_id, ipPrefix, nextHops)) + if (m_fg NhgOrch->isRouteFineGrained(vrf_id, ipPrefix, nextHops)) { /* The route is pointing to a Fine Grained nexthop group */ curNhgIsFineGrained = true; From 95e108b1e9b55c3e200ecda3c538be69cb9c1e2a Mon Sep 17 00:00:00 2001 From: Tejaswini Chadaga <85581939+tjchadaga@users.noreply.github.com> Date: Fri, 6 Dec 2024 18:29:37 +0000 Subject: [PATCH 09/12] typo fix --- orchagent/routeorch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orchagent/routeorch.cpp b/orchagent/routeorch.cpp index a7436720ca..16e1400848 100644 --- a/orchagent/routeorch.cpp +++ b/orchagent/routeorch.cpp @@ -1817,7 +1817,7 @@ bool RouteOrch::addRoute(RouteBulkContext& ctx, const NextHopGroupKey &nextHops) auto it_route = m_syncdRoutes.at(vrf_id).find(ipPrefix); - if (m_fg NhgOrch->isRouteFineGrained(vrf_id, ipPrefix, nextHops)) + if (m_fgNhgOrch->isRouteFineGrained(vrf_id, ipPrefix, nextHops)) NhgOrch->isRouteFineGrained(vrf_id, ipPrefix, nextHops)) { /* The route is pointing to a Fine Grained nexthop group */ curNhgIsFineGrained = true; From 3e0a6a11d069e5f9356ef7b719108204606f6b82 Mon Sep 17 00:00:00 2001 From: Tejaswini Chadaga <85581939+tjchadaga@users.noreply.github.com> Date: Fri, 6 Dec 2024 21:10:27 +0000 Subject: [PATCH 10/12] Typo fix --- orchagent/routeorch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orchagent/routeorch.cpp b/orchagent/routeorch.cpp index 16e1400848..029053f7d9 100644 --- a/orchagent/routeorch.cpp +++ b/orchagent/routeorch.cpp @@ -1817,7 +1817,7 @@ bool RouteOrch::addRoute(RouteBulkContext& ctx, const NextHopGroupKey &nextHops) auto it_route = m_syncdRoutes.at(vrf_id).find(ipPrefix); - if (m_fgNhgOrch->isRouteFineGrained(vrf_id, ipPrefix, nextHops)) NhgOrch->isRouteFineGrained(vrf_id, ipPrefix, nextHops)) + if (m_fgNhgOrch->isRouteFineGrained(vrf_id, ipPrefix, nextHops)) { /* The route is pointing to a Fine Grained nexthop group */ curNhgIsFineGrained = true; From bb3187cc276ec08049a2ff90c0463797fce5d00b Mon Sep 17 00:00:00 2001 From: Tejaswini Chadaga <85581939+tjchadaga@users.noreply.github.com> Date: Tue, 10 Dec 2024 01:02:39 +0000 Subject: [PATCH 11/12] Fix looping --- orchagent/routeorch.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/orchagent/routeorch.cpp b/orchagent/routeorch.cpp index 029053f7d9..6673b973b6 100644 --- a/orchagent/routeorch.cpp +++ b/orchagent/routeorch.cpp @@ -669,7 +669,10 @@ void RouteOrch::doTask(Consumer& consumer) if (fvField(i) == "weight") { weights = fvValue(i); - SWSS_LOG_ERROR("Weight %s received", weights.c_str()); + if(!weights.empty()) + { + SWSS_LOG_ERROR("Weight %s received", weights.c_str()); + } } if (fvField(i) == "nexthop_group") nhg_index = fvValue(i); @@ -852,7 +855,10 @@ void RouteOrch::doTask(Consumer& consumer) } nhg = NextHopGroupKey(nhg_str, weights); - SWSS_LOG_ERROR("UCMP: weights: %s", weights.c_str()); + if(!weights.empty()) + { + SWSS_LOG_ERROR("UCMP: weights: %s", weights.c_str()); + } } else { @@ -1440,15 +1446,16 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) (uint32_t)nhgm_attrs.size(), nhgm_attrs.data()); NextHopGroupMemberEntry entry = {nhgm_id, seq_id}; - nhgm_ids[nhid].push_back(entry); + nhgm_ids[nhid].push_back(entry); } } gNextHopGroupMemberBulker.flush(); + for (size_t i = 0; i < npid_count; i++) { auto nhid = next_hop_ids[i]; - for(size_t j = 0; j < nhgm_ids.size(); j++) + for(size_t j = 0; j < nhgm_ids[nhid].size(); j++) { auto nhgm_id = nhgm_ids[nhid][j].next_hop_id; auto seq_id = nhgm_ids[nhid][j].seq_id; From 2d680a7f784cdc0f5bdde5280b77eeee2d3acdcb Mon Sep 17 00:00:00 2001 From: Tejaswini Chadaga <85581939+tjchadaga@users.noreply.github.com> Date: Wed, 18 Dec 2024 09:09:29 +0000 Subject: [PATCH 12/12] Weight offset --- orchagent/routeorch.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/orchagent/routeorch.cpp b/orchagent/routeorch.cpp index 6673b973b6..f300b8de82 100644 --- a/orchagent/routeorch.cpp +++ b/orchagent/routeorch.cpp @@ -1348,7 +1348,7 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) nhopgroup_members_set[next_hop_id] = it; if(nhopgroup_members_set[next_hop_id].weight) { - weights.push_back(nhopgroup_members_set[next_hop_id].weight); + weights.push_back(nhopgroup_members_set[next_hop_id].weight + 1); SWSS_LOG_ERROR("Next hop member weight: %u", nhopgroup_members_set[next_hop_id].weight); } } @@ -1403,7 +1403,7 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) break; } } - SWSS_LOG_ERROR("Weights size: %lu, GCD computed: %u\n", weights.size(), weight_offset); + SWSS_LOG_ERROR("Nexthops size: %lu, Weights size: %lu, GCD computed: %u\n", npid_count, weights.size(), weight_offset); next_hop_group_entry.weight_offset = weight_offset; std::map> nhgm_ids; @@ -1411,7 +1411,7 @@ bool RouteOrch::addNextHopGroup(const NextHopGroupKey &nexthops) for (size_t i = 0; i < npid_count; i++) { auto nhid = next_hop_ids[i]; - auto weight = nhopgroup_members_set[nhid].weight/weight_offset; + auto weight = (nhopgroup_members_set[nhid].weight + 1)/weight_offset; sai_object_id_t nhgm_id; SWSS_LOG_ERROR("Weight: %u\n", weight); for(size_t j = 0; j < weight; j++)