3 from scapy.layers.inet import IP, UDP, ICMP
4 from scapy.layers.inet6 import IPv6
5 from scapy.layers.l2 import Ether, GRE
6 from scapy.packet import Raw
8 from framework import VppTestCase
11 """ TestPing is a subclass of VPPTestCase classes.
13 Basic test for sanity check of the ping.
18 class TestPing(VppTestCase):
19 """ Ping Test Case """
23 super(TestPing, cls).setUpClass()
25 cls.create_pg_interfaces(range(2))
26 cls.interfaces = list(cls.pg_interfaces)
28 for i in cls.interfaces:
36 super(TestPing, cls).tearDownClass()
40 def tearDownClass(cls):
41 super(TestPing, cls).tearDownClass()
44 super(TestPing, self).tearDown()
46 def show_commands_at_teardown(self):
47 self.logger.info(self.vapi.cli("show hardware"))
49 def test_ping_basic(self):
50 """ basic ping test """
52 self.pg_enable_capture(self.pg_interfaces)
54 self.logger.info(self.vapi.cli("show ip arp"))
55 self.logger.info(self.vapi.cli("show ip6 neighbors"))
57 remote_ip4 = self.pg1.remote_ip4
58 ping_cmd = "ping " + remote_ip4 + " interval 0.01 repeat 10"
59 ret = self.vapi.cli(ping_cmd)
61 out = self.pg1.get_capture(10)
66 self.assertEqual(ip.version, 4)
67 self.assertEqual(ip.flags, 0)
68 self.assertEqual(ip.src, self.pg1.local_ip4)
69 self.assertEqual(ip.dst, self.pg1.remote_ip4)
70 self.assertEqual(ip.proto, 1)
71 self.assertEqual(len(ip.options), 0)
72 self.assertGreaterEqual(ip.ttl, 254)
74 self.assertEqual(icmp.type, 8)
75 self.assertEqual(icmp.code, 0)
76 self.assertEqual(icmp.seq, icmp_seq)
77 icmp_seq = icmp_seq + 1
81 self.assertEqual(icmp.id, icmp_id)
83 self.vapi.cli("show error")
85 def test_ping_burst(self):
86 """ burst ping test """
88 self.pg_enable_capture(self.pg_interfaces)
90 self.logger.info(self.vapi.cli("show ip arp"))
91 self.logger.info(self.vapi.cli("show ip6 neighbors"))
93 remote_ip4 = self.pg1.remote_ip4
94 ping_cmd = "ping " + remote_ip4 + " interval 0.01 burst 3"
95 ret = self.vapi.cli(ping_cmd)
97 out = self.pg1.get_capture(3*5)
103 self.assertEqual(ip.version, 4)
104 self.assertEqual(ip.flags, 0)
105 self.assertEqual(ip.src, self.pg1.local_ip4)
106 self.assertEqual(ip.dst, self.pg1.remote_ip4)
107 self.assertEqual(ip.proto, 1)
108 self.assertEqual(len(ip.options), 0)
109 self.assertGreaterEqual(ip.ttl, 254)
111 self.assertEqual(icmp.type, 8)
112 self.assertEqual(icmp.code, 0)
113 self.assertEqual(icmp.seq, icmp_seq)
116 icmp_seq = icmp_seq + 1
121 self.assertEqual(icmp.id, icmp_id)
123 self.vapi.cli("show error")