blob: 0ef3465c5cd1e17e8fb0e4afd5107ae824f26b52 [file] [log] [blame]
Daniele Morob8404e82022-02-25 00:17:28 +01001from tests.USECASE.SegmentRouting.dependencies.Testcaselib import \
2 Testcaselib as run
3from tests.USECASE.SegmentRouting.dependencies.trex import Trex
4from tests.USECASE.SegmentRouting.dependencies.up4 import UP4
5import json
6
7
8class PolicingTest:
9
10 def runTest(self, main, test_idx):
11 run.initTest(main)
12 main.log.info(main.Cluster.numCtrls)
13 main.Cluster.setRunningNode(3)
14 run.installOnos(main, skipPackage=True, cliSleep=5)
15
16 main.step("Start P4rt client and setup TRex")
17 # Use the first available ONOS instance CLI
18 onos_cli = main.Cluster.active(0).CLI
19 up4 = UP4()
20 trex = Trex()
21 # Get the P4RT client connected to UP4 in the first available ONOS instance
22 up4.setup(main.Cluster.active(0).p4rtUp4, no_host=True)
23 trex.setup(main.TRexClient)
24
25 try:
26 main.step("Program UPF entities via UP4")
27 up4.attachUes()
28 up4.verifyUp4Flow(onos_cli)
29
30 # Load traffic config for the current test case
31 main.step("Load test JSON config")
32 cfgFile = main.configPath + "/tests/" + "CASE_%d.json" % test_idx
33 with open(cfgFile) as cfg:
34 testCfg = json.load(cfg)
35
36 for flow in testCfg["flows"]:
37 trex.createFlow(flow)
38 results = trex.sendAndReceiveTraffic(testCfg["duration"])
39
40 main.step("Log port and flow stats")
41 trex.logPortStats()
42 for flow in testCfg["flows"]:
43 trex.logFlowStats(flow)
44
45 for flow in testCfg["flows"]:
46 if trex.isFlowStats(flow):
47 main.step("{}: Assert RX Packets".format(flow))
48 trex.assertRxPackets(flow)
49 # Assert received traffic is similar to expected for that flow
50 trex.assertRxRate(flow, results["duration"][-1])
51 finally:
52 main.step("Remove UPF entities via UP4")
53 up4.detachUes()
54 up4.verifyNoUesFlow(onos_cli)
55
56 main.step("Teardown")
57 trex.teardown()
58 up4.teardown()
59 run.cleanup(main)