Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dash] Improve dash test cases #16612

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions tests/dash/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from ipaddress import ip_interface
from constants import ENI, VM_VNI, VNET1_VNI, VNET2_VNI, REMOTE_CA_IP, LOCAL_CA_IP, REMOTE_ENI_MAC,\
LOCAL_ENI_MAC, REMOTE_CA_PREFIX, LOOPBACK_IP, DUT_MAC, LOCAL_PA_IP, LOCAL_PTF_INTF, LOCAL_PTF_MAC,\
REMOTE_PA_IP, REMOTE_PTF_INTF, REMOTE_PTF_MAC, REMOTE_PA_PREFIX, VNET1_NAME, VNET2_NAME, ROUTING_ACTION, \
ROUTING_ACTION_TYPE, LOOKUP_OVERLAY_IP, ACL_GROUP, ACL_STAGE
REMOTE_PA_IP, REMOTE_PTF_INTF, REMOTE_PTF_MAC, REMOTE_PA_PREFIX, VNET1_NAME, VNET2_NAME, ROUTING_TYPE, \
ROUTING_ACTION_TYPE, LOOKUP_OVERLAY_IP, ACL_GROUP, ACL_STAGE, OUTBOUND_ROUTING_GROUP
from dash_utils import render_template_to_host, apply_swssconfig_file
from gnmi_utils import generate_gnmi_cert, apply_gnmi_cert, recover_gnmi_cert, apply_gnmi_file
from dash_acl import AclGroup, DEFAULT_ACL_GROUP, WAIT_AFTER_CONFIG, DefaultAclRule
Expand Down Expand Up @@ -50,7 +50,7 @@ def pytest_addoption(parser):
parser.addoption(
"--vxlan_udp_dport",
action="store",
default="random",
default="default",
help="The vxlan udp dst port used in the test"
)

Expand Down Expand Up @@ -134,6 +134,7 @@ def dash_config_info(duthost, config_facts, minigraph_facts, tbinfo):
REMOTE_ENI_MAC: "F9:22:83:99:22:A2",
LOCAL_ENI_MAC: "F4:93:9F:EF:C4:7E",
REMOTE_CA_PREFIX: "20.2.2.0/24",
OUTBOUND_ROUTING_GROUP: "orouting_group1",
ACL_GROUP: "group1",
ACL_STAGE: 5
}
Expand Down Expand Up @@ -211,7 +212,7 @@ def _apply_config(config_info):
@pytest.fixture(scope="function")
def dash_inbound_configs(dash_config_info, use_underlay_route, minigraph_facts):
if use_underlay_route:
dash_config_info[LOCAL_PA_IP] = u"30.30.30.30"
dash_config_info[LOCAL_PA_IP] = u"30.30.30.20"
dash_config_info[LOCAL_PTF_INTF] = list(minigraph_facts["minigraph_ptf_indices"].values())
else:
dash_config_info[LOCAL_PTF_INTF] = [dash_config_info[LOCAL_PTF_INTF]]
Expand All @@ -222,7 +223,7 @@ def dash_inbound_configs(dash_config_info, use_underlay_route, minigraph_facts):

@pytest.fixture(scope="function")
def apply_inbound_configs(dash_inbound_configs, apply_config):
dash_inbound_configs[ROUTING_ACTION] = "vnet"
dash_inbound_configs[ROUTING_TYPE] = "vnet"
apply_config(dash_inbound_configs)


Expand All @@ -244,13 +245,14 @@ def dash_outbound_configs(dash_config_info, use_underlay_route, minigraph_facts,

@pytest.fixture(scope="function")
def apply_vnet_configs(dash_outbound_configs, apply_config):
dash_outbound_configs[ROUTING_ACTION] = "vnet"
dash_outbound_configs[ROUTING_TYPE] = "vnet"
dash_outbound_configs[ROUTING_ACTION_TYPE] = "maprouting"
apply_config(dash_outbound_configs)


@pytest.fixture(scope="function")
def apply_vnet_direct_configs(dash_outbound_configs, apply_config):
dash_outbound_configs[ROUTING_ACTION] = "vnet_direct"
dash_outbound_configs[ROUTING_TYPE] = "vnet_direct"
dash_outbound_configs[ROUTING_ACTION_TYPE] = "maprouting"
dash_outbound_configs[LOOKUP_OVERLAY_IP] = "1.1.1.1"

Expand All @@ -259,7 +261,7 @@ def apply_vnet_direct_configs(dash_outbound_configs, apply_config):

@pytest.fixture(scope="function")
def apply_direct_configs(dash_outbound_configs, apply_config):
dash_outbound_configs[ROUTING_ACTION] = "direct"
dash_outbound_configs[ROUTING_TYPE] = "direct"
del dash_outbound_configs[VNET2_NAME]

apply_config(dash_outbound_configs)
Expand Down Expand Up @@ -331,8 +333,9 @@ def vxlan_udp_dport(request, duthost):

yield vxlan_udp_dport

logger.info("Restore the VXLAN UDP dst port to 4789")
config_vxlan_udp_dport(duthost, 4789)
if vxlan_udp_dport != 4789:
logger.info("Restore the VXLAN UDP dst port to 4789")
config_vxlan_udp_dport(duthost, 4789)


@pytest.fixture(scope="function")
Expand Down
3 changes: 2 additions & 1 deletion tests/dash/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
REMOTE_PA_PREFIX = "remote_pa_prefix"
LOCAL_PTF_INTF = "local_ptf_intf"
REMOTE_PTF_INTF = "remote_ptf_intf"
ROUTING_ACTION = "routing_action"
ROUTING_TYPE = "routing_type"
ROUTING_ACTION_TYPE = "routing_action_type"
LOOKUP_OVERLAY_IP = "lookup_overlay_ip"
OUTBOUND_ROUTING_GROUP = "outbound_routing_group"
# For ACL
ACL_GROUP = "acl_group"
ACL_STAGE = "acl_stage"
Expand Down
4 changes: 3 additions & 1 deletion tests/dash/gnmi_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def gnmi_get(duthost, ptfhost, path_list):


def apply_gnmi_file(localhost, duthost, ptfhost, dest_path=None, config_json=None,
wait_after_apply=5, max_updates_in_single_cmd=1024):
wait_after_apply=5, max_updates_in_single_cmd=1):
"""
Apply dash configuration with gnmi client

Expand Down Expand Up @@ -393,6 +393,8 @@ def _devide_list(operation_list):

if delete_list:
delete_list_group = _devide_list(delete_list)
# Deletion in reverse order for dependency
delete_list_group.reverse()
for delete_list in delete_list_group:
gnmi_set(duthost, ptfhost, delete_list, [], [])
if update_list:
Expand Down
6 changes: 6 additions & 0 deletions tests/dash/packets.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ def inbound_vnet_packets(dash_config_info, inner_extra_conf={}, inner_packet_typ
pa_mismatch_vxlan_packet["IP"].src = str(remote_pa_ip + 1)

masked_exp_packet = Mask(expected_packet)
masked_exp_packet.set_do_not_care_scapy(scapy.Ether, "dst")
masked_exp_packet.set_do_not_care_scapy(scapy.Ether, "src")
masked_exp_packet.set_do_not_care_scapy(scapy.IP, "id")
masked_exp_packet.set_do_not_care_scapy(scapy.IP, "chksum")
masked_exp_packet.set_do_not_care_scapy(scapy.IP, "ttl")
masked_exp_packet.set_do_not_care_scapy(scapy.UDP, "sport")
masked_exp_packet.set_do_not_care_scapy(scapy.UDP, "chksum")

Expand Down Expand Up @@ -121,8 +124,11 @@ def outbound_vnet_packets(dash_config_info, inner_extra_conf={}, inner_packet_ty
)

masked_exp_packet = Mask(expected_packet)
masked_exp_packet.set_do_not_care_scapy(scapy.Ether, "dst")
masked_exp_packet.set_do_not_care_scapy(scapy.Ether, "src")
masked_exp_packet.set_do_not_care_scapy(scapy.IP, "id")
masked_exp_packet.set_do_not_care_scapy(scapy.IP, "chksum")
masked_exp_packet.set_do_not_care_scapy(scapy.IP, "ttl")
masked_exp_packet.set_do_not_care_scapy(scapy.UDP, "sport")
masked_exp_packet.set_do_not_care_scapy(scapy.UDP, "chksum")
return inner_packet, vxlan_packet, masked_exp_packet
Expand Down
20 changes: 18 additions & 2 deletions tests/dash/proto_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
from dash_api.route_pb2 import Route
from dash_api.route_rule_pb2 import RouteRule
from dash_api.vnet_mapping_pb2 import VnetMapping
from dash_api.route_type_pb2 import RoutingType, ActionType, RouteType, RouteTypeItem
from dash_api.route_type_pb2 import RoutingType, ActionType, EncapType, RouteType, RouteTypeItem
from dash_api.types_pb2 import IpVersion, IpPrefix, ValueOrRange
from dash_api.acl_group_pb2 import AclGroup
from dash_api.acl_out_pb2 import AclOut
from dash_api.acl_in_pb2 import AclIn
from dash_api.acl_rule_pb2 import AclRule, Action
from dash_api.prefix_tag_pb2 import PrefixTag
from dash_api.route_group_pb2 import RouteGroup
from dash_api.eni_route_pb2 import EniRoute


ENABLE_PROTO = True
Expand Down Expand Up @@ -65,6 +67,14 @@ def eni_from_json(json_obj):
pb.qos = json_obj["qos"]
return pb

def eni_route_from_json(json_obj):
pb = EniRoute()
pb.group_id = json_obj["group_id"]
return pb

def route_group_from_json(json_obj):
pb = RouteGroup()
return pb

def route_from_json(json_obj):
pb = Route()
Expand Down Expand Up @@ -96,7 +106,11 @@ def routing_type_from_json(json_obj):
pb = RouteType()
pbi = RouteTypeItem()
pbi.action_name = json_obj["name"]
pbi.action_type = ActionType.ACTION_TYPE_MAPROUTING
if json_obj["action_type"] == "staticencap":
pbi.action_type = ActionType.ACTION_TYPE_STATICENCAP
pbi.encap_type = EncapType.ENCAP_TYPE_VXLAN
elif json_obj["action_type"] == "maprouting":
pbi.action_type = ActionType.ACTION_TYPE_MAPROUTING
pb.items.append(pbi)
return pb

Expand Down Expand Up @@ -186,7 +200,9 @@ def prefix_tag_from_json(json_obj):
"VNET": vnet_from_json,
"VNET_MAPPING": vnet_mapping_from_json,
"QOS": qos_from_json,
"ROUTE_GROUP": route_group_from_json,
"ENI": eni_from_json,
"ENI_ROUTE": eni_route_from_json,
"ROUTE": route_from_json,
"ROUTE_RULE": route_rule_from_json,
"ROUTING_TYPE": routing_type_from_json,
Expand Down
43 changes: 31 additions & 12 deletions tests/dash/templates/dash_basic_config.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@
},
"OP": "{{ op }}"
},
{
"DASH_ROUTING_TYPE_TABLE:vnet_encap" : {
"name": "action1",
"action_type": "staticencap"
},
"OP": "{{ op }}"
},
{%- if routing_action_type is defined -%}
{
"DASH_ROUTING_TYPE_TABLE:{{ routing_type }}" : {
"name": "action1",
"action_type": "{{ routing_action_type }}"
},
"OP": "{{ op }}"
},
{%- endif %}
{%- if vnet1_name is defined %}
{
"DASH_VNET_TABLE:{{ vnet1_name }}" : {
Expand Down Expand Up @@ -33,6 +49,12 @@
"OP": "{{ op }}"
},
{%- endif %}
{
"DASH_ROUTE_GROUP_TABLE:{{ outbound_routing_group }}" : {
"disabled":"false"
},
"OP": "{{ op }}"
},
{
"DASH_QOS_TABLE:qos100" : {
"qos_id":"100",
Expand All @@ -54,8 +76,8 @@
"OP": "{{ op }}"
},
{
"DASH_ROUTE_TABLE:{{ eni }}:{{ remote_ca_prefix }}" : {
"action_type":"{{ routing_action }}"
"DASH_ROUTE_TABLE:{{ outbound_routing_group }}:{{ remote_ca_prefix }}" : {
"action_type":"{{ routing_type }}"
{%- if lookup_overlay_ip is defined -%},
"overlay_ip": "{{ lookup_overlay_ip }}"
{%- endif %}
Expand All @@ -65,18 +87,9 @@
},
"OP": "{{ op }}"
}
{%- if routing_action_type is defined -%},
{
"DASH_ROUTING_TYPE_TABLE:{{ routing_action }}" : {
"name": "action1",
"action_type": "{{ routing_action_type }}"
},
"OP": "{{ op }}"
}
{%- endif %}
{%- if vnet2_name is defined -%},
{
"DASH_ROUTE_RULE_TABLE:{{ eni }}:{{ vnet2_vni }}:{{ remote_pa_prefix }}" : {
"DASH_ROUTE_RULE_TABLE:{{ eni }}:{{ vnet2_vni }}:{{ remote_pa_ip }}" : {
"action_type":"decap",
"priority":"1",
"pa_validation":"true",
Expand All @@ -85,4 +98,10 @@
"OP": "{{ op }}"
}
{%- endif %}
,{
"DASH_ENI_ROUTE_TABLE:{{ eni }}" : {
"group_id":"{{ outbound_routing_group }}"
},
"OP": "{{ op }}"
}
]
Loading