Skip to content

Commit 3faa884

Browse files
weixchen1215prsunny
authored andcommitted
swss-orchagent: add new orch for vnet routes/tunnel routes tables in CONFIG_DB (sonic-net#907)
* Vnet route persistence Signed-off-by: [email protected]
1 parent fed2228 commit 3faa884

File tree

4 files changed

+126
-8
lines changed

4 files changed

+126
-8
lines changed

orchagent/orchdaemon.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ bool OrchDaemon::init()
7777
APP_VNET_RT_TABLE_NAME,
7878
APP_VNET_RT_TUNNEL_TABLE_NAME
7979
};
80+
81+
vector<string> cfg_vnet_tables = {
82+
CFG_VNET_RT_TABLE_NAME,
83+
CFG_VNET_RT_TUNNEL_TABLE_NAME
84+
};
85+
8086
VNetOrch *vnet_orch;
8187
if (platform == MLNX_PLATFORM_SUBSTRING)
8288
{
@@ -87,6 +93,8 @@ bool OrchDaemon::init()
8793
vnet_orch = new VNetOrch(m_applDb, APP_VNET_TABLE_NAME);
8894
}
8995
gDirectory.set(vnet_orch);
96+
VNetCfgRouteOrch *cfg_vnet_rt_orch = new VNetCfgRouteOrch(m_configDb, m_applDb, cfg_vnet_tables);
97+
gDirectory.set(cfg_vnet_rt_orch);
9098
VNetRouteOrch *vnet_rt_orch = new VNetRouteOrch(m_applDb, vnet_tables, vnet_orch);
9199
gDirectory.set(vnet_rt_orch);
92100
VRFOrch *vrf_orch = new VRFOrch(m_applDb, APP_VRF_TABLE_NAME);
@@ -204,6 +212,7 @@ bool OrchDaemon::init()
204212
m_orchList.push_back(gFdbOrch);
205213
m_orchList.push_back(mirror_orch);
206214
m_orchList.push_back(gAclOrch);
215+
m_orchList.push_back(cfg_vnet_rt_orch);
207216
m_orchList.push_back(vnet_orch);
208217
m_orchList.push_back(vnet_rt_orch);
209218
m_orchList.push_back(vrf_orch);

orchagent/vnetorch.cpp

+93
Original file line numberDiff line numberDiff line change
@@ -2003,3 +2003,96 @@ bool VNetRouteOrch::delOperation(const Request& request)
20032003

20042004
return true;
20052005
}
2006+
2007+
VNetCfgRouteOrch::VNetCfgRouteOrch(DBConnector *db, DBConnector *appDb, vector<string> &tableNames)
2008+
: Orch(db, tableNames),
2009+
m_appVnetRouteTable(appDb, APP_VNET_RT_TABLE_NAME),
2010+
m_appVnetRouteTunnelTable(appDb, APP_VNET_RT_TUNNEL_TABLE_NAME)
2011+
{
2012+
}
2013+
2014+
void VNetCfgRouteOrch::doTask(Consumer &consumer)
2015+
{
2016+
SWSS_LOG_ENTER();
2017+
2018+
const string & table_name = consumer.getTableName();
2019+
auto it = consumer.m_toSync.begin();
2020+
2021+
while (it != consumer.m_toSync.end())
2022+
{
2023+
bool task_result = false;
2024+
auto t = it->second;
2025+
const string & op = kfvOp(t);
2026+
if (table_name == CFG_VNET_RT_TABLE_NAME)
2027+
{
2028+
task_result = doVnetRouteTask(t, op);
2029+
}
2030+
else if (table_name == CFG_VNET_RT_TUNNEL_TABLE_NAME)
2031+
{
2032+
task_result = doVnetTunnelRouteTask(t, op);
2033+
}
2034+
else
2035+
{
2036+
SWSS_LOG_ERROR("Unknown table : %s", table_name.c_str());
2037+
}
2038+
2039+
if (task_result == true)
2040+
{
2041+
it = consumer.m_toSync.erase(it);
2042+
}
2043+
else
2044+
{
2045+
++it;
2046+
}
2047+
}
2048+
}
2049+
2050+
bool VNetCfgRouteOrch::doVnetTunnelRouteTask(const KeyOpFieldsValuesTuple & t, const string & op)
2051+
{
2052+
SWSS_LOG_ENTER();
2053+
2054+
string vnetRouteTunnelName = kfvKey(t);
2055+
replace(vnetRouteTunnelName.begin(), vnetRouteTunnelName.end(), config_db_key_delimiter, delimiter);
2056+
if (op == SET_COMMAND)
2057+
{
2058+
m_appVnetRouteTunnelTable.set(vnetRouteTunnelName, kfvFieldsValues(t));
2059+
SWSS_LOG_INFO("Create vnet route tunnel %s", vnetRouteTunnelName.c_str());
2060+
}
2061+
else if (op == DEL_COMMAND)
2062+
{
2063+
m_appVnetRouteTunnelTable.del(vnetRouteTunnelName);
2064+
SWSS_LOG_INFO("Delete vnet route tunnel %s", vnetRouteTunnelName.c_str());
2065+
}
2066+
else
2067+
{
2068+
SWSS_LOG_ERROR("Unknown command : %s", op.c_str());
2069+
return false;
2070+
}
2071+
2072+
return true;
2073+
}
2074+
2075+
bool VNetCfgRouteOrch::doVnetRouteTask(const KeyOpFieldsValuesTuple & t, const string & op)
2076+
{
2077+
SWSS_LOG_ENTER();
2078+
2079+
string vnetRouteName = kfvKey(t);
2080+
replace(vnetRouteName.begin(), vnetRouteName.end(), config_db_key_delimiter, delimiter);
2081+
if (op == SET_COMMAND)
2082+
{
2083+
m_appVnetRouteTable.set(vnetRouteName, kfvFieldsValues(t));
2084+
SWSS_LOG_INFO("Create vnet route %s", vnetRouteName.c_str());
2085+
}
2086+
else if (op == DEL_COMMAND)
2087+
{
2088+
m_appVnetRouteTable.del(vnetRouteName);
2089+
SWSS_LOG_INFO("Delete vnet route %s", vnetRouteName.c_str());
2090+
}
2091+
else
2092+
{
2093+
SWSS_LOG_ERROR("Unknown command : %s", op.c_str());
2094+
return false;
2095+
}
2096+
2097+
return true;
2098+
}

orchagent/vnetorch.h

+16
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "request_parser.h"
1111
#include "ipaddresses.h"
12+
#include "producerstatetable.h"
1213

1314
#define VNET_BITMAP_SIZE 32
1415
#define VNET_TUNNEL_SIZE 512
@@ -376,4 +377,19 @@ class VNetRouteOrch : public Orch2
376377
handler_map handler_map_;
377378
};
378379

380+
class VNetCfgRouteOrch : public Orch
381+
{
382+
public:
383+
VNetCfgRouteOrch(DBConnector *db, DBConnector *appDb, vector<string> &tableNames);
384+
using Orch::doTask;
385+
386+
private:
387+
void doTask(Consumer &consumer);
388+
389+
bool doVnetTunnelRouteTask(const KeyOpFieldsValuesTuple & t, const std::string & op);
390+
bool doVnetRouteTask(const KeyOpFieldsValuesTuple & t, const std::string & op);
391+
392+
ProducerStateTable m_appVnetRouteTable, m_appVnetRouteTunnelTable;
393+
};
394+
379395
#endif // __VNETORCH_H

tests/test_vnet.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ def check_deleted_object(db, table, key):
111111

112112

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

116-
create_entry_pst(
117-
app_db,
118-
"VNET_ROUTE_TABLE", ':', "%s:%s" % (vnet_name, prefix),
116+
create_entry_tbl(
117+
conf_db,
118+
"VNET_ROUTE", '|', "%s|%s" % (vnet_name, prefix),
119119
[
120120
("ifname", ifname),
121121
]
@@ -133,7 +133,7 @@ def delete_vnet_local_routes(dvs, prefix, vnet_name):
133133

134134

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

138138
attrs = [
139139
("endpoint", endpoint),
@@ -145,9 +145,9 @@ def create_vnet_routes(dvs, prefix, vnet_name, endpoint, mac="", vni=0):
145145
if mac:
146146
attrs.append(('mac_address', mac))
147147

148-
create_entry_pst(
149-
app_db,
150-
"VNET_ROUTE_TUNNEL_TABLE", ':', "%s:%s" % (vnet_name, prefix),
148+
create_entry_tbl(
149+
conf_db,
150+
"VNET_ROUTE_TUNNEL", '|', "%s|%s" % (vnet_name, prefix),
151151
attrs,
152152
)
153153

0 commit comments

Comments
 (0)