Mohsin Kazmi | c990aae | 2024-10-30 15:00:46 +0000 | [diff] [blame^] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | import unittest |
| 4 | |
| 5 | from scapy.packet import Raw |
| 6 | from scapy.layers.l2 import Ether |
| 7 | from scapy.layers.inet import IP, UDP |
| 8 | from scapy.layers.inet6 import IPv6 |
| 9 | |
| 10 | from framework import VppTestCase |
| 11 | from asfframework import VppTestRunner |
| 12 | |
| 13 | |
| 14 | class TestPgStream(VppTestCase): |
| 15 | """PG Stream Test Case""" |
| 16 | |
| 17 | def __init__(self, *args): |
| 18 | VppTestCase.__init__(self, *args) |
| 19 | |
| 20 | def setUp(self): |
| 21 | super(TestPgStream, self).setUp() |
| 22 | |
| 23 | # Create 3 pg interfaces - one each for ethernet, IPv4, and IPv6. |
| 24 | self.create_pg_interfaces(range(0, 1)) |
| 25 | self.pg_interfaces += self.create_pg_ip4_interfaces(range(1, 2)) |
| 26 | self.pg_interfaces += self.create_pg_ip6_interfaces(range(2, 3)) |
| 27 | |
| 28 | for i in self.pg_interfaces: |
| 29 | i.admin_up() |
| 30 | |
| 31 | for i in [self.pg0, self.pg1]: |
| 32 | i.config_ip4() |
| 33 | |
| 34 | for i in [self.pg0, self.pg2]: |
| 35 | i.config_ip6() |
| 36 | |
| 37 | self.pg0.resolve_arp() |
| 38 | self.pg0.resolve_ndp() |
| 39 | |
| 40 | def tearDown(self): |
| 41 | super(TestPgStream, self).tearDown() |
| 42 | for i in self.pg_interfaces: |
| 43 | i.unconfig_ip4() |
| 44 | i.admin_down() |
| 45 | i.remove_vpp_config() |
| 46 | |
| 47 | def pg_stream(self, count=100, rate=1e6, packet_size=700): |
| 48 | rate = str(rate) |
| 49 | packet_size = str(packet_size) |
| 50 | count = str(count) |
| 51 | |
| 52 | cmds = [ |
| 53 | "packet-generator new {{\n" |
| 54 | " name pg0-stream\n" |
| 55 | " limit {count}\n" |
| 56 | " node ethernet-input\n" |
| 57 | " source pg0\n" |
| 58 | " rate {rate}\n" |
| 59 | " size {packet_size}+{packet_size}\n" |
| 60 | " data {{\n" |
| 61 | " IP4: {src_mac} -> 00:02:03:04:05:06\n" |
| 62 | " UDP: 192.168.20.20 -> 192.168.10.100\n" |
| 63 | " UDP: 1234 -> 4321\n" |
| 64 | " incrementing 100\n" |
| 65 | " }}\n" |
| 66 | "}}\n".format( |
| 67 | count=count, |
| 68 | rate=rate, |
| 69 | packet_size=packet_size, |
| 70 | src_mac=self.pg0.local_mac, |
| 71 | ), |
| 72 | "packet-generator enable", |
| 73 | "packet-generator disable", |
| 74 | "packet-generator delete pg0-stream", |
| 75 | ] |
| 76 | |
| 77 | for cmd in cmds: |
| 78 | r = self.vapi.cli_return_response(cmd) |
| 79 | if r.retval != 0: |
| 80 | if hasattr(r, "reply"): |
| 81 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 82 | else: |
| 83 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 84 | |
| 85 | def test_pg_stream(self): |
| 86 | """PG Stream testing""" |
| 87 | self.pg_stream(rate=100, packet_size=64) |
| 88 | self.pg_stream(count=1000, rate=1000) |
| 89 | self.pg_stream(count=100000, rate=10000, packet_size=1500) |
| 90 | self.pg_stream(packet_size=4000) |
| 91 | |
| 92 | |
| 93 | if __name__ == "__main__": |
| 94 | unittest.main(testRunner=VppTestRunner) |