From 99fe5eea9ed6e4cb1353e6a62a4728d8852ee4bb Mon Sep 17 00:00:00 2001 From: Judong Date: Sat, 2 Dec 2017 15:33:18 +0800 Subject: [PATCH 1/7] [VLAN test] Add VLAN test --- .../roles/test/files/ptftests/vlan_test.py | 268 ++++++++++++++++++ ansible/roles/test/tasks/sonic.yml | 4 + ansible/roles/test/tasks/vlan_cleanup.yml | 23 ++ ansible/roles/test/tasks/vlan_configure.yml | 79 ++++++ ansible/roles/test/tasks/vlan_test.yml | 44 +++ ansible/roles/test/tasks/vlantb.yml | 20 ++ ansible/roles/test/templates/vlan_info.j2 | 34 +++ 7 files changed, 472 insertions(+) create mode 100644 ansible/roles/test/files/ptftests/vlan_test.py create mode 100644 ansible/roles/test/tasks/vlan_cleanup.yml create mode 100644 ansible/roles/test/tasks/vlan_configure.yml create mode 100644 ansible/roles/test/tasks/vlan_test.yml create mode 100644 ansible/roles/test/tasks/vlantb.yml create mode 100644 ansible/roles/test/templates/vlan_info.j2 diff --git a/ansible/roles/test/files/ptftests/vlan_test.py b/ansible/roles/test/files/ptftests/vlan_test.py new file mode 100644 index 00000000000..b7f2daee07a --- /dev/null +++ b/ansible/roles/test/files/ptftests/vlan_test.py @@ -0,0 +1,268 @@ +import ast +import json +import logging +import subprocess + +from collections import defaultdict +from ipaddress import ip_address, ip_network + +import ptf +import ptf.packet as scapy +import ptf.dataplane as dataplane + +from ptf import config +from ptf.base_tests import BaseTest +from ptf.testutils import * +from ptf.mask import Mask + +class VlanTest(BaseTest): + def __init__(self): + BaseTest.__init__(self) + self.test_params = test_params_get() + #-------------------------------------------------------------------------- + + def log(self, message): + logging.info(message) + #-------------------------------------------------------------------------- + + def shell(self, cmds): + sp = subprocess.Popen(cmds, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = sp.communicate() + rc = sp.returncode + + return stdout, stderr, rc + #-------------------------------------------------------------------------- + + def setUp(self): + self.vlan_ports_list = ast.literal_eval(self.test_params["vlan_ports_list"]) + self.vlan_intf_list = ast.literal_eval(self.test_params["vlan_intf_list"]) + self.router_mac = self.test_params["router_mac"] + + for vlan_port in self.vlan_ports_list: + vlan_port["pvid"] = int(vlan_port["pvid"]) + vlan_port["port_index"] = int(vlan_port["port_index"]) + + self.dataplane = ptf.dataplane_instance + self.test_params = test_params_get() + self.setUpArpResponder() + self.log("Start arp_responder") + self.shell(["supervisorctl", "start", "arp_responder"]) + + self.log("Create VLAN intf") + for vlan_port in self.vlan_ports_list: + for permit_vlanid in vlan_port["permit_vlanid"].keys(): + if int(permit_vlanid) != vlan_port["pvid"]: + self.shell(["ip", "link", "add", "link", "eth%d"%vlan_port["port_index"], + "name", "eth%d.%s"%(vlan_port["port_index"], permit_vlanid), + "type", "vlan", "id", str(permit_vlanid)]) + self.shell(["ip", "link", "set", + "eth%d.%s"%(vlan_port["port_index"], permit_vlanid), "up"]) + + logging.info("VLAN test starting ...") + pass + #-------------------------------------------------------------------------- + + def setUpArpResponder(self): + vlan_ports_list = self.vlan_ports_list + d = defaultdict(list) + for vlan_port in vlan_ports_list: + for permit_vlanid in vlan_port["permit_vlanid"].keys(): + if int(permit_vlanid) == vlan_port["pvid"]: + iface = "eth%d" % vlan_port["port_index"] + else: + iface = "eth%d.%s" % (vlan_port["port_index"], permit_vlanid) + d[iface].append(vlan_port["permit_vlanid"][str(permit_vlanid)]["peer_ip"]) + with open('/tmp/from_t1.json', 'w') as file: + json.dump(d, file) + + #-------------------------------------------------------------------------- + def tearDown(self): + logging.info("VLAN test ending ...") + + self.log("Delete VLAN intf") + for vlan_port in self.vlan_ports_list: + for permit_vlanid in vlan_port["permit_vlanid"].keys(): + if int(permit_vlanid) != vlan_port["pvid"]: + self.shell(["ip", "link", "delete", "eth%d.%d"%(vlan_port["port_index"], int(permit_vlanid))]) + + self.log("Stop arp_responder") + self.shell(["supervisorctl", "stop", "arp_responder"]) + + pass + + #-------------------------------------------------------------------------- + def build_icmp_packet(self, vlan_id, + src_mac="00:22:00:00:00:02", dst_mac="00:22:00:00:00:01", + src_ip="192.168.0.1", dst_ip="192.168.0.2", ttl=64): + pkt = simple_icmp_packet(pktlen=100 if vlan_id == 0 else 104, + eth_dst=dst_mac, + eth_src=src_mac, + dl_vlan_enable=False if vlan_id == 0 else True, + vlan_vid=vlan_id, + vlan_pcp=0, + ip_src=src_ip, + ip_dst=dst_ip, + ip_ttl=ttl) + return pkt + + + #-------------------------------------------------------------------------- + def send_icmp_packet(self, vlan_port, vlan_id=0, + src_mac="00:22:00:00:00:02", dst_mac="00:22:00:00:00:01", + src_ip="192.168.0.1", dst_ip="192.168.0.2", ttl=64): + pkt = self.build_icmp_packet(vlan_id, src_mac, dst_mac, src_ip, dst_ip, ttl) + self.log("Send " + ("untagged" if vlan_id == 0 else "tagged(%d)"%vlan_id) + + " packet from " + str(vlan_port["port_index"]) + "...") + self.log("%s -> %s, %s -> %s"%(src_mac, dst_mac, src_ip, dst_ip)) + send(self, vlan_port["port_index"], pkt) + + #-------------------------------------------------------------------------- + def verify_icmp_packets(self, vlan_port, vlan_id, + src_mac="00:22:00:00:00:02", dst_mac="00:22:00:00:00:01", + src_ip="192.168.0.1", dst_ip="192.168.0.2", ttl=64): + untagged_dst_ports = [] + tagged_dst_ports = [] + untagged_pkts = [] + tagged_pkts = [] + untagged_pkt = self.build_icmp_packet(0, src_mac, dst_mac, src_ip, dst_ip, ttl) + tagged_pkt = self.build_icmp_packet(vlan_id, src_mac, dst_mac, src_ip, dst_ip, ttl) + + for port in self.vlan_ports_list: + if vlan_port["port_index"] == port["port_index"]: + # Skip src port + continue + if port["pvid"] == vlan_id: + untagged_dst_ports.append(port["port_index"]) + untagged_pkts.append(untagged_pkt) + elif vlan_id in map(int, port["permit_vlanid"].keys()): + tagged_dst_ports.append(port["port_index"]) + tagged_pkts.append(tagged_pkt) + self.log("Verify untagged packets from ports " + str(untagged_dst_ports) + " tagged packets from ports " + str(tagged_dst_ports)) + verify_each_packet_on_each_port(self, untagged_pkts+tagged_pkts, untagged_dst_ports+tagged_dst_ports) + + #-------------------------------------------------------------------------- + def verify_icmp_packets_from_specified_port(self, port_id, vlan_id, + src_mac="00:22:00:00:00:02", dst_mac="00:22:00:00:00:01", + src_ip="192.168.0.1", dst_ip="192.168.0.2", ttl=64): + self.log("Verify packet from port " + str(port_id)) + pkt = self.build_icmp_packet(vlan_id, src_mac, dst_mac, src_ip, dst_ip, ttl) + verify_packet(self, pkt, port_id) + + #-------------------------------------------------------------------------- + def runTest(self): + vlan_ports_list = self.vlan_ports_list + vlan_intf_list = self.vlan_intf_list + + + # Test case #1 + self.log("Test case #1 starting ...") + + # Send untagged packets from each port. + # Verify packets egress without tag from ports whose PVID same with ingress port + # Verify packets egress with tag from ports who include VLAN ID but PVID different from ingress port. + for vlan_port in vlan_ports_list: + self.send_icmp_packet(vlan_port, 0) + self.verify_icmp_packets(vlan_port, vlan_port["pvid"]) + + # Test case #2 + self.log("Test case #2 starting ...") + # Send tagged packets from each port. + # Verify packets egress without tag from ports whose PVID same with ingress port + # Verify packets egress with tag from ports who include VLAN ID but PVID different from ingress port. + for vlan_port in vlan_ports_list: + for permit_vlanid in map(int, vlan_port["permit_vlanid"].keys()): + self.send_icmp_packet(vlan_port, permit_vlanid) + self.verify_icmp_packets(vlan_port, permit_vlanid) + + # Test case #3 + # Send packets with invalid VLAN ID + # Verify no port can receive these pacekts + self.log("Test case #3 starting ...") + invalid_tagged_pkt = self.build_icmp_packet(4095) + masked_invalid_tagged_pkt = Mask(invalid_tagged_pkt) + masked_invalid_tagged_pkt.set_do_not_care_scapy(scapy.Dot1Q, "vlan") + + for vlan_port in vlan_ports_list: + src_port = vlan_port["port_index"] + dst_ports = [port["port_index"] for port in vlan_ports_list + if port != vlan_port ] + self.log("Send invalid tagged packet " + " from " + str(src_port) + "...") + send(self, src_port, invalid_tagged_pkt) + self.log("Check on " + str(dst_ports) + "...") + verify_no_packet_any(self, masked_invalid_tagged_pkt, dst_ports) + + # Test case #4 + # Send packets over VLAN interfaces. + # Verify packets can be receive on the egress port. + self.log("Test case #4 starting ...") + + target_list = [] + for vlan_port in vlan_ports_list: + for vlan_id in vlan_port["permit_vlanid"].keys(): + item = {"vlan_id": int(vlan_id), "port_index": vlan_port["port_index"], + "peer_ip": vlan_port["permit_vlanid"][vlan_id]["peer_ip"], + "remote_ip": vlan_port["permit_vlanid"][vlan_id]["remote_ip"], + "pvid": vlan_port["pvid"]} + target_list.append(item) + + for vlan_port in vlan_ports_list: + src_port = vlan_port["port_index"] + src_mac = self.dataplane.get_mac(0, src_port) + dst_mac = self.router_mac + for vlan_id in map(int, vlan_port["permit_vlanid"].keys()): + # Test for for directly-connected routing + src_ip = vlan_port["permit_vlanid"][str(vlan_id)]["peer_ip"] + for target in target_list: + if vlan_id == target["vlan_id"]: + # Skip same VLAN forwarding + continue + self.send_icmp_packet(vlan_port, vlan_id if vlan_id != vlan_port["pvid"] else 0, + src_mac, dst_mac, src_ip, target["peer_ip"]) + self.verify_icmp_packets_from_specified_port(target["port_index"], + target["vlan_id"] if target["vlan_id"] != target["pvid"] else 0, + dst_mac, self.dataplane.get_mac(0, target["port_index"]), + src_ip, target["peer_ip"], 63) + # Test for for indirectly-connected routing + src_ip = vlan_port["permit_vlanid"][str(vlan_id)]["remote_ip"] + for target in target_list: + if vlan_id == target["vlan_id"]: + # Skip same VLAN forwarding + continue + self.send_icmp_packet(vlan_port, vlan_id if vlan_id != vlan_port["pvid"] else 0, + src_mac, dst_mac, src_ip, target["remote_ip"]) + self.verify_icmp_packets_from_specified_port(target["port_index"], + target["vlan_id"] if target["vlan_id"] != target["pvid"] else 0, + dst_mac, self.dataplane.get_mac(0, target["port_index"]), + src_ip, target["remote_ip"], 63) + + # Test case #5 + # Send ICMP packets to VLAN interfaces. + # Verify ICMP reply packets can be received from ingress port. + self.log("Test case #5 starting ...") + for vlan_port in vlan_ports_list: + src_port = vlan_port["port_index"] + src_mac = self.dataplane.get_mac(0, src_port) + dst_mac = self.router_mac + for vlan_id in map(int, vlan_port["permit_vlanid"].keys()): + src_ip = vlan_port["permit_vlanid"][str(vlan_id)]["peer_ip"] + for vlan_intf in vlan_intf_list: + if int(vlan_intf["vlan_id"]) != vlan_id: + continue + dst_ip = vlan_intf["ip"].split("/")[0] + self.send_icmp_packet(vlan_port, vlan_id if vlan_id != vlan_port["pvid"] else 0, + src_mac, dst_mac, src_ip, dst_ip) + exp_pkt = simple_icmp_packet(eth_src=self.router_mac, + eth_dst=src_mac, + dl_vlan_enable=True if vlan_id != vlan_port["pvid"] else False, + vlan_vid=vlan_id if vlan_id != vlan_port["pvid"] else 0, + vlan_pcp=0, + ip_dst=src_ip, + ip_src=dst_ip, + icmp_type=0, + icmp_code=0) + + masked_exp_pkt = Mask(exp_pkt) + masked_exp_pkt.set_do_not_care_scapy(scapy.IP, "id") + + verify_packets(self, masked_exp_pkt, list(str(src_port))) + #-------------------------------------------------------------------------- diff --git a/ansible/roles/test/tasks/sonic.yml b/ansible/roles/test/tasks/sonic.yml index d254ed6dbe2..2997e1e0394 100644 --- a/ansible/roles/test/tasks/sonic.yml +++ b/ansible/roles/test/tasks/sonic.yml @@ -33,6 +33,10 @@ include: interface.yml tags: always +- name: VLAN test + include: vlantb.yml + tags: vlan + - name: BGP facts test include: bgp_fact.yml tags: bgp_fact diff --git a/ansible/roles/test/tasks/vlan_cleanup.yml b/ansible/roles/test/tasks/vlan_cleanup.yml new file mode 100644 index 00000000000..f0cf41c6c9a --- /dev/null +++ b/ansible/roles/test/tasks/vlan_cleanup.yml @@ -0,0 +1,23 @@ +- name: Generate config_db.json + shell: sonic-cfggen -m /etc/sonic/minigraph.xml --print-data > /etc/sonic/config_db.json + become: true + +- name: Reboot is required for config_db.json change + shell: sleep 2 && shutdown -r now "Ansible change config_db.json file, triggerred reboot." + async: 1 + poll: 0 + become: true + ignore_errors: true + +- name: Waiting for switch to come back + local_action: + wait_for host={{ ansible_ssh_host }} + port=22 + state=started + delay=30 + timeout=300 + become: false + changed_when: false + +- name: sleep for some time + pause: seconds=60 diff --git a/ansible/roles/test/tasks/vlan_configure.yml b/ansible/roles/test/tasks/vlan_configure.yml new file mode 100644 index 00000000000..ce0a16c56b2 --- /dev/null +++ b/ansible/roles/test/tasks/vlan_configure.yml @@ -0,0 +1,79 @@ +- fail: msg="Please set ptf_host variable" + when: ptf_host is not defined + +- fail: msg="Invalid testbed_type value '{{testbed_type}}'" + when: testbed_type not in [ 't0' ] + + +- debug: var=minigraph_portchannels + +- debug: var=minigraph_port_indices + +- name: Generate VLAN ports information + template: src=roles/test/templates/vlan_info.j2 + dest=/tmp/vlan_info.yml + connection: local + +- name: Load VLAN ports info from file + include_vars: '/tmp/vlan_info.yml' + +- debug: var=vlan_ports_list +- debug: var=vlan_intf_list + +- name: Flush all IP addresses on the LAGs + shell: cfgmgr intf del {{ (item.addr ~ "/" ~ item.mask)|ipaddr()|upper() }} dev {{ item.attachto }} + with_items: + - "{{ minigraph_portchannel_interfaces }}" + become: true + +- name: Remove native VLAN members + shell: cfgmgr vlan del vlan 1000 dev {{ item.dev }} + with_items: "{{ vlan_ports_list }}" + become: true + +- name: Create VLAN interfaces + shell: cfgmgr vlan add vlan {{ item.vlan_id }} up + with_items: "{{ vlan_intf_list }}" + become: true + +- name: Add VLAN members + shell: cfgmgr vlan add vlan {{ item.1 }} dev {{ item.0.dev }} + with_nested: + - "{{ vlan_ports_list }}" + - "{{ vlan_ports_list[0].permit_vlanid.keys() }}" + become: true + +- name: Add native VLAN members + shell: cfgmgr vlan add vlan {{ item.pvid }} dev {{ item.dev }} untagged + with_items: "{{ vlan_ports_list }}" + become: true + +- name: Configure IP addresses on VLAN interfaces + shell: cfgmgr intf add {{ item.ip }} dev Vlan{{ item.vlan_id }} + with_items: "{{ vlan_intf_list }}" + become: true + +- name: Save configuration in config_db.json + shell: config save -y + become: true + +- name: Reboot is required for config_db.json change + shell: sleep 2 && shutdown -r now "Ansible change config_db.json file, triggered reboot." + async: 1 + poll: 0 + become: true + ignore_errors: true + +- name: waiting for switch to come back + local_action: + wait_for host={{ ansible_ssh_host }} + port=22 + state=started + delay=30 + timeout=300 + become: false + changed_when: false + +- name: sleep for some time + pause: seconds=60 + diff --git a/ansible/roles/test/tasks/vlan_test.yml b/ansible/roles/test/tasks/vlan_test.yml new file mode 100644 index 00000000000..dd5f8c7f46b --- /dev/null +++ b/ansible/roles/test/tasks/vlan_test.yml @@ -0,0 +1,44 @@ +- name: Configure route for remote IP + shell: ip route add {{ item[0].permit_vlanid[item[1]].remote_ip }} via {{ item[0].permit_vlanid[item[1]].peer_ip }} + with_nested: + - "{{ vlan_ports_list }}" + - "{{ vlan_ports_list[0].permit_vlanid.keys() }}" + become: true + +- name: Copy ARP responder to PTF + copy: src=roles/test/files/helpers/arp_responder.py dest=/opt + delegate_to: "{{ptf_host}}" + +- name: Copy arp responder supervisor configuration to the PTF container + template: src=arp_responder.conf.j2 dest=/etc/supervisor/conf.d/arp_responder.conf + vars: + - arp_responder_args: '' + delegate_to: "{{ ptf_host }}" + +- name: Reread supervisor configuration + shell: /usr/local/bin/supervisorctl reread + delegate_to: "{{ptf_host}}" + +- name: Update supervisor configuration + shell: /usr/local/bin/supervisorctl update + delegate_to: "{{ ptf_host }}" + +- name: Copy tests to the PTF container + copy: src=roles/test/files/ptftests dest=/root + delegate_to: "{{ ptf_host }}" + +- block: + - include: ptf_runner.yml + vars: + ptf_test_name: VLAN test + ptf_test_dir: ptftests + ptf_test_path: vlan_test.VlanTest + ptf_platform: remote + ptf_test_params: + - vlan_ports_list = \"{{ vlan_ports_list }}\" + - vlan_intf_list = \"{{ vlan_intf_list }}\" + - router_mac = \"{{ ansible_Ethernet0['macaddress'] }}\" + ptf_extra_options: "--relax --debug info --log-file /tmp/vlan_test.log" + rescue: + - debug: msg="PTF test raise error" + diff --git a/ansible/roles/test/tasks/vlantb.yml b/ansible/roles/test/tasks/vlantb.yml new file mode 100644 index 00000000000..e62d84f4581 --- /dev/null +++ b/ansible/roles/test/tasks/vlantb.yml @@ -0,0 +1,20 @@ +#----------------------------------------- +# Apply Vlan configuration +#----------------------------------------- +- name: Vlan test setup on testbed + include: vlan_configure.yml + tags: vlan_configure + +#----------------------------------------- +# Run Vlan test +#----------------------------------------- +- name: Vlan test run on testbed + include: vlan_test.yml + tags: vlan_test + +#----------------------------------------- +# Clean up Vlan configuration +#----------------------------------------- +- name: Clean up Vlan test configuration on the testbed + include: vlan_cleanup.yml + tags: vlan_cleanup diff --git a/ansible/roles/test/templates/vlan_info.j2 b/ansible/roles/test/templates/vlan_info.j2 new file mode 100644 index 00000000000..98a56ce43c9 --- /dev/null +++ b/ansible/roles/test/templates/vlan_info.j2 @@ -0,0 +1,34 @@ +--- + +{% set vlan_id_list = [ 100, 200 ] %} +vlan_ports_list: +{% for lag_number in range(2) %} + - dev: '{{ minigraph_portchannels.keys()[lag_number|int] }}' + port_index: '{{ minigraph_port_indices[minigraph_portchannels[minigraph_portchannels.keys()[lag_number|int]].members[0]] }}' + pvid: '{{ vlan_id_list[(lag_number|int)%2] }}' + permit_vlanid: +{% for vlan in vlan_id_list %} + '{{ vlan }}': + peer_ip: '192.168.{{ vlan }}.{{ minigraph_port_indices[minigraph_portchannels[minigraph_portchannels.keys()[lag_number|int]].members[0]] }}' + remote_ip: '{{vlan}}.1.1.{{ minigraph_port_indices[minigraph_portchannels[minigraph_portchannels.keys()[lag_number|int]].members[0]] }}' +{% endfor %} +{% endfor %} +{% for port_number in range(2) %} + - dev: '{{ minigraph_ports.keys()[port_number|int]}}' + port_index: '{{ minigraph_port_indices[minigraph_ports.keys()[port_number|int]]}}' + pvid: '{{ ((port_number|int)%2+1)*100}}' + permit_vlanid: +{% for vlan in ['100', '200'] %} + '{{ vlan }}': + peer_ip: '192.168.{{ vlan }}.{{ minigraph_port_indices[minigraph_ports.keys()[port_number|int]] }}' + remote_ip: '{{vlan}}.1.1.{{ minigraph_port_indices[minigraph_ports.keys()[port_number|int]] }}' +{% endfor %} +{% endfor %} + +vlan_intf_list: +{% for vlan in vlan_id_list %} + - vlan_id: '{{ (vlan|int) }}' + ip: '192.168.{{ vlan }}.1/24' +{% endfor %} + +... From 94a9f04caaa6b49f82934a710f11271e2615a494 Mon Sep 17 00:00:00 2001 From: Judong Date: Wed, 6 Dec 2017 15:33:49 +0800 Subject: [PATCH 2/7] [VLAN test] use new VLAN command instead of cfgmgr --- ansible/roles/test/tasks/vlan_cleanup.yml | 4 +-- ansible/roles/test/tasks/vlan_configure.yml | 28 ++++++++++++++------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/ansible/roles/test/tasks/vlan_cleanup.yml b/ansible/roles/test/tasks/vlan_cleanup.yml index f0cf41c6c9a..8ba5fc61384 100644 --- a/ansible/roles/test/tasks/vlan_cleanup.yml +++ b/ansible/roles/test/tasks/vlan_cleanup.yml @@ -1,5 +1,5 @@ -- name: Generate config_db.json - shell: sonic-cfggen -m /etc/sonic/minigraph.xml --print-data > /etc/sonic/config_db.json +- name: Restore config_db.json + shell: mv /etc/sonic/config_db_bak.json /etc/sonic/config_db.json become: true - name: Reboot is required for config_db.json change diff --git a/ansible/roles/test/tasks/vlan_configure.yml b/ansible/roles/test/tasks/vlan_configure.yml index ce0a16c56b2..98a1cf31090 100644 --- a/ansible/roles/test/tasks/vlan_configure.yml +++ b/ansible/roles/test/tasks/vlan_configure.yml @@ -4,7 +4,6 @@ - fail: msg="Invalid testbed_type value '{{testbed_type}}'" when: testbed_type not in [ 't0' ] - - debug: var=minigraph_portchannels - debug: var=minigraph_port_indices @@ -21,38 +20,49 @@ - debug: var=vlan_intf_list - name: Flush all IP addresses on the LAGs - shell: cfgmgr intf del {{ (item.addr ~ "/" ~ item.mask)|ipaddr()|upper() }} dev {{ item.attachto }} + shell: ip addr flush {{ item.attachto }} with_items: - "{{ minigraph_portchannel_interfaces }}" become: true -- name: Remove native VLAN members - shell: cfgmgr vlan del vlan 1000 dev {{ item.dev }} - with_items: "{{ vlan_ports_list }}" +- name: Delete all IP addresses on the LAGs in config DB + shell: docker exec -i database redis-cli -n 4 del "PORTCHANNEL_INTERFACE|{{ item.attachto }}|{{ (item.addr ~ '/' ~ item.mask)|ipaddr()|upper() }}" + with_items: + - "{{ minigraph_portchannel_interfaces }}" become: true - name: Create VLAN interfaces - shell: cfgmgr vlan add vlan {{ item.vlan_id }} up + shell: config vlan add {{ item.vlan_id}} with_items: "{{ vlan_intf_list }}" become: true - name: Add VLAN members - shell: cfgmgr vlan add vlan {{ item.1 }} dev {{ item.0.dev }} + shell: config vlan member add {{ item.1 }} {{ item.0.dev }} with_nested: - "{{ vlan_ports_list }}" - "{{ vlan_ports_list[0].permit_vlanid.keys() }}" + when: item.1 != item.0.pvid become: true - name: Add native VLAN members - shell: cfgmgr vlan add vlan {{ item.pvid }} dev {{ item.dev }} untagged + shell: config vlan member add {{ item.pvid }} {{ item.dev }} -u with_items: "{{ vlan_ports_list }}" become: true - name: Configure IP addresses on VLAN interfaces - shell: cfgmgr intf add {{ item.ip }} dev Vlan{{ item.vlan_id }} + shell: ip addr add {{ item.ip }} dev Vlan{{ item.vlan_id }} + with_items: "{{ vlan_intf_list }}" + become: true + +- name: Configure IP addresses on VLAN interfaces + shell: docker exec -i database redis-cli -n 4 hset "VLAN_INTERFACE|Vlan{{ item.vlan_id }}|{{ item.ip }}" NULL NULL with_items: "{{ vlan_intf_list }}" become: true +- name: Backup original configuration + shell: cp /etc/sonic/config_db.json /etc/sonic/config_db_bak.json + become: true + - name: Save configuration in config_db.json shell: config save -y become: true From 52d56bc2b3643c9c8baf9d1fabd79e84ae33188b Mon Sep 17 00:00:00 2001 From: Judong Date: Fri, 8 Dec 2017 11:37:59 +0800 Subject: [PATCH 3/7] [VLAN test] Add command line how to run test in README.test.md --- ansible/README.test.md | 7 +++++++ ansible/roles/test/tasks/vlan_configure.yml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ansible/README.test.md b/ansible/README.test.md index c3ac324a06c..d33d8b1eca4 100644 --- a/ansible/README.test.md +++ b/ansible/README.test.md @@ -129,3 +129,10 @@ ansible-playbook test_sonic.yml -i inventory --limit {DUT_NAME} --tags bgp_multi This test only works for T1 related topologies(t1, t1-lag, ...) You might need to redeploy your VMs before you run this test due to the change for ToR VM router configuration changes `./testbed-cli.sh config-vm your-topo-name(vms1-1) your-vm-name(VM0108)` will do this for you + +### VLAN test +``` +ansible-playbook test_sonic.yml -i inventory --limit {DUT_NAME} --become --tags vlan --extra-vars "testbed_type={TESTBED_TYPE} ptf_host={PTF_HOST}" +- Requires switch connected to a t0 testbed +- Requires switch connected to fanout switch and fanout switch need support [QinQ](https://en.wikipedia.org/wiki/IEEE_802.1ad). +``` diff --git a/ansible/roles/test/tasks/vlan_configure.yml b/ansible/roles/test/tasks/vlan_configure.yml index 98a1cf31090..f3f68ee3271 100644 --- a/ansible/roles/test/tasks/vlan_configure.yml +++ b/ansible/roles/test/tasks/vlan_configure.yml @@ -54,7 +54,7 @@ with_items: "{{ vlan_intf_list }}" become: true -- name: Configure IP addresses on VLAN interfaces +- name: Configure IP addresses on VLAN interfaces in Config DB shell: docker exec -i database redis-cli -n 4 hset "VLAN_INTERFACE|Vlan{{ item.vlan_id }}|{{ item.ip }}" NULL NULL with_items: "{{ vlan_intf_list }}" become: true From f3f5aa6782e21237125387fcf2069e94b0fec022 Mon Sep 17 00:00:00 2001 From: Judong Date: Fri, 8 Dec 2017 11:44:15 +0800 Subject: [PATCH 4/7] [VLAN test] fix VLAN test wrong format in README.test.md --- ansible/README.test.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible/README.test.md b/ansible/README.test.md index d33d8b1eca4..34354c1edd8 100644 --- a/ansible/README.test.md +++ b/ansible/README.test.md @@ -133,6 +133,6 @@ You might need to redeploy your VMs before you run this test due to the change f ### VLAN test ``` ansible-playbook test_sonic.yml -i inventory --limit {DUT_NAME} --become --tags vlan --extra-vars "testbed_type={TESTBED_TYPE} ptf_host={PTF_HOST}" +``` - Requires switch connected to a t0 testbed - Requires switch connected to fanout switch and fanout switch need support [QinQ](https://en.wikipedia.org/wiki/IEEE_802.1ad). -``` From 3fde3601c03d98cceaa2e053259cad8173796891 Mon Sep 17 00:00:00 2001 From: Judong Date: Mon, 11 Dec 2017 19:35:51 +0800 Subject: [PATCH 5/7] [VLAN test] modify according to the review --- .../roles/test/files/ptftests/vlan_test.py | 52 ++++++++-------- ansible/roles/test/tasks/vlan_cleanup.yml | 34 +++++----- ansible/roles/test/tasks/vlan_configure.yml | 62 +++++-------------- ansible/roles/test/tasks/vlan_test.yml | 5 +- .../test/templates/vlan_configuration.j2 | 29 +++++++++ ansible/roles/test/templates/vlan_info.j2 | 27 ++++---- 6 files changed, 104 insertions(+), 105 deletions(-) create mode 100644 ansible/roles/test/templates/vlan_configuration.j2 diff --git a/ansible/roles/test/files/ptftests/vlan_test.py b/ansible/roles/test/files/ptftests/vlan_test.py index b7f2daee07a..fdd1ee616d9 100644 --- a/ansible/roles/test/files/ptftests/vlan_test.py +++ b/ansible/roles/test/files/ptftests/vlan_test.py @@ -92,7 +92,7 @@ def tearDown(self): #-------------------------------------------------------------------------- def build_icmp_packet(self, vlan_id, - src_mac="00:22:00:00:00:02", dst_mac="00:22:00:00:00:01", + src_mac="00:22:00:00:00:02", dst_mac="ff:ff:ff:ff:ff:ff", src_ip="192.168.0.1", dst_ip="192.168.0.2", ttl=64): pkt = simple_icmp_packet(pktlen=100 if vlan_id == 0 else 104, eth_dst=dst_mac, @@ -107,25 +107,13 @@ def build_icmp_packet(self, vlan_id, #-------------------------------------------------------------------------- - def send_icmp_packet(self, vlan_port, vlan_id=0, - src_mac="00:22:00:00:00:02", dst_mac="00:22:00:00:00:01", - src_ip="192.168.0.1", dst_ip="192.168.0.2", ttl=64): - pkt = self.build_icmp_packet(vlan_id, src_mac, dst_mac, src_ip, dst_ip, ttl) - self.log("Send " + ("untagged" if vlan_id == 0 else "tagged(%d)"%vlan_id) - + " packet from " + str(vlan_port["port_index"]) + "...") - self.log("%s -> %s, %s -> %s"%(src_mac, dst_mac, src_ip, dst_ip)) - send(self, vlan_port["port_index"], pkt) - - #-------------------------------------------------------------------------- - def verify_icmp_packets(self, vlan_port, vlan_id, - src_mac="00:22:00:00:00:02", dst_mac="00:22:00:00:00:01", - src_ip="192.168.0.1", dst_ip="192.168.0.2", ttl=64): + def verify_icmp_packets(self, vlan_port, vlan_id): untagged_dst_ports = [] tagged_dst_ports = [] untagged_pkts = [] tagged_pkts = [] - untagged_pkt = self.build_icmp_packet(0, src_mac, dst_mac, src_ip, dst_ip, ttl) - tagged_pkt = self.build_icmp_packet(vlan_id, src_mac, dst_mac, src_ip, dst_ip, ttl) + untagged_pkt = self.build_icmp_packet(0) + tagged_pkt = self.build_icmp_packet(vlan_id) for port in self.vlan_ports_list: if vlan_port["port_index"] == port["port_index"]: @@ -141,9 +129,7 @@ def verify_icmp_packets(self, vlan_port, vlan_id, verify_each_packet_on_each_port(self, untagged_pkts+tagged_pkts, untagged_dst_ports+tagged_dst_ports) #-------------------------------------------------------------------------- - def verify_icmp_packets_from_specified_port(self, port_id, vlan_id, - src_mac="00:22:00:00:00:02", dst_mac="00:22:00:00:00:01", - src_ip="192.168.0.1", dst_ip="192.168.0.2", ttl=64): + def verify_icmp_packets_from_specified_port(self, port_id, vlan_id, src_mac, dst_mac, src_ip, dst_ip, ttl): self.log("Verify packet from port " + str(port_id)) pkt = self.build_icmp_packet(vlan_id, src_mac, dst_mac, src_ip, dst_ip, ttl) verify_packet(self, pkt, port_id) @@ -156,12 +142,14 @@ def runTest(self): # Test case #1 self.log("Test case #1 starting ...") - # Send untagged packets from each port. # Verify packets egress without tag from ports whose PVID same with ingress port # Verify packets egress with tag from ports who include VLAN ID but PVID different from ingress port. for vlan_port in vlan_ports_list: - self.send_icmp_packet(vlan_port, 0) + pkt = self.build_icmp_packet(0) + self.log("Send untagged packet from {} ...".format(str(vlan_port["port_index"]))) + self.log(pkt.sprintf("%Ether.src% %IP.src% -> %Ether.dst% %IP.dst%")) + send(self, vlan_port["port_index"], pkt) self.verify_icmp_packets(vlan_port, vlan_port["pvid"]) # Test case #2 @@ -171,7 +159,10 @@ def runTest(self): # Verify packets egress with tag from ports who include VLAN ID but PVID different from ingress port. for vlan_port in vlan_ports_list: for permit_vlanid in map(int, vlan_port["permit_vlanid"].keys()): - self.send_icmp_packet(vlan_port, permit_vlanid) + pkt = self.build_icmp_packet(permit_vlanid) + self.log("Send tagged({}) packet from {} ...".format(permit_vlanid, str(vlan_port["port_index"]))) + self.log(pkt.sprintf("%Ether.src% %IP.src% -> %Ether.dst% %IP.dst%")) + send(self, vlan_port["port_index"], pkt) self.verify_icmp_packets(vlan_port, permit_vlanid) # Test case #3 @@ -187,6 +178,7 @@ def runTest(self): dst_ports = [port["port_index"] for port in vlan_ports_list if port != vlan_port ] self.log("Send invalid tagged packet " + " from " + str(src_port) + "...") + self.log(invalid_tagged_pkt.sprintf("%Ether.src% %IP.src% -> %Ether.dst% %IP.dst%")) send(self, src_port, invalid_tagged_pkt) self.log("Check on " + str(dst_ports) + "...") verify_no_packet_any(self, masked_invalid_tagged_pkt, dst_ports) @@ -216,8 +208,11 @@ def runTest(self): if vlan_id == target["vlan_id"]: # Skip same VLAN forwarding continue - self.send_icmp_packet(vlan_port, vlan_id if vlan_id != vlan_port["pvid"] else 0, + pkt = self.build_icmp_packet(vlan_id if vlan_id != vlan_port["pvid"] else 0, src_mac, dst_mac, src_ip, target["peer_ip"]) + send(self, src_port, pkt) + self.log("Send {} packet from {} ...".format("untagged" if vlan_id == 0 else "tagged(%d)"%vlan_id, src_port)) + self.log(pkt.sprintf("%Ether.src% %IP.src% -> %Ether.dst% %IP.dst%")) self.verify_icmp_packets_from_specified_port(target["port_index"], target["vlan_id"] if target["vlan_id"] != target["pvid"] else 0, dst_mac, self.dataplane.get_mac(0, target["port_index"]), @@ -228,8 +223,11 @@ def runTest(self): if vlan_id == target["vlan_id"]: # Skip same VLAN forwarding continue - self.send_icmp_packet(vlan_port, vlan_id if vlan_id != vlan_port["pvid"] else 0, + pkt = self.build_icmp_packet(vlan_id if vlan_id != vlan_port["pvid"] else 0, src_mac, dst_mac, src_ip, target["remote_ip"]) + self.log("Send {} packet from {} ...".format("untagged" if vlan_id == 0 else "tagged(%d)"%vlan_id, src_port)) + self.log(pkt.sprintf("%Ether.src% %IP.src% -> %Ether.dst% %IP.dst%")) + send(self, src_port, pkt) self.verify_icmp_packets_from_specified_port(target["port_index"], target["vlan_id"] if target["vlan_id"] != target["pvid"] else 0, dst_mac, self.dataplane.get_mac(0, target["port_index"]), @@ -249,8 +247,11 @@ def runTest(self): if int(vlan_intf["vlan_id"]) != vlan_id: continue dst_ip = vlan_intf["ip"].split("/")[0] - self.send_icmp_packet(vlan_port, vlan_id if vlan_id != vlan_port["pvid"] else 0, + pkt = self.build_icmp_packet(vlan_id if vlan_id != vlan_port["pvid"] else 0, src_mac, dst_mac, src_ip, dst_ip) + self.log("Send {} packet from {} ...".format("untagged" if vlan_id == 0 else "tagged(%d)"%vlan_id, src_port)) + self.log(pkt.sprintf("%Ether.src% %IP.src% -> %Ether.dst% %IP.dst%")) + send(self, src_port, pkt) exp_pkt = simple_icmp_packet(eth_src=self.router_mac, eth_dst=src_mac, dl_vlan_enable=True if vlan_id != vlan_port["pvid"] else False, @@ -265,4 +266,5 @@ def runTest(self): masked_exp_pkt.set_do_not_care_scapy(scapy.IP, "id") verify_packets(self, masked_exp_pkt, list(str(src_port))) + self.log("Verify packet from port " + str(src_port)) #-------------------------------------------------------------------------- diff --git a/ansible/roles/test/tasks/vlan_cleanup.yml b/ansible/roles/test/tasks/vlan_cleanup.yml index 8ba5fc61384..e71d0c1fcae 100644 --- a/ansible/roles/test/tasks/vlan_cleanup.yml +++ b/ansible/roles/test/tasks/vlan_cleanup.yml @@ -1,23 +1,21 @@ -- name: Restore config_db.json - shell: mv /etc/sonic/config_db_bak.json /etc/sonic/config_db.json +- name: Restore all IP addresses on the LAGs + shell: ip addr add {{ (item.addr ~ "/" ~ item.mask)|ipaddr() }} dev {{ item.attachto }} + with_items: + - "{{ minigraph_portchannel_interfaces }}" become: true -- name: Reboot is required for config_db.json change - shell: sleep 2 && shutdown -r now "Ansible change config_db.json file, triggerred reboot." - async: 1 - poll: 0 +- name: Bring up LAGs + shell: ifconfig {{ item.attachto }} up + with_items: + - "{{ minigraph_portchannel_interfaces }}" become: true - ignore_errors: true -- name: Waiting for switch to come back - local_action: - wait_for host={{ ansible_ssh_host }} - port=22 - state=started - delay=30 - timeout=300 - become: false - changed_when: false +- name: Remove configuration for test + file: + state: absent + path: /etc/sonic/vlan_configuration.json + become: true -- name: sleep for some time - pause: seconds=60 +- name: Reload configuration + shell: config reload -y + become: true diff --git a/ansible/roles/test/tasks/vlan_configure.yml b/ansible/roles/test/tasks/vlan_configure.yml index f3f68ee3271..d8957746223 100644 --- a/ansible/roles/test/tasks/vlan_configure.yml +++ b/ansible/roles/test/tasks/vlan_configure.yml @@ -8,6 +8,8 @@ - debug: var=minigraph_port_indices +- debug: var=minigraph_ports + - name: Generate VLAN ports information template: src=roles/test/templates/vlan_info.j2 dest=/tmp/vlan_info.yml @@ -31,59 +33,23 @@ - "{{ minigraph_portchannel_interfaces }}" become: true -- name: Create VLAN interfaces - shell: config vlan add {{ item.vlan_id}} - with_items: "{{ vlan_intf_list }}" - become: true - -- name: Add VLAN members - shell: config vlan member add {{ item.1 }} {{ item.0.dev }} - with_nested: - - "{{ vlan_ports_list }}" - - "{{ vlan_ports_list[0].permit_vlanid.keys() }}" - when: item.1 != item.0.pvid - become: true - -- name: Add native VLAN members - shell: config vlan member add {{ item.pvid }} {{ item.dev }} -u - with_items: "{{ vlan_ports_list }}" - become: true - -- name: Configure IP addresses on VLAN interfaces - shell: ip addr add {{ item.ip }} dev Vlan{{ item.vlan_id }} - with_items: "{{ vlan_intf_list }}" - become: true - -- name: Configure IP addresses on VLAN interfaces in Config DB - shell: docker exec -i database redis-cli -n 4 hset "VLAN_INTERFACE|Vlan{{ item.vlan_id }}|{{ item.ip }}" NULL NULL - with_items: "{{ vlan_intf_list }}" +- name: Shutdown LAGs + shell: ifconfig {{ item.attachto }} down + with_items: + - "{{ minigraph_portchannel_interfaces }}" become: true -- name: Backup original configuration - shell: cp /etc/sonic/config_db.json /etc/sonic/config_db_bak.json - become: true +- name: sleep for some time + pause: seconds=10 -- name: Save configuration in config_db.json - shell: config save -y +- name: Generate nessesary configuration for test + template: src=roles/test/templates/vlan_configuration.j2 + dest=/etc/sonic/vlan_configuration.json become: true -- name: Reboot is required for config_db.json change - shell: sleep 2 && shutdown -r now "Ansible change config_db.json file, triggered reboot." - async: 1 - poll: 0 +- name: Load configuration + shell: config load -y /etc/sonic/vlan_configuration.json become: true - ignore_errors: true - -- name: waiting for switch to come back - local_action: - wait_for host={{ ansible_ssh_host }} - port=22 - state=started - delay=30 - timeout=300 - become: false - changed_when: false - name: sleep for some time - pause: seconds=60 - + pause: seconds=10 diff --git a/ansible/roles/test/tasks/vlan_test.yml b/ansible/roles/test/tasks/vlan_test.yml index dd5f8c7f46b..0f4ce39c431 100644 --- a/ansible/roles/test/tasks/vlan_test.yml +++ b/ansible/roles/test/tasks/vlan_test.yml @@ -5,6 +5,10 @@ - "{{ vlan_ports_list[0].permit_vlanid.keys() }}" become: true +- name: Set unique MACs to PTF interfaces + script: roles/test/files/helpers/change_mac.sh + delegate_to: "{{ptf_host}}" + - name: Copy ARP responder to PTF copy: src=roles/test/files/helpers/arp_responder.py dest=/opt delegate_to: "{{ptf_host}}" @@ -41,4 +45,3 @@ ptf_extra_options: "--relax --debug info --log-file /tmp/vlan_test.log" rescue: - debug: msg="PTF test raise error" - diff --git a/ansible/roles/test/templates/vlan_configuration.j2 b/ansible/roles/test/templates/vlan_configuration.j2 new file mode 100644 index 00000000000..bbdb2026b5e --- /dev/null +++ b/ansible/roles/test/templates/vlan_configuration.j2 @@ -0,0 +1,29 @@ +{ + "PORTCHANNEL_INTERFACE": {}, + "VLAN": { +{% for vlan_intf in vlan_intf_list %} + "Vlan{{ vlan_intf.vlan_id }}": { + "vlanid": {{ vlan_intf.vlan_id }} + }{{ "," if not loop.last else "" }} +{% endfor %} + }, + "VLAN_INTERFACE": { +{% for vlan_intf in vlan_intf_list %} + "Vlan{{ vlan_intf.vlan_id }}|{{ vlan_intf.ip }}": {}{{ "," if not loop.last else "" }} +{% endfor %} + }, + "VLAN_MEMBER": { +{% for vlan_port in vlan_ports_list %} +{% set outer_loop = loop %} +{% for permit_vlanid in vlan_port['permit_vlanid'].keys() %} + "Vlan{{ permit_vlanid }}|{{ vlan_port['dev'] }}": { +{% if vlan_port['pvid'] == permit_vlanid %} + "tagging_mode": "untagged" +{% else %} + "tagging_mode": "tagged" +{% endif %} + }{{ "," if not outer_loop.last or not loop.last else "" }} +{% endfor %} +{% endfor %} + } +} diff --git a/ansible/roles/test/templates/vlan_info.j2 b/ansible/roles/test/templates/vlan_info.j2 index 98a56ce43c9..0ceb3ba6768 100644 --- a/ansible/roles/test/templates/vlan_info.j2 +++ b/ansible/roles/test/templates/vlan_info.j2 @@ -2,26 +2,27 @@ {% set vlan_id_list = [ 100, 200 ] %} vlan_ports_list: -{% for lag_number in range(2) %} - - dev: '{{ minigraph_portchannels.keys()[lag_number|int] }}' - port_index: '{{ minigraph_port_indices[minigraph_portchannels[minigraph_portchannels.keys()[lag_number|int]].members[0]] }}' - pvid: '{{ vlan_id_list[(lag_number|int)%2] }}' +{% for portchannel in minigraph_portchannels.keys()[:2] %} +{% set members = minigraph_portchannels[portchannel].members %} + - dev: {{ portchannel }} + port_index: {{ minigraph_port_indices[members[0]] }} + pvid: '{{ vlan_id_list[loop.index0%2] }}' permit_vlanid: {% for vlan in vlan_id_list %} '{{ vlan }}': - peer_ip: '192.168.{{ vlan }}.{{ minigraph_port_indices[minigraph_portchannels[minigraph_portchannels.keys()[lag_number|int]].members[0]] }}' - remote_ip: '{{vlan}}.1.1.{{ minigraph_port_indices[minigraph_portchannels[minigraph_portchannels.keys()[lag_number|int]].members[0]] }}' + peer_ip: '192.168.{{ vlan }}.{{ 1 + minigraph_port_indices.keys().index(members[0]) }}' + remote_ip: '{{vlan}}.1.1.{{ 1 + minigraph_port_indices.keys().index(members[0]) }}' {% endfor %} {% endfor %} -{% for port_number in range(2) %} - - dev: '{{ minigraph_ports.keys()[port_number|int]}}' - port_index: '{{ minigraph_port_indices[minigraph_ports.keys()[port_number|int]]}}' - pvid: '{{ ((port_number|int)%2+1)*100}}' +{% for port in minigraph_ports.keys()[:2] %} + - dev: {{ port }} + port_index: '{{ minigraph_port_indices[port]}}' + pvid: '{{ vlan_id_list[loop.index0%2] }}' permit_vlanid: -{% for vlan in ['100', '200'] %} +{% for vlan in vlan_id_list %} '{{ vlan }}': - peer_ip: '192.168.{{ vlan }}.{{ minigraph_port_indices[minigraph_ports.keys()[port_number|int]] }}' - remote_ip: '{{vlan}}.1.1.{{ minigraph_port_indices[minigraph_ports.keys()[port_number|int]] }}' + peer_ip: '192.168.{{ vlan }}.{{ 1 + minigraph_port_indices.keys().index(port) }}' + remote_ip: '{{vlan}}.1.1.{{ 1 + minigraph_port_indices.keys().index(port) }}' {% endfor %} {% endfor %} From 28f4469cd97b3f124821b80980d3248329e7fea7 Mon Sep 17 00:00:00 2001 From: Judong Date: Tue, 12 Dec 2017 17:09:39 +0800 Subject: [PATCH 6/7] [VLAN test] start arp_responder after interface created and stop before interface deleted --- ansible/roles/test/files/ptftests/vlan_test.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ansible/roles/test/files/ptftests/vlan_test.py b/ansible/roles/test/files/ptftests/vlan_test.py index fdd1ee616d9..c7a01c9eb82 100644 --- a/ansible/roles/test/files/ptftests/vlan_test.py +++ b/ansible/roles/test/files/ptftests/vlan_test.py @@ -44,11 +44,8 @@ def setUp(self): self.dataplane = ptf.dataplane_instance self.test_params = test_params_get() - self.setUpArpResponder() - self.log("Start arp_responder") - self.shell(["supervisorctl", "start", "arp_responder"]) - self.log("Create VLAN intf") + for vlan_port in self.vlan_ports_list: for permit_vlanid in vlan_port["permit_vlanid"].keys(): if int(permit_vlanid) != vlan_port["pvid"]: @@ -58,6 +55,10 @@ def setUp(self): self.shell(["ip", "link", "set", "eth%d.%s"%(vlan_port["port_index"], permit_vlanid), "up"]) + self.setUpArpResponder() + self.log("Start arp_responder") + self.shell(["supervisorctl", "start", "arp_responder"]) + logging.info("VLAN test starting ...") pass #-------------------------------------------------------------------------- @@ -79,15 +80,15 @@ def setUpArpResponder(self): def tearDown(self): logging.info("VLAN test ending ...") + self.log("Stop arp_responder") + self.shell(["supervisorctl", "stop", "arp_responder"]) + self.log("Delete VLAN intf") for vlan_port in self.vlan_ports_list: for permit_vlanid in vlan_port["permit_vlanid"].keys(): if int(permit_vlanid) != vlan_port["pvid"]: self.shell(["ip", "link", "delete", "eth%d.%d"%(vlan_port["port_index"], int(permit_vlanid))]) - self.log("Stop arp_responder") - self.shell(["supervisorctl", "stop", "arp_responder"]) - pass #-------------------------------------------------------------------------- From 6c97f0b5e4aac3ccc29a448aaa369e896da4cab2 Mon Sep 17 00:00:00 2001 From: Judong Date: Wed, 13 Dec 2017 15:27:13 +0800 Subject: [PATCH 7/7] [VLAN test] Fix peer_ip may conflict with VLAN interface IP --- ansible/roles/test/templates/vlan_info.j2 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ansible/roles/test/templates/vlan_info.j2 b/ansible/roles/test/templates/vlan_info.j2 index 0ceb3ba6768..dec14186944 100644 --- a/ansible/roles/test/templates/vlan_info.j2 +++ b/ansible/roles/test/templates/vlan_info.j2 @@ -10,8 +10,8 @@ vlan_ports_list: permit_vlanid: {% for vlan in vlan_id_list %} '{{ vlan }}': - peer_ip: '192.168.{{ vlan }}.{{ 1 + minigraph_port_indices.keys().index(members[0]) }}' - remote_ip: '{{vlan}}.1.1.{{ 1 + minigraph_port_indices.keys().index(members[0]) }}' + peer_ip: '192.168.{{ vlan }}.{{ 2 + minigraph_port_indices.keys().index(members[0]) }}' + remote_ip: '{{vlan}}.1.1.{{ 2 + minigraph_port_indices.keys().index(members[0]) }}' {% endfor %} {% endfor %} {% for port in minigraph_ports.keys()[:2] %} @@ -21,8 +21,8 @@ vlan_ports_list: permit_vlanid: {% for vlan in vlan_id_list %} '{{ vlan }}': - peer_ip: '192.168.{{ vlan }}.{{ 1 + minigraph_port_indices.keys().index(port) }}' - remote_ip: '{{vlan}}.1.1.{{ 1 + minigraph_port_indices.keys().index(port) }}' + peer_ip: '192.168.{{ vlan }}.{{ 2 + minigraph_port_indices.keys().index(port) }}' + remote_ip: '{{vlan}}.1.1.{{ 2 + minigraph_port_indices.keys().index(port) }}' {% endfor %} {% endfor %}