Skip to content

Commit

Permalink
[SRV6] Sonic-swss changes for SRV6 (#1964)
Browse files Browse the repository at this point in the history
*RouteOrch changes to trigger SRV6 nexthops and update route entries
*SRV6Orch changes to create SRV6 nexthops, tunnel and SRV6 MY_SID_ENTRY objects
  • Loading branch information
Kumaresh Perumal authored Nov 11, 2021
1 parent f502c32 commit 37c197d
Show file tree
Hide file tree
Showing 18 changed files with 1,357 additions and 47 deletions.
17 changes: 17 additions & 0 deletions doc/swss-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ and reflects the LAG ports into the redis under: `LAG_TABLE:<team0>:port`
blackhole = BIT ; Set to 1 if this route is a blackhole (or null0)
weight = weight_list ; List of weights.
nexthop_group = string ; index within the NEXTHOP_GROUP_TABLE, used instead of nexthop and intf fields
segment = string ; SRV6 segment name
seg_src = string ; ipv6 address for SRV6 tunnel source

---------------------------------------------

Expand Down Expand Up @@ -203,6 +205,21 @@ and reflects the LAG ports into the redis under: `LAG_TABLE:<team0>:port`
neigh = 12HEXDIG ; mac address of the neighbor
family = "IPv4" / "IPv6" ; address family

---------------------------------------------
### SRV6_SID_LIST_TABLE
; Stores IPV6 prefixes for a SRV6 segment name
key = ROUTE_TABLE:segment ; SRV6 segment name
; field = value
path = STRING ; Comma-separated list of IPV6 prefixes for a SRV6 segment

---------------------------------------------
### SRV6_MY_SID_TABLE
; Stores SRV6 MY_SID table entries and associated actions
key = STRING ; SRV6 MY_SID prefix string
; field = value
action = STRING ; MY_SID actions like "end", "end.dt46"
vrf = STRING ; VRF string for END.DT46 or END.DT4 or END.DT6

---------------------------------------------
### FDB_TABLE

Expand Down
3 changes: 2 additions & 1 deletion orchagent/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ orchagent_SOURCES = \
muxorch.cpp \
macsecorch.cpp \
lagid.cpp \
bfdorch.cpp
bfdorch.cpp \
srv6orch.cpp

orchagent_SOURCES += flex_counter/flex_counter_manager.cpp flex_counter/flex_counter_stat_manager.cpp
orchagent_SOURCES += debug_counter/debug_counter.cpp debug_counter/drop_counter.cpp
Expand Down
70 changes: 70 additions & 0 deletions orchagent/crmorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const map<CrmResourceType, string> crmResTypeNameMap =
{ CrmResourceType::CRM_DNAT_ENTRY, "DNAT_ENTRY" },
{ CrmResourceType::CRM_MPLS_INSEG, "MPLS_INSEG" },
{ CrmResourceType::CRM_MPLS_NEXTHOP, "MPLS_NEXTHOP" },
{ CrmResourceType::CRM_SRV6_MY_SID_ENTRY, "SRV6_MY_SID_ENTRY" },
{ CrmResourceType::CRM_SRV6_NEXTHOP, "SRV6_NEXTHOP" },
};

const map<CrmResourceType, uint32_t> crmResSaiAvailAttrMap =
Expand All @@ -65,6 +67,8 @@ const map<CrmResourceType, uint32_t> crmResSaiAvailAttrMap =
{ CrmResourceType::CRM_DNAT_ENTRY, SAI_SWITCH_ATTR_AVAILABLE_DNAT_ENTRY },
{ CrmResourceType::CRM_MPLS_INSEG, SAI_OBJECT_TYPE_INSEG_ENTRY },
{ CrmResourceType::CRM_MPLS_NEXTHOP, SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY },
{ CrmResourceType::CRM_SRV6_MY_SID_ENTRY, SAI_OBJECT_TYPE_MY_SID_ENTRY },
{ CrmResourceType::CRM_SRV6_NEXTHOP, SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY },
};

const map<string, CrmResourceType> crmThreshTypeResMap =
Expand All @@ -87,6 +91,8 @@ const map<string, CrmResourceType> crmThreshTypeResMap =
{ "dnat_entry_threshold_type", CrmResourceType::CRM_DNAT_ENTRY },
{ "mpls_inseg_threshold_type", CrmResourceType::CRM_MPLS_INSEG },
{ "mpls_nexthop_threshold_type", CrmResourceType::CRM_MPLS_NEXTHOP },
{ "srv6_my_sid_entry_threshold_type", CrmResourceType::CRM_SRV6_MY_SID_ENTRY },
{ "srv6_nexthop_threshold_type", CrmResourceType::CRM_SRV6_NEXTHOP },
};

const map<string, CrmResourceType> crmThreshLowResMap =
Expand All @@ -109,6 +115,8 @@ const map<string, CrmResourceType> crmThreshLowResMap =
{"dnat_entry_low_threshold", CrmResourceType::CRM_DNAT_ENTRY },
{"mpls_inseg_low_threshold", CrmResourceType::CRM_MPLS_INSEG },
{"mpls_nexthop_low_threshold", CrmResourceType::CRM_MPLS_NEXTHOP },
{"srv6_my_sid_entry_low_threshold", CrmResourceType::CRM_SRV6_MY_SID_ENTRY },
{"srv6_nexthop_low_threshold", CrmResourceType::CRM_SRV6_NEXTHOP },
};

const map<string, CrmResourceType> crmThreshHighResMap =
Expand All @@ -131,6 +139,8 @@ const map<string, CrmResourceType> crmThreshHighResMap =
{"dnat_entry_high_threshold", CrmResourceType::CRM_DNAT_ENTRY },
{"mpls_inseg_high_threshold", CrmResourceType::CRM_MPLS_INSEG },
{"mpls_nexthop_high_threshold", CrmResourceType::CRM_MPLS_NEXTHOP },
{"srv6_my_sid_entry_high_threshold", CrmResourceType::CRM_SRV6_MY_SID_ENTRY },
{"srv6_nexthop_high_threshold", CrmResourceType::CRM_SRV6_NEXTHOP },
};

const map<string, CrmThresholdType> crmThreshTypeMap =
Expand Down Expand Up @@ -160,6 +170,8 @@ const map<string, CrmResourceType> crmAvailCntsTableMap =
{ "crm_stats_dnat_entry_available", CrmResourceType::CRM_DNAT_ENTRY },
{ "crm_stats_mpls_inseg_available", CrmResourceType::CRM_MPLS_INSEG },
{ "crm_stats_mpls_nexthop_available", CrmResourceType::CRM_MPLS_NEXTHOP },
{ "crm_stats_srv6_my_sid_entry_available", CrmResourceType::CRM_SRV6_MY_SID_ENTRY },
{ "crm_stats_srv6_nexthop_available", CrmResourceType::CRM_SRV6_NEXTHOP },
};

const map<string, CrmResourceType> crmUsedCntsTableMap =
Expand All @@ -182,6 +194,8 @@ const map<string, CrmResourceType> crmUsedCntsTableMap =
{ "crm_stats_dnat_entry_used", CrmResourceType::CRM_DNAT_ENTRY },
{ "crm_stats_mpls_inseg_used", CrmResourceType::CRM_MPLS_INSEG },
{ "crm_stats_mpls_nexthop_used", CrmResourceType::CRM_MPLS_NEXTHOP },
{ "crm_stats_srv6_my_sid_entry_used", CrmResourceType::CRM_SRV6_MY_SID_ENTRY },
{ "crm_stats_srv6_nexthop_used", CrmResourceType::CRM_SRV6_NEXTHOP },
};

CrmOrch::CrmOrch(DBConnector *db, string tableName):
Expand Down Expand Up @@ -614,6 +628,62 @@ void CrmOrch::getResAvailableCounters()
break;
}

case CrmResourceType::CRM_SRV6_MY_SID_ENTRY:
{
sai_object_type_t objType = static_cast<sai_object_type_t>(crmResSaiAvailAttrMap.at(res.first));
uint64_t availCount = 0;
sai_status_t status = sai_object_type_get_availability(gSwitchId, objType, 0, nullptr, &availCount);
if (status != SAI_STATUS_SUCCESS)
{
if ((status == SAI_STATUS_NOT_SUPPORTED) ||
(status == SAI_STATUS_NOT_IMPLEMENTED) ||
SAI_STATUS_IS_ATTR_NOT_SUPPORTED(status) ||
SAI_STATUS_IS_ATTR_NOT_IMPLEMENTED(status))
{
// mark unsupported resources
res.second.resStatus = CrmResourceStatus::CRM_RES_NOT_SUPPORTED;
SWSS_LOG_NOTICE("CRM Resource %s not supported", crmResTypeNameMap.at(res.first).c_str());
break;
}
SWSS_LOG_ERROR("Failed to get availability for object_type %u , rv:%d", objType, status);
break;
}

res.second.countersMap[CRM_COUNTERS_TABLE_KEY].availableCounter = static_cast<uint32_t>(availCount);

break;
}

case CrmResourceType::CRM_SRV6_NEXTHOP:
{
sai_object_type_t objType = static_cast<sai_object_type_t>(crmResSaiAvailAttrMap.at(res.first));
sai_attribute_t attr;
uint64_t availCount = 0;

attr.id = SAI_NEXT_HOP_ATTR_TYPE;
attr.value.s32 = SAI_NEXT_HOP_TYPE_SRV6_SIDLIST;
sai_status_t status = sai_object_type_get_availability(gSwitchId, objType, 1, &attr, &availCount);
if (status != SAI_STATUS_SUCCESS)
{
if ((status == SAI_STATUS_NOT_SUPPORTED) ||
(status == SAI_STATUS_NOT_IMPLEMENTED) ||
SAI_STATUS_IS_ATTR_NOT_SUPPORTED(status) ||
SAI_STATUS_IS_ATTR_NOT_IMPLEMENTED(status))
{
// mark unsupported resources
res.second.resStatus = CrmResourceStatus::CRM_RES_NOT_SUPPORTED;
SWSS_LOG_NOTICE("CRM Resource %s not supported", crmResTypeNameMap.at(res.first).c_str());
break;
}
SWSS_LOG_ERROR("Failed to get availability for object_type %u , rv:%d", objType, status);
break;
}

res.second.countersMap[CRM_COUNTERS_TABLE_KEY].availableCounter = static_cast<uint32_t>(availCount);

break;
}

default:
SWSS_LOG_ERROR("Failed to get CRM resource type %u. Unknown resource type.\n", static_cast<uint32_t>(res.first));
return;
Expand Down
2 changes: 2 additions & 0 deletions orchagent/crmorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ enum class CrmResourceType
CRM_DNAT_ENTRY,
CRM_MPLS_INSEG,
CRM_MPLS_NEXTHOP,
CRM_SRV6_MY_SID_ENTRY,
CRM_SRV6_NEXTHOP,
};

enum class CrmThresholdType
Expand Down
19 changes: 19 additions & 0 deletions orchagent/neighorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1702,3 +1702,22 @@ bool NeighOrch::updateVoqNeighborEncapIndex(const NeighborEntry &neighborEntry,

return true;
}

void NeighOrch::updateSrv6Nexthop(const NextHopKey &nh, const sai_object_id_t &nh_id)
{
if (nh_id != SAI_NULL_OBJECT_ID)
{
NextHopEntry next_hop_entry;
next_hop_entry.next_hop_id = nh_id;
next_hop_entry.ref_count = 0;
next_hop_entry.nh_flags = 0;
m_syncdNextHops[nh] = next_hop_entry;
gCrmOrch->incCrmResUsedCounter(CrmResourceType::CRM_SRV6_NEXTHOP);
}
else
{
assert(m_syncdNextHops[nh].ref_count == 0);
gCrmOrch->decCrmResUsedCounter(CrmResourceType::CRM_SRV6_NEXTHOP);
m_syncdNextHops.erase(nh);
}
}
1 change: 1 addition & 0 deletions orchagent/neighorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class NeighOrch : public Orch, public Subject, public Observer
bool delInbandNeighbor(string alias, IpAddress ip_address);

void resolveNeighbor(const NeighborEntry &);
void updateSrv6Nexthop(const NextHopKey &, const sai_object_id_t &);

private:
PortsOrch *m_portsOrch;
Expand Down
39 changes: 31 additions & 8 deletions orchagent/nexthopgroupkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class NextHopGroupKey
NextHopGroupKey(const std::string &nexthops)
{
m_overlay_nexthops = false;
m_srv6_nexthops = false;
auto nhv = tokenize(nexthops, NHG_DELIMITER);
for (const auto &nh : nhv)
{
Expand All @@ -20,20 +21,36 @@ class NextHopGroupKey
}

/* ip_string|if_alias|vni|router_mac separated by ',' */
NextHopGroupKey(const std::string &nexthops, bool overlay_nh)
NextHopGroupKey(const std::string &nexthops, bool overlay_nh, bool srv6_nh)
{
m_overlay_nexthops = true;
auto nhv = tokenize(nexthops, NHG_DELIMITER);
for (const auto &nh_str : nhv)
if (overlay_nh)
{
auto nh = NextHopKey(nh_str, overlay_nh);
m_nexthops.insert(nh);
m_overlay_nexthops = true;
m_srv6_nexthops = false;
auto nhv = tokenize(nexthops, NHG_DELIMITER);
for (const auto &nh_str : nhv)
{
auto nh = NextHopKey(nh_str, overlay_nh, srv6_nh);
m_nexthops.insert(nh);
}
}
else if (srv6_nh)
{
m_overlay_nexthops = false;
m_srv6_nexthops = true;
auto nhv = tokenize(nexthops, NHG_DELIMITER);
for (const auto &nh_str : nhv)
{
auto nh = NextHopKey(nh_str, overlay_nh, srv6_nh);
m_nexthops.insert(nh);
}
}
}

NextHopGroupKey(const std::string &nexthops, const std::string &weights)
{
m_overlay_nexthops = false;
m_srv6_nexthops = false;
std::vector<std::string> nhv = tokenize(nexthops, NHG_DELIMITER);
std::vector<std::string> wtv = tokenize(weights, NHG_DELIMITER);
bool set_weight = wtv.size() == nhv.size();
Expand Down Expand Up @@ -184,8 +201,8 @@ class NextHopGroupKey
{
nhs_str += NHG_DELIMITER;
}
if (m_overlay_nexthops) {
nhs_str += it->to_string(m_overlay_nexthops);
if (m_overlay_nexthops || m_srv6_nexthops) {
nhs_str += it->to_string(m_overlay_nexthops, m_srv6_nexthops);
} else {
nhs_str += it->to_string();
}
Expand All @@ -199,6 +216,11 @@ class NextHopGroupKey
return m_overlay_nexthops;
}

inline bool is_srv6_nexthop() const
{
return m_srv6_nexthops;
}

void clear()
{
m_nexthops.clear();
Expand All @@ -207,6 +229,7 @@ class NextHopGroupKey
private:
std::set<NextHopKey> m_nexthops;
bool m_overlay_nexthops;
bool m_srv6_nexthops;
};

#endif /* SWSS_NEXTHOPGROUPKEY_H */
Loading

0 comments on commit 37c197d

Please sign in to comment.