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

[lagidallocator] LAG ID allocator class #3

Open
wants to merge 28 commits into
base: voq-inbandif-port
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
30c8a0c
[voq] Redis instance for global app db
Sep 10, 2020
bfb6f2f
[voq] System port init and orchestration
Sep 10, 2020
ee967d9
[voq] Router interface for system ports, global app db sync
Sep 10, 2020
45942e7
[voq] Inband interface config
Sep 10, 2020
10771a8
[voq] System port neighbors
Sep 10, 2020
2ca2a00
[swss] Review comments fixes
Sep 29, 2020
8e235e6
[swss]Code review comments fix 2
Oct 1, 2020
52fe3e1
Merge branch 'master' into chassis-voq-pr1
vganesan-nokia Oct 1, 2020
1b6d62f
Merge branch 'master' into chassis-voq-pr1
vganesan-nokia Oct 11, 2020
8704004
[swss] voq code review comment fix 3
Oct 12, 2020
8b68af4
[swss] voq code review comments fixes 4
Oct 13, 2020
52972b6
[swss] Voq code review comments fixes 5
Oct 22, 2020
b6fe4e6
Merge branch 'master' into chassis-voq-pr1
vganesan-nokia Nov 3, 2020
34e9f68
[swss]VS tests for VOQ system ports
Nov 9, 2020
a42d3f5
[vstest]Voq switch test - removed chassis_db.json
Nov 20, 2020
8922f46
[vstest]VOQ switch system ports test
Nov 21, 2020
d9df781
[swss]VOQ Code review comments fix 6
Nov 21, 2020
39b1858
Merge branch 'master' into chassis-voq-pr1
vganesan-nokia Nov 30, 2020
21b7cd6
Merge branch 'master' into chassis-voq-pr1
vganesan-nokia Dec 2, 2020
233a1be
[swss]vs test for voq neighbor
Dec 3, 2020
e9fc950
[swss]vs test for voq nbr review comments fix 1
Dec 8, 2020
ae86130
[swss]vs test for voq nbr review comments fix 2
Dec 9, 2020
624d924
[swss]Inband interface setup for voq systems
Dec 10, 2020
00ecb07
[inbandif]Changes to handle port type inband processing
Dec 15, 2020
a8bb5c7
[lagidallocator] LAG allocator class
Dec 15, 2020
2271c87
[inbandif] VS tests for inbandif and remote neigh in asic db
Dec 17, 2020
296add5
Merge remote-tracking branch 'origin/voq-inbandif-port' into voq-syst…
Dec 17, 2020
3b056dd
[lagidallocator] Code review comments fix - 1
Dec 25, 2020
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
12 changes: 12 additions & 0 deletions cfgmgr/intfmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,8 @@ void IntfMgr::doTask(Consumer &consumer)
{
SWSS_LOG_ENTER();

string table_name = consumer.getTableName();

auto it = consumer.m_toSync.begin();
while (it != consumer.m_toSync.end())
{
Expand All @@ -688,6 +690,16 @@ void IntfMgr::doTask(Consumer &consumer)

if (keys.size() == 1)
{
if((table_name == CFG_VOQ_INBAND_INTERFACE_TABLE_NAME) &&
(op == SET_COMMAND))
{
//No further processing needed. Just relay to orchagent
m_appIntfTableProducer.set(keys[0], data);
m_stateIntfTable.hset(keys[0], "vrf", "");

it = consumer.m_toSync.erase(it);
continue;
}
if (!doIntfGeneralTask(keys, data, op))
{
it++;
Expand Down
1 change: 1 addition & 0 deletions cfgmgr/intfmgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ int main(int argc, char **argv)
CFG_VLAN_INTF_TABLE_NAME,
CFG_LOOPBACK_INTERFACE_TABLE_NAME,
CFG_VLAN_SUB_INTF_TABLE_NAME,
CFG_VOQ_INBAND_INTERFACE_TABLE_NAME,
};

DBConnector cfgDb("CONFIG_DB", 0);
Expand Down
292 changes: 291 additions & 1 deletion cfgmgr/nbrmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "nbrmgr.h"
#include "exec.h"
#include "shellcmd.h"
#include "subscriberstatetable.h"

using namespace swss;

Expand Down Expand Up @@ -64,6 +65,20 @@ NbrMgr::NbrMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, con
TableConsumable::DEFAULT_POP_BATCH_SIZE, default_orch_pri);
auto consumer = new Consumer(consumerStateTable, this, APP_NEIGH_RESOLVE_TABLE_NAME);
Orch::addExecutor(consumer);

string swtype;
Table cfgDeviceMetaDataTable(cfgDb, CFG_DEVICE_METADATA_TABLE_NAME);
if(cfgDeviceMetaDataTable.hget("localhost", "switch_type", swtype))
{
//If this is voq system, let the neighbor manager subscribe to state of SYSTEM_NEIGH
//entries. This is used to program static neigh and static route in kernel for remote neighbors.
if(swtype == "voq")
{
string tableName = STATE_SYSTEM_NEIGH_TABLE_NAME;
Orch::addExecutor(new Consumer(new SubscriberStateTable(stateDb, tableName, TableConsumable::DEFAULT_POP_BATCH_SIZE, 0), this, tableName));
m_cfgVoqInbandInterfaceTable = unique_ptr<Table>(new Table(cfgDb, CFG_VOQ_INBAND_INTERFACE_TABLE_NAME));
}
}
}

bool NbrMgr::isIntfStateOk(const string &alias)
Expand Down Expand Up @@ -294,8 +309,283 @@ void NbrMgr::doTask(Consumer &consumer)
} else if (table_name == APP_NEIGH_RESOLVE_TABLE_NAME)
{
doResolveNeighTask(consumer);
} else
} else if(table_name == STATE_SYSTEM_NEIGH_TABLE_NAME)
{
doStateSystemNeighTask(consumer);
}
else
{
SWSS_LOG_ERROR("Unknown REDIS table %s ", table_name.c_str());
}
}

void NbrMgr::doStateSystemNeighTask(Consumer &consumer)
{
SWSS_LOG_ENTER();

//Get the name of the device on which the neigh and route are
//going to be programmed.
string nbr_odev;
string ibif_type;
if(!getVoqInbandInterfaceName(nbr_odev, ibif_type))
{
//The inband interface is not available yet
return;
}

auto it = consumer.m_toSync.begin();
while (it != consumer.m_toSync.end())
{
KeyOpFieldsValuesTuple t = it->second;
string key = kfvKey(t);
string op = kfvOp(t);

size_t found = key.find_last_of(state_db_key_delimiter);
if (found == string::npos)
{
SWSS_LOG_ERROR("Failed to parse key %s", key.c_str());
it = consumer.m_toSync.erase(it);
continue;
}

IpAddress ip_address(key.substr(found+1));
if (op == SET_COMMAND)
{
MacAddress mac_address;
for (auto i = kfvFieldsValues(t).begin();
i != kfvFieldsValues(t).end(); i++)
{
if (fvField(*i) == "neigh")
mac_address = MacAddress(fvValue(*i));
}

if (ibif_type == "port" && !isIntfOperUp(nbr_odev))
{
SWSS_LOG_DEBUG("Device %s is not oper up, skipping system neigh %s'", nbr_odev.c_str(), kfvKey(t).c_str());
it++;
continue;
}

if (!addKernelNeigh(nbr_odev, ip_address, mac_address))
{
SWSS_LOG_ERROR("Neigh entry add on dev %s failed for '%s'", nbr_odev.c_str(), kfvKey(t).c_str());
it++;
continue;
}
else
{
SWSS_LOG_NOTICE("Neigh entry added on dev %s for '%s'", nbr_odev.c_str(), kfvKey(t).c_str());
}

if (!addKernelRoute(nbr_odev, ip_address))
{
SWSS_LOG_ERROR("Route entry add on dev %s failed for '%s'", nbr_odev.c_str(), kfvKey(t).c_str());
delKernelNeigh(nbr_odev, ip_address);
// Delete route to take care of deletion of exiting route of nbr for mac change.
delKernelRoute(ip_address);
it++;
continue;
}
else
{
SWSS_LOG_NOTICE("Route entry added on dev %s for '%s'", nbr_odev.c_str(), kfvKey(t).c_str());
}
SWSS_LOG_NOTICE("Added voq neighbor %s to kernel", kfvKey(t).c_str());
}
else if (op == DEL_COMMAND)
{
if (!delKernelRoute(ip_address))
{
SWSS_LOG_ERROR("Route entry on dev %s delete failed for '%s'", nbr_odev.c_str(), kfvKey(t).c_str());
}
else
{
SWSS_LOG_NOTICE("Route entry on dev %s deleted for '%s'", nbr_odev.c_str(), kfvKey(t).c_str());
}

if (!delKernelNeigh(nbr_odev, ip_address))
{
SWSS_LOG_ERROR("Neigh entry on dev %s delete failed for '%s'", nbr_odev.c_str(), kfvKey(t).c_str());
}
else
{
SWSS_LOG_NOTICE("Neigh entry on dev %s deleted for '%s'", nbr_odev.c_str(), kfvKey(t).c_str());
}
SWSS_LOG_DEBUG("Deleted voq neighbor %s from kernel", kfvKey(t).c_str());
}

it = consumer.m_toSync.erase(it);
}
}

bool NbrMgr::isIntfOperUp(const string &alias)
{
string oper;

if (m_statePortTable.hget(alias, "oper_status", oper))
{
if (oper == "up")
{
SWSS_LOG_DEBUG("Intf %s is oper up", alias.c_str());
return true;
}
}

return false;
}

bool NbrMgr::getVoqInbandInterfaceName(string &ibif, string &type)
{
vector<string> keys;
m_cfgVoqInbandInterfaceTable->getKeys(keys);

if (keys.empty())
{
SWSS_LOG_NOTICE("Voq Inband interface is not configured!");
return false;
}

// key:"alias" = inband interface name

vector<string> if_keys = tokenize(keys[0], config_db_key_delimiter);

ibif = if_keys[0];

// Get the type of the inband interface

if (!m_cfgVoqInbandInterfaceTable->hget(ibif, "inband_type", type))
{
SWSS_LOG_ERROR("Getting Voq Inband interface type failed for %s", ibif.c_str());
return false;
}

return true;
}

bool NbrMgr::addKernelRoute(string odev, IpAddress ip_addr)
{
string cmd, res;

SWSS_LOG_ENTER();

string ip_str = ip_addr.to_string();

if(ip_addr.isV4())
{
cmd = string("") + IP_CMD + " route add " + ip_str + "/32 dev " + odev;
SWSS_LOG_NOTICE("IPv4 Route Add cmd: %s",cmd.c_str());
}
else
{
cmd = string("") + IP_CMD + " -6 route add " + ip_str + "/128 dev " + odev;
SWSS_LOG_NOTICE("IPv6 Route Add cmd: %s",cmd.c_str());
}

int32_t ret = swss::exec(cmd, res);

if(ret)
{
/* Just log error and return */
SWSS_LOG_ERROR("Failed to add route for %s, error: %d", ip_str.c_str(), ret);
return false;
}

SWSS_LOG_INFO("Added route for %s on device %s", ip_str.c_str(), odev.c_str());
return true;
}

bool NbrMgr::delKernelRoute(IpAddress ip_addr)
{
string cmd, res;

SWSS_LOG_ENTER();

string ip_str = ip_addr.to_string();

if(ip_addr.isV4())
{
cmd = string("") + IP_CMD + " route del " + ip_str + "/32";
SWSS_LOG_NOTICE("IPv4 Route Del cmd: %s",cmd.c_str());
}
else
{
cmd = string("") + IP_CMD + " -6 route del " + ip_str + "/128";
SWSS_LOG_NOTICE("IPv6 Route Del cmd: %s",cmd.c_str());
}

int32_t ret = swss::exec(cmd, res);

if(ret)
{
/* Just log error and return */
SWSS_LOG_ERROR("Failed to delete route for %s, error: %d", ip_str.c_str(), ret);
return false;
}

SWSS_LOG_INFO("Deleted route for %s", ip_str.c_str());
return true;
}

bool NbrMgr::addKernelNeigh(string odev, IpAddress ip_addr, MacAddress mac_addr)
{
SWSS_LOG_ENTER();

string cmd, res;
string ip_str = ip_addr.to_string();
string mac_str = mac_addr.to_string();

if(ip_addr.isV4())
{
cmd = string("") + IP_CMD + " neigh add " + ip_str + " lladdr " + mac_str + " dev " + odev;
SWSS_LOG_NOTICE("IPv4 Nbr Add cmd: %s",cmd.c_str());
}
else
{
cmd = string("") + IP_CMD + " -6 neigh add " + ip_str + " lladdr " + mac_str + " dev " + odev;
SWSS_LOG_NOTICE("IPv6 Nbr Add cmd: %s",cmd.c_str());
}

int32_t ret = swss::exec(cmd, res);

if(ret)
{
/* Just log error and return */
SWSS_LOG_ERROR("Failed to add Nbr for %s, error: %d", ip_str.c_str(), ret);
return false;
}

SWSS_LOG_INFO("Added Nbr for %s on interface %s", ip_str.c_str(), odev.c_str());
return true;
}

bool NbrMgr::delKernelNeigh(string odev, IpAddress ip_addr)
{
string cmd, res;

SWSS_LOG_ENTER();

string ip_str = ip_addr.to_string();

if(ip_addr.isV4())
{
cmd = string("") + IP_CMD + " neigh del " + ip_str + " dev " + odev;
SWSS_LOG_NOTICE("IPv4 Nbr Del cmd: %s",cmd.c_str());
}
else
{
cmd = string("") + IP_CMD + " -6 neigh del " + ip_str + " dev " + odev;
SWSS_LOG_NOTICE("IPv6 Nbr Del cmd: %s",cmd.c_str());
}

int32_t ret = swss::exec(cmd, res);

if(ret)
{
/* Just log error and return */
SWSS_LOG_ERROR("Failed to delete Nbr for %s, error: %d", ip_str.c_str(), ret);
return false;
}

SWSS_LOG_INFO("Deleted Nbr for %s on interface %s", ip_str.c_str(), odev.c_str());
return true;
}
8 changes: 8 additions & 0 deletions cfgmgr/nbrmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ class NbrMgr : public Orch
void doResolveNeighTask(Consumer &consumer);
void doSetNeighTask(Consumer &consumer);
void doTask(Consumer &consumer);
void doStateSystemNeighTask(Consumer &consumer);
bool getVoqInbandInterfaceName(string &nbr_odev, string &ibiftype);
bool addKernelRoute(string odev, IpAddress ip_addr);
bool delKernelRoute(IpAddress ip_addr);
bool addKernelNeigh(string odev, IpAddress ip_addr, MacAddress mac_addr);
bool delKernelNeigh(string odev, IpAddress ip_addr);
bool isIntfOperUp(const std::string &alias);
unique_ptr<Table> m_cfgVoqInbandInterfaceTable;

Table m_statePortTable, m_stateLagTable, m_stateVlanTable, m_stateIntfTable, m_stateNeighRestoreTable;
struct nl_sock *m_nl_sock;
Expand Down
Loading