From 8522390aa58835887a8603fea4fc38bfbdf56d6c Mon Sep 17 00:00:00 2001 From: Prince Sunny Date: Tue, 27 Nov 2018 21:05:22 -0800 Subject: [PATCH] Add vxlan switch attributes to switch orch (#712) --- orchagent/switchorch.cpp | 15 ++++++++- tests/test_switch.py | 73 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 tests/test_switch.py diff --git a/orchagent/switchorch.cpp b/orchagent/switchorch.cpp index 7b7d63a3f1bc..6c93556cfbcb 100644 --- a/orchagent/switchorch.cpp +++ b/orchagent/switchorch.cpp @@ -4,6 +4,7 @@ #include "converter.h" #include "notifier.h" #include "notificationproducer.h" +#include "macaddress.h" using namespace std; using namespace swss; @@ -18,7 +19,9 @@ const map switch_attribute_map = {"fdb_multicast_miss_packet_action", SAI_SWITCH_ATTR_FDB_MULTICAST_MISS_PACKET_ACTION}, {"ecmp_hash_seed", SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_SEED}, {"lag_hash_seed", SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_SEED}, - {"fdb_aging_time", SAI_SWITCH_ATTR_FDB_AGING_TIME} + {"fdb_aging_time", SAI_SWITCH_ATTR_FDB_AGING_TIME}, + {"vxlan_port", SAI_SWITCH_ATTR_VXLAN_DEFAULT_PORT}, + {"vxlan_router_mac", SAI_SWITCH_ATTR_VXLAN_DEFAULT_ROUTER_MAC} }; const map packet_action_map = @@ -66,6 +69,7 @@ void SwitchOrch::doTask(Consumer &consumer) sai_attribute_t attr; attr.id = switch_attribute_map.at(attribute); + MacAddress mac_addr; bool invalid_attr = false; switch (attr.id) { @@ -90,6 +94,15 @@ void SwitchOrch::doTask(Consumer &consumer) attr.value.u32 = to_uint(value); break; + case SAI_SWITCH_ATTR_VXLAN_DEFAULT_PORT: + attr.value.u16 = to_uint(value); + break; + + case SAI_SWITCH_ATTR_VXLAN_DEFAULT_ROUTER_MAC: + mac_addr = value; + memcpy(attr.value.mac, mac_addr.getMac(), sizeof(sai_mac_t)); + break; + default: invalid_attr = true; break; diff --git a/tests/test_switch.py b/tests/test_switch.py new file mode 100644 index 000000000000..a5070f7b1f3a --- /dev/null +++ b/tests/test_switch.py @@ -0,0 +1,73 @@ +from swsscommon import swsscommon +import time + + +def create_entry(tbl, key, pairs): + fvs = swsscommon.FieldValuePairs(pairs) + tbl.set(key, fvs) + time.sleep(1) + + +def get_exist_entry(dvs, table): + db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + tbl = swsscommon.Table(db, table) + entries = list(tbl.getKeys()) + return entries[0] + + +def create_entry_pst(db, table, separator, key, pairs): + tbl = swsscommon.ProducerStateTable(db, table) + create_entry(tbl, key, pairs) + + +def check_object(db, table, key, expected_attributes): + tbl = swsscommon.Table(db, table) + keys = tbl.getKeys() + assert key in keys, "The desired key is not presented" + + status, fvs = tbl.get(key) + assert status, "Got an error when get a key" + + assert len(fvs) >= len(expected_attributes), "Incorrect attributes" + + attr_keys = {entry[0] for entry in fvs} + + for name, value in fvs: + if name in expected_attributes: + assert expected_attributes[name] == value, "Wrong value %s for the attribute %s = %s" % \ + (value, name, expected_attributes[name]) + + +def vxlan_switch_test(dvs, oid, port, mac): + app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + create_entry_pst( + app_db, + "SWITCH_TABLE", ':', "switch", + [ + ("vxlan_port", port), + ("vxlan_router_mac", mac) + ], + ) + time.sleep(2) + + asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + check_object(asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_SWITCH", oid, + { + 'SAI_SWITCH_ATTR_VXLAN_DEFAULT_PORT': port, + 'SAI_SWITCH_ATTR_VXLAN_DEFAULT_ROUTER_MAC': mac, + } + ) + + +class TestSwitch(object): + + ''' + Test- Check switch attributes + ''' + def test_switch_attribute(self, dvs, testlog): + switch_oid = get_exist_entry(dvs, "ASIC_STATE:SAI_OBJECT_TYPE_SWITCH") + + vxlan_switch_test(dvs, switch_oid, "12345", "00:01:02:03:04:05") + + vxlan_switch_test(dvs, switch_oid, "56789", "00:0A:0B:0C:0D:0E") +