|
| 1 | +import pytest |
| 2 | +import snappi |
| 3 | +import time |
| 4 | + |
| 5 | +vlan_id = "10" |
| 6 | +macs = ["00:1A:C5:00:00:01", "00:1B:6E:00:00:01"] |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture(scope="module", autouse=True) |
| 10 | +def discovery(npu): |
| 11 | + npu.objects_discovery() |
| 12 | + |
| 13 | + |
| 14 | +def test_l2_traffic(npu, dataplane): |
| 15 | + """ |
| 16 | + Creates vlan 10 and adds two ports to the vlan 10 member |
| 17 | + and validates the config using l2 traffic |
| 18 | + """ |
| 19 | + commands = [ |
| 20 | + { |
| 21 | + "name": "vlan_10", |
| 22 | + "op": "create", |
| 23 | + "type": "SAI_OBJECT_TYPE_VLAN", |
| 24 | + "attributes": ["SAI_VLAN_ATTR_VLAN_ID", "10"], |
| 25 | + }, |
| 26 | + { |
| 27 | + "name": "bridge_p_2", |
| 28 | + "op": "create", |
| 29 | + "type": "SAI_OBJECT_TYPE_BRIDGE_PORT", |
| 30 | + "attributes": [ |
| 31 | + "SAI_BRIDGE_PORT_ATTR_TYPE", |
| 32 | + "SAI_BRIDGE_PORT_TYPE_PORT", |
| 33 | + "SAI_BRIDGE_PORT_ATTR_PORT_ID", |
| 34 | + "$PORT_2", |
| 35 | + "SAI_BRIDGE_PORT_ATTR_ADMIN_STATE", |
| 36 | + "true", |
| 37 | + "SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", |
| 38 | + "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW", |
| 39 | + ], |
| 40 | + }, |
| 41 | + { |
| 42 | + "name": "vlan_member_2", |
| 43 | + "op": "create", |
| 44 | + "type": "SAI_OBJECT_TYPE_VLAN_MEMBER", |
| 45 | + "attributes": [ |
| 46 | + "SAI_VLAN_MEMBER_ATTR_VLAN_ID", |
| 47 | + "$vlan_10", |
| 48 | + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID", |
| 49 | + "$bridge_p_2", |
| 50 | + "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE", |
| 51 | + "SAI_VLAN_TAGGING_MODE_UNTAGGED", |
| 52 | + ], |
| 53 | + }, |
| 54 | + { |
| 55 | + "name": "PORT_2", |
| 56 | + "op": "set", |
| 57 | + "type": "SAI_OBJECT_TYPE_PORT", |
| 58 | + "attributes": [ |
| 59 | + "SAI_PORT_ATTR_ADMIN_STATE", |
| 60 | + "true", |
| 61 | + "SAI_PORT_ATTR_PORT_VLAN_ID", |
| 62 | + "10", |
| 63 | + ], |
| 64 | + }, |
| 65 | + { |
| 66 | + "name": "bridge_p_3", |
| 67 | + "op": "create", |
| 68 | + "type": "SAI_OBJECT_TYPE_BRIDGE_PORT", |
| 69 | + "attributes": [ |
| 70 | + "SAI_BRIDGE_PORT_ATTR_TYPE", |
| 71 | + "SAI_BRIDGE_PORT_TYPE_PORT", |
| 72 | + "SAI_BRIDGE_PORT_ATTR_PORT_ID", |
| 73 | + "$PORT_3", |
| 74 | + "SAI_BRIDGE_PORT_ATTR_ADMIN_STATE", |
| 75 | + "true", |
| 76 | + "SAI_BRIDGE_PORT_ATTR_FDB_LEARNING_MODE", |
| 77 | + "SAI_BRIDGE_PORT_FDB_LEARNING_MODE_HW", |
| 78 | + ], |
| 79 | + }, |
| 80 | + { |
| 81 | + "name": "vlan_member_3", |
| 82 | + "op": "create", |
| 83 | + "type": "SAI_OBJECT_TYPE_VLAN_MEMBER", |
| 84 | + "attributes": [ |
| 85 | + "SAI_VLAN_MEMBER_ATTR_VLAN_ID", |
| 86 | + "$vlan_10", |
| 87 | + "SAI_VLAN_MEMBER_ATTR_BRIDGE_PORT_ID", |
| 88 | + "$bridge_p_3", |
| 89 | + "SAI_VLAN_MEMBER_ATTR_VLAN_TAGGING_MODE", |
| 90 | + "SAI_VLAN_TAGGING_MODE_UNTAGGED", |
| 91 | + ], |
| 92 | + }, |
| 93 | + { |
| 94 | + "name": "PORT_3", |
| 95 | + "op": "set", |
| 96 | + "type": "SAI_OBJECT_TYPE_PORT", |
| 97 | + "attributes": [ |
| 98 | + "SAI_PORT_ATTR_ADMIN_STATE", |
| 99 | + "true", |
| 100 | + "SAI_PORT_ATTR_PORT_VLAN_ID", |
| 101 | + "10", |
| 102 | + ], |
| 103 | + }, |
| 104 | + ] |
| 105 | + for command in commands: |
| 106 | + print("-" * 80) |
| 107 | + print(command) |
| 108 | + result = npu.command_processor.process_command(command) |
| 109 | + print(result) |
| 110 | + |
| 111 | + macs = ["00:11:11:11:11:11", "00:22:22:22:22:22"] |
| 112 | + config = dataplane.configuration |
| 113 | + config.options.port_options.location_preemption = True |
| 114 | + layer1 = config.layer1.layer1()[-1] |
| 115 | + layer1.name = "port settings" |
| 116 | + layer1.port_names = [port.name for port in config.ports] |
| 117 | + layer1.ieee_media_defaults = False |
| 118 | + layer1.auto_negotiation.rs_fec = False |
| 119 | + layer1.auto_negotiation.link_training = False |
| 120 | + layer1.speed = "speed_100_gbps" |
| 121 | + layer1.auto_negotiate = False |
| 122 | + flow1 = config.flows.flow(name="Vlan Traffic")[-1] |
| 123 | + |
| 124 | + flow1.tx_rx.port.tx_name = config.ports[0].name |
| 125 | + flow1.tx_rx.port.rx_name = config.ports[1].name |
| 126 | + flow1.size.fixed = 1024 |
| 127 | + flow1.rate.percentage = 100 |
| 128 | + flow1.metrics.enable = True |
| 129 | + flow1.metrics.loss = True |
| 130 | + source = macs[1] |
| 131 | + destination = macs[0] |
| 132 | + eth, vlan = flow1.packet.ethernet().vlan() |
| 133 | + eth.src.value = source |
| 134 | + eth.dst.value = destination |
| 135 | + vlan.id.value = int(vlan_id) |
| 136 | + |
| 137 | + dataplane.set_config() |
| 138 | + restpy_session = dataplane.api.assistant.Session |
| 139 | + ixnet = restpy_session.Ixnetwork |
| 140 | + for port in ixnet.Vport.find(): |
| 141 | + port.L1Config.NovusHundredGigLan.AutoInstrumentation = "endOfFrame" |
| 142 | + |
| 143 | + ts = dataplane.api.transmit_state() |
| 144 | + ts.flow_names = [flow1.name] |
| 145 | + ts.state = ts.START |
| 146 | + dataplane.api.set_transmit_state(ts) |
| 147 | + time.sleep(10) |
| 148 | + ts = dataplane.api.transmit_state() |
| 149 | + ts.flow_names = [flow1.name] |
| 150 | + ts.state = ts.STOP |
| 151 | + dataplane.api.set_transmit_state(ts) |
| 152 | + time.sleep(10) |
| 153 | + request = dataplane.api.metrics_request() |
| 154 | + request.flow.flow_names = [flow1.name] |
| 155 | + rows = dataplane.api.get_metrics(request).flow_metrics |
| 156 | + print("Loss {}".format(rows[0].loss)) |
| 157 | + |
| 158 | + req = dataplane.api.metrics_request() |
| 159 | + req.port.port_names = [p.name for p in config.ports] |
| 160 | + req.port.column_names = [req.port.FRAMES_TX, req.port.FRAMES_RX] |
| 161 | + # fetch port metrics |
| 162 | + res = dataplane.api.get_metrics(req) |
| 163 | + total_tx = sum([m.frames_tx for m in res.port_metrics]) |
| 164 | + total_rx = sum([m.frames_rx for m in res.port_metrics]) |
| 165 | + print("Tx_Frame : {}".format(total_tx)) |
| 166 | + print("Rx_Frame : {}".format(total_rx)) |
| 167 | + assert (total_tx == total_rx, "Tx Frame not equal to Rx Frame") |
| 168 | + assert (int(rows[0].loss) == 0, "Loss observed") |
| 169 | + assert (total_tx > 0, "Tx Frame rate is Zero") |
0 commit comments