Skip to content

Commit ebb723f

Browse files
committed
sonic-swss updates for MPLS
1 parent 73ffd5f commit ebb723f

21 files changed

+2119
-206
lines changed

cfgmgr/intfmgr.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,34 @@ void IntfMgr::setIntfVrf(const string &alias, const string &vrfName)
114114
}
115115
}
116116

117+
bool IntfMgr::setIntfMpls(const string &alias, const string& mpls)
118+
{
119+
stringstream cmd;
120+
string res;
121+
122+
if (mpls == "enable")
123+
{
124+
cmd << "sysctl -w net.mpls.conf." << alias << ".input=1";
125+
}
126+
else if ((mpls == "disable") || mpls.empty())
127+
{
128+
cmd << "sysctl -w net.mpls.conf." << alias << ".input=0";
129+
}
130+
else
131+
{
132+
SWSS_LOG_ERROR("MPLS state is invalid: \"%s\"", mpls.c_str());
133+
return false;
134+
}
135+
int ret = swss::exec(cmd.str(), res);
136+
// Don't return error unless MPLS is explicitly set
137+
if (ret && !mpls.empty())
138+
{
139+
SWSS_LOG_ERROR("Command '%s' failed with rc %d", cmd.str().c_str(), ret);
140+
return false;
141+
}
142+
return true;
143+
}
144+
117145
void IntfMgr::addLoopbackIntf(const string &alias)
118146
{
119147
stringstream cmd;
@@ -447,6 +475,7 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
447475
string nat_zone = "";
448476
string proxy_arp = "";
449477
string grat_arp = "";
478+
string mpls = "";
450479

451480
for (auto idx : data)
452481
{
@@ -473,6 +502,10 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
473502
{
474503
grat_arp = value;
475504
}
505+
else if (field == "mpls")
506+
{
507+
mpls = value;
508+
}
476509

477510
if (field == "nat_zone")
478511
{
@@ -518,6 +551,17 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
518551
FieldValueTuple fvTuple("nat_zone", nat_zone);
519552
data.push_back(fvTuple);
520553
}
554+
/* Set mpls */
555+
if (!setIntfMpls(alias, mpls))
556+
{
557+
SWSS_LOG_ERROR("Failed to set MPLS to \"%s\" for the \"%s\" interface", mpls.c_str(), alias.c_str());
558+
return false;
559+
}
560+
if (!mpls.empty())
561+
{
562+
FieldValueTuple fvTuple("mpls", mpls);
563+
data.push_back(fvTuple);
564+
}
521565
}
522566

523567
if (!vrf_name.empty())

cfgmgr/intfmgr.h

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class IntfMgr : public Orch
2929
void setIntfIp(const std::string &alias, const std::string &opCmd, const IpPrefix &ipPrefix);
3030
void setIntfVrf(const std::string &alias, const std::string &vrfName);
3131
void setIntfMac(const std::string &alias, const std::string &macAddr);
32+
bool setIntfMpls(const std::string &alias, const std::string &mpls);
3233

3334
bool doIntfGeneralTask(const std::vector<std::string>& keys, std::vector<FieldValueTuple> data, const std::string& op);
3435
bool doIntfAddrTask(const std::vector<std::string>& keys, const std::vector<FieldValueTuple>& data, const std::string& op);

fpmsyncd/fpmsyncd.cpp

+67-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <getopt.h>
12
#include <iostream>
23
#include <inttypes.h>
34
#include "logger.h"
@@ -7,6 +8,7 @@
78
#include "warmRestartHelper.h"
89
#include "fpmsyncd/fpmlink.h"
910
#include "fpmsyncd/routesync.h"
11+
#include "netlink.h"
1012

1113

1214
using namespace std;
@@ -44,6 +46,13 @@ static bool eoiuFlagsSet(Table &bgpStateTable)
4446
return true;
4547
}
4648

49+
static void usage()
50+
{
51+
cout << "Usage: fpmsyncd [ -l ( fpm | net) ]" << endl;
52+
cout << " fpm = FpmLink (default)" << endl;
53+
cout << " net = NetLink" << endl;
54+
}
55+
4756
int main(int argc, char **argv)
4857
{
4958
swss::Logger::linkToDbNative("fpmsyncd");
@@ -57,11 +66,45 @@ int main(int argc, char **argv)
5766
NetDispatcher::getInstance().registerMessageHandler(RTM_NEWROUTE, &sync);
5867
NetDispatcher::getInstance().registerMessageHandler(RTM_DELROUTE, &sync);
5968

69+
bool useFpmLink = true;
70+
int opt;
71+
while ((opt = getopt(argc, argv, "l:h")) != -1 )
72+
{
73+
switch (opt)
74+
{
75+
case 'l':
76+
{
77+
string linkmode(optarg);
78+
if (linkmode == "net")
79+
{
80+
useFpmLink = false;
81+
}
82+
else if (linkmode == "fpm")
83+
{
84+
useFpmLink = true;
85+
}
86+
else
87+
{
88+
usage();
89+
return EXIT_FAILURE;
90+
}
91+
break;
92+
}
93+
94+
case 'h':
95+
usage();
96+
return 1;
97+
98+
default: /* '?' */
99+
usage();
100+
return EXIT_FAILURE;
101+
}
102+
}
103+
60104
while (true)
61105
{
62106
try
63107
{
64-
FpmLink fpm(&sync);
65108
Select s;
66109
SelectableTimer warmStartTimer(timespec{0, 0});
67110
// Before eoiu flags detected, check them periodically. It also stop upon detection of reconciliation done.
@@ -75,11 +118,30 @@ int main(int argc, char **argv)
75118
*/
76119
pipeline.flush();
77120

78-
cout << "Waiting for fpm-client connection..." << endl;
79-
fpm.accept();
80-
cout << "Connected!" << endl;
121+
shared_ptr<Selectable> link;
122+
if (useFpmLink)
123+
{
124+
shared_ptr<FpmLink> fpm = make_shared<FpmLink>(&sync);
125+
126+
cout << "Waiting for fpm-client connection..." << endl;
127+
fpm->accept();
128+
cout << "Connected!" << endl;
81129

82-
s.addSelectable(&fpm);
130+
link = fpm;
131+
}
132+
else
133+
{
134+
shared_ptr<NetLink> netlink = make_shared<NetLink>();
135+
136+
netlink->registerGroup(RTNLGRP_IPV4_ROUTE);
137+
netlink->registerGroup(RTNLGRP_IPV6_ROUTE);
138+
netlink->registerGroup(RTNLGRP_MPLS_ROUTE);
139+
cout << "NetLink listening for route messages..." << endl;
140+
netlink->dumpRequest(RTM_GETROUTE);
141+
142+
link = netlink;
143+
}
144+
s.addSelectable(link.get());
83145

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

0 commit comments

Comments
 (0)