Skip to content

Commit

Permalink
swss-orchagent: add new orch for vnet routes/tunnel routes tables in …
Browse files Browse the repository at this point in the history
…CONFIG_DB (#907)

* Vnet route persistence

Signed-off-by: weixi.chen@microsoft.com
  • Loading branch information
weixchen1215 authored and prsunny committed Jun 11, 2019
1 parent fed2228 commit 3faa884
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 8 deletions.
9 changes: 9 additions & 0 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ bool OrchDaemon::init()
APP_VNET_RT_TABLE_NAME,
APP_VNET_RT_TUNNEL_TABLE_NAME
};

vector<string> cfg_vnet_tables = {
CFG_VNET_RT_TABLE_NAME,
CFG_VNET_RT_TUNNEL_TABLE_NAME
};

VNetOrch *vnet_orch;
if (platform == MLNX_PLATFORM_SUBSTRING)
{
Expand All @@ -87,6 +93,8 @@ bool OrchDaemon::init()
vnet_orch = new VNetOrch(m_applDb, APP_VNET_TABLE_NAME);
}
gDirectory.set(vnet_orch);
VNetCfgRouteOrch *cfg_vnet_rt_orch = new VNetCfgRouteOrch(m_configDb, m_applDb, cfg_vnet_tables);
gDirectory.set(cfg_vnet_rt_orch);
VNetRouteOrch *vnet_rt_orch = new VNetRouteOrch(m_applDb, vnet_tables, vnet_orch);
gDirectory.set(vnet_rt_orch);
VRFOrch *vrf_orch = new VRFOrch(m_applDb, APP_VRF_TABLE_NAME);
Expand Down Expand Up @@ -204,6 +212,7 @@ bool OrchDaemon::init()
m_orchList.push_back(gFdbOrch);
m_orchList.push_back(mirror_orch);
m_orchList.push_back(gAclOrch);
m_orchList.push_back(cfg_vnet_rt_orch);
m_orchList.push_back(vnet_orch);
m_orchList.push_back(vnet_rt_orch);
m_orchList.push_back(vrf_orch);
Expand Down
93 changes: 93 additions & 0 deletions orchagent/vnetorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2003,3 +2003,96 @@ bool VNetRouteOrch::delOperation(const Request& request)

return true;
}

VNetCfgRouteOrch::VNetCfgRouteOrch(DBConnector *db, DBConnector *appDb, vector<string> &tableNames)
: Orch(db, tableNames),
m_appVnetRouteTable(appDb, APP_VNET_RT_TABLE_NAME),
m_appVnetRouteTunnelTable(appDb, APP_VNET_RT_TUNNEL_TABLE_NAME)
{
}

void VNetCfgRouteOrch::doTask(Consumer &consumer)
{
SWSS_LOG_ENTER();

const string & table_name = consumer.getTableName();
auto it = consumer.m_toSync.begin();

while (it != consumer.m_toSync.end())
{
bool task_result = false;
auto t = it->second;
const string & op = kfvOp(t);
if (table_name == CFG_VNET_RT_TABLE_NAME)
{
task_result = doVnetRouteTask(t, op);
}
else if (table_name == CFG_VNET_RT_TUNNEL_TABLE_NAME)
{
task_result = doVnetTunnelRouteTask(t, op);
}
else
{
SWSS_LOG_ERROR("Unknown table : %s", table_name.c_str());
}

if (task_result == true)
{
it = consumer.m_toSync.erase(it);
}
else
{
++it;
}
}
}

bool VNetCfgRouteOrch::doVnetTunnelRouteTask(const KeyOpFieldsValuesTuple & t, const string & op)
{
SWSS_LOG_ENTER();

string vnetRouteTunnelName = kfvKey(t);
replace(vnetRouteTunnelName.begin(), vnetRouteTunnelName.end(), config_db_key_delimiter, delimiter);
if (op == SET_COMMAND)
{
m_appVnetRouteTunnelTable.set(vnetRouteTunnelName, kfvFieldsValues(t));
SWSS_LOG_INFO("Create vnet route tunnel %s", vnetRouteTunnelName.c_str());
}
else if (op == DEL_COMMAND)
{
m_appVnetRouteTunnelTable.del(vnetRouteTunnelName);
SWSS_LOG_INFO("Delete vnet route tunnel %s", vnetRouteTunnelName.c_str());
}
else
{
SWSS_LOG_ERROR("Unknown command : %s", op.c_str());
return false;
}

return true;
}

bool VNetCfgRouteOrch::doVnetRouteTask(const KeyOpFieldsValuesTuple & t, const string & op)
{
SWSS_LOG_ENTER();

string vnetRouteName = kfvKey(t);
replace(vnetRouteName.begin(), vnetRouteName.end(), config_db_key_delimiter, delimiter);
if (op == SET_COMMAND)
{
m_appVnetRouteTable.set(vnetRouteName, kfvFieldsValues(t));
SWSS_LOG_INFO("Create vnet route %s", vnetRouteName.c_str());
}
else if (op == DEL_COMMAND)
{
m_appVnetRouteTable.del(vnetRouteName);
SWSS_LOG_INFO("Delete vnet route %s", vnetRouteName.c_str());
}
else
{
SWSS_LOG_ERROR("Unknown command : %s", op.c_str());
return false;
}

return true;
}
16 changes: 16 additions & 0 deletions orchagent/vnetorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "request_parser.h"
#include "ipaddresses.h"
#include "producerstatetable.h"

#define VNET_BITMAP_SIZE 32
#define VNET_TUNNEL_SIZE 512
Expand Down Expand Up @@ -376,4 +377,19 @@ class VNetRouteOrch : public Orch2
handler_map handler_map_;
};

class VNetCfgRouteOrch : public Orch
{
public:
VNetCfgRouteOrch(DBConnector *db, DBConnector *appDb, vector<string> &tableNames);
using Orch::doTask;

private:
void doTask(Consumer &consumer);

bool doVnetTunnelRouteTask(const KeyOpFieldsValuesTuple & t, const std::string & op);
bool doVnetRouteTask(const KeyOpFieldsValuesTuple & t, const std::string & op);

ProducerStateTable m_appVnetRouteTable, m_appVnetRouteTunnelTable;
};

#endif // __VNETORCH_H
16 changes: 8 additions & 8 deletions tests/test_vnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ def check_deleted_object(db, table, key):


def create_vnet_local_routes(dvs, prefix, vnet_name, ifname):
app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0)
conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0)

create_entry_pst(
app_db,
"VNET_ROUTE_TABLE", ':', "%s:%s" % (vnet_name, prefix),
create_entry_tbl(
conf_db,
"VNET_ROUTE", '|', "%s|%s" % (vnet_name, prefix),
[
("ifname", ifname),
]
Expand All @@ -133,7 +133,7 @@ def delete_vnet_local_routes(dvs, prefix, vnet_name):


def create_vnet_routes(dvs, prefix, vnet_name, endpoint, mac="", vni=0):
app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0)
conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0)

attrs = [
("endpoint", endpoint),
Expand All @@ -145,9 +145,9 @@ def create_vnet_routes(dvs, prefix, vnet_name, endpoint, mac="", vni=0):
if mac:
attrs.append(('mac_address', mac))

create_entry_pst(
app_db,
"VNET_ROUTE_TUNNEL_TABLE", ':', "%s:%s" % (vnet_name, prefix),
create_entry_tbl(
conf_db,
"VNET_ROUTE_TUNNEL", '|', "%s|%s" % (vnet_name, prefix),
attrs,
)

Expand Down

0 comments on commit 3faa884

Please sign in to comment.