Skip to content

Commit

Permalink
updates for MPLS
Browse files Browse the repository at this point in the history
  • Loading branch information
qbdwlr committed Apr 20, 2021
1 parent c25844e commit da104eb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
14 changes: 14 additions & 0 deletions cfgmgr/intfmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ void IntfMgr::setIntfVrf(const string &alias, const string &vrfName)
}
}

void IntfMgr::setIntfMpls(const string &alias, bool enable)
{
stringstream cmd;
string res;

cmd << "sysctl -w net.mpls.conf." << alias << ".input=" << (enable ? "1":"0");
int ret = swss::exec(cmd.str(), res);
if (ret)
{
SWSS_LOG_ERROR("Command '%s' failed with rc %d", cmd.str().c_str(), ret);
}
}

void IntfMgr::addLoopbackIntf(const string &alias)
{
stringstream cmd;
Expand Down Expand Up @@ -524,6 +537,7 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
data.push_back(fvTuple);
}
/* Set mpls */
setIntfMpls(alias, (mpls == "enable"));
if (!mpls.empty())
{
FieldValueTuple fvTuple("mpls", mpls);
Expand Down
1 change: 1 addition & 0 deletions cfgmgr/intfmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class IntfMgr : public Orch
std::set<std::string> m_pendingReplayIntfList;

void setIntfIp(const std::string &alias, const std::string &opCmd, const IpPrefix &ipPrefix);
void setIntfMpls(const std::string &alias, bool enable);
void setIntfVrf(const std::string &alias, const std::string &vrfName);
void setIntfMac(const std::string &alias, const std::string &macAddr);

Expand Down
31 changes: 24 additions & 7 deletions orchagent/nexthopkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "tokenize.h"
#include "label.h"

#define LABELSTACK_DELIMITER '+'
#define NH_DELIMITER '@'
#define NHG_DELIMITER ','
#define VRF_PREFIX "Vrf"
Expand All @@ -19,7 +20,21 @@ struct NextHopKey
LabelStack label_stack; // MPLS label stack

NextHopKey() = default;
NextHopKey(const std::string &ipstr, const std::string &alias) : ip_address(ipstr), alias(alias), vni(0), mac_address() {}
NextHopKey(const std::string &str, const std::string &alias) : alias(alias), vni(0), mac_address()
{
std::size_t label_delimiter = str.find(LABELSTACK_DELIMITER);
std::string ip_str;
if (label_delimiter != std::string::npos)
{
label_stack = LabelStack(str.substr(0, label_delimiter));
ip_str = str.substr(label_delimiter+1);
}
else
{
ip_str = str;
}
ip_address = ip_str;
}
NextHopKey(const IpAddress &ip, const std::string &alias) : ip_address(ip), alias(alias), vni(0), mac_address() {}
NextHopKey(const std::string &str)
{
Expand All @@ -28,7 +43,7 @@ struct NextHopKey
std::string err = "Error converting " + str + " to NextHop";
throw std::invalid_argument(err);
}
std::size_t label_delimiter = str.find(LABEL_DELIMITER);
std::size_t label_delimiter = str.find(LABELSTACK_DELIMITER);
std::string ip_str;
if (label_delimiter != std::string::npos)
{
Expand Down Expand Up @@ -69,7 +84,7 @@ struct NextHopKey
std::string err = "Error converting " + str + " to NextHop";
throw std::invalid_argument(err);
}
std::size_t label_delimiter = str.find(LABEL_DELIMITER);
std::size_t label_delimiter = str.find(LABELSTACK_DELIMITER);
std::string ip_str;
if (label_delimiter != std::string::npos)
{
Expand Down Expand Up @@ -98,7 +113,7 @@ struct NextHopKey
if (!label_stack.empty())
{
str += label_stack.to_string();
str += LABEL_DELIMITER;
str += LABELSTACK_DELIMITER;
}
str += ip_address.to_string() + NH_DELIMITER + alias;
return str;
Expand All @@ -110,7 +125,7 @@ struct NextHopKey
if (!label_stack.empty())
{
str += label_stack.to_string();
str += LABEL_DELIMITER;
str += LABELSTACK_DELIMITER;
}
str += (ip_address.to_string() + NH_DELIMITER + alias + NH_DELIMITER +
std::to_string(vni) + NH_DELIMITER + mac_address.to_string());
Expand All @@ -119,12 +134,14 @@ struct NextHopKey

bool operator<(const NextHopKey &o) const
{
return tie(ip_address, alias, vni, mac_address) < tie(o.ip_address, o.alias, o.vni, o.mac_address);
return tie(label_stack, ip_address, alias, vni, mac_address) <
tie(o.label_stack, o.ip_address, o.alias, o.vni, o.mac_address);
}

bool operator==(const NextHopKey &o) const
{
return (ip_address == o.ip_address) && (alias == o.alias) && (vni == o.vni) && (mac_address == o.mac_address);
return (label_stack == o.label_stack) && (ip_address == o.ip_address) &&
(alias == o.alias) && (vni == o.vni) && (mac_address == o.mac_address);
}

bool operator!=(const NextHopKey &o) const
Expand Down
6 changes: 3 additions & 3 deletions orchagent/routeorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ void RouteOrch::doPrefixTask(Consumer& consumer)
nhg = NextHopGroupKey(nhg_str, overlay_nh);
}

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

const NextHopGroupKey& nhg = ctx.nhg;

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

const NextHopGroupKey& nhg = ctx.nhg;

if (ipv.size() == 1 && IpAddress(ipv[0]).isZero())
if (ipv.size() == 1 && NextHopKey(ipv[0]).ip_address.isZero())
{
if (addLabelRoutePost(ctx, nhg))
it_prev = consumer.m_toSync.erase(it_prev);
Expand Down

0 comments on commit da104eb

Please sign in to comment.