Skip to content

Commit 8c5b903

Browse files
committed
address the review comments
1 parent 8808707 commit 8c5b903

4 files changed

Lines changed: 33 additions & 93 deletions

File tree

orchagent/nexthopgroupkey.h

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -54,41 +54,6 @@ class NextHopGroupKey
5454
}
5555
}
5656

57-
NextHopGroupKey(const std::string &nexthops, bool overlay_nh, bool srv6_nh, const std::string& weights)
58-
{
59-
auto nhv = tokenize(nexthops, NHG_DELIMITER);
60-
auto wtv = tokenize(weights, NHG_DELIMITER);
61-
bool set_weight = wtv.size() == nhv.size();
62-
if (overlay_nh)
63-
{
64-
m_overlay_nexthops = true;
65-
m_srv6_nexthops = false;
66-
m_srv6_vpn = false;
67-
for (uint32_t i = 0; i < nhv.size(); ++i)
68-
{
69-
auto nh = NextHopKey(nhv[i], overlay_nh, srv6_nh);
70-
nh.weight = set_weight ? (uint32_t)std::stoi(wtv[i]) : 0;
71-
m_nexthops.insert(nh);
72-
}
73-
}
74-
else if (srv6_nh)
75-
{
76-
m_overlay_nexthops = false;
77-
m_srv6_nexthops = true;
78-
m_srv6_vpn = false;
79-
for (uint32_t i = 0; i < nhv.size(); ++i)
80-
{
81-
auto nh = NextHopKey(nhv[i], overlay_nh, srv6_nh);
82-
nh.weight = set_weight ? (uint32_t)std::stoi(wtv[i]) : 0;
83-
m_nexthops.insert(nh);
84-
if (nh.isSrv6Vpn())
85-
{
86-
m_srv6_vpn = true;
87-
}
88-
}
89-
}
90-
}
91-
9257
NextHopGroupKey(const std::string &nexthops, const std::string &weights)
9358
{
9459
m_overlay_nexthops = false;
@@ -105,16 +70,6 @@ class NextHopGroupKey
10570
}
10671
}
10772

108-
inline bool is_srv6_nexthop() const
109-
{
110-
return m_srv6_nexthops;
111-
}
112-
113-
inline bool is_srv6_vpn() const
114-
{
115-
return m_srv6_vpn;
116-
}
117-
11873
inline const std::set<NextHopKey> &getNextHops() const
11974
{
12075
return m_nexthops;
@@ -269,6 +224,16 @@ class NextHopGroupKey
269224
return m_overlay_nexthops;
270225
}
271226

227+
inline bool is_srv6_nexthop() const
228+
{
229+
return m_srv6_nexthops;
230+
}
231+
232+
inline bool is_srv6_vpn() const
233+
{
234+
return m_srv6_vpn;
235+
}
236+
272237
void clear()
273238
{
274239
m_nexthops.clear();

orchagent/nexthopkey.h

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,17 @@ struct NextHopKey
2424
string srv6_source; // SRV6 source address
2525
string srv6_vpn_sid; // SRV6 vpn sid
2626

27-
NextHopKey() :
28-
weight(0),
29-
srv6_vpn_sid(""),
30-
srv6_source(""),
31-
srv6_segment("")
32-
{}
27+
NextHopKey() : weight(0) {}
3328
NextHopKey(const std::string &str, const std::string &alias) :
34-
alias(alias), vni(0), mac_address(), weight(0),
35-
srv6_vpn_sid(""),
36-
srv6_source(""),
37-
srv6_segment("")
29+
alias(alias), vni(0), mac_address(), weight(0)
3830
{
3931
std::string ip_str = parseMplsNextHop(str);
4032
ip_address = ip_str;
4133
}
4234
NextHopKey(const IpAddress &ip, const std::string &alias) :
43-
ip_address(ip), alias(alias), vni(0), mac_address(), weight(0),
44-
srv6_vpn_sid(""),
45-
srv6_source(""),
46-
srv6_segment("")
47-
{}
35+
ip_address(ip), alias(alias), vni(0), mac_address(), weight(0) {}
4836
NextHopKey(const std::string &str) :
49-
vni(0), mac_address(),
50-
srv6_vpn_sid(""),
51-
srv6_source(""),
52-
srv6_segment("")
37+
vni(0), mac_address()
5338
{
5439
if (str.find(NHG_DELIMITER) != string::npos)
5540
{
@@ -98,9 +83,9 @@ struct NextHopKey
9883
throw std::invalid_argument(err);
9984
}
10085
ip_address = keys[0];
101-
srv6_vpn_sid = keys[1];
86+
srv6_segment = keys[1];
10287
srv6_source = keys[2];
103-
srv6_segment = keys[3];
88+
srv6_vpn_sid = keys[3];
10489
}
10590
else
10691
{
@@ -116,18 +101,10 @@ struct NextHopKey
116101
vni = static_cast<uint32_t>(std::stoul(keys[2]));
117102
mac_address = keys[3];
118103
weight = 0;
119-
srv6_vpn_sid = "";
120-
srv6_source = "";
121-
srv6_segment = "";
122104
}
123105
}
124106

125-
NextHopKey(const IpAddress &ip, const MacAddress &mac, const uint32_t &vni, bool overlay_nh) :
126-
ip_address(ip), alias(""), vni(vni), mac_address(mac), weight(0),
127-
srv6_vpn_sid(""),
128-
srv6_source(""),
129-
srv6_segment("")
130-
{}
107+
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){}
131108

132109
const std::string to_string() const
133110
{
@@ -140,10 +117,8 @@ struct NextHopKey
140117
{
141118
if (srv6_nh)
142119
{
143-
return ip_address.to_string() + NH_DELIMITER +
144-
srv6_vpn_sid + NH_DELIMITER +
145-
srv6_source + NH_DELIMITER +
146-
srv6_segment + NH_DELIMITER;
120+
return ip_address.to_string() + NH_DELIMITER + srv6_segment + NH_DELIMITER + srv6_source
121+
+ NH_DELIMITER + srv6_vpn_sid;
147122
}
148123
std::string str = formatMplsNextHop();
149124
str += (ip_address.to_string() + NH_DELIMITER + alias + NH_DELIMITER +
@@ -181,6 +156,16 @@ struct NextHopKey
181156
return (!label_stack.empty());
182157
}
183158

159+
bool isSrv6NextHop() const
160+
{
161+
return ((srv6_segment != "") || (srv6_vpn_sid != "") || (srv6_source != ""));
162+
}
163+
164+
bool isSrv6Vpn() const
165+
{
166+
return (srv6_vpn_sid != "");
167+
}
168+
184169
std::string parseMplsNextHop(const std::string& str)
185170
{
186171
// parseMplsNextHop initializes MPLS-related member data of the NextHopKey
@@ -221,16 +206,6 @@ struct NextHopKey
221206
}
222207
return str;
223208
}
224-
225-
bool isSrv6NextHop() const
226-
{
227-
return ((srv6_segment != "") || (srv6_vpn_sid != "") || (srv6_source != ""));
228-
}
229-
230-
bool isSrv6Vpn() const
231-
{
232-
return (srv6_vpn_sid != "");
233-
}
234209
};
235210

236211
#endif /* SWSS_NEXTHOPKEY_H */

orchagent/nhgorch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void NhgOrch::doTask(Consumer& consumer)
199199
}
200200

201201
if (srv6_nh)
202-
nhg_key = NextHopGroupKey(nhg_str, overlay_nh, srv6_nh, weights);
202+
nhg_key = NextHopGroupKey(nhg_str, overlay_nh, srv6_nh);
203203
else
204204
nhg_key = NextHopGroupKey(nhg_str, weights);
205205
}
@@ -221,7 +221,7 @@ void NhgOrch::doTask(Consumer& consumer)
221221
nhg_str += srv6_srcv[i] + NH_DELIMITER; // srv6 source
222222
nhg_str += NH_DELIMITER; // srv6 segment
223223
}
224-
nhg_key = NextHopGroupKey(nhg_str, overlay_nh, srv6_nh, weights);
224+
nhg_key = NextHopGroupKey(nhg_str, overlay_nh, srv6_nh);
225225
}
226226
else
227227
{

orchagent/routeorch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,9 +849,9 @@ void RouteOrch::doTask(Consumer& consumer)
849849
{
850850
if (i) nhg_str += NHG_DELIMITER;
851851
nhg_str += ipv[i] + NH_DELIMITER; // ip address
852-
nhg_str += (srv6_vpn ? srv6_vpn_sidv[i] : "") + NH_DELIMITER; // srv6 vpn sid
853-
nhg_str += srv6_src[i] + NH_DELIMITER; // srv6 source
854852
nhg_str += (srv6_seg ? srv6_segv[i] : "") + NH_DELIMITER; // srv6 segment
853+
nhg_str += srv6_src[i] + NH_DELIMITER; // srv6 source
854+
nhg_str += (srv6_vpn ? srv6_vpn_sidv[i] : "") + NH_DELIMITER; // srv6 vpn sid
855855
}
856856

857857
nhg = NextHopGroupKey(nhg_str, overlay_nh, srv6_nh);

0 commit comments

Comments
 (0)