Skip to content

Commit

Permalink
Add test case for FDB sync up and CRM check.
Browse files Browse the repository at this point in the history
Signed-off-by: Jipan Yang <jipan.yang@alibaba-inc.com>
  • Loading branch information
jipanyang committed Jun 12, 2018
1 parent ebbe19d commit 34a7de7
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 49 deletions.
8 changes: 7 additions & 1 deletion orchagent/crmorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ CrmOrch::CrmOrch(DBConnector *db, string tableName):
m_resourcesMap.emplace(res.first, CrmResourceEntry(res.second, CRM_THRESHOLD_TYPE_DEFAULT, CRM_THRESHOLD_LOW_DEFAULT, CRM_THRESHOLD_HIGH_DEFAULT));
}

if (isWarmStart())
{
// The CRM stats needs to be populated again
m_countersCrmTable->del(CRM_COUNTERS_TABLE_KEY);
}

auto executor = new ExecutableTimer(m_timer.get(), this);
Orch::addExecutor("CRM_COUNTERS_POLL", executor);
m_timer->start();
Expand Down Expand Up @@ -332,7 +338,7 @@ void CrmOrch::decCrmAclUsedCounter(CrmResourceType resource, sai_acl_stage_t sta
{
m_resourcesMap.at(resource).countersMap[getCrmAclKey(stage, point)].usedCounter--;

// Remove ACL table related counters
// Remove ACL table related counters
if (resource == CrmResourceType::CRM_ACL_TABLE)
{
auto & cntMap = m_resourcesMap.at(CrmResourceType::CRM_ACL_TABLE).countersMap;
Expand Down
2 changes: 2 additions & 0 deletions orchagent/fdborch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ void FdbOrch::syncUpFdb()
sai_fdb_entry_t entry;
sai_deserialize_fdb_entry(key, entry);
this->update(SAI_FDB_EVENT_LEARNED, &entry, bridge_port_id);
SWSS_LOG_INFO("FDB from ASICDB %s", key.c_str());
}
}

}

void FdbOrch::update(sai_fdb_event_t type, const sai_fdb_entry_t* entry, sai_object_id_t bridge_port_id)
Expand Down
2 changes: 1 addition & 1 deletion orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ bool PortsOrch::setPortPvid(Port &port, sai_uint32_t pvid)

if (port.m_rif_id)
{
SWSS_LOG_ERROR("pvid setting for router interface is not allowed");
SWSS_LOG_ERROR("pvid setting for router interface %s is not allowed", port.m_alias.c_str());
return false;
}

Expand Down
181 changes: 134 additions & 47 deletions tests/test_warm_reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,15 @@ def test_swss_warm_restore(dvs):
keys = warmtbl.getKeys()
print(keys)

(status, fvs) = warmtbl.get("vlanmgrd")
assert status == True
for fv in fvs:
if fv[0] == "restart_count":
assert fv[1] == "1"
else:
assert False

(status, fvs) = warmtbl.get("portsyncd")
assert status == True
for fv in fvs:
if fv[0] == "restart_count":
assert fv[1] == "1"
else:
assert False

(status, fvs) = warmtbl.get("orchagent")
assert status == True
for fv in fvs:
if fv[0] == "restart_count":
assert fv[1] == "1"
else:
assert False
# restart_count for each process in SWSS should be 1
for key in ['vlanmgrd', 'portsyncd', 'orchagent']:
(status, fvs) = warmtbl.get(key)
assert status == True
for fv in fvs:
if fv[0] == "restart_count":
assert fv[1] == "1"
else:
assert False

def test_swss_port_state_syncup(dvs):
# syncd warm start with temp view not supported yet
Expand All @@ -64,6 +50,7 @@ def test_swss_port_state_syncup(dvs):
time.sleep(3)
dvs.runcmd("mv /var/log/swss/sairedis.rec /var/log/swss/sairedis.rec.b")

# Change port state before swss up again
dvs.runcmd("ifconfig Ethernet0 10.0.0.0/31 up")
dvs.runcmd("ifconfig Ethernet4 10.0.0.2/31 up")
dvs.runcmd("ifconfig Ethernet8 10.0.0.4/31 up")
Expand All @@ -85,32 +72,17 @@ def test_swss_port_state_syncup(dvs):

warmtbl = swsscommon.Table(db, "WARM_START_TABLE")

# restart_count for each process in SWSS should be 2
keys = warmtbl.getKeys()
print(keys)

(status, fvs) = warmtbl.get("vlanmgrd")
assert status == True
for fv in fvs:
if fv[0] == "restart_count":
assert fv[1] == "2"
else:
assert False

(status, fvs) = warmtbl.get("portsyncd")
assert status == True
for fv in fvs:
if fv[0] == "restart_count":
assert fv[1] == "2"
else:
assert False

(status, fvs) = warmtbl.get("orchagent")
assert status == True
for fv in fvs:
if fv[0] == "restart_count":
assert fv[1] == "2"
else:
assert False
for key in keys:
(status, fvs) = warmtbl.get(key)
assert status == True
for fv in fvs:
if fv[0] == "restart_count":
assert fv[1] == "2"
else:
assert False

tbl = swsscommon.Table(db, "PORT_TABLE")

Expand All @@ -129,3 +101,118 @@ def test_swss_port_state_syncup(dvs):
else:
assert oper_status == "down"


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 del_entry_tbl(db, table, key):
tbl = swsscommon.Table(db, table)
tbl._del(key)

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 getCrmCounterValue(dvs, key, counter):

counters_db = swsscommon.DBConnector(swsscommon.COUNTERS_DB, dvs.redis_sock, 0)
crm_stats_table = swsscommon.Table(counters_db, 'CRM')

for k in crm_stats_table.get(key)[1]:
if k[0] == counter:
return int(k[1])
return 0

def test_swss_fdb_syncup_and_crm(dvs):
# syncd warm start with temp view not supported yet
if dvs.tmpview == True:
return

# Prepare FDB entry before swss stop
appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0)
asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)
conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0)

# create a FDB entry in Application DB
create_entry_pst(
appl_db,
"FDB_TABLE", "Vlan2:52-54-00-25-06-E9",
[
("port", "Ethernet12"),
("type", "dynamic"),
]
)
# create vlan
create_entry_tbl(
conf_db,
"VLAN", "Vlan2",
[
("vlanid", "2"),
]
)

# create vlan member entry in application db. Don't use Ethernet0/4/8 as IP configured on them in previous testing.
create_entry_tbl(
conf_db,
"VLAN_MEMBER", "Vlan2|Ethernet12",
[
("tagging_mode", "untagged"),
]
)
# check that the FDB entry was inserted into ASIC DB
assert how_many_entries_exist(asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY") == 1, "The fdb entry wasn't inserted to ASIC"

dvs.runcmd("crm config polling interval 1")
time.sleep(2)
# get counters
used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_used')
assert used_counter == 1

# Change the polling interval to 20 so we may see the crm counter changes after warm restart
dvs.runcmd("crm config polling interval 20")

dvs.runcmd("/usr/bin/stop_swss.sh")

# delete the FDB entry in AppDB before swss is started again,
# the orchagent is supposed to sync up the entry from ASIC DB after warm restart
del_entry_tbl(appl_db, "FDB_TABLE", "Vlan2:52-54-00-25-06-E9")


time.sleep(1)
dvs.runcmd("/usr/bin/start_swss.sh")
time.sleep(10)

# restart_count for each process in SWSS should be 3
warmtbl = swsscommon.Table(appl_db, "WARM_START_TABLE")
keys = warmtbl.getKeys()
print(keys)
for key in keys:
(status, fvs) = warmtbl.get(key)
assert status == True
for fv in fvs:
if fv[0] == "restart_count":
assert fv[1] == "3"
else:
assert False

# get counters for FDB entries, it should be 0
used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_used')
assert used_counter == 0
dvs.runcmd("crm config polling interval 10")
time.sleep(20)
# get counters for FDB entries, it should be 1
used_counter = getCrmCounterValue(dvs, 'STATS', 'crm_stats_fdb_entry_used')
assert used_counter == 1

0 comments on commit 34a7de7

Please sign in to comment.