Skip to content

Commit

Permalink
address the review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shuaishang committed Nov 20, 2024
1 parent 8808707 commit 8c5b903
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 93 deletions.
55 changes: 10 additions & 45 deletions orchagent/nexthopgroupkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,41 +54,6 @@ class NextHopGroupKey
}
}

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;
}
}
}
}

NextHopGroupKey(const std::string &nexthops, const std::string &weights)
{
m_overlay_nexthops = false;
Expand All @@ -105,16 +70,6 @@ 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 @@ -269,6 +224,16 @@ class NextHopGroupKey
return m_overlay_nexthops;
}

inline bool is_srv6_nexthop() const
{
return m_srv6_nexthops;
}

inline bool is_srv6_vpn() const
{
return m_srv6_vpn;
}

void clear()
{
m_nexthops.clear();
Expand Down
63 changes: 19 additions & 44 deletions orchagent/nexthopkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,17 @@ struct NextHopKey
string srv6_source; // SRV6 source address
string srv6_vpn_sid; // SRV6 vpn sid

NextHopKey() :
weight(0),
srv6_vpn_sid(""),
srv6_source(""),
srv6_segment("")
{}
NextHopKey() : weight(0) {}
NextHopKey(const std::string &str, const std::string &alias) :
alias(alias), vni(0), mac_address(), weight(0),
srv6_vpn_sid(""),
srv6_source(""),
srv6_segment("")
alias(alias), vni(0), mac_address(), weight(0)
{
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),
srv6_vpn_sid(""),
srv6_source(""),
srv6_segment("")
{}
ip_address(ip), alias(alias), vni(0), mac_address(), weight(0) {}
NextHopKey(const std::string &str) :
vni(0), mac_address(),
srv6_vpn_sid(""),
srv6_source(""),
srv6_segment("")
vni(0), mac_address()
{
if (str.find(NHG_DELIMITER) != string::npos)
{
Expand Down Expand Up @@ -98,9 +83,9 @@ struct NextHopKey
throw std::invalid_argument(err);
}
ip_address = keys[0];
srv6_vpn_sid = keys[1];
srv6_segment = keys[1];
srv6_source = keys[2];
srv6_segment = keys[3];
srv6_vpn_sid = keys[3];
}
else
{
Expand All @@ -116,18 +101,10 @@ 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),
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){}

const std::string to_string() const
{
Expand All @@ -140,10 +117,8 @@ struct NextHopKey
{
if (srv6_nh)
{
return ip_address.to_string() + NH_DELIMITER +
srv6_vpn_sid + NH_DELIMITER +
srv6_source + NH_DELIMITER +
srv6_segment + NH_DELIMITER;
return ip_address.to_string() + NH_DELIMITER + srv6_segment + NH_DELIMITER + srv6_source
+ NH_DELIMITER + srv6_vpn_sid;
}
std::string str = formatMplsNextHop();
str += (ip_address.to_string() + NH_DELIMITER + alias + NH_DELIMITER +
Expand Down Expand Up @@ -181,6 +156,16 @@ struct NextHopKey
return (!label_stack.empty());
}

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

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

std::string parseMplsNextHop(const std::string& str)
{
// parseMplsNextHop initializes MPLS-related member data of the NextHopKey
Expand Down Expand Up @@ -221,16 +206,6 @@ 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 */
4 changes: 2 additions & 2 deletions orchagent/nhgorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void NhgOrch::doTask(Consumer& consumer)
}

if (srv6_nh)
nhg_key = NextHopGroupKey(nhg_str, overlay_nh, srv6_nh, weights);
nhg_key = NextHopGroupKey(nhg_str, overlay_nh, srv6_nh);
else
nhg_key = NextHopGroupKey(nhg_str, weights);
}
Expand All @@ -221,7 +221,7 @@ void NhgOrch::doTask(Consumer& consumer)
nhg_str += srv6_srcv[i] + NH_DELIMITER; // srv6 source
nhg_str += NH_DELIMITER; // srv6 segment
}
nhg_key = NextHopGroupKey(nhg_str, overlay_nh, srv6_nh, weights);
nhg_key = NextHopGroupKey(nhg_str, overlay_nh, srv6_nh);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions orchagent/routeorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,9 +849,9 @@ void RouteOrch::doTask(Consumer& consumer)
{
if (i) nhg_str += NHG_DELIMITER;
nhg_str += ipv[i] + NH_DELIMITER; // ip address
nhg_str += (srv6_vpn ? srv6_vpn_sidv[i] : "") + NH_DELIMITER; // srv6 vpn sid
nhg_str += srv6_src[i] + NH_DELIMITER; // srv6 source
nhg_str += (srv6_seg ? srv6_segv[i] : "") + NH_DELIMITER; // srv6 segment
nhg_str += srv6_src[i] + NH_DELIMITER; // srv6 source
nhg_str += (srv6_vpn ? srv6_vpn_sidv[i] : "") + NH_DELIMITER; // srv6 vpn sid
}

nhg = NextHopGroupKey(nhg_str, overlay_nh, srv6_nh);
Expand Down

0 comments on commit 8c5b903

Please sign in to comment.