Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SAG]: Add SAG implementation #1974

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 98 additions & 3 deletions cfgmgr/intfmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,22 @@ using namespace swss;

#define LOOPBACK_DEFAULT_MTU_STR "65536"

extern MacAddress gMacAddress;

IntfMgr::IntfMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const vector<string> &tableNames) :
Orch(cfgDb, tableNames),
m_cfgIntfTable(cfgDb, CFG_INTF_TABLE_NAME),
m_cfgVlanIntfTable(cfgDb, CFG_VLAN_INTF_TABLE_NAME),
m_cfgLagIntfTable(cfgDb, CFG_LAG_INTF_TABLE_NAME),
m_cfgLoopbackIntfTable(cfgDb, CFG_LOOPBACK_INTERFACE_TABLE_NAME),
m_cfgSagTable(cfgDb, CFG_SAG_TABLE_NAME),
m_statePortTable(stateDb, STATE_PORT_TABLE_NAME),
m_stateLagTable(stateDb, STATE_LAG_TABLE_NAME),
m_stateVlanTable(stateDb, STATE_VLAN_TABLE_NAME),
m_stateVrfTable(stateDb, STATE_VRF_TABLE_NAME),
m_stateIntfTable(stateDb, STATE_INTERFACE_TABLE_NAME),
m_appIntfTableProducer(appDb, APP_INTF_TABLE_NAME)
m_appIntfTableProducer(appDb, APP_INTF_TABLE_NAME),
m_appSagTableProducer(appDb, APP_SAG_TABLE_NAME)
{
if (!WarmStart::isWarmStart())
{
Expand Down Expand Up @@ -477,6 +481,7 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
string grat_arp = "";
string mpls = "";
string ipv6_link_local_mode = "";
string sag = "";

for (auto idx : data)
{
Expand Down Expand Up @@ -515,6 +520,10 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
{
ipv6_link_local_mode = value;
}
else if (field == "static_anycast_gateway")
{
sag = value;
}
}

if (op == SET_COMMAND)
Expand Down Expand Up @@ -643,8 +652,55 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
}
else
{
FieldValueTuple fvTuple("mac_addr", MacAddress().to_string());
data.push_back(fvTuple);
if (!sag.empty())
{
// only VLAN interface can set static anycast gateway
if (!alias.compare(0, strlen(VLAN_PREFIX), VLAN_PREFIX))
{
vector<FieldValueTuple> fvs;
string gwmac = "";
if (m_cfgSagTable.get("GLOBAL", fvs))
superchild marked this conversation as resolved.
Show resolved Hide resolved
{
for (auto idx: fvs)
{
const auto &field = fvField(idx);
const auto &value = fvValue(idx);

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

if (!gwmac.empty())
{
if (sag == "true")
{
setHostSubIntfAdminStatus(alias, "down");
setIntfMac(alias, gwmac);
setHostSubIntfAdminStatus(alias, "up");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to restore the interface to its original admin state instead of just bringing it up directly?


FieldValueTuple fvTuple("mac_addr", MacAddress(gwmac).to_string());
data.push_back(fvTuple);
}
else if (sag == "false")
{
setHostSubIntfAdminStatus(alias, "down");
setIntfMac(alias, gMacAddress.to_string());
setHostSubIntfAdminStatus(alias, "up");

FieldValueTuple fvTuple("mac_addr", MacAddress().to_string());
data.push_back(fvTuple);
}
superchild marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
else
{
FieldValueTuple fvTuple("mac_addr", MacAddress().to_string());
data.push_back(fvTuple);
}
}

if (!proxy_arp.empty())
Expand Down Expand Up @@ -772,6 +828,37 @@ bool IntfMgr::doIntfAddrTask(const vector<string>& keys,
return true;
}

void IntfMgr::doSagTask(const vector<string>& keys,
const vector<FieldValueTuple> &data,
const string& op)
{
SWSS_LOG_ENTER();

string mac = "";
for (auto idx : data)
{
const auto &field = fvField(idx);
const auto &value = fvValue(idx);

if (field == "gwmac")
{
mac = value;
}
}

vector<FieldValueTuple> fvAppSag;
if (op == SET_COMMAND)
{
FieldValueTuple gwmac("gwmac", MacAddress(mac).to_string());
fvAppSag.push_back(gwmac);
m_appSagTableProducer.set("GLOBAL", fvAppSag);
}
else if (op == DEL_COMMAND)
{
m_appSagTableProducer.del("GLOBAL");
}
}

void IntfMgr::doTask(Consumer &consumer)
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -799,6 +886,14 @@ void IntfMgr::doTask(Consumer &consumer)
it = consumer.m_toSync.erase(it);
continue;
}

if (table_name == CFG_SAG_TABLE_NAME)
{
doSagTask(keys, data, op);
it = consumer.m_toSync.erase(it);
continue;
}

if (!doIntfGeneralTask(keys, data, op))
{
it++;
Expand Down
5 changes: 3 additions & 2 deletions cfgmgr/intfmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class IntfMgr : public Orch
using Orch::doTask;

private:
ProducerStateTable m_appIntfTableProducer;
Table m_cfgIntfTable, m_cfgVlanIntfTable, m_cfgLagIntfTable, m_cfgLoopbackIntfTable;
ProducerStateTable m_appIntfTableProducer, m_appSagTableProducer;
Table m_cfgIntfTable, m_cfgVlanIntfTable, m_cfgLagIntfTable, m_cfgLoopbackIntfTable, m_cfgSagTable;
Table m_statePortTable, m_stateLagTable, m_stateVlanTable, m_stateVrfTable, m_stateIntfTable;

std::set<std::string> m_subIntfList;
Expand All @@ -33,6 +33,7 @@ class IntfMgr : public Orch

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 doSagTask(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);
Expand Down
12 changes: 12 additions & 0 deletions cfgmgr/intfmgrd.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <unistd.h>
#include <vector>
#include <mutex>
#include <algorithm>
#include "dbconnector.h"
#include "select.h"
#include "exec.h"
Expand Down Expand Up @@ -31,6 +32,7 @@ ofstream gRecordOfs;
string gRecordFile;
/* Global database mutex */
mutex gDbMutex;
MacAddress gMacAddress;

int main(int argc, char **argv)
{
Expand All @@ -48,6 +50,7 @@ int main(int argc, char **argv)
CFG_LOOPBACK_INTERFACE_TABLE_NAME,
CFG_VLAN_SUB_INTF_TABLE_NAME,
CFG_VOQ_INBAND_INTERFACE_TABLE_NAME,
CFG_SAG_TABLE_NAME,
};

DBConnector cfgDb("CONFIG_DB", 0);
Expand All @@ -68,6 +71,15 @@ int main(int argc, char **argv)
s.addSelectables(o->getSelectables());
}

Table table(&cfgDb, "DEVICE_METADATA");
std::vector<FieldValueTuple> ovalues;
table.get("localhost", ovalues);
superchild marked this conversation as resolved.
Show resolved Hide resolved
auto it = std::find_if(ovalues.begin(), ovalues.end(), [](const FieldValueTuple& t){ return t.first == "mac";} );
if (it == ovalues.end()) {
throw runtime_error("couldn't find MAC address of the device from config DB");
}
gMacAddress = MacAddress(it->second);

SWSS_LOG_NOTICE("starting main loop");
while (true)
{
Expand Down
Loading