Skip to content

Commit

Permalink
Add vs test cases
Browse files Browse the repository at this point in the history
Signed-off-by: bingwang <wang.bing@microsoft.com>
  • Loading branch information
bingwang-ms committed Apr 12, 2022
1 parent dbf28d3 commit 2af94da
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 67 deletions.
27 changes: 21 additions & 6 deletions orchagent/muxorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ static sai_object_id_t create_tunnel(
const IpAddress* p_dst_ip,
const IpAddress* p_src_ip,
sai_object_id_t tc_to_dscp_map_id,
sai_object_id_t tc_to_queue_map_id)
sai_object_id_t tc_to_queue_map_id,
string dscp_mode_name)
{
sai_status_t status;

Expand Down Expand Up @@ -210,10 +211,17 @@ static sai_object_id_t create_tunnel(
attr.value.s32 = SAI_TUNNEL_TTL_MODE_PIPE_MODEL;
tunnel_attrs.push_back(attr);

// Set DSCP mode to PIPE to ensure that outer DSCP is independent of inner DSCP
// and inner DSCP is unchanged at decap
sai_tunnel_dscp_mode_t dscp_mode;
if (dscp_mode_name == "uniform")
{
dscp_mode = SAI_TUNNEL_DSCP_MODE_UNIFORM_MODEL;
}
else
{
dscp_mode = SAI_TUNNEL_DSCP_MODE_PIPE_MODEL;
}
attr.id = SAI_TUNNEL_ATTR_ENCAP_DSCP_MODE;
attr.value.s32 = SAI_TUNNEL_DSCP_MODE_PIPE_MODEL;
attr.value.s32 = dscp_mode;
tunnel_attrs.push_back(attr);

attr.id = SAI_TUNNEL_ATTR_LOOPBACK_PACKET_ACTION;
Expand All @@ -239,13 +247,15 @@ static sai_object_id_t create_tunnel(
{
attr.id = SAI_TUNNEL_ATTR_ENCAP_QOS_TC_AND_COLOR_TO_DSCP_MAP;
attr.value.oid = tc_to_dscp_map_id;
tunnel_attrs.push_back(attr);
}

// TC remapping
if (tc_to_queue_map_id != SAI_NULL_OBJECT_ID)
{
attr.id = SAI_TUNNEL_ATTR_ENCAP_QOS_TC_TO_QUEUE_MAP;
attr.value.oid = tc_to_queue_map_id;
tunnel_attrs.push_back(attr);
}

sai_object_id_t tunnel_id;
Expand Down Expand Up @@ -1262,7 +1272,7 @@ bool MuxOrch::resolveQosTableIds()
tc_to_dscp_map_id_ = id;
}
setObjectReference(QosOrch::getTypeMap(), CFG_TUNNEL_TABLE_NAME, MUX_TUNNEL, map_type_name, object_name);
SWSS_LOG_INFO("Resolved QoS map for tunnel %s type %s name %s", MUX_TUNNEL, map_type_name.c_str(), map_name.c_str());
SWSS_LOG_NOTICE("Resolved QoS map for tunnel %s type %s name %s", MUX_TUNNEL, map_type_name.c_str(), map_name.c_str());
}
}
}
Expand Down Expand Up @@ -1302,7 +1312,12 @@ bool MuxOrch::handlePeerSwitch(const Request& request)
}
auto it = dst_ips.getIpAddresses().begin();
const IpAddress& dst_ip = *it;
mux_tunnel_id_ = create_tunnel(&peer_ip, &dst_ip, tc_to_dscp_map_id_, tc_to_queue_map_id_);

// Read dscp_mode of MuxTunnel0 from config_db
string dscp_mode_name = "pipe";
cfgTunnelTable_.hget(MUX_TUNNEL, "dscp_mode", dscp_mode_name);

mux_tunnel_id_ = create_tunnel(&peer_ip, &dst_ip, tc_to_dscp_map_id_, tc_to_queue_map_id_, dscp_mode_name);
SWSS_LOG_NOTICE("Mux peer ip '%s' was added, peer name '%s'",
peer_ip.to_string().c_str(), peer_name.c_str());
}
Expand Down
3 changes: 2 additions & 1 deletion orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ bool OrchDaemon::init()
CFG_PFC_PRIORITY_TO_PRIORITY_GROUP_MAP_TABLE_NAME,
CFG_PFC_PRIORITY_TO_QUEUE_MAP_TABLE_NAME,
CFG_DSCP_TO_FC_MAP_TABLE_NAME,
CFG_EXP_TO_FC_MAP_TABLE_NAME
CFG_EXP_TO_FC_MAP_TABLE_NAME,
CFG_TC_TO_DSCP_MAP_TABLE_NAME
};
gQosOrch = new QosOrch(m_configDb, qos_tables);

Expand Down
3 changes: 2 additions & 1 deletion orchagent/qosorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ type_map QosOrch::m_qos_maps = {
{CFG_PFC_PRIORITY_TO_QUEUE_MAP_TABLE_NAME, new object_reference_map()},
{CFG_DSCP_TO_FC_MAP_TABLE_NAME, new object_reference_map()},
{CFG_EXP_TO_FC_MAP_TABLE_NAME, new object_reference_map()},
{CFG_TC_TO_DSCP_MAP_TABLE_NAME, new object_reference_map()}
{CFG_TC_TO_DSCP_MAP_TABLE_NAME, new object_reference_map()},
{CFG_TUNNEL_TABLE_NAME, new object_reference_map()}
};

map<string, string> qos_to_ref_table_map = {
Expand Down
61 changes: 30 additions & 31 deletions tests/test_mux.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class TestMuxTunnelBase(object):
ASIC_NEXTHOP_TABLE = "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP"
ASIC_ROUTE_TABLE = "ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY"
CONFIG_MUX_CABLE = "MUX_CABLE"
CONFIG_TUNNEL_TABLE_NAME = "TUNNEL"
ASIC_QOS_MAP_TABLE_KEY = "ASIC_STATE:SAI_OBJECT_TYPE_QOS_MAP"
TUNNEL_QOS_MAP_NAME = "AZURE_TUNNEL"

SERV1_IPV4 = "192.168.0.100"
Expand All @@ -31,7 +33,7 @@ class TestMuxTunnelBase(object):
IPV6_MASK = "/128"
TUNNEL_NH_ID = 0
ACL_PRIORITY = "999"

ecn_modes_map = {
"standard" : "SAI_TUNNEL_DECAP_ECN_MODE_STANDARD",
"copy_from_outer": "SAI_TUNNEL_DECAP_ECN_MODE_COPY_FROM_OUTER"
Expand All @@ -47,7 +49,7 @@ class TestMuxTunnelBase(object):
"uniform" : "SAI_TUNNEL_TTL_MODE_UNIFORM_MODEL"
}

TC_TO_DSCP_MAP = {str(i):str{i} for i in range(0, 8)}
TC_TO_DSCP_MAP = {str(i):str(i) for i in range(0, 8)}
TC_TO_QUEUE_MAP = {str(i):str(i) for i in range(0, 8)}

def create_vlan_interface(self, confdb, asicdb, dvs):
Expand Down Expand Up @@ -147,7 +149,7 @@ def check_nexthop_group_in_asic_db(self, asicdb, key, num_tnl_nh=0):
for k in keys:
fvs = asicdb.get_entry("ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP_GROUP_MEMBER", k)
assert fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID"] == nhg_id

# Count the number of Nexthop member pointing to tunnel
if fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID"] == tunnel_nh_id:
count += 1
Expand Down Expand Up @@ -191,7 +193,7 @@ def create_and_test_neighbor(self, confdb, appdb, asicdb, dvs, dvs_route):
self.set_mux_state(appdb, "Ethernet4", "standby")

self.add_neighbor(dvs, self.SERV1_IPV4, "00:00:00:00:00:01")
# Broadcast neigh 192.168.0.255 is default added. Hence +1 for expected number
# Broadcast neigh 192.168.0.255 is default added. Hence +1 for expected number
srv1_v4 = self.check_neigh_in_asic_db(asicdb, self.SERV1_IPV4, 2)

self.add_neighbor(dvs, self.SERV1_IPV6, "00:00:00:00:00:01", True)
Expand Down Expand Up @@ -334,9 +336,9 @@ def create_and_test_route(self, appdb, asicdb, dvs, dvs_route):
dvs_route.check_asicdb_deleted_route_entries([rtprefix])

ps = swsscommon.ProducerStateTable(pdb.db_connection, "ROUTE_TABLE")

fvs = swsscommon.FieldValuePairs([("nexthop", self.SERV1_IPV4 + "," + self.SERV2_IPV4), ("ifname", "Vlan1000,Vlan1000")])

ps.set(rtprefix, fvs)

# Check if route was propagated to ASIC DB
Expand Down Expand Up @@ -544,7 +546,7 @@ def create_and_test_peer(self, db, asicdb, peer_name, peer_ip, src_ip, tc_to_dsc
assert p2p_obj != None

fvs = asicdb.wait_for_entry(self.ASIC_TUNNEL_TABLE, p2p_obj)

if tc_to_dscp_map_oid:
assert "SAI_TUNNEL_ATTR_ENCAP_QOS_TC_AND_COLOR_TO_DSCP_MAP" in fvs
if tc_to_queue_map_oid:
Expand All @@ -571,18 +573,20 @@ def create_and_test_peer(self, db, asicdb, peer_name, peer_ip, src_ip, tc_to_dsc
assert value == tc_to_dscp_map_oid
elif field == "SAI_TUNNEL_ATTR_ENCAP_QOS_TC_TO_QUEUE_MAP":
assert value == tc_to_queue_map_oid
elif field == "SAI_TUNNEL_ATTR_ENCAP_DSCP_MODE":
assert value == "SAI_TUNNEL_DSCP_MODE_PIPE_MODEL"
else:
assert False, "Field %s is not tested" % field


def check_tunnel_termination_entry_exists_in_asicdb(self, asicdb, tunnel_sai_oid, dst_ips, src_ip=None):
tunnel_term_entries = asicdb.wait_for_n_keys(self.ASIC_TUNNEL_TERM_ENTRIES, len(dst_ips))
expected_term_type = "SAI_TUNNEL_TERM_TABLE_ENTRY_TYPE_P2P" if src_ip else "SAI_TUNNEL_TERM_TABLE_ENTRY_TYPE_P2MP"

expected_len = 6 if src_ip else 5
for term_entry in tunnel_term_entries:
fvs = asicdb.get_entry(self.ASIC_TUNNEL_TERM_ENTRIES, term_entry)

assert len(fvs) == 5
assert len(fvs) == expected_len

for field, value in fvs.items():
if field == "SAI_TUNNEL_TERM_TABLE_ENTRY_ATTR_VR_ID":
Expand All @@ -601,17 +605,14 @@ def check_tunnel_termination_entry_exists_in_asicdb(self, asicdb, tunnel_sai_oid
assert False, "Field %s is not tested" % field


def create_and_test_tunnel(self, db, asicdb, tunnel_name, **kwargs):
def create_and_test_tunnel(self, configdb, asicdb, tunnel_name, **kwargs):
""" Create tunnel and verify all needed enties in ASIC DB exists """

is_symmetric_tunnel = "src_ip" in kwargs;

# create tunnel entry in DB
ps = swsscommon.ProducerStateTable(db, self.APP_TUNNEL_DECAP_TABLE_NAME)

is_symmetric_tunnel = "src_ip" in kwargs
fvs = create_fvs(**kwargs)

ps.set(tunnel_name, fvs)
# Write into config db for muxorch, tunnelmgrd will write to APP_DB
configdb_ps = swsscommon.Table(configdb, self.CONFIG_TUNNEL_TABLE_NAME)
configdb_ps.set(tunnel_name, fvs)

# wait till config will be applied
time.sleep(1)
Expand Down Expand Up @@ -681,21 +682,19 @@ def remove_and_test_tunnel(self, db, asicdb, tunnel_name):
def add_qos_map(self, configdb, asicdb, qos_map_type_name, qos_map_name, qos_map):
current_oids = asicdb.get_keys(self.ASIC_QOS_MAP_TABLE_KEY)
# Apply QoS map to config db
table = swsscommon.Table(configdb, qos_map_type_name)
table = swsscommon.Table(configdb.db_connection, qos_map_type_name)
fvs = swsscommon.FieldValuePairs(list(qos_map.items()))
table.set(qos_map_name, fvs)
time.sleep(1)

diff = set(asicdb.get_keys(self.ASIC_QOS_MAP_TABLE_KEY)) - set(current_oids)
assert len(diff) == 1
oid = diff.pop()
fvs_in_asicdb = asicdb.get_entry(self.ASIC_QOS_MAP_TABLE_KEY, oid)
assert(fvs_in_asicdb["SAI_QOS_MAP_ATTR_TYPE"] == qos_map_type_name)
return oid

def remove_qos_map(self, configdb, qos_map_oid):
def remove_qos_map(self, configdb, qos_map_type_name, qos_map_oid):
""" Remove the testing qos map"""
table = swsscommon.Table(configdb, qos_map_type_name)
table = swsscommon.Table(configdb.db_connection, qos_map_type_name)
table._del(qos_map_oid)

def cleanup_left_over(self, db, asicdb):
Expand All @@ -720,32 +719,32 @@ class TestMuxTunnel(TestMuxTunnelBase):
def test_Tunnel(self, dvs, testlog):
""" test IPv4 Mux tunnel creation """

db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0)
configdb = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0)
asicdb = dvs.get_asic_db()

#self.cleanup_left_over(db, asicdb)

# create tunnel IPv4 tunnel
self.create_and_test_tunnel(db, asicdb, tunnel_name="MuxTunnel0", tunnel_type="IPINIP",
dst_ip="10.1.0.32", dscp_mode="pipe",
self.create_and_test_tunnel(configdb, asicdb, tunnel_name="MuxTunnel0", tunnel_type="IPINIP",
src_ip="10.1.0.33", dst_ip="10.1.0.32", dscp_mode="pipe",
ecn_mode="standard", ttl_mode="pipe",
encap_tc_to_queue_map=self.TUNNEL_QOS_MAP_NAME,
encap_tc_color_to_dscp_map=self.TUNNEL_QOS_MAP_NAME)
encap_tc_to_dscp_map=self.TUNNEL_QOS_MAP_NAME)


def test_Peer(self, dvs, testlog):
""" test IPv4 Mux tunnel creation """

db = dvs.get_config_db()
asicdb = dvs.get_asic_db()
tc_to_dscp_map_oid = self.add_qos_map(configdb, asicdb, swsscommon.CFG_TC_TO_DSCP_MAP_TABLE_NAME, self.TUNNEL_QOS_MAP_NAME, self.TC_TO_DSCP_MAP)
tc_to_queue_map_oid = self.add_qos_map(configdb, asicdb, swsscommon.CFG_TC_TO_QUEUE_MAP_TABLE_NAME, self.TUNNEL_QOS_MAP_NAME, self.TC_TO_QUEUE_MAP)

tc_to_dscp_map_oid = self.add_qos_map(db, asicdb, swsscommon.CFG_TC_TO_DSCP_MAP_TABLE_NAME, self.TUNNEL_QOS_MAP_NAME, self.TC_TO_DSCP_MAP)
tc_to_queue_map_oid = self.add_qos_map(db, asicdb, swsscommon.CFG_TC_TO_QUEUE_MAP_TABLE_NAME, self.TUNNEL_QOS_MAP_NAME, self.TC_TO_QUEUE_MAP)

self.create_and_test_peer(db, asicdb, "peer", "1.1.1.1", "10.1.0.32", tc_to_dscp_map_oid, tc_to_queue_map_oid)

self.remove_qos_map(configdb, tc_to_dscp_map_oid)
self.remove_qos_map(tc_to_queue_map_oid)
self.remove_qos_map(db, swsscommon.CFG_TC_TO_DSCP_MAP_TABLE_NAME, tc_to_dscp_map_oid)
self.remove_qos_map(db, swsscommon.CFG_TC_TO_QUEUE_MAP_TABLE_NAME, tc_to_queue_map_oid)


def test_Neighbor(self, dvs, dvs_route, testlog):
Expand Down
Loading

0 comments on commit 2af94da

Please sign in to comment.