Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
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 @@ -202,6 +210,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 @@ -1972,3 +1972,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 std::string & op = kfvOp(t);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could you remove the std:: in the cpp file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

remove them all for my changes in this .cpp files

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 std::string & op)
{
SWSS_LOG_ENTER();

std::string vnetRouteTunnelName = kfvKey(t);
std::replace(vnetRouteTunnelName.begin(), vnetRouteTunnelName.end(), config_db_key_delimiter, delimiter);
if (op == SET_COMMAND)
{
m_appVnetRouteTunnelTable.set(vnetRouteTunnelName, kfvFieldsValues(t));
SWSS_LOG_NOTICE("Create vnet route tunnel %s", vnetRouteTunnelName.c_str());
}
else if (op == DEL_COMMAND)
{
m_appVnetRouteTunnelTable.del(vnetRouteTunnelName);
SWSS_LOG_NOTICE("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 std::string & op)
{
SWSS_LOG_ENTER();

std::string vnetRouteName = kfvKey(t);
std::replace(vnetRouteName.begin(), vnetRouteName.end(), config_db_key_delimiter, delimiter);
if (op == SET_COMMAND)
{
m_appVnetRouteTable.set(vnetRouteName, kfvFieldsValues(t));
SWSS_LOG_NOTICE("Create vnet route %s", vnetRouteName.c_str());
}
else if (op == DEL_COMMAND)
{
m_appVnetRouteTable.del(vnetRouteName);
SWSS_LOG_NOTICE("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 @@ -366,4 +367,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 @@ -85,11 +85,11 @@ def check_object(db, table, key, expected_attributes):


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 @@ -99,7 +99,7 @@ def create_vnet_local_routes(dvs, prefix, vnet_name, ifname):


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 @@ -111,9 +111,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