Skip to content

Commit eb6e395

Browse files
committed
modified cleanup step
Signed-off-by: selldinesh <[email protected]>
1 parent f119949 commit eb6e395

File tree

1 file changed

+61
-75
lines changed

1 file changed

+61
-75
lines changed

tests/snappi/test_vlan_traffic.py

+61-75
Original file line numberDiff line numberDiff line change
@@ -73,82 +73,68 @@ def test_l2_untagged_vlan_traffic(npu, dataplane):
7373
print(command)
7474
result = npu.command_processor.process_command(command)
7575
print(result)
76+
try:
77+
macs = ["00:11:11:11:11:11", "00:22:22:22:22:22"]
78+
config = dataplane.configuration
79+
config.options.port_options.location_preemption = True
80+
layer1 = config.layer1.layer1()[-1]
81+
layer1.name = "port settings"
82+
layer1.port_names = [port.name for port in config.ports]
83+
layer1.ieee_media_defaults = False
84+
layer1.auto_negotiation.rs_fec = False
85+
layer1.auto_negotiation.link_training = False
86+
layer1.speed = "speed_100_gbps"
87+
layer1.auto_negotiate = False
88+
flow1 = config.flows.flow(name="Vlan Traffic")[-1]
7689

77-
macs = ["00:11:11:11:11:11", "00:22:22:22:22:22"]
78-
config = dataplane.configuration
79-
config.options.port_options.location_preemption = True
80-
layer1 = config.layer1.layer1()[-1]
81-
layer1.name = "port settings"
82-
layer1.port_names = [port.name for port in config.ports]
83-
layer1.ieee_media_defaults = False
84-
layer1.auto_negotiation.rs_fec = False
85-
layer1.auto_negotiation.link_training = False
86-
layer1.speed = "speed_100_gbps"
87-
layer1.auto_negotiate = False
88-
flow1 = config.flows.flow(name="Vlan Traffic")[-1]
90+
flow1.tx_rx.port.tx_name = config.ports[0].name
91+
flow1.tx_rx.port.rx_name = config.ports[1].name
92+
flow1.size.fixed = 1024
93+
flow1.rate.percentage = 100
94+
flow1.metrics.enable = True
95+
flow1.metrics.loss = True
96+
source = macs[1]
97+
destination = macs[0]
98+
eth, vlan = flow1.packet.ethernet().vlan()
99+
eth.src.value = source
100+
eth.dst.value = destination
101+
vlan.id.value = int(vlan_id)
89102

90-
flow1.tx_rx.port.tx_name = config.ports[0].name
91-
flow1.tx_rx.port.rx_name = config.ports[1].name
92-
flow1.size.fixed = 1024
93-
flow1.rate.percentage = 100
94-
flow1.metrics.enable = True
95-
flow1.metrics.loss = True
96-
source = macs[1]
97-
destination = macs[0]
98-
eth, vlan = flow1.packet.ethernet().vlan()
99-
eth.src.value = source
100-
eth.dst.value = destination
101-
vlan.id.value = int(vlan_id)
103+
dataplane.set_config()
104+
restpy_session = dataplane.api.assistant.Session
105+
ixnet = restpy_session.Ixnetwork
106+
for port in ixnet.Vport.find():
107+
port.L1Config.NovusHundredGigLan.AutoInstrumentation = "endOfFrame"
102108

103-
dataplane.set_config()
104-
restpy_session = dataplane.api.assistant.Session
105-
ixnet = restpy_session.Ixnetwork
106-
for port in ixnet.Vport.find():
107-
port.L1Config.NovusHundredGigLan.AutoInstrumentation = "endOfFrame"
109+
ts = dataplane.api.transmit_state()
110+
ts.flow_names = [flow1.name]
111+
ts.state = ts.START
112+
dataplane.api.set_transmit_state(ts)
113+
time.sleep(10)
114+
ts = dataplane.api.transmit_state()
115+
ts.flow_names = [flow1.name]
116+
ts.state = ts.STOP
117+
dataplane.api.set_transmit_state(ts)
118+
time.sleep(10)
119+
request = dataplane.api.metrics_request()
120+
request.flow.flow_names = [flow1.name]
121+
rows = dataplane.api.get_metrics(request).flow_metrics
122+
print("Loss {}".format(rows[0].loss))
108123

109-
ts = dataplane.api.transmit_state()
110-
ts.flow_names = [flow1.name]
111-
ts.state = ts.START
112-
dataplane.api.set_transmit_state(ts)
113-
time.sleep(10)
114-
ts = dataplane.api.transmit_state()
115-
ts.flow_names = [flow1.name]
116-
ts.state = ts.STOP
117-
dataplane.api.set_transmit_state(ts)
118-
time.sleep(10)
119-
request = dataplane.api.metrics_request()
120-
request.flow.flow_names = [flow1.name]
121-
rows = dataplane.api.get_metrics(request).flow_metrics
122-
print("Loss {}".format(rows[0].loss))
123-
124-
req = dataplane.api.metrics_request()
125-
req.port.port_names = [p.name for p in config.ports]
126-
req.port.column_names = [req.port.FRAMES_TX, req.port.FRAMES_RX]
127-
# fetch port metrics
128-
res = dataplane.api.get_metrics(req)
129-
total_tx = sum([m.frames_tx for m in res.port_metrics])
130-
total_rx = sum([m.frames_rx for m in res.port_metrics])
131-
print("Tx_Frame : {}".format(total_tx))
132-
print("Rx_Frame : {}".format(total_rx))
133-
assert total_tx == total_rx, "Tx Frame not equal to Rx Frame"
134-
assert int(rows[0].loss) == 0, "Loss observed"
135-
assert total_tx > 0, "Tx Frame rate is Zero"
136-
137-
commands = [
138-
{
139-
'name': 'vlan_10',
140-
'op': 'remove',
141-
},
142-
{
143-
'name': 'PORT_2',
144-
'op': 'remove',
145-
},
146-
{
147-
'name': 'PORT_3',
148-
'op': 'remove',
149-
}
150-
]
151-
152-
results = [*npu.process_commands(commands)]
153-
print('======= SAI commands RETURN values remove =======')
154-
pprint(results)
124+
req = dataplane.api.metrics_request()
125+
req.port.port_names = [p.name for p in config.ports]
126+
req.port.column_names = [req.port.FRAMES_TX, req.port.FRAMES_RX]
127+
# fetch port metrics
128+
res = dataplane.api.get_metrics(req)
129+
total_tx = sum([m.frames_tx for m in res.port_metrics])
130+
total_rx = sum([m.frames_rx for m in res.port_metrics])
131+
print("Tx_Frame : {}".format(total_tx))
132+
print("Rx_Frame : {}".format(total_rx))
133+
assert total_tx == total_rx, "Tx Frame not equal to Rx Frame"
134+
assert int(rows[0].loss) == 0, "Loss observed"
135+
assert total_tx > 0, "Tx Frame rate is Zero"
136+
137+
finally:
138+
results = [*npu.process_commands(commands, cleanup=True)]
139+
print('======= SAI commands RETURN values remove =======')
140+
pprint(results)

0 commit comments

Comments
 (0)