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 5 commits
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
1 change: 1 addition & 0 deletions doc/swss-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ and reflects the LAG ports into the redis under: `LAG_TABLE:<team0>:port`
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
vpn_sid = string ; ipv6 address for SRV6 VPN sid

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

Expand Down
14 changes: 13 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,8 @@ class NextHopGroupKey
{
m_overlay_nexthops = false;
m_srv6_nexthops = true;
m_srv6_vpn = srv6_vpn;

auto nhv = tokenize(nexthops, NHG_DELIMITER);
for (const auto &nh_str : nhv)
{
Expand All @@ -47,10 +51,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 Down Expand Up @@ -221,6 +227,11 @@ class NextHopGroupKey
return m_srv6_nexthops;
}

inline bool is_srv6_vpn() const
{
return m_srv6_vpn;
}

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

#endif /* SWSS_NEXTHOPGROUPKEY_H */
66 changes: 51 additions & 15 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_source(""),
srv6_segment(""),
srv6_vpn_sid("")
{}
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_source(""),
srv6_segment(""),
srv6_vpn_sid("")
{
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_source(""),
srv6_segment(""),
srv6_vpn_sid("")
{}
NextHopKey(const std::string &str) :
vni(0), mac_address()
vni(0), mac_address(),
srv6_source(""),
srv6_segment(""),
srv6_vpn_sid("")
{
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_source = keys[2];
srv6_source = keys[1];
srv6_segment = keys[2];
srv6_vpn_sid = 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_source = "";
srv6_segment = "";
srv6_vpn_sid = "";
}
}

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_source(""),
srv6_segment(""),
srv6_vpn_sid("")
{}

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_source + NH_DELIMITER +
srv6_segment + NH_DELIMITER +
srv6_vpn_sid + 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