From ade486c1dc4bb87ac5e84a4ab9ca2fcbac738e62 Mon Sep 17 00:00:00 2001 From: Antony Rheneus Date: Wed, 24 Jul 2019 00:43:28 +0530 Subject: [PATCH 01/22] ARM32 bit fixes, for 64bit printf format specifier Signed-off-by: Antony Rheneus --- orchagent/aclorch.cpp | 21 ++++--- orchagent/bufferorch.cpp | 12 ++-- orchagent/copporch.cpp | 11 ++-- orchagent/countercheckorch.cpp | 13 ++-- orchagent/crmorch.cpp | 5 +- orchagent/fdborch.cpp | 25 ++++---- orchagent/main.cpp | 5 +- orchagent/orch.cpp | 3 +- orchagent/pfcactionhandler.cpp | 31 +++++----- orchagent/pfcwdorch.cpp | 15 ++--- orchagent/policerorch.cpp | 3 +- orchagent/portsorch.cpp | 109 +++++++++++++++++---------------- orchagent/qosorch.cpp | 21 ++++--- orchagent/routeorch.cpp | 13 ++-- orchagent/switchorch.cpp | 5 +- orchagent/tunneldecaporch.cpp | 9 +-- orchagent/vnetorch.cpp | 7 ++- orchagent/vxlanorch.cpp | 9 +-- 18 files changed, 167 insertions(+), 150 deletions(-) diff --git a/orchagent/aclorch.cpp b/orchagent/aclorch.cpp index fb79a2f157..560791b459 100644 --- a/orchagent/aclorch.cpp +++ b/orchagent/aclorch.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -715,7 +716,7 @@ bool AclRule::removeCounter() gCrmOrch->decCrmAclTableUsedCounter(CrmResourceType::CRM_ACL_COUNTER, m_tableOid); - SWSS_LOG_INFO("Removing record about the counter %lX from the DB", m_counterOid); + SWSS_LOG_INFO("Removing record about the counter %" PRIx64 " from the DB", m_counterOid); AclOrch::getCountersTable().del(getTableId() + ":" + getId()); m_counterOid = SAI_NULL_OBJECT_ID; @@ -1445,7 +1446,7 @@ bool AclTable::unbind(sai_object_id_t portOid) sai_object_id_t member = ports[portOid]; sai_status_t status = sai_acl_api->remove_acl_table_group_member(member); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to unbind table %lu as member %lu from ACL table: %d", + SWSS_LOG_ERROR("Failed to unbind table %" PRIu64 " as member %" PRIu64 " from ACL table: %d", m_oid, member, status); return false; } @@ -1888,14 +1889,14 @@ AclRange *AclRange::create(sai_acl_range_type_t type, int min, int max) return NULL; } - SWSS_LOG_INFO("Created ACL Range object. Type: %d, range %d-%d, oid: %lX", type, min, max, range_oid); + SWSS_LOG_INFO("Created ACL Range object. Type: %d, range %d-%d, oid: %" PRIx64, type, min, max, range_oid); m_ranges[rangeProperties] = new AclRange(type, range_oid, min, max); range_it = m_ranges.find(rangeProperties); } else { - SWSS_LOG_INFO("Reusing range object oid %lX ref count increased to %d", range_it->second->m_oid, range_it->second->m_refCnt); + SWSS_LOG_INFO("Reusing range object oid %" PRIx64 " ref count increased to %d", range_it->second->m_oid, range_it->second->m_refCnt); } // increase range reference count @@ -1947,10 +1948,10 @@ bool AclRange::remove() if (m_refCnt == 0) { - SWSS_LOG_INFO("Range object oid %lX ref count is %d, removing..", m_oid, m_refCnt); + SWSS_LOG_INFO("Range object oid %" PRIx64 " ref count is %d, removing..", m_oid, m_refCnt); if (sai_acl_api->remove_acl_range(m_oid) != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to delete ACL Range object oid: %lX", m_oid); + SWSS_LOG_ERROR("Failed to delete ACL Range object oid: %" PRIx64, m_oid); return false; } auto range_it = m_ranges.find(make_tuple(m_type, m_min, m_max)); @@ -1960,7 +1961,7 @@ bool AclRange::remove() } else { - SWSS_LOG_INFO("Range object oid %lX ref count decreased to %d", m_oid, m_refCnt); + SWSS_LOG_INFO("Range object oid %" PRIx64 " ref count decreased to %d", m_oid, m_refCnt); } return true; @@ -2207,7 +2208,7 @@ bool AclOrch::addAclTable(AclTable &newTable, string table_id) if (createBindAclTable(newTable, table_oid)) { m_AclTables[table_oid] = newTable; - SWSS_LOG_NOTICE("Created ACL table %s oid:%lx", + SWSS_LOG_NOTICE("Created ACL table %s oid:%" PRIx64, newTable.id.c_str(), table_oid); // Mark the existence of the mirror table @@ -2820,7 +2821,7 @@ sai_status_t AclOrch::createDTelWatchListTables() gCrmOrch->incCrmAclUsedCounter(CrmResourceType::CRM_ACL_TABLE, SAI_ACL_STAGE_INGRESS, SAI_ACL_BIND_POINT_TYPE_SWITCH); m_AclTables[table_oid] = flowWLTable; - SWSS_LOG_INFO("Successfully created ACL table %s, oid: %lX", flowWLTable.description.c_str(), table_oid); + SWSS_LOG_INFO("Successfully created ACL table %s, oid: %" PRIx64, flowWLTable.description.c_str(), table_oid); /* Create Drop watchlist ACL table */ @@ -2881,7 +2882,7 @@ sai_status_t AclOrch::createDTelWatchListTables() gCrmOrch->incCrmAclUsedCounter(CrmResourceType::CRM_ACL_TABLE, SAI_ACL_STAGE_INGRESS, SAI_ACL_BIND_POINT_TYPE_SWITCH); m_AclTables[table_oid] = dropWLTable; - SWSS_LOG_INFO("Successfully created ACL table %s, oid: %lX", dropWLTable.description.c_str(), table_oid); + SWSS_LOG_INFO("Successfully created ACL table %s, oid: %" PRIx64, dropWLTable.description.c_str(), table_oid); return status; } diff --git a/orchagent/bufferorch.cpp b/orchagent/bufferorch.cpp index e35b4c7f48..5534c311ea 100644 --- a/orchagent/bufferorch.cpp +++ b/orchagent/bufferorch.cpp @@ -280,10 +280,10 @@ task_process_status BufferOrch::processBufferPool(Consumer &consumer) sai_status = sai_buffer_api->set_buffer_pool_attribute(sai_object, &attribs[0]); if (SAI_STATUS_SUCCESS != sai_status) { - SWSS_LOG_ERROR("Failed to modify buffer pool, name:%s, sai object:%lx, status:%d", object_name.c_str(), sai_object, sai_status); + SWSS_LOG_ERROR("Failed to modify buffer pool, name:%s, sai object:%" PRIx64 ", status:%d", object_name.c_str(), sai_object, sai_status); return task_process_status::task_failed; } - SWSS_LOG_DEBUG("Modified existing pool:%lx, type:%s name:%s ", sai_object, map_type_name.c_str(), object_name.c_str()); + SWSS_LOG_DEBUG("Modified existing pool:%" PRIx64 ", type:%s name:%s ", sai_object, map_type_name.c_str(), object_name.c_str()); } else { @@ -422,11 +422,11 @@ task_process_status BufferOrch::processBufferProfile(Consumer &consumer) } if (SAI_NULL_OBJECT_ID != sai_object) { - SWSS_LOG_DEBUG("Modifying existing sai object:%lx ", sai_object); + SWSS_LOG_DEBUG("Modifying existing sai object:%" PRIx64, sai_object); sai_status = sai_buffer_api->set_buffer_profile_attribute(sai_object, &attribs[0]); if (SAI_STATUS_SUCCESS != sai_status) { - SWSS_LOG_ERROR("Failed to modify buffer profile, name:%s, sai object:%lx, status:%d", object_name.c_str(), sai_object, sai_status); + SWSS_LOG_ERROR("Failed to modify buffer profile, name:%s, sai object:%" PRIx64 ", status:%d", object_name.c_str(), sai_object, sai_status); return task_process_status::task_failed; } } @@ -521,7 +521,7 @@ task_process_status BufferOrch::processQueue(Consumer &consumer) return task_process_status::task_invalid_entry; } queue_id = port.m_queue_ids[ind]; - SWSS_LOG_DEBUG("Applying buffer profile:0x%lx to queue index:%zd, queue sai_id:0x%lx", sai_buffer_profile, ind, queue_id); + SWSS_LOG_DEBUG("Applying buffer profile:0x%" PRIx64 " to queue index:%zd, queue sai_id:0x%" PRIx64, sai_buffer_profile, ind, queue_id); sai_status_t sai_status = sai_queue_api->set_queue_attribute(queue_id, &attr); if (sai_status != SAI_STATUS_SUCCESS) { @@ -608,7 +608,7 @@ task_process_status BufferOrch::processPriorityGroup(Consumer &consumer) return task_process_status::task_invalid_entry; } pg_id = port.m_priority_group_ids[ind]; - SWSS_LOG_DEBUG("Applying buffer profile:0x%lx to port:%s pg index:%zd, pg sai_id:0x%lx", sai_buffer_profile, port_name.c_str(), ind, pg_id); + SWSS_LOG_DEBUG("Applying buffer profile:0x%" PRIx64 " to port:%s pg index:%zd, pg sai_id:0x%" PRIx64, sai_buffer_profile, port_name.c_str(), ind, pg_id); sai_status_t sai_status = sai_buffer_api->set_ingress_priority_group_attribute(pg_id, &attr); if (sai_status != SAI_STATUS_SUCCESS) { diff --git a/orchagent/copporch.cpp b/orchagent/copporch.cpp index a38aa99a4b..fe45ad3d43 100644 --- a/orchagent/copporch.cpp +++ b/orchagent/copporch.cpp @@ -4,6 +4,7 @@ #include "tokenize.h" #include "logger.h" +#include #include #include @@ -277,12 +278,12 @@ sai_object_id_t CoppOrch::getPolicer(string trap_group_name) { return SAI_NULL_OBJECT_ID; } - SWSS_LOG_DEBUG("trap group id:%lx", m_trap_group_map[trap_group_name]); + SWSS_LOG_DEBUG("trap group id:%" PRIx64, m_trap_group_map[trap_group_name]); if (m_trap_group_policer_map.find(m_trap_group_map[trap_group_name]) == m_trap_group_policer_map.end()) { return SAI_NULL_OBJECT_ID; } - SWSS_LOG_DEBUG("trap group policer id:%lx", m_trap_group_policer_map[m_trap_group_map[trap_group_name]]); + SWSS_LOG_DEBUG("trap group policer id:%" PRIx64, m_trap_group_policer_map[m_trap_group_map[trap_group_name]]); return m_trap_group_policer_map[m_trap_group_map[trap_group_name]]; } @@ -456,12 +457,12 @@ task_process_status CoppOrch::processCoppRule(Consumer& consumer) sai_object_id_t policer_id = getPolicer(trap_group_name); if (SAI_NULL_OBJECT_ID == policer_id) { - SWSS_LOG_WARN("Creating policer for existing Trap group:%lx (name:%s).", m_trap_group_map[trap_group_name], trap_group_name.c_str()); + SWSS_LOG_WARN("Creating policer for existing Trap group:%" PRIx64 " (name:%s).", m_trap_group_map[trap_group_name], trap_group_name.c_str()); if (!createPolicer(trap_group_name, policer_attribs)) { return task_process_status::task_failed; } - SWSS_LOG_DEBUG("Created policer:%lx for existing trap group", policer_id); + SWSS_LOG_DEBUG("Created policer:%" PRIx64 " for existing trap group", policer_id); } else { @@ -487,7 +488,7 @@ task_process_status CoppOrch::processCoppRule(Consumer& consumer) sai_status = sai_hostif_api->set_hostif_trap_group_attribute(m_trap_group_map[trap_group_name], &trap_gr_attr); if (sai_status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to apply attribute:%d to trap group:%lx, name:%s, error:%d\n", trap_gr_attr.id, m_trap_group_map[trap_group_name], trap_group_name.c_str(), sai_status); + SWSS_LOG_ERROR("Failed to apply attribute:%d to trap group:%" PRIx64 ", name:%s, error:%d\n", trap_gr_attr.id, m_trap_group_map[trap_group_name], trap_group_name.c_str(), sai_status); return task_process_status::task_failed; } SWSS_LOG_NOTICE("Set trap group %s to host interface", trap_group_name.c_str()); diff --git a/orchagent/countercheckorch.cpp b/orchagent/countercheckorch.cpp index c2d3239bd9..671eef1d61 100644 --- a/orchagent/countercheckorch.cpp +++ b/orchagent/countercheckorch.cpp @@ -4,6 +4,7 @@ #include "notifier.h" #include "redisclient.h" #include "sai_serialize.h" +#include #define COUNTER_CHECK_POLL_TIMEOUT_SEC (5 * 60) @@ -61,7 +62,7 @@ void CounterCheckOrch::mcCounterCheck() Port port; if (!gPortsOrch->getPort(oid, port)) { - SWSS_LOG_ERROR("Invalid port oid 0x%lx", oid); + SWSS_LOG_ERROR("Invalid port oid 0x%" PRIx64, oid); continue; } @@ -78,13 +79,13 @@ void CounterCheckOrch::mcCounterCheck() bool isLossy = ((1 << prio) & pfcMask) == 0; if (newMcCounters[prio] == numeric_limits::max()) { - SWSS_LOG_WARN("Could not retreive MC counters on queue %lu port %s", + SWSS_LOG_WARN("Could not retreive MC counters on queue %" PRIu64 " port %s", prio, port.m_alias.c_str()); } else if (!isLossy && mcCounters[prio] < newMcCounters[prio]) { - SWSS_LOG_WARN("Got Multicast %lu frame(s) on lossless queue %lu port %s", + SWSS_LOG_WARN("Got Multicast %" PRIu64 " frame(s) on lossless queue %" PRIu64 " port %s", newMcCounters[prio] - mcCounters[prio], prio, port.m_alias.c_str()); @@ -109,7 +110,7 @@ void CounterCheckOrch::pfcFrameCounterCheck() Port port; if (!gPortsOrch->getPort(oid, port)) { - SWSS_LOG_ERROR("Invalid port oid 0x%lx", oid); + SWSS_LOG_ERROR("Invalid port oid 0x%" PRIx64, oid); continue; } @@ -124,13 +125,13 @@ void CounterCheckOrch::pfcFrameCounterCheck() bool isLossy = ((1 << prio) & pfcMask) == 0; if (newCounters[prio] == numeric_limits::max()) { - SWSS_LOG_WARN("Could not retreive PFC frame count on queue %lu port %s", + SWSS_LOG_WARN("Could not retreive PFC frame count on queue %" PRIu64 " port %s", prio, port.m_alias.c_str()); } else if (isLossy && counters[prio] < newCounters[prio]) { - SWSS_LOG_WARN("Got PFC %lu frame(s) on lossy queue %lu port %s", + SWSS_LOG_WARN("Got PFC %" PRIu64 " frame(s) on lossy queue %" PRIu64 " port %s", newCounters[prio] - counters[prio], prio, port.m_alias.c_str()); diff --git a/orchagent/crmorch.cpp b/orchagent/crmorch.cpp index 41f68dfc20..e5fc39f796 100644 --- a/orchagent/crmorch.cpp +++ b/orchagent/crmorch.cpp @@ -1,4 +1,5 @@ #include +#include #include "crmorch.h" #include "converter.h" @@ -378,7 +379,7 @@ void CrmOrch::incCrmAclTableUsedCounter(CrmResourceType resource, sai_object_id_ } catch (...) { - SWSS_LOG_ERROR("Failed to increment \"used\" counter for the %s CRM resource (tableId:%lx).", crmResTypeNameMap.at(resource).c_str(), tableId); + SWSS_LOG_ERROR("Failed to increment \"used\" counter for the %s CRM resource (tableId:%" PRIx64 ").", crmResTypeNameMap.at(resource).c_str(), tableId); return; } } @@ -393,7 +394,7 @@ void CrmOrch::decCrmAclTableUsedCounter(CrmResourceType resource, sai_object_id_ } catch (...) { - SWSS_LOG_ERROR("Failed to decrement \"used\" counter for the %s CRM resource (tableId:%lx).", crmResTypeNameMap.at(resource).c_str(), tableId); + SWSS_LOG_ERROR("Failed to decrement \"used\" counter for the %s CRM resource (tableId:%" PRIx64 ").", crmResTypeNameMap.at(resource).c_str(), tableId); return; } } diff --git a/orchagent/fdborch.cpp b/orchagent/fdborch.cpp index 7498eb7e05..794f22d10e 100644 --- a/orchagent/fdborch.cpp +++ b/orchagent/fdborch.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "logger.h" #include "tokenize.h" @@ -63,7 +64,7 @@ bool FdbOrch::storeFdbEntryState(const FdbUpdate& update) if (!m_portsOrch->getPort(entry.bv_id, vlan)) { - SWSS_LOG_NOTICE("FdbOrch notification: Failed to locate vlan port from bv_id 0x%lx", entry.bv_id); + SWSS_LOG_NOTICE("FdbOrch notification: Failed to locate vlan port from bv_id 0x%" PRIx64, entry.bv_id); return false; } @@ -74,7 +75,7 @@ bool FdbOrch::storeFdbEntryState(const FdbUpdate& update) { auto inserted = m_entries.insert(entry); - SWSS_LOG_DEBUG("FdbOrch notification: mac %s was inserted into bv_id 0x%lx", + SWSS_LOG_DEBUG("FdbOrch notification: mac %s was inserted into bv_id 0x%" PRIx64, entry.mac.to_string().c_str(), entry.bv_id); if (!inserted.second) @@ -95,7 +96,7 @@ bool FdbOrch::storeFdbEntryState(const FdbUpdate& update) else { size_t erased = m_entries.erase(entry); - SWSS_LOG_DEBUG("FdbOrch notification: mac %s was removed from bv_id 0x%lx", entry.mac.to_string().c_str(), entry.bv_id); + SWSS_LOG_DEBUG("FdbOrch notification: mac %s was removed from bv_id 0x%" PRIx64, entry.mac.to_string().c_str(), entry.bv_id); if (erased == 0) { @@ -123,14 +124,14 @@ void FdbOrch::update(sai_fdb_event_t type, const sai_fdb_entry_t* entry, sai_obj case SAI_FDB_EVENT_LEARNED: if (!m_portsOrch->getPortByBridgePortId(bridge_port_id, update.port)) { - SWSS_LOG_ERROR("Failed to get port by bridge port ID 0x%lx", bridge_port_id); + SWSS_LOG_ERROR("Failed to get port by bridge port ID 0x%" PRIx64, bridge_port_id); return; } // we already have such entries if (m_entries.find(update.entry) != m_entries.end()) { - SWSS_LOG_INFO("FdbOrch notification: mac %s is already in bv_id 0x%lx", + SWSS_LOG_INFO("FdbOrch notification: mac %s is already in bv_id 0x%" PRIx64, update.entry.mac.to_string().c_str(), entry->bv_id); break; } @@ -186,16 +187,16 @@ void FdbOrch::update(sai_fdb_event_t type, const sai_fdb_entry_t* entry, sai_obj else if (bridge_port_id && entry->bv_id == SAI_NULL_OBJECT_ID) { /*this is a placeholder for flush port fdb case, not supported yet.*/ - SWSS_LOG_ERROR("FdbOrch notification: not supported flush port fdb action, port_id = 0x%lx, bv_id = 0x%lx.", bridge_port_id, entry->bv_id); + SWSS_LOG_ERROR("FdbOrch notification: not supported flush port fdb action, port_id = 0x%" PRIx64 ", bv_id = 0x%" PRIx64 ".", bridge_port_id, entry->bv_id); } else if (bridge_port_id == SAI_NULL_OBJECT_ID && entry->bv_id != SAI_NULL_OBJECT_ID) { /*this is a placeholder for flush vlan fdb case, not supported yet.*/ - SWSS_LOG_ERROR("FdbOrch notification: not supported flush vlan fdb action, port_id = 0x%lx, bv_id = 0x%lx.", bridge_port_id, entry->bv_id); + SWSS_LOG_ERROR("FdbOrch notification: not supported flush vlan fdb action, port_id = 0x%" PRIx64 ", bv_id = 0x%" PRIx64 ".", bridge_port_id, entry->bv_id); } else { - SWSS_LOG_ERROR("FdbOrch notification: not supported flush fdb action, port_id = 0x%lx, bv_id = 0x%lx.", bridge_port_id, entry->bv_id); + SWSS_LOG_ERROR("FdbOrch notification: not supported flush fdb action, port_id = 0x%" PRIx64 ", bv_id = 0x%" PRIx64 ".", bridge_port_id, entry->bv_id); } break; } @@ -251,7 +252,7 @@ bool FdbOrch::getPort(const MacAddress& mac, uint16_t vlan, Port& port) if (!m_portsOrch->getPortByBridgePortId(attr.value.oid, port)) { - SWSS_LOG_ERROR("Failed to get port by bridge port ID 0x%lx", attr.value.oid); + SWSS_LOG_ERROR("Failed to get port by bridge port ID 0x%" PRIx64, attr.value.oid); return false; } @@ -445,7 +446,7 @@ bool FdbOrch::addFdbEntry(const FdbEntry& entry, const string& port_name, const { // FIXME: should we check that the entry are moving to another port? // FIXME: should we check that the entry are changing its type? - SWSS_LOG_ERROR("FDB entry already exists. mac=%s bv_id=0x%lx", entry.mac.to_string().c_str(), entry.bv_id); + SWSS_LOG_ERROR("FDB entry already exists. mac=%s bv_id=0x%" PRIx64, entry.mac.to_string().c_str(), entry.bv_id); return true; } @@ -518,7 +519,7 @@ bool FdbOrch::removeFdbEntry(const FdbEntry& entry) if (m_entries.count(entry) == 0) { - SWSS_LOG_ERROR("FDB entry isn't found. mac=%s bv_id=0x%lx", entry.mac.to_string().c_str(), entry.bv_id); + SWSS_LOG_ERROR("FDB entry isn't found. mac=%s bv_id=0x%" PRIx64, entry.mac.to_string().c_str(), entry.bv_id); return true; } @@ -531,7 +532,7 @@ bool FdbOrch::removeFdbEntry(const FdbEntry& entry) status = sai_fdb_api->remove_fdb_entry(&fdb_entry); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to remove FDB entry. mac=%s, bv_id=0x%lx", + SWSS_LOG_ERROR("Failed to remove FDB entry. mac=%s, bv_id=0x%" PRIx64, entry.mac.to_string().c_str(), entry.bv_id); return true; //FIXME: it should be based on status. Some could be retried. some not } diff --git a/orchagent/main.cpp b/orchagent/main.cpp index 856e3a02a3..620103dc7a 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -12,6 +12,7 @@ extern "C" { #include #include #include +#include #include #include "timestamp.h" @@ -246,7 +247,7 @@ int main(int argc, char **argv) } gVirtualRouterId = attr.value.oid; - SWSS_LOG_NOTICE("Get switch virtual router ID %lx", gVirtualRouterId); + SWSS_LOG_NOTICE("Get switch virtual router ID %" PRIx64, gVirtualRouterId); /* Create a loopback underlay router interface */ vector underlay_intf_attrs; @@ -267,7 +268,7 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } - SWSS_LOG_NOTICE("Created underlay router interface ID %lx", gUnderlayIfId); + SWSS_LOG_NOTICE("Created underlay router interface ID %" PRIx64, gUnderlayIfId); /* Initialize orchestration components */ DBConnector appl_db(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0); diff --git a/orchagent/orch.cpp b/orchagent/orch.cpp index fb8a8eec5d..89f924dccc 100644 --- a/orchagent/orch.cpp +++ b/orchagent/orch.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include "timestamp.h" #include "orch.h" @@ -462,7 +463,7 @@ ref_resolve_status Orch::resolveFieldRefArray( return ref_resolve_status::not_resolved; } sai_object_id_t sai_obj = (*(type_maps[ref_type_name]))[object_name]; - SWSS_LOG_DEBUG("Resolved to sai_object:0x%lx, type:%s, name:%s", sai_obj, ref_type_name.c_str(), object_name.c_str()); + SWSS_LOG_DEBUG("Resolved to sai_object:0x%" PRIx64 ", type:%s, name:%s", sai_obj, ref_type_name.c_str(), object_name.c_str()); sai_object_arr.push_back(sai_obj); } count++; diff --git a/orchagent/pfcactionhandler.cpp b/orchagent/pfcactionhandler.cpp index 3778ef1c5f..c726d18b58 100644 --- a/orchagent/pfcactionhandler.cpp +++ b/orchagent/pfcactionhandler.cpp @@ -4,6 +4,7 @@ #include "sai_serialize.h" #include "portsorch.h" #include +#include #define PFC_WD_QUEUE_STATUS "PFC_WD_STATUS" #define PFC_WD_QUEUE_STATUS_OPERATIONAL "operational" @@ -334,14 +335,14 @@ PfcWdLossyHandler::PfcWdLossyHandler(sai_object_id_t port, sai_object_id_t queue if (!gPortsOrch->getPortPfc(port, &pfcMask)) { - SWSS_LOG_ERROR("Failed to get PFC mask on port 0x%lx", port); + SWSS_LOG_ERROR("Failed to get PFC mask on port 0x%" PRIx64, port); } pfcMask = static_cast(pfcMask & ~(1 << queueId)); if (!gPortsOrch->setPortPfc(port, pfcMask)) { - SWSS_LOG_ERROR("Failed to set PFC mask on port 0x%lx", port); + SWSS_LOG_ERROR("Failed to set PFC mask on port 0x%" PRIx64, port); } } @@ -353,14 +354,14 @@ PfcWdLossyHandler::~PfcWdLossyHandler(void) if (!gPortsOrch->getPortPfc(getPort(), &pfcMask)) { - SWSS_LOG_ERROR("Failed to get PFC mask on port 0x%lx", getPort()); + SWSS_LOG_ERROR("Failed to get PFC mask on port 0x%" PRIx64, getPort()); } pfcMask = static_cast(pfcMask | (1 << getQueueId())); if (!gPortsOrch->setPortPfc(getPort(), pfcMask)) { - SWSS_LOG_ERROR("Failed to set PFC mask on port 0x%lx", getPort()); + SWSS_LOG_ERROR("Failed to set PFC mask on port 0x%" PRIx64, getPort()); } } @@ -391,7 +392,7 @@ bool PfcWdLossyHandler::getHwCounters(PfcWdHwStats& counters) if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to fetch queue 0x%lx stats: %d", getQueue(), status); + SWSS_LOG_ERROR("Failed to fetch queue 0x%" PRIx64 " stats: %d", getQueue(), status); return false; } @@ -399,7 +400,7 @@ bool PfcWdLossyHandler::getHwCounters(PfcWdHwStats& counters) Port portInstance; if (!gPortsOrch->getPort(getPort(), portInstance)) { - SWSS_LOG_ERROR("Cannot get port by ID 0x%lx", getPort()); + SWSS_LOG_ERROR("Cannot get port by ID 0x%" PRIx64, getPort()); return false; } @@ -415,7 +416,7 @@ bool PfcWdLossyHandler::getHwCounters(PfcWdHwStats& counters) if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to fetch pg 0x%lx stats: %d", pg, status); + SWSS_LOG_ERROR("Failed to fetch pg 0x%" PRIx64 " stats: %d", pg, status); return false; } @@ -440,7 +441,7 @@ PfcWdZeroBufferHandler::PfcWdZeroBufferHandler(sai_object_id_t port, sai_status_t status = sai_queue_api->get_queue_attribute(queue, 1, &attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to get buffer profile ID on queue 0x%lx: %d", queue, status); + SWSS_LOG_ERROR("Failed to get buffer profile ID on queue 0x%" PRIx64 ": %d", queue, status); return; } @@ -453,7 +454,7 @@ PfcWdZeroBufferHandler::PfcWdZeroBufferHandler(sai_object_id_t port, status = sai_queue_api->set_queue_attribute(queue, &attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to set buffer profile ID on queue 0x%lx: %d", queue, status); + SWSS_LOG_ERROR("Failed to set buffer profile ID on queue 0x%" PRIx64 ": %d", queue, status); return; } @@ -464,7 +465,7 @@ PfcWdZeroBufferHandler::PfcWdZeroBufferHandler(sai_object_id_t port, Port portInstance; if (!gPortsOrch->getPort(port, portInstance)) { - SWSS_LOG_ERROR("Cannot get port by ID 0x%lx", port); + SWSS_LOG_ERROR("Cannot get port by ID 0x%" PRIx64, port); return; } @@ -476,7 +477,7 @@ PfcWdZeroBufferHandler::PfcWdZeroBufferHandler(sai_object_id_t port, status = sai_buffer_api->get_ingress_priority_group_attribute(pg, 1, &attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to get buffer profile ID on PG 0x%lx: %d", pg, status); + SWSS_LOG_ERROR("Failed to get buffer profile ID on PG 0x%" PRIx64 ": %d", pg, status); return; } @@ -489,7 +490,7 @@ PfcWdZeroBufferHandler::PfcWdZeroBufferHandler(sai_object_id_t port, status = sai_buffer_api->set_ingress_priority_group_attribute(pg, &attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to set buffer profile ID on pg 0x%lx: %d", pg, status); + SWSS_LOG_ERROR("Failed to set buffer profile ID on pg 0x%" PRIx64 ": %d", pg, status); return; } @@ -509,14 +510,14 @@ PfcWdZeroBufferHandler::~PfcWdZeroBufferHandler(void) sai_status_t status = sai_queue_api->set_queue_attribute(getQueue(), &attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to set buffer profile ID on queue 0x%lx: %d", getQueue(), status); + SWSS_LOG_ERROR("Failed to set buffer profile ID on queue 0x%" PRIx64 ": %d", getQueue(), status); return; } Port portInstance; if (!gPortsOrch->getPort(getPort(), portInstance)) { - SWSS_LOG_ERROR("Cannot get port by ID 0x%lx", getPort()); + SWSS_LOG_ERROR("Cannot get port by ID 0x%" PRIx64, getPort()); return; } @@ -529,7 +530,7 @@ PfcWdZeroBufferHandler::~PfcWdZeroBufferHandler(void) status = sai_buffer_api->set_ingress_priority_group_attribute(pg, &attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to set buffer profile ID on queue 0x%lx: %d", getQueue(), status); + SWSS_LOG_ERROR("Failed to set buffer profile ID on queue 0x%" PRIx64 ": %d", getQueue(), status); return; } } diff --git a/orchagent/pfcwdorch.cpp b/orchagent/pfcwdorch.cpp index 043ea64a03..61c67c03a0 100644 --- a/orchagent/pfcwdorch.cpp +++ b/orchagent/pfcwdorch.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "pfcwdorch.h" #include "sai_serialize.h" @@ -352,7 +353,7 @@ void PfcWdSwOrch::disableBigRedSwitchMode() if (entry.second.handler != nullptr) { SWSS_LOG_NOTICE( - "PFC Watchdog BIG_RED_SWITCH mode disabled on port %s, queue index %d, queue id 0x%lx and port id 0x%lx.", + "PFC Watchdog BIG_RED_SWITCH mode disabled on port %s, queue index %d, queue id 0x%" PRIx64 " and port id 0x%" PRIx64 ".", entry.second.portAlias.c_str(), entry.second.index, entry.first, @@ -456,7 +457,7 @@ void PfcWdSwOrch::enableBigRedSwitchMode() if (entry->second.handler== nullptr) { SWSS_LOG_NOTICE( - "PFC Watchdog BIG_RED_SWITCH mode enabled on port %s, queue index %d, queue id 0x%lx and port id 0x%lx.", + "PFC Watchdog BIG_RED_SWITCH mode enabled on port %s, queue index %d, queue id 0x%" PRIx64 " and port id 0x%" PRIx64 ".", entry->second.portAlias.c_str(), entry->second.index, entry->first, @@ -900,7 +901,7 @@ bool PfcWdSwOrch::startWdActionOnQueue(const string auto entry = m_entryMap.find(queueId); if (entry == m_entryMap.end()) { - SWSS_LOG_ERROR("Queue 0x%lx is not registered", queueId); + SWSS_LOG_ERROR("Queue 0x%" PRIx64 " is not registered", queueId); return false; } @@ -917,7 +918,7 @@ bool PfcWdSwOrch::startWdActionOnQueue(const string if (entry->second.handler == nullptr) { SWSS_LOG_NOTICE( - "PFC Watchdog detected PFC storm on port %s, queue index %d, queue id 0x%lx and port id 0x%lx.", + "PFC Watchdog detected PFC storm on port %s, queue index %d, queue id 0x%" PRIx64 " and port id 0x%" PRIx64 ".", entry->second.portAlias.c_str(), entry->second.index, entry->first, @@ -939,7 +940,7 @@ bool PfcWdSwOrch::startWdActionOnQueue(const string if (entry->second.handler == nullptr) { SWSS_LOG_NOTICE( - "PFC Watchdog detected PFC storm on port %s, queue index %d, queue id 0x%lx and port id 0x%lx.", + "PFC Watchdog detected PFC storm on port %s, queue index %d, queue id 0x%" PRIx64 " and port id 0x%" PRIx64 ".", entry->second.portAlias.c_str(), entry->second.index, entry->first, @@ -961,7 +962,7 @@ bool PfcWdSwOrch::startWdActionOnQueue(const string if (entry->second.handler == nullptr) { SWSS_LOG_NOTICE( - "PFC Watchdog detected PFC storm on port %s, queue index %d, queue id 0x%lx and port id 0x%lx.", + "PFC Watchdog detected PFC storm on port %s, queue index %d, queue id 0x%" PRIx64 " and port id 0x%" PRIx64 ".", entry->second.portAlias.c_str(), entry->second.index, entry->first, @@ -989,7 +990,7 @@ bool PfcWdSwOrch::startWdActionOnQueue(const string if (entry->second.handler != nullptr) { SWSS_LOG_NOTICE( - "PFC Watchdog storm restored on port %s, queue index %d, queue id 0x%lx and port id 0x%lx.", + "PFC Watchdog storm restored on port %s, queue index %d, queue id 0x%" PRIx64 " and port id 0x%" PRIx64 ".", entry->second.portAlias.c_str(), entry->second.index, entry->first, diff --git a/orchagent/policerorch.cpp b/orchagent/policerorch.cpp index 3aecf822c9..a8c6c16fd7 100644 --- a/orchagent/policerorch.cpp +++ b/orchagent/policerorch.cpp @@ -2,6 +2,7 @@ #include "policerorch.h" #include "converter.h" +#include using namespace std; using namespace swss; @@ -63,7 +64,7 @@ bool PolicerOrch::getPolicerOid(const string &name, sai_object_id_t &oid) if (policerExists(name)) { oid = m_syncdPolicers[name]; - SWSS_LOG_NOTICE("Get policer %s oid:%lx", name.c_str(), oid); + SWSS_LOG_NOTICE("Get policer %s oid:%" PRIx64, name.c_str(), oid); return true; } diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 5b1cdae88a..177fb60a2a 100644 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -3,6 +3,7 @@ #include "bufferorch.h" #include "neighorch.h" +#include #include #include #include @@ -261,7 +262,7 @@ PortsOrch::PortsOrch(DBConnector *db, vector &tableNames) status = sai_port_api->get_port_attribute(port_list[i], 1, &attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to get hardware lane list pid:%lx", port_list[i]); + SWSS_LOG_ERROR("Failed to get hardware lane list pid:%" PRIx64, port_list[i]); throw runtime_error("PortsOrch initialization failure"); } @@ -278,7 +279,7 @@ PortsOrch::PortsOrch(DBConnector *db, vector &tableNames) } tmp_lane_str = tmp_lane_str.substr(0, tmp_lane_str.size()-1); - SWSS_LOG_NOTICE("Get port with lanes pid:%lx lanes:%s", port_list[i], tmp_lane_str.c_str()); + SWSS_LOG_NOTICE("Get port with lanes pid:%" PRIx64 " lanes:%s", port_list[i], tmp_lane_str.c_str()); m_portListLaneMap[tmp_lane_set] = port_list[i]; } @@ -546,11 +547,11 @@ bool PortsOrch::setPortAdminStatus(sai_object_id_t id, bool up) sai_status_t status = sai_port_api->set_port_attribute(id, &attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to set admin status %s to port pid:%lx", + SWSS_LOG_ERROR("Failed to set admin status %s to port pid:%" PRIx64, up ? "UP" : "DOWN", id); return false; } - SWSS_LOG_INFO("Set admin status %s to port pid:%lx", + SWSS_LOG_INFO("Set admin status %s to port pid:%" PRIx64, up ? "UP" : "DOWN", id); return true; } @@ -565,7 +566,7 @@ bool PortsOrch::getPortAdminStatus(sai_object_id_t id, bool &up) sai_status_t status = sai_port_api->get_port_attribute(id, 1, &attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to get admin status for port pid:%lx", id); + SWSS_LOG_ERROR("Failed to get admin status for port pid:%" PRIx64, id); return false; } @@ -586,11 +587,11 @@ bool PortsOrch::setPortMtu(sai_object_id_t id, sai_uint32_t mtu) sai_status_t status = sai_port_api->set_port_attribute(id, &attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to set MTU %u to port pid:%lx, rv:%d", + SWSS_LOG_ERROR("Failed to set MTU %u to port pid:%" PRIx64 ", rv:%d", attr.value.u32, id, status); return false; } - SWSS_LOG_INFO("Set MTU %u to port pid:%lx", attr.value.u32, id); + SWSS_LOG_INFO("Set MTU %u to port pid:%" PRIx64, attr.value.u32, id); return true; } @@ -605,11 +606,11 @@ bool PortsOrch::setPortFec(sai_object_id_t id, sai_port_fec_mode_t mode) sai_status_t status = sai_port_api->set_port_attribute(id, &attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to set fec mode %d to port pid:%lx", + SWSS_LOG_ERROR("Failed to set fec mode %d to port pid:%" PRIx64, mode, id); return false; } - SWSS_LOG_INFO("Set fec mode %d to port pid:%lx", + SWSS_LOG_INFO("Set fec mode %d to port pid:%" PRIx64, mode, id); return true; } @@ -622,7 +623,7 @@ bool PortsOrch::getPortPfc(sai_object_id_t portId, uint8_t *pfc_bitmask) if (!getPort(portId, p)) { - SWSS_LOG_ERROR("Failed to get port object for port id 0x%lx", portId); + SWSS_LOG_ERROR("Failed to get port object for port id 0x%" PRIx64, portId); return false; } @@ -640,7 +641,7 @@ bool PortsOrch::setPortPfc(sai_object_id_t portId, uint8_t pfc_bitmask) if (!getPort(portId, p)) { - SWSS_LOG_ERROR("Failed to get port object for port id 0x%lx", portId); + SWSS_LOG_ERROR("Failed to get port object for port id 0x%" PRIx64, portId); return false; } @@ -663,7 +664,7 @@ bool PortsOrch::setPortPfc(sai_object_id_t portId, uint8_t pfc_bitmask) sai_status_t status = sai_port_api->set_port_attribute(portId, &attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to set PFC 0x%x to port id 0x%lx (rc:%d)", attr.value.u8, portId, status); + SWSS_LOG_ERROR("Failed to set PFC 0x%x to port id 0x%" PRIx64 " (rc:%d)", attr.value.u8, portId, status); return false; } @@ -711,7 +712,7 @@ bool PortsOrch::setPortPfcAsym(Port &port, string pfc_asym) sai_status_t status = sai_port_api->set_port_attribute(port.m_port_id, &attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to set PFC mode %d to port id 0x%lx (rc:%d)", port.m_pfc_asym, port.m_port_id, status); + SWSS_LOG_ERROR("Failed to set PFC mode %d to port id 0x%" PRIx64 " (rc:%d)", port.m_pfc_asym, port.m_port_id, status); return false; } @@ -728,12 +729,12 @@ bool PortsOrch::setPortPfcAsym(Port &port, string pfc_asym) sai_status_t status = sai_port_api->set_port_attribute(port.m_port_id, &attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to set RX PFC 0x%x to port id 0x%lx (rc:%d)", attr.value.u8, port.m_port_id, status); + SWSS_LOG_ERROR("Failed to set RX PFC 0x%x to port id 0x%" PRIx64 " (rc:%d)", attr.value.u8, port.m_port_id, status); return false; } } - SWSS_LOG_INFO("Set asymmetric PFC %s to port id 0x%lx", pfc_asym.c_str(), port.m_port_id); + SWSS_LOG_INFO("Set asymmetric PFC %s to port id 0x%" PRIx64, pfc_asym.c_str(), port.m_port_id); return true; } @@ -751,7 +752,7 @@ bool PortsOrch::createBindAclTableGroup(sai_object_id_t id, sai_object_id_t &gro Port port; if (!getPort(id, port)) { - SWSS_LOG_ERROR("Failed to get port by port ID %lx", id); + SWSS_LOG_ERROR("Failed to get port by port ID %" PRIx64, id); return false; } @@ -837,7 +838,7 @@ bool PortsOrch::createBindAclTableGroup(sai_object_id_t id, sai_object_id_t &gro status = sai_port_api->set_port_attribute(port.m_port_id, &port_attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to bind port %s to ACL table group %lx, rv:%d", + SWSS_LOG_ERROR("Failed to bind port %s to ACL table group %" PRIx64 ", rv:%d", port.m_alias.c_str(), group_oid, status); return false; } @@ -853,7 +854,7 @@ bool PortsOrch::createBindAclTableGroup(sai_object_id_t id, sai_object_id_t &gro status = sai_lag_api->set_lag_attribute(port.m_lag_id, &lag_attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to bind LAG %s to ACL table group %lx, rv:%d", + SWSS_LOG_ERROR("Failed to bind LAG %s to ACL table group %" PRIx64 ", rv:%d", port.m_alias.c_str(), group_oid, status); return false; } @@ -869,7 +870,7 @@ bool PortsOrch::createBindAclTableGroup(sai_object_id_t id, sai_object_id_t &gro status = sai_vlan_api->set_vlan_attribute(port.m_vlan_info.vlan_oid, &vlan_attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to bind VLAN %s to ACL table group %lx, rv:%d", + SWSS_LOG_ERROR("Failed to bind VLAN %s to ACL table group %" PRIx64 ", rv:%d", port.m_alias.c_str(), group_oid, status); return false; } @@ -894,7 +895,7 @@ bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_ if (table_oid == SAI_NULL_OBJECT_ID) { - SWSS_LOG_ERROR("Invalid ACL table %lx", table_oid); + SWSS_LOG_ERROR("Invalid ACL table %" PRIx64, table_oid); return false; } @@ -904,7 +905,7 @@ bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_ // Create an ACL table group and bind to port if (!createBindAclTableGroup(id, groupOid, acl_stage)) { - SWSS_LOG_ERROR("Fail to create or bind to port %lx ACL table group", id); + SWSS_LOG_ERROR("Fail to create or bind to port %" PRIx64 " ACL table group", id); return false; } @@ -927,7 +928,7 @@ bool PortsOrch::bindAclTable(sai_object_id_t id, sai_object_id_t table_oid, sai_ status = sai_acl_api->create_acl_table_group_member(&group_member_oid, gSwitchId, (uint32_t)member_attrs.size(), member_attrs.data()); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to create member in ACL table group %lx for ACL table %lx, rv:%d", + SWSS_LOG_ERROR("Failed to create member in ACL table group %" PRIx64 " for ACL table %" PRIx64 ", rv:%d", groupOid, table_oid, status); return false; } @@ -1086,7 +1087,7 @@ bool PortsOrch::isSpeedSupported(const std::string& alias, sai_object_id_t port_ if (status == SAI_STATUS_BUFFER_OVERFLOW) { // something went wrong in SAI implementation - SWSS_LOG_ERROR("Failed to get supported speed list for port %s id=%lx. Not enough container size", + SWSS_LOG_ERROR("Failed to get supported speed list for port %s id=%" PRIx64 ". Not enough container size", alias.c_str(), port_id); } else if (SAI_STATUS_IS_ATTR_NOT_SUPPORTED(status) || @@ -1095,12 +1096,12 @@ bool PortsOrch::isSpeedSupported(const std::string& alias, sai_object_id_t port_ { // unable to validate speed if attribute is not supported on platform // assuming input value is correct - SWSS_LOG_WARN("Unable to validate speed for port %s id=%lx. Not supported by platform", + SWSS_LOG_WARN("Unable to validate speed for port %s id=%" PRIx64 ". Not supported by platform", alias.c_str(), port_id); } else { - SWSS_LOG_ERROR("Failed to get a list of supported speeds for port %s id=%lx. Error=%d", + SWSS_LOG_ERROR("Failed to get a list of supported speeds for port %s id=%" PRIx64 ". Error=%d", alias.c_str(), port_id, status); } m_portSupportedSpeeds[port_id] = {}; // use an empty list, @@ -1180,7 +1181,7 @@ bool PortsOrch::getQueueTypeAndIndex(sai_object_id_t queue_id, string &type, uin sai_status_t status = sai_queue_api->get_queue_attribute(queue_id, 2, attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to get queue type and index for queue %lu rv:%d", queue_id, status); + SWSS_LOG_ERROR("Failed to get queue type and index for queue %" PRIu64 " rv:%d", queue_id, status); return false; } @@ -1196,7 +1197,7 @@ bool PortsOrch::getQueueTypeAndIndex(sai_object_id_t queue_id, string &type, uin type = "SAI_QUEUE_TYPE_MULTICAST"; break; default: - SWSS_LOG_ERROR("Got unsupported queue type %d for %lu queue", attr[0].value.s32, queue_id); + SWSS_LOG_ERROR("Got unsupported queue type %d for %" PRIu64 " queue", attr[0].value.s32, queue_id); throw runtime_error("Got unsupported queue type"); } @@ -1223,10 +1224,10 @@ bool PortsOrch::setPortAutoNeg(sai_object_id_t id, int an) sai_status_t status = sai_port_api->set_port_attribute(id, &attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to set AutoNeg %u to port pid:%lx", attr.value.booldata, id); + SWSS_LOG_ERROR("Failed to set AutoNeg %u to port pid:%" PRIx64, attr.value.booldata, id); return false; } - SWSS_LOG_INFO("Set AutoNeg %u to port pid:%lx", attr.value.booldata, id); + SWSS_LOG_INFO("Set AutoNeg %u to port pid:%" PRIx64, attr.value.booldata, id); return true; } @@ -1304,7 +1305,7 @@ bool PortsOrch::addPort(const set &lane_set, uint32_t speed, int an, string m_portListLaneMap[lane_set] = port_id; - SWSS_LOG_NOTICE("Create port %lx with the speed %u", port_id, speed); + SWSS_LOG_NOTICE("Create port %" PRIx64 " with the speed %u", port_id, speed); return true; } @@ -1323,11 +1324,11 @@ bool PortsOrch::removePort(sai_object_id_t port_id) sai_status_t status = sai_port_api->remove_port(port_id); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to remove port %lx, rv:%d", port_id, status); + SWSS_LOG_ERROR("Failed to remove port %" PRIx64 ", rv:%d", port_id, status); return false; } removeAclTableGroup(p); - SWSS_LOG_NOTICE("Remove port %lx", port_id); + SWSS_LOG_NOTICE("Remove port %" PRIx64, port_id); return true; } @@ -1447,11 +1448,11 @@ bool PortsOrch::bake() } portCount = stoul(value); - SWSS_LOG_NOTICE("portCount = %lu, m_portCount = %u", portCount, m_portCount); + SWSS_LOG_NOTICE("portCount = %" PRIu64 ", m_portCount = %u", portCount, m_portCount); if (portCount != keys.size() - 2) { // Invalid port table - SWSS_LOG_ERROR("Invalid port table: portCount, expecting %lu, got %lu", + SWSS_LOG_ERROR("Invalid port table: portCount, expecting %" PRIu64 ", got %" PRIu64, portCount, keys.size() - 2); cleanPortTable(keys); @@ -1645,7 +1646,7 @@ void PortsOrch::doPortTask(Consumer &consumer) } else { - SWSS_LOG_NOTICE("Failed to remove Port %lx due to missing SAI remove_port API.", it->second); + SWSS_LOG_NOTICE("Failed to remove Port %" PRIx64 " due to missing SAI remove_port API.", it->second); } it = m_portListLaneMap.erase(it); @@ -2339,7 +2340,7 @@ void PortsOrch::doLagMemberTask(Consumer &consumer) if (!port.m_lag_id || !port.m_lag_member_id) { - SWSS_LOG_WARN("Member %s not found in LAG %s lid:%lx lmid:%lx,", + SWSS_LOG_WARN("Member %s not found in LAG %s lid:%" PRIx64 " lmid:%" PRIx64 ",", port.m_alias.c_str(), lag.m_alias.c_str(), lag.m_lag_id, port.m_lag_member_id); it = consumer.m_toSync.erase(it); continue; @@ -2468,7 +2469,7 @@ bool PortsOrch::initializePort(Port &port) { SWSS_LOG_ENTER(); - SWSS_LOG_NOTICE("Initializing port alias:%s pid:%lx", port.m_alias.c_str(), port.m_port_id); + SWSS_LOG_NOTICE("Initializing port alias:%s pid:%" PRIx64, port.m_alias.c_str(), port.m_port_id); initializePriorityGroups(port); initializeQueues(port); @@ -2588,10 +2589,10 @@ bool PortsOrch::setBridgePortLearningFDB(Port &port, sai_bridge_port_fdb_learnin auto status = sai_bridge_api->set_bridge_port_attribute(bridge_port_id, &bport_attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to set bridge port %lx learning_mode attribute: %d", bridge_port_id, status); + SWSS_LOG_ERROR("Failed to set bridge port %" PRIx64 " learning_mode attribute: %d", bridge_port_id, status); return false; } - SWSS_LOG_NOTICE("Disable FDB learning on bridge port %s(%lx)", port.m_alias.c_str(), bridge_port_id); + SWSS_LOG_NOTICE("Disable FDB learning on bridge port %s(%" PRIx64 ")", port.m_alias.c_str(), bridge_port_id); return true; } @@ -2820,11 +2821,11 @@ bool PortsOrch::addVlanMember(Port &vlan, Port &port, string &tagging_mode) sai_status_t status = sai_vlan_api->create_vlan_member(&vlan_member_id, gSwitchId, (uint32_t)attrs.size(), attrs.data()); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to add member %s to VLAN %s vid:%hu pid:%lx", + SWSS_LOG_ERROR("Failed to add member %s to VLAN %s vid:%hu pid:%" PRIx64, port.m_alias.c_str(), vlan.m_alias.c_str(), vlan.m_vlan_info.vlan_id, port.m_port_id); return false; } - SWSS_LOG_NOTICE("Add member %s to VLAN %s vid:%hu pid%lx", + SWSS_LOG_NOTICE("Add member %s to VLAN %s vid:%hu pid%" PRIx64, port.m_alias.c_str(), vlan.m_alias.c_str(), vlan.m_vlan_info.vlan_id, port.m_port_id); /* Use untagged VLAN as pvid of the member port */ @@ -2865,12 +2866,12 @@ bool PortsOrch::removeVlanMember(Port &vlan, Port &port) sai_status_t status = sai_vlan_api->remove_vlan_member(vlan_member_id); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to remove member %s from VLAN %s vid:%hx vmid:%lx", + SWSS_LOG_ERROR("Failed to remove member %s from VLAN %s vid:%hx vmid:%" PRIx64, port.m_alias.c_str(), vlan.m_alias.c_str(), vlan.m_vlan_info.vlan_id, vlan_member_id); return false; } port.m_vlan_members.erase(vlan_member); - SWSS_LOG_NOTICE("Remove member %s from VLAN %s lid:%hx vmid:%lx", + SWSS_LOG_NOTICE("Remove member %s from VLAN %s lid:%hx vmid:%" PRIx64, port.m_alias.c_str(), vlan.m_alias.c_str(), vlan.m_vlan_info.vlan_id, vlan_member_id); /* Restore to default pvid if this port joined this VLAN in untagged mode previously */ @@ -2901,11 +2902,11 @@ bool PortsOrch::addLag(string lag_alias) if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to create LAG %s lid:%lx", lag_alias.c_str(), lag_id); + SWSS_LOG_ERROR("Failed to create LAG %s lid:%" PRIx64, lag_alias.c_str(), lag_id); return false; } - SWSS_LOG_NOTICE("Create an empty LAG %s lid:%lx", lag_alias.c_str(), lag_id); + SWSS_LOG_NOTICE("Create an empty LAG %s lid:%" PRIx64, lag_alias.c_str(), lag_id); Port lag(lag_alias, Port::LAG); lag.m_lag_id = lag_id; @@ -2946,13 +2947,13 @@ bool PortsOrch::removeLag(Port lag) sai_status_t status = sai_lag_api->remove_lag(lag.m_lag_id); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to remove LAG %s lid:%lx", lag.m_alias.c_str(), lag.m_lag_id); + SWSS_LOG_ERROR("Failed to remove LAG %s lid:%" PRIx64, lag.m_alias.c_str(), lag.m_lag_id); return false; } removeAclTableGroup(lag); - SWSS_LOG_NOTICE("Remove LAG %s lid:%lx", lag.m_alias.c_str(), lag.m_lag_id); + SWSS_LOG_NOTICE("Remove LAG %s lid:%" PRIx64, lag.m_alias.c_str(), lag.m_lag_id); m_portList.erase(lag.m_alias); m_port_ref_count.erase(lag.m_alias); @@ -3004,12 +3005,12 @@ bool PortsOrch::addLagMember(Port &lag, Port &port) if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to add member %s to LAG %s lid:%lx pid:%lx", + SWSS_LOG_ERROR("Failed to add member %s to LAG %s lid:%" PRIx64 " pid:%" PRIx64, port.m_alias.c_str(), lag.m_alias.c_str(), lag.m_lag_id, port.m_port_id); return false; } - SWSS_LOG_NOTICE("Add member %s to LAG %s lid:%lx pid:%lx", + SWSS_LOG_NOTICE("Add member %s to LAG %s lid:%" PRIx64 " pid:%" PRIx64, port.m_alias.c_str(), lag.m_alias.c_str(), lag.m_lag_id, port.m_port_id); port.m_lag_id = lag.m_lag_id; @@ -3041,12 +3042,12 @@ bool PortsOrch::removeLagMember(Port &lag, Port &port) if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to remove member %s from LAG %s lid:%lx lmid:%lx", + SWSS_LOG_ERROR("Failed to remove member %s from LAG %s lid:%" PRIx64 " lmid:%" PRIx64, port.m_alias.c_str(), lag.m_alias.c_str(), lag.m_lag_id, port.m_lag_member_id); return false; } - SWSS_LOG_NOTICE("Remove member %s from LAG %s lid:%lx lmid:%lx", + SWSS_LOG_NOTICE("Remove member %s from LAG %s lid:%" PRIx64 " lmid:%" PRIx64, port.m_alias.c_str(), lag.m_alias.c_str(), lag.m_lag_id, port.m_lag_member_id); port.m_lag_id = 0; @@ -3250,13 +3251,13 @@ void PortsOrch::doTask(NotificationConsumer &consumer) sai_object_id_t id = portoperstatus[i].port_id; sai_port_oper_status_t status = portoperstatus[i].port_state; - SWSS_LOG_NOTICE("Get port state change notification id:%lx status:%d", id, status); + SWSS_LOG_NOTICE("Get port state change notification id:%" PRIx64 " status:%d", id, status); Port port; if (!getPort(id, port)) { - SWSS_LOG_ERROR("Failed to get port object for port id 0x%lx", id); + SWSS_LOG_ERROR("Failed to get port object for port id 0x%" PRIx64, id); continue; } @@ -3412,7 +3413,7 @@ bool PortsOrch::setPortSerdesAttribute(sai_object_id_t port_id, sai_attr_id_t at sai_status_t status = sai_port_api->set_port_attribute(port_id, &attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to set serdes attribute %d to port pid:%lx", + SWSS_LOG_ERROR("Failed to set serdes attribute %d to port pid:%" PRIx64, attr_id, port_id); return false; } diff --git a/orchagent/qosorch.cpp b/orchagent/qosorch.cpp index 8859f8ef4b..db098ca0e1 100644 --- a/orchagent/qosorch.cpp +++ b/orchagent/qosorch.cpp @@ -3,6 +3,7 @@ #include "logger.h" #include "crmorch.h" +#include #include #include #include @@ -115,7 +116,7 @@ task_process_status QosMapHandler::processWorkItem(Consumer& consumer) } if (!removeQosItem(sai_object)) { - SWSS_LOG_ERROR("Failed to remove dscp_to_tc map. db name:%s sai object:%lx", qos_object_name.c_str(), sai_object); + SWSS_LOG_ERROR("Failed to remove dscp_to_tc map. db name:%s sai object:%" PRIx64, qos_object_name.c_str(), sai_object); return task_process_status::task_failed; } auto it_to_delete = (QosOrch::getTypeMap()[qos_map_type_name])->find(qos_object_name); @@ -144,7 +145,7 @@ bool QosMapHandler::modifyQosItem(sai_object_id_t sai_object, vectorremove_qos_map(sai_object); if (SAI_STATUS_SUCCESS != sai_status) { @@ -204,7 +205,7 @@ sai_object_id_t DscpToTcMapHandler::addQosItem(const vector &at SWSS_LOG_ERROR("Failed to create dscp_to_tc map. status:%d", sai_status); return SAI_NULL_OBJECT_ID; } - SWSS_LOG_DEBUG("created QosMap object:%lx", sai_object); + SWSS_LOG_DEBUG("created QosMap object:%" PRIx64, sai_object); return sai_object; } @@ -910,7 +911,7 @@ task_process_status QosOrch::handleSchedulerTable(Consumer& consumer) sai_status = sai_scheduler_api->remove_scheduler(sai_object); if (SAI_STATUS_SUCCESS != sai_status) { - SWSS_LOG_ERROR("Failed to remove scheduler profile. db name:%s sai object:%lx", qos_object_name.c_str(), sai_object); + SWSS_LOG_ERROR("Failed to remove scheduler profile. db name:%s sai object:%" PRIx64, qos_object_name.c_str(), sai_object); return task_process_status::task_failed; } auto it_to_delete = (m_qos_maps[qos_map_type_name])->find(qos_object_name); @@ -975,7 +976,7 @@ sai_object_id_t QosOrch::getSchedulerGroup(const Port &port, const sai_object_id sai_status = sai_scheduler_group_api->get_scheduler_group_attribute(group_id, 1, &attr); if (SAI_STATUS_SUCCESS != sai_status) { - SWSS_LOG_ERROR("Failed to get child count for scheduler group:0x%lx of port:%s", group_id, port.m_alias.c_str()); + SWSS_LOG_ERROR("Failed to get child count for scheduler group:0x%" PRIx64 " of port:%s", group_id, port.m_alias.c_str()); return SAI_NULL_OBJECT_ID; } @@ -994,7 +995,7 @@ sai_object_id_t QosOrch::getSchedulerGroup(const Port &port, const sai_object_id sai_status = sai_scheduler_group_api->get_scheduler_group_attribute(group_id, 1, &attr); if (SAI_STATUS_SUCCESS != sai_status) { - SWSS_LOG_ERROR("Failed to get child list for scheduler group:0x%lx of port:%s", group_id, port.m_alias.c_str()); + SWSS_LOG_ERROR("Failed to get child list for scheduler group:0x%" PRIx64 " of port:%s", group_id, port.m_alias.c_str()); return SAI_NULL_OBJECT_ID; } @@ -1028,7 +1029,7 @@ bool QosOrch::applySchedulerToQueueSchedulerGroup(Port &port, size_t queue_ind, const sai_object_id_t group_id = getSchedulerGroup(port, queue_id); if(group_id == SAI_NULL_OBJECT_ID) { - SWSS_LOG_ERROR("Failed to find a scheduler group for port: %s queue: %lu", port.m_alias.c_str(), queue_ind); + SWSS_LOG_ERROR("Failed to find a scheduler group for port: %s queue: %" PRIu64, port.m_alias.c_str(), queue_ind); return false; } @@ -1042,11 +1043,11 @@ bool QosOrch::applySchedulerToQueueSchedulerGroup(Port &port, size_t queue_ind, sai_status = sai_scheduler_group_api->set_scheduler_group_attribute(group_id, &attr); if (SAI_STATUS_SUCCESS != sai_status) { - SWSS_LOG_ERROR("Failed applying scheduler profile:0x%lx to scheduler group:0x%lx, port:%s", scheduler_profile_id, group_id, port.m_alias.c_str()); + SWSS_LOG_ERROR("Failed applying scheduler profile:0x%" PRIx64 " to scheduler group:0x%" PRIx64 ", port:%s", scheduler_profile_id, group_id, port.m_alias.c_str()); return false; } - SWSS_LOG_DEBUG("port:%s, scheduler_profile_id:0x%lx applied to scheduler group:0x%lx", port.m_alias.c_str(), scheduler_profile_id, group_id); + SWSS_LOG_DEBUG("port:%s, scheduler_profile_id:0x%" PRIx64 " applied to scheduler group:0x%" PRIx64, port.m_alias.c_str(), scheduler_profile_id, group_id); return true; } @@ -1222,7 +1223,7 @@ bool QosOrch::applyMapToPort(Port &port, sai_attr_id_t attr_id, sai_object_id_t sai_status_t status = sai_port_api->set_port_attribute(port.m_port_id, &attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed setting sai object:%lx for port:%s, status:%d", map_id, port.m_alias.c_str(), status); + SWSS_LOG_ERROR("Failed setting sai object:%" PRIx64 " for port:%s, status:%d", map_id, port.m_alias.c_str(), status); return false; } return true; diff --git a/orchagent/routeorch.cpp b/orchagent/routeorch.cpp index 44af8df375..9a5e5c6ed2 100644 --- a/orchagent/routeorch.cpp +++ b/orchagent/routeorch.cpp @@ -1,4 +1,5 @@ #include +#include #include "routeorch.h" #include "logger.h" #include "swssnet.h" @@ -238,7 +239,7 @@ bool RouteOrch::validnexthopinNextHopGroup(const IpAddress &ipaddr) if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to add next hop member to group %lx: %d\n", + SWSS_LOG_ERROR("Failed to add next hop member to group %" PRIx64 ": %d\n", nhopgroup->second.next_hop_group_id, status); return false; } @@ -271,7 +272,7 @@ bool RouteOrch::invalidnexthopinNextHopGroup(const IpAddress &ipaddr) if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to remove next hop member %lx from group %lx: %d\n", + SWSS_LOG_ERROR("Failed to remove next hop member %" PRIx64 " from group %" PRIx64 ": %d\n", nexthop_id, nhopgroup->second.next_hop_group_id, status); return false; } @@ -626,7 +627,7 @@ bool RouteOrch::addNextHopGroup(IpAddresses ipAddresses) if (status != SAI_STATUS_SUCCESS) { // TODO: do we need to clean up? - SWSS_LOG_ERROR("Failed to create next hop group %lx member %lx: %d\n", + SWSS_LOG_ERROR("Failed to create next hop group %" PRIx64 " member %" PRIx64 ": %d\n", next_hop_group_id, next_hop_group_member_id, status); return false; } @@ -677,7 +678,7 @@ bool RouteOrch::removeNextHopGroup(IpAddresses ipAddresses) if (m_neighOrch->isNextHopFlagSet(nhop->first, NHFLAGS_IFDOWN)) { - SWSS_LOG_WARN("NHFLAGS_IFDOWN set for next hop group member %s with next_hop_id %lx", + SWSS_LOG_WARN("NHFLAGS_IFDOWN set for next hop group member %s with next_hop_id %" PRIx64, nhop->first.to_string().c_str(), nhop->second); nhop = next_hop_group_entry->second.nhopgroup_members.erase(nhop); continue; @@ -685,7 +686,7 @@ bool RouteOrch::removeNextHopGroup(IpAddresses ipAddresses) status = sai_next_hop_group_api->remove_next_hop_group_member(nhop->second); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to remove next hop group member %lx, rv:%d", + SWSS_LOG_ERROR("Failed to remove next hop group member %" PRIx64 ", rv:%d", nhop->second, status); return false; } @@ -697,7 +698,7 @@ bool RouteOrch::removeNextHopGroup(IpAddresses ipAddresses) status = sai_next_hop_group_api->remove_next_hop_group(next_hop_group_id); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to remove next hop group %lx, rv:%d", next_hop_group_id, status); + SWSS_LOG_ERROR("Failed to remove next hop group %" PRIx64 ", rv:%d", next_hop_group_id, status); return false; } diff --git a/orchagent/switchorch.cpp b/orchagent/switchorch.cpp index 4664b49bdb..2a9341acff 100644 --- a/orchagent/switchorch.cpp +++ b/orchagent/switchorch.cpp @@ -1,4 +1,5 @@ #include +#include #include "switchorch.h" #include "converter.h" @@ -200,9 +201,9 @@ bool SwitchOrch::setAgingFDB(uint32_t sec) auto status = sai_switch_api->set_switch_attribute(gSwitchId, &attr); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to set switch %lx fdb_aging_time attribute: %d", gSwitchId, status); + SWSS_LOG_ERROR("Failed to set switch %" PRIx64 " fdb_aging_time attribute: %d", gSwitchId, status); return false; } - SWSS_LOG_NOTICE("Set switch %lx fdb_aging_time %u sec", gSwitchId, sec); + SWSS_LOG_NOTICE("Set switch %" PRIx64 " fdb_aging_time %u sec", gSwitchId, sec); return true; } diff --git a/orchagent/tunneldecaporch.cpp b/orchagent/tunneldecaporch.cpp index f056d5753f..ce75f237ef 100644 --- a/orchagent/tunneldecaporch.cpp +++ b/orchagent/tunneldecaporch.cpp @@ -1,4 +1,5 @@ #include +#include #include "tunneldecaporch.h" #include "portsorch.h" #include "logger.h" @@ -216,7 +217,7 @@ bool TunnelDecapOrch::addDecapTunnel(string key, string type, IpAddresses dst_ip return false; } - SWSS_LOG_NOTICE("Create overlay loopback router interface oid:%lx", overlayIfId); + SWSS_LOG_NOTICE("Create overlay loopback router interface oid:%" PRIx64, overlayIfId); // tunnel type (only ipinip for now) attr.id = SAI_TUNNEL_ATTR_TYPE; @@ -525,7 +526,7 @@ bool TunnelDecapOrch::removeDecapTunnel(string key) status = sai_tunnel_api->remove_tunnel(tunnel_info->tunnel_id); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to remove tunnel: %lu", tunnel_info->tunnel_id); + SWSS_LOG_ERROR("Failed to remove tunnel: %" PRIu64, tunnel_info->tunnel_id); return false; } @@ -533,7 +534,7 @@ bool TunnelDecapOrch::removeDecapTunnel(string key) status = sai_router_intfs_api->remove_router_interface(tunnel_info->overlay_intf_id); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to remove tunnel overlay interface: %lu", tunnel_info->overlay_intf_id); + SWSS_LOG_ERROR("Failed to remove tunnel overlay interface: %" PRIu64, tunnel_info->overlay_intf_id); return false; } @@ -558,7 +559,7 @@ bool TunnelDecapOrch::removeDecapTunnelTermEntry(sai_object_id_t tunnel_term_id, status = sai_tunnel_api->remove_tunnel_term_table_entry(tunnel_term_id); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("Failed to remove tunnel table entry: %lu", tunnel_term_id); + SWSS_LOG_ERROR("Failed to remove tunnel table entry: %" PRIu64, tunnel_term_id); return false; } diff --git a/orchagent/vnetorch.cpp b/orchagent/vnetorch.cpp index cc9be2deca..a0390f25d2 100644 --- a/orchagent/vnetorch.cpp +++ b/orchagent/vnetorch.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "sai.h" #include "saiextensions.h" @@ -103,7 +104,7 @@ bool VNetVrfObject::createObj(vector& attrs) sai_object_id_t router_id; if (vr_type != VR_TYPE::VR_INVALID && l_fn(router_id)) { - SWSS_LOG_DEBUG("VNET vr_type %d router id %lx ", static_cast(vr_type), router_id); + SWSS_LOG_DEBUG("VNET vr_type %d router id %" PRIx64 " ", static_cast(vr_type), router_id); vr_ids_.insert(std::pair(vr_type, router_id)); } } @@ -1669,12 +1670,12 @@ bool VNetRouteOrch::doRouteTask(const string& vnet, IpPrefix& ipP { if (op == SET_COMMAND && !add_route(vr_id, pfx, nh_id)) { - SWSS_LOG_ERROR("Route add failed for %s, vr_id '0x%lx", ipPrefix.to_string().c_str(), vr_id); + SWSS_LOG_ERROR("Route add failed for %s, vr_id '0x%" PRIx64, ipPrefix.to_string().c_str(), vr_id); return false; } else if (op == DEL_COMMAND && !del_route(vr_id, pfx)) { - SWSS_LOG_ERROR("Route del failed for %s, vr_id '0x%lx", ipPrefix.to_string().c_str(), vr_id); + SWSS_LOG_ERROR("Route del failed for %s, vr_id '0x%" PRIx64, ipPrefix.to_string().c_str(), vr_id); return false; } } diff --git a/orchagent/vxlanorch.cpp b/orchagent/vxlanorch.cpp index 8471a34aa4..543cfe1089 100644 --- a/orchagent/vxlanorch.cpp +++ b/orchagent/vxlanorch.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "sai.h" @@ -552,7 +553,7 @@ VxlanTunnelOrch::createNextHopTunnel(string tunnelName, IpAddress& ipAddr, MacAd //Store the nh tunnel id tunnel_obj->updateNextHop(ipAddr, macAddress, vni, nh_id); - SWSS_LOG_INFO("NH vxlan tunnel was created for %s, id 0x%lx", tunnelName.c_str(), nh_id); + SWSS_LOG_INFO("NH vxlan tunnel was created for %s, id 0x%" PRIx64, tunnelName.c_str(), nh_id); return nh_id; } @@ -608,7 +609,7 @@ bool VxlanTunnelOrch::createVxlanTunnelMap(string tunnelName, tunnel_map_type_t tunnel_obj->insertMapperEntry(encap_id, decap_id, vni); - SWSS_LOG_DEBUG("Vxlan tunnel encap entry '%lx' decap entry '0x%lx'", encap_id, decap_id); + SWSS_LOG_DEBUG("Vxlan tunnel encap entry '%" PRIx64 "' decap entry '0x%" PRIx64 "'", encap_id, decap_id); } catch(const std::runtime_error& error) { @@ -651,7 +652,7 @@ bool VxlanTunnelOrch::removeVxlanTunnelMap(string tunnelName, uint32_t vni) remove_tunnel_map_entry(mapper.first); remove_tunnel_map_entry(mapper.second); - SWSS_LOG_DEBUG("Vxlan tunnel encap entry '%lx' decap entry '0x%lx'", mapper.first, mapper.second); + SWSS_LOG_DEBUG("Vxlan tunnel encap entry '%" PRIx64 "' decap entry '0x%" PRIx64 "'", mapper.first, mapper.second); } catch(const std::runtime_error& error) { @@ -895,7 +896,7 @@ bool VxlanVrfMapOrch::addOperation(const Request& request) entry.encap_id = tunnel_obj->addEncapMapperEntry(vrf_id, vni_id); entry.decap_id = tunnel_obj->addDecapMapperEntry(vrf_id, vni_id); - SWSS_LOG_DEBUG("Vxlan tunnel encap entry '%lx' decap entry '0x%lx'", + SWSS_LOG_DEBUG("Vxlan tunnel encap entry '%" PRIx64 "' decap entry '0x%" PRIx64 "'", entry.encap_id, entry.decap_id); vxlan_vrf_table_[full_map_entry_name] = entry; From b4b65d98b4df1e9fc358e43235ea228762886476 Mon Sep 17 00:00:00 2001 From: Antony Rheneus Date: Wed, 24 Jul 2019 00:59:07 +0530 Subject: [PATCH 02/22] ARM32 bit fixes, for 64bit printf format specifier Signed-off-by: Antony Rheneus --- orchagent/bufferorch.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/orchagent/bufferorch.cpp b/orchagent/bufferorch.cpp index 5534c311ea..73a6d2efc4 100644 --- a/orchagent/bufferorch.cpp +++ b/orchagent/bufferorch.cpp @@ -3,6 +3,7 @@ #include "logger.h" #include "sai_serialize.h" +#include #include #include From 1dac55630ed3cbbfb68e58d574eab04245ad7f47 Mon Sep 17 00:00:00 2001 From: Antony Rheneus Date: Wed, 24 Jul 2019 12:04:49 +0530 Subject: [PATCH 03/22] ARM32 bit fixes, for 64bit printf format specifier Signed-off-by: Antony Rheneus --- orchagent/intfsorch.cpp | 3 ++- orchagent/watermarkorch.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/orchagent/intfsorch.cpp b/orchagent/intfsorch.cpp index d9946fa981..79bd100efb 100644 --- a/orchagent/intfsorch.cpp +++ b/orchagent/intfsorch.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "sai_serialize.h" #include "intfsorch.h" @@ -856,7 +857,7 @@ void IntfsOrch::doTask(SelectableTimer &timer) { SWSS_LOG_ENTER(); - SWSS_LOG_DEBUG("Registering %ld new intfs", m_rifsToAdd.size()); + SWSS_LOG_DEBUG("Registering %" PRId64 " new intfs", m_rifsToAdd.size()); string value; for (auto it = m_rifsToAdd.begin(); it != m_rifsToAdd.end(); ) { diff --git a/orchagent/watermarkorch.cpp b/orchagent/watermarkorch.cpp index 0cf746dcd4..b7f01b396c 100644 --- a/orchagent/watermarkorch.cpp +++ b/orchagent/watermarkorch.cpp @@ -4,6 +4,7 @@ #include "notifier.h" #include "converter.h" #include "bufferorch.h" +#include #define DEFAULT_TELEMETRY_INTERVAL 120 @@ -294,7 +295,7 @@ void WatermarkOrch::clearSingleWm(Table *table, string wm_name, vector vfvt = {{wm_name, "0"}}; From b980260a53da218466f19a1308c5a7fa1e92a070 Mon Sep 17 00:00:00 2001 From: Kamil Cudnik Date: Thu, 25 Jul 2019 17:04:49 +0200 Subject: [PATCH 04/22] Add synchronous switch to orch agent (#987) --- orchagent/main.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/orchagent/main.cpp b/orchagent/main.cpp index 620103dc7a..34cd7c17c1 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -47,12 +47,14 @@ int gBatchSize = DEFAULT_BATCH_SIZE; bool gSairedisRecord = true; bool gSwssRecord = true; bool gLogRotate = false; +bool gSyncMode = false; + ofstream gRecordOfs; string gRecordFile; void usage() { - cout << "usage: orchagent [-h] [-r record_type] [-d record_location] [-b batch_size] [-m MAC]" << endl; + cout << "usage: orchagent [-h] [-r record_type] [-d record_location] [-b batch_size] [-m MAC] [-s]" << endl; cout << " -h: display this message" << endl; cout << " -r record_type: record orchagent logs with type (default 3)" << endl; cout << " 0: do not record logs" << endl; @@ -62,6 +64,7 @@ void usage() cout << " -d record_location: set record logs folder location (default .)" << endl; cout << " -b batch_size: set consumer table pop operation batch size (default 128)" << endl; cout << " -m MAC: set switch MAC address" << endl; + cout << " -s: enable synchronous mode" << endl; } void sighup_handler(int signo) @@ -118,7 +121,7 @@ int main(int argc, char **argv) string record_location = "."; - while ((opt = getopt(argc, argv, "b:m:r:d:h")) != -1) + while ((opt = getopt(argc, argv, "b:m:r:d:hs")) != -1) { switch (opt) { @@ -163,6 +166,11 @@ int main(int argc, char **argv) case 'h': usage(); exit(EXIT_SUCCESS); + case 's': + gSyncMode = true; + SWSS_LOG_NOTICE("Enabling synchronous mode"); + break; + default: /* '?' */ exit(EXIT_FAILURE); } @@ -220,6 +228,14 @@ int main(int argc, char **argv) } SWSS_LOG_NOTICE("Create a switch"); + if (gSyncMode) + { + attr.id = SAI_REDIS_SWITCH_ATTR_SYNC_MODE; + attr.value.booldata = true; + + sai_switch_api->set_switch_attribute(gSwitchId, &attr); + } + /* Get switch source MAC address if not provided */ if (!gMacAddress) { From b5ffa3ea5d28408c617a7b9125379fa3542140dc Mon Sep 17 00:00:00 2001 From: Shuotian Cheng Date: Thu, 25 Jul 2019 09:46:20 -0700 Subject: [PATCH 05/22] [test]: Update test_vlan to use dvs functions (#986) Signed-off-by: Shu0t1an Cheng --- tests/test_vlan.py | 185 +++++++++++++++++++++------------------------ 1 file changed, 86 insertions(+), 99 deletions(-) diff --git a/tests/test_vlan.py b/tests/test_vlan.py index 0bc12af549..aa0df6c122 100644 --- a/tests/test_vlan.py +++ b/tests/test_vlan.py @@ -8,45 +8,18 @@ class TestVlan(object): - def setup_db(self, dvs): - self.pdb = swsscommon.DBConnector(0, dvs.redis_sock, 0) - self.adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - self.cdb = swsscommon.DBConnector(4, dvs.redis_sock, 0) - - def create_vlan(self, vlan): - tbl = swsscommon.Table(self.cdb, "VLAN") - fvs = swsscommon.FieldValuePairs([("vlanid", vlan)]) - tbl.set("Vlan" + vlan, fvs) - time.sleep(1) - - def remove_vlan(self, vlan): - tbl = swsscommon.Table(self.cdb, "VLAN") - tbl._del("Vlan" + vlan) - time.sleep(1) - - def create_vlan_member(self, vlan, interface): - tbl = swsscommon.Table(self.cdb, "VLAN_MEMBER") - fvs = swsscommon.FieldValuePairs([("tagging_mode", "untagged")]) - tbl.set("Vlan" + vlan + "|" + interface, fvs) - time.sleep(1) - - def remove_vlan_member(self, vlan, interface): - tbl = swsscommon.Table(self.cdb, "VLAN_MEMBER") - tbl._del("Vlan" + vlan + "|" + interface) - time.sleep(1) - def check_syslog(self, dvs, marker, process, err_log, vlan_str, expected_cnt): (exitcode, num) = dvs.runcmd(['sh', '-c', "awk \'/%s/,ENDFILE {print;}\' /var/log/syslog | grep %s | grep \"%s\" | grep -i %s | wc -l" % (marker, process, err_log, vlan_str)]) assert num.strip() == str(expected_cnt) def test_VlanAddRemove(self, dvs, testlog): - self.setup_db(dvs) + dvs.setup_db() # create vlan - self.create_vlan("2") + dvs.create_vlan("2") # check asic database - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") vlan_entries = [k for k in tbl.getKeys() if k != dvs.asicdb.default_vlan_id] assert len(vlan_entries) == 1 vlan_oid = vlan_entries[0] @@ -58,11 +31,11 @@ def test_VlanAddRemove(self, dvs, testlog): assert fv[1] == "2" # create vlan member - self.create_vlan_member("2", "Ethernet0") + dvs.create_vlan_member("2", "Ethernet0") # check asic database bridge_port_map = {} - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") bridge_port_entries = tbl.getKeys() for key in bridge_port_entries: (status, fvs) = tbl.get(key) @@ -71,7 +44,7 @@ def test_VlanAddRemove(self, dvs, testlog): if fv[0] == "SAI_BRIDGE_PORT_ATTR_PORT_ID": bridge_port_map[key] = fv[1] - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") vlan_member_entries = tbl.getKeys() assert len(vlan_member_entries) == 1 @@ -89,7 +62,7 @@ def test_VlanAddRemove(self, dvs, testlog): assert False # check port pvid - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") (status, fvs) = tbl.get(dvs.asicdb.portnamemap["Ethernet0"]) assert status == True assert "SAI_PORT_ATTR_PORT_VLAN_ID" in [fv[0] for fv in fvs] @@ -98,7 +71,7 @@ def test_VlanAddRemove(self, dvs, testlog): assert fv[1] == "2" # check host interface vlan tag - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF") (status, fvs) = tbl.get(dvs.asicdb.hostifnamemap["Ethernet0"]) assert status == True assert "SAI_HOSTIF_ATTR_VLAN_TAG" in [fv[0] for fv in fvs] @@ -107,87 +80,87 @@ def test_VlanAddRemove(self, dvs, testlog): assert fv[1] == "SAI_HOSTIF_VLAN_TAG_KEEP" # remove vlan member - self.remove_vlan_member("2", "Ethernet0") + dvs.remove_vlan_member("2", "Ethernet0") - # remvoe vlan - self.remove_vlan("2") + # remove vlan + dvs.remove_vlan("2") def test_MultipleVlan(self, dvs, testlog): return - self.setup_db(dvs) + dvs.setup_db() # create vlan and vlan members - self.create_vlan("18") - self.create_vlan_member("18", "Ethernet0") - self.create_vlan_member("18", "Ethernet4") - self.create_vlan_member("18", "Ethernet8") + dvs.create_vlan("18") + dvs.create_vlan_member("18", "Ethernet0") + dvs.create_vlan_member("18", "Ethernet4") + dvs.create_vlan_member("18", "Ethernet8") # check asic database - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") vlan_entries = [k for k in tbl.getKeys() if k != dvs.asicdb.default_vlan_id] assert len(vlan_entries) == 1 - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") vlan_member_entries = tbl.getKeys() assert len(vlan_member_entries) == 3 # remove vlan members - self.remove_vlan_member("18", "Ethernet0") - self.remove_vlan_member("18", "Ethernet4") - self.remove_vlan_member("18", "Ethernet8") + dvs.remove_vlan_member("18", "Ethernet0") + dvs.remove_vlan_member("18", "Ethernet4") + dvs.remove_vlan_member("18", "Ethernet8") - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") vlan_member_entries = tbl.getKeys() assert len(vlan_member_entries) == 0 # create vlan and vlan members - self.create_vlan("188") - self.create_vlan_member("188", "Ethernet20") - self.create_vlan_member("188", "Ethernet24") - self.create_vlan_member("188", "Ethernet28") + dvs.create_vlan("188") + dvs.create_vlan_member("188", "Ethernet20") + dvs.create_vlan_member("188", "Ethernet24") + dvs.create_vlan_member("188", "Ethernet28") # check asic database - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") vlan_entries = [k for k in tbl.getKeys() if k != dvs.asicdb.default_vlan_id] assert len(vlan_entries) == 2 - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") vlan_member_entries = tbl.getKeys() assert len(vlan_member_entries) == 3 # create vlan members - self.create_vlan_member("18", "Ethernet40") - self.create_vlan_member("18", "Ethernet44") - self.create_vlan_member("18", "Ethernet48") + dvs.create_vlan_member("18", "Ethernet40") + dvs.create_vlan_member("18", "Ethernet44") + dvs.create_vlan_member("18", "Ethernet48") - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") vlan_member_entries = tbl.getKeys() assert len(vlan_member_entries) == 6 # remove vlan members - self.remove_vlan_member("18", "Ethernet40") - self.remove_vlan_member("18", "Ethernet44") - self.remove_vlan_member("18", "Ethernet48") + dvs.remove_vlan_member("18", "Ethernet40") + dvs.remove_vlan_member("18", "Ethernet44") + dvs.remove_vlan_member("18", "Ethernet48") - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") vlan_member_entries = tbl.getKeys() assert len(vlan_member_entries) == 3 # remove vlan members - self.remove_vlan_member("188", "Ethernet20") - self.remove_vlan_member("188", "Ethernet24") - self.remove_vlan_member("188", "Ethernet28") + dvs.remove_vlan_member("188", "Ethernet20") + dvs.remove_vlan_member("188", "Ethernet24") + dvs.remove_vlan_member("188", "Ethernet28") - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") vlan_member_entries = tbl.getKeys() assert len(vlan_member_entries) == 0 # remove vlans - self.remove_vlan("18") - self.remove_vlan("188") + dvs.remove_vlan("18") + dvs.remove_vlan("188") # check asic database - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") vlan_entries = [k for k in tbl.getKeys() if k != dvs.asicdb.default_vlan_id] assert len(vlan_entries) == 0 @@ -298,7 +271,7 @@ def test_VlanIncrementalConfig(self, dvs, testlog): # remove vlan member dvs.remove_vlan_member("2", "Ethernet0") - # remvoe vlan + # remove vlan dvs.remove_vlan("2") @@ -310,19 +283,19 @@ def test_VlanIncrementalConfig(self, dvs, testlog): (["Vlan", "5"], 1), ]) def test_AddVlanWithIncorrectKeyPrefix(self, dvs, testlog, test_input, expected): - self.setup_db(dvs) + dvs.setup_db() marker = dvs.add_log_marker() vlan_prefix = test_input[0] vlan = test_input[1] # create vlan - tbl = swsscommon.Table(self.cdb, "VLAN") + tbl = swsscommon.Table(dvs.cdb, "VLAN") fvs = swsscommon.FieldValuePairs([("vlanid", vlan)]) tbl.set(vlan_prefix + vlan, fvs) time.sleep(1) # check asic database - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") vlan_entries = [k for k in tbl.getKeys() if k != dvs.asicdb.default_vlan_id] assert len(vlan_entries) == expected @@ -331,7 +304,7 @@ def test_AddVlanWithIncorrectKeyPrefix(self, dvs, testlog, test_input, expected) self.check_syslog(dvs, marker, "vlanmgrd", "Invalid key format. No 'Vlan' prefix:", vlan_prefix+vlan, 1) else: #remove vlan - self.remove_vlan(vlan) + dvs.remove_vlan(vlan) @pytest.mark.skipif(StrictVersion(platform.linux_distribution()[1]) <= StrictVersion('8.9'), reason="Debian 8.9 or before has no support") @pytest.mark.parametrize("test_input, expected", [ @@ -341,19 +314,19 @@ def test_AddVlanWithIncorrectKeyPrefix(self, dvs, testlog, test_input, expected) (["Vlan", "5"], 1), ]) def test_AddVlanWithIncorrectValueType(self, dvs, testlog, test_input, expected): - self.setup_db(dvs) + dvs.setup_db() marker = dvs.add_log_marker() vlan_prefix = test_input[0] vlan = test_input[1] # create vlan - tbl = swsscommon.Table(self.cdb, "VLAN") + tbl = swsscommon.Table(dvs.cdb, "VLAN") fvs = swsscommon.FieldValuePairs([("vlanid", vlan)]) tbl.set(vlan_prefix + vlan, fvs) time.sleep(1) # check asic database - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") vlan_entries = [k for k in tbl.getKeys() if k != dvs.asicdb.default_vlan_id] assert len(vlan_entries) == expected @@ -362,55 +335,55 @@ def test_AddVlanWithIncorrectValueType(self, dvs, testlog, test_input, expected) self.check_syslog(dvs, marker, "vlanmgrd", "Invalid key format. Not a number after \'Vlan\' prefix:", vlan_prefix+vlan, 1) else: #remove vlan - self.remove_vlan(vlan) + dvs.remove_vlan(vlan) def test_AddVlanMemberWithNonExistVlan(self, dvs, testlog): - self.setup_db(dvs) + dvs.setup_db() marker = dvs.add_log_marker() vlan = "2" # create vlan member - self.create_vlan_member(vlan, "Ethernet0") + dvs.create_vlan_member(vlan, "Ethernet0") # check asic database - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") vlan_entries = [k for k in tbl.getKeys() if k != dvs.asicdb.default_vlan_id] assert len(vlan_entries) == 0 - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") vlan_member_entries = tbl.getKeys() assert len(vlan_member_entries) == 0 # remove vlan member from cfgdb - self.remove_vlan_member(vlan, "Ethernet0") + dvs.remove_vlan_member(vlan, "Ethernet0") def test_RemoveNonexistentVlan(self, dvs, testlog): - self.setup_db(dvs) + dvs.setup_db() marker = dvs.add_log_marker() vlan = "2" # check asic database - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") vlan_entries = [k for k in tbl.getKeys() if k != dvs.asicdb.default_vlan_id] assert len(vlan_entries) == 0 # remove nonexistent vlan - self.remove_vlan(vlan) + dvs.remove_vlan(vlan) # create vlan - self.create_vlan(vlan) + dvs.create_vlan(vlan) # check asic database - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") vlan_entries = [k for k in tbl.getKeys() if k != dvs.asicdb.default_vlan_id] assert len(vlan_entries) == 1 # remove vlan - self.remove_vlan(vlan) + dvs.remove_vlan(vlan) @pytest.mark.skip(reason="AddMaxVlan take too long to execute") def test_AddMaxVlan(self, dvs, testlog): - self.setup_db(dvs) + dvs.setup_db() min_vid = 2 max_vid = 4094 @@ -418,22 +391,22 @@ def test_AddMaxVlan(self, dvs, testlog): # create max vlan vlan = min_vid while vlan <= max_vid: - self.create_vlan(str(vlan)) + dvs.create_vlan(str(vlan)) vlan += 1 # check asic database - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") vlan_entries = [k for k in tbl.getKeys() if k != dvs.asicdb.default_vlan_id] assert len(vlan_entries) == (4094-1) # remove all vlan vlan = min_vid while vlan <= max_vid: - self.remove_vlan(str(vlan)) + dvs.remove_vlan(str(vlan)) vlan += 1 # check asic database - tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") vlan_entries = [k for k in tbl.getKeys() if k != dvs.asicdb.default_vlan_id] assert len(vlan_entries) == 0 @@ -465,14 +438,28 @@ def test_RemoveVlanWithRouterInterface(self, dvs, testlog): # one loopback router interface one vlan based router interface assert len(intf_entries) == 2 - # remvoe vlan + # remove vlan dvs.remove_vlan("100") - # check error log - self.check_syslog(dvs, marker, "orchagent", "Failed to remove ref count", "Vlan100", 1) + # check asic database still contains the vlan + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + vlan_entries = [k for k in tbl.getKeys() if k != dvs.asicdb.default_vlan_id] + assert len(vlan_entries) == 1 + vlan_oid = vlan_entries[0] + + (status, fvs) = tbl.get(vlan_oid) + assert status == True + for fv in fvs: + if fv[0] == "SAI_VLAN_ATTR_VLAN_ID": + assert fv[1] == "100" # remove IP from interface dvs.remove_ip_address("Vlan100", "20.0.0.8/29") - # remvoe vlan + # remove vlan dvs.remove_vlan("100") + + # check asic database does not contain the vlan anymore + tbl = swsscommon.Table(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + vlan_entries = [k for k in tbl.getKeys() if k != dvs.asicdb.default_vlan_id] + assert len(vlan_entries) == 0 From c764b05bb8db14e82e3c5608db3229d9912268c0 Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Thu, 25 Jul 2019 13:29:52 -0700 Subject: [PATCH 06/22] Support per buffer pool watermark polling mode (#973) Buffer pool watermark design is built on a READ_AND_CLEAR polling mode at the syncd level. We observe some SAI implementation is missing the clear_stats operation support for buffer pool watermark, either simply not coded yet or having hardware limitation. In such cases, we have mismatch between the actual polling behavior and what a user perceives from FLEX_COUNTER_DB read from FLEX_COUNTER_GROUP_TABLE. To have a consistent view, we propose per buffer pool watermark stats polling mode at the orchagent level when not all buffer pools support clear_stats operation on a switch. The situation is detected by issuing clear_stats operation at the orchagent level to probe the capability over all pools first. If this is truly the case, we then do not set "STATS_MODE" field in "FLEX_COUNTER_GROUP_TABLE:BUFFER_POOL_WATERMARK_STAT_COUNTER", but set it to the per buffer pool table "FLEX_COUNTER_TABLE:BUFFER_POOL_WATERMARK_STAT_COUNTER:oid:". --- orchagent/bufferorch.cpp | 57 +++++++++++++++++++++++++++++++++------ orchagent/portsorch.cpp | 4 +-- orchagent/watermarkorch.h | 2 +- 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/orchagent/bufferorch.cpp b/orchagent/bufferorch.cpp index 73a6d2efc4..c560551bca 100644 --- a/orchagent/bufferorch.cpp +++ b/orchagent/bufferorch.cpp @@ -111,11 +111,6 @@ void BufferOrch::initFlexCounterGroupTable(void) fvTuples.emplace_back(BUFFER_POOL_PLUGIN_FIELD, bufferPoolWmSha); fvTuples.emplace_back(POLL_INTERVAL_FIELD, BUFFER_POOL_WATERMARK_FLEX_STAT_COUNTER_POLL_MSECS); - // TODO (work in progress): - // Some platforms do not support buffer pool watermark clear operation on a particular pool - // Invoke the SAI clear_stats API per pool to query the capability from the API call return status - fvTuples.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ_AND_CLEAR); - m_flexCounterGroupTable->set(BUFFER_POOL_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP, fvTuples); } catch (const runtime_error &e) @@ -171,14 +166,60 @@ void BufferOrch::generateBufferPoolWatermarkCounterIdList(void) statList.pop_back(); } - vector fvTuples; - fvTuples.emplace_back(BUFFER_POOL_COUNTER_ID_LIST, statList); + // Some platforms do not support buffer pool watermark clear operation on a particular pool + // Invoke the SAI clear_stats API per pool to query the capability from the API call return status + // We use bit mask to mark the clear watermark capability of each buffer pool. We use an unsigned int to place hold + // these bits. This assumes the total number of buffer pools to be no greater than 32, which should satisfy all use cases. + unsigned int noWmClrCapability = 0; + unsigned int bitMask = 1; + for (const auto &it : *(m_buffer_type_maps[CFG_BUFFER_POOL_TABLE_NAME])) + { + sai_status_t status = sai_buffer_api->clear_buffer_pool_stats( + it.second, + static_cast(bufferPoolWatermarkStatIds.size()), + reinterpret_cast(bufferPoolWatermarkStatIds.data())); + if (status == SAI_STATUS_NOT_SUPPORTED || status == SAI_STATUS_NOT_IMPLEMENTED) + { + SWSS_LOG_NOTICE("Clear watermark failed on %s, rv: %s", it.first.c_str(), sai_serialize_status(status).c_str()); + noWmClrCapability |= bitMask; + } + + bitMask <<= 1; + } + + if (!noWmClrCapability) + { + vector fvs; + + fvs.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ_AND_CLEAR); + m_flexCounterGroupTable->set(BUFFER_POOL_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP, fvs); + } // Push buffer pool watermark COUNTER_ID_LIST to FLEX_COUNTER_TABLE on a per buffer pool basis + vector fvTuples; + fvTuples.emplace_back(BUFFER_POOL_COUNTER_ID_LIST, statList); + bitMask = 1; for (const auto &it : *(m_buffer_type_maps[CFG_BUFFER_POOL_TABLE_NAME])) { string key = BUFFER_POOL_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP ":" + sai_serialize_object_id(it.second); - m_flexCounterTable->set(key, fvTuples); + + if (noWmClrCapability) + { + string stats_mode = STATS_MODE_READ_AND_CLEAR; + if (noWmClrCapability & bitMask) + { + stats_mode = STATS_MODE_READ; + } + fvTuples.emplace_back(STATS_MODE_FIELD, stats_mode); + + m_flexCounterTable->set(key, fvTuples); + fvTuples.pop_back(); + bitMask <<= 1; + } + else + { + m_flexCounterTable->set(key, fvTuples); + } } m_isBufferPoolWatermarkCounterIdListGenerated = true; diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index b2a796c5f7..75e862300f 100644 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -199,9 +199,9 @@ PortsOrch::PortsOrch(DBConnector *db, vector &tableNames) fieldValues.emplace_back(STATS_MODE_FIELD, STATS_MODE_READ_AND_CLEAR); m_flexCounterGroupTable->set(PG_WATERMARK_STAT_COUNTER_FLEX_COUNTER_GROUP, fieldValues); } - catch (...) + catch (const runtime_error &e) { - SWSS_LOG_WARN("Watermark flex counter groups were not set successfully"); + SWSS_LOG_ERROR("Watermark flex counter groups were not set successfully: %s", e.what()); } uint32_t i, j; diff --git a/orchagent/watermarkorch.h b/orchagent/watermarkorch.h index 27ac112eb1..35279efbab 100644 --- a/orchagent/watermarkorch.h +++ b/orchagent/watermarkorch.h @@ -51,7 +51,7 @@ class WatermarkOrch : public Orch /* [7-2] - unused [1] - pg wm status - [0] - queue wm status (least significant bit) + [0] - queue wm status (least significant bit) */ uint8_t m_wmStatus = 0; bool m_timerChanged = false; From c679b0b0a0664660ac42c2775cdec32249dc4a9b Mon Sep 17 00:00:00 2001 From: lguohan Date: Thu, 25 Jul 2019 15:28:45 -0700 Subject: [PATCH 07/22] [vstest]: report error when team kernel module is not available (#994) make explicit failure if team kernel module is not available on the system Signed-off-by: Guohan Lu --- tests/conftest.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index a4d8ecb9e3..36189dbd22 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -158,6 +158,9 @@ def __init__(self, name=None, keeptb=False, fakeplatform=None): self.alld = self.basicd + self.swssd + self.syncd + self.rtd + self.teamd self.client = docker.from_env() + if subprocess.check_call(["/sbin/modprobe", "team"]) != 0: + raise NameError("cannot install kernel team module") + self.ctn = None if keeptb: self.cleanup = False From d7f6c0205576de56f6f91be76740c1c4a3ca188d Mon Sep 17 00:00:00 2001 From: Teng Fei Date: Fri, 26 Jul 2019 06:49:19 +0800 Subject: [PATCH 08/22] [qosorch]: Add cir and pir parameters for scheduler (#991) Signed-off-by: tengfei --- orchagent/qosorch.cpp | 24 ++++++++++++++++++++++++ orchagent/qosorch.h | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/orchagent/qosorch.cpp b/orchagent/qosorch.cpp index 4add06b87b..0486ad3af6 100644 --- a/orchagent/qosorch.cpp +++ b/orchagent/qosorch.cpp @@ -870,6 +870,30 @@ task_process_status QosOrch::handleSchedulerTable(Consumer& consumer) // TODO: The meaning is to be able to adjus priority of the given scheduler group. // However currently SAI model does not provide such ability. } + else if (fvField(*i) == scheduler_min_bandwidth_rate_field_name) + { + attr.id = SAI_SCHEDULER_ATTR_MIN_BANDWIDTH_RATE; + attr.value.u64 = (uint64_t)stoi(fvValue(*i)); + sai_attr_list.push_back(attr); + } + else if (fvField(*i) == scheduler_min_bandwidth_burst_rate_field_name) + { + attr.id = SAI_SCHEDULER_ATTR_MIN_BANDWIDTH_BURST_RATE; + attr.value.u64 = (uint64_t)stoi(fvValue(*i)); + sai_attr_list.push_back(attr); + } + else if (fvField(*i) == scheduler_max_bandwidth_rate_field_name) + { + attr.id = SAI_SCHEDULER_ATTR_MAX_BANDWIDTH_RATE; + attr.value.u64 = (uint64_t)stoi(fvValue(*i)); + sai_attr_list.push_back(attr); + } + else if (fvField(*i) == scheduler_max_bandwidth_burst_rate_field_name) + { + attr.id = SAI_SCHEDULER_ATTR_MAX_BANDWIDTH_BURST_RATE; + attr.value.u64 = (uint64_t)stoi(fvValue(*i)); + sai_attr_list.push_back(attr); + } else { SWSS_LOG_ERROR("Unknown field:%s", fvField(*i).c_str()); return task_process_status::task_invalid_entry; diff --git a/orchagent/qosorch.h b/orchagent/qosorch.h index 9d8a81b8f0..079260c5d5 100644 --- a/orchagent/qosorch.h +++ b/orchagent/qosorch.h @@ -36,6 +36,11 @@ const string scheduler_algo_STRICT = "STRICT"; const string scheduler_weight_field_name = "weight"; const string scheduler_priority_field_name = "priority"; +const string scheduler_min_bandwidth_rate_field_name = "cir";//Committed Information Rate +const string scheduler_min_bandwidth_burst_rate_field_name = "cbs";//Committed Burst Size +const string scheduler_max_bandwidth_rate_field_name = "pir";//Peak Information Rate +const string scheduler_max_bandwidth_burst_rate_field_name = "pbs";//Peak Burst Size + const string ecn_field_name = "ecn"; const string ecn_none = "ecn_none"; const string ecn_red = "ecn_red"; From 77e4126f5b6cd8d652674a2f36c38eadf74e0a2b Mon Sep 17 00:00:00 2001 From: lguohan Date: Fri, 26 Jul 2019 22:16:59 -0700 Subject: [PATCH 09/22] [vstest]: add --imgname option to specify vs image to test (#996) default image is docker-sonic-vs:latest Signed-off-by: Guohan Lu --- tests/conftest.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 36189dbd22..c510e441cd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -23,6 +23,8 @@ def pytest_addoption(parser): help="dvs name") parser.addoption("--keeptb", action="store_true", default=False, help="keep testbed after test") + parser.addoption("--imgname", action="store", default="docker-sonic-vs", + help="image name") class AsicDbValidator(object): def __init__(self, dvs): @@ -142,7 +144,7 @@ def runcmd_output(self, cmd): return subprocess.check_output("ip netns exec %s %s" % (self.nsname, cmd), shell=True) class DockerVirtualSwitch(object): - def __init__(self, name=None, keeptb=False, fakeplatform=None): + def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None): self.basicd = ['redis-server', 'rsyslogd'] self.swssd = ['orchagent', @@ -214,7 +216,7 @@ def __init__(self, name=None, keeptb=False, fakeplatform=None): self.environment = ["fake_platform={}".format(fakeplatform)] if fakeplatform else [] # create virtual switch container - self.ctn = self.client.containers.run('docker-sonic-vs', privileged=True, detach=True, + self.ctn = self.client.containers.run(imgname, privileged=True, detach=True, environment=self.environment, network_mode="container:%s" % self.ctn_sw.name, volumes={ self.mount: { 'bind': '/var/run/redis', 'mode': 'rw' } }) @@ -794,8 +796,9 @@ def setReadOnlyAttr(self, obj, attr, val): def dvs(request): name = request.config.getoption("--dvsname") keeptb = request.config.getoption("--keeptb") + imgname = request.config.getoption("--imgname") fakeplatform = getattr(request.module, "DVS_FAKE_PLATFORM", None) - dvs = DockerVirtualSwitch(name, keeptb, fakeplatform) + dvs = DockerVirtualSwitch(name, imgname, keeptb, fakeplatform) yield dvs if name == None: dvs.get_logs(request.module.__name__) From 6bb0924ce921619d5beea00123fc0f8ce2bfaf6c Mon Sep 17 00:00:00 2001 From: Shuotian Cheng Date: Sun, 28 Jul 2019 14:15:43 -0700 Subject: [PATCH 10/22] [test]: Add Class object in each test script file (#992) This is to get a better JUnitXML file and align all the tests under the same level of hierarchy. Signed-off-by: Shu0T1an ChenG --- tests/test_crm.py | 804 ++++----- tests/test_dirbcast.py | 131 +- tests/test_fdb.py | 374 ++++ tests/test_fdb_cold.py | 80 - tests/test_fdb_warm.py | 318 ---- tests/test_nhg.py | 190 +- tests/test_pfc.py | 60 +- tests/test_port.py | 252 +-- tests/test_port_an.py | 173 ++ tests/test_port_an_cold.py | 85 - tests/test_port_an_warm.py | 90 - tests/test_port_buffer_rel.py | 50 +- tests/test_portchannel.py | 79 +- tests/test_route.py | 53 +- tests/test_setro.py | 39 +- tests/test_vrf.py | 168 +- tests/test_vxlan_tunnel.py | 98 +- tests/test_warm_reboot.py | 3103 +++++++++++++++++---------------- 18 files changed, 3063 insertions(+), 3084 deletions(-) create mode 100644 tests/test_fdb.py delete mode 100644 tests/test_fdb_cold.py delete mode 100644 tests/test_fdb_warm.py create mode 100644 tests/test_port_an.py delete mode 100644 tests/test_port_an_cold.py delete mode 100644 tests/test_port_an_warm.py diff --git a/tests/test_crm.py b/tests/test_crm.py index bd4db74c5f..c12a1a1d75 100644 --- a/tests/test_crm.py +++ b/tests/test_crm.py @@ -40,583 +40,583 @@ def setReadOnlyAttr(dvs, obj, attr, val): ntf.send("set_ro", key, fvp) +class TestCrm(object): + def test_CrmFdbEntry(self, dvs, testlog): -def test_CrmFdbEntry(dvs, testlog): + # disable ipv6 on Ethernet8 neighbor as once ipv6 link-local address is + # configured, server 2 will send packet which can switch to learn another + # mac and fail the test. + dvs.servers[2].runcmd("sysctl -w net.ipv6.conf.eth0.disable_ipv6=1") + dvs.runcmd("crm config polling interval 1") - # disable ipv6 on Ethernet8 neighbor as once ipv6 link-local address is - # configured, server 2 will send packet which can switch to learn another - # mac and fail the test. - dvs.servers[2].runcmd("sysctl -w net.ipv6.conf.eth0.disable_ipv6=1") - dvs.runcmd("crm config polling interval 1") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000') - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_used') + avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_available') - # get counters - used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_used') - avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_available') + app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + cfg_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - cfg_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + # create a FDB entry + tbl = swsscommon.ProducerStateTable(app_db, "FDB_TABLE") + fvs = swsscommon.FieldValuePairs([("port","Ethernet8"),("type","dynamic")]) + tbl.set("Vlan2:52-54-00-25-06-E9", fvs) - # create a FDB entry - tbl = swsscommon.ProducerStateTable(app_db, "FDB_TABLE") - fvs = swsscommon.FieldValuePairs([("port","Ethernet8"),("type","dynamic")]) - tbl.set("Vlan2:52-54-00-25-06-E9", fvs) + # create vlan + tbl = swsscommon.Table(cfg_db, "VLAN") + fvs = swsscommon.FieldValuePairs([("vlanid", "2")]) + tbl.set("Vlan2", fvs) - # create vlan - tbl = swsscommon.Table(cfg_db, "VLAN") - fvs = swsscommon.FieldValuePairs([("vlanid", "2")]) - tbl.set("Vlan2", fvs) + # create vlan member + tbl = swsscommon.Table(cfg_db, "VLAN_MEMBER") + fvs = swsscommon.FieldValuePairs([("tagging_mode", "untagged")]) + tbl.set("Vlan2|Ethernet8", fvs) - # create vlan member - tbl = swsscommon.Table(cfg_db, "VLAN_MEMBER") - fvs = swsscommon.FieldValuePairs([("tagging_mode", "untagged")]) - tbl.set("Vlan2|Ethernet8", fvs) + # update available counter + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '999') - # update available counter - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '999') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_available') + assert new_used_counter - used_counter == 1 + assert avail_counter - new_avail_counter == 1 - assert new_used_counter - used_counter == 1 - assert avail_counter - new_avail_counter == 1 + # update available counter + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000') - # update available counter - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_available') - # get counters - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_available') + assert new_avail_counter == avail_counter - assert new_avail_counter == avail_counter + # enable ipv6 on server 2 + dvs.servers[2].runcmd("sysctl -w net.ipv6.conf.eth0.disable_ipv6=0") - # enable ipv6 on server 2 - dvs.servers[2].runcmd("sysctl -w net.ipv6.conf.eth0.disable_ipv6=0") + def test_CrmIpv4Route(self, dvs, testlog): -def test_CrmIpv4Route(dvs, testlog): + 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", fvs) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + dvs.runcmd("ifconfig Ethernet0 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", fvs) - intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) - dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("crm config polling interval 1") - dvs.runcmd("crm config polling interval 1") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '1000') - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '1000') + # add static neighbor + dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - # add static neighbor - dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") + fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1"), ("ifname", "Ethernet0")]) - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") - fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1"), ("ifname", "Ethernet0")]) + time.sleep(2) - time.sleep(2) + # get counters + used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_used') + avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_available') - # get counters - used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_used') - avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_available') + # add route and update available counter + ps.set("2.2.2.0/24", fvs) + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '999') - # add route and update available counter - ps.set("2.2.2.0/24", fvs) - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '999') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_available') + assert new_used_counter - used_counter == 1 + assert avail_counter - new_avail_counter == 1 - assert new_used_counter - used_counter == 1 - assert avail_counter - new_avail_counter == 1 + # remove route and update available counter + ps._del("2.2.2.0/24") + dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '1000') - # remove route and update available counter - ps._del("2.2.2.0/24") - dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_route_available') + assert new_used_counter == used_counter + assert new_avail_counter == avail_counter - assert new_used_counter == used_counter - assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|10.0.0.0/31") + time.sleep(2) - intf_tbl._del("Ethernet0|10.0.0.0/31") - time.sleep(2) + def test_CrmIpv6Route(self, dvs, testlog): -def test_CrmIpv6Route(dvs, testlog): + # Enable IPv6 routing + dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") + time.sleep(2) - # Enable IPv6 routing - dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") - time.sleep(2) + 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", fvs) + intf_tbl.set("Ethernet0|fc00::1/126", fvs) + dvs.runcmd("ifconfig Ethernet0 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", fvs) - 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") - dvs.servers[0].runcmd("ifconfig eth0 inet6 add fc00::2/126") - dvs.servers[0].runcmd("ip -6 route add default via fc00::1") + dvs.runcmd("crm config polling interval 1") - dvs.runcmd("crm config polling interval 1") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '1000') - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '1000') + # get neighbor and arp entry + dvs.servers[0].runcmd("ping6 -c 4 fc00::1") - # get neighbor and arp entry - dvs.servers[0].runcmd("ping6 -c 4 fc00::1") + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") + fvs = swsscommon.FieldValuePairs([("nexthop","fc00::2"), ("ifname", "Ethernet0")]) - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") - fvs = swsscommon.FieldValuePairs([("nexthop","fc00::2"), ("ifname", "Ethernet0")]) + time.sleep(2) - time.sleep(2) + # get counters + used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_used') + avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_available') - # get counters - used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_used') - avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_available') + # add route and update available counter + ps.set("2001::/64", fvs) + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '999') - # add route and update available counter - ps.set("2001::/64", fvs) - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '999') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_available') + assert new_used_counter - used_counter == 1 + assert avail_counter - new_avail_counter == 1 - assert new_used_counter - used_counter == 1 - assert avail_counter - new_avail_counter == 1 + # remove route and update available counter + ps._del("2001::/64") + dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '1000') - # remove route and update available counter - ps._del("2001::/64") - dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_route_available') + assert new_used_counter == used_counter + assert new_avail_counter == avail_counter - assert new_used_counter == used_counter - assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|fc00::1/126") + time.sleep(2) - intf_tbl._del("Ethernet0|fc00::1/126") - time.sleep(2) + def test_CrmIpv4Nexthop(self, dvs, testlog): -def test_CrmIpv4Nexthop(dvs, testlog): + 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("Ethernet0", fvs) + dvs.runcmd("ifconfig Ethernet0 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("Ethernet0", fvs) - dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("crm config polling interval 1") - dvs.runcmd("crm config polling interval 1") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '1000') - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_used') + avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_available') - # get counters - used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_used') - avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_available') + # add nexthop and update available counter + dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '999') - # add nexthop and update available counter - dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '999') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_available') + assert new_used_counter - used_counter == 1 + assert avail_counter - new_avail_counter == 1 - assert new_used_counter - used_counter == 1 - assert avail_counter - new_avail_counter == 1 + # remove nexthop and update available counter + dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '1000') - # remove nexthop and update available counter - dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_nexthop_available') + assert new_used_counter == used_counter + assert new_avail_counter == avail_counter - assert new_used_counter == used_counter - assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|10.0.0.0/31") + time.sleep(2) - intf_tbl._del("Ethernet0|10.0.0.0/31") - time.sleep(2) + def test_CrmIpv6Nexthop(self, dvs, testlog): -def test_CrmIpv6Nexthop(dvs, testlog): + # Enable IPv6 routing + dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") + time.sleep(2) - # Enable IPv6 routing - dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") - time.sleep(2) + 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", fvs) + intf_tbl.set("Ethernet0|fc00::1/126", fvs) + dvs.runcmd("ifconfig Ethernet0 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", fvs) - intf_tbl.set("Ethernet0|fc00::1/126", fvs) - dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("crm config polling interval 1") - dvs.runcmd("crm config polling interval 1") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '1000') - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_used') + avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_available') - # get counters - used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_used') - avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_available') + # add nexthop and update available counter + dvs.runcmd("ip -6 neigh replace fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '999') - # add nexthop and update available counter - dvs.runcmd("ip -6 neigh replace fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '999') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_available') + assert new_used_counter - used_counter == 1 + assert avail_counter - new_avail_counter == 1 - assert new_used_counter - used_counter == 1 - assert avail_counter - new_avail_counter == 1 + # remove nexthop and update available counter + dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '1000') - # remove nexthop and update available counter - dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_nexthop_available') + assert new_used_counter == used_counter + assert new_avail_counter == avail_counter - assert new_used_counter == used_counter - assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|fc00::1/126") + time.sleep(2) - intf_tbl._del("Ethernet0|fc00::1/126") - time.sleep(2) + def test_CrmIpv4Neighbor(self, dvs, testlog): -def test_CrmIpv4Neighbor(dvs, testlog): + 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", fvs) + intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) + dvs.runcmd("ifconfig Ethernet0 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", fvs) - intf_tbl.set("Ethernet0|10.0.0.0/31", fvs) - dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("crm config polling interval 1") - dvs.runcmd("crm config polling interval 1") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '1000') - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_used') + avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_available') - # get counters - used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_used') - avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_available') + # add neighbor and update available counter + dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '999') - # add neighbor and update available counter - dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '999') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_available') + assert new_used_counter - used_counter == 1 + assert avail_counter - new_avail_counter == 1 - assert new_used_counter - used_counter == 1 - assert avail_counter - new_avail_counter == 1 + # remove neighbor and update available counter + dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '1000') - # remove neighbor and update available counter - dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv4_neighbor_available') + assert new_used_counter == used_counter + assert new_avail_counter == avail_counter - assert new_used_counter == used_counter - assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|10.0.0.0/31") + time.sleep(2) - intf_tbl._del("Ethernet0|10.0.0.0/31") - time.sleep(2) + def test_CrmIpv6Neighbor(self, dvs, testlog): -def test_CrmIpv6Neighbor(dvs, testlog): + # Enable IPv6 routing + dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") + time.sleep(2) - # Enable IPv6 routing - dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") - time.sleep(2) + 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", fvs) + intf_tbl.set("Ethernet0|fc00::1/126", fvs) + dvs.runcmd("ifconfig Ethernet0 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", fvs) - intf_tbl.set("Ethernet0|fc00::1/126", fvs) - dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("crm config polling interval 1") - dvs.runcmd("crm config polling interval 1") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '1000') - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_used') + avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_available') - # get counters - used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_used') - avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_available') + # add neighbor and update available counter + dvs.runcmd("ip -6 neigh replace fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '999') - # add neighbor and update available counter - dvs.runcmd("ip -6 neigh replace fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '999') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_available') + assert new_used_counter - used_counter == 1 + assert avail_counter - new_avail_counter == 1 - assert new_used_counter - used_counter == 1 - assert avail_counter - new_avail_counter == 1 + # remove neighbor and update available counter + dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '1000') - # remove neighbor and update available counter - dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_ipv6_neighbor_available') + assert new_used_counter == used_counter + assert new_avail_counter == avail_counter - assert new_used_counter == used_counter - assert new_avail_counter == avail_counter + intf_tbl._del("Ethernet0|fc00::1/126") + time.sleep(2) - intf_tbl._del("Ethernet0|fc00::1/126") - time.sleep(2) + def test_CrmNexthopGroup(self, dvs, testlog): -def test_CrmNexthopGroup(dvs, testlog): + 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", fvs) + intf_tbl.set("Ethernet4", fvs) + 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") - 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", fvs) - intf_tbl.set("Ethernet4", fvs) - 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") - dvs.runcmd("crm config polling interval 1") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '1000') - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '1000') + # add neighbors + dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") + dvs.runcmd("ip neigh replace 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4") - # add neighbors - dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - dvs.runcmd("ip neigh replace 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4") + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") + fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1,10.0.0.3"), ("ifname", "Ethernet0,Ethernet4")]) - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") - fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1,10.0.0.3"), ("ifname", "Ethernet0,Ethernet4")]) + time.sleep(2) - time.sleep(2) + # get counters + used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_used') + avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_available') - # get counters - used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_used') - avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_available') + # add route and update available counter + ps.set("2.2.2.0/24", fvs) + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '999') - # add route and update available counter - ps.set("2.2.2.0/24", fvs) - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '999') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_available') + assert new_used_counter - used_counter == 1 + assert avail_counter - new_avail_counter == 1 - assert new_used_counter - used_counter == 1 - assert avail_counter - new_avail_counter == 1 + # remove route and update available counter + ps._del("2.2.2.0/24") + dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") + dvs.runcmd("ip neigh del 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '1000') - # remove route and update available counter - ps._del("2.2.2.0/24") - dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - dvs.runcmd("ip neigh del 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_available') + assert new_used_counter == used_counter + assert new_avail_counter == avail_counter - 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) - intf_tbl._del("Ethernet0|10.0.0.0/31") - intf_tbl._del("Ethernet4|10.0.0.2/31") - time.sleep(2) + def test_CrmNexthopGroupMember(self, dvs, testlog): -def test_CrmNexthopGroupMember(dvs, testlog): + # down, then up to generate port up signal + dvs.servers[0].runcmd("ip link set down dev eth0") == 0 + dvs.servers[1].runcmd("ip link set down dev eth0") == 0 + dvs.servers[0].runcmd("ip link set up dev eth0") == 0 + dvs.servers[1].runcmd("ip link set up dev eth0") == 0 - # down, then up to generate port up signal - dvs.servers[0].runcmd("ip link set down dev eth0") == 0 - dvs.servers[1].runcmd("ip link set down dev eth0") == 0 - dvs.servers[0].runcmd("ip link set up dev eth0") == 0 - dvs.servers[1].runcmd("ip link set up dev eth0") == 0 + 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", fvs) + intf_tbl.set("Ethernet4", fvs) + 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") - 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", fvs) - intf_tbl.set("Ethernet4", fvs) - 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") - dvs.runcmd("crm config polling interval 1") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '1000') - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '1000') + # add neighbors + dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") + dvs.runcmd("ip neigh replace 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4") - # add neighbors - dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - dvs.runcmd("ip neigh replace 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4") + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") + fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1,10.0.0.3"), ("ifname", "Ethernet0,Ethernet4")]) - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") - fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1,10.0.0.3"), ("ifname", "Ethernet0,Ethernet4")]) + time.sleep(2) - time.sleep(2) + # get counters + used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_used') + avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_available') - # get counters - used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_used') - avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_available') + # add route and update available counter + ps.set("2.2.2.0/24", fvs) + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '998') - # add route and update available counter - ps.set("2.2.2.0/24", fvs) - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '998') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_available') + assert new_used_counter - used_counter == 2 + assert avail_counter - new_avail_counter == 2 - assert new_used_counter - used_counter == 2 - assert avail_counter - new_avail_counter == 2 + # remove route and update available counter + ps._del("2.2.2.0/24") + dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") + dvs.runcmd("ip neigh del 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4") + setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '1000') - # remove route and update available counter - ps._del("2.2.2.0/24") - dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - dvs.runcmd("ip neigh del 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '1000') + time.sleep(2) - time.sleep(2) + # get counters + new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_used') + new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_available') - # get counters - new_used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_used') - new_avail_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_nexthop_group_member_available') + assert new_used_counter == used_counter + assert new_avail_counter == avail_counter - 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) - intf_tbl._del("Ethernet0|10.0.0.0/31") - intf_tbl._del("Ethernet4|10.0.0.2/31") - time.sleep(2) + def test_CrmAcl(self, dvs, testlog): -def test_CrmAcl(dvs, testlog): + db = swsscommon.DBConnector(4, dvs.redis_sock, 0) + adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - db = swsscommon.DBConnector(4, dvs.redis_sock, 0) - adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + dvs.runcmd("crm config polling interval 1") + time.sleep(1) - dvs.runcmd("crm config polling interval 1") - time.sleep(1) + bind_ports = ["Ethernet0", "Ethernet4"] - bind_ports = ["Ethernet0", "Ethernet4"] + old_table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_table_used') - old_table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_table_used') + # create ACL table + ttbl = swsscommon.Table(db, "ACL_TABLE") + fvs = swsscommon.FieldValuePairs([("policy_desc", "test"), ("type", "L3"), ("ports", ",".join(bind_ports))]) + ttbl.set("test", fvs) - # create ACL table - ttbl = swsscommon.Table(db, "ACL_TABLE") - fvs = swsscommon.FieldValuePairs([("policy_desc", "test"), ("type", "L3"), ("ports", ",".join(bind_ports))]) - ttbl.set("test", fvs) + # create ACL rule + rtbl = swsscommon.Table(db, "ACL_RULE") + fvs = swsscommon.FieldValuePairs([("priority", "55"), ("PACKET_ACTION", "FORWARD"), ("L4_SRC_PORT", "65000")]) + rtbl.set("test|acl_test_rule", fvs) - # create ACL rule - rtbl = swsscommon.Table(db, "ACL_RULE") - fvs = swsscommon.FieldValuePairs([("priority", "55"), ("PACKET_ACTION", "FORWARD"), ("L4_SRC_PORT", "65000")]) - rtbl.set("test|acl_test_rule", fvs) + time.sleep(2) - time.sleep(2) - - new_table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_table_used') - table_used_counter = new_table_used_counter - old_table_used_counter - assert table_used_counter == 1 + new_table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_table_used') + table_used_counter = new_table_used_counter - old_table_used_counter + assert table_used_counter == 1 - # get ACL table key - atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE") - acl_tables = [k for k in atbl.getKeys() if k not in dvs.asicdb.default_acl_tables] - key = "ACL_TABLE_STATS:{0}".format(acl_tables[0].replace('oid:', '')) + # get ACL table key + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE") + acl_tables = [k for k in atbl.getKeys() if k not in dvs.asicdb.default_acl_tables] + key = "ACL_TABLE_STATS:{0}".format(acl_tables[0].replace('oid:', '')) - entry_used_counter = getCrmCounterValue(dvs, key, 'crm_stats_acl_entry_used') - assert entry_used_counter == 1 + entry_used_counter = getCrmCounterValue(dvs, key, 'crm_stats_acl_entry_used') + assert entry_used_counter == 1 - cnt_used_counter = getCrmCounterValue(dvs, key, 'crm_stats_acl_counter_used') - assert entry_used_counter == 1 + cnt_used_counter = getCrmCounterValue(dvs, key, 'crm_stats_acl_counter_used') + assert entry_used_counter == 1 - # remove ACL rule - rtbl._del("test|acl_test_rule") + # remove ACL rule + rtbl._del("test|acl_test_rule") - time.sleep(2) + time.sleep(2) - entry_used_counter = getCrmCounterValue(dvs, key, 'crm_stats_acl_entry_used') - assert entry_used_counter == 0 + entry_used_counter = getCrmCounterValue(dvs, key, 'crm_stats_acl_entry_used') + assert entry_used_counter == 0 - cnt_used_counter = getCrmCounterValue(dvs, key, 'crm_stats_acl_counter_used') - assert cnt_used_counter == 0 + cnt_used_counter = getCrmCounterValue(dvs, key, 'crm_stats_acl_counter_used') + assert cnt_used_counter == 0 - # remove ACL table - ttbl._del("test") + # remove ACL table + ttbl._del("test") - time.sleep(2) + time.sleep(2) - new_table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_table_used') - table_used_counter = new_table_used_counter - old_table_used_counter - assert table_used_counter == 0 + new_table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_table_used') + table_used_counter = new_table_used_counter - old_table_used_counter + assert table_used_counter == 0 - counters_db = swsscommon.DBConnector(swsscommon.COUNTERS_DB, dvs.redis_sock, 0) - crm_stats_table = swsscommon.Table(counters_db, 'CRM') - keys = crm_stats_table.getKeys() - assert key not in keys + counters_db = swsscommon.DBConnector(swsscommon.COUNTERS_DB, dvs.redis_sock, 0) + crm_stats_table = swsscommon.Table(counters_db, 'CRM') + keys = crm_stats_table.getKeys() + assert key not in keys diff --git a/tests/test_dirbcast.py b/tests/test_dirbcast.py index 12068812ca..4f966d44cd 100644 --- a/tests/test_dirbcast.py +++ b/tests/test_dirbcast.py @@ -3,90 +3,91 @@ import re import json -def test_DirectedBroadcast(dvs, testlog): +class TestDirectedBroadcast(object): + def test_DirectedBroadcast(self, dvs, testlog): - db = swsscommon.DBConnector(4, dvs.redis_sock, 0) - adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + db = swsscommon.DBConnector(4, dvs.redis_sock, 0) + adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - # create vlan in config db - tbl = swsscommon.Table(db, "VLAN") - fvs = swsscommon.FieldValuePairs([("vlanid", "100")]) - tbl.set("Vlan100", fvs) + # create vlan in config db + tbl = swsscommon.Table(db, "VLAN") + fvs = swsscommon.FieldValuePairs([("vlanid", "100")]) + tbl.set("Vlan100", fvs) - # create a vlan member in config db - tbl = swsscommon.Table(db, "VLAN_MEMBER") - fvs = swsscommon.FieldValuePairs([("tagging_mode", "tagged")]) - tbl.set("Vlan100|Ethernet24", fvs) + # create a vlan member in config db + tbl = swsscommon.Table(db, "VLAN_MEMBER") + fvs = swsscommon.FieldValuePairs([("tagging_mode", "tagged")]) + tbl.set("Vlan100|Ethernet24", fvs) - time.sleep(1) + time.sleep(1) - # create vlan interface in config db - tbl = swsscommon.Table(db, "VLAN_INTERFACE") - fvs = swsscommon.FieldValuePairs([("family", "IPv4")]) - tbl.set("Vlan100", fvs) - tbl.set("Vlan100|192.169.0.1/27", fvs) + # create vlan interface in config db + tbl = swsscommon.Table(db, "VLAN_INTERFACE") + fvs = swsscommon.FieldValuePairs([("family", "IPv4")]) + tbl.set("Vlan100", fvs) + tbl.set("Vlan100|192.169.0.1/27", fvs) - time.sleep(1) + time.sleep(1) - # check vlan in asic db - atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") - keys = atbl.getKeys() - vlan_oid = None + # check vlan in asic db + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + keys = atbl.getKeys() + vlan_oid = None - for key in keys: - if key == dvs.asicdb.default_vlan_id: - continue + for key in keys: + if key == dvs.asicdb.default_vlan_id: + continue - (status, fvs) = atbl.get(key) - assert status == True + (status, fvs) = atbl.get(key) + assert status == True - if fvs[0][0] == "SAI_VLAN_ATTR_VLAN_ID": - assert fvs[0][1] == '100' - vlan_oid = key + if fvs[0][0] == "SAI_VLAN_ATTR_VLAN_ID": + assert fvs[0][1] == '100' + vlan_oid = key - assert vlan_oid != None + assert vlan_oid != None - # check router interface in asic db - atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE") - keys = atbl.getKeys() - rif_oid = None + # check router interface in asic db + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE") + keys = atbl.getKeys() + rif_oid = None - for key in keys: - (status, fvs) = atbl.get(key) - assert status == True - for fv in fvs: - if fv[0] == "SAI_ROUTER_INTERFACE_ATTR_VLAN_ID": - assert vlan_oid == fv[1] - rif_oid = key + for key in keys: + (status, fvs) = atbl.get(key) + assert status == True + for fv in fvs: + if fv[0] == "SAI_ROUTER_INTERFACE_ATTR_VLAN_ID": + assert vlan_oid == fv[1] + rif_oid = key - assert rif_oid != None + assert rif_oid != None - # check neighbor entry in asic db - atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY") - keys = atbl.getKeys() - dir_bcast = False + # check neighbor entry in asic db + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY") + keys = atbl.getKeys() + dir_bcast = False - for key in keys: - neigh = json.loads(key) + for key in keys: + neigh = json.loads(key) - if neigh['ip'] == "192.169.0.31": - dir_bcast = True - assert neigh['rif'] == rif_oid - (status, fvs) = atbl.get(key) - assert status == True - if fvs[0][0] == "SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS": - assert fvs[0][1] == "FF:FF:FF:FF:FF:FF" + if neigh['ip'] == "192.169.0.31": + dir_bcast = True + assert neigh['rif'] == rif_oid + (status, fvs) = atbl.get(key) + assert status == True + if fvs[0][0] == "SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS": + assert fvs[0][1] == "FF:FF:FF:FF:FF:FF" - assert dir_bcast + assert dir_bcast - # Explicitly add a neighbor entry with BCAST MAC and check if its in ASIC_DB - dvs.runcmd("ip neigh replace 192.169.0.30 lladdr FF:FF:FF:FF:FF:FF dev Vlan100") + # Explicitly add a neighbor entry with BCAST MAC and check if its in ASIC_DB + dvs.runcmd("ip neigh replace 192.169.0.30 lladdr FF:FF:FF:FF:FF:FF dev Vlan100") - time.sleep(1) + time.sleep(1) - keys = atbl.getKeys() - for key in keys: - neigh = json.loads(key) + keys = atbl.getKeys() + for key in keys: + neigh = json.loads(key) - if neigh['ip'] == "192.169.0.30": - assert False + if neigh['ip'] == "192.169.0.30": + assert False diff --git a/tests/test_fdb.py b/tests/test_fdb.py new file mode 100644 index 0000000000..4e714d2021 --- /dev/null +++ b/tests/test_fdb.py @@ -0,0 +1,374 @@ +from swsscommon import swsscommon +import os +import sys +import time +import json +from distutils.version import StrictVersion + +def create_entry(tbl, key, pairs): + fvs = swsscommon.FieldValuePairs(pairs) + tbl.set(key, fvs) + + # FIXME: better to wait until DB create them + time.sleep(1) + +def create_entry_tbl(db, table, key, pairs): + tbl = swsscommon.Table(db, table) + create_entry(tbl, key, pairs) + +def create_entry_pst(db, table, key, pairs): + tbl = swsscommon.ProducerStateTable(db, table) + create_entry(tbl, key, pairs) + +def how_many_entries_exist(db, table): + tbl = swsscommon.Table(db, table) + return len(tbl.getKeys()) + +class TestFdb(object): + def test_FdbWarmRestartNotifications(self, dvs, testlog): + dvs.setup_db() + + dvs.runcmd("sonic-clear fdb all") + + dvs.runcmd("crm config polling interval 1") + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000') + + time.sleep(2) + counter_before = dvs.getCrmCounterValue('STATS', 'crm_stats_fdb_entry_used') + + # create vlan; create vlan member + dvs.create_vlan("6") + dvs.create_vlan_member("6", "Ethernet64") + dvs.create_vlan_member("6", "Ethernet68") + + # Put Ethernet72 and Ethernet76 into vlan 7 in untagged mode, they will have pvid of 7 + # and into vlan8 in tagged mode + dvs.create_vlan("7") + dvs.create_vlan_member("7", "Ethernet72") + dvs.create_vlan_member("7", "Ethernet76") + + dvs.create_vlan("8") + dvs.create_vlan_member_tagged("8", "Ethernet72") + dvs.create_vlan_member_tagged("8", "Ethernet76") + + + # Get mapping between interface name and its bridge port_id + time.sleep(2) + iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) + + # check FDB learning mode + ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', + iface_2_bridge_port_id["Ethernet64"], + [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) + assert ok, str(extra) + ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', + iface_2_bridge_port_id["Ethernet68"], + [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) + assert ok, str(extra) + + ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', + iface_2_bridge_port_id["Ethernet72"], + [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) + assert ok, str(extra) + + ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', + iface_2_bridge_port_id["Ethernet76"], + [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) + assert ok, str(extra) + + # check fdb aging attr + ok, extra = dvs.all_table_entry_has_no(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_SWITCH', + ".*", + ["SAI_SWITCH_ATTR_FDB_AGING_TIME"]) + + # bring up vlan and member + dvs.set_interface_status("Vlan6", "up") + dvs.set_interface_status("Vlan7", "up") + dvs.set_interface_status("Vlan8", "up") + + dvs.add_ip_address("Vlan6", "6.6.6.1/24") + dvs.add_ip_address("Vlan7", "7.7.7.1/24") + dvs.add_ip_address("Vlan8", "8.8.8.1/24") + + dvs.set_interface_status("Ethernet64", "up") + dvs.set_interface_status("Ethernet68", "up") + dvs.set_interface_status("Ethernet72", "up") + dvs.set_interface_status("Ethernet76", "up") + dvs.servers[16].runcmd("ifconfig eth0 6.6.6.6/24 up") + dvs.servers[16].runcmd("ip route add default via 6.6.6.1") + dvs.servers[17].runcmd("ifconfig eth0 6.6.6.7/24 up") + dvs.servers[17].runcmd("ip route add default via 6.6.6.1") + + dvs.servers[18].runcmd("vconfig add eth0 8") + dvs.servers[18].runcmd("ifconfig eth0.8 8.8.8.6/24 up") + dvs.servers[18].runcmd("ip route add default via 8.8.8.1") + + dvs.servers[19].runcmd("vconfig add eth0 8") + dvs.servers[19].runcmd("ifconfig eth0.8 8.8.8.7/24 up") + dvs.servers[19].runcmd("ip route add default via 8.8.8.1") + + dvs.servers[18].runcmd("ifconfig eth0 7.7.7.6/24 up") + dvs.servers[18].runcmd("ip route add default via 7.7.7.1") + dvs.servers[19].runcmd("ifconfig eth0 7.7.7.7/24 up") + dvs.servers[19].runcmd("ip route add default via 7.7.7.1") + + # get neighbor and arp entry + time.sleep(2) + rc = dvs.servers[16].runcmd("ping -c 1 6.6.6.7") + assert rc == 0 + rc = dvs.servers[17].runcmd("ping -c 1 6.6.6.6") + assert rc == 0 + + # get neighbor and arp entry + time.sleep(2) + rc = dvs.servers[18].runcmd("ping -c 1 8.8.8.7") + assert rc == 0 + rc = dvs.servers[19].runcmd("ping -c 1 8.8.8.6") + assert rc == 0 + + time.sleep(2) + rc = dvs.servers[18].runcmd("ping -c 1 -I 7.7.7.6 7.7.7.7") + assert rc == 0 + rc = dvs.servers[19].runcmd("ping -c 1 -I 7.7.7.7 7.7.7.6") + assert rc == 0 + + # check that the FDB entries were inserted into ASIC DB + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet64"]), + ] + ) + assert ok, str(extra) + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet68"]), + ] + ) + assert ok, str(extra) + + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet72"]), + ] + ) + assert ok, str(extra) + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet76"]), + ] + ) + assert ok, str(extra) + + time.sleep(2) + counter_inserted = dvs.getCrmCounterValue('STATS', 'crm_stats_fdb_entry_used') + # vlan 6: Ethernet64, Ethernet68; + # vlan 7: Ethernet72, Ethernet76; + # vlan 8 (tagged): Ethernet72, Ethernet76; + # 6 FDB entries wil be created in total + assert counter_inserted - counter_before == 6 + + # check that the FDB entries were inserted into State DB for Ethernet64, Ethernet68 with Vlan6 + ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", + "Vlan6:.*", + [("port", "Ethernet64"), + ("type", "dynamic"), + ] + ) + assert ok, str(extra) + ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", + "Vlan6:*", + [("port", "Ethernet68"), + ("type", "dynamic"), + ] + ) + assert ok, str(extra) + + # check that the FDB entries were inserted into State DB, + # Vlan7(untagged) in the key for Ethernet72, Ethernet76 + ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", + "Vlan7:.*", + [("port", "Ethernet72"), + ("type", "dynamic"), + ] + ) + assert ok, str(extra) + ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", + "Vlan7:*", + [("port", "Ethernet76"), + ("type", "dynamic"), + ] + ) + assert ok, str(extra) + + # check that the FDB entries were inserted into State DB, + # Vlan8 (tagged) in the key for Ethernet72, Ethernet76 + ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", + "Vlan8:.*", + [("port", "Ethernet72"), + ("type", "dynamic"), + ] + ) + assert ok, str(extra) + ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", + "Vlan8:*", + [("port", "Ethernet76"), + ("type", "dynamic"), + ] + ) + assert ok, str(extra) + + # enable warm restart + (exitcode, result) = dvs.runcmd("config warm_restart enable swss") + assert exitcode == 0 + + # freeze orchagent for warm restart + (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check") + assert result == "RESTARTCHECK succeeded\n" + time.sleep(2) + + try: + # restart orchagent + dvs.stop_swss() + + # check FDB learning mode + ok, extra = dvs.all_table_entry_has(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', + ".*", + [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_DISABLE")]) + assert ok, str(extra) + # check FDB aging time + ok, extra = dvs.all_table_entry_has(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_SWITCH', + ".*", + [("SAI_SWITCH_ATTR_FDB_AGING_TIME", "0")]) + assert ok, str(extra) + + dvs.start_swss() + time.sleep(2) + + # Get mapping between interface name and its bridge port_id + # Note: they are changed + iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) + + # check that the FDB entries were inserted into ASIC DB + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet64"]), + ] + ) + assert ok, str(extra) + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet68"]), + ] + ) + assert ok, str(extra) + + # check that the FDB entries were inserted into ASIC DB + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet72"]), + ] + ) + assert ok, str(extra) + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet76"]), + ] + ) + assert ok, str(extra) + + # check FDB learning mode + ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', + iface_2_bridge_port_id["Ethernet64"], + [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) + assert ok, str(extra) + ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', + iface_2_bridge_port_id["Ethernet68"], + [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) + assert ok, str(extra) + + ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', + iface_2_bridge_port_id["Ethernet72"], + [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) + assert ok, str(extra) + ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', + iface_2_bridge_port_id["Ethernet76"], + [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) + assert ok, str(extra) + + time.sleep(2) + counter_restarted = dvs.getCrmCounterValue('STATS', 'crm_stats_fdb_entry_used') + assert counter_inserted == counter_restarted + + # check fdb aging attr + ok, extra = dvs.all_table_entry_has_no(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_SWITCH', + ".*", + ["SAI_SWITCH_ATTR_FDB_AGING_TIME"]) + + finally: + # disable warm restart + dvs.runcmd("config warm_restart disable swss") + # slow down crm polling + dvs.runcmd("crm config polling interval 10000") + + def test_FdbAddedAfterMemberCreated(self, dvs, testlog): + dvs.setup_db() + + dvs.runcmd("sonic-clear fdb all") + time.sleep(2) + + # create a FDB entry in Application DB + create_entry_pst( + dvs.pdb, + "FDB_TABLE", "Vlan2:52-54-00-25-06-E9", + [ + ("port", "Ethernet0"), + ("type", "dynamic"), + ] + ) + + # check that the FDB entry wasn't inserted into ASIC DB + assert how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY") == 0, "The fdb entry leaked to ASIC" + + vlan_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + bp_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + vm_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + + # create vlan + dvs.create_vlan("2") + dvs.create_vlan_member("2", "Ethernet0") + + # check that the vlan information was propagated + vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") + vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") + + assert vlan_after - vlan_before == 1, "The Vlan2 wasn't created" + assert bp_after - bp_before == 1, "The bridge port wasn't created" + assert vm_after - vm_before == 1, "The vlan member wasn't added" + + # Get mapping between interface name and its bridge port_id + iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) + + # check that the FDB entry was inserted into ASIC DB + assert how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY") == 1, "The fdb entry wasn't inserted to ASIC" + + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [("mac", "52-54-00-25-06-E9"), ("vlan", "2")], + [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), + ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet0"]), + ('SAI_FDB_ENTRY_ATTR_PACKET_ACTION', 'SAI_PACKET_ACTION_FORWARD')] + ) + assert ok, str(extra) + + dvs.runcmd("sonic-clear fdb all") + dvs.remove_vlan_member("2", "Ethernet0") + dvs.remove_vlan("2") + diff --git a/tests/test_fdb_cold.py b/tests/test_fdb_cold.py deleted file mode 100644 index 8ebe7bf816..0000000000 --- a/tests/test_fdb_cold.py +++ /dev/null @@ -1,80 +0,0 @@ -from swsscommon import swsscommon -import os -import sys -import time -import json -from distutils.version import StrictVersion - -def create_entry(tbl, key, pairs): - fvs = swsscommon.FieldValuePairs(pairs) - tbl.set(key, fvs) - - # FIXME: better to wait until DB create them - time.sleep(1) - -def create_entry_tbl(db, table, key, pairs): - tbl = swsscommon.Table(db, table) - create_entry(tbl, key, pairs) - -def create_entry_pst(db, table, key, pairs): - tbl = swsscommon.ProducerStateTable(db, table) - create_entry(tbl, key, pairs) - -def how_many_entries_exist(db, table): - tbl = swsscommon.Table(db, table) - return len(tbl.getKeys()) - -def test_FDBAddedAfterMemberCreated(dvs, testlog): - dvs.setup_db() - - dvs.runcmd("sonic-clear fdb all") - time.sleep(2) - - # create a FDB entry in Application DB - create_entry_pst( - dvs.pdb, - "FDB_TABLE", "Vlan2:52-54-00-25-06-E9", - [ - ("port", "Ethernet0"), - ("type", "dynamic"), - ] - ) - - # check that the FDB entry wasn't inserted into ASIC DB - assert how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY") == 0, "The fdb entry leaked to ASIC" - - vlan_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") - bp_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") - vm_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - - # create vlan - dvs.create_vlan("2") - dvs.create_vlan_member("2", "Ethernet0") - - # check that the vlan information was propagated - vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") - bp_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") - vm_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") - - assert vlan_after - vlan_before == 1, "The Vlan2 wasn't created" - assert bp_after - bp_before == 1, "The bridge port wasn't created" - assert vm_after - vm_before == 1, "The vlan member wasn't added" - - # Get mapping between interface name and its bridge port_id - iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) - - # check that the FDB entry was inserted into ASIC DB - assert how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY") == 1, "The fdb entry wasn't inserted to ASIC" - - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [("mac", "52-54-00-25-06-E9"), ("vlan", "2")], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet0"]), - ('SAI_FDB_ENTRY_ATTR_PACKET_ACTION', 'SAI_PACKET_ACTION_FORWARD')] - ) - assert ok, str(extra) - - dvs.runcmd("sonic-clear fdb all") - dvs.remove_vlan_member("2", "Ethernet0") - dvs.remove_vlan("2") - diff --git a/tests/test_fdb_warm.py b/tests/test_fdb_warm.py deleted file mode 100644 index 0754e9628d..0000000000 --- a/tests/test_fdb_warm.py +++ /dev/null @@ -1,318 +0,0 @@ -from swsscommon import swsscommon -import os -import sys -import time -import json -from distutils.version import StrictVersion - -def create_entry(tbl, key, pairs): - fvs = swsscommon.FieldValuePairs(pairs) - tbl.set(key, fvs) - - # FIXME: better to wait until DB create them - time.sleep(1) - -def create_entry_tbl(db, table, key, pairs): - tbl = swsscommon.Table(db, table) - create_entry(tbl, key, pairs) - -def create_entry_pst(db, table, key, pairs): - tbl = swsscommon.ProducerStateTable(db, table) - create_entry(tbl, key, pairs) - -def how_many_entries_exist(db, table): - tbl = swsscommon.Table(db, table) - return len(tbl.getKeys()) - -def test_fdb_notifications(dvs, testlog): - dvs.setup_db() - - dvs.runcmd("sonic-clear fdb all") - - dvs.runcmd("crm config polling interval 1") - dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000') - - time.sleep(2) - counter_before = dvs.getCrmCounterValue('STATS', 'crm_stats_fdb_entry_used') - - # create vlan; create vlan member - dvs.create_vlan("6") - dvs.create_vlan_member("6", "Ethernet64") - dvs.create_vlan_member("6", "Ethernet68") - - # Put Ethernet72 and Ethernet76 into vlan 7 in untagged mode, they will have pvid of 7 - # and into vlan8 in tagged mode - dvs.create_vlan("7") - dvs.create_vlan_member("7", "Ethernet72") - dvs.create_vlan_member("7", "Ethernet76") - - dvs.create_vlan("8") - dvs.create_vlan_member_tagged("8", "Ethernet72") - dvs.create_vlan_member_tagged("8", "Ethernet76") - - - # Get mapping between interface name and its bridge port_id - time.sleep(2) - iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) - - # check FDB learning mode - ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', - iface_2_bridge_port_id["Ethernet64"], - [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) - assert ok, str(extra) - ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', - iface_2_bridge_port_id["Ethernet68"], - [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) - assert ok, str(extra) - - ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', - iface_2_bridge_port_id["Ethernet72"], - [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) - assert ok, str(extra) - - ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', - iface_2_bridge_port_id["Ethernet76"], - [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) - assert ok, str(extra) - - # check fdb aging attr - ok, extra = dvs.all_table_entry_has_no(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_SWITCH', - ".*", - ["SAI_SWITCH_ATTR_FDB_AGING_TIME"]) - - # bring up vlan and member - dvs.set_interface_status("Vlan6", "up") - dvs.set_interface_status("Vlan7", "up") - dvs.set_interface_status("Vlan8", "up") - - dvs.add_ip_address("Vlan6", "6.6.6.1/24") - dvs.add_ip_address("Vlan7", "7.7.7.1/24") - dvs.add_ip_address("Vlan8", "8.8.8.1/24") - - dvs.set_interface_status("Ethernet64", "up") - dvs.set_interface_status("Ethernet68", "up") - dvs.set_interface_status("Ethernet72", "up") - dvs.set_interface_status("Ethernet76", "up") - dvs.servers[16].runcmd("ifconfig eth0 6.6.6.6/24 up") - dvs.servers[16].runcmd("ip route add default via 6.6.6.1") - dvs.servers[17].runcmd("ifconfig eth0 6.6.6.7/24 up") - dvs.servers[17].runcmd("ip route add default via 6.6.6.1") - - dvs.servers[18].runcmd("vconfig add eth0 8") - dvs.servers[18].runcmd("ifconfig eth0.8 8.8.8.6/24 up") - dvs.servers[18].runcmd("ip route add default via 8.8.8.1") - - dvs.servers[19].runcmd("vconfig add eth0 8") - dvs.servers[19].runcmd("ifconfig eth0.8 8.8.8.7/24 up") - dvs.servers[19].runcmd("ip route add default via 8.8.8.1") - - dvs.servers[18].runcmd("ifconfig eth0 7.7.7.6/24 up") - dvs.servers[18].runcmd("ip route add default via 7.7.7.1") - dvs.servers[19].runcmd("ifconfig eth0 7.7.7.7/24 up") - dvs.servers[19].runcmd("ip route add default via 7.7.7.1") - - # get neighbor and arp entry - time.sleep(2) - rc = dvs.servers[16].runcmd("ping -c 1 6.6.6.7") - assert rc == 0 - rc = dvs.servers[17].runcmd("ping -c 1 6.6.6.6") - assert rc == 0 - - # get neighbor and arp entry - time.sleep(2) - rc = dvs.servers[18].runcmd("ping -c 1 8.8.8.7") - assert rc == 0 - rc = dvs.servers[19].runcmd("ping -c 1 8.8.8.6") - assert rc == 0 - - time.sleep(2) - rc = dvs.servers[18].runcmd("ping -c 1 -I 7.7.7.6 7.7.7.7") - assert rc == 0 - rc = dvs.servers[19].runcmd("ping -c 1 -I 7.7.7.7 7.7.7.6") - assert rc == 0 - - # check that the FDB entries were inserted into ASIC DB - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet64"]), - ] - ) - assert ok, str(extra) - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet68"]), - ] - ) - assert ok, str(extra) - - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet72"]), - ] - ) - assert ok, str(extra) - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet76"]), - ] - ) - assert ok, str(extra) - - time.sleep(2) - counter_inserted = dvs.getCrmCounterValue('STATS', 'crm_stats_fdb_entry_used') - # vlan 6: Ethernet64, Ethernet68; - # vlan 7: Ethernet72, Ethernet76; - # vlan 8 (tagged): Ethernet72, Ethernet76; - # 6 FDB entries wil be created in total - assert counter_inserted - counter_before == 6 - - # check that the FDB entries were inserted into State DB for Ethernet64, Ethernet68 with Vlan6 - ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", - "Vlan6:.*", - [("port", "Ethernet64"), - ("type", "dynamic"), - ] - ) - assert ok, str(extra) - ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", - "Vlan6:*", - [("port", "Ethernet68"), - ("type", "dynamic"), - ] - ) - assert ok, str(extra) - - # check that the FDB entries were inserted into State DB, - # Vlan7(untagged) in the key for Ethernet72, Ethernet76 - ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", - "Vlan7:.*", - [("port", "Ethernet72"), - ("type", "dynamic"), - ] - ) - assert ok, str(extra) - ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", - "Vlan7:*", - [("port", "Ethernet76"), - ("type", "dynamic"), - ] - ) - assert ok, str(extra) - - # check that the FDB entries were inserted into State DB, - # Vlan8 (tagged) in the key for Ethernet72, Ethernet76 - ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", - "Vlan8:.*", - [("port", "Ethernet72"), - ("type", "dynamic"), - ] - ) - assert ok, str(extra) - ok, extra = dvs.is_table_entry_exists(dvs.sdb, "FDB_TABLE", - "Vlan8:*", - [("port", "Ethernet76"), - ("type", "dynamic"), - ] - ) - assert ok, str(extra) - - # enable warm restart - (exitcode, result) = dvs.runcmd("config warm_restart enable swss") - assert exitcode == 0 - - # freeze orchagent for warm restart - (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check") - assert result == "RESTARTCHECK succeeded\n" - time.sleep(2) - - try: - # restart orchagent - dvs.stop_swss() - - # check FDB learning mode - ok, extra = dvs.all_table_entry_has(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', - ".*", - [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_DISABLE")]) - assert ok, str(extra) - # check FDB aging time - ok, extra = dvs.all_table_entry_has(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_SWITCH', - ".*", - [("SAI_SWITCH_ATTR_FDB_AGING_TIME", "0")]) - assert ok, str(extra) - - dvs.start_swss() - time.sleep(2) - - # Get mapping between interface name and its bridge port_id - # Note: they are changed - iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) - - # check that the FDB entries were inserted into ASIC DB - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet64"]), - ] - ) - assert ok, str(extra) - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet68"]), - ] - ) - assert ok, str(extra) - - # check that the FDB entries were inserted into ASIC DB - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet72"]), - ] - ) - assert ok, str(extra) - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [], - [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), - ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet76"]), - ] - ) - assert ok, str(extra) - - # check FDB learning mode - ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', - iface_2_bridge_port_id["Ethernet64"], - [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) - assert ok, str(extra) - ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', - iface_2_bridge_port_id["Ethernet68"], - [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) - assert ok, str(extra) - - ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', - iface_2_bridge_port_id["Ethernet72"], - [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) - assert ok, str(extra) - ok, extra = dvs.is_table_entry_exists(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT', - iface_2_bridge_port_id["Ethernet76"], - [("SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW")]) - assert ok, str(extra) - - time.sleep(2) - counter_restarted = dvs.getCrmCounterValue('STATS', 'crm_stats_fdb_entry_used') - assert counter_inserted == counter_restarted - - # check fdb aging attr - ok, extra = dvs.all_table_entry_has_no(dvs.adb, 'ASIC_STATE:SAI_OBJECT_TYPE_SWITCH', - ".*", - ["SAI_SWITCH_ATTR_FDB_AGING_TIME"]) - - finally: - # disable warm restart - dvs.runcmd("config warm_restart disable swss") - # slow down crm polling - dvs.runcmd("crm config polling interval 10000") diff --git a/tests/test_nhg.py b/tests/test_nhg.py index 97a70d571e..a2bbe5fd1f 100644 --- a/tests/test_nhg.py +++ b/tests/test_nhg.py @@ -4,134 +4,134 @@ import time import json -def test_route_nhg(dvs, testlog): +class TestNextHopGroup(object): + def test_route_nhg(self, dvs, testlog): + 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", fvs) + intf_tbl.set("Ethernet4", fvs) + intf_tbl.set("Ethernet8", fvs) + 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") + dvs.runcmd("arp -s 10.0.0.5 00:00:00:00:00:03") + + dvs.servers[0].runcmd("ip link set down dev eth0") == 0 + dvs.servers[1].runcmd("ip link set down dev eth0") == 0 + dvs.servers[2].runcmd("ip link set down dev eth0") == 0 + + dvs.servers[0].runcmd("ip link set up dev eth0") == 0 + dvs.servers[1].runcmd("ip link set up dev eth0") == 0 + dvs.servers[2].runcmd("ip link set up dev eth0") == 0 + + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") + fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1,10.0.0.3,10.0.0.5"), ("ifname", "Ethernet0,Ethernet4,Ethernet8")]) + + ps.set("2.2.2.0/24", fvs) - 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", fvs) - intf_tbl.set("Ethernet4", fvs) - intf_tbl.set("Ethernet8", fvs) - 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") - dvs.runcmd("arp -s 10.0.0.5 00:00:00:00:00:03") - - dvs.servers[0].runcmd("ip link set down dev eth0") == 0 - dvs.servers[1].runcmd("ip link set down dev eth0") == 0 - dvs.servers[2].runcmd("ip link set down dev eth0") == 0 - - dvs.servers[0].runcmd("ip link set up dev eth0") == 0 - dvs.servers[1].runcmd("ip link set up dev eth0") == 0 - dvs.servers[2].runcmd("ip link set up dev eth0") == 0 - - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") - fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1,10.0.0.3,10.0.0.5"), ("ifname", "Ethernet0,Ethernet4,Ethernet8")]) - - ps.set("2.2.2.0/24", fvs) - - time.sleep(1) + time.sleep(1) - # check if route was propagated to ASIC DB + # check if route was propagated to ASIC DB - adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - rtbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY") - nhgtbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP_GROUP") - nhg_member_tbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP_GROUP_MEMBER") + rtbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY") + nhgtbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP_GROUP") + nhg_member_tbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP_GROUP_MEMBER") - keys = rtbl.getKeys() + keys = rtbl.getKeys() - found_route = False - for k in keys: - rt_key = json.loads(k) + found_route = False + for k in keys: + rt_key = json.loads(k) - if rt_key['dest'] == "2.2.2.0/24": - found_route = True - break + if rt_key['dest'] == "2.2.2.0/24": + found_route = True + break - assert found_route + assert found_route - # assert the route points to next hop group - (status, fvs) = rtbl.get(k) + # assert the route points to next hop group + (status, fvs) = rtbl.get(k) - for v in fvs: - if v[0] == "SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID": - nhgid = v[1] + for v in fvs: + if v[0] == "SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID": + nhgid = v[1] - (status, fvs) = nhgtbl.get(nhgid) + (status, fvs) = nhgtbl.get(nhgid) - assert status + assert status - keys = nhg_member_tbl.getKeys() + keys = nhg_member_tbl.getKeys() - assert len(keys) == 3 + assert len(keys) == 3 - for k in keys: - (status, fvs) = nhg_member_tbl.get(k) + for k in keys: + (status, fvs) = nhg_member_tbl.get(k) - for v in fvs: - if v[0] == "SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID": - assert v[1] == nhgid + for v in fvs: + if v[0] == "SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID": + assert v[1] == nhgid - # bring links down one-by-one - for i in [0, 1, 2]: - dvs.servers[i].runcmd("ip link set down dev eth0") == 0 + # bring links down one-by-one + for i in [0, 1, 2]: + dvs.servers[i].runcmd("ip link set down dev eth0") == 0 - time.sleep(1) + time.sleep(1) - tbl = swsscommon.Table(db, "PORT_TABLE") - (status, fvs) = tbl.get("Ethernet%d" % (i * 4)) + tbl = swsscommon.Table(db, "PORT_TABLE") + (status, fvs) = tbl.get("Ethernet%d" % (i * 4)) - assert status == True + assert status == True - oper_status = "unknown" + oper_status = "unknown" - for v in fvs: - if v[0] == "oper_status": - oper_status = v[1] - break + for v in fvs: + if v[0] == "oper_status": + oper_status = v[1] + break - assert oper_status == "down" + assert oper_status == "down" - keys = nhg_member_tbl.getKeys() + keys = nhg_member_tbl.getKeys() - assert len(keys) == 2 - i + assert len(keys) == 2 - i - # bring links up one-by-one - for i in [0, 1, 2]: - dvs.servers[i].runcmd("ip link set up dev eth0") == 0 + # bring links up one-by-one + for i in [0, 1, 2]: + dvs.servers[i].runcmd("ip link set up dev eth0") == 0 - time.sleep(1) + time.sleep(1) - tbl = swsscommon.Table(db, "PORT_TABLE") - (status, fvs) = tbl.get("Ethernet%d" % (i * 4)) + tbl = swsscommon.Table(db, "PORT_TABLE") + (status, fvs) = tbl.get("Ethernet%d" % (i * 4)) - assert status == True + assert status == True - oper_status = "unknown" + oper_status = "unknown" - for v in fvs: - if v[0] == "oper_status": - oper_status = v[1] - break + for v in fvs: + if v[0] == "oper_status": + oper_status = v[1] + break - assert oper_status == "up" + assert oper_status == "up" - keys = nhg_member_tbl.getKeys() + keys = nhg_member_tbl.getKeys() - assert len(keys) == i + 1 + assert len(keys) == i + 1 - for k in keys: - (status, fvs) = nhg_member_tbl.get(k) + for k in keys: + (status, fvs) = nhg_member_tbl.get(k) - for v in fvs: - if v[0] == "SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID": - assert v[1] == nhgid + for v in fvs: + if v[0] == "SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID": + assert v[1] == nhgid diff --git a/tests/test_pfc.py b/tests/test_pfc.py index 8ed9112bea..9a59adf20b 100644 --- a/tests/test_pfc.py +++ b/tests/test_pfc.py @@ -57,45 +57,45 @@ def getPortAttr(dvs, port_oid, port_attr): return '' +class TestPfc(object): + def test_PfcAsymmetric(self, dvs, testlog): -def test_PfcAsymmetric(dvs, testlog): + port_name = 'Ethernet0' + pfc_queues = [ 3, 4 ] - port_name = 'Ethernet0' - pfc_queues = [ 3, 4 ] + # Configure default PFC + setPortPfc(dvs, port_name, pfc_queues) - # Configure default PFC - setPortPfc(dvs, port_name, pfc_queues) + # Get SAI object ID for the interface + port_oid = getPortOid(dvs, port_name) - # Get SAI object ID for the interface - port_oid = getPortOid(dvs, port_name) + # Verify default PFC is set to configured value + pfc = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL') + assert pfc == getBitMaskStr(pfc_queues) - # Verify default PFC is set to configured value - pfc = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL') - assert pfc == getBitMaskStr(pfc_queues) + # Enable asymmetric PFC + setPortPfcAsym(dvs, port_name, 'on') - # Enable asymmetric PFC - setPortPfcAsym(dvs, port_name, 'on') + # Verify PFC mode is set to 'SEPARATE' + pfc_mode = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_MODE') + assert pfc_mode == 'SAI_PORT_PRIORITY_FLOW_CONTROL_MODE_SEPARATE' - # Verify PFC mode is set to 'SEPARATE' - pfc_mode = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_MODE') - assert pfc_mode == 'SAI_PORT_PRIORITY_FLOW_CONTROL_MODE_SEPARATE' + # Verify TX PFC is set to previous PFC value + pfc_tx = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_TX') + assert pfc_tx == pfc - # Verify TX PFC is set to previous PFC value - pfc_tx = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_TX') - assert pfc_tx == pfc + # Verify RX PFC is set to 0xFF (255) + pfc_rx = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_RX') + assert pfc_rx == '255' - # Verify RX PFC is set to 0xFF (255) - pfc_rx = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_RX') - assert pfc_rx == '255' + # Disable asymmetric PFC + setPortPfcAsym(dvs, port_name, 'off') - # Disable asymmetric PFC - setPortPfcAsym(dvs, port_name, 'off') + # Verify PFC mode is set to 'COMBINED' + pfc_mode = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_MODE') + assert pfc_mode == 'SAI_PORT_PRIORITY_FLOW_CONTROL_MODE_COMBINED' - # Verify PFC mode is set to 'COMBINED' - pfc_mode = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL_MODE') - assert pfc_mode == 'SAI_PORT_PRIORITY_FLOW_CONTROL_MODE_COMBINED' - - # Verify PFC is set to TX PFC value - pfc = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL') - assert pfc == pfc_tx + # Verify PFC is set to TX PFC value + pfc = getPortAttr(dvs, port_oid, 'SAI_PORT_ATTR_PRIORITY_FLOW_CONTROL') + assert pfc == pfc_tx diff --git a/tests/test_port.py b/tests/test_port.py index cf429ca985..edf459301c 100644 --- a/tests/test_port.py +++ b/tests/test_port.py @@ -23,195 +23,195 @@ def test_PortMtu(self, dvs, testlog): if fv[0] == "mtu": assert fv[1] == "9100" -def test_PortNotification(dvs, testlog): + def test_PortNotification(self, dvs, testlog): - dvs.runcmd("ifconfig Ethernet0 10.0.0.0/31 up") == 0 - dvs.runcmd("ifconfig Ethernet4 10.0.0.2/31 up") == 0 + dvs.runcmd("ifconfig Ethernet0 10.0.0.0/31 up") == 0 + dvs.runcmd("ifconfig Ethernet4 10.0.0.2/31 up") == 0 - dvs.servers[0].runcmd("ip link set down dev eth0") == 0 + dvs.servers[0].runcmd("ip link set down dev eth0") == 0 - time.sleep(1) + time.sleep(1) - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - tbl = swsscommon.Table(db, "PORT_TABLE") + tbl = swsscommon.Table(db, "PORT_TABLE") - (status, fvs) = tbl.get("Ethernet0") + (status, fvs) = tbl.get("Ethernet0") - assert status == True + assert status == True - oper_status = "unknown" + oper_status = "unknown" - for v in fvs: - if v[0] == "oper_status": - oper_status = v[1] - break + for v in fvs: + if v[0] == "oper_status": + oper_status = v[1] + break - assert oper_status == "down" + assert oper_status == "down" - dvs.servers[0].runcmd("ip link set up dev eth0") == 0 + dvs.servers[0].runcmd("ip link set up dev eth0") == 0 - time.sleep(1) + time.sleep(1) - (status, fvs) = tbl.get("Ethernet0") + (status, fvs) = tbl.get("Ethernet0") - assert status == True + assert status == True - oper_status = "unknown" + oper_status = "unknown" - for v in fvs: - if v[0] == "oper_status": - oper_status = v[1] - break + for v in fvs: + if v[0] == "oper_status": + oper_status = v[1] + break - assert oper_status == "up" + assert oper_status == "up" -def test_PortFec(dvs, testlog): + def test_PortFec(self, dvs, testlog): - dvs.runcmd("ifconfig Ethernet0 10.0.0.0/31 up") == 0 - dvs.runcmd("ifconfig Ethernet4 10.0.0.2/31 up") == 0 + dvs.runcmd("ifconfig Ethernet0 10.0.0.0/31 up") == 0 + dvs.runcmd("ifconfig Ethernet4 10.0.0.2/31 up") == 0 - dvs.servers[0].runcmd("ip link set down dev eth0") == 0 + dvs.servers[0].runcmd("ip link set down dev eth0") == 0 - time.sleep(1) + time.sleep(1) - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - tbl = swsscommon.Table(db, "PORT_TABLE") - ptbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") - atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") + tbl = swsscommon.Table(db, "PORT_TABLE") + ptbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") - (status, fvs) = tbl.get("Ethernet0") + (status, fvs) = tbl.get("Ethernet0") - assert status == True + assert status == True - oper_status = "unknown" + oper_status = "unknown" - for v in fvs: - if v[0] == "oper_status": - oper_status = v[1] - break + for v in fvs: + if v[0] == "oper_status": + oper_status = v[1] + break - assert oper_status == "down" + assert oper_status == "down" - dvs.servers[0].runcmd("ip link set up dev eth0") == 0 + dvs.servers[0].runcmd("ip link set up dev eth0") == 0 - time.sleep(1) + time.sleep(1) - (status, fvs) = tbl.get("Ethernet0") + (status, fvs) = tbl.get("Ethernet0") - assert status == True + assert status == True - oper_status = "unknown" + oper_status = "unknown" - for v in fvs: - if v[0] == "oper_status": - oper_status = v[1] - break + for v in fvs: + if v[0] == "oper_status": + oper_status = v[1] + break - assert oper_status == "up" + assert oper_status == "up" - # set fec - fvs = swsscommon.FieldValuePairs([("fec","rs"), ("speed", "1000")]) - ptbl.set("Ethernet0", fvs) + # set fec + fvs = swsscommon.FieldValuePairs([("fec","rs"), ("speed", "1000")]) + ptbl.set("Ethernet0", fvs) - time.sleep(1) + time.sleep(1) - # get fec - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True + # get fec + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_FEC_MODE": - assert fv[1] == "SAI_PORT_FEC_MODE_RS" + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_FEC_MODE": + assert fv[1] == "SAI_PORT_FEC_MODE_RS" -def test_PortPreemp(dvs, testlog): + def test_PortPreemp(self, dvs, testlog): - pre_name = 'preemphasis' - pre_val = [0x1234,0x2345,0x3456,0x4567] - pre_val_str = str(hex(pre_val[0])) + "," + str(hex(pre_val[1]))+ "," + \ - str(hex(pre_val[2]))+ "," + str(hex(pre_val[3])) + pre_name = 'preemphasis' + pre_val = [0x1234,0x2345,0x3456,0x4567] + pre_val_str = str(hex(pre_val[0])) + "," + str(hex(pre_val[1]))+ "," + \ + str(hex(pre_val[2]))+ "," + str(hex(pre_val[3])) - pre_val_asic = '4:' + str(pre_val[0]) + "," + str(pre_val[1]) + "," + \ - str(pre_val[2]) + "," + str(pre_val[3]) - fvs = swsscommon.FieldValuePairs([(pre_name, pre_val_str)]) - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + pre_val_asic = '4:' + str(pre_val[0]) + "," + str(pre_val[1]) + "," + \ + str(pre_val[2]) + "," + str(pre_val[3]) + fvs = swsscommon.FieldValuePairs([(pre_name, pre_val_str)]) + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - tbl = swsscommon.Table(db, "PORT_TABLE") - ptbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") - atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") + tbl = swsscommon.Table(db, "PORT_TABLE") + ptbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") - ptbl.set("Ethernet0", fvs) + ptbl.set("Ethernet0", fvs) - time.sleep(1) + time.sleep(1) - # get fec - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True + # get fec + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_SERDES_PREEMPHASIS": - assert fv[1] == pre_val_asic + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_SERDES_PREEMPHASIS": + assert fv[1] == pre_val_asic -def test_PortIdriver(dvs, testlog): + def test_PortIdriver(self, dvs, testlog): - idrv_name = 'idriver' - idrv_val = [0x1,0x1,0x2,0x2] - idrv_val_str = str(hex(idrv_val[0])) + "," + str(hex(idrv_val[1]))+ "," + \ - str(hex(idrv_val[2]))+ "," + str(hex(idrv_val[3])) + idrv_name = 'idriver' + idrv_val = [0x1,0x1,0x2,0x2] + idrv_val_str = str(hex(idrv_val[0])) + "," + str(hex(idrv_val[1]))+ "," + \ + str(hex(idrv_val[2]))+ "," + str(hex(idrv_val[3])) - idrv_val_asic = '4:' + str(idrv_val[0]) + "," + str(idrv_val[1]) + "," + \ - str(idrv_val[2]) + "," + str(idrv_val[3]) - fvs = swsscommon.FieldValuePairs([(idrv_name, idrv_val_str)]) - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + idrv_val_asic = '4:' + str(idrv_val[0]) + "," + str(idrv_val[1]) + "," + \ + str(idrv_val[2]) + "," + str(idrv_val[3]) + fvs = swsscommon.FieldValuePairs([(idrv_name, idrv_val_str)]) + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - tbl = swsscommon.Table(db, "PORT_TABLE") - ptbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") - atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") + tbl = swsscommon.Table(db, "PORT_TABLE") + ptbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") - ptbl.set("Ethernet0", fvs) + ptbl.set("Ethernet0", fvs) - time.sleep(1) + time.sleep(1) - # get fec - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True + # get fec + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_SERDES_IDRIVER": - assert fv[1] == idrv_val_asic + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_SERDES_IDRIVER": + assert fv[1] == idrv_val_asic -def test_PortIpredriver(dvs, testlog): + def test_PortIpredriver(self, dvs, testlog): - ipre_name = 'ipredriver' - ipre_val = [0x2,0x3,0x4,0x5] - ipre_val_str = str(hex(ipre_val[0])) + "," + str(hex(ipre_val[1]))+ "," + \ - str(hex(ipre_val[2]))+ "," + str(hex(ipre_val[3])) + ipre_name = 'ipredriver' + ipre_val = [0x2,0x3,0x4,0x5] + ipre_val_str = str(hex(ipre_val[0])) + "," + str(hex(ipre_val[1]))+ "," + \ + str(hex(ipre_val[2]))+ "," + str(hex(ipre_val[3])) - ipre_val_asic = '4:' + str(ipre_val[0]) + "," + str(ipre_val[1]) + "," + \ - str(ipre_val[2]) + "," + str(ipre_val[3]) - fvs = swsscommon.FieldValuePairs([(ipre_name, ipre_val_str)]) - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + ipre_val_asic = '4:' + str(ipre_val[0]) + "," + str(ipre_val[1]) + "," + \ + str(ipre_val[2]) + "," + str(ipre_val[3]) + fvs = swsscommon.FieldValuePairs([(ipre_name, ipre_val_str)]) + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - tbl = swsscommon.Table(db, "PORT_TABLE") - ptbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") - atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") + tbl = swsscommon.Table(db, "PORT_TABLE") + ptbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") - ptbl.set("Ethernet0", fvs) + ptbl.set("Ethernet0", fvs) - time.sleep(1) + time.sleep(1) - # get fec - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True + # get fec + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_SERDES_IPREDRIVER": - assert fv[1] == ipre_val_asic + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_SERDES_IPREDRIVER": + assert fv[1] == ipre_val_asic diff --git a/tests/test_port_an.py b/tests/test_port_an.py new file mode 100644 index 0000000000..67ce59f317 --- /dev/null +++ b/tests/test_port_an.py @@ -0,0 +1,173 @@ +from swsscommon import swsscommon +import time +import os + +class TestPortAutoNeg(object): + def test_PortAutoNegCold(self, dvs, testlog): + + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + + tbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") + + # set autoneg = false and speed = 1000 + fvs = swsscommon.FieldValuePairs([("autoneg","1"), ("speed", "1000")]) + + tbl.set("Ethernet0", fvs) + + time.sleep(1) + + adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True + + assert "SAI_PORT_ATTR_AUTO_NEG_MODE" in [fv[0] for fv in fvs] + assert "SAI_PORT_ATTR_ADVERTISED_SPEED" in [fv[0] for fv in fvs] + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": + assert fv[1] == "true" + elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": + assert fv[1] == "1:1000" + + # set speed = 100 + fvs = swsscommon.FieldValuePairs([("speed", "100")]) + + tbl.set("Ethernet0", fvs) + + time.sleep(1) + + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True + + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": + assert fv[1] == "true" + elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": + assert fv[1] == "1:100" + + # change autoneg to false + fvs = swsscommon.FieldValuePairs([("autoneg","0")]) + + tbl.set("Ethernet0", fvs) + + time.sleep(1) + + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True + + assert "SAI_PORT_ATTR_AUTO_NEG_MODE" in [fv[0] for fv in fvs] + assert "SAI_PORT_ATTR_ADVERTISED_SPEED" in [fv[0] for fv in fvs] + assert "SAI_PORT_ATTR_SPEED" in [fv[0] for fv in fvs] + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": + assert fv[1] == "false" + elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": + assert fv[1] == "1:100" + elif fv[0] == "SAI_PORT_ATTR_SPEED": + assert fv[1] == "100" + + # set speed = 1000 + fvs = swsscommon.FieldValuePairs([("speed", "1000")]) + + tbl.set("Ethernet0", fvs) + + time.sleep(1) + + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True + + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": + assert fv[1] == "false" + elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": + assert fv[1] == "1:100" + elif fv[0] == "SAI_PORT_ATTR_SPEED": + assert fv[1] == "1000" + + def test_PortAutoNegWarm(self, dvs, testlog): + + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + cdb = swsscommon.DBConnector(4, dvs.redis_sock, 0) + sdb = swsscommon.DBConnector(6, dvs.redis_sock, 0) + + tbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") + ctbl = swsscommon.Table(cdb, "PORT") + stbl = swsscommon.Table(sdb, "PORT_TABLE") + + # set autoneg = true and speed = 1000 + fvs = swsscommon.FieldValuePairs([("autoneg","1"), ("speed", "1000")]) + ctbl.set("Ethernet0", fvs) + + time.sleep(1) + + adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + + atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True + + assert "SAI_PORT_ATTR_AUTO_NEG_MODE" in [fv[0] for fv in fvs] + assert "SAI_PORT_ATTR_ADVERTISED_SPEED" in [fv[0] for fv in fvs] + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": + assert fv[1] == "true" + elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": + assert fv[1] == "1:1000" + + # set speed = 100 + fvs = swsscommon.FieldValuePairs([("speed", "100")]) + + ctbl.set("Ethernet0", fvs) + + time.sleep(1) + + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True + + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": + assert fv[1] == "true" + elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": + assert fv[1] == "1:100" + + # set admin up + cfvs = swsscommon.FieldValuePairs([("admin_status", "up")]) + ctbl.set("Ethernet0", cfvs) + + # enable warm restart + (exitcode, result) = dvs.runcmd("config warm_restart enable swss") + assert exitcode == 0 + + # freeze orchagent for warm restart + (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check") + assert result == "RESTARTCHECK succeeded\n" + time.sleep(2) + + try: + # restart orchagent + # clean port state + dvs.stop_swss() + ports = stbl.getKeys() + for port in ports: + stbl._del(port) + dvs.start_swss() + time.sleep(2) + + # check ASIC DB after warm restart + (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) + assert status == True + + assert "SAI_PORT_ATTR_AUTO_NEG_MODE" in [fv[0] for fv in fvs] + assert "SAI_PORT_ATTR_ADVERTISED_SPEED" in [fv[0] for fv in fvs] + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": + assert fv[1] == "true" + elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": + assert fv[1] == "1:100" + + finally: + # disable warm restart + dvs.runcmd("config warm_restart disable swss") + # slow down crm polling + dvs.runcmd("crm config polling interval 10000") diff --git a/tests/test_port_an_cold.py b/tests/test_port_an_cold.py deleted file mode 100644 index 3b4414059a..0000000000 --- a/tests/test_port_an_cold.py +++ /dev/null @@ -1,85 +0,0 @@ -from swsscommon import swsscommon -import time -import os - -def test_PortAutoNeg(dvs, testlog): - - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - - tbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") - - # set autoneg = false and speed = 1000 - fvs = swsscommon.FieldValuePairs([("autoneg","1"), ("speed", "1000")]) - - tbl.set("Ethernet0", fvs) - - time.sleep(1) - - adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - - atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True - - assert "SAI_PORT_ATTR_AUTO_NEG_MODE" in [fv[0] for fv in fvs] - assert "SAI_PORT_ATTR_ADVERTISED_SPEED" in [fv[0] for fv in fvs] - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": - assert fv[1] == "true" - elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": - assert fv[1] == "1:1000" - - # set speed = 100 - fvs = swsscommon.FieldValuePairs([("speed", "100")]) - - tbl.set("Ethernet0", fvs) - - time.sleep(1) - - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True - - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": - assert fv[1] == "true" - elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": - assert fv[1] == "1:100" - - # change autoneg to false - fvs = swsscommon.FieldValuePairs([("autoneg","0")]) - - tbl.set("Ethernet0", fvs) - - time.sleep(1) - - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True - - assert "SAI_PORT_ATTR_AUTO_NEG_MODE" in [fv[0] for fv in fvs] - assert "SAI_PORT_ATTR_ADVERTISED_SPEED" in [fv[0] for fv in fvs] - assert "SAI_PORT_ATTR_SPEED" in [fv[0] for fv in fvs] - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": - assert fv[1] == "false" - elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": - assert fv[1] == "1:100" - elif fv[0] == "SAI_PORT_ATTR_SPEED": - assert fv[1] == "100" - - # set speed = 1000 - fvs = swsscommon.FieldValuePairs([("speed", "1000")]) - - tbl.set("Ethernet0", fvs) - - time.sleep(1) - - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True - - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": - assert fv[1] == "false" - elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": - assert fv[1] == "1:100" - elif fv[0] == "SAI_PORT_ATTR_SPEED": - assert fv[1] == "1000" diff --git a/tests/test_port_an_warm.py b/tests/test_port_an_warm.py deleted file mode 100644 index 50ffbbf819..0000000000 --- a/tests/test_port_an_warm.py +++ /dev/null @@ -1,90 +0,0 @@ -from swsscommon import swsscommon -import time -import os - -def test_PortAutoNeg_warm(dvs, testlog): - - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - cdb = swsscommon.DBConnector(4, dvs.redis_sock, 0) - sdb = swsscommon.DBConnector(6, dvs.redis_sock, 0) - - tbl = swsscommon.ProducerStateTable(db, "PORT_TABLE") - ctbl = swsscommon.Table(cdb, "PORT") - stbl = swsscommon.Table(sdb, "PORT_TABLE") - - # set autoneg = true and speed = 1000 - fvs = swsscommon.FieldValuePairs([("autoneg","1"), ("speed", "1000")]) - ctbl.set("Ethernet0", fvs) - - time.sleep(1) - - adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - - atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True - - assert "SAI_PORT_ATTR_AUTO_NEG_MODE" in [fv[0] for fv in fvs] - assert "SAI_PORT_ATTR_ADVERTISED_SPEED" in [fv[0] for fv in fvs] - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": - assert fv[1] == "true" - elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": - assert fv[1] == "1:1000" - - # set speed = 100 - fvs = swsscommon.FieldValuePairs([("speed", "100")]) - - ctbl.set("Ethernet0", fvs) - - time.sleep(1) - - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True - - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": - assert fv[1] == "true" - elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": - assert fv[1] == "1:100" - - # set admin up - cfvs = swsscommon.FieldValuePairs([("admin_status", "up")]) - ctbl.set("Ethernet0", cfvs) - - # enable warm restart - (exitcode, result) = dvs.runcmd("config warm_restart enable swss") - assert exitcode == 0 - - # freeze orchagent for warm restart - (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check") - assert result == "RESTARTCHECK succeeded\n" - time.sleep(2) - - try: - # restart orchagent - # clean port state - dvs.stop_swss() - ports = stbl.getKeys() - for port in ports: - stbl._del(port) - dvs.start_swss() - time.sleep(2) - - # check ASIC DB after warm restart - (status, fvs) = atbl.get(dvs.asicdb.portnamemap["Ethernet0"]) - assert status == True - - assert "SAI_PORT_ATTR_AUTO_NEG_MODE" in [fv[0] for fv in fvs] - assert "SAI_PORT_ATTR_ADVERTISED_SPEED" in [fv[0] for fv in fvs] - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_AUTO_NEG_MODE": - assert fv[1] == "true" - elif fv[0] == "SAI_PORT_ATTR_ADVERTISED_SPEED": - assert fv[1] == "1:100" - - finally: - # disable warm restart - dvs.runcmd("config warm_restart disable swss") - # slow down crm polling - dvs.runcmd("crm config polling interval 10000") diff --git a/tests/test_port_buffer_rel.py b/tests/test_port_buffer_rel.py index 231bec6ddf..ed21660562 100644 --- a/tests/test_port_buffer_rel.py +++ b/tests/test_port_buffer_rel.py @@ -2,32 +2,32 @@ import time # The test check that the ports will be up, when the admin state is UP by conf db. +class TestPortBuffer(object): + def test_PortsAreUpAfterBuffers(self, dvs, testlog): + num_ports = 32 + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) -def test_PortsAreUpAfterBuffers(dvs, testlog): - num_ports = 32 - asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + conf_port_table = swsscommon.Table(conf_db, "PORT") + asic_port_table = swsscommon.Table(asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") - conf_port_table = swsscommon.Table(conf_db, "PORT") - asic_port_table = swsscommon.Table(asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") + # enable all ports + fvs = swsscommon.FieldValuePairs([("admin_status", "up")]) + for i in range(0, num_ports): + conf_port_table.set("Ethernet%d" % (i*4), fvs) - # enable all ports - fvs = swsscommon.FieldValuePairs([("admin_status", "up")]) - for i in range(0, num_ports): - conf_port_table.set("Ethernet%d" % (i*4), fvs) + time.sleep(5) - time.sleep(5) - - # check that the ports are enabled in ASIC - asic_port_records = asic_port_table.getKeys() - assert len(asic_port_records) == (num_ports + 1), "Number of port records doesn't match number of ports" # +CPU port - num_set = 0 - for k in asic_port_records: - status, fvs = asic_port_table.get(k) - assert status, "Got an error when get a key" - for fv in fvs: - if fv[0] == "SAI_PORT_ATTR_ADMIN_STATE": - assert fv[1] == "true", "The port isn't UP as expected" - num_set += 1 - # make sure that state is set for all "num_ports" ports - assert num_set == num_ports, "Not all ports are up" + # check that the ports are enabled in ASIC + asic_port_records = asic_port_table.getKeys() + assert len(asic_port_records) == (num_ports + 1), "Number of port records doesn't match number of ports" # +CPU port + num_set = 0 + for k in asic_port_records: + status, fvs = asic_port_table.get(k) + assert status, "Got an error when get a key" + for fv in fvs: + if fv[0] == "SAI_PORT_ATTR_ADMIN_STATE": + assert fv[1] == "true", "The port isn't UP as expected" + num_set += 1 + # make sure that state is set for all "num_ports" ports + assert num_set == num_ports, "Not all ports are up" diff --git a/tests/test_portchannel.py b/tests/test_portchannel.py index e4875160f9..320cf598e8 100644 --- a/tests/test_portchannel.py +++ b/tests/test_portchannel.py @@ -3,56 +3,57 @@ import re import json -def test_PortChannel(dvs, testlog): +class TestPortchannel(object): + def test_Portchannel(self, dvs, testlog): - # create port channel - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - ps = swsscommon.ProducerStateTable(db, "LAG_TABLE") - fvs = swsscommon.FieldValuePairs([("admin", "up"), ("mtu", "1500")]) + # create port channel + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + ps = swsscommon.ProducerStateTable(db, "LAG_TABLE") + fvs = swsscommon.FieldValuePairs([("admin", "up"), ("mtu", "1500")]) - ps.set("PortChannel0001", fvs) + ps.set("PortChannel0001", fvs) - # create port channel member - ps = swsscommon.ProducerStateTable(db, "LAG_MEMBER_TABLE") - fvs = swsscommon.FieldValuePairs([("status", "enabled")]) + # create port channel member + ps = swsscommon.ProducerStateTable(db, "LAG_MEMBER_TABLE") + fvs = swsscommon.FieldValuePairs([("status", "enabled")]) - ps.set("PortChannel0001:Ethernet0", fvs) + ps.set("PortChannel0001:Ethernet0", fvs) - time.sleep(1) + time.sleep(1) - # check asic db - asicdb = swsscommon.DBConnector(1, dvs.redis_sock, 0) + # check asic db + asicdb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - lagtbl = swsscommon.Table(asicdb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG") - lags = lagtbl.getKeys() - assert len(lags) == 1 + lagtbl = swsscommon.Table(asicdb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG") + lags = lagtbl.getKeys() + assert len(lags) == 1 - lagmtbl = swsscommon.Table(asicdb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG_MEMBER") - lagms = lagmtbl.getKeys() - assert len(lagms) == 1 + lagmtbl = swsscommon.Table(asicdb, "ASIC_STATE:SAI_OBJECT_TYPE_LAG_MEMBER") + lagms = lagmtbl.getKeys() + assert len(lagms) == 1 - (status, fvs) = lagmtbl.get(lagms[0]) - for fv in fvs: - if fv[0] == "SAI_LAG_MEMBER_ATTR_LAG_ID": - assert fv[1] == lags[0] - elif fv[0] == "SAI_LAG_MEMBER_ATTR_PORT_ID": - assert dvs.asicdb.portoidmap[fv[1]] == "Ethernet0" - else: - assert False + (status, fvs) = lagmtbl.get(lagms[0]) + for fv in fvs: + if fv[0] == "SAI_LAG_MEMBER_ATTR_LAG_ID": + assert fv[1] == lags[0] + elif fv[0] == "SAI_LAG_MEMBER_ATTR_PORT_ID": + assert dvs.asicdb.portoidmap[fv[1]] == "Ethernet0" + else: + assert False - # remove port channel member - ps = swsscommon.ProducerStateTable(db, "LAG_MEMBER_TABLE") - ps._del("PortChannel0001:Ethernet0") + # remove port channel member + ps = swsscommon.ProducerStateTable(db, "LAG_MEMBER_TABLE") + ps._del("PortChannel0001:Ethernet0") - # remove port channel - ps = swsscommon.ProducerStateTable(db, "LAG_TABLE") - ps._del("PortChannel0001") + # remove port channel + ps = swsscommon.ProducerStateTable(db, "LAG_TABLE") + ps._del("PortChannel0001") - time.sleep(1) + time.sleep(1) - # check asic db - lags = lagtbl.getKeys() - assert len(lags) == 0 + # check asic db + lags = lagtbl.getKeys() + assert len(lags) == 0 - lagms = lagmtbl.getKeys() - assert len(lagms) == 0 + lagms = lagmtbl.getKeys() + assert len(lagms) == 0 diff --git a/tests/test_route.py b/tests/test_route.py index d6f4a502c7..c992821451 100644 --- a/tests/test_route.py +++ b/tests/test_route.py @@ -4,41 +4,42 @@ import time import json -def test_RouteAdd(dvs, testlog): +class TestRoute(object): + def test_RouteAdd(self, dvs, testlog): - 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("Ethernet0", fvs) - intf_tbl.set("Ethernet4", fvs) - dvs.runcmd("ifconfig Ethernet0 up") - dvs.runcmd("ifconfig Ethernet4 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("Ethernet0", fvs) + intf_tbl.set("Ethernet4", 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") + dvs.servers[0].runcmd("ifconfig eth0 10.0.0.1/31") + dvs.servers[0].runcmd("ip route add default via 10.0.0.0") - dvs.servers[1].runcmd("ifconfig eth0 10.0.0.3/31") - dvs.servers[1].runcmd("ip route add default via 10.0.0.2") + dvs.servers[1].runcmd("ifconfig eth0 10.0.0.3/31") + dvs.servers[1].runcmd("ip route add default via 10.0.0.2") - # get neighbor and arp entry - dvs.servers[0].runcmd("ping -c 1 10.0.0.3") + # get neighbor and arp entry + dvs.servers[0].runcmd("ping -c 1 10.0.0.3") - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") - fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1"), ("ifname", "Ethernet0")]) + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + ps = swsscommon.ProducerStateTable(db, "ROUTE_TABLE") + fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1"), ("ifname", "Ethernet0")]) - pubsub = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE_ROUTE_ENTRY") + pubsub = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE_ROUTE_ENTRY") - ps.set("2.2.2.0/24", fvs) + ps.set("2.2.2.0/24", fvs) - # check if route was propagated to ASIC DB + # check if route was propagated to ASIC DB - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsub) + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsub) - assert len(addobjs) == 1 + assert len(addobjs) == 1 - rt_key = json.loads(addobjs[0]['key']) + rt_key = json.loads(addobjs[0]['key']) - assert rt_key['dest'] == "2.2.2.0/24" + assert rt_key['dest'] == "2.2.2.0/24" diff --git a/tests/test_setro.py b/tests/test_setro.py index 8c962dd20e..84b004a878 100644 --- a/tests/test_setro.py +++ b/tests/test_setro.py @@ -4,37 +4,38 @@ import redis from pprint import pprint -def test_SetReadOnlyAttribute(dvs, testlog): +class TestSetRo(object): + def test_SetReadOnlyAttribute(self, dvs, testlog): - db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - tbl = swsscommon.Table(db, "ASIC_STATE:SAI_OBJECT_TYPE_SWITCH") + tbl = swsscommon.Table(db, "ASIC_STATE:SAI_OBJECT_TYPE_SWITCH") - keys = tbl.getKeys() + keys = tbl.getKeys() - assert len(keys) == 1 + assert len(keys) == 1 - swVid = keys[0] - - r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB) + swVid = keys[0] - swRid = r.hget("VIDTORID", swVid) + r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB) - assert swRid is not None + swRid = r.hget("VIDTORID", swVid) - ntf = swsscommon.NotificationProducer(db, "SAI_VS_UNITTEST_CHANNEL") + assert swRid is not None - fvp = swsscommon.FieldValuePairs() + ntf = swsscommon.NotificationProducer(db, "SAI_VS_UNITTEST_CHANNEL") - ntf.send("enable_unittests", "true", fvp) + fvp = swsscommon.FieldValuePairs() - fvp = swsscommon.FieldValuePairs([('SAI_SWITCH_ATTR_PORT_MAX_MTU', '42')]) + ntf.send("enable_unittests", "true", fvp) - key = "SAI_OBJECT_TYPE_SWITCH:" + swRid + fvp = swsscommon.FieldValuePairs([('SAI_SWITCH_ATTR_PORT_MAX_MTU', '42')]) - print key + key = "SAI_OBJECT_TYPE_SWITCH:" + swRid - ntf.send("set_ro", key, fvp) + print key - # make action on appdb so orchagent will get RO value - # read asic db to see if orchagent behaved correctly + ntf.send("set_ro", key, fvp) + + # make action on appdb so orchagent will get RO value + # read asic db to see if orchagent behaved correctly diff --git a/tests/test_vrf.py b/tests/test_vrf.py index 3dec3e0dc1..a53d498b98 100644 --- a/tests/test_vrf.py +++ b/tests/test_vrf.py @@ -150,90 +150,90 @@ def packet_action_gen(): r = random.choice(values) return r[0], r[1] - -def test_VRFOrch_Comprehensive(dvs, testlog): - asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - - attributes = [ - ('v4', 'SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE', boolean_gen), - ('v6', 'SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE', boolean_gen), - ('src_mac', 'SAI_VIRTUAL_ROUTER_ATTR_SRC_MAC_ADDRESS', mac_addr_gen), - ('ttl_action', 'SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_PACKET_ACTION', packet_action_gen), - ('ip_opt_action', 'SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS_PACKET_ACTION', packet_action_gen), - ('l3_mc_action', 'SAI_VIRTUAL_ROUTER_ATTR_UNKNOWN_L3_MULTICAST_PACKET_ACTION', packet_action_gen), - ] - - random.seed(int(time.clock())) - - for n in xrange(2**len(attributes)): - # generate testcases for all combinations of attributes +class TestVrf(object): + def test_VRFOrch_Comprehensive(self, dvs, testlog): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + + attributes = [ + ('v4', 'SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE', boolean_gen), + ('v6', 'SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE', boolean_gen), + ('src_mac', 'SAI_VIRTUAL_ROUTER_ATTR_SRC_MAC_ADDRESS', mac_addr_gen), + ('ttl_action', 'SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_PACKET_ACTION', packet_action_gen), + ('ip_opt_action', 'SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS_PACKET_ACTION', packet_action_gen), + ('l3_mc_action', 'SAI_VIRTUAL_ROUTER_ATTR_UNKNOWN_L3_MULTICAST_PACKET_ACTION', packet_action_gen), + ] + + random.seed(int(time.clock())) + + for n in xrange(2**len(attributes)): + # generate testcases for all combinations of attributes + req_attr = [] + exp_attr = {} + vrf_name = "vrf_%d" % n + bmask = 0x1 + for an in xrange(len(attributes)): + if (bmask & n) > 0: + req_res, exp_res = attributes[an][2]() + req_attr.append((attributes[an][0], req_res)) + exp_attr[attributes[an][1]] = exp_res + bmask <<= 1 + state = vrf_create(asic_db, appl_db, vrf_name, req_attr, exp_attr) + vrf_remove(asic_db, appl_db, vrf_name, state) + + + def test_VRFOrch(self, dvs, testlog): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + state = vrf_create(asic_db, appl_db, "vrf0", + [ + ], + { + } + ) + vrf_remove(asic_db, appl_db, "vrf0", state) + + state = vrf_create(asic_db, appl_db, "vrf1", + [ + ('v4', 'true'), + ('src_mac', '02:04:06:07:08:09'), + ], + { + 'SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE': 'true', + 'SAI_VIRTUAL_ROUTER_ATTR_SRC_MAC_ADDRESS': '02:04:06:07:08:09', + } + ) + vrf_remove(asic_db, appl_db, "vrf1", state) + + def test_VRFOrch_Update(self, dvs, testlog): + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + + attributes = [ + ('v4', 'SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE', boolean_gen), + ('v6', 'SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE', boolean_gen), + ('src_mac', 'SAI_VIRTUAL_ROUTER_ATTR_SRC_MAC_ADDRESS', mac_addr_gen), + ('ttl_action', 'SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_PACKET_ACTION', packet_action_gen), + ('ip_opt_action', 'SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS_PACKET_ACTION', packet_action_gen), + ('l3_mc_action', 'SAI_VIRTUAL_ROUTER_ATTR_UNKNOWN_L3_MULTICAST_PACKET_ACTION', packet_action_gen), + ] + + random.seed(int(time.clock())) + + state = vrf_create(asic_db, appl_db, "vrf_a", + [ + ], + { + } + ) + + # try to update each attribute req_attr = [] exp_attr = {} - vrf_name = "vrf_%d" % n - bmask = 0x1 - for an in xrange(len(attributes)): - if (bmask & n) > 0: - req_res, exp_res = attributes[an][2]() - req_attr.append((attributes[an][0], req_res)) - exp_attr[attributes[an][1]] = exp_res - bmask <<= 1 - state = vrf_create(asic_db, appl_db, vrf_name, req_attr, exp_attr) - vrf_remove(asic_db, appl_db, vrf_name, state) - - -def test_VRFOrch(dvs, testlog): - asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - state = vrf_create(asic_db, appl_db, "vrf0", - [ - ], - { - } - ) - vrf_remove(asic_db, appl_db, "vrf0", state) - - state = vrf_create(asic_db, appl_db, "vrf1", - [ - ('v4', 'true'), - ('src_mac', '02:04:06:07:08:09'), - ], - { - 'SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE': 'true', - 'SAI_VIRTUAL_ROUTER_ATTR_SRC_MAC_ADDRESS': '02:04:06:07:08:09', - } - ) - vrf_remove(asic_db, appl_db, "vrf1", state) - -def test_VRFOrch_Update(dvs, testlog): - asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - - attributes = [ - ('v4', 'SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V4_STATE', boolean_gen), - ('v6', 'SAI_VIRTUAL_ROUTER_ATTR_ADMIN_V6_STATE', boolean_gen), - ('src_mac', 'SAI_VIRTUAL_ROUTER_ATTR_SRC_MAC_ADDRESS', mac_addr_gen), - ('ttl_action', 'SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_TTL1_PACKET_ACTION', packet_action_gen), - ('ip_opt_action', 'SAI_VIRTUAL_ROUTER_ATTR_VIOLATION_IP_OPTIONS_PACKET_ACTION', packet_action_gen), - ('l3_mc_action', 'SAI_VIRTUAL_ROUTER_ATTR_UNKNOWN_L3_MULTICAST_PACKET_ACTION', packet_action_gen), - ] - - random.seed(int(time.clock())) - - state = vrf_create(asic_db, appl_db, "vrf_a", - [ - ], - { - } - ) - - # try to update each attribute - req_attr = [] - exp_attr = {} - for attr in attributes: - req_res, exp_res = attr[2]() - req_attr.append((attr[0], req_res)) - exp_attr[attr[1]] = exp_res - vrf_update(asic_db, appl_db, "vrf_a", req_attr, exp_attr, state) + for attr in attributes: + req_res, exp_res = attr[2]() + req_attr.append((attr[0], req_res)) + exp_attr[attr[1]] = exp_res + vrf_update(asic_db, appl_db, "vrf_a", req_attr, exp_attr, state) - vrf_remove(asic_db, appl_db, "vrf_a", state) + vrf_remove(asic_db, appl_db, "vrf_a", state) diff --git a/tests/test_vxlan_tunnel.py b/tests/test_vxlan_tunnel.py index c1306b8966..225a913bb6 100644 --- a/tests/test_vxlan_tunnel.py +++ b/tests/test_vxlan_tunnel.py @@ -241,69 +241,69 @@ def get_lo(dvs): return lo_id +class TestVxlan(object): + def test_vxlan_term_orch(self, dvs, testlog): + tunnel_map_ids = set() + tunnel_map_entry_ids = set() + tunnel_ids = set() + tunnel_term_ids = set() + tunnel_map_map = {} + vlan_ids = get_exist_entries(dvs, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + loopback_id = get_lo(dvs) -def test_vxlan_term_orch(dvs, testlog): - tunnel_map_ids = set() - tunnel_map_entry_ids = set() - tunnel_ids = set() - tunnel_term_ids = set() - tunnel_map_map = {} - vlan_ids = get_exist_entries(dvs, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") - loopback_id = get_lo(dvs) + create_vlan(dvs, "Vlan50", vlan_ids) + create_vlan(dvs, "Vlan51", vlan_ids) + create_vlan(dvs, "Vlan52", vlan_ids) + create_vlan(dvs, "Vlan53", vlan_ids) + create_vlan(dvs, "Vlan54", vlan_ids) + create_vlan(dvs, "Vlan55", vlan_ids) + create_vlan(dvs, "Vlan56", vlan_ids) + create_vlan(dvs, "Vlan57", vlan_ids) - create_vlan(dvs, "Vlan50", vlan_ids) - create_vlan(dvs, "Vlan51", vlan_ids) - create_vlan(dvs, "Vlan52", vlan_ids) - create_vlan(dvs, "Vlan53", vlan_ids) - create_vlan(dvs, "Vlan54", vlan_ids) - create_vlan(dvs, "Vlan55", vlan_ids) - create_vlan(dvs, "Vlan56", vlan_ids) - create_vlan(dvs, "Vlan57", vlan_ids) + create_vxlan_tunnel(dvs, 'tunnel_1', '10.0.0.1', '100.100.100.1', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) - create_vxlan_tunnel(dvs, 'tunnel_1', '10.0.0.1', '100.100.100.1', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) + create_vxlan_tunnel_entry(dvs, 'tunnel_1', 'entry_1', tunnel_map_map, 'Vlan50', '850', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) - create_vxlan_tunnel_entry(dvs, 'tunnel_1', 'entry_1', tunnel_map_map, 'Vlan50', '850', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) + tunnel_map_map['tunnel_1'] = check_vxlan_tunnel(dvs,'10.0.0.1', '100.100.100.1', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) - tunnel_map_map['tunnel_1'] = check_vxlan_tunnel(dvs,'10.0.0.1', '100.100.100.1', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) + create_vxlan_tunnel(dvs, 'tunnel_2', '11.0.0.2', '101.101.101.2', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) - create_vxlan_tunnel(dvs, 'tunnel_2', '11.0.0.2', '101.101.101.2', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) + create_vxlan_tunnel_entry(dvs, 'tunnel_2', 'entry_1', tunnel_map_map, 'Vlan51', '851', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) - create_vxlan_tunnel_entry(dvs, 'tunnel_2', 'entry_1', tunnel_map_map, 'Vlan51', '851', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) + tunnel_map_map['tunnel_2'] = check_vxlan_tunnel(dvs,'11.0.0.2', '101.101.101.2', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) - tunnel_map_map['tunnel_2'] = check_vxlan_tunnel(dvs,'11.0.0.2', '101.101.101.2', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) + create_vxlan_tunnel(dvs, 'tunnel_3', '12.0.0.3', '0.0.0.0', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) - create_vxlan_tunnel(dvs, 'tunnel_3', '12.0.0.3', '0.0.0.0', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) + create_vxlan_tunnel_entry(dvs, 'tunnel_3', 'entry_1', tunnel_map_map, 'Vlan52', '852', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) - create_vxlan_tunnel_entry(dvs, 'tunnel_3', 'entry_1', tunnel_map_map, 'Vlan52', '852', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) + tunnel_map_map['tunnel_3'] = check_vxlan_tunnel(dvs, '12.0.0.3', '0.0.0.0', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) - tunnel_map_map['tunnel_3'] = check_vxlan_tunnel(dvs, '12.0.0.3', '0.0.0.0', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) + create_vxlan_tunnel(dvs, 'tunnel_4', '15.0.0.5', '0.0.0.0', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id, True) - create_vxlan_tunnel(dvs, 'tunnel_4', '15.0.0.5', '0.0.0.0', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id, True) + create_vxlan_tunnel_entry(dvs, 'tunnel_4', 'entry_1', tunnel_map_map, 'Vlan53', '853', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) - create_vxlan_tunnel_entry(dvs, 'tunnel_4', 'entry_1', tunnel_map_map, 'Vlan53', '853', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) + tunnel_map_map['tunnel_4'] = check_vxlan_tunnel(dvs, '15.0.0.5', '0.0.0.0', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) - tunnel_map_map['tunnel_4'] = check_vxlan_tunnel(dvs, '15.0.0.5', '0.0.0.0', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids, loopback_id) + create_vxlan_tunnel_entry(dvs, 'tunnel_1', 'entry_2', tunnel_map_map, 'Vlan54', '854', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) - create_vxlan_tunnel_entry(dvs, 'tunnel_1', 'entry_2', tunnel_map_map, 'Vlan54', '854', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) + create_vxlan_tunnel_entry(dvs, 'tunnel_2', 'entry_2', tunnel_map_map, 'Vlan55', '855', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) - create_vxlan_tunnel_entry(dvs, 'tunnel_2', 'entry_2', tunnel_map_map, 'Vlan55', '855', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) + create_vxlan_tunnel_entry(dvs, 'tunnel_3', 'entry_2', tunnel_map_map, 'Vlan56', '856', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) - create_vxlan_tunnel_entry(dvs, 'tunnel_3', 'entry_2', tunnel_map_map, 'Vlan56', '856', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) - - create_vxlan_tunnel_entry(dvs, 'tunnel_4', 'entry_2', tunnel_map_map, 'Vlan57', '857', - tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) + create_vxlan_tunnel_entry(dvs, 'tunnel_4', 'entry_2', tunnel_map_map, 'Vlan57', '857', + tunnel_map_ids, tunnel_map_entry_ids, tunnel_ids, tunnel_term_ids) diff --git a/tests/test_warm_reboot.py b/tests/test_warm_reboot.py index e87c644b47..31795d3ddd 100644 --- a/tests/test_warm_reboot.py +++ b/tests/test_warm_reboot.py @@ -5,6 +5,14 @@ import json import pytest + +# 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 +# TBD: Need tune gc_thresh1/2/3 at host side of vs docker to support this. +NUM_INTF = 8 +NUM_NEIGH_PER_INTF = 16 #128 +NUM_OF_NEIGHS = (NUM_INTF*NUM_NEIGH_PER_INTF) + # Get restore count of all processes supporting warm restart def swss_get_RestoreCount(dvs, state_db): restore_count = {} @@ -106,213 +114,6 @@ def how_many_entries_exist(db, table): tbl = swsscommon.Table(db, table) return len(tbl.getKeys()) -def test_PortSyncdWarmRestart(dvs, testlog): - - conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) - - dvs.runcmd("config warm_restart enable swss") - - dvs.runcmd("ifconfig Ethernet16 up") - dvs.runcmd("ifconfig Ethernet20 up") - - time.sleep(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("Ethernet16|11.0.0.1/29", fvs) - intf_tbl.set("Ethernet20|11.0.0.9/29", fvs) - intf_tbl.set("Ethernet16", fvs) - intf_tbl.set("Ethernet20", 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 - dvs.servers[4].runcmd("ifconfig eth0 11.0.0.2/29") - dvs.servers[4].runcmd("ip route add default via 11.0.0.1") - - dvs.servers[5].runcmd("ip link set down dev eth0") == 0 - dvs.servers[5].runcmd("ip link set up dev eth0") == 0 - dvs.servers[5].runcmd("ifconfig eth0 11.0.0.10/29") - dvs.servers[5].runcmd("ip route add default via 11.0.0.9") - - time.sleep(1) - - # Ethernet port oper status should be up - check_port_oper_status(appl_db, "Ethernet16", "up") - check_port_oper_status(appl_db, "Ethernet20", "up") - - # Ping should work between servers via vs vlan interfaces - ping_stats = dvs.servers[4].runcmd("ping -c 1 11.0.0.10") - time.sleep(1) - - neighTbl = swsscommon.Table(appl_db, "NEIGH_TABLE") - (status, fvs) = neighTbl.get("Ethernet16:11.0.0.2") - assert status == True - - (status, fvs) = neighTbl.get("Ethernet20:11.0.0.10") - assert status == True - - restore_count = swss_get_RestoreCount(dvs, state_db) - - # restart portsyncd - dvs.runcmd(['sh', '-c', 'pkill -x portsyncd']) - - pubsub = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE") - dvs.runcmd(['sh', '-c', 'supervisorctl start portsyncd']) - - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) - assert nadd == 0 - assert ndel == 0 - - #new ip on server 5 - dvs.servers[5].runcmd("ifconfig eth0 11.0.0.11/29") - - # Ping should work between servers via vs Ethernet interfaces - ping_stats = dvs.servers[4].runcmd("ping -c 1 11.0.0.11") - - # new neighbor learn on VS - (status, fvs) = neighTbl.get("Ethernet20:11.0.0.11") - assert status == True - - # Port state change reflected in appDB correctly - dvs.servers[6].runcmd("ip link set down dev eth0") == 0 - dvs.servers[6].runcmd("ip link set up dev eth0") == 0 - time.sleep(1) - - check_port_oper_status(appl_db, "Ethernet16", "up") - check_port_oper_status(appl_db, "Ethernet20", "up") - check_port_oper_status(appl_db, "Ethernet24", "up") - - - 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") - intf_tbl._del("Ethernet16") - intf_tbl._del("Ethernet20") - time.sleep(2) - - -def test_VlanMgrdWarmRestart(dvs, testlog): - - conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) - - dvs.runcmd("ifconfig Ethernet16 0") - dvs.runcmd("ifconfig Ethernet20 0") - - dvs.runcmd("ifconfig Ethernet16 up") - dvs.runcmd("ifconfig Ethernet20 up") - - time.sleep(1) - - dvs.runcmd("config warm_restart enable swss") - - # create vlan - create_entry_tbl( - conf_db, - "VLAN", "Vlan16", - [ - ("vlanid", "16"), - ] - ) - # create vlan - create_entry_tbl( - conf_db, - "VLAN", "Vlan20", - [ - ("vlanid", "20"), - ] - ) - # create vlan member entry in config db. Don't use Ethernet0/4/8/12 as IP configured on them in previous testing. - create_entry_tbl( - conf_db, - "VLAN_MEMBER", "Vlan16|Ethernet16", - [ - ("tagging_mode", "untagged"), - ] - ) - - create_entry_tbl( - conf_db, - "VLAN_MEMBER", "Vlan20|Ethernet20", - [ - ("tagging_mode", "untagged"), - ] - ) - - time.sleep(1) - - 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) - intf_tbl.set("Vlan16", fvs) - intf_tbl.set("Vlan20", 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") - - dvs.servers[5].runcmd("ifconfig eth0 11.0.0.10/29") - dvs.servers[5].runcmd("ip route add default via 11.0.0.9") - - time.sleep(1) - - # Ping should work between servers via vs vlan interfaces - ping_stats = dvs.servers[4].runcmd("ping -c 1 11.0.0.10") - time.sleep(1) - - tbl = swsscommon.Table(appl_db, "NEIGH_TABLE") - (status, fvs) = tbl.get("Vlan16:11.0.0.2") - assert status == True - - (status, fvs) = tbl.get("Vlan20:11.0.0.10") - assert status == True - - (exitcode, bv_before) = dvs.runcmd("bridge vlan") - print(bv_before) - - restore_count = swss_get_RestoreCount(dvs, state_db) - - dvs.runcmd(['sh', '-c', 'pkill -x vlanmgrd']) - - pubsub = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE") - - dvs.runcmd(['sh', '-c', 'supervisorctl start vlanmgrd']) - time.sleep(2) - - (exitcode, bv_after) = dvs.runcmd("bridge vlan") - assert bv_after == bv_before - - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub, ignore=["SAI_OBJECT_TYPE_FDB_ENTRY"]) - assert nadd == 0 - assert ndel == 0 - - #new ip on server 5 - dvs.servers[5].runcmd("ifconfig eth0 11.0.0.11/29") - - # Ping should work between servers via vs vlan interfaces - ping_stats = dvs.servers[4].runcmd("ping -c 1 11.0.0.11") - - # new neighbor learn on VS - (status, fvs) = tbl.get("Vlan20:11.0.0.11") - assert status == True - - 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") - intf_tbl._del("Vlan16") - intf_tbl._del("Vlan20") - time.sleep(2) - def stop_neighsyncd(dvs): dvs.runcmd(['sh', '-c', 'pkill -x neighsyncd']) @@ -384,593 +185,6 @@ def check_syslog_for_neighbor_entry(dvs, marker, new_cnt, delete_cnt, iptype): else: assert "iptype is unknown" == "" -def test_swss_neighbor_syncup(dvs, testlog): - - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) - - dvs.runcmd("config warm_restart enable swss") - - # - # Testcase1: - # Add neighbor entries in linux kernel, appDB should get all of them - # - - # create neighbor entries (4 ipv4 and 4 ip6, two each on each interface) in linux kernel - intfs = ["Ethernet24", "Ethernet28"] - - for intf in intfs: - # set timeout to be the same as real HW - dvs.runcmd("sysctl -w net.ipv4.neigh.{}.base_reachable_time_ms=1800000".format(intf)) - dvs.runcmd("sysctl -w net.ipv6.neigh.{}.base_reachable_time_ms=1800000".format(intf)) - - #enable ipv6 on docker - dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") - - 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) - intf_tbl.set("{}".format(intfs[0]), fvs) - intf_tbl.set("{}".format(intfs[1]), fvs) - intf_tbl.set("{}".format(intfs[0]), fvs) - intf_tbl.set("{}".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"] - - macs = ["00:00:00:00:24:02", "00:00:00:00:24:03", "00:00:00:00:28:02", "00:00:00:00:28:03"] - - for i in range(len(ips)): - dvs.runcmd("ip neigh add {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], macs[i])) - - for i in range(len(v6ips)): - dvs.runcmd("ip -6 neigh add {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], macs[i])) - - time.sleep(1) - - # Check the neighbor entries are inserted correctly - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - tbl = swsscommon.Table(db, "NEIGH_TABLE") - - for i in range(len(ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) - assert status == True - - for v in fvs: - if v[0] == "neigh": - assert v[1] == macs[i] - if v[0] == "family": - assert v[1] == "IPv4" - - for i in range(len(v6ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) - assert status == True - - for v in fvs: - if v[0] == "neigh": - assert v[1] == macs[i] - if v[0] == "family": - assert v[1] == "IPv6" - - # - # Testcase 2: - # Restart neighsyncd without change neighbor entries, nothing should be sent to appDB or sairedis, - # appDB should be kept the same. - # - - # get restore_count - restore_count = swss_get_RestoreCount(dvs, state_db) - - # stop neighsyncd and sairedis.rec - stop_neighsyncd(dvs) - del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") - marker = dvs.add_log_marker() - pubsub = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE_NEIGHBOR_ENTRY") - start_neighsyncd(dvs) - start_restore_neighbors(dvs) - time.sleep(10) - - # Check the neighbor entries are still in appDB correctly - for i in range(len(ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) - assert status == True - - for v in fvs: - if v[0] == "neigh": - assert v[1] == macs[i] - if v[0] == "family": - assert v[1] == "IPv4" - - for i in range(len(v6ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) - assert status == True - - for v in fvs: - if v[0] == "neigh": - assert v[1] == macs[i] - if v[0] == "family": - assert v[1] == "IPv6" - - # check syslog and sairedis.rec file for activities - check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv4") - check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv6") - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) - assert nadd == 0 - assert ndel == 0 - - # check restore Count - swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") - - # - # Testcase 3: - # stop neighsyncd, delete even nummber ipv4/ipv6 neighbor entries from each interface, warm start neighsyncd. - # the neighsyncd is supposed to sync up the entries from kernel after warm restart - # note: there was an issue for neighbor delete, it will be marked as FAILED instead of deleted in kernel - # but it will send netlink message to be removed from appDB, so it works ok here, - # just that if we want to add the same neighbor again, use "change" instead of "add" - - # get restore_count - restore_count = swss_get_RestoreCount(dvs, state_db) - - # stop neighsyncd - stop_neighsyncd(dvs) - del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") - marker = dvs.add_log_marker() - - # delete even nummber of ipv4/ipv6 neighbor entries from each interface - for i in range(0, len(ips), 2): - dvs.runcmd("ip neigh del {} dev {}".format(ips[i], intfs[i/2])) - - for i in range(0, len(v6ips), 2): - dvs.runcmd("ip -6 neigh del {} dev {}".format(v6ips[i], intfs[i/2])) - - # start neighsyncd again - start_neighsyncd(dvs) - start_restore_neighbors(dvs) - time.sleep(10) - - # check ipv4 and ipv6 neighbors - for i in range(len(ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) - #should not see deleted neighbor entries - if i % 2 == 0: - assert status == False - continue - else: - assert status == True - - #undeleted entries should still be there. - for v in fvs: - if v[0] == "neigh": - assert v[1] == macs[i] - if v[0] == "family": - assert v[1] == "IPv4" - - for i in range(len(v6ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) - #should not see deleted neighbor entries - if i % 2 == 0: - assert status == False - continue - else: - assert status == True - - #undeleted entries should still be there. - for v in fvs: - if v[0] == "neigh": - assert v[1] == macs[i] - if v[0] == "family": - assert v[1] == "IPv6" - - # check syslog and sairedis.rec file for activities - # 2 deletes each for ipv4 and ipv6 - # 4 neighbor removal in asic db - check_syslog_for_neighbor_entry(dvs, marker, 0, 2, "ipv4") - check_syslog_for_neighbor_entry(dvs, marker, 0, 2, "ipv6") - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) - assert nadd == 0 - assert ndel == 4 - - # check restore Count - swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") - - - # - # Testcase 4: - # Stop neighsyncd, add even nummber of ipv4/ipv6 neighbor entries to each interface again, - # Start neighsyncd - # The neighsyncd is supposed to sync up the entries from kernel after warm restart - # Check the timer is not retrieved from configDB since it is not configured - - # get restore_count - restore_count = swss_get_RestoreCount(dvs, state_db) - - # stop neighsyncd - stop_neighsyncd(dvs) - del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") - marker = dvs.add_log_marker() - - # add even nummber of ipv4/ipv6 neighbor entries to each interface - # use "change" if neighbor is in FAILED state - for i in range(0, len(ips), 2): - (rc, output) = dvs.runcmd(['sh', '-c', "ip -4 neigh | grep {}".format(ips[i])]) - print output - if output: - dvs.runcmd("ip neigh change {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], macs[i])) - else: - dvs.runcmd("ip neigh add {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], macs[i])) - - for i in range(0, len(v6ips), 2): - (rc, output) = dvs.runcmd(['sh', '-c', "ip -6 neigh | grep {}".format(v6ips[i])]) - print output - if output: - dvs.runcmd("ip -6 neigh change {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], macs[i])) - else: - dvs.runcmd("ip -6 neigh add {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], macs[i])) - - # start neighsyncd again - start_neighsyncd(dvs) - start_restore_neighbors(dvs) - time.sleep(10) - - # no neighsyncd timer configured - check_no_neighsyncd_timer(dvs) - - # check ipv4 and ipv6 neighbors, should see all neighbors - for i in range(len(ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) - assert status == True - for v in fvs: - if v[0] == "neigh": - assert v[1] == macs[i] - if v[0] == "family": - assert v[1] == "IPv4" - - for i in range(len(v6ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) - assert status == True - for v in fvs: - if v[0] == "neigh": - assert v[1] == macs[i] - if v[0] == "family": - assert v[1] == "IPv6" - - # check syslog and asic db for activities - # 2 news entries for ipv4 and ipv6 each - # 4 neighbor creation in asic db - check_syslog_for_neighbor_entry(dvs, marker, 2, 0, "ipv4") - check_syslog_for_neighbor_entry(dvs, marker, 2, 0, "ipv6") - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) - assert nadd == 4 - assert ndel == 0 - - # check restore Count - swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") - - # - # Testcase 5: - # Even number of ip4/6 neigbors updated with new mac. - # Odd number of ipv4/6 neighbors removed - # neighbor syncd should sync it up after warm restart - # include the timer settings in this testcase - - # setup timer in configDB - timer_value = "15" - - dvs.runcmd("config warm_restart neighsyncd_timer {}".format(timer_value)) - - # get restore_count - restore_count = swss_get_RestoreCount(dvs, state_db) - - # stop neighsyncd - stop_neighsyncd(dvs) - del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") - marker = dvs.add_log_marker() - - # Even number of ip4/6 neigbors updated with new mac. - # Odd number of ipv4/6 neighbors removed - newmacs = ["00:00:00:01:12:02", "00:00:00:01:12:03", "00:00:00:01:16:02", "00:00:00:01:16:03"] - - for i in range(len(ips)): - if i % 2 == 0: - dvs.runcmd("ip neigh change {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], newmacs[i])) - else: - dvs.runcmd("ip neigh del {} dev {}".format(ips[i], intfs[i/2])) - - for i in range(len(v6ips)): - if i % 2 == 0: - dvs.runcmd("ip -6 neigh change {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], newmacs[i])) - else: - dvs.runcmd("ip -6 neigh del {} dev {}".format(v6ips[i], intfs[i/2])) - - # start neighsyncd again - start_neighsyncd(dvs) - start_restore_neighbors(dvs) - time.sleep(10) - - # timer is not expired yet, state should be "restored" - swss_app_check_warmstart_state(state_db, "neighsyncd", "restored") - time.sleep(10) - - # check neigh syncd timer is retrived from configDB - check_neighsyncd_timer(dvs, timer_value) - - # check ipv4 and ipv6 neighbors, should see all neighbors with updated info - for i in range(len(ips)): - if i % 2 == 0: - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) - assert status == True - for v in fvs: - if v[0] == "neigh": - assert v[1] == newmacs[i] - if v[0] == "family": - assert v[1] == "IPv4" - else: - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) - assert status == False - - for i in range(len(v6ips)): - if i % 2 == 0: - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) - assert status == True - for v in fvs: - if v[0] == "neigh": - assert v[1] == newmacs[i] - if v[0] == "family": - assert v[1] == "IPv6" - else: - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) - assert status == False - - time.sleep(2) - - # check syslog and asic db for activities - # 2 news, 2 deletes for ipv4 and ipv6 each - # 4 set, 4 removes for neighbor in asic db - check_syslog_for_neighbor_entry(dvs, marker, 2, 2, "ipv4") - check_syslog_for_neighbor_entry(dvs, marker, 2, 2, "ipv6") - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) - assert nadd == 4 - assert ndel == 4 - - # check restore Count - swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") - - # post-cleanup - dvs.runcmd("ip -s neigh flush all") - dvs.runcmd("ip -6 -s neigh flush all") - - 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])) - intf_tbl._del("{}".format(intfs[0])) - intf_tbl._del("{}".format(intfs[1])) - intf_tbl._del("{}".format(intfs[0])) - intf_tbl._del("{}".format(intfs[1])) - time.sleep(2) - - -# TODO: The condition of warm restart readiness check is still under discussion. -def test_OrchagentWarmRestartReadyCheck(dvs, testlog): - - time.sleep(1) - - dvs.runcmd("config warm_restart enable swss") - - 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("Ethernet0", fvs) - intf_tbl.set("Ethernet4", 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") - - dvs.servers[1].runcmd("ifconfig eth0 10.0.0.3/31") - dvs.servers[1].runcmd("ip route add default via 10.0.0.2") - - - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - ps = swsscommon.ProducerStateTable(appl_db, swsscommon.APP_ROUTE_TABLE_NAME) - fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1"), ("ifname", "Ethernet0")]) - - ps.set("2.2.2.0/24", fvs) - - time.sleep(1) - # Should fail, since neighbor for next 10.0.0.1 has not been not resolved yet - (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check") - assert result == "RESTARTCHECK failed\n" - - # Should succeed, the option for skipPendingTaskCheck -s and noFreeze -n have been provided. - # Wait up to 500 milliseconds for response from orchagent. Default wait time is 1000 milliseconds. - (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check -n -s -w 500") - assert result == "RESTARTCHECK succeeded\n" - - # get neighbor and arp entry - dvs.servers[1].runcmd("ping -c 1 10.0.0.1") - - time.sleep(1) - (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check") - assert result == "RESTARTCHECK succeeded\n" - - # Should fail since orchagent has been frozen at last step. - (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check -n -s -w 500") - assert result == "RESTARTCHECK failed\n" - - # Cleaning previously pushed route-entry to ease life of subsequent testcases. - 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") - intf_tbl._del("Ethernet0") - intf_tbl._del("Ethernet4") - time.sleep(2) - - # recover for test cases after this one. - dvs.stop_swss() - dvs.start_swss() - time.sleep(5) - -def test_swss_port_state_syncup(dvs, testlog): - - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) - - dvs.runcmd("config warm_restart enable swss") - - tbl = swsscommon.Table(appl_db, swsscommon.APP_PORT_TABLE_NAME) - - restore_count = swss_get_RestoreCount(dvs, state_db) - - # update port admin state - 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) - intf_tbl.set("Ethernet0", fvs) - intf_tbl.set("Ethernet4", fvs) - intf_tbl.set("Ethernet8", 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") - dvs.runcmd("arp -s 10.0.0.5 00:00:00:00:00:03") - - dvs.servers[0].runcmd("ip link set down dev eth0") == 0 - dvs.servers[1].runcmd("ip link set down dev eth0") == 0 - dvs.servers[2].runcmd("ip link set down dev eth0") == 0 - - dvs.servers[2].runcmd("ip link set up dev eth0") == 0 - - time.sleep(3) - - for i in [0, 1, 2]: - (status, fvs) = tbl.get("Ethernet%d" % (i * 4)) - assert status == True - oper_status = "unknown" - for v in fvs: - if v[0] == "oper_status": - oper_status = v[1] - break - if i == 2: - assert oper_status == "up" - 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") - intf_tbl._del("Ethernet0") - intf_tbl._del("Ethernet4") - intf_tbl._del("Ethernet8") - time.sleep(2) - - dvs.stop_swss() - time.sleep(3) - - # flap the port oper status for Ethernet0, Ethernet4 and Ethernet8 - dvs.servers[0].runcmd("ip link set down dev eth0") == 0 - dvs.servers[1].runcmd("ip link set down dev eth0") == 0 - dvs.servers[2].runcmd("ip link set down dev eth0") == 0 - - dvs.servers[0].runcmd("ip link set up dev eth0") == 0 - dvs.servers[1].runcmd("ip link set up dev eth0") == 0 - - time.sleep(5) - dbobjs =[(swsscommon.APPL_DB, swsscommon.APP_PORT_TABLE_NAME + ":*"), \ - (swsscommon.STATE_DB, swsscommon.STATE_WARM_RESTART_TABLE_NAME + "|orchagent")] - pubsubDbs = dvs.SubscribeDbObjects(dbobjs) - dvs.start_swss() - start_restore_neighbors(dvs) - time.sleep(10) - - 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) - intf_tbl.set("Ethernet0", fvs) - intf_tbl.set("Ethernet4", fvs) - intf_tbl.set("Ethernet8", fvs) - time.sleep(3) - - for i in [0, 1, 2]: - (status, fvs) = tbl.get("Ethernet%d" % (i * 4)) - assert status == True - oper_status = "unknown" - for v in fvs: - if v[0] == "oper_status": - oper_status = v[1] - break - if i == 2: - assert oper_status == "down" - else: - assert oper_status == "up" - - # check the pubsub messages. - # No appDB port table operation should exist before orchagent state restored flag got set. - # appDB port table status sync up happens before WARM_RESTART_TABLE reconciled flag is set - # pubsubMessages is an ordered list of pubsub messages. - pubsubMessages = dvs.GetSubscribedMessages(pubsubDbs) - - portOperStatusChanged = False - # number of times that WARM_RESTART_TABLE|orchagent key was set after the first - # appDB port table operation - orchStateCount = 0 - for message in pubsubMessages: - print message - key = message['channel'].split(':', 1)[1] - print key - if message['data'] != 'hset' and message['data'] != 'del': - continue - if key.find(swsscommon.APP_PORT_TABLE_NAME)==0: - portOperStatusChanged = True - else: - # found one orchagent WARM_RESTART_TABLE operation after appDB port table change - if portOperStatusChanged == True: - orchStateCount += 1; - - # Only WARM_RESTART_TABLE|orchagent state=reconciled operation may exist after port oper status change. - assert orchStateCount == 1 - - #clean up arp - dvs.runcmd("arp -d 10.0.0.1") - 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") - intf_tbl._del("Ethernet0") - intf_tbl._del("Ethernet4") - intf_tbl._del("Ethernet8") - time.sleep(2) - - -############################################################################# -# # -# Routing Warm-Restart Testing # -# # -############################################################################# - - def set_restart_timer(dvs, db, app_name, value): create_entry_tbl( db, @@ -980,967 +194,1754 @@ def set_restart_timer(dvs, db, app_name, value): ] ) -################################################################################ -# -# Routing warm-restart testcases -# -################################################################################ - - -def test_routing_WarmRestart(dvs, testlog): - - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) - - # Restart-timer to utilize during the following testcases - restart_timer = 15 +# 'ip neigh flush all' won't remove failed entries if number of neighs less than gc_threshold1 +# Also it takes time to remove them completly. +# We use arp off/on to do it +def flush_neigh_entries(dvs): + dvs.runcmd("ip link set group default arp off") + dvs.runcmd("ip link set group default arp on") +# Add neighbor entries on servers connecting to SONiC ports +# ping them to get the neighbor entries +def setup_initial_neighbors(dvs): + for i in range(8, 8+NUM_INTF): + for j in range(NUM_NEIGH_PER_INTF): + dvs.servers[i].runcmd("ip addr add {}.0.0.{}/24 dev eth0".format(i*4, j+2)) + dvs.servers[i].runcmd("ip -6 addr add {}00::{}/64 dev eth0".format(i*4,j+2)) - ############################################################################# - # - # Baseline configuration - # - ############################################################################# + time.sleep(1) + for i in range(8, 8+NUM_INTF): + for j in range(NUM_NEIGH_PER_INTF): + dvs.runcmd(['sh', '-c', "ping -c 1 -W 0 -q {}.0.0.{} > /dev/null 2>&1".format(i*4,j+2)]) + dvs.runcmd(['sh', '-c', "ping6 -c 1 -W 0 -q {}00::{} > /dev/null 2>&1".format(i*4,j+2)]) - # Defining create neighbor entries (4 ipv4 and 4 ip6, two each on each interface) in linux kernel - intfs = ["Ethernet0", "Ethernet4", "Ethernet8"] - - # Enable ipv6 on docker - dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=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) - intf_tbl.set("{}".format(intfs[0]), fvs) - intf_tbl.set("{}".format(intfs[0]), fvs) - intf_tbl.set("{}".format(intfs[1]), fvs) - intf_tbl.set("{}".format(intfs[1]), fvs) - intf_tbl.set("{}".format(intfs[2]), fvs) - intf_tbl.set("{}".format(intfs[2]), fvs) - dvs.runcmd("ip link set {} up".format(intfs[0])) - dvs.runcmd("ip link set {} up".format(intfs[1])) - dvs.runcmd("ip link set {} up".format(intfs[2])) +# Del half of the ips and a new half of the ips +# note: the first ipv4 can not be deleted only +def del_and_add_neighbors(dvs): + for i in range(8, 8+NUM_INTF): + for j in range(NUM_NEIGH_PER_INTF/2): + dvs.servers[i].runcmd("ip addr del {}.0.0.{}/24 dev eth0".format(i*4, j+NUM_NEIGH_PER_INTF/2+2)) + dvs.servers[i].runcmd("ip -6 addr del {}00::{}/64 dev eth0".format(i*4,j+NUM_NEIGH_PER_INTF/2+2)) + dvs.servers[i].runcmd("ip addr add {}.0.0.{}/24 dev eth0".format(i*4, j+NUM_NEIGH_PER_INTF+2)) + dvs.servers[i].runcmd("ip -6 addr add {}00::{}/64 dev eth0".format(i*4,j+NUM_NEIGH_PER_INTF+2)) - time.sleep(1) +#ping new IPs +def ping_new_ips(dvs): + for i in range(8, 8+NUM_INTF): + for j in range(NUM_NEIGH_PER_INTF/2): + dvs.runcmd(['sh', '-c', "ping -c 1 -W 0 -q {}.0.0.{} > /dev/null 2>&1".format(i*4,j+NUM_NEIGH_PER_INTF+2)]) + dvs.runcmd(['sh', '-c', "ping6 -c 1 -W 0 -q {}00::{} > /dev/null 2>&1".format(i*4,j+NUM_NEIGH_PER_INTF+2)]) - # - # Setting peer's ip-addresses and associated neighbor-entries - # - ips = ["111.0.0.2", "122.0.0.2", "133.0.0.2"] - v6ips = ["1110::2", "1220::2", "1330::2"] - macs = ["00:00:00:00:11:02", "00:00:00:00:12:02", "00:00:00:00:13:02"] +class TestWarmReboot(object): + def test_PortSyncdWarmRestart(self, dvs, testlog): - for i in range(len(ips)): - dvs.runcmd("ip neigh add {} dev {} lladdr {}".format(ips[i], intfs[i%2], macs[i])) + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) - for i in range(len(v6ips)): - dvs.runcmd("ip -6 neigh add {} dev {} lladdr {}".format(v6ips[i], intfs[i%2], macs[i])) + dvs.runcmd("config warm_restart enable swss") - time.sleep(1) + dvs.runcmd("ifconfig Ethernet16 up") + dvs.runcmd("ifconfig Ethernet20 up") - # - # Defining baseline IPv4 non-ecmp route-entries - # - dvs.runcmd("ip route add 192.168.1.100/32 nexthop via 111.0.0.2") - dvs.runcmd("ip route add 192.168.1.200/32 nexthop via 122.0.0.2") - dvs.runcmd("ip route add 192.168.1.230/32 nexthop via 133.0.0.2") + time.sleep(1) - # - # Defining baseline IPv4 ecmp route-entries - # - dvs.runcmd("ip route add 192.168.1.1/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") - dvs.runcmd("ip route add 192.168.1.2/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") - dvs.runcmd("ip route add 192.168.1.3/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2") + 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) + intf_tbl.set("Ethernet16", fvs) + intf_tbl.set("Ethernet20", fvs) + dvs.runcmd("ifconfig Ethernet16 up") + dvs.runcmd("ifconfig Ethernet20 up") - # - # Defining baseline IPv6 non-ecmp route-entries - # - dvs.runcmd("ip -6 route add fc00:11:11::1/128 nexthop via 1110::2") - dvs.runcmd("ip -6 route add fc00:12:12::1/128 nexthop via 1220::2") - dvs.runcmd("ip -6 route add fc00:13:13::1/128 nexthop via 1330::2") + dvs.servers[4].runcmd("ip link set down dev eth0") == 0 + dvs.servers[4].runcmd("ip link set up dev eth0") == 0 + dvs.servers[4].runcmd("ifconfig eth0 11.0.0.2/29") + dvs.servers[4].runcmd("ip route add default via 11.0.0.1") - # - # Defining baseline IPv6 ecmp route-entries - # - dvs.runcmd("ip -6 route add fc00:1:1::1/128 nexthop via 1110::2 nexthop via 1220::2 nexthop via 1330::2") - dvs.runcmd("ip -6 route add fc00:2:2::1/128 nexthop via 1110::2 nexthop via 1220::2 nexthop via 1330::2") - dvs.runcmd("ip -6 route add fc00:3:3::1/128 nexthop via 1110::2 nexthop via 1220::2") + dvs.servers[5].runcmd("ip link set down dev eth0") == 0 + dvs.servers[5].runcmd("ip link set up dev eth0") == 0 + dvs.servers[5].runcmd("ifconfig eth0 11.0.0.10/29") + dvs.servers[5].runcmd("ip route add default via 11.0.0.9") - time.sleep(5) + time.sleep(1) - # Enabling some extra logging for troubleshooting purposes - dvs.runcmd("swssloglevel -l INFO -c fpmsyncd") + # Ethernet port oper status should be up + check_port_oper_status(appl_db, "Ethernet16", "up") + check_port_oper_status(appl_db, "Ethernet20", "up") - # Subscribe to pubsub channels for routing-state associated to swss and sairedis dbs - pubsubAppDB = dvs.SubscribeAppDbObject("ROUTE_TABLE") - pubsubAsicDB = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE_ROUTE_ENTRY") + # Ping should work between servers via vs vlan interfaces + ping_stats = dvs.servers[4].runcmd("ping -c 1 11.0.0.10") + time.sleep(1) + neighTbl = swsscommon.Table(appl_db, "NEIGH_TABLE") + (status, fvs) = neighTbl.get("Ethernet16:11.0.0.2") + assert status == True - ############################################################################# - # - # Testcase 1. Having routing-warm-reboot disabled, restart zebra and verify - # that the traditional/cold-boot logic is followed. - # - ############################################################################# + (status, fvs) = neighTbl.get("Ethernet20:11.0.0.10") + assert status == True - # Restart zebra - dvs.stop_zebra() - dvs.start_zebra() + restore_count = swss_get_RestoreCount(dvs, state_db) - time.sleep(5) + # restart portsyncd + dvs.runcmd(['sh', '-c', 'pkill -x portsyncd']) - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "") + pubsub = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE") + dvs.runcmd(['sh', '-c', 'supervisorctl start portsyncd']) - # Verify that multiple changes are seen in swss and sairedis logs as there's - # no warm-reboot logic in place. - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) != 0 + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) + assert nadd == 0 + assert ndel == 0 - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) != 0 + #new ip on server 5 + dvs.servers[5].runcmd("ifconfig eth0 11.0.0.11/29") + # Ping should work between servers via vs Ethernet interfaces + ping_stats = dvs.servers[4].runcmd("ping -c 1 11.0.0.11") - ############################################################################# - # - # Testcase 2. Restart zebra and make no control-plane changes. - # For this and all subsequent test-cases routing-warm-reboot - # feature will be kept enabled. - # - ############################################################################# + # new neighbor learn on VS + (status, fvs) = neighTbl.get("Ethernet20:11.0.0.11") + assert status == True + # Port state change reflected in appDB correctly + dvs.servers[6].runcmd("ip link set down dev eth0") == 0 + dvs.servers[6].runcmd("ip link set up dev eth0") == 0 + time.sleep(1) + + check_port_oper_status(appl_db, "Ethernet16", "up") + check_port_oper_status(appl_db, "Ethernet20", "up") + check_port_oper_status(appl_db, "Ethernet24", "up") + + + 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") + intf_tbl._del("Ethernet16") + intf_tbl._del("Ethernet20") + time.sleep(2) + + + def test_VlanMgrdWarmRestart(self, dvs, testlog): + + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) + + dvs.runcmd("ifconfig Ethernet16 0") + dvs.runcmd("ifconfig Ethernet20 0") + + dvs.runcmd("ifconfig Ethernet16 up") + dvs.runcmd("ifconfig Ethernet20 up") + + time.sleep(1) + + dvs.runcmd("config warm_restart enable swss") + + # create vlan + create_entry_tbl( + conf_db, + "VLAN", "Vlan16", + [ + ("vlanid", "16"), + ] + ) + # create vlan + create_entry_tbl( + conf_db, + "VLAN", "Vlan20", + [ + ("vlanid", "20"), + ] + ) + # create vlan member entry in config db. Don't use Ethernet0/4/8/12 as IP configured on them in previous testing. + create_entry_tbl( + conf_db, + "VLAN_MEMBER", "Vlan16|Ethernet16", + [ + ("tagging_mode", "untagged"), + ] + ) + + create_entry_tbl( + conf_db, + "VLAN_MEMBER", "Vlan20|Ethernet20", + [ + ("tagging_mode", "untagged"), + ] + ) + + time.sleep(1) + + 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) + intf_tbl.set("Vlan16", fvs) + intf_tbl.set("Vlan20", 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") + + dvs.servers[5].runcmd("ifconfig eth0 11.0.0.10/29") + dvs.servers[5].runcmd("ip route add default via 11.0.0.9") + + time.sleep(1) + + # Ping should work between servers via vs vlan interfaces + ping_stats = dvs.servers[4].runcmd("ping -c 1 11.0.0.10") + time.sleep(1) + + tbl = swsscommon.Table(appl_db, "NEIGH_TABLE") + (status, fvs) = tbl.get("Vlan16:11.0.0.2") + assert status == True - # Enabling bgp warmrestart and setting restart timer. - # The following two instructions will be substituted by the commented ones - # once the later ones are added to sonic-utilities repo. + (status, fvs) = tbl.get("Vlan20:11.0.0.10") + assert status == True - dvs.runcmd("config warm_restart enable bgp") - dvs.runcmd("config warm_restart bgp_timer {}".format(restart_timer)) + (exitcode, bv_before) = dvs.runcmd("bridge vlan") + print(bv_before) - time.sleep(1) + restore_count = swss_get_RestoreCount(dvs, state_db) - # Restart zebra - dvs.stop_zebra() - dvs.start_zebra() + dvs.runcmd(['sh', '-c', 'pkill -x vlanmgrd']) - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + pubsub = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE") - # Verify swss changes -- none are expected this time - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 0 and len(delobjs) == 0 + dvs.runcmd(['sh', '-c', 'supervisorctl start vlanmgrd']) + time.sleep(2) - # Verify swss changes -- none are expected this time - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 0 and len(delobjs) == 0 + (exitcode, bv_after) = dvs.runcmd("bridge vlan") + assert bv_after == bv_before + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub, ignore=["SAI_OBJECT_TYPE_FDB_ENTRY"]) + assert nadd == 0 + assert ndel == 0 - ############################################################################# - # - # Testcase 3. Restart zebra and add one new non-ecmp IPv4 prefix - # - ############################################################################# + #new ip on server 5 + dvs.servers[5].runcmd("ifconfig eth0 11.0.0.11/29") - # Stop zebra - dvs.stop_zebra() + # Ping should work between servers via vs vlan interfaces + ping_stats = dvs.servers[4].runcmd("ping -c 1 11.0.0.11") - # Add new prefix - dvs.runcmd("ip route add 192.168.100.0/24 nexthop via 111.0.0.2") - time.sleep(1) + # new neighbor learn on VS + (status, fvs) = tbl.get("Vlan20:11.0.0.11") + assert status == True - # Start zebra - dvs.start_zebra() + swss_app_check_RestoreCount_single(state_db, restore_count, "vlanmgrd") - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + intf_tbl._del("Vlan16|11.0.0.1/29") + intf_tbl._del("Vlan20|11.0.0.9/29") + intf_tbl._del("Vlan16") + intf_tbl._del("Vlan20") + time.sleep(2) - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - rt_val = json.loads(addobjs[0]['vals']) - assert rt_key == "192.168.100.0/24" - assert rt_val == {"ifname": "Ethernet0", "nexthop": "111.0.0.2"} + def test_swss_neighbor_syncup(self, dvs, testlog): - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - assert rt_key['dest'] == "192.168.100.0/24" + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) + dvs.runcmd("config warm_restart enable swss") - ############################################################################# - # - # Testcase 4. Restart zebra and withdraw one non-ecmp IPv4 prefix - # - ############################################################################# + # + # Testcase1: + # Add neighbor entries in linux kernel, appDB should get all of them + # + # create neighbor entries (4 ipv4 and 4 ip6, two each on each interface) in linux kernel + intfs = ["Ethernet24", "Ethernet28"] - # Stop zebra - dvs.stop_zebra() + for intf in intfs: + # set timeout to be the same as real HW + dvs.runcmd("sysctl -w net.ipv4.neigh.{}.base_reachable_time_ms=1800000".format(intf)) + dvs.runcmd("sysctl -w net.ipv6.neigh.{}.base_reachable_time_ms=1800000".format(intf)) - # Delete prefix - dvs.runcmd("ip route del 192.168.100.0/24 nexthop via 111.0.0.2") - time.sleep(1) + #enable ipv6 on docker + dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") - # Start zebra - dvs.start_zebra() + 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) + intf_tbl.set("{}".format(intfs[0]), fvs) + intf_tbl.set("{}".format(intfs[1]), fvs) + intf_tbl.set("{}".format(intfs[0]), fvs) + intf_tbl.set("{}".format(intfs[1]), fvs) + dvs.runcmd("ifconfig {} up".format(intfs[0])) + dvs.runcmd("ifconfig {} up".format(intfs[1])) - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + 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"] - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 0 and len(delobjs) == 1 - rt_key = json.loads(delobjs[0]['key']) - assert rt_key == "192.168.100.0/24" + macs = ["00:00:00:00:24:02", "00:00:00:00:24:03", "00:00:00:00:28:02", "00:00:00:00:28:03"] - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 0 and len(delobjs) == 1 - rt_key = json.loads(delobjs[0]['key']) - assert rt_key['dest'] == "192.168.100.0/24" + for i in range(len(ips)): + dvs.runcmd("ip neigh add {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], macs[i])) + for i in range(len(v6ips)): + dvs.runcmd("ip -6 neigh add {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], macs[i])) - ############################################################################# - # - # Testcase 5. Restart zebra and add a new IPv4 ecmp-prefix - # - ############################################################################# + time.sleep(1) + # Check the neighbor entries are inserted correctly + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + tbl = swsscommon.Table(db, "NEIGH_TABLE") - # Stop zebra - dvs.stop_zebra() + for i in range(len(ips)): + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + assert status == True - # Add prefix - dvs.runcmd("ip route add 192.168.200.0/24 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") - time.sleep(1) + for v in fvs: + if v[0] == "neigh": + assert v[1] == macs[i] + if v[0] == "family": + assert v[1] == "IPv4" - # Start zebra - dvs.start_zebra() + for i in range(len(v6ips)): + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + assert status == True - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + for v in fvs: + if v[0] == "neigh": + assert v[1] == macs[i] + if v[0] == "family": + assert v[1] == "IPv6" - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - rt_val = json.loads(addobjs[0]['vals']) - assert rt_key == "192.168.200.0/24" - assert rt_val == {"ifname": "Ethernet0,Ethernet4,Ethernet8", "nexthop": "111.0.0.2,122.0.0.2,133.0.0.2"} + # + # Testcase 2: + # Restart neighsyncd without change neighbor entries, nothing should be sent to appDB or sairedis, + # appDB should be kept the same. + # + + # get restore_count + restore_count = swss_get_RestoreCount(dvs, state_db) + + # stop neighsyncd and sairedis.rec + stop_neighsyncd(dvs) + del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") + marker = dvs.add_log_marker() + pubsub = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE_NEIGHBOR_ENTRY") + start_neighsyncd(dvs) + start_restore_neighbors(dvs) + time.sleep(10) - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - assert rt_key['dest'] == "192.168.200.0/24" + # Check the neighbor entries are still in appDB correctly + for i in range(len(ips)): + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + assert status == True + for v in fvs: + if v[0] == "neigh": + assert v[1] == macs[i] + if v[0] == "family": + assert v[1] == "IPv4" - ############################################################################# - # - # Testcase 6. Restart zebra and delete one existing IPv4 ecmp-prefix. - # - ############################################################################# + for i in range(len(v6ips)): + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + assert status == True + for v in fvs: + if v[0] == "neigh": + assert v[1] == macs[i] + if v[0] == "family": + assert v[1] == "IPv6" - # Stop zebra - dvs.stop_zebra() + # check syslog and sairedis.rec file for activities + check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv4") + check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv6") + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) + assert nadd == 0 + assert ndel == 0 + + # check restore Count + swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") + + # + # Testcase 3: + # stop neighsyncd, delete even nummber ipv4/ipv6 neighbor entries from each interface, warm start neighsyncd. + # the neighsyncd is supposed to sync up the entries from kernel after warm restart + # note: there was an issue for neighbor delete, it will be marked as FAILED instead of deleted in kernel + # but it will send netlink message to be removed from appDB, so it works ok here, + # just that if we want to add the same neighbor again, use "change" instead of "add" + + # get restore_count + restore_count = swss_get_RestoreCount(dvs, state_db) + + # stop neighsyncd + stop_neighsyncd(dvs) + del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") + marker = dvs.add_log_marker() + + # delete even nummber of ipv4/ipv6 neighbor entries from each interface + for i in range(0, len(ips), 2): + dvs.runcmd("ip neigh del {} dev {}".format(ips[i], intfs[i/2])) - # Delete prefix - dvs.runcmd("ip route del 192.168.200.0/24 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") - time.sleep(1) + for i in range(0, len(v6ips), 2): + dvs.runcmd("ip -6 neigh del {} dev {}".format(v6ips[i], intfs[i/2])) - # Start zebra - dvs.start_zebra() + # start neighsyncd again + start_neighsyncd(dvs) + start_restore_neighbors(dvs) + time.sleep(10) - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + # check ipv4 and ipv6 neighbors + for i in range(len(ips)): + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + #should not see deleted neighbor entries + if i % 2 == 0: + assert status == False + continue + else: + assert status == True + + #undeleted entries should still be there. + for v in fvs: + if v[0] == "neigh": + assert v[1] == macs[i] + if v[0] == "family": + assert v[1] == "IPv4" - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 0 and len(delobjs) == 1 - rt_key = json.loads(delobjs[0]['key']) - assert rt_key == "192.168.200.0/24" + for i in range(len(v6ips)): + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + #should not see deleted neighbor entries + if i % 2 == 0: + assert status == False + continue + else: + assert status == True + + #undeleted entries should still be there. + for v in fvs: + if v[0] == "neigh": + assert v[1] == macs[i] + if v[0] == "family": + assert v[1] == "IPv6" - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 0 and len(delobjs) == 1 - rt_key = json.loads(delobjs[0]['key']) - assert rt_key['dest'] == "192.168.200.0/24" + # check syslog and sairedis.rec file for activities + # 2 deletes each for ipv4 and ipv6 + # 4 neighbor removal in asic db + check_syslog_for_neighbor_entry(dvs, marker, 0, 2, "ipv4") + check_syslog_for_neighbor_entry(dvs, marker, 0, 2, "ipv6") + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) + assert nadd == 0 + assert ndel == 4 + + # check restore Count + swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") + + + # + # Testcase 4: + # Stop neighsyncd, add even nummber of ipv4/ipv6 neighbor entries to each interface again, + # Start neighsyncd + # The neighsyncd is supposed to sync up the entries from kernel after warm restart + # Check the timer is not retrieved from configDB since it is not configured + + # get restore_count + restore_count = swss_get_RestoreCount(dvs, state_db) + + # stop neighsyncd + stop_neighsyncd(dvs) + del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") + marker = dvs.add_log_marker() + + # add even nummber of ipv4/ipv6 neighbor entries to each interface + # use "change" if neighbor is in FAILED state + for i in range(0, len(ips), 2): + (rc, output) = dvs.runcmd(['sh', '-c', "ip -4 neigh | grep {}".format(ips[i])]) + print output + if output: + dvs.runcmd("ip neigh change {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], macs[i])) + else: + dvs.runcmd("ip neigh add {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], macs[i])) + + for i in range(0, len(v6ips), 2): + (rc, output) = dvs.runcmd(['sh', '-c', "ip -6 neigh | grep {}".format(v6ips[i])]) + print output + if output: + dvs.runcmd("ip -6 neigh change {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], macs[i])) + else: + dvs.runcmd("ip -6 neigh add {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], macs[i])) + + # start neighsyncd again + start_neighsyncd(dvs) + start_restore_neighbors(dvs) + time.sleep(10) + # no neighsyncd timer configured + check_no_neighsyncd_timer(dvs) - ############################################################################# - # - # Testcase 7. Restart zebra and add one new path to an IPv4 ecmp-prefix - # - ############################################################################# + # check ipv4 and ipv6 neighbors, should see all neighbors + for i in range(len(ips)): + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + assert status == True + for v in fvs: + if v[0] == "neigh": + assert v[1] == macs[i] + if v[0] == "family": + assert v[1] == "IPv4" + for i in range(len(v6ips)): + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + assert status == True + for v in fvs: + if v[0] == "neigh": + assert v[1] == macs[i] + if v[0] == "family": + assert v[1] == "IPv6" - # Stop zebra - dvs.stop_zebra() + # check syslog and asic db for activities + # 2 news entries for ipv4 and ipv6 each + # 4 neighbor creation in asic db + check_syslog_for_neighbor_entry(dvs, marker, 2, 0, "ipv4") + check_syslog_for_neighbor_entry(dvs, marker, 2, 0, "ipv6") + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) + assert nadd == 4 + assert ndel == 0 + + # check restore Count + swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") + + # + # Testcase 5: + # Even number of ip4/6 neigbors updated with new mac. + # Odd number of ipv4/6 neighbors removed + # neighbor syncd should sync it up after warm restart + # include the timer settings in this testcase + + # setup timer in configDB + timer_value = "15" + + dvs.runcmd("config warm_restart neighsyncd_timer {}".format(timer_value)) + + # get restore_count + restore_count = swss_get_RestoreCount(dvs, state_db) + + # stop neighsyncd + stop_neighsyncd(dvs) + del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") + marker = dvs.add_log_marker() + + # Even number of ip4/6 neigbors updated with new mac. + # Odd number of ipv4/6 neighbors removed + newmacs = ["00:00:00:01:12:02", "00:00:00:01:12:03", "00:00:00:01:16:02", "00:00:00:01:16:03"] + + for i in range(len(ips)): + if i % 2 == 0: + dvs.runcmd("ip neigh change {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], newmacs[i])) + else: + dvs.runcmd("ip neigh del {} dev {}".format(ips[i], intfs[i/2])) + + for i in range(len(v6ips)): + if i % 2 == 0: + dvs.runcmd("ip -6 neigh change {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], newmacs[i])) + else: + dvs.runcmd("ip -6 neigh del {} dev {}".format(v6ips[i], intfs[i/2])) + + # start neighsyncd again + start_neighsyncd(dvs) + start_restore_neighbors(dvs) + time.sleep(10) - # Add new path - dvs.runcmd("ip route del 192.168.1.3/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2") - dvs.runcmd("ip route add 192.168.1.3/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") - time.sleep(1) + # timer is not expired yet, state should be "restored" + swss_app_check_warmstart_state(state_db, "neighsyncd", "restored") + time.sleep(10) - # Start zebra - dvs.start_zebra() + # check neigh syncd timer is retrived from configDB + check_neighsyncd_timer(dvs, timer_value) + + # check ipv4 and ipv6 neighbors, should see all neighbors with updated info + for i in range(len(ips)): + if i % 2 == 0: + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + assert status == True + for v in fvs: + if v[0] == "neigh": + assert v[1] == newmacs[i] + if v[0] == "family": + assert v[1] == "IPv4" + else: + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + assert status == False + + for i in range(len(v6ips)): + if i % 2 == 0: + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + assert status == True + for v in fvs: + if v[0] == "neigh": + assert v[1] == newmacs[i] + if v[0] == "family": + assert v[1] == "IPv6" + else: + (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + assert status == False + + time.sleep(2) + + # check syslog and asic db for activities + # 2 news, 2 deletes for ipv4 and ipv6 each + # 4 set, 4 removes for neighbor in asic db + check_syslog_for_neighbor_entry(dvs, marker, 2, 2, "ipv4") + check_syslog_for_neighbor_entry(dvs, marker, 2, 2, "ipv6") + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) + assert nadd == 4 + assert ndel == 4 + + # check restore Count + swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") + + # post-cleanup + dvs.runcmd("ip -s neigh flush all") + dvs.runcmd("ip -6 -s neigh flush all") + + 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])) + intf_tbl._del("{}".format(intfs[0])) + intf_tbl._del("{}".format(intfs[1])) + intf_tbl._del("{}".format(intfs[0])) + intf_tbl._del("{}".format(intfs[1])) + time.sleep(2) + + + # TODO: The condition of warm restart readiness check is still under discussion. + def test_OrchagentWarmRestartReadyCheck(self, dvs, testlog): + + time.sleep(1) + + dvs.runcmd("config warm_restart enable swss") + + 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("Ethernet0", fvs) + intf_tbl.set("Ethernet4", 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") + + dvs.servers[1].runcmd("ifconfig eth0 10.0.0.3/31") + dvs.servers[1].runcmd("ip route add default via 10.0.0.2") + + + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + ps = swsscommon.ProducerStateTable(appl_db, swsscommon.APP_ROUTE_TABLE_NAME) + fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1"), ("ifname", "Ethernet0")]) + + ps.set("2.2.2.0/24", fvs) + + time.sleep(1) + # Should fail, since neighbor for next 10.0.0.1 has not been not resolved yet + (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check") + assert result == "RESTARTCHECK failed\n" + + # Should succeed, the option for skipPendingTaskCheck -s and noFreeze -n have been provided. + # Wait up to 500 milliseconds for response from orchagent. Default wait time is 1000 milliseconds. + (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check -n -s -w 500") + assert result == "RESTARTCHECK succeeded\n" + + # get neighbor and arp entry + dvs.servers[1].runcmd("ping -c 1 10.0.0.1") + + time.sleep(1) + (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check") + assert result == "RESTARTCHECK succeeded\n" + + # Should fail since orchagent has been frozen at last step. + (exitcode, result) = dvs.runcmd("/usr/bin/orchagent_restart_check -n -s -w 500") + assert result == "RESTARTCHECK failed\n" + + # Cleaning previously pushed route-entry to ease life of subsequent testcases. + 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") + intf_tbl._del("Ethernet0") + intf_tbl._del("Ethernet4") + time.sleep(2) + + # recover for test cases after this one. + dvs.stop_swss() + dvs.start_swss() + time.sleep(5) + + def test_swss_port_state_syncup(self, dvs, testlog): - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - rt_val = json.loads(addobjs[0]['vals']) - assert rt_key == "192.168.1.3" - assert rt_val == {"ifname": "Ethernet0,Ethernet4,Ethernet8", "nexthop": "111.0.0.2,122.0.0.2,133.0.0.2"} + dvs.runcmd("config warm_restart enable swss") + + tbl = swsscommon.Table(appl_db, swsscommon.APP_PORT_TABLE_NAME) - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - assert rt_key['dest'] == "192.168.1.3/32" + restore_count = swss_get_RestoreCount(dvs, state_db) + # update port admin state + 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) + intf_tbl.set("Ethernet0", fvs) + intf_tbl.set("Ethernet4", fvs) + intf_tbl.set("Ethernet8", fvs) + dvs.runcmd("ifconfig Ethernet0 up") + dvs.runcmd("ifconfig Ethernet4 up") + dvs.runcmd("ifconfig Ethernet8 up") - ############################################################################# - # - # Testcase 8. Restart zebra and delete one ecmp-path from an IPv4 ecmp-prefix. - # - ############################################################################# + 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") + dvs.runcmd("arp -s 10.0.0.5 00:00:00:00:00:03") + dvs.servers[0].runcmd("ip link set down dev eth0") == 0 + dvs.servers[1].runcmd("ip link set down dev eth0") == 0 + dvs.servers[2].runcmd("ip link set down dev eth0") == 0 - # Stop zebra - dvs.stop_zebra() + dvs.servers[2].runcmd("ip link set up dev eth0") == 0 - # Delete ecmp-path - dvs.runcmd("ip route del 192.168.1.3/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") - dvs.runcmd("ip route add 192.168.1.3/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2") - time.sleep(1) + time.sleep(3) - # Start zebra - dvs.start_zebra() + for i in [0, 1, 2]: + (status, fvs) = tbl.get("Ethernet%d" % (i * 4)) + assert status == True + oper_status = "unknown" + for v in fvs: + if v[0] == "oper_status": + oper_status = v[1] + break + if i == 2: + assert oper_status == "up" + 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") + intf_tbl._del("Ethernet0") + intf_tbl._del("Ethernet4") + intf_tbl._del("Ethernet8") + time.sleep(2) + + dvs.stop_swss() + time.sleep(3) + + # flap the port oper status for Ethernet0, Ethernet4 and Ethernet8 + dvs.servers[0].runcmd("ip link set down dev eth0") == 0 + dvs.servers[1].runcmd("ip link set down dev eth0") == 0 + dvs.servers[2].runcmd("ip link set down dev eth0") == 0 + + dvs.servers[0].runcmd("ip link set up dev eth0") == 0 + dvs.servers[1].runcmd("ip link set up dev eth0") == 0 + + time.sleep(5) + dbobjs =[(swsscommon.APPL_DB, swsscommon.APP_PORT_TABLE_NAME + ":*"), \ + (swsscommon.STATE_DB, swsscommon.STATE_WARM_RESTART_TABLE_NAME + "|orchagent")] + pubsubDbs = dvs.SubscribeDbObjects(dbobjs) + dvs.start_swss() + start_restore_neighbors(dvs) + time.sleep(10) - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + swss_check_RestoreCount(dvs, state_db, restore_count) - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - rt_val = json.loads(addobjs[0]['vals']) - assert rt_key == "192.168.1.3" - assert rt_val == {"ifname": "Ethernet0,Ethernet4", "nexthop": "111.0.0.2,122.0.0.2"} + 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) + intf_tbl.set("Ethernet0", fvs) + intf_tbl.set("Ethernet4", fvs) + intf_tbl.set("Ethernet8", fvs) + time.sleep(3) - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - assert rt_key['dest'] == "192.168.1.3/32" + for i in [0, 1, 2]: + (status, fvs) = tbl.get("Ethernet%d" % (i * 4)) + assert status == True + oper_status = "unknown" + for v in fvs: + if v[0] == "oper_status": + oper_status = v[1] + break + if i == 2: + assert oper_status == "down" + else: + assert oper_status == "up" + + # check the pubsub messages. + # No appDB port table operation should exist before orchagent state restored flag got set. + # appDB port table status sync up happens before WARM_RESTART_TABLE reconciled flag is set + # pubsubMessages is an ordered list of pubsub messages. + pubsubMessages = dvs.GetSubscribedMessages(pubsubDbs) + + portOperStatusChanged = False + # number of times that WARM_RESTART_TABLE|orchagent key was set after the first + # appDB port table operation + orchStateCount = 0 + for message in pubsubMessages: + print message + key = message['channel'].split(':', 1)[1] + print key + if message['data'] != 'hset' and message['data'] != 'del': + continue + if key.find(swsscommon.APP_PORT_TABLE_NAME)==0: + portOperStatusChanged = True + else: + # found one orchagent WARM_RESTART_TABLE operation after appDB port table change + if portOperStatusChanged == True: + orchStateCount += 1; + + # Only WARM_RESTART_TABLE|orchagent state=reconciled operation may exist after port oper status change. + assert orchStateCount == 1 + + #clean up arp + dvs.runcmd("arp -d 10.0.0.1") + 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") + intf_tbl._del("Ethernet0") + intf_tbl._del("Ethernet4") + intf_tbl._del("Ethernet8") + time.sleep(2) ############################################################################# - # - # Testcase 9. Restart zebra and add one new non-ecmp IPv6 prefix - # + # # + # Routing Warm-Restart Testing # + # # ############################################################################# - # Stop zebra - dvs.stop_zebra() + ################################################################################ + # + # Routing warm-restart testcases + # + ################################################################################ + + + def test_routing_WarmRestart(self, dvs, testlog): + + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) + + # Restart-timer to utilize during the following testcases + restart_timer = 15 + + + ############################################################################# + # + # Baseline configuration + # + ############################################################################# + + + # Defining create neighbor entries (4 ipv4 and 4 ip6, two each on each interface) in linux kernel + intfs = ["Ethernet0", "Ethernet4", "Ethernet8"] + + # Enable ipv6 on docker + dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") - # Add prefix - dvs.runcmd("ip -6 route add fc00:4:4::1/128 nexthop via 1110::2") - time.sleep(1) + # 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) + intf_tbl.set("{}".format(intfs[0]), fvs) + intf_tbl.set("{}".format(intfs[0]), fvs) + intf_tbl.set("{}".format(intfs[1]), fvs) + intf_tbl.set("{}".format(intfs[1]), fvs) + intf_tbl.set("{}".format(intfs[2]), fvs) + intf_tbl.set("{}".format(intfs[2]), fvs) + dvs.runcmd("ip link set {} up".format(intfs[0])) + dvs.runcmd("ip link set {} up".format(intfs[1])) + dvs.runcmd("ip link set {} up".format(intfs[2])) - # Start zebra - dvs.start_zebra() + time.sleep(1) - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + # + # Setting peer's ip-addresses and associated neighbor-entries + # + ips = ["111.0.0.2", "122.0.0.2", "133.0.0.2"] + v6ips = ["1110::2", "1220::2", "1330::2"] + macs = ["00:00:00:00:11:02", "00:00:00:00:12:02", "00:00:00:00:13:02"] - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - rt_val = json.loads(addobjs[0]['vals']) - assert rt_key == "fc00:4:4::1" - assert rt_val == {"ifname": "Ethernet0", "nexthop": "1110::2"} + for i in range(len(ips)): + dvs.runcmd("ip neigh add {} dev {} lladdr {}".format(ips[i], intfs[i%2], macs[i])) - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - assert rt_key['dest'] == "fc00:4:4::1/128" + for i in range(len(v6ips)): + dvs.runcmd("ip -6 neigh add {} dev {} lladdr {}".format(v6ips[i], intfs[i%2], macs[i])) + time.sleep(1) - ############################################################################# - # - # Testcase 10. Restart zebra and withdraw one non-ecmp IPv6 prefix - # - ############################################################################# + # + # Defining baseline IPv4 non-ecmp route-entries + # + dvs.runcmd("ip route add 192.168.1.100/32 nexthop via 111.0.0.2") + dvs.runcmd("ip route add 192.168.1.200/32 nexthop via 122.0.0.2") + dvs.runcmd("ip route add 192.168.1.230/32 nexthop via 133.0.0.2") - # Stop zebra - dvs.stop_zebra() + # + # Defining baseline IPv4 ecmp route-entries + # + dvs.runcmd("ip route add 192.168.1.1/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") + dvs.runcmd("ip route add 192.168.1.2/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") + dvs.runcmd("ip route add 192.168.1.3/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2") - # Delete prefix - dvs.runcmd("ip -6 route del fc00:4:4::1/128 nexthop via 1110::2") - time.sleep(1) + # + # Defining baseline IPv6 non-ecmp route-entries + # + dvs.runcmd("ip -6 route add fc00:11:11::1/128 nexthop via 1110::2") + dvs.runcmd("ip -6 route add fc00:12:12::1/128 nexthop via 1220::2") + dvs.runcmd("ip -6 route add fc00:13:13::1/128 nexthop via 1330::2") - # Start zebra - dvs.start_zebra() + # + # Defining baseline IPv6 ecmp route-entries + # + dvs.runcmd("ip -6 route add fc00:1:1::1/128 nexthop via 1110::2 nexthop via 1220::2 nexthop via 1330::2") + dvs.runcmd("ip -6 route add fc00:2:2::1/128 nexthop via 1110::2 nexthop via 1220::2 nexthop via 1330::2") + dvs.runcmd("ip -6 route add fc00:3:3::1/128 nexthop via 1110::2 nexthop via 1220::2") - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + time.sleep(5) + + # Enabling some extra logging for troubleshooting purposes + dvs.runcmd("swssloglevel -l INFO -c fpmsyncd") + + # Subscribe to pubsub channels for routing-state associated to swss and sairedis dbs + pubsubAppDB = dvs.SubscribeAppDbObject("ROUTE_TABLE") + pubsubAsicDB = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE_ROUTE_ENTRY") - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 0 and len(delobjs) == 1 - rt_key = json.loads(delobjs[0]['key']) - assert rt_key == "fc00:4:4::1" - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 0 and len(delobjs) == 1 - rt_key = json.loads(delobjs[0]['key']) - assert rt_key['dest'] == "fc00:4:4::1/128" + ############################################################################# + # + # Testcase 1. Having routing-warm-reboot disabled, restart zebra and verify + # that the traditional/cold-boot logic is followed. + # + ############################################################################# + + # Restart zebra + dvs.stop_zebra() + dvs.start_zebra() + + time.sleep(5) + + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "") + + # Verify that multiple changes are seen in swss and sairedis logs as there's + # no warm-reboot logic in place. + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) != 0 + + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) != 0 + + + ############################################################################# + # + # Testcase 2. Restart zebra and make no control-plane changes. + # For this and all subsequent test-cases routing-warm-reboot + # feature will be kept enabled. + # + ############################################################################# + + + # Enabling bgp warmrestart and setting restart timer. + # The following two instructions will be substituted by the commented ones + # once the later ones are added to sonic-utilities repo. + + dvs.runcmd("config warm_restart enable bgp") + dvs.runcmd("config warm_restart bgp_timer {}".format(restart_timer)) + + time.sleep(1) + # Restart zebra + dvs.stop_zebra() + dvs.start_zebra() - ############################################################################# - # - # Testcase 11. Restart fpmsyncd and make no control-plane changes. - # - ############################################################################# + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + # Verify swss changes -- none are expected this time + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 0 and len(delobjs) == 0 - # Stop fpmsyncd - dvs.stop_fpmsyncd() + # Verify swss changes -- none are expected this time + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 0 and len(delobjs) == 0 - # Start fpmsyncd - dvs.start_fpmsyncd() - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + ############################################################################# + # + # Testcase 3. Restart zebra and add one new non-ecmp IPv4 prefix + # + ############################################################################# + + # Stop zebra + dvs.stop_zebra() + + # Add new prefix + dvs.runcmd("ip route add 192.168.100.0/24 nexthop via 111.0.0.2") + time.sleep(1) - # Verify swss changes -- none are expected this time - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 0 and len(delobjs) == 0 + # Start zebra + dvs.start_zebra() - # Verify sairedis changes -- none are expected this time - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 0 and len(delobjs) == 0 + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + rt_val = json.loads(addobjs[0]['vals']) + assert rt_key == "192.168.100.0/24" + assert rt_val == {"ifname": "Ethernet0", "nexthop": "111.0.0.2"} - ############################################################################# - # - # Testcase 12. Restart fpmsyncd and add one new non-ecmp IPv4 prefix - # - ############################################################################# + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + assert rt_key['dest'] == "192.168.100.0/24" - # Stop fpmsyncd - dvs.stop_fpmsyncd() + ############################################################################# + # + # Testcase 4. Restart zebra and withdraw one non-ecmp IPv4 prefix + # + ############################################################################# - # Add new prefix - dvs.runcmd("ip route add 192.168.100.0/24 nexthop via 111.0.0.2") - time.sleep(1) - # Start fpmsyncd - dvs.start_fpmsyncd() + # Stop zebra + dvs.stop_zebra() - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + # Delete prefix + dvs.runcmd("ip route del 192.168.100.0/24 nexthop via 111.0.0.2") + time.sleep(1) - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - rt_val = json.loads(addobjs[0]['vals']) - assert rt_key == "192.168.100.0/24" - assert rt_val == {"ifname": "Ethernet0", "nexthop": "111.0.0.2"} + # Start zebra + dvs.start_zebra() - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - assert rt_key['dest'] == "192.168.100.0/24" + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 0 and len(delobjs) == 1 + rt_key = json.loads(delobjs[0]['key']) + assert rt_key == "192.168.100.0/24" - ############################################################################# - # - # Testcase 13. Restart fpmsyncd and withdraw one non-ecmp IPv4 prefix - # - ############################################################################# + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 0 and len(delobjs) == 1 + rt_key = json.loads(delobjs[0]['key']) + assert rt_key['dest'] == "192.168.100.0/24" - # Stop fpmsyncd - dvs.stop_fpmsyncd() + ############################################################################# + # + # Testcase 5. Restart zebra and add a new IPv4 ecmp-prefix + # + ############################################################################# - # Delete prefix - dvs.runcmd("ip route del 192.168.100.0/24 nexthop via 111.0.0.2") - time.sleep(1) - # Start fpmsyncd - dvs.start_fpmsyncd() + # Stop zebra + dvs.stop_zebra() + + # Add prefix + dvs.runcmd("ip route add 192.168.200.0/24 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") + time.sleep(1) + + # Start zebra + dvs.start_zebra() - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 0 and len(delobjs) == 1 - rt_key = json.loads(delobjs[0]['key']) - assert rt_key == "192.168.100.0/24" + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + rt_val = json.loads(addobjs[0]['vals']) + assert rt_key == "192.168.200.0/24" + assert rt_val == {"ifname": "Ethernet0,Ethernet4,Ethernet8", "nexthop": "111.0.0.2,122.0.0.2,133.0.0.2"} + + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + assert rt_key['dest'] == "192.168.200.0/24" + + + ############################################################################# + # + # Testcase 6. Restart zebra and delete one existing IPv4 ecmp-prefix. + # + ############################################################################# + + + # Stop zebra + dvs.stop_zebra() + + # Delete prefix + dvs.runcmd("ip route del 192.168.200.0/24 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") + time.sleep(1) + + # Start zebra + dvs.start_zebra() + + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 0 and len(delobjs) == 1 - rt_key = json.loads(delobjs[0]['key']) - assert rt_key['dest'] == "192.168.100.0/24" + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 0 and len(delobjs) == 1 + rt_key = json.loads(delobjs[0]['key']) + assert rt_key == "192.168.200.0/24" + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 0 and len(delobjs) == 1 + rt_key = json.loads(delobjs[0]['key']) + assert rt_key['dest'] == "192.168.200.0/24" - ############################################################################# - # - # Testcase 14. Restart zebra and add/remove a new non-ecmp IPv4 prefix. As - # the 'delete' instruction would arrive after the 'add' one, no - # changes should be pushed down to SwSS. - # - ############################################################################# + ############################################################################# + # + # Testcase 7. Restart zebra and add one new path to an IPv4 ecmp-prefix + # + ############################################################################# + + + # Stop zebra + dvs.stop_zebra() + + # Add new path + dvs.runcmd("ip route del 192.168.1.3/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2") + dvs.runcmd("ip route add 192.168.1.3/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") + time.sleep(1) + + # Start zebra + dvs.start_zebra() + + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + rt_val = json.loads(addobjs[0]['vals']) + assert rt_key == "192.168.1.3" + assert rt_val == {"ifname": "Ethernet0,Ethernet4,Ethernet8", "nexthop": "111.0.0.2,122.0.0.2,133.0.0.2"} + + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + assert rt_key['dest'] == "192.168.1.3/32" + + + ############################################################################# + # + # Testcase 8. Restart zebra and delete one ecmp-path from an IPv4 ecmp-prefix. + # + ############################################################################# + + + # Stop zebra + dvs.stop_zebra() + + # Delete ecmp-path + dvs.runcmd("ip route del 192.168.1.3/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2 nexthop via 133.0.0.2") + dvs.runcmd("ip route add 192.168.1.3/32 nexthop via 111.0.0.2 nexthop via 122.0.0.2") + time.sleep(1) + + # Start zebra + dvs.start_zebra() + + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") - # Restart zebra - dvs.stop_zebra() - dvs.start_zebra() + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + rt_val = json.loads(addobjs[0]['vals']) + assert rt_key == "192.168.1.3" + assert rt_val == {"ifname": "Ethernet0,Ethernet4", "nexthop": "111.0.0.2,122.0.0.2"} - # Add/delete new prefix - dvs.runcmd("ip route add 192.168.100.0/24 nexthop via 111.0.0.2") - time.sleep(1) - dvs.runcmd("ip route del 192.168.100.0/24 nexthop via 111.0.0.2") - time.sleep(1) + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + assert rt_key['dest'] == "192.168.1.3/32" - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") - # Verify swss changes -- none are expected this time - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 0 and len(delobjs) == 0 + ############################################################################# + # + # Testcase 9. Restart zebra and add one new non-ecmp IPv6 prefix + # + ############################################################################# + + + # Stop zebra + dvs.stop_zebra() - # Verify swss changes -- none are expected this time - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 0 and len(delobjs) == 0 + # Add prefix + dvs.runcmd("ip -6 route add fc00:4:4::1/128 nexthop via 1110::2") + time.sleep(1) + # Start zebra + dvs.start_zebra() - ############################################################################# - # - # Testcase 15. Restart zebra and generate an add/remove/add for new non-ecmp - # IPv4 prefix. Verify that only the second 'add' instruction is - # honored and the corresponding update passed down to SwSS. - # - ############################################################################# + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + rt_val = json.loads(addobjs[0]['vals']) + assert rt_key == "fc00:4:4::1" + assert rt_val == {"ifname": "Ethernet0", "nexthop": "1110::2"} - # Restart zebra - dvs.stop_zebra() - dvs.start_zebra() + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + assert rt_key['dest'] == "fc00:4:4::1/128" + + + ############################################################################# + # + # Testcase 10. Restart zebra and withdraw one non-ecmp IPv6 prefix + # + ############################################################################# + + # Stop zebra + dvs.stop_zebra() - marker1 = dvs.add_log_marker("/var/log/swss/swss.rec") - marker2 = dvs.add_log_marker("/var/log/swss/sairedis.rec") + # Delete prefix + dvs.runcmd("ip -6 route del fc00:4:4::1/128 nexthop via 1110::2") + time.sleep(1) - # Add/delete new prefix - dvs.runcmd("ip route add 192.168.100.0/24 nexthop via 111.0.0.2") - time.sleep(1) - dvs.runcmd("ip route del 192.168.100.0/24 nexthop via 111.0.0.2") - time.sleep(1) - dvs.runcmd("ip route add 192.168.100.0/24 nexthop via 122.0.0.2") - time.sleep(1) + # Start zebra + dvs.start_zebra() - # Verify FSM - swss_app_check_warmstart_state(state_db, "bgp", "restored") - time.sleep(restart_timer + 1) - swss_app_check_warmstart_state(state_db, "bgp", "reconciled") - - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - rt_val = json.loads(addobjs[0]['vals']) - assert rt_key == "192.168.100.0/24" - assert rt_val == {"ifname": "Ethernet4", "nexthop": "122.0.0.2"} - - # Verify the changed prefix is seen in sairedis - (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - 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])) - intf_tbl._del("{}".format(intfs[0])) - intf_tbl._del("{}".format(intfs[0])) - intf_tbl._del("{}".format(intfs[1])) - intf_tbl._del("{}".format(intfs[1])) - intf_tbl._del("{}".format(intfs[2])) - intf_tbl._del("{}".format(intfs[2])) - time.sleep(2) + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 0 and len(delobjs) == 1 + rt_key = json.loads(delobjs[0]['key']) + assert rt_key == "fc00:4:4::1" -# 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 -# TBD: Need tune gc_thresh1/2/3 at host side of vs docker to support this. -NUM_INTF = 8 -NUM_NEIGH_PER_INTF = 16 #128 -NUM_OF_NEIGHS = (NUM_INTF*NUM_NEIGH_PER_INTF) + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 0 and len(delobjs) == 1 + rt_key = json.loads(delobjs[0]['key']) + assert rt_key['dest'] == "fc00:4:4::1/128" -# 'ip neigh flush all' won't remove failed entries if number of neighs less than gc_threshold1 -# Also it takes time to remove them completly. -# We use arp off/on to do it -def flush_neigh_entries(dvs): - dvs.runcmd("ip link set group default arp off") - dvs.runcmd("ip link set group default arp on") -# Add neighbor entries on servers connecting to SONiC ports -# ping them to get the neighbor entries -def setup_initial_neighbors(dvs): - for i in range(8, 8+NUM_INTF): - for j in range(NUM_NEIGH_PER_INTF): - dvs.servers[i].runcmd("ip addr add {}.0.0.{}/24 dev eth0".format(i*4, j+2)) - dvs.servers[i].runcmd("ip -6 addr add {}00::{}/64 dev eth0".format(i*4,j+2)) + ############################################################################# + # + # Testcase 11. Restart fpmsyncd and make no control-plane changes. + # + ############################################################################# + + + # Stop fpmsyncd + dvs.stop_fpmsyncd() + + # Start fpmsyncd + dvs.start_fpmsyncd() - time.sleep(1) + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") - for i in range(8, 8+NUM_INTF): - for j in range(NUM_NEIGH_PER_INTF): - dvs.runcmd(['sh', '-c', "ping -c 1 -W 0 -q {}.0.0.{} > /dev/null 2>&1".format(i*4,j+2)]) - dvs.runcmd(['sh', '-c', "ping6 -c 1 -W 0 -q {}00::{} > /dev/null 2>&1".format(i*4,j+2)]) + # Verify swss changes -- none are expected this time + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 0 and len(delobjs) == 0 -# Del half of the ips and a new half of the ips -# note: the first ipv4 can not be deleted only -def del_and_add_neighbors(dvs): - for i in range(8, 8+NUM_INTF): - for j in range(NUM_NEIGH_PER_INTF/2): - dvs.servers[i].runcmd("ip addr del {}.0.0.{}/24 dev eth0".format(i*4, j+NUM_NEIGH_PER_INTF/2+2)) - dvs.servers[i].runcmd("ip -6 addr del {}00::{}/64 dev eth0".format(i*4,j+NUM_NEIGH_PER_INTF/2+2)) - dvs.servers[i].runcmd("ip addr add {}.0.0.{}/24 dev eth0".format(i*4, j+NUM_NEIGH_PER_INTF+2)) - dvs.servers[i].runcmd("ip -6 addr add {}00::{}/64 dev eth0".format(i*4,j+NUM_NEIGH_PER_INTF+2)) + # Verify sairedis changes -- none are expected this time + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 0 and len(delobjs) == 0 -#ping new IPs -def ping_new_ips(dvs): - for i in range(8, 8+NUM_INTF): - for j in range(NUM_NEIGH_PER_INTF/2): - dvs.runcmd(['sh', '-c', "ping -c 1 -W 0 -q {}.0.0.{} > /dev/null 2>&1".format(i*4,j+NUM_NEIGH_PER_INTF+2)]) - dvs.runcmd(['sh', '-c', "ping6 -c 1 -W 0 -q {}00::{} > /dev/null 2>&1".format(i*4,j+NUM_NEIGH_PER_INTF+2)]) -def test_system_warmreboot_neighbor_syncup(dvs, testlog): + ############################################################################# + # + # Testcase 12. Restart fpmsyncd and add one new non-ecmp IPv4 prefix + # + ############################################################################# - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) - state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) - #enable ipv6 on docker - dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") + # Stop fpmsyncd + dvs.stop_fpmsyncd() + + # Add new prefix + dvs.runcmd("ip route add 192.168.100.0/24 nexthop via 111.0.0.2") + time.sleep(1) - # flush all neighs first - flush_neigh_entries(dvs) - time.sleep(5) + # Start fpmsyncd + dvs.start_fpmsyncd() + + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") - dvs.runcmd("config warm_restart enable system") + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + rt_val = json.loads(addobjs[0]['vals']) + assert rt_key == "192.168.100.0/24" + assert rt_val == {"ifname": "Ethernet0", "nexthop": "111.0.0.2"} - # Test neighbors on NUM_INTF (e,g 8) interfaces - # Ethernet32/36/.../60, with ip: 32.0.0.1/24... 60.0.0.1/24 - # 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. - # set ip on server facing interfaces - # bring servers' interface up, save the macs - dvs.runcmd("sysctl -w net.ipv4.neigh.Ethernet{}.base_reachable_time_ms=1800000".format(i*4)) - dvs.runcmd("sysctl -w net.ipv6.neigh.Ethernet{}.base_reachable_time_ms=1800000".format(i*4)) - 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)) - 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) - intf_tbl.set("Ethernet{}".format(i*4, i*4), fvs) - intf_tbl.set("Ethernet{}".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}'") - result = dvs.servers[i].runcmd_output("cat /sys/class/net/eth0/address") - macs.append(result.strip()) + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + assert rt_key['dest'] == "192.168.100.0/24" - # - # Testcase 1: - # Setup initial neigbors - setup_initial_neighbors(dvs) - # Check the neighbor entries are inserted correctly - db = swsscommon.DBConnector(0, dvs.redis_sock, 0) - tbl = swsscommon.Table(db, "NEIGH_TABLE") + ############################################################################# + # + # Testcase 13. Restart fpmsyncd and withdraw one non-ecmp IPv4 prefix + # + ############################################################################# + + + # Stop fpmsyncd + dvs.stop_fpmsyncd() + + # Delete prefix + dvs.runcmd("ip route del 192.168.100.0/24 nexthop via 111.0.0.2") + time.sleep(1) + + # Start fpmsyncd + dvs.start_fpmsyncd() + + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 0 and len(delobjs) == 1 + rt_key = json.loads(delobjs[0]['key']) + assert rt_key == "192.168.100.0/24" + + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 0 and len(delobjs) == 1 + rt_key = json.loads(delobjs[0]['key']) + assert rt_key['dest'] == "192.168.100.0/24" + + + ############################################################################# + # + # Testcase 14. Restart zebra and add/remove a new non-ecmp IPv4 prefix. As + # the 'delete' instruction would arrive after the 'add' one, no + # changes should be pushed down to SwSS. + # + ############################################################################# + + + # Restart zebra + dvs.stop_zebra() + dvs.start_zebra() + + # Add/delete new prefix + dvs.runcmd("ip route add 192.168.100.0/24 nexthop via 111.0.0.2") + time.sleep(1) + dvs.runcmd("ip route del 192.168.100.0/24 nexthop via 111.0.0.2") + time.sleep(1) + + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + + # Verify swss changes -- none are expected this time + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 0 and len(delobjs) == 0 + + # Verify swss changes -- none are expected this time + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 0 and len(delobjs) == 0 + + + ############################################################################# + # + # Testcase 15. Restart zebra and generate an add/remove/add for new non-ecmp + # IPv4 prefix. Verify that only the second 'add' instruction is + # honored and the corresponding update passed down to SwSS. + # + ############################################################################# + + + # Restart zebra + dvs.stop_zebra() + dvs.start_zebra() + + marker1 = dvs.add_log_marker("/var/log/swss/swss.rec") + marker2 = dvs.add_log_marker("/var/log/swss/sairedis.rec") + + # Add/delete new prefix + dvs.runcmd("ip route add 192.168.100.0/24 nexthop via 111.0.0.2") + time.sleep(1) + dvs.runcmd("ip route del 192.168.100.0/24 nexthop via 111.0.0.2") + time.sleep(1) + dvs.runcmd("ip route add 192.168.100.0/24 nexthop via 122.0.0.2") + time.sleep(1) + + # Verify FSM + swss_app_check_warmstart_state(state_db, "bgp", "restored") + time.sleep(restart_timer + 1) + swss_app_check_warmstart_state(state_db, "bgp", "reconciled") + + # Verify the changed prefix is seen in swss + (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + rt_key = json.loads(addobjs[0]['key']) + rt_val = json.loads(addobjs[0]['vals']) + assert rt_key == "192.168.100.0/24" + assert rt_val == {"ifname": "Ethernet4", "nexthop": "122.0.0.2"} + + # Verify the changed prefix is seen in sairedis + (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) + assert len(addobjs) == 1 and len(delobjs) == 0 + 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])) + intf_tbl._del("{}".format(intfs[0])) + intf_tbl._del("{}".format(intfs[0])) + intf_tbl._del("{}".format(intfs[1])) + intf_tbl._del("{}".format(intfs[1])) + intf_tbl._del("{}".format(intfs[2])) + intf_tbl._del("{}".format(intfs[2])) + time.sleep(2) + + def test_system_warmreboot_neighbor_syncup(self, dvs, testlog): + + appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) + state_db = swsscommon.DBConnector(swsscommon.STATE_DB, dvs.redis_sock, 0) + + #enable ipv6 on docker + dvs.runcmd("sysctl net.ipv6.conf.all.disable_ipv6=0") + + # flush all neighs first + flush_neigh_entries(dvs) + time.sleep(5) + + dvs.runcmd("config warm_restart enable system") + + # Test neighbors on NUM_INTF (e,g 8) interfaces + # Ethernet32/36/.../60, with ip: 32.0.0.1/24... 60.0.0.1/24 + # 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. + # set ip on server facing interfaces + # bring servers' interface up, save the macs + dvs.runcmd("sysctl -w net.ipv4.neigh.Ethernet{}.base_reachable_time_ms=1800000".format(i*4)) + dvs.runcmd("sysctl -w net.ipv6.neigh.Ethernet{}.base_reachable_time_ms=1800000".format(i*4)) + 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)) + 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) + intf_tbl.set("Ethernet{}".format(i*4, i*4), fvs) + intf_tbl.set("Ethernet{}".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}'") + result = dvs.servers[i].runcmd_output("cat /sys/class/net/eth0/address") + macs.append(result.strip()) + + # + # Testcase 1: + # Setup initial neigbors + setup_initial_neighbors(dvs) + + # Check the neighbor entries are inserted correctly + db = swsscommon.DBConnector(0, dvs.redis_sock, 0) + tbl = swsscommon.Table(db, "NEIGH_TABLE") + + # number of neighbors should match what we configured + # ipv4/ipv6 entries and loopback + check_redis_neigh_entries(dvs, tbl, 2*NUM_OF_NEIGHS) + + # All neighbor entries should match + for i in range(8, 8+NUM_INTF): + for j in range(NUM_NEIGH_PER_INTF): + (status, fvs) = tbl.get("Ethernet{}:{}.0.0.{}".format(i*4, i*4, j+2)) + assert status == True + for v in fvs: + if v[0] == "family": + assert v[1] == "IPv4" + if v[0] == "neigh": + assert v[1] == macs[i-8] + + (status, fvs) = tbl.get("Ethernet{}:{}00::{}".format(i*4, i*4, j+2)) + assert status == True + for v in fvs: + if v[0] == "family": + assert v[1] == "IPv6" + if v[0] == "neigh": + assert v[1] == macs[i-8] + + # + # Testcase 2: + # Stop neighsyncd, appDB entries should be reserved + # flush kernel neigh table to simulate warm reboot + # start neighsyncd, start restore_neighbors service to restore the neighbor table in kernel + # check all neighbors learned in kernel + # no changes should be there in syslog and sairedis.rec + + # get restore_count + restore_count = swss_get_RestoreCount(dvs, state_db) + + # stop neighsyncd and sairedis.rec + stop_neighsyncd(dvs) + del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") + time.sleep(3) + flush_neigh_entries(dvs) + time.sleep(3) + + # check neighbors are gone + check_kernel_reachable_neigh_num(dvs, 0) + + # start neighsyncd and restore_neighbors + marker = dvs.add_log_marker() + pubsub = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE_NEIGHBOR_ENTRY") + start_neighsyncd(dvs) + start_restore_neighbors(dvs) + + # should finish the store within 10 seconds + time.sleep(10) - # number of neighbors should match what we configured - # ipv4/ipv6 entries and loopback - check_redis_neigh_entries(dvs, tbl, 2*NUM_OF_NEIGHS) + check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS) + check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS) - # All neighbor entries should match - for i in range(8, 8+NUM_INTF): - for j in range(NUM_NEIGH_PER_INTF): - (status, fvs) = tbl.get("Ethernet{}:{}.0.0.{}".format(i*4, i*4, j+2)) - assert status == True - for v in fvs: - if v[0] == "family": - assert v[1] == "IPv4" - if v[0] == "neigh": - assert v[1] == macs[i-8] + # check syslog and sairedis.rec file for activities + check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv4") + check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv6") + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) + assert nadd == 0 + assert ndel == 0 - (status, fvs) = tbl.get("Ethernet{}:{}00::{}".format(i*4, i*4, j+2)) - assert status == True - for v in fvs: - if v[0] == "family": - assert v[1] == "IPv6" - if v[0] == "neigh": - assert v[1] == macs[i-8] + # check restore Count + swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") - # - # Testcase 2: - # Stop neighsyncd, appDB entries should be reserved - # flush kernel neigh table to simulate warm reboot - # start neighsyncd, start restore_neighbors service to restore the neighbor table in kernel - # check all neighbors learned in kernel - # no changes should be there in syslog and sairedis.rec - - # get restore_count - restore_count = swss_get_RestoreCount(dvs, state_db) - - # stop neighsyncd and sairedis.rec - stop_neighsyncd(dvs) - del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") - time.sleep(3) - flush_neigh_entries(dvs) - time.sleep(3) - - # check neighbors are gone - check_kernel_reachable_neigh_num(dvs, 0) - - # start neighsyncd and restore_neighbors - marker = dvs.add_log_marker() - pubsub = dvs.SubscribeAsicDbObject("SAI_OBJECT_TYPE_NEIGHBOR_ENTRY") - start_neighsyncd(dvs) - start_restore_neighbors(dvs) - - # should finish the store within 10 seconds - time.sleep(10) - - check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS) - check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS) - - # check syslog and sairedis.rec file for activities - check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv4") - check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv6") - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) - assert nadd == 0 - assert ndel == 0 - - # check restore Count - swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") + # + # Testcase 3: + # Stop neighsyncd, appDB entries should be reserved + # flush kernel neigh table to simulate warm reboot + # Remove half of ips of servers' interfaces, add new half of ips + # start neighsyncd, start restore_neighbors service to restore the neighbor table in kernel + # check all new neighbors learned in kernel + # no changes should be there in syslog and sairedis.rec - # - # Testcase 3: - # Stop neighsyncd, appDB entries should be reserved - # flush kernel neigh table to simulate warm reboot - # Remove half of ips of servers' interfaces, add new half of ips - # start neighsyncd, start restore_neighbors service to restore the neighbor table in kernel - # check all new neighbors learned in kernel - # no changes should be there in syslog and sairedis.rec + # get restore_count + restore_count = swss_get_RestoreCount(dvs, state_db) - # get restore_count - restore_count = swss_get_RestoreCount(dvs, state_db) + # stop neighsyncd and sairedis.rec + stop_neighsyncd(dvs) + del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") + time.sleep(3) - # stop neighsyncd and sairedis.rec - stop_neighsyncd(dvs) - del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") - time.sleep(3) + del_and_add_neighbors(dvs) - del_and_add_neighbors(dvs) + flush_neigh_entries(dvs) + time.sleep(3) - flush_neigh_entries(dvs) - time.sleep(3) + # check neighbors are gone + check_kernel_reachable_neigh_num(dvs, 0) - # check neighbors are gone - check_kernel_reachable_neigh_num(dvs, 0) + # start neighsyncd and restore_neighbors + marker = dvs.add_log_marker() + start_neighsyncd(dvs) + start_restore_neighbors(dvs) - # start neighsyncd and restore_neighbors - marker = dvs.add_log_marker() - start_neighsyncd(dvs) - start_restore_neighbors(dvs) + # should finish the store within 10 seconds + time.sleep(10) - # should finish the store within 10 seconds - time.sleep(10) + check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) + check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) + check_kernel_stale_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) + check_kernel_stale_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_stale_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_stale_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) + # check syslog and sairedis.rec file for activities + check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv4") + check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv6") + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) + assert nadd == 0 + assert ndel == 0 - # check syslog and sairedis.rec file for activities - check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv4") - check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv6") - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) - assert nadd == 0 - assert ndel == 0 + # check restore Count + swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") - # check restore Count - swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") + # Test case 4: + # ping the new ips, should get it into appDB + marker = dvs.add_log_marker() - # Test case 4: - # ping the new ips, should get it into appDB - marker = dvs.add_log_marker() + ping_new_ips(dvs) - ping_new_ips(dvs) + check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS) + check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS) - check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS) - check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS) + check_kernel_stale_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) + check_kernel_stale_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_stale_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_stale_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) + check_redis_neigh_entries(dvs, tbl, 2*(NUM_OF_NEIGHS+NUM_OF_NEIGHS/2)) - check_redis_neigh_entries(dvs, tbl, 2*(NUM_OF_NEIGHS+NUM_OF_NEIGHS/2)) + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) + assert nadd == NUM_OF_NEIGHS #ipv4 and ipv6 + assert ndel == 0 - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) - assert nadd == NUM_OF_NEIGHS #ipv4 and ipv6 - assert ndel == 0 + # Remove stale entries manually + for i in range(8, 8+NUM_INTF): + for j in range(NUM_NEIGH_PER_INTF/2): + dvs.runcmd(['sh', '-c', "ip neigh del {}.0.0.{} dev Ethernet{}".format(i*4,j+NUM_NEIGH_PER_INTF/2+2, i*4)]) + dvs.runcmd(['sh', '-c', "ip -6 neigh del {}00::{} dev Ethernet{}".format(i*4,j+NUM_NEIGH_PER_INTF/2+2, i*4)]) - # Remove stale entries manually - for i in range(8, 8+NUM_INTF): - for j in range(NUM_NEIGH_PER_INTF/2): - dvs.runcmd(['sh', '-c', "ip neigh del {}.0.0.{} dev Ethernet{}".format(i*4,j+NUM_NEIGH_PER_INTF/2+2, i*4)]) - dvs.runcmd(['sh', '-c', "ip -6 neigh del {}00::{} dev Ethernet{}".format(i*4,j+NUM_NEIGH_PER_INTF/2+2, i*4)]) + time.sleep(5) - time.sleep(5) + check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS) + check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS) - check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS) - check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS) + check_kernel_stale_v4_neigh_num(dvs, 0) + check_kernel_stale_v6_neigh_num(dvs, 0) - check_kernel_stale_v4_neigh_num(dvs, 0) - check_kernel_stale_v6_neigh_num(dvs, 0) + check_redis_neigh_entries(dvs, tbl, 2*NUM_OF_NEIGHS) - check_redis_neigh_entries(dvs, tbl, 2*NUM_OF_NEIGHS) + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) + assert nadd == 0 + assert ndel == NUM_OF_NEIGHS #ipv4 and ipv6 - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) - assert nadd == 0 - assert ndel == NUM_OF_NEIGHS #ipv4 and ipv6 + # + # Testcase 5: + # Stop neighsyncd, appDB entries should be reserved + # flush kernel neigh table to simulate warm reboot + # keep half of the interface down + # start neighsyncd, start restore_neighbors service to restore the neighbor table in kernel + # check all new neighbors with interface up to be learned in kernel + # syslog/sai log should show half of the entries stale/deleted - # - # Testcase 5: - # Stop neighsyncd, appDB entries should be reserved - # flush kernel neigh table to simulate warm reboot - # keep half of the interface down - # start neighsyncd, start restore_neighbors service to restore the neighbor table in kernel - # check all new neighbors with interface up to be learned in kernel - # syslog/sai log should show half of the entries stale/deleted + # get restore_count + restore_count = swss_get_RestoreCount(dvs, state_db) - # get restore_count - restore_count = swss_get_RestoreCount(dvs, state_db) + # stop neighsyncd and sairedis.rec + stop_neighsyncd(dvs) + del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") + time.sleep(3) - # stop neighsyncd and sairedis.rec - stop_neighsyncd(dvs) - del_entry_tbl(state_db, "NEIGH_RESTORE_TABLE", "Flags") - time.sleep(3) + flush_neigh_entries(dvs) + time.sleep(3) - flush_neigh_entries(dvs) - time.sleep(3) + # check neighbors are gone + check_kernel_reachable_neigh_num(dvs, 0) - # check neighbors are gone - check_kernel_reachable_neigh_num(dvs, 0) + # bring down half of the links + for i in range(8, 8+NUM_INTF/2): + dvs.runcmd("ip link set down dev Ethernet{}".format(i*4)) - # bring down half of the links - for i in range(8, 8+NUM_INTF/2): - dvs.runcmd("ip link set down dev Ethernet{}".format(i*4)) + # start neighsyncd and restore_neighbors + marker = dvs.add_log_marker() + start_neighsyncd(dvs) + start_restore_neighbors(dvs) - # start neighsyncd and restore_neighbors - marker = dvs.add_log_marker() - start_neighsyncd(dvs) - start_restore_neighbors(dvs) + # restore for up interfaces should be done within 10 seconds + time.sleep(10) - # restore for up interfaces should be done within 10 seconds - time.sleep(10) + check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) + check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) + restoretbl = swsscommon.Table(state_db, swsscommon.STATE_NEIGH_RESTORE_TABLE_NAME) - restoretbl = swsscommon.Table(state_db, swsscommon.STATE_NEIGH_RESTORE_TABLE_NAME) + # waited 10 above already + i = 10 + while (not kernel_restore_neighs_done(restoretbl)): + print "Waiting for kernel neighbors restore process done: {} seconds".format(i) + time.sleep(10) + i += 10 - # waited 10 above already - i = 10 - while (not kernel_restore_neighs_done(restoretbl)): - print "Waiting for kernel neighbors restore process done: {} seconds".format(i) time.sleep(10) - i += 10 - - time.sleep(10) - # check syslog and sairedis.rec file for activities - check_syslog_for_neighbor_entry(dvs, marker, 0, NUM_OF_NEIGHS/2, "ipv4") - check_syslog_for_neighbor_entry(dvs, marker, 0, NUM_OF_NEIGHS/2, "ipv6") - (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) - assert nadd == 0 - assert ndel == NUM_OF_NEIGHS + # check syslog and sairedis.rec file for activities + check_syslog_for_neighbor_entry(dvs, marker, 0, NUM_OF_NEIGHS/2, "ipv4") + check_syslog_for_neighbor_entry(dvs, marker, 0, NUM_OF_NEIGHS/2, "ipv6") + (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) + assert nadd == 0 + assert ndel == NUM_OF_NEIGHS - # check restore Count - swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") + # check restore Count + swss_app_check_RestoreCount_single(state_db, restore_count, "neighsyncd") - # disable system warm restart - dvs.runcmd("config warm_restart disable system") + # 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)) - intf_tbl._del("Ethernet{}".format(i*4, i*4)) - intf_tbl._del("Ethernet{}".format(i*4, i*4)) + 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)) + intf_tbl._del("Ethernet{}".format(i*4, i*4)) + intf_tbl._del("Ethernet{}".format(i*4, i*4)) From d0fa310c943850961ab196d1737ba7fd0453eef0 Mon Sep 17 00:00:00 2001 From: Antony Rheneus Date: Thu, 1 Aug 2019 15:13:31 +0530 Subject: [PATCH 11/22] [Warning] Fixed warning reported in ARM32 compiler Signed-off-by: Antony Rheneus --- fpmsyncd/fpm/fpm.h | 2 +- fpmsyncd/fpmlink.cpp | 2 +- fpmsyncd/fpmsyncd.cpp | 2 +- orchagent/aclorch.cpp | 1 + orchagent/countercheckorch.cpp | 8 ++++---- orchagent/crmorch.cpp | 2 +- orchagent/pfcactionhandler.cpp | 6 +++--- orchagent/portsorch.cpp | 4 ++-- orchagent/qosorch.cpp | 2 +- orchagent/watermarkorch.cpp | 4 ++-- warmrestart/warmRestartAssist.h | 2 +- 11 files changed, 18 insertions(+), 17 deletions(-) diff --git a/fpmsyncd/fpm/fpm.h b/fpmsyncd/fpm/fpm.h index 96f05f4865..8af9b30ae9 100644 --- a/fpmsyncd/fpm/fpm.h +++ b/fpmsyncd/fpm/fpm.h @@ -221,7 +221,7 @@ fpm_msg_next (fpm_msg_hdr_t *hdr, size_t *len) *len -= msg_len; } - return (fpm_msg_hdr_t *) (((char*) hdr) + msg_len); + return reinterpret_cast(static_cast(((char*) hdr) + msg_len)); } /* diff --git a/fpmsyncd/fpmlink.cpp b/fpmsyncd/fpmlink.cpp index 2147f85d7d..bed95b1dd4 100644 --- a/fpmsyncd/fpmlink.cpp +++ b/fpmsyncd/fpmlink.cpp @@ -106,7 +106,7 @@ void FpmLink::readData() /* Check for complete messages */ while (true) { - hdr = (fpm_msg_hdr_t *)(m_messageBuffer + start); + hdr = reinterpret_cast(static_cast(m_messageBuffer + start)); left = m_pos - start; if (left < FPM_MSG_HDR_LEN) break; diff --git a/fpmsyncd/fpmsyncd.cpp b/fpmsyncd/fpmsyncd.cpp index 42eba65f0f..21645900fe 100644 --- a/fpmsyncd/fpmsyncd.cpp +++ b/fpmsyncd/fpmsyncd.cpp @@ -54,7 +54,7 @@ int main(int argc, char **argv) if (warmStartEnabled) { /* Obtain warm-restart timer defined for routing application */ - uint32_t warmRestartIval = sync.m_warmStartHelper.getRestartTimer(); + time_t warmRestartIval = sync.m_warmStartHelper.getRestartTimer(); if (!warmRestartIval) { warmStartTimer.setInterval(timespec{DEFAULT_ROUTING_RESTART_INTERVAL, 0}); diff --git a/orchagent/aclorch.cpp b/orchagent/aclorch.cpp index 947ad3270d..345a964c15 100644 --- a/orchagent/aclorch.cpp +++ b/orchagent/aclorch.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/orchagent/countercheckorch.cpp b/orchagent/countercheckorch.cpp index 671eef1d61..68edb69e20 100644 --- a/orchagent/countercheckorch.cpp +++ b/orchagent/countercheckorch.cpp @@ -79,13 +79,13 @@ void CounterCheckOrch::mcCounterCheck() bool isLossy = ((1 << prio) & pfcMask) == 0; if (newMcCounters[prio] == numeric_limits::max()) { - SWSS_LOG_WARN("Could not retreive MC counters on queue %" PRIu64 " port %s", + SWSS_LOG_WARN("Could not retreive MC counters on queue %zu port %s", prio, port.m_alias.c_str()); } else if (!isLossy && mcCounters[prio] < newMcCounters[prio]) { - SWSS_LOG_WARN("Got Multicast %" PRIu64 " frame(s) on lossless queue %" PRIu64 " port %s", + SWSS_LOG_WARN("Got Multicast %" PRIu64 " frame(s) on lossless queue %zu port %s", newMcCounters[prio] - mcCounters[prio], prio, port.m_alias.c_str()); @@ -125,13 +125,13 @@ void CounterCheckOrch::pfcFrameCounterCheck() bool isLossy = ((1 << prio) & pfcMask) == 0; if (newCounters[prio] == numeric_limits::max()) { - SWSS_LOG_WARN("Could not retreive PFC frame count on queue %" PRIu64 " port %s", + SWSS_LOG_WARN("Could not retreive PFC frame count on queue %zu port %s", prio, port.m_alias.c_str()); } else if (isLossy && counters[prio] < newCounters[prio]) { - SWSS_LOG_WARN("Got PFC %" PRIu64 " frame(s) on lossy queue %" PRIu64 " port %s", + SWSS_LOG_WARN("Got PFC %" PRIu64 " frame(s) on lossy queue %zu port %s", newCounters[prio] - counters[prio], prio, port.m_alias.c_str()); diff --git a/orchagent/crmorch.cpp b/orchagent/crmorch.cpp index e5fc39f796..9e26cd58aa 100644 --- a/orchagent/crmorch.cpp +++ b/orchagent/crmorch.cpp @@ -240,7 +240,7 @@ void CrmOrch::handleSetCommand(const string& key, const vector& if (field == CRM_POLLING_INTERVAL) { m_pollingInterval = chrono::seconds(to_uint(value)); - auto interv = timespec { .tv_sec = m_pollingInterval.count(), .tv_nsec = 0 }; + auto interv = timespec { .tv_sec = (time_t)m_pollingInterval.count(), .tv_nsec = 0 }; m_timer->setInterval(interv); m_timer->reset(); } diff --git a/orchagent/pfcactionhandler.cpp b/orchagent/pfcactionhandler.cpp index c726d18b58..4cd79b22aa 100644 --- a/orchagent/pfcactionhandler.cpp +++ b/orchagent/pfcactionhandler.cpp @@ -404,7 +404,7 @@ bool PfcWdLossyHandler::getHwCounters(PfcWdHwStats& counters) return false; } - sai_object_id_t pg = portInstance.m_priority_group_ids[getQueueId()]; + sai_object_id_t pg = portInstance.m_priority_group_ids[static_cast (getQueueId())]; vector pgStats; pgStats.resize(pgStatIds.size()); @@ -469,7 +469,7 @@ PfcWdZeroBufferHandler::PfcWdZeroBufferHandler(sai_object_id_t port, return; } - sai_object_id_t pg = portInstance.m_priority_group_ids[queueId]; + sai_object_id_t pg = portInstance.m_priority_group_ids[static_cast (queueId)]; attr.id = SAI_INGRESS_PRIORITY_GROUP_ATTR_BUFFER_PROFILE; @@ -521,7 +521,7 @@ PfcWdZeroBufferHandler::~PfcWdZeroBufferHandler(void) return; } - sai_object_id_t pg = portInstance.m_priority_group_ids[getQueueId()]; + sai_object_id_t pg = portInstance.m_priority_group_ids[static_cast (getQueueId())]; attr.id = SAI_INGRESS_PRIORITY_GROUP_ATTR_BUFFER_PROFILE; attr.value.oid = m_originalPgBufferProfile; diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 75e862300f..e101f43b3a 100644 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -1430,7 +1430,7 @@ bool PortsOrch::bake() vector tuples; string value; bool foundPortConfigDone = m_portTable->hget("PortConfigDone", "count", value); - unsigned long portCount; + uint64_t portCount; SWSS_LOG_NOTICE("foundPortConfigDone = %d", foundPortConfigDone); bool foundPortInitDone = m_portTable->get("PortInitDone", tuples); @@ -1452,7 +1452,7 @@ bool PortsOrch::bake() if (portCount != keys.size() - 2) { // Invalid port table - SWSS_LOG_ERROR("Invalid port table: portCount, expecting %" PRIu64 ", got %" PRIu64, + SWSS_LOG_ERROR("Invalid port table: portCount, expecting %" PRIu64 ", got %zu", portCount, keys.size() - 2); cleanPortTable(keys); diff --git a/orchagent/qosorch.cpp b/orchagent/qosorch.cpp index 0486ad3af6..12783468fb 100644 --- a/orchagent/qosorch.cpp +++ b/orchagent/qosorch.cpp @@ -1053,7 +1053,7 @@ bool QosOrch::applySchedulerToQueueSchedulerGroup(Port &port, size_t queue_ind, const sai_object_id_t group_id = getSchedulerGroup(port, queue_id); if(group_id == SAI_NULL_OBJECT_ID) { - SWSS_LOG_ERROR("Failed to find a scheduler group for port: %s queue: %" PRIu64, port.m_alias.c_str(), queue_ind); + SWSS_LOG_ERROR("Failed to find a scheduler group for port: %s queue: %zu", port.m_alias.c_str(), queue_ind); return false; } diff --git a/orchagent/watermarkorch.cpp b/orchagent/watermarkorch.cpp index 11737badf6..52251b6e3e 100644 --- a/orchagent/watermarkorch.cpp +++ b/orchagent/watermarkorch.cpp @@ -98,7 +98,7 @@ void WatermarkOrch::handleWmConfigUpdate(const std::string &key, const std::vect { if (i.first == "interval") { - auto intervT = timespec { .tv_sec = to_uint(i.second.c_str()) , .tv_nsec = 0 }; + auto intervT = timespec { .tv_sec = static_cast(to_uint(i.second.c_str())) , .tv_nsec = 0 }; m_telemetryTimer->setInterval(intervT); // reset the timer interval when current timer expires m_timerChanged = true; @@ -295,7 +295,7 @@ void WatermarkOrch::clearSingleWm(Table *table, string wm_name, vector vfvt = {{wm_name, "0"}}; diff --git a/warmrestart/warmRestartAssist.h b/warmrestart/warmRestartAssist.h index 2d5e387ee1..227815c264 100644 --- a/warmrestart/warmRestartAssist.h +++ b/warmrestart/warmRestartAssist.h @@ -108,7 +108,7 @@ class AppRestartAssist std::string m_appTableName; // application table name bool m_warmStartInProgress; // indicate if warm start is in progress - uint32_t m_reconcileTimer; // reconcile timer value + time_t m_reconcileTimer; // reconcile timer value SelectableTimer m_warmStartTimer; // reconcile timer // Set or get cache entry state From dfbe8d8798cbc3764ffc42a2baa61b1f5d2eb1fc Mon Sep 17 00:00:00 2001 From: Antony Rheneus Date: Thu, 1 Aug 2019 15:16:30 +0530 Subject: [PATCH 12/22] removed extra headers Signed-off-by: Antony Rheneus --- orchagent/aclorch.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/orchagent/aclorch.cpp b/orchagent/aclorch.cpp index 345a964c15..508c5ecb09 100644 --- a/orchagent/aclorch.cpp +++ b/orchagent/aclorch.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include "aclorch.h" From 9e126c481771f24ccdb0370474a711fcca4f62fd Mon Sep 17 00:00:00 2001 From: Antony Rheneus Date: Thu, 1 Aug 2019 15:47:38 +0530 Subject: [PATCH 13/22] merge conflicts Signed-off-by: Antony Rheneus --- tests/test_warm_reboot.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/tests/test_warm_reboot.py b/tests/test_warm_reboot.py index cb592a0704..165e2f267c 100644 --- a/tests/test_warm_reboot.py +++ b/tests/test_warm_reboot.py @@ -1193,9 +1193,6 @@ def test_routing_WarmRestart(self, dvs, testlog): (addobjs, delobjs) = dvs.GetSubscribedAsicDbObjects(pubsubAsicDB) assert len(addobjs) == 0 and len(delobjs) == 0 - # Verify swss changes -- none are expected this time - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 0 and len(delobjs) == 0 ############################################################################# # @@ -1232,13 +1229,6 @@ def test_routing_WarmRestart(self, dvs, testlog): rt_key = json.loads(addobjs[0]['key']) assert rt_key['dest'] == "192.168.100.0/24" - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 1 and len(delobjs) == 0 - rt_key = json.loads(addobjs[0]['key']) - rt_val = json.loads(addobjs[0]['vals']) - assert rt_key == "192.168.100.0/24" - assert rt_val == {"ifname": "Ethernet0", "nexthop": "111.0.0.2"} ############################################################################# # @@ -1274,11 +1264,6 @@ def test_routing_WarmRestart(self, dvs, testlog): rt_key = json.loads(delobjs[0]['key']) assert rt_key['dest'] == "192.168.100.0/24" - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 0 and len(delobjs) == 1 - rt_key = json.loads(delobjs[0]['key']) - assert rt_key == "192.168.100.0/24" ############################################################################# # @@ -1498,11 +1483,6 @@ def test_routing_WarmRestart(self, dvs, testlog): rt_key = json.loads(delobjs[0]['key']) assert rt_key['dest'] == "fc00:4:4::1/128" - # Verify the changed prefix is seen in swss - (addobjs, delobjs) = dvs.GetSubscribedAppDbObjects(pubsubAppDB) - assert len(addobjs) == 0 and len(delobjs) == 1 - rt_key = json.loads(delobjs[0]['key']) - assert rt_key == "fc00:4:4::1" ############################################################################# # From d7ea2b3fd9bbce92ab5e18c202262c2679ee6f0f Mon Sep 17 00:00:00 2001 From: Antony Rheneus Date: Thu, 1 Aug 2019 15:51:19 +0530 Subject: [PATCH 14/22] merge conflicts Signed-off-by: Antony Rheneus --- orchagent/portsorch.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 97084c3d28..95af65fd34 100644 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -1636,17 +1636,9 @@ void PortsOrch::doPortTask(Consumer &consumer) { if (m_lanesAliasSpeedMap.find(it->first) == m_lanesAliasSpeedMap.end()) { - char *platform = getenv("platform"); - if (platform && (strstr(platform, BFN_PLATFORM_SUBSTRING) || strstr(platform, MLNX_PLATFORM_SUBSTRING))) + if (!removePort(it->second)) { - if (!removePort(it->second)) - { - throw runtime_error("PortsOrch initialization failure."); - } - } - else - { - SWSS_LOG_NOTICE("Failed to remove Port %" PRIx64 " due to missing SAI remove_port API.", it->second); + throw runtime_error("PortsOrch initialization failure."); } it = m_portListLaneMap.erase(it); } From 00c8c939f69a8faf857ee2b29f3df7e58b3bd304 Mon Sep 17 00:00:00 2001 From: Antony Rheneus Date: Thu, 1 Aug 2019 15:58:31 +0530 Subject: [PATCH 15/22] merge conflicts Signed-off-by: Antony Rheneus --- orchagent/aclorch.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/orchagent/aclorch.cpp b/orchagent/aclorch.cpp index 4c8ef92e27..947ad3270d 100644 --- a/orchagent/aclorch.cpp +++ b/orchagent/aclorch.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include "aclorch.h" From 6512be86b372f17da318e51af45a9953644ba37b Mon Sep 17 00:00:00 2001 From: Antony Rheneus Date: Fri, 2 Aug 2019 20:54:00 +0530 Subject: [PATCH 16/22] [Warning] Replacing stoul with strtoumax to fix 32/64 bit arch issue Signed-off-by: Antony Rheneus --- orchagent/portsorch.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 95af65fd34..45c174158e 100644 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -1430,7 +1430,8 @@ bool PortsOrch::bake() vector tuples; string value; bool foundPortConfigDone = m_portTable->hget("PortConfigDone", "count", value); - uint64_t portCount; + uintmax_t portCount; + char* endPtr = NULL; SWSS_LOG_NOTICE("foundPortConfigDone = %d", foundPortConfigDone); bool foundPortInitDone = m_portTable->get("PortInitDone", tuples); @@ -1447,12 +1448,12 @@ bool PortsOrch::bake() return false; } - portCount = stoul(value); - SWSS_LOG_NOTICE("portCount = %" PRIu64 ", m_portCount = %u", portCount, m_portCount); + portCount = strtoumax(value.c_str(), &endPtr, 0); + SWSS_LOG_NOTICE("portCount = %" PRIuMAX ", m_portCount = %u", portCount, m_portCount); if (portCount != keys.size() - 2) { // Invalid port table - SWSS_LOG_ERROR("Invalid port table: portCount, expecting %" PRIu64 ", got %zu", + SWSS_LOG_ERROR("Invalid port table: portCount, expecting %" PRIuMAX ", got %zu", portCount, keys.size() - 2); cleanPortTable(keys); From b5a52e9944eb53509568c5b63093c72cd57cbbe3 Mon Sep 17 00:00:00 2001 From: Antony Rheneus Date: Tue, 6 Aug 2019 18:44:46 +0530 Subject: [PATCH 17/22] COnverted uint32 to time_t using mktime() Signed-off-by: Antony Rheneus --- orchagent/crmorch.cpp | 5 ++++- orchagent/watermarkorch.cpp | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/orchagent/crmorch.cpp b/orchagent/crmorch.cpp index 9e26cd58aa..3820ad48dc 100644 --- a/orchagent/crmorch.cpp +++ b/orchagent/crmorch.cpp @@ -239,8 +239,11 @@ void CrmOrch::handleSetCommand(const string& key, const vector& { if (field == CRM_POLLING_INTERVAL) { + struct tm tmInterval; + memset(&tmInterval, 0, sizeof(tm)); + tmInterval.tm_sec = static_cast (m_pollingInterval.count()); m_pollingInterval = chrono::seconds(to_uint(value)); - auto interv = timespec { .tv_sec = (time_t)m_pollingInterval.count(), .tv_nsec = 0 }; + auto interv = timespec { .tv_sec = mktime(&tmInterval), .tv_nsec = 0 }; m_timer->setInterval(interv); m_timer->reset(); } diff --git a/orchagent/watermarkorch.cpp b/orchagent/watermarkorch.cpp index 52251b6e3e..1c078fd39a 100644 --- a/orchagent/watermarkorch.cpp +++ b/orchagent/watermarkorch.cpp @@ -98,7 +98,10 @@ void WatermarkOrch::handleWmConfigUpdate(const std::string &key, const std::vect { if (i.first == "interval") { - auto intervT = timespec { .tv_sec = static_cast(to_uint(i.second.c_str())) , .tv_nsec = 0 }; + struct tm tmInterval; + memset(&tmInterval, 0, sizeof(tm)); + tmInterval.tm_sec = to_uint(i.second.c_str()); + auto intervT = timespec { .tv_sec = mktime(&tmInterval), .tv_nsec = 0 }; m_telemetryTimer->setInterval(intervT); // reset the timer interval when current timer expires m_timerChanged = true; @@ -295,7 +298,7 @@ void WatermarkOrch::clearSingleWm(Table *table, string wm_name, vector vfvt = {{wm_name, "0"}}; From c85c1b9034c2b78bcf11a873fbba273f14e6dc28 Mon Sep 17 00:00:00 2001 From: Antony Rheneus Date: Wed, 7 Aug 2019 12:00:55 +0530 Subject: [PATCH 18/22] Fix uint32 to time_t using mktime Signed-off-by: Antony Rheneus --- orchagent/crmorch.cpp | 2 +- orchagent/watermarkorch.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/orchagent/crmorch.cpp b/orchagent/crmorch.cpp index 3820ad48dc..c7d9e57605 100644 --- a/orchagent/crmorch.cpp +++ b/orchagent/crmorch.cpp @@ -240,7 +240,7 @@ void CrmOrch::handleSetCommand(const string& key, const vector& if (field == CRM_POLLING_INTERVAL) { struct tm tmInterval; - memset(&tmInterval, 0, sizeof(tm)); + memset(&tmInterval, 0, sizeof(tmInterval)); tmInterval.tm_sec = static_cast (m_pollingInterval.count()); m_pollingInterval = chrono::seconds(to_uint(value)); auto interv = timespec { .tv_sec = mktime(&tmInterval), .tv_nsec = 0 }; diff --git a/orchagent/watermarkorch.cpp b/orchagent/watermarkorch.cpp index 1c078fd39a..1cd6cd7000 100644 --- a/orchagent/watermarkorch.cpp +++ b/orchagent/watermarkorch.cpp @@ -99,7 +99,7 @@ void WatermarkOrch::handleWmConfigUpdate(const std::string &key, const std::vect if (i.first == "interval") { struct tm tmInterval; - memset(&tmInterval, 0, sizeof(tm)); + memset(&tmInterval, 0, sizeof(tmInterval)); tmInterval.tm_sec = to_uint(i.second.c_str()); auto intervT = timespec { .tv_sec = mktime(&tmInterval), .tv_nsec = 0 }; m_telemetryTimer->setInterval(intervT); From 3f944116847eadacdbba53592b6478870f7ac115 Mon Sep 17 00:00:00 2001 From: Antony Rheneus Date: Wed, 7 Aug 2019 13:50:23 +0530 Subject: [PATCH 19/22] Reverted mktime() changes, and used typecast to convert int to time_t mktime() returns timestamp since epoch and cannot be usedfor typecasting Signed-off-by: Antony Rheneus --- orchagent/crmorch.cpp | 5 +---- orchagent/watermarkorch.cpp | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/orchagent/crmorch.cpp b/orchagent/crmorch.cpp index c7d9e57605..9e26cd58aa 100644 --- a/orchagent/crmorch.cpp +++ b/orchagent/crmorch.cpp @@ -239,11 +239,8 @@ void CrmOrch::handleSetCommand(const string& key, const vector& { if (field == CRM_POLLING_INTERVAL) { - struct tm tmInterval; - memset(&tmInterval, 0, sizeof(tmInterval)); - tmInterval.tm_sec = static_cast (m_pollingInterval.count()); m_pollingInterval = chrono::seconds(to_uint(value)); - auto interv = timespec { .tv_sec = mktime(&tmInterval), .tv_nsec = 0 }; + auto interv = timespec { .tv_sec = (time_t)m_pollingInterval.count(), .tv_nsec = 0 }; m_timer->setInterval(interv); m_timer->reset(); } diff --git a/orchagent/watermarkorch.cpp b/orchagent/watermarkorch.cpp index 1cd6cd7000..0b8c20e911 100644 --- a/orchagent/watermarkorch.cpp +++ b/orchagent/watermarkorch.cpp @@ -98,10 +98,7 @@ void WatermarkOrch::handleWmConfigUpdate(const std::string &key, const std::vect { if (i.first == "interval") { - struct tm tmInterval; - memset(&tmInterval, 0, sizeof(tmInterval)); - tmInterval.tm_sec = to_uint(i.second.c_str()); - auto intervT = timespec { .tv_sec = mktime(&tmInterval), .tv_nsec = 0 }; + auto intervT = timespec { .tv_sec = static_cast(to_uint(i.second.c_str())), .tv_nsec = 0 }; m_telemetryTimer->setInterval(intervT); // reset the timer interval when current timer expires m_timerChanged = true; From df498f3b4a6fcdf55879871b03aafd4fb6c41506 Mon Sep 17 00:00:00 2001 From: Antony Rheneus Date: Tue, 13 Aug 2019 19:17:45 +0530 Subject: [PATCH 20/22] Removed extra blank spaces and used size_t() instead of typecast Signed-off-by: Antony Rheneus --- fpmsyncd/fpmsyncd.cpp | 2 +- orchagent/pfcactionhandler.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fpmsyncd/fpmsyncd.cpp b/fpmsyncd/fpmsyncd.cpp index 2c8ea64728..ada7caa05e 100644 --- a/fpmsyncd/fpmsyncd.cpp +++ b/fpmsyncd/fpmsyncd.cpp @@ -84,7 +84,7 @@ int main(int argc, char **argv) if (warmStartEnabled) { /* Obtain warm-restart timer defined for routing application */ - time_t warmRestartIval = sync.m_warmStartHelper.getRestartTimer(); + time_t warmRestartIval = sync.m_warmStartHelper.getRestartTimer(); if (!warmRestartIval) { warmStartTimer.setInterval(timespec{DEFAULT_ROUTING_RESTART_INTERVAL, 0}); diff --git a/orchagent/pfcactionhandler.cpp b/orchagent/pfcactionhandler.cpp index 4cd79b22aa..df0977cb66 100644 --- a/orchagent/pfcactionhandler.cpp +++ b/orchagent/pfcactionhandler.cpp @@ -521,7 +521,7 @@ PfcWdZeroBufferHandler::~PfcWdZeroBufferHandler(void) return; } - sai_object_id_t pg = portInstance.m_priority_group_ids[static_cast (getQueueId())]; + sai_object_id_t pg = portInstance.m_priority_group_ids[size_t(getQueueId())]; attr.id = SAI_INGRESS_PRIORITY_GROUP_ATTR_BUFFER_PROFILE; attr.value.oid = m_originalPgBufferProfile; From f6df981ec36d99f8c5a95d735c71fb44406b8099 Mon Sep 17 00:00:00 2001 From: Antony Rheneus Date: Tue, 13 Aug 2019 21:09:33 +0530 Subject: [PATCH 21/22] Warning fix for time_t Signed-off-by: Antony Rheneus --- fpmsyncd/fpmsyncd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fpmsyncd/fpmsyncd.cpp b/fpmsyncd/fpmsyncd.cpp index ada7caa05e..d9e6528536 100644 --- a/fpmsyncd/fpmsyncd.cpp +++ b/fpmsyncd/fpmsyncd.cpp @@ -157,7 +157,7 @@ int main(int argc, char **argv) } else { - eoiuHoldTimer.setInterval(timespec{eoiuHoldIval, 0}); + eoiuHoldTimer.setInterval(timespec{(time_t)eoiuHoldIval, 0}); } eoiuHoldTimer.start(); s.addSelectable(&eoiuHoldTimer); From 4bb9142edacf013bdbd613dc5f5e8b2aa1265584 Mon Sep 17 00:00:00 2001 From: Antony Rheneus Date: Wed, 14 Aug 2019 12:18:55 +0530 Subject: [PATCH 22/22] Waring fixes for time_t - fix for tests failure Signed-off-by: Antony Rheneus --- fpmsyncd/fpmsyncd.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fpmsyncd/fpmsyncd.cpp b/fpmsyncd/fpmsyncd.cpp index d9e6528536..8040a7ecb4 100644 --- a/fpmsyncd/fpmsyncd.cpp +++ b/fpmsyncd/fpmsyncd.cpp @@ -1,4 +1,5 @@ #include +#include #include "logger.h" #include "select.h" #include "selectabletimer.h" @@ -149,7 +150,7 @@ int main(int argc, char **argv) if (eoiuFlagsSet(bgpStateTable)) { /* Obtain eoiu hold timer defined for bgp docker */ - uint32_t eoiuHoldIval = WarmStart::getWarmStartTimer("eoiu_hold", "bgp"); + uintmax_t eoiuHoldIval = WarmStart::getWarmStartTimer("eoiu_hold", "bgp"); if (!eoiuHoldIval) { eoiuHoldTimer.setInterval(timespec{DEFAULT_EOIU_HOLD_INTERVAL, 0}); @@ -161,7 +162,7 @@ int main(int argc, char **argv) } eoiuHoldTimer.start(); s.addSelectable(&eoiuHoldTimer); - SWSS_LOG_NOTICE("Warm-Restart started EOIU hold timer which is to expire in %d seconds.", eoiuHoldIval); + SWSS_LOG_NOTICE("Warm-Restart started EOIU hold timer which is to expire in %" PRIuMAX " seconds.", eoiuHoldIval); s.removeSelectable(&eoiuCheckTimer); continue; }