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] Add support for SRv6 VPN #3293

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 54 additions & 5 deletions 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 @@ -27,6 +28,7 @@ class NextHopGroupKey
{
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,11 +40,51 @@ class NextHopGroupKey
{
m_overlay_nexthops = false;
m_srv6_nexthops = true;
m_srv6_vpn = 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);
if (nh.isSrv6Vpn())
{
m_srv6_vpn = true;
}
}
}
}

NextHopGroupKey(const std::string &nexthops, bool overlay_nh, bool srv6_nh, const std::string& weights)
{
auto nhv = tokenize(nexthops, NHG_DELIMITER);
auto wtv = tokenize(weights, NHG_DELIMITER);
bool set_weight = wtv.size() == nhv.size();
if (overlay_nh)
{
m_overlay_nexthops = true;
m_srv6_nexthops = false;
m_srv6_vpn = false;
for (uint32_t i = 0; i < nhv.size(); ++i)
{
auto nh = NextHopKey(nhv[i], overlay_nh, srv6_nh);
nh.weight = set_weight ? (uint32_t)std::stoi(wtv[i]) : 0;
m_nexthops.insert(nh);
}
}
else if (srv6_nh)
{
m_overlay_nexthops = false;
m_srv6_nexthops = true;
m_srv6_vpn = false;
for (uint32_t i = 0; i < nhv.size(); ++i)
{
auto nh = NextHopKey(nhv[i], overlay_nh, srv6_nh);
nh.weight = set_weight ? (uint32_t)std::stoi(wtv[i]) : 0;
m_nexthops.insert(nh);
if (nh.isSrv6Vpn())
{
m_srv6_vpn = true;
}
}
}
}
Expand All @@ -51,6 +93,7 @@ class NextHopGroupKey
{
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 @@ -62,6 +105,16 @@ class NextHopGroupKey
}
}

inline bool is_srv6_nexthop() const
{
return m_srv6_nexthops;
}

inline bool is_srv6_vpn() const
{
return m_srv6_vpn;
}

inline const std::set<NextHopKey> &getNextHops() const
{
return m_nexthops;
Expand Down Expand Up @@ -216,11 +269,6 @@ class NextHopGroupKey
return m_overlay_nexthops;
}

inline bool is_srv6_nexthop() const
{
return m_srv6_nexthops;
}

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

#endif /* SWSS_NEXTHOPGROUPKEY_H */
68 changes: 51 additions & 17 deletions orchagent/nexthopkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,34 @@ struct NextHopKey
uint32_t weight; // NH weight for NHGs
string srv6_segment; // SRV6 segment string
string srv6_source; // SRV6 source address

NextHopKey() : weight(0) {}
string srv6_vpn_sid; // SRV6 vpn sid

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(""),
srv6_source(""),
srv6_segment("")
{
if (str.find(NHG_DELIMITER) != string::npos)
{
Expand Down Expand Up @@ -76,14 +92,15 @@ struct NextHopKey
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 +116,18 @@ 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 @@ -115,7 +140,10 @@ struct NextHopKey
{
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 +153,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 @@ -152,11 +181,6 @@ struct NextHopKey
return (!label_stack.empty());
}

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

std::string parseMplsNextHop(const std::string& str)
{
// parseMplsNextHop initializes MPLS-related member data of the NextHopKey
Expand Down Expand Up @@ -197,6 +221,16 @@ struct NextHopKey
}
return str;
}

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

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

#endif /* SWSS_NEXTHOPKEY_H */
Loading
Loading