Skip to content

Commit 8522390

Browse files
authored
Add vxlan switch attributes to switch orch (sonic-net#712)
1 parent b123fa0 commit 8522390

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed

orchagent/switchorch.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "converter.h"
55
#include "notifier.h"
66
#include "notificationproducer.h"
7+
#include "macaddress.h"
78

89
using namespace std;
910
using namespace swss;
@@ -18,7 +19,9 @@ const map<string, sai_switch_attr_t> switch_attribute_map =
1819
{"fdb_multicast_miss_packet_action", SAI_SWITCH_ATTR_FDB_MULTICAST_MISS_PACKET_ACTION},
1920
{"ecmp_hash_seed", SAI_SWITCH_ATTR_ECMP_DEFAULT_HASH_SEED},
2021
{"lag_hash_seed", SAI_SWITCH_ATTR_LAG_DEFAULT_HASH_SEED},
21-
{"fdb_aging_time", SAI_SWITCH_ATTR_FDB_AGING_TIME}
22+
{"fdb_aging_time", SAI_SWITCH_ATTR_FDB_AGING_TIME},
23+
{"vxlan_port", SAI_SWITCH_ATTR_VXLAN_DEFAULT_PORT},
24+
{"vxlan_router_mac", SAI_SWITCH_ATTR_VXLAN_DEFAULT_ROUTER_MAC}
2225
};
2326

2427
const map<string, sai_packet_action_t> packet_action_map =
@@ -66,6 +69,7 @@ void SwitchOrch::doTask(Consumer &consumer)
6669
sai_attribute_t attr;
6770
attr.id = switch_attribute_map.at(attribute);
6871

72+
MacAddress mac_addr;
6973
bool invalid_attr = false;
7074
switch (attr.id)
7175
{
@@ -90,6 +94,15 @@ void SwitchOrch::doTask(Consumer &consumer)
9094
attr.value.u32 = to_uint<uint32_t>(value);
9195
break;
9296

97+
case SAI_SWITCH_ATTR_VXLAN_DEFAULT_PORT:
98+
attr.value.u16 = to_uint<uint16_t>(value);
99+
break;
100+
101+
case SAI_SWITCH_ATTR_VXLAN_DEFAULT_ROUTER_MAC:
102+
mac_addr = value;
103+
memcpy(attr.value.mac, mac_addr.getMac(), sizeof(sai_mac_t));
104+
break;
105+
93106
default:
94107
invalid_attr = true;
95108
break;

tests/test_switch.py

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from swsscommon import swsscommon
2+
import time
3+
4+
5+
def create_entry(tbl, key, pairs):
6+
fvs = swsscommon.FieldValuePairs(pairs)
7+
tbl.set(key, fvs)
8+
time.sleep(1)
9+
10+
11+
def get_exist_entry(dvs, table):
12+
db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)
13+
tbl = swsscommon.Table(db, table)
14+
entries = list(tbl.getKeys())
15+
return entries[0]
16+
17+
18+
def create_entry_pst(db, table, separator, key, pairs):
19+
tbl = swsscommon.ProducerStateTable(db, table)
20+
create_entry(tbl, key, pairs)
21+
22+
23+
def check_object(db, table, key, expected_attributes):
24+
tbl = swsscommon.Table(db, table)
25+
keys = tbl.getKeys()
26+
assert key in keys, "The desired key is not presented"
27+
28+
status, fvs = tbl.get(key)
29+
assert status, "Got an error when get a key"
30+
31+
assert len(fvs) >= len(expected_attributes), "Incorrect attributes"
32+
33+
attr_keys = {entry[0] for entry in fvs}
34+
35+
for name, value in fvs:
36+
if name in expected_attributes:
37+
assert expected_attributes[name] == value, "Wrong value %s for the attribute %s = %s" % \
38+
(value, name, expected_attributes[name])
39+
40+
41+
def vxlan_switch_test(dvs, oid, port, mac):
42+
app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0)
43+
create_entry_pst(
44+
app_db,
45+
"SWITCH_TABLE", ':', "switch",
46+
[
47+
("vxlan_port", port),
48+
("vxlan_router_mac", mac)
49+
],
50+
)
51+
time.sleep(2)
52+
53+
asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)
54+
check_object(asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_SWITCH", oid,
55+
{
56+
'SAI_SWITCH_ATTR_VXLAN_DEFAULT_PORT': port,
57+
'SAI_SWITCH_ATTR_VXLAN_DEFAULT_ROUTER_MAC': mac,
58+
}
59+
)
60+
61+
62+
class TestSwitch(object):
63+
64+
'''
65+
Test- Check switch attributes
66+
'''
67+
def test_switch_attribute(self, dvs, testlog):
68+
switch_oid = get_exist_entry(dvs, "ASIC_STATE:SAI_OBJECT_TYPE_SWITCH")
69+
70+
vxlan_switch_test(dvs, switch_oid, "12345", "00:01:02:03:04:05")
71+
72+
vxlan_switch_test(dvs, switch_oid, "56789", "00:0A:0B:0C:0D:0E")
73+

0 commit comments

Comments
 (0)