Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SRv6]: SRv6 VPN SID #2793

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 30 additions & 1 deletion orchagent/nexthopgroupkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class NextHopGroupKey
{
m_overlay_nexthops = false;
m_srv6_nexthops = false;
m_srv6_vpn = false;
auto nhv = tokenize(nexthops, NHG_DELIMITER);
for (const auto &nh : nhv)
{
Expand All @@ -21,12 +22,13 @@ class NextHopGroupKey
}

/* ip_string|if_alias|vni|router_mac separated by ',' */
NextHopGroupKey(const std::string &nexthops, bool overlay_nh, bool srv6_nh = false)
NextHopGroupKey(const std::string &nexthops, bool overlay_nh, bool srv6_nh = false, bool srv6_vpn = false)
{
if (overlay_nh)
{
m_overlay_nexthops = true;
m_srv6_nexthops = false;
m_srv6_vpn = false;
auto nhv = tokenize(nexthops, NHG_DELIMITER);
for (const auto &nh_str : nhv)
{
Expand All @@ -38,6 +40,9 @@ class NextHopGroupKey
{
m_overlay_nexthops = false;
m_srv6_nexthops = true;
m_srv6_vpn = srv6_vpn;
m_srv6_str = nexthops;

auto nhv = tokenize(nexthops, NHG_DELIMITER);
for (const auto &nh_str : nhv)
{
Expand All @@ -47,10 +52,12 @@ class NextHopGroupKey
}
}


NextHopGroupKey(const std::string &nexthops, const std::string &weights)
{
m_overlay_nexthops = false;
m_srv6_nexthops = false;
m_srv6_vpn = 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 All @@ -74,6 +81,11 @@ class NextHopGroupKey

inline bool operator<(const NextHopGroupKey &o) const
{
if (m_srv6_nexthops)
{
return m_srv6_str < o.m_srv6_str;
}

if (m_nexthops < o.m_nexthops)
{
return true;
Expand Down Expand Up @@ -193,6 +205,9 @@ class NextHopGroupKey

const std::string to_string() const
{
if (m_srv6_nexthops) {
return m_srv6_str;
}
string nhs_str;

for (auto it = m_nexthops.begin(); it != m_nexthops.end(); ++it)
Expand Down Expand Up @@ -221,6 +236,17 @@ class NextHopGroupKey
return m_srv6_nexthops;
}

inline bool is_srv6_vpn() const
{
return m_srv6_vpn;
}

inline string get_srv6_vpn_key() const
{
// use nexthopgroupkey as vpn key
return m_srv6_str;
}

void clear()
{
m_nexthops.clear();
Expand All @@ -230,6 +256,9 @@ class NextHopGroupKey
std::set<NextHopKey> m_nexthops;
bool m_overlay_nexthops;
bool m_srv6_nexthops;

string m_srv6_str;
bool m_srv6_vpn;
};

#endif /* SWSS_NEXTHOPGROUPKEY_H */
64 changes: 50 additions & 14 deletions orchagent/nexthopkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,33 @@ struct NextHopKey
uint32_t weight; // NH weight for NHGs
string srv6_segment; // SRV6 segment string
string srv6_source; // SRV6 source address
string srv6_vpn_sid; // SRV6 vpn sid

NextHopKey() : weight(0) {}
NextHopKey() : weight(0),
srv6_vpn_sid(""),
srv6_source(""),
srv6_segment("")
{}
NextHopKey(const std::string &str, const std::string &alias) :
alias(alias), vni(0), mac_address(), weight(0)
alias(alias), vni(0), mac_address(), weight(0),
srv6_vpn_sid(""),
srv6_source(""),
srv6_segment("")
{
std::string ip_str = parseMplsNextHop(str);
ip_address = ip_str;
}
NextHopKey(const IpAddress &ip, const std::string &alias) :
ip_address(ip), alias(alias), vni(0), mac_address(), weight(0) {}
ip_address(ip), alias(alias), vni(0), mac_address(), weight(0),
srv6_vpn_sid(""),
srv6_source(""),
srv6_segment("")
{}
NextHopKey(const std::string &str) :
vni(0), mac_address()
vni(0), mac_address(),
srv6_vpn_sid(""),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move the vpn_sid to the end of NH key without affecting the non-VPN NH key?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will not affect non-VPN NH key, however I moved srv6_vpn_sid to end of NH key.

srv6_source(""),
srv6_segment("")
{
if (str.find(NHG_DELIMITER) != string::npos)
{
Expand Down Expand Up @@ -74,16 +89,16 @@ struct NextHopKey
{
weight = 0;
vni = 0;
weight = 0;
auto keys = tokenize(str, NH_DELIMITER);
if (keys.size() != 3)
if (keys.size() != 4)
{
std::string err = "Error converting " + str + " to Nexthop";
throw std::invalid_argument(err);
}
ip_address = keys[0];
srv6_segment = keys[1];
srv6_vpn_sid = keys[1];
srv6_source = keys[2];
srv6_segment = keys[3];
}
else
{
Expand All @@ -99,10 +114,22 @@ struct NextHopKey
vni = static_cast<uint32_t>(std::stoul(keys[2]));
mac_address = keys[3];
weight = 0;
srv6_vpn_sid = "";
srv6_source = "";
srv6_segment = "";
}
}

NextHopKey(const IpAddress &ip, const MacAddress &mac, const uint32_t &vni, bool overlay_nh) : ip_address(ip), alias(""), vni(vni), mac_address(mac), weight(0){}
NextHopKey(const IpAddress &ip, const MacAddress &mac, const uint32_t &vni, bool overlay_nh) :
ip_address(ip),
alias(""),
vni(vni),
mac_address(mac),
weight(0),
srv6_vpn_sid(""),
srv6_source(""),
srv6_segment("")
{}

const std::string to_string() const
{
Expand All @@ -111,11 +138,14 @@ struct NextHopKey
return str;
}

const std::string to_string(bool overlay_nh, bool srv6_nh) const
const std::string to_string(bool overlay_nh, bool srv6_nh = false) const
{
if (srv6_nh)
{
return ip_address.to_string() + NH_DELIMITER + srv6_segment + NH_DELIMITER + srv6_source;
return ip_address.to_string() + NH_DELIMITER +
srv6_vpn_sid + NH_DELIMITER +
srv6_source + NH_DELIMITER +
srv6_segment + NH_DELIMITER;
}
std::string str = formatMplsNextHop();
str += (ip_address.to_string() + NH_DELIMITER + alias + NH_DELIMITER +
Expand All @@ -125,16 +155,17 @@ struct NextHopKey

bool operator<(const NextHopKey &o) const
{
return tie(ip_address, alias, label_stack, vni, mac_address, srv6_segment, srv6_source) <
tie(o.ip_address, o.alias, o.label_stack, o.vni, o.mac_address, o.srv6_segment, o.srv6_source);
return tie(ip_address, alias, label_stack, vni, mac_address, srv6_segment, srv6_source, srv6_vpn_sid) <
tie(o.ip_address, o.alias, o.label_stack, o.vni, o.mac_address, o.srv6_segment, o.srv6_source, o.srv6_vpn_sid);
}

bool operator==(const NextHopKey &o) const
{
return (ip_address == o.ip_address) && (alias == o.alias) &&
(label_stack == o.label_stack) &&
(vni == o.vni) && (mac_address == o.mac_address) &&
(srv6_segment == o.srv6_segment) && (srv6_source == o.srv6_source);
(srv6_segment == o.srv6_segment) && (srv6_source == o.srv6_source) &&
(srv6_vpn_sid == o.srv6_vpn_sid);
}

bool operator!=(const NextHopKey &o) const
Expand All @@ -154,7 +185,12 @@ struct NextHopKey

bool isSrv6NextHop() const
{
return (srv6_segment != "");
return ((srv6_segment != "") || (srv6_vpn_sid != ""));
}

bool isSrv6Vpn() const
{
return (srv6_vpn_sid != "");
}

std::string parseMplsNextHop(const std::string& str)
Expand Down