Skip to content

Commit

Permalink
sonic-swss updates for MPLS
Browse files Browse the repository at this point in the history
  • Loading branch information
qbdwlr committed May 21, 2021
1 parent 73ffd5f commit ebb723f
Show file tree
Hide file tree
Showing 21 changed files with 2,119 additions and 206 deletions.
44 changes: 44 additions & 0 deletions cfgmgr/intfmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,34 @@ void IntfMgr::setIntfVrf(const string &alias, const string &vrfName)
}
}

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

if (mpls == "enable")
{
cmd << "sysctl -w net.mpls.conf." << alias << ".input=1";
}
else if ((mpls == "disable") || mpls.empty())
{
cmd << "sysctl -w net.mpls.conf." << alias << ".input=0";
}
else
{
SWSS_LOG_ERROR("MPLS state is invalid: \"%s\"", mpls.c_str());
return false;
}
int ret = swss::exec(cmd.str(), res);
// Don't return error unless MPLS is explicitly set
if (ret && !mpls.empty())
{
SWSS_LOG_ERROR("Command '%s' failed with rc %d", cmd.str().c_str(), ret);
return false;
}
return true;
}

void IntfMgr::addLoopbackIntf(const string &alias)
{
stringstream cmd;
Expand Down Expand Up @@ -447,6 +475,7 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
string nat_zone = "";
string proxy_arp = "";
string grat_arp = "";
string mpls = "";

for (auto idx : data)
{
Expand All @@ -473,6 +502,10 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
{
grat_arp = value;
}
else if (field == "mpls")
{
mpls = value;
}

if (field == "nat_zone")
{
Expand Down Expand Up @@ -518,6 +551,17 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
FieldValueTuple fvTuple("nat_zone", nat_zone);
data.push_back(fvTuple);
}
/* Set mpls */
if (!setIntfMpls(alias, mpls))
{
SWSS_LOG_ERROR("Failed to set MPLS to \"%s\" for the \"%s\" interface", mpls.c_str(), alias.c_str());
return false;
}
if (!mpls.empty())
{
FieldValueTuple fvTuple("mpls", mpls);
data.push_back(fvTuple);
}
}

if (!vrf_name.empty())
Expand Down
1 change: 1 addition & 0 deletions cfgmgr/intfmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class IntfMgr : public Orch
void setIntfIp(const std::string &alias, const std::string &opCmd, const IpPrefix &ipPrefix);
void setIntfVrf(const std::string &alias, const std::string &vrfName);
void setIntfMac(const std::string &alias, const std::string &macAddr);
bool setIntfMpls(const std::string &alias, const std::string &mpls);

bool doIntfGeneralTask(const std::vector<std::string>& keys, std::vector<FieldValueTuple> data, const std::string& op);
bool doIntfAddrTask(const std::vector<std::string>& keys, const std::vector<FieldValueTuple>& data, const std::string& op);
Expand Down
72 changes: 67 additions & 5 deletions fpmsyncd/fpmsyncd.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <getopt.h>
#include <iostream>
#include <inttypes.h>
#include "logger.h"
Expand All @@ -7,6 +8,7 @@
#include "warmRestartHelper.h"
#include "fpmsyncd/fpmlink.h"
#include "fpmsyncd/routesync.h"
#include "netlink.h"


using namespace std;
Expand Down Expand Up @@ -44,6 +46,13 @@ static bool eoiuFlagsSet(Table &bgpStateTable)
return true;
}

static void usage()
{
cout << "Usage: fpmsyncd [ -l ( fpm | net) ]" << endl;
cout << " fpm = FpmLink (default)" << endl;
cout << " net = NetLink" << endl;
}

int main(int argc, char **argv)
{
swss::Logger::linkToDbNative("fpmsyncd");
Expand All @@ -57,11 +66,45 @@ int main(int argc, char **argv)
NetDispatcher::getInstance().registerMessageHandler(RTM_NEWROUTE, &sync);
NetDispatcher::getInstance().registerMessageHandler(RTM_DELROUTE, &sync);

bool useFpmLink = true;
int opt;
while ((opt = getopt(argc, argv, "l:h")) != -1 )
{
switch (opt)
{
case 'l':
{
string linkmode(optarg);
if (linkmode == "net")
{
useFpmLink = false;
}
else if (linkmode == "fpm")
{
useFpmLink = true;
}
else
{
usage();
return EXIT_FAILURE;
}
break;
}

case 'h':
usage();
return 1;

default: /* '?' */
usage();
return EXIT_FAILURE;
}
}

while (true)
{
try
{
FpmLink fpm(&sync);
Select s;
SelectableTimer warmStartTimer(timespec{0, 0});
// Before eoiu flags detected, check them periodically. It also stop upon detection of reconciliation done.
Expand All @@ -75,11 +118,30 @@ int main(int argc, char **argv)
*/
pipeline.flush();

cout << "Waiting for fpm-client connection..." << endl;
fpm.accept();
cout << "Connected!" << endl;
shared_ptr<Selectable> link;
if (useFpmLink)
{
shared_ptr<FpmLink> fpm = make_shared<FpmLink>(&sync);

cout << "Waiting for fpm-client connection..." << endl;
fpm->accept();
cout << "Connected!" << endl;

s.addSelectable(&fpm);
link = fpm;
}
else
{
shared_ptr<NetLink> netlink = make_shared<NetLink>();

netlink->registerGroup(RTNLGRP_IPV4_ROUTE);
netlink->registerGroup(RTNLGRP_IPV6_ROUTE);
netlink->registerGroup(RTNLGRP_MPLS_ROUTE);
cout << "NetLink listening for route messages..." << endl;
netlink->dumpRequest(RTM_GETROUTE);

link = netlink;
}
s.addSelectable(link.get());

/* If warm-restart feature is enabled, execute 'restoration' logic */
bool warmStartEnabled = sync.m_warmStartHelper.checkAndStart();
Expand Down
Loading

0 comments on commit ebb723f

Please sign in to comment.