|
14 | 14 |
|
15 | 15 |
|
16 | 16 | @pytest.fixture(scope="module") |
17 | | -def downstream_links(rand_selected_dut, tbinfo): |
| 17 | +def downstream_links(rand_selected_dut, tbinfo, nbrhosts): |
18 | 18 | """ |
19 | 19 | Returns a dictionary of all the links that are downstream from the DUT. |
20 | 20 |
|
21 | 21 | Args: |
22 | 22 | rand_selected_dut: DUT fixture |
23 | 23 | tbinfo: testbed information fixture |
| 24 | + nbrhosts: neighbor host fixture |
24 | 25 | Returns: |
25 | 26 | links: Dictionary of links downstream from the DUT |
26 | 27 | """ |
27 | 28 | links = dict() |
28 | 29 | duthost = rand_selected_dut |
29 | 30 |
|
30 | 31 | def filter(interface, neighbor, mg_facts, tbinfo): |
31 | | - if ((tbinfo["topo"]["type"] == "t0" and "Server" in neighbor["name"]) |
32 | | - or (tbinfo["topo"]["type"] == "t1" and "T0" in neighbor["name"])): |
33 | | - port = mg_facts["minigraph_neighbors"][interface]["port"] |
| 32 | + port = mg_facts["minigraph_neighbors"][interface]["port"] |
| 33 | + ptf_port_id = mg_facts["minigraph_ptf_indices"][interface] |
| 34 | + if tbinfo["topo"]["type"] == "t1" and "T0" in neighbor["name"]: |
| 35 | + # Search for BGP neighbor information |
| 36 | + local_ipv4_addr = None |
| 37 | + peer_ipv4_addr = None |
| 38 | + for item in mg_facts["minigraph_bgp"]: |
| 39 | + if item["name"] == neighbor["name"]: |
| 40 | + if isinstance(ip_address(item["addr"]), IPv4Address): |
| 41 | + # The address of neighbor device |
| 42 | + local_ipv4_addr = item["addr"] |
| 43 | + # The address of DUT |
| 44 | + peer_ipv4_addr = item["peer_addr"] |
| 45 | + break |
34 | 46 | links[interface] = { |
35 | 47 | "name": neighbor["name"], |
36 | | - "ptf_port_id": mg_facts["minigraph_ptf_indices"][interface], |
| 48 | + "ptf_port_id": ptf_port_id, |
| 49 | + "local_ipv4_addr": local_ipv4_addr, |
| 50 | + "peer_ipv4_addr": peer_ipv4_addr, |
| 51 | + "downstream_port": port, |
| 52 | + "host": nbrhosts[neighbor["name"]]["host"] |
| 53 | + } |
| 54 | + elif tbinfo["topo"]["type"] == "t0" and "Server" in neighbor["name"]: |
| 55 | + links[interface] = { |
| 56 | + "name": neighbor["name"], |
| 57 | + "ptf_port_id": ptf_port_id, |
37 | 58 | "downstream_port": port |
38 | 59 | } |
39 | 60 |
|
@@ -83,6 +104,47 @@ def filter(interface, neighbor, mg_facts, tbinfo): |
83 | 104 | return links |
84 | 105 |
|
85 | 106 |
|
| 107 | +@pytest.fixture(scope="module") |
| 108 | +def peer_links(rand_selected_dut, tbinfo, nbrhosts): |
| 109 | + """ |
| 110 | + Returns a dictionary of all the links that are service ports from the DUT. |
| 111 | +
|
| 112 | + Args: |
| 113 | + rand_selected_dut: DUT fixture |
| 114 | + tbinfo: testbed information fixture |
| 115 | + nbrhosts: neighbor host fixture |
| 116 | + Returns: |
| 117 | + links: Dictionary of service links from the DUT |
| 118 | + """ |
| 119 | + links = dict() |
| 120 | + duthost = rand_selected_dut |
| 121 | + |
| 122 | + def filter(interface, neighbor, mg_facts, tbinfo): |
| 123 | + if "PT0" in neighbor["name"]: |
| 124 | + local_ipv4_addr = None |
| 125 | + peer_ipv4_addr = None |
| 126 | + for item in mg_facts["minigraph_bgp"]: |
| 127 | + if item["name"] == neighbor["name"]: |
| 128 | + if isinstance(ip_address(item["addr"]), IPv4Address): |
| 129 | + # The address of neighbor device |
| 130 | + local_ipv4_addr = item["addr"] |
| 131 | + # The address of DUT |
| 132 | + peer_ipv4_addr = item["peer_addr"] |
| 133 | + break |
| 134 | + port = mg_facts["minigraph_neighbors"][interface]["port"] |
| 135 | + links[interface] = { |
| 136 | + "name": neighbor["name"], |
| 137 | + "ptf_port_id": mg_facts["minigraph_ptf_indices"][interface], |
| 138 | + "local_ipv4_addr": local_ipv4_addr, |
| 139 | + "peer_ipv4_addr": peer_ipv4_addr, |
| 140 | + "service_port": port, |
| 141 | + "host": nbrhosts[neighbor["name"]]["host"] |
| 142 | + } |
| 143 | + |
| 144 | + find_links(duthost, tbinfo, filter) |
| 145 | + return links |
| 146 | + |
| 147 | + |
86 | 148 | def apply_dscp_cfg_setup(duthost, dscp_mode): |
87 | 149 | """ |
88 | 150 | Applies the DSCP decap configuration to the DUT. |
|
0 commit comments