diff --git a/ansible/roles/test/tasks/bgp_speaker.yml b/ansible/roles/test/tasks/bgp_speaker.yml index a885fe71ad..a40c865063 100644 --- a/ansible/roles/test/tasks/bgp_speaker.yml +++ b/ansible/roles/test/tasks/bgp_speaker.yml @@ -2,215 +2,216 @@ # Run BGP Speaker test #======================================== -- fail: msg="Information about tested missing" - when: (testbed_type is not defined or ptf_host is not defined) +- block: + - fail: msg="Information about tested missing" + when: (testbed_type is not defined or ptf_host is not defined) -- fail: msg="Invalid testbed_type value '{{testbed_type}}'" - when: testbed_type not in ['t0', 't0-64', 't0-116'] + - fail: msg="Invalid testbed_type value '{{testbed_type}}'" + when: testbed_type not in ['t0', 't0-64', 't0-116'] -- name: Gather minigraph facts about the device - minigraph_facts: host={{inventory_hostname}} - become: no - connection: local - -- name: print deployment id - debug: msg="{{deployment_id}}" - -- name: fetch bgp speaker asn number from DUT - shell: sonic-cfggen -m -d -y /etc/sonic/deployment_id_asn_map.yml -v "deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']]" - register: cfggen_out - -- name: set bgp speaker asn number - set_fact: - bgp_speaker_asn={{cfggen_out.stdout}} - -- set_fact: addr_family='ipv4' - when: addr_family is not defined - -- set_fact: portchannel_name="{{minigraph_portchannel_interfaces[0].attachto}}" - when: addr_family == 'ipv6' - -- name: print bgp speaker asn number - debug: msg="{{bgp_speaker_asn}}" - -- name: Generate three ips in VLAN range - get_ip_in_range: num=3 prefix="{{minigraph_vlan_interfaces[0]['addr']}}/{{minigraph_vlan_interfaces[0]['prefixlen']}}" exclude_ips="{{minigraph_vlan_interfaces[0]['addr']}}" - become: no - connection: local - failed_when: False - -- name: Store the value of VLAN IPs - set_fact: - vlan_ips={{generated_ips}} - -- debug: msg="{{generated_ips}}" - -- name: Generate two ips in bgp speaker peer range - get_ip_in_range: num=2 prefix={{minigraph_bgp_peers_with_range[0]['ip_range'][0]}} - become: no - connection: local - -- name: Set the value of ips in bgp speaker peer range - set_fact: speaker_ips={{generated_ips}} - -- name: Flush vlan ips route - command: ip route flush {{item.split('/')[0]}}/32 - when: addr_family == 'ipv4' - become: yes - with_items: "{{vlan_ips}}" - -- name: Add vlan ips route - command: ip route add {{item.split('/')[0]}}/32 dev {{minigraph_vlan_interfaces[0]['attachto']}} - when: addr_family == 'ipv4' - become: yes - with_items: "{{vlan_ips}}" - -- debug: msg="{{generated_ips}}" - -# vlan_ips[0], speaker_ips[0], speaker_ips[1] are IPs for three bgp speakers -# vlan_ips[1], vlan_ips[2] are IPs for mux under DUT. - -- name: set exabgp folder name - set_fact: - exabgp_dir="/root/exabgp" - -- name: Create directory /exabgp to store exabgp related files. - file: path={{exabgp_dir}} state=directory - delegate_to: "{{ptf_host}}" - -- name: Copy helper files to ptf container - copy: src=roles/test/files/helpers dest=/root - delegate_to: "{{ptf_host}}" - -- name: set exabgp folder name - set_fact: - helper_dir="/root/helpers" - -- name: Generate configurations for exabgp instances - template: src=roles/test/templates/exabgp/config.j2 dest={{exabgp_dir}}/{{item.file_name}} - with_items: - - {file_name: "config_1.ini", local_ip: '{{speaker_ips[0]}}', port_num: '5000'} - - {file_name: "config_2.ini", local_ip: '{{speaker_ips[1]}}', port_num: '6000'} - - {file_name: "config_3.ini", local_ip: '{{vlan_ips[0]}}', port_num: '7000'} - delegate_to: "{{ptf_host}}" - -- set_fact: portchannel_peer="{%for p in minigraph_portchannel_interfaces%}{%if p['attachto']==portchannel_name and p['peer_addr']|ipv6%}{{p['peer_addr']}}{%endif %}{%endfor%}" - when: addr_family == 'ipv6' - -- set_fact: mux_ip_1="{% if addr_family=='ipv4' %}{{vlan_ips[1]}}{% else %}{{portchannel_peer}}{% endif %}" -- set_fact: mux_ip_2="{% if addr_family=='ipv4' %}{{vlan_ips[2]}}{% else %}{{portchannel_peer}}{% endif %}" - -- name: Set the prefix to be announced - set_fact: - announce_prefix: "{% if addr_family=='ipv4' %}10.10.10.0/26{% else %}2010::/126{% endif %}" - -- name: Generate routes to be announced - template: src=roles/test/templates/exabgp/routes.j2 dest={{exabgp_dir}}/routes - with_items: - - {speaker_ip: '{{vlan_ips[0]}}', - mux_ip_1: "{{mux_ip_1}}", - mux_ip_2: "{{mux_ip_2}}", - port_num_1: '5000', - port_num_2: '6000', - port_num_3: '7000'} - delegate_to: "{{ptf_host}}" - -- name: Generate start file for exabgp instances - template: src=roles/test/templates/exabgp/start.j2 dest={{exabgp_dir}}/{{item.file_name}} mode=u+rwx - with_items: - - {file_name: 'start.sh', - config_file_1: 'config_1.ini', - config_file_2: 'config_2.ini', - config_file_3: 'config_3.ini', - phy_ip: '{{vlan_ips[0]}}', - logical_ip_1: '{{speaker_ips[0]}}', - logical_ip_2: '{{speaker_ips[1]}}', - mux_ip_1: "{{mux_ip_1}}", - mux_ip_2: "{{mux_ip_2}}"} - delegate_to: "{{ptf_host}}" - -- name: Kill exabgp instances if existing - shell: pkill exabgp - delegate_to: "{{ptf_host}}" - ignore_errors: yes - -- name: Start exabgp instances - shell: sh {{exabgp_dir}}/start.sh - delegate_to: "{{ptf_host}}" - -- pause: - seconds: 5 - prompt: "make sure dynamic bgp neighbors appear" - -- name: Announce the routes - shell: python {{helper_dir}}/announce_routes.py {{exabgp_dir}}/routes >/dev/null 2>&1 & - delegate_to: "{{ptf_host}}" - -- pause: - seconds: 30 - prompt: "make sure routes announced to dynamic bgp neighbors" - -- name: Gather bgp facts from bgp container - bgp_facts: - -- debug: msg="{{bgp_neighbors}}" - -- name: Verify bgp sessions are established - assert: {that: "'{{ bgp_neighbors[item]['state'] }}' == 'established'"} - with_items: "{{ bgp_neighbors.keys() }}" - -- name: Verify accepted prefixes of the dynamic neighbors are correct - assert: {that: "'{{ bgp_neighbors[item]['accepted prefixes'] }}' == '1'"} - with_items: "['{{speaker_ips[0].split('/')[0]}}', '{{speaker_ips[1].split('/')[0]}}', '{{vlan_ips[0].split('/')[0]}}'] " - -# Send packets to verify that accepted prefixes are correctly applied in HW. -# PTF FIB test is used to send the packets. - -- name: Generate route-port map information - template: src=roles/test/templates/bgp_speaker_route.j2 - dest=/tmp/bgp_speaker_route.txt - connection: local - -- name: Copy the bgp_speaker_route to ptf container - copy: src=/tmp/bgp_speaker_route.txt dest=/root - delegate_to: "{{ptf_host}}" - -- name: Copy the test to ptf container - copy: src=roles/test/files/ptftests dest=/root - delegate_to: "{{ ptf_host }}" - -- set_fact: ipv4=true - when: addr_family == 'ipv4' - -- set_fact: ipv6=true - when: addr_family == 'ipv6' - -- name: "Start PTF runner" - include: ptf_runner.yml - vars: - ptf_test_name: FIB test - ptf_test_dir: ptftests - ptf_test_path: fib_test.FibTest - ptf_platform: remote - ptf_platform_dir: ptftests - ptf_test_params: - - testbed_type='{{testbed_type}}' - - router_mac='{{ansible_Ethernet0['macaddress']}}' - - fib_info='/root/bgp_speaker_route.txt' - - ipv4={{ ipv4|default(false) }} - - ipv6={{ ipv6|default(false) }} - ptf_extra_options: "--relax --debug info --log-file /tmp/bgp_speaker_test.FibTest.log" - -- name: Kill exabgp instances - shell: pkill exabgp - delegate_to: "{{ptf_host}}" - -- name: Flush vlan ips route - command: ip route flush {{item.split('/')[0]}}/32 - when: addr_family == 'ipv4' - become: yes - with_items: "{{vlan_ips}}" - -- name: Remove Assigned IPs - shell: ip addr flush dev eth{{ '%d' % (minigraph_vlans[minigraph_vlan_interfaces[0]['attachto']]['members'][0] | replace("Ethernet", "") | int / 4)}} - delegate_to: "{{ptf_host}}" + - name: Gather minigraph facts about the device + minigraph_facts: host={{inventory_hostname}} + become: no + connection: local + + - name: print deployment id + debug: msg="{{deployment_id}}" + + - name: fetch bgp speaker asn number from DUT + shell: sonic-cfggen -m -d -y /etc/sonic/deployment_id_asn_map.yml -v "deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']]" + register: cfggen_out + + - name: set bgp speaker asn number + set_fact: + bgp_speaker_asn={{cfggen_out.stdout}} + + - set_fact: addr_family='ipv4' + when: addr_family is not defined + + - set_fact: portchannel_name="{{minigraph_portchannel_interfaces[0].attachto}}" + when: addr_family == 'ipv6' + + - name: print bgp speaker asn number + debug: msg="{{bgp_speaker_asn}}" + + - name: Generate three ips in VLAN range + get_ip_in_range: num=3 prefix="{{minigraph_vlan_interfaces[0]['addr']}}/{{minigraph_vlan_interfaces[0]['prefixlen']}}" exclude_ips="{{minigraph_vlan_interfaces[0]['addr']}}" + become: no + connection: local + failed_when: False + + - name: Store the value of VLAN IPs + set_fact: + vlan_ips={{generated_ips}} + + - debug: msg="{{generated_ips}}" + + - name: Generate two ips in bgp speaker peer range + get_ip_in_range: num=2 prefix={{minigraph_bgp_peers_with_range[0]['ip_range'][0]}} + become: no + connection: local + + - name: Set the value of ips in bgp speaker peer range + set_fact: speaker_ips={{generated_ips}} + + - name: Flush vlan ips route + command: ip route flush {{item.split('/')[0]}}/32 + when: addr_family == 'ipv4' + become: yes + with_items: "{{vlan_ips}}" + + - name: Add vlan ips route + command: ip route add {{item.split('/')[0]}}/32 dev {{minigraph_vlan_interfaces[0]['attachto']}} + when: addr_family == 'ipv4' + become: yes + with_items: "{{vlan_ips}}" + + - debug: msg="{{generated_ips}}" + + # vlan_ips[0], speaker_ips[0], speaker_ips[1] are IPs for three bgp speakers + # vlan_ips[1], vlan_ips[2] are IPs for mux under DUT. + + - name: set exabgp folder name + set_fact: + exabgp_dir="/root/exabgp" + + - name: Create directory /exabgp to store exabgp related files. + file: path={{exabgp_dir}} state=directory + delegate_to: "{{ptf_host}}" + + - name: Copy helper files to ptf container + copy: src=roles/test/files/helpers dest=/root + delegate_to: "{{ptf_host}}" + + - name: set exabgp folder name + set_fact: + helper_dir="/root/helpers" + + - name: Generate configurations for exabgp instances + template: src=roles/test/templates/exabgp/config.j2 dest={{exabgp_dir}}/{{item.file_name}} + with_items: + - {file_name: "config_1.ini", local_ip: '{{speaker_ips[0]}}', port_num: '5000'} + - {file_name: "config_2.ini", local_ip: '{{speaker_ips[1]}}', port_num: '6000'} + - {file_name: "config_3.ini", local_ip: '{{vlan_ips[0]}}', port_num: '7000'} + delegate_to: "{{ptf_host}}" + + - set_fact: portchannel_peer="{%for p in minigraph_portchannel_interfaces%}{%if p['attachto']==portchannel_name and p['peer_addr']|ipv6%}{{p['peer_addr']}}{%endif %}{%endfor%}" + when: addr_family == 'ipv6' + + - set_fact: mux_ip_1="{% if addr_family=='ipv4' %}{{vlan_ips[1]}}{% else %}{{portchannel_peer}}{% endif %}" + - set_fact: mux_ip_2="{% if addr_family=='ipv4' %}{{vlan_ips[2]}}{% else %}{{portchannel_peer}}{% endif %}" + + - name: Set the prefix to be announced + set_fact: + announce_prefix: "{% if addr_family=='ipv4' %}10.10.10.0/26{% else %}2010::/126{% endif %}" + + - name: Generate routes to be announced + template: src=roles/test/templates/exabgp/routes.j2 dest={{exabgp_dir}}/routes + with_items: + - {speaker_ip: '{{vlan_ips[0]}}', + mux_ip_1: "{{mux_ip_1}}", + mux_ip_2: "{{mux_ip_2}}", + port_num_1: '5000', + port_num_2: '6000', + port_num_3: '7000'} + delegate_to: "{{ptf_host}}" + + - name: Generate start file for exabgp instances + template: src=roles/test/templates/exabgp/start.j2 dest={{exabgp_dir}}/{{item.file_name}} mode=u+rwx + with_items: + - {file_name: 'start.sh', + config_file_1: 'config_1.ini', + config_file_2: 'config_2.ini', + config_file_3: 'config_3.ini', + phy_ip: '{{vlan_ips[0]}}', + logical_ip_1: '{{speaker_ips[0]}}', + logical_ip_2: '{{speaker_ips[1]}}', + mux_ip_1: "{{mux_ip_1}}", + mux_ip_2: "{{mux_ip_2}}"} + delegate_to: "{{ptf_host}}" + + - name: Kill exabgp instances if existing + shell: pkill exabgp + delegate_to: "{{ptf_host}}" + ignore_errors: yes + + - name: Start exabgp instances + shell: sh {{exabgp_dir}}/start.sh + delegate_to: "{{ptf_host}}" + + - pause: + seconds: 5 + prompt: "make sure dynamic bgp neighbors appear" + + - name: Announce the routes + shell: python {{helper_dir}}/announce_routes.py {{exabgp_dir}}/routes >/dev/null 2>&1 & + delegate_to: "{{ptf_host}}" + + - pause: + seconds: 30 + prompt: "make sure routes announced to dynamic bgp neighbors" + + - name: Gather bgp facts from bgp container + bgp_facts: + + - debug: msg="{{bgp_neighbors}}" + + - name: Verify bgp sessions are established + assert: {that: "'{{ bgp_neighbors[item]['state'] }}' == 'established'"} + with_items: "{{ bgp_neighbors.keys() }}" + + - name: Verify accepted prefixes of the dynamic neighbors are correct + assert: {that: "'{{ bgp_neighbors[item]['accepted prefixes'] }}' == '1'"} + with_items: "['{{speaker_ips[0].split('/')[0]}}', '{{speaker_ips[1].split('/')[0]}}', '{{vlan_ips[0].split('/')[0]}}'] " + + # Send packets to verify that accepted prefixes are correctly applied in HW. + # PTF FIB test is used to send the packets. + + - name: Generate route-port map information + template: src=roles/test/templates/bgp_speaker_route.j2 + dest=/tmp/bgp_speaker_route.txt + connection: local + + - name: Copy the bgp_speaker_route to ptf container + copy: src=/tmp/bgp_speaker_route.txt dest=/root + delegate_to: "{{ptf_host}}" + + - name: Copy the test to ptf container + copy: src=roles/test/files/ptftests dest=/root + delegate_to: "{{ ptf_host }}" + + - set_fact: ipv4=true + when: addr_family == 'ipv4' + + - set_fact: ipv6=true + when: addr_family == 'ipv6' + + - name: "Start PTF runner" + include: ptf_runner.yml + vars: + ptf_test_name: FIB test + ptf_test_dir: ptftests + ptf_test_path: fib_test.FibTest + ptf_platform: remote + ptf_platform_dir: ptftests + ptf_test_params: + - testbed_type='{{testbed_type}}' + - router_mac='{{ansible_Ethernet0['macaddress']}}' + - fib_info='/root/bgp_speaker_route.txt' + - ipv4={{ ipv4|default(false) }} + - ipv6={{ ipv6|default(false) }} + ptf_extra_options: "--relax --debug info --log-file /tmp/bgp_speaker_test.FibTest.log" + always: + - name: Kill exabgp instances + shell: pkill exabgp + delegate_to: "{{ptf_host}}" + + - name: Flush vlan ips route + command: ip route flush {{item.split('/')[0]}}/32 + when: addr_family == 'ipv4' + become: yes + with_items: "{{vlan_ips}}" + + - name: Remove Assigned IPs + shell: ip addr flush dev eth{{ '%d' % (minigraph_vlans[minigraph_vlan_interfaces[0]['attachto']]['members'][0] | replace("Ethernet", "") | int / 4)}} + delegate_to: "{{ptf_host}}"