From 0c07a809166b4efcb3ddb972b121282352774c35 Mon Sep 17 00:00:00 2001 From: Marian Pritsak Date: Thu, 27 Dec 2018 02:04:01 +0200 Subject: [PATCH] [intfmgrd]: Merge intfsyncd into intfmgrd (#635) * [intfmgrd]: Merge intfsyncd into intfmgrd Move intfsyncd functionality to intfmgrd, add VRF membership support. --- .gitignore | 1 - Makefile.am | 2 +- cfgmgr/intfmgr.cpp | 169 +++++++++++++++++++++++++++++++------- cfgmgr/intfmgr.h | 7 +- configure.ac | 1 - doc/swss-schema.md | 4 +- intfsyncd/Makefile.am | 16 ---- intfsyncd/intfsync.cpp | 64 --------------- intfsyncd/intfsync.h | 25 ------ intfsyncd/intfsyncd.cpp | 47 ----------- tests/conftest.py | 1 - tests/test_crm.py | 80 +++++++++++++++--- tests/test_nhg.py | 12 ++- tests/test_route.py | 9 +- tests/test_warm_reboot.py | 120 +++++++++++++++++++++------ 15 files changed, 327 insertions(+), 231 deletions(-) delete mode 100644 intfsyncd/Makefile.am delete mode 100644 intfsyncd/intfsync.cpp delete mode 100644 intfsyncd/intfsync.h delete mode 100644 intfsyncd/intfsyncd.cpp diff --git a/.gitignore b/.gitignore index dcbee4ba420c..cfc81d4257e4 100644 --- a/.gitignore +++ b/.gitignore @@ -44,7 +44,6 @@ deps/ ############### teamsyncd/teamsyncd fpmsyncd/fpmsyncd -intfsyncd/intfsyncd cfgmgr/buffermgrd cfgmgr/intfmgrd cfgmgr/portmgrd diff --git a/Makefile.am b/Makefile.am index a86163ae2b81..8f704815853e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = fpmsyncd neighsyncd intfsyncd portsyncd orchagent swssconfig cfgmgr +SUBDIRS = fpmsyncd neighsyncd portsyncd orchagent swssconfig cfgmgr if HAVE_LIBTEAM SUBDIRS += teamsyncd diff --git a/cfgmgr/intfmgr.cpp b/cfgmgr/intfmgr.cpp index 19b01db93646..0aef86eea44a 100644 --- a/cfgmgr/intfmgr.cpp +++ b/cfgmgr/intfmgr.cpp @@ -13,6 +13,7 @@ using namespace swss; #define VLAN_PREFIX "Vlan" #define LAG_PREFIX "PortChannel" +#define VNET_PREFIX "Vnet" IntfMgr::IntfMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const vector &tableNames) : Orch(cfgDb, tableNames), @@ -21,12 +22,13 @@ IntfMgr::IntfMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, c 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) { } -bool IntfMgr::setIntfIp(const string &alias, const string &opCmd, +void IntfMgr::setIntfIp(const string &alias, const string &opCmd, const string &ipPrefixStr, const bool ipv4) { stringstream cmd; @@ -41,7 +43,26 @@ bool IntfMgr::setIntfIp(const string &alias, const string &opCmd, cmd << IP_CMD << " -6 address " << opCmd << " " << ipPrefixStr << " dev " << alias; } int ret = swss::exec(cmd.str(), res); - return (ret == 0); + if (ret) + { + SWSS_LOG_ERROR("Command '%s' failed with rc %d", cmd.str().c_str(), ret); + } +} + +void IntfMgr::setIntfVrf(const string &alias, const string vrfName) +{ + stringstream cmd; + string res; + + if (!vrfName.empty()) + { + cmd << IP_CMD << " link set " << alias << " master " << vrfName; + } + else + { + cmd << IP_CMD << " link set " << alias << " nomaster"; + } + EXEC_WITH_ERROR_THROW(cmd.str(), res); } bool IntfMgr::isIntfStateOk(const string &alias) @@ -64,6 +85,14 @@ bool IntfMgr::isIntfStateOk(const string &alias) return true; } } + else if (!alias.compare(0, strlen(VNET_PREFIX), VNET_PREFIX)) + { + if (m_stateVrfTable.get(alias, temp)) + { + SWSS_LOG_DEBUG("Vnet %s is ready", alias.c_str()); + return true; + } + } else if (m_statePortTable.get(alias, temp)) { SWSS_LOG_DEBUG("Port %s is ready", alias.c_str()); @@ -72,55 +101,133 @@ bool IntfMgr::isIntfStateOk(const string &alias) return false; } -void IntfMgr::doTask(Consumer &consumer) + +bool IntfMgr::doIntfGeneralTask(const vector& keys, + const vector& data, + const string& op) { SWSS_LOG_ENTER(); - auto it = consumer.m_toSync.begin(); - while (it != consumer.m_toSync.end()) + string alias(keys[0]); + string vrf_name = ""; + + for (auto idx : data) { - KeyOpFieldsValuesTuple t = it->second; + const auto &field = fvField(idx); + const auto &value = fvValue(idx); + if (field == "vnet_name" || field == "vrf_name") + { + vrf_name = value; + } + } - vector keys = tokenize(kfvKey(t), config_db_key_delimiter); + if (op == SET_COMMAND) + { + if (!isIntfStateOk(alias)) + { + SWSS_LOG_DEBUG("Interface is not ready, skipping %s", alias.c_str()); + return false; + } - if (keys.size() != 2) + if (!vrf_name.empty() && !isIntfStateOk(vrf_name)) { - SWSS_LOG_ERROR("Invalid key %s", kfvKey(t).c_str()); - it = consumer.m_toSync.erase(it); - continue; + SWSS_LOG_DEBUG("VRF is not ready, skipping %s", vrf_name.c_str()); + return false; + } + + setIntfVrf(alias, vrf_name); + m_appIntfTableProducer.set(alias, data); + } + else if (op == DEL_COMMAND) + { + setIntfVrf(alias, ""); + m_appIntfTableProducer.del(alias); + } + else + { + SWSS_LOG_ERROR("Unknown operation: %s", op.c_str()); + } + + return true; +} + +bool IntfMgr::doIntfAddrTask(const vector& keys, + const vector& data, + const string& op) +{ + SWSS_LOG_ENTER(); + + string alias(keys[0]); + IpPrefix ip_prefix(keys[1]); + string appKey = keys[0] + ":" + keys[1]; + + if (op == SET_COMMAND) + { + /* + * Don't proceed if port/LAG/VLAN is not ready yet. + * The pending task will be checked periodically and retried. + */ + if (!isIntfStateOk(alias)) + { + SWSS_LOG_DEBUG("Interface is not ready, skipping %s", alias.c_str()); + return false; } - string alias(keys[0]); - IpPrefix ip_prefix(keys[1]); + setIntfIp(alias, "add", ip_prefix.to_string(), ip_prefix.isV4()); + + std::vector fvVector; + FieldValueTuple f("family", ip_prefix.isV4() ? IPV4_NAME : IPV6_NAME); + FieldValueTuple s("scope", "global"); + fvVector.push_back(s); + fvVector.push_back(f); + m_appIntfTableProducer.set(appKey, fvVector); + m_stateIntfTable.hset(keys[0] + state_db_key_delimiter + keys[1], "state", "ok"); + } + else if (op == DEL_COMMAND) + { + setIntfIp(alias, "del", ip_prefix.to_string(), ip_prefix.isV4()); + m_appIntfTableProducer.del(appKey); + m_stateIntfTable.del(keys[0] + state_db_key_delimiter + keys[1]); + } + else + { + SWSS_LOG_ERROR("Unknown operation: %s", op.c_str()); + } + + return true; +} + +void IntfMgr::doTask(Consumer &consumer) +{ + SWSS_LOG_ENTER(); + + auto it = consumer.m_toSync.begin(); + while (it != consumer.m_toSync.end()) + { + KeyOpFieldsValuesTuple t = it->second; + + vector keys = tokenize(kfvKey(t), config_db_key_delimiter); + const vector& data = kfvFieldsValues(t); string op = kfvOp(t); - if (op == SET_COMMAND) + + if (keys.size() == 1) { - /* - * Don't proceed if port/LAG/VLAN is not ready yet. - * The pending task will be checked periodically and retried. - * TODO: Subscribe to stateDB for port/lag/VLAN state and retry - * pending tasks immediately upon state change. - */ - if (!isIntfStateOk(alias)) + if (!doIntfGeneralTask(keys, data, op)) { - SWSS_LOG_DEBUG("Interface is not ready, skipping %s", kfvKey(t).c_str()); - it++; continue; } - setIntfIp(alias, "add", ip_prefix.to_string(), ip_prefix.isV4()); - m_stateIntfTable.hset(keys[0] + state_db_key_delimiter + keys[1], "state", "ok"); - SWSS_LOG_NOTICE("Add %s to %s", ip_prefix.to_string().c_str(), alias.c_str()); } - else if (op == DEL_COMMAND) + else if (keys.size() == 2) { - setIntfIp(alias, "del", ip_prefix.to_string(), ip_prefix.isV4()); - m_stateIntfTable.del(keys[0] + state_db_key_delimiter + keys[1]); - SWSS_LOG_NOTICE("Remove %s from %s", ip_prefix.to_string().c_str(), alias.c_str()); + if (!doIntfAddrTask(keys, data, op)) + { + continue; + } } else { - SWSS_LOG_ERROR("Unknown operation: %s", op.c_str()); + SWSS_LOG_ERROR("Invalid key %s", kfvKey(t).c_str()); } it = consumer.m_toSync.erase(it); diff --git a/cfgmgr/intfmgr.h b/cfgmgr/intfmgr.h index 7c0901844de3..d10b5d8b4c49 100644 --- a/cfgmgr/intfmgr.h +++ b/cfgmgr/intfmgr.h @@ -19,9 +19,12 @@ class IntfMgr : public Orch private: ProducerStateTable m_appIntfTableProducer; Table m_cfgIntfTable, m_cfgVlanIntfTable; - Table m_statePortTable, m_stateLagTable, m_stateVlanTable, m_stateIntfTable; + Table m_statePortTable, m_stateLagTable, m_stateVlanTable, m_stateVrfTable, m_stateIntfTable; - bool setIntfIp(const string &alias, const string &opCmd, const string &ipPrefixStr, const bool ipv4 = true); + void setIntfIp(const string &alias, const string &opCmd, const string &ipPrefixStr, const bool ipv4 = true); + void setIntfVrf(const string &alias, const string vrfName); + bool doIntfGeneralTask(const vector& keys, const vector& data, const string& op); + bool doIntfAddrTask(const vector& keys, const vector& data, const string& op); void doTask(Consumer &consumer); bool isIntfStateOk(const string &alias); }; diff --git a/configure.ac b/configure.ac index a33396cd3c94..a277c86a5f91 100644 --- a/configure.ac +++ b/configure.ac @@ -87,7 +87,6 @@ AC_CONFIG_FILES([ orchagent/Makefile fpmsyncd/Makefile neighsyncd/Makefile - intfsyncd/Makefile portsyncd/Makefile teamsyncd/Makefile swssconfig/Makefile diff --git a/doc/swss-schema.md b/doc/swss-schema.md index f6af65b8159f..4c2a1eed0754 100644 --- a/doc/swss-schema.md +++ b/doc/swss-schema.md @@ -38,7 +38,7 @@ Stores information for physical switch ports managed by the switch chip. Ports t --------------------------------------------- ### INTF_TABLE -intfsyncd manages this table. In SONiC, CPU (management) and logical ports (vlan, loopback, LAG) are declared in /etc/network/interface and loaded into the INTF_TABLE. +cfgmgrd manages this table. In SONiC, CPU (management) and logical ports (vlan, loopback, LAG) are declared in /etc/network/interface and /etc/sonic/config_db.json and loaded into the INTF_TABLE. IP prefixes are formatted according to [RFC5954](https://tools.ietf.org/html/rfc5954) with a prefix length appended to the end @@ -802,5 +802,3 @@ What configuration files should we have? Do apps, orch agent each need separate [port_config.ini](https://github.com/stcheng/swss/blob/mock/portsyncd/port_config.ini) - defines physical port information portsyncd reads from port_config.ini and updates PORT_TABLE in APP_DB - -All other apps (intfsyncd) read from PORT_TABLE in APP_DB diff --git a/intfsyncd/Makefile.am b/intfsyncd/Makefile.am deleted file mode 100644 index e87b69e54522..000000000000 --- a/intfsyncd/Makefile.am +++ /dev/null @@ -1,16 +0,0 @@ -INCLUDES = -I $(top_srcdir) - -bin_PROGRAMS = intfsyncd - -if DEBUG -DBGFLAGS = -ggdb -DDEBUG -else -DBGFLAGS = -g -endif - -intfsyncd_SOURCES = intfsyncd.cpp intfsync.cpp - -intfsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -intfsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) -intfsyncd_LDADD = -lnl-3 -lnl-route-3 -lswsscommon - diff --git a/intfsyncd/intfsync.cpp b/intfsyncd/intfsync.cpp deleted file mode 100644 index 45ece341c8d2..000000000000 --- a/intfsyncd/intfsync.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include "logger.h" -#include "netmsg.h" -#include "dbconnector.h" -#include "producerstatetable.h" -#include "linkcache.h" -#include "intfsyncd/intfsync.h" - -using namespace std; -using namespace swss; - -IntfSync::IntfSync(DBConnector *db) : - m_intfTable(db, APP_INTF_TABLE_NAME) -{ -} - -void IntfSync::onMsg(int nlmsg_type, struct nl_object *obj) -{ - char addrStr[MAX_ADDR_SIZE + 1] = {0}; - struct rtnl_addr *addr = (struct rtnl_addr *)obj; - string key; - string scope = "global"; - string family; - - if ((nlmsg_type != RTM_NEWADDR) && (nlmsg_type != RTM_GETADDR) && - (nlmsg_type != RTM_DELADDR)) - return; - - /* Don't sync local routes */ - if (rtnl_addr_get_scope(addr) != RT_SCOPE_UNIVERSE) - { - scope = "local"; - return; - } - - if (rtnl_addr_get_family(addr) == AF_INET) - family = IPV4_NAME; - else if (rtnl_addr_get_family(addr) == AF_INET6) - family = IPV6_NAME; - else - // Not supported - return; - - key = LinkCache::getInstance().ifindexToName(rtnl_addr_get_ifindex(addr)); - key+= ":"; - nl_addr2str(rtnl_addr_get_local(addr), addrStr, MAX_ADDR_SIZE); - key+= addrStr; - if (nlmsg_type == RTM_DELADDR) - { - m_intfTable.del(key); - return; - } - - std::vector fvVector; - FieldValueTuple f("family", family); - FieldValueTuple s("scope", scope); - fvVector.push_back(s); - fvVector.push_back(f); - m_intfTable.set(key, fvVector); -} diff --git a/intfsyncd/intfsync.h b/intfsyncd/intfsync.h deleted file mode 100644 index 3f8440a771c7..000000000000 --- a/intfsyncd/intfsync.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef __INTFSYNC__ -#define __INTFSYNC__ - -#include "dbconnector.h" -#include "producerstatetable.h" -#include "netmsg.h" - -namespace swss { - -class IntfSync : public NetMsg -{ -public: - enum { MAX_ADDR_SIZE = 64 }; - - IntfSync(DBConnector *db); - - virtual void onMsg(int nlmsg_type, struct nl_object *obj); - -private: - ProducerStateTable m_intfTable; -}; - -} - -#endif diff --git a/intfsyncd/intfsyncd.cpp b/intfsyncd/intfsyncd.cpp deleted file mode 100644 index 82ffba58afc1..000000000000 --- a/intfsyncd/intfsyncd.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include "logger.h" -#include "select.h" -#include "netdispatcher.h" -#include "netlink.h" -#include "intfsyncd/intfsync.h" - -using namespace std; -using namespace swss; - -int main(int argc, char **argv) -{ - swss::Logger::linkToDbNative("intfsyncd"); - DBConnector db(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0); - IntfSync sync(&db); - - NetDispatcher::getInstance().registerMessageHandler(RTM_NEWADDR, &sync); - NetDispatcher::getInstance().registerMessageHandler(RTM_DELADDR, &sync); - - while (1) - { - try - { - NetLink netlink; - Select s; - - netlink.registerGroup(RTNLGRP_IPV4_IFADDR); - netlink.registerGroup(RTNLGRP_IPV6_IFADDR); - cout << "Listens to interface messages..." << endl; - netlink.dumpRequest(RTM_GETADDR); - - s.addSelectable(&netlink); - while (true) - { - Selectable *temps; - s.select(&temps); - } - } - catch (const std::exception& e) - { - cout << "Exception \"" << e.what() << "\" had been thrown in deamon" << endl; - return 0; - } - } - - return 1; -} diff --git a/tests/conftest.py b/tests/conftest.py index f72fc817148f..70ca0b1f9648 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -147,7 +147,6 @@ def __init__(self, name=None, keeptb=False): 'rsyslogd'] self.swssd = ['orchagent', 'intfmgrd', - 'intfsyncd', 'neighsyncd', 'portsyncd', 'vlanmgrd', diff --git a/tests/test_crm.py b/tests/test_crm.py index 6d2034a193ef..eeba6f5a4b01 100644 --- a/tests/test_crm.py +++ b/tests/test_crm.py @@ -100,7 +100,11 @@ def test_CrmFdbEntry(dvs, testlog): def test_CrmIpv4Route(dvs, testlog): - dvs.runcmd("ifconfig Ethernet0 10.0.0.0/31 up") + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + dvs.runcmd("ifconfig Ethernet0 up") dvs.runcmd("crm config polling interval 1") @@ -146,6 +150,9 @@ def test_CrmIpv4Route(dvs, testlog): assert new_used_counter == used_counter assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|10.0.0.0/31") + time.sleep(2) + def test_CrmIpv6Route(dvs, testlog): @@ -153,7 +160,11 @@ def test_CrmIpv6Route(dvs, testlog): dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") time.sleep(2) - dvs.runcmd("ifconfig Ethernet0 inet6 add fc00::1/126 up") + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0|fc00::1/126", fvs) + dvs.runcmd("ifconfig Ethernet0 up") dvs.servers[0].runcmd("ifconfig eth0 inet6 add fc00::2/126") dvs.servers[0].runcmd("ip -6 route add default via fc00::1") @@ -202,10 +213,17 @@ def test_CrmIpv6Route(dvs, testlog): assert new_used_counter == used_counter assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|fc00::1/126") + time.sleep(2) + def test_CrmIpv4Nexthop(dvs, testlog): - dvs.runcmd("ifconfig Ethernet0 10.0.0.0/31 up") + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + dvs.runcmd("ifconfig Ethernet0 up") dvs.runcmd("crm config polling interval 1") @@ -243,6 +261,9 @@ def test_CrmIpv4Nexthop(dvs, testlog): assert new_used_counter == used_counter assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|10.0.0.0/31") + time.sleep(2) + def test_CrmIpv6Nexthop(dvs, testlog): @@ -250,7 +271,11 @@ def test_CrmIpv6Nexthop(dvs, testlog): dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") time.sleep(2) - dvs.runcmd("ifconfig Ethernet0 inet6 add fc00::1/126 up") + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0|fc00::1/126", fvs) + dvs.runcmd("ifconfig Ethernet0 up") dvs.runcmd("crm config polling interval 1") @@ -288,10 +313,17 @@ def test_CrmIpv6Nexthop(dvs, testlog): assert new_used_counter == used_counter assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|fc00::1/126") + time.sleep(2) + def test_CrmIpv4Neighbor(dvs, testlog): - dvs.runcmd("ifconfig Ethernet0 10.0.0.0/31 up") + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + dvs.runcmd("ifconfig Ethernet0 up") dvs.runcmd("crm config polling interval 1") @@ -329,6 +361,9 @@ def test_CrmIpv4Neighbor(dvs, testlog): assert new_used_counter == used_counter assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|10.0.0.0/31") + time.sleep(2) + def test_CrmIpv6Neighbor(dvs, testlog): @@ -336,7 +371,11 @@ def test_CrmIpv6Neighbor(dvs, testlog): dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") time.sleep(2) - dvs.runcmd("ifconfig Ethernet0 inet6 add fc00::1/126 up") + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0|fc00::1/126", fvs) + dvs.runcmd("ifconfig Ethernet0 up") dvs.runcmd("crm config polling interval 1") @@ -374,11 +413,19 @@ def test_CrmIpv6Neighbor(dvs, testlog): assert new_used_counter == used_counter assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|fc00::1/126") + time.sleep(2) + def test_CrmNexthopGroup(dvs, testlog): - dvs.runcmd("ifconfig Ethernet0 10.0.0.0/31 up") - dvs.runcmd("ifconfig Ethernet4 10.0.0.2/31 up") + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) + dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("ifconfig Ethernet4 up") dvs.runcmd("crm config polling interval 1") @@ -426,6 +473,10 @@ def test_CrmNexthopGroup(dvs, testlog): assert new_used_counter == used_counter assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|10.0.0.0/31") + intf_tbl._del("Ethernet4|10.0.0.2/31") + time.sleep(2) + def test_CrmNexthopGroupMember(dvs, testlog): @@ -435,8 +486,13 @@ def test_CrmNexthopGroupMember(dvs, testlog): dvs.servers[0].runcmd("ip link set up dev eth0") == 0 dvs.servers[1].runcmd("ip link set up dev eth0") == 0 - dvs.runcmd("ifconfig Ethernet0 10.0.0.0/31 up") - dvs.runcmd("ifconfig Ethernet4 10.0.0.2/31 up") + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) + dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("ifconfig Ethernet4 up") dvs.runcmd("crm config polling interval 1") @@ -484,6 +540,10 @@ def test_CrmNexthopGroupMember(dvs, testlog): assert new_used_counter == used_counter assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|10.0.0.0/31") + intf_tbl._del("Ethernet4|10.0.0.2/31") + time.sleep(2) + def test_CrmAcl(dvs, testlog): diff --git a/tests/test_nhg.py b/tests/test_nhg.py index 6694cd885fc8..57b96edaae48 100644 --- a/tests/test_nhg.py +++ b/tests/test_nhg.py @@ -6,9 +6,15 @@ def test_route_nhg(dvs, testlog): - dvs.runcmd("ifconfig Ethernet0 10.0.0.0/31 up") - dvs.runcmd("ifconfig Ethernet4 10.0.0.2/31 up") - dvs.runcmd("ifconfig Ethernet8 10.0.0.4/31 up") + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) + intf_tbl.set("Ethernet8|10.0.0.4/31", fvs) + dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("ifconfig Ethernet4 up") + dvs.runcmd("ifconfig Ethernet8 up") dvs.runcmd("arp -s 10.0.0.1 00:00:00:00:00:01") dvs.runcmd("arp -s 10.0.0.3 00:00:00:00:00:02") diff --git a/tests/test_route.py b/tests/test_route.py index 8cffd1d58d45..bb8f8de6d474 100644 --- a/tests/test_route.py +++ b/tests/test_route.py @@ -6,8 +6,13 @@ def test_RouteAdd(dvs, testlog): - dvs.runcmd("ifconfig Ethernet0 10.0.0.0/31 up") - dvs.runcmd("ifconfig Ethernet4 10.0.0.2/31 up") + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) + dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("ifconfig Ethernet4 up") dvs.servers[0].runcmd("ifconfig eth0 10.0.0.1/31") dvs.servers[0].runcmd("ip route add default via 10.0.0.0") diff --git a/tests/test_warm_reboot.py b/tests/test_warm_reboot.py index 517c85232cc0..b2bad7f8fbe4 100644 --- a/tests/test_warm_reboot.py +++ b/tests/test_warm_reboot.py @@ -119,8 +119,13 @@ def test_PortSyncdWarmRestart(dvs, testlog): time.sleep(1) - dvs.runcmd("ifconfig Ethernet16 11.0.0.1/29 up") - dvs.runcmd("ifconfig Ethernet20 11.0.0.9/29 up") + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet16|11.0.0.1/29", fvs) + intf_tbl.set("Ethernet20|11.0.0.9/29", fvs) + dvs.runcmd("ifconfig Ethernet16 up") + dvs.runcmd("ifconfig Ethernet20 up") dvs.servers[4].runcmd("ip link set down dev eth0") == 0 dvs.servers[4].runcmd("ip link set up dev eth0") == 0 @@ -183,6 +188,10 @@ def test_PortSyncdWarmRestart(dvs, testlog): swss_app_check_RestoreCount_single(state_db, restore_count, "portsyncd") + intf_tbl._del("Ethernet16|11.0.0.1/29") + intf_tbl._del("Ethernet20|11.0.0.9/29") + time.sleep(2) + def test_VlanMgrdWarmRestart(dvs, testlog): @@ -235,8 +244,12 @@ def test_VlanMgrdWarmRestart(dvs, testlog): time.sleep(1) - dvs.runcmd("ifconfig Vlan16 11.0.0.1/29 up") - dvs.runcmd("ifconfig Vlan20 11.0.0.9/29 up") + intf_tbl = swsscommon.Table(conf_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Vlan16|11.0.0.1/29", fvs) + intf_tbl.set("Vlan20|11.0.0.9/29", fvs) + dvs.runcmd("ifconfig Vlan16 up") + dvs.runcmd("ifconfig Vlan20 up") dvs.servers[4].runcmd("ifconfig eth0 11.0.0.2/29") dvs.servers[4].runcmd("ip route add default via 11.0.0.1") @@ -288,6 +301,10 @@ def test_VlanMgrdWarmRestart(dvs, testlog): swss_app_check_RestoreCount_single(state_db, restore_count, "vlanmgrd") + intf_tbl._del("Vlan16|11.0.0.1/29") + intf_tbl._del("Vlan20|11.0.0.9/29") + time.sleep(2) + def stop_neighsyncd(dvs): dvs.runcmd(['sh', '-c', 'pkill -x neighsyncd']) @@ -383,11 +400,15 @@ def test_swss_neighbor_syncup(dvs, testlog): #enable ipv6 on docker dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") - dvs.runcmd("ifconfig {} 24.0.0.1/24 up".format(intfs[0])) - dvs.runcmd("ip -6 addr add 2400::1/64 dev {}".format(intfs[0])) - - dvs.runcmd("ifconfig {} 28.0.0.1/24 up".format(intfs[1])) - dvs.runcmd("ip -6 addr add 2800::1/64 dev {}".format(intfs[1])) + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("{}|24.0.0.1/24".format(intfs[0]), fvs) + intf_tbl.set("{}|28.0.0.9/24".format(intfs[1]), fvs) + intf_tbl.set("{}|2400::1/64".format(intfs[0]), fvs) + intf_tbl.set("{}|2800::1/64".format(intfs[1]), fvs) + dvs.runcmd("ifconfig {} up".format(intfs[0])) + dvs.runcmd("ifconfig {} up".format(intfs[1])) ips = ["24.0.0.2", "24.0.0.3", "28.0.0.2", "28.0.0.3"] v6ips = ["2400::2", "2400::3", "2800::2", "2800::3"] @@ -710,6 +731,12 @@ def test_swss_neighbor_syncup(dvs, testlog): # check restore Count swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") + intf_tbl._del("{}|24.0.0.1/24".format(intfs[0])) + intf_tbl._del("{}|28.0.0.9/24".format(intfs[1])) + intf_tbl._del("{}|2400::1/64".format(intfs[0])) + intf_tbl._del("{}|2800::1/64".format(intfs[1])) + time.sleep(2) + # TODO: The condition of warm restart readiness check is still under discussion. def test_OrchagentWarmRestartReadyCheck(dvs, testlog): @@ -720,8 +747,13 @@ def test_OrchagentWarmRestartReadyCheck(dvs, testlog): dvs.runcmd("config warm_restart enable swss") - dvs.runcmd("ifconfig Ethernet0 10.0.0.0/31 up") - dvs.runcmd("ifconfig Ethernet4 10.0.0.2/31 up") + config_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + intf_tbl = swsscommon.Table(config_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) + dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("ifconfig Ethernet4 up") dvs.servers[0].runcmd("ifconfig eth0 10.0.0.1/31") dvs.servers[0].runcmd("ip route add default via 10.0.0.0") @@ -761,6 +793,10 @@ def test_OrchagentWarmRestartReadyCheck(dvs, testlog): ps._del("2.2.2.0/24") time.sleep(1) + intf_tbl._del("Ethernet0|10.0.0.0/31") + intf_tbl._del("Ethernet4|10.0.0.2/31") + time.sleep(2) + # recover for test cases after this one. dvs.stop_swss() dvs.start_swss() @@ -779,9 +815,14 @@ def test_swss_port_state_syncup(dvs, testlog): restore_count = swss_get_RestoreCount(dvs, state_db) # update port admin state - dvs.runcmd("ifconfig Ethernet0 10.0.0.0/31 up") - dvs.runcmd("ifconfig Ethernet4 10.0.0.2/31 up") - dvs.runcmd("ifconfig Ethernet8 10.0.0.4/31 up") + intf_tbl = swsscommon.Table(conf_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) + intf_tbl.set("Ethernet8|10.0.0.4/31", fvs) + dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("ifconfig Ethernet4 up") + dvs.runcmd("ifconfig Ethernet8 up") dvs.runcmd("arp -s 10.0.0.1 00:00:00:00:00:01") dvs.runcmd("arp -s 10.0.0.3 00:00:00:00:00:02") @@ -808,6 +849,11 @@ def test_swss_port_state_syncup(dvs, testlog): else: assert oper_status == "down" + intf_tbl._del("Ethernet0|10.0.0.0/31") + intf_tbl._del("Ethernet4|10.0.0.2/31") + intf_tbl._del("Ethernet8|10.0.0.4/31") + time.sleep(2) + dvs.stop_swss() time.sleep(3) @@ -829,6 +875,11 @@ def test_swss_port_state_syncup(dvs, testlog): swss_check_RestoreCount(dvs, state_db, restore_count) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + intf_tbl.set("Ethernet4|10.0.0.2/31", fvs) + intf_tbl.set("Ethernet8|10.0.0.4/31", fvs) + time.sleep(3) + for i in [0, 1, 2]: (status, fvs) = tbl.get("Ethernet%d" % (i * 4)) assert status == True @@ -873,6 +924,11 @@ def test_swss_port_state_syncup(dvs, testlog): dvs.runcmd("arp -d 10.0.0.3") dvs.runcmd("arp -d 10.0.0.5") + intf_tbl._del("Ethernet0|10.0.0.0/31") + intf_tbl._del("Ethernet4|10.0.0.2/31") + intf_tbl._del("Ethernet8|10.0.0.4/31") + time.sleep(2) + ############################################################################# # # @@ -934,16 +990,17 @@ def test_routing_WarmRestart(dvs, testlog): # Enable ipv6 on docker dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") - dvs.runcmd("ip -4 addr add 111.0.0.1/24 dev {}".format(intfs[0])) - dvs.runcmd("ip -6 addr add 1110::1/64 dev {}".format(intfs[0])) + # Defining create neighbor entries (4 ipv4 and 4 ip6, two each on each interface) in linux kernel + intf_tbl = swsscommon.Table(conf_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) + intf_tbl.set("{}|111.0.0.1/24".format(intfs[0]), fvs) + intf_tbl.set("{}|1110::1/64".format(intfs[0]), fvs) + intf_tbl.set("{}|122.0.0.1/24".format(intfs[1]), fvs) + intf_tbl.set("{}|1220::1/64".format(intfs[1]), fvs) + intf_tbl.set("{}|133.0.0.1/24".format(intfs[2]), fvs) + intf_tbl.set("{}|1330::1/64".format(intfs[2]), fvs) dvs.runcmd("ip link set {} up".format(intfs[0])) - - dvs.runcmd("ip -4 addr add 122.0.0.1/24 dev {}".format(intfs[1])) - dvs.runcmd("ip -6 addr add 1220::1/64 dev {}".format(intfs[1])) dvs.runcmd("ip link set {} up".format(intfs[1])) - - dvs.runcmd("ip -4 addr add 133.0.0.1/24 dev {}".format(intfs[2])) - dvs.runcmd("ip -6 addr add 1330::1/64 dev {}".format(intfs[2])) dvs.runcmd("ip link set {} up".format(intfs[2])) time.sleep(1) @@ -1528,6 +1585,14 @@ def test_routing_WarmRestart(dvs, testlog): rt_key = json.loads(addobjs[0]['key']) assert rt_key['dest'] == "192.168.100.0/24" + intf_tbl._del("{}|111.0.0.1/24".format(intfs[0])) + intf_tbl._del("{}|1110::1/64".format(intfs[0])) + intf_tbl._del("{}|122.0.0.1/24".format(intfs[1])) + intf_tbl._del("{}|1220::1/64".format(intfs[1])) + intf_tbl._del("{}|133.0.0.1/24".format(intfs[2])) + intf_tbl._del("{}|1330::1/64".format(intfs[2])) + time.sleep(2) + # macros for number of interfaces and number of neighbors # TBD: NUM_NEIGH_PER_INTF >= 128 ips will cause test framework to hang by default kernel settings @@ -1595,6 +1660,8 @@ def test_system_warmreboot_neighbor_syncup(dvs, testlog): # ipv6: 3200::1/64...6000::1/64 # bring up the servers'interfaces and assign NUM_NEIGH_PER_INTF (e,g 128) ips per interface macs = [] + intf_tbl = swsscommon.Table(conf_db, "INTERFACE") + fvs = swsscommon.FieldValuePairs([("NULL","NULL")]) for i in range(8, 8+NUM_INTF): # set timeout to be the same as real HW # set stale timer bigger to avoid testbed difference related timing issues. @@ -1605,8 +1672,9 @@ def test_system_warmreboot_neighbor_syncup(dvs, testlog): dvs.runcmd("sysctl -w net.ipv4.neigh.Ethernet{}.gc_stale_time=180".format(i*4)) dvs.runcmd("sysctl -w net.ipv6.neigh.Ethernet{}.gc_stale_time=180".format(i*4)) dvs.runcmd("ip addr flush dev Ethernet{}".format(i*4)) - dvs.runcmd("ifconfig Ethernet{} {}.0.0.1/24 up".format(i*4, i*4)) - dvs.runcmd("ip -6 addr add {}00::1/64 dev Ethernet{}".format(i*4,i*4)) + intf_tbl.set("Ethernet{}|{}.0.0.1/24".format(i*4, i*4), fvs) + intf_tbl.set("Ethernet{}|{}00::1/64".format(i*4, i*4), fvs) + dvs.runcmd("ip link set Ethernet{} up".format(i*4, i*4)) dvs.servers[i].runcmd("ip link set up dev eth0") dvs.servers[i].runcmd("ip addr flush dev eth0") #result = dvs.servers[i].runcmd_output("ifconfig eth0 | grep HWaddr | awk '{print $NF}'") @@ -1837,3 +1905,7 @@ def test_system_warmreboot_neighbor_syncup(dvs, testlog): # disable system warm restart dvs.runcmd("config warm_restart disable system") + for i in range(8, 8+NUM_INTF): + intf_tbl._del("Ethernet{}|{}.0.0.1/24".format(i*4, i*4)) + intf_tbl._del("Ethernet{}|{}00::1/64".format(i*4, i*4)) +