Skip to content

Commit da104eb

Browse files
committed
updates for MPLS
1 parent c25844e commit da104eb

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

cfgmgr/intfmgr.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@ void IntfMgr::setIntfVrf(const string &alias, const string &vrfName)
114114
}
115115
}
116116

117+
void IntfMgr::setIntfMpls(const string &alias, bool enable)
118+
{
119+
stringstream cmd;
120+
string res;
121+
122+
cmd << "sysctl -w net.mpls.conf." << alias << ".input=" << (enable ? "1":"0");
123+
int ret = swss::exec(cmd.str(), res);
124+
if (ret)
125+
{
126+
SWSS_LOG_ERROR("Command '%s' failed with rc %d", cmd.str().c_str(), ret);
127+
}
128+
}
129+
117130
void IntfMgr::addLoopbackIntf(const string &alias)
118131
{
119132
stringstream cmd;
@@ -524,6 +537,7 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
524537
data.push_back(fvTuple);
525538
}
526539
/* Set mpls */
540+
setIntfMpls(alias, (mpls == "enable"));
527541
if (!mpls.empty())
528542
{
529543
FieldValueTuple fvTuple("mpls", mpls);

cfgmgr/intfmgr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class IntfMgr : public Orch
2727
std::set<std::string> m_pendingReplayIntfList;
2828

2929
void setIntfIp(const std::string &alias, const std::string &opCmd, const IpPrefix &ipPrefix);
30+
void setIntfMpls(const std::string &alias, bool enable);
3031
void setIntfVrf(const std::string &alias, const std::string &vrfName);
3132
void setIntfMac(const std::string &alias, const std::string &macAddr);
3233

orchagent/nexthopkey.h

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "tokenize.h"
66
#include "label.h"
77

8+
#define LABELSTACK_DELIMITER '+'
89
#define NH_DELIMITER '@'
910
#define NHG_DELIMITER ','
1011
#define VRF_PREFIX "Vrf"
@@ -19,7 +20,21 @@ struct NextHopKey
1920
LabelStack label_stack; // MPLS label stack
2021

2122
NextHopKey() = default;
22-
NextHopKey(const std::string &ipstr, const std::string &alias) : ip_address(ipstr), alias(alias), vni(0), mac_address() {}
23+
NextHopKey(const std::string &str, const std::string &alias) : alias(alias), vni(0), mac_address()
24+
{
25+
std::size_t label_delimiter = str.find(LABELSTACK_DELIMITER);
26+
std::string ip_str;
27+
if (label_delimiter != std::string::npos)
28+
{
29+
label_stack = LabelStack(str.substr(0, label_delimiter));
30+
ip_str = str.substr(label_delimiter+1);
31+
}
32+
else
33+
{
34+
ip_str = str;
35+
}
36+
ip_address = ip_str;
37+
}
2338
NextHopKey(const IpAddress &ip, const std::string &alias) : ip_address(ip), alias(alias), vni(0), mac_address() {}
2439
NextHopKey(const std::string &str)
2540
{
@@ -28,7 +43,7 @@ struct NextHopKey
2843
std::string err = "Error converting " + str + " to NextHop";
2944
throw std::invalid_argument(err);
3045
}
31-
std::size_t label_delimiter = str.find(LABEL_DELIMITER);
46+
std::size_t label_delimiter = str.find(LABELSTACK_DELIMITER);
3247
std::string ip_str;
3348
if (label_delimiter != std::string::npos)
3449
{
@@ -69,7 +84,7 @@ struct NextHopKey
6984
std::string err = "Error converting " + str + " to NextHop";
7085
throw std::invalid_argument(err);
7186
}
72-
std::size_t label_delimiter = str.find(LABEL_DELIMITER);
87+
std::size_t label_delimiter = str.find(LABELSTACK_DELIMITER);
7388
std::string ip_str;
7489
if (label_delimiter != std::string::npos)
7590
{
@@ -98,7 +113,7 @@ struct NextHopKey
98113
if (!label_stack.empty())
99114
{
100115
str += label_stack.to_string();
101-
str += LABEL_DELIMITER;
116+
str += LABELSTACK_DELIMITER;
102117
}
103118
str += ip_address.to_string() + NH_DELIMITER + alias;
104119
return str;
@@ -110,7 +125,7 @@ struct NextHopKey
110125
if (!label_stack.empty())
111126
{
112127
str += label_stack.to_string();
113-
str += LABEL_DELIMITER;
128+
str += LABELSTACK_DELIMITER;
114129
}
115130
str += (ip_address.to_string() + NH_DELIMITER + alias + NH_DELIMITER +
116131
std::to_string(vni) + NH_DELIMITER + mac_address.to_string());
@@ -119,12 +134,14 @@ struct NextHopKey
119134

120135
bool operator<(const NextHopKey &o) const
121136
{
122-
return tie(ip_address, alias, vni, mac_address) < tie(o.ip_address, o.alias, o.vni, o.mac_address);
137+
return tie(label_stack, ip_address, alias, vni, mac_address) <
138+
tie(o.label_stack, o.ip_address, o.alias, o.vni, o.mac_address);
123139
}
124140

125141
bool operator==(const NextHopKey &o) const
126142
{
127-
return (ip_address == o.ip_address) && (alias == o.alias) && (vni == o.vni) && (mac_address == o.mac_address);
143+
return (label_stack == o.label_stack) && (ip_address == o.ip_address) &&
144+
(alias == o.alias) && (vni == o.vni) && (mac_address == o.mac_address);
128145
}
129146

130147
bool operator!=(const NextHopKey &o) const

orchagent/routeorch.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ void RouteOrch::doPrefixTask(Consumer& consumer)
636636
nhg = NextHopGroupKey(nhg_str, overlay_nh);
637637
}
638638

639-
if (ipv.size() == 1 && IpAddress(ipv[0]).isZero())
639+
if (ipv.size() == 1 && NextHopKey(ipv[0]).ip_address.isZero())
640640
{
641641
/* blackhole to be done */
642642
if (alsv[0] == "unknown")
@@ -750,7 +750,7 @@ void RouteOrch::doPrefixTask(Consumer& consumer)
750750

751751
const NextHopGroupKey& nhg = ctx.nhg;
752752

753-
if (ipv.size() == 1 && IpAddress(ipv[0]).isZero())
753+
if (ipv.size() == 1 && NextHopKey(ipv[0]).ip_address.isZero())
754754
{
755755
if (addRoutePost(ctx, nhg))
756756
it_prev = consumer.m_toSync.erase(it_prev);
@@ -2366,7 +2366,7 @@ void RouteOrch::doLabelTask(Consumer& consumer)
23662366

23672367
const NextHopGroupKey& nhg = ctx.nhg;
23682368

2369-
if (ipv.size() == 1 && IpAddress(ipv[0]).isZero())
2369+
if (ipv.size() == 1 && NextHopKey(ipv[0]).ip_address.isZero())
23702370
{
23712371
if (addLabelRoutePost(ctx, nhg))
23722372
it_prev = consumer.m_toSync.erase(it_prev);

0 commit comments

Comments
 (0)