Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
anilkpandey committed Apr 24, 2020
2 parents a9fb507 + 3829053 commit a9c4b5d
Show file tree
Hide file tree
Showing 144 changed files with 21,816 additions and 3,391 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Expand Up @@ -54,11 +54,17 @@ cfgmgr/vlanmgrd
cfgmgr/vrfmgrd
cfgmgr/nbrmgrd
cfgmgr/vxlanmgrd
cfgmgr/natmgrd
neighsyncd/neighsyncd
portsyncd/portsyncd
natsyncd/natsyncd
orchagent/orchagent
orchagent/routeresync
orchagent/orchagent_restart_check
swssconfig/swssconfig
swssconfig/swssplayer
tests/tests

# Test Files #
##############
tests/log
3 changes: 2 additions & 1 deletion Makefile.am
@@ -1,4 +1,5 @@
SUBDIRS = fpmsyncd neighsyncd portsyncd orchagent swssconfig cfgmgr tests

SUBDIRS = fpmsyncd neighsyncd portsyncd mclagsyncd natsyncd orchagent swssconfig cfgmgr tests

if HAVE_LIBTEAM
SUBDIRS += teamsyncd
Expand Down
8 changes: 5 additions & 3 deletions README.md
@@ -1,6 +1,8 @@
Broadcom[![Broadcom](https://sonic-jenkins.westus2.cloudapp.azure.com/job/broadcom/job/sonic-swss-build/badge/icon)](https://sonic-jenkins.westus2.cloudapp.azure.com/job/broadcom/job/sonic-swss-build/)
Mellanox[![Mellanox](https://sonic-jenkins.westus2.cloudapp.azure.com/job/mellanox/job/sonic-swss-build/badge/icon)](https://sonic-jenkins.westus2.cloudapp.azure.com/job/mellanox/job/sonic-swss-build/)
VS[![VS](https://sonic-jenkins.westus2.cloudapp.azure.com/job/vs/job/sonic-swss-build/badge/icon)](https://sonic-jenkins.westus2.cloudapp.azure.com/job/vs/job/sonic-swss-build/)
[![Total alerts](https://img.shields.io/lgtm/alerts/g/Azure/sonic-swss.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Azure/sonic-swss/alerts/)
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/Azure/sonic-swss.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Azure/sonic-swss/context:python)
[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/Azure/sonic-swss.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Azure/sonic-swss/context:cpp)

[![VS](https://sonic-jenkins.westus2.cloudapp.azure.com/job/vs/job/sonic-swss-build/badge/icon?subject=VS%20build)](https://sonic-jenkins.westus2.cloudapp.azure.com/job/vs/job/sonic-swss-build/)

# SONiC - SWitch State Service - SWSS

Expand Down
9 changes: 7 additions & 2 deletions cfgmgr/Makefile.am
@@ -1,9 +1,9 @@
INCLUDES = -I $(top_srcdir) -I $(top_srcdir)/orchagent -I $(top_srcdir)/warmrestart
INCLUDES = -I $(top_srcdir) -I $(top_srcdir)/orchagent -I $(top_srcdir)/warmrestart -I $(top_srcdir)/orchagent/flex_counter
CFLAGS_SAI = -I /usr/include/sai
LIBNL_CFLAGS = -I/usr/include/libnl3
LIBNL_LIBS = -lnl-genl-3 -lnl-route-3 -lnl-3

bin_PROGRAMS = vlanmgrd teammgrd portmgrd intfmgrd buffermgrd vrfmgrd nbrmgrd vxlanmgrd sflowmgrd
bin_PROGRAMS = vlanmgrd teammgrd portmgrd intfmgrd buffermgrd vrfmgrd nbrmgrd vxlanmgrd sflowmgrd natmgrd

if DEBUG
DBGFLAGS = -ggdb -DDEBUG
Expand Down Expand Up @@ -55,3 +55,8 @@ sflowmgrd_SOURCES = sflowmgrd.cpp sflowmgr.cpp $(top_srcdir)/orchagent/orch.cpp
sflowmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
sflowmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
sflowmgrd_LDADD = -lswsscommon

natmgrd_SOURCES = natmgrd.cpp natmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp shellcmd.h
natmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
natmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
natmgrd_LDADD = -lswsscommon
15 changes: 15 additions & 0 deletions cfgmgr/buffermgr.cpp
Expand Up @@ -182,6 +182,21 @@ task_process_status BufferMgr::doSpeedUpdateTask(string port, string speed)
buffer_profile_key +
"]";

/* Check if PG Mapping is already then log message and return. */

m_cfgBufferPgTable.get(buffer_pg_key, fvVector);

for (auto& prop : fvVector)
{
if ((fvField(prop) == "profile") && (profile_ref == fvValue(prop)))
{
SWSS_LOG_NOTICE("PG to Buffer Profile Mapping %s already present", buffer_pg_key.c_str());
return task_process_status::task_success;
}
}

fvVector.clear();

fvVector.push_back(make_pair("profile", profile_ref));
m_cfgBufferPgTable.set(buffer_pg_key, fvVector);
return task_process_status::task_success;
Expand Down
172 changes: 78 additions & 94 deletions cfgmgr/intfmgr.cpp
Expand Up @@ -7,6 +7,8 @@
#include "intfmgr.h"
#include "exec.h"
#include "shellcmd.h"
#include "macaddress.h"
#include "warm_restart.h"

using namespace std;
using namespace swss;
Expand All @@ -29,6 +31,10 @@ IntfMgr::IntfMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, c
m_stateIntfTable(stateDb, STATE_INTERFACE_TABLE_NAME),
m_appIntfTableProducer(appDb, APP_INTF_TABLE_NAME)
{
if (!WarmStart::isWarmStart())
{
flushLoopbackIntfs();
}
}

void IntfMgr::setIntfIp(const string &alias, const string &opCmd,
Expand Down Expand Up @@ -60,6 +66,20 @@ void IntfMgr::setIntfIp(const string &alias, const string &opCmd,
}
}

void IntfMgr::setIntfMac(const string &alias, const string &mac_str)
{
stringstream cmd;
string res;

cmd << IP_CMD << " link set " << alias << " address " << mac_str;

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::setIntfVrf(const string &alias, const string &vrfName)
{
stringstream cmd;
Expand Down Expand Up @@ -107,6 +127,28 @@ void IntfMgr::delLoopbackIntf(const string &alias)
}
}

void IntfMgr::flushLoopbackIntfs()
{
stringstream cmd;
string res;

cmd << IP_CMD << " link show type dummy | grep -o '" << LOOPBACK_PREFIX << "[^:]*'";

int ret = swss::exec(cmd.str(), res);
if (ret)
{
SWSS_LOG_DEBUG("Command '%s' failed with rc %d", cmd.str().c_str(), ret);
return;
}

auto aliases = tokenize(res, '\n');
for (string &alias : aliases)
{
SWSS_LOG_NOTICE("Remove loopback device %s", alias.c_str());
delLoopbackIntf(alias);
}
}

int IntfMgr::getIntfIpCount(const string &alias)
{
stringstream cmd;
Expand Down Expand Up @@ -168,124 +210,37 @@ bool IntfMgr::isIntfChangeVrf(const string &alias, const string &vrfName)

void IntfMgr::addHostSubIntf(const string&intf, const string &subIntf, const string &vlan)
{
// TODO: remove when validation check at mgmt is in place
for (const auto &c : intf)
{
if (!isalnum(c))
{
SWSS_LOG_ERROR("Invalid parent port name %s for host sub interface %s", intf.c_str(), subIntf.c_str());
return;
}
}
for (const auto &c : vlan)
{
if (!isdigit(c))
{
SWSS_LOG_ERROR("Invalid vlan id %s for host sub interface %s", vlan.c_str(), subIntf.c_str());
return;
}
}

stringstream cmd;
string res;

cmd << IP_CMD << " link add link " << intf << " name " << subIntf << " type vlan id " << vlan;
cmd << IP_CMD " link add link " << shellquote(intf) << " name " << shellquote(subIntf) << " type vlan id " << shellquote(vlan);
EXEC_WITH_ERROR_THROW(cmd.str(), res);
}

void IntfMgr::setHostSubIntfMtu(const string &subIntf, const string &mtu)
{
// TODO: remove when validation check at mgmt is in place
size_t found = subIntf.find(VLAN_SUB_INTERFACE_SEPARATOR);
if (found == string::npos)
{
SWSS_LOG_ERROR("Invalid host sub interface name: %s", subIntf.c_str());
return;
}
size_t i = 0;
for (const auto &c : subIntf)
{
if (i < found && !isalnum(c))
{
SWSS_LOG_ERROR("Invalid host sub interface name: %s", subIntf.c_str());
return;
}
else if (i > found && !isdigit(c))
{
SWSS_LOG_ERROR("Invalid host sub interface name: %s", subIntf.c_str());
return;
}
i++;
}

stringstream cmd;
string res;

cmd << IP_CMD << " link set " << subIntf << " mtu " << mtu;
cmd << IP_CMD " link set " << shellquote(subIntf) << " mtu " << shellquote(mtu);
EXEC_WITH_ERROR_THROW(cmd.str(), res);
}

void IntfMgr::setHostSubIntfAdminStatus(const string &subIntf, const string &adminStatus)
{
// TODO: remove when validation check at mgmt is in place
size_t found = subIntf.find(VLAN_SUB_INTERFACE_SEPARATOR);
if (found == string::npos)
{
SWSS_LOG_ERROR("Invalid host sub interface name: %s", subIntf.c_str());
return;
}
size_t i = 0;
for (const auto &c : subIntf)
{
if (i < found && !isalnum(c))
{
SWSS_LOG_ERROR("Invalid host sub interface name: %s", subIntf.c_str());
return;
}
else if (i > found && !isdigit(c))
{
SWSS_LOG_ERROR("Invalid host sub interface name: %s", subIntf.c_str());
return;
}
i++;
}

stringstream cmd;
string res;

cmd << IP_CMD << " link set " << subIntf << " " << adminStatus;
cmd << IP_CMD " link set " << shellquote(subIntf) << " " << shellquote(adminStatus);
EXEC_WITH_ERROR_THROW(cmd.str(), res);
}

void IntfMgr::removeHostSubIntf(const string &subIntf)
{
// TODO: remove when validation check at mgmt is in place
size_t found = subIntf.find(VLAN_SUB_INTERFACE_SEPARATOR);
if (found == string::npos)
{
SWSS_LOG_ERROR("Invalid host sub interface name: %s", subIntf.c_str());
return;
}
size_t i = 0;
for (const auto &c : subIntf)
{
if (i < found && !isalnum(c))
{
SWSS_LOG_ERROR("Invalid host sub interface name: %s", subIntf.c_str());
return;
}
else if (i > found && !isdigit(c))
{
SWSS_LOG_ERROR("Invalid host sub interface name: %s", subIntf.c_str());
return;
}
i++;
}

stringstream cmd;
string res;

cmd << IP_CMD << " link del " << subIntf;
cmd << IP_CMD " link del " << shellquote(subIntf);
EXEC_WITH_ERROR_THROW(cmd.str(), res);
}

Expand Down Expand Up @@ -386,10 +341,11 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
alias = alias.substr(0, found);
}
bool is_lo = !alias.compare(0, strlen(LOOPBACK_PREFIX), LOOPBACK_PREFIX);

string mac = "";
string vrf_name = "";
string mtu = "";
string adminStatus = "";
string nat_zone = "";
for (auto idx : data)
{
const auto &field = fvField(idx);
Expand All @@ -399,11 +355,19 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
{
vrf_name = value;
}

if (field == "admin_status")
else if (field == "mac_addr")
{
mac = value;
}
else if (field == "admin_status")
{
adminStatus = value;
}

if (field == "nat_zone")
{
nat_zone = value;
}
}

if (op == SET_COMMAND)
Expand Down Expand Up @@ -431,12 +395,32 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
{
addLoopbackIntf(alias);
}
else
{
/* Set nat zone */
if (!nat_zone.empty())
{
FieldValueTuple fvTuple("nat_zone", nat_zone);
data.push_back(fvTuple);
}
}

if (!vrf_name.empty())
{
setIntfVrf(alias, vrf_name);
}

/*Set the mac of interface*/
if (!mac.empty())
{
setIntfMac(alias, mac);
}
else
{
FieldValueTuple fvTuple("mac_addr", MacAddress().to_string());
data.push_back(fvTuple);
}

if (!subIntfAlias.empty())
{
if (m_subIntfList.find(subIntfAlias) == m_subIntfList.end())
Expand Down
5 changes: 5 additions & 0 deletions cfgmgr/intfmgr.h
Expand Up @@ -25,15 +25,20 @@ 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 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);
void doTask(Consumer &consumer);

bool isIntfStateOk(const std::string &alias);
bool isIntfCreated(const std::string &alias);
bool isIntfChangeVrf(const std::string &alias, const std::string &vrfName);
int getIntfIpCount(const std::string &alias);

void addLoopbackIntf(const std::string &alias);
void delLoopbackIntf(const std::string &alias);
void flushLoopbackIntfs(void);

void addHostSubIntf(const std::string&intf, const std::string &subIntf, const std::string &vlan);
void setHostSubIntfMtu(const std::string &subIntf, const std::string &mtu);
Expand Down
4 changes: 4 additions & 0 deletions cfgmgr/intfmgrd.cpp
Expand Up @@ -8,6 +8,7 @@
#include "intfmgr.h"
#include <fstream>
#include <iostream>
#include "warm_restart.h"

using namespace std;
using namespace swss;
Expand Down Expand Up @@ -52,6 +53,9 @@ int main(int argc, char **argv)
DBConnector appDb("APPL_DB", 0);
DBConnector stateDb("STATE_DB", 0);

WarmStart::initialize("intfmgrd", "swss");
WarmStart::checkWarmStart("intfmgrd", "swss");

IntfMgr intfmgr(&cfgDb, &appDb, &stateDb, cfg_intf_tables);

// TODO: add tables in stateDB which interface depends on to monitor list
Expand Down

0 comments on commit a9c4b5d

Please sign in to comment.