2021-02-14 11:37:02 -08:00
|
|
|
from scapy.layers.l2 import ARP
|
|
|
|
from scapy.layers.inet6 import ICMPv6ND_NS, ICMPv6ND_NA, IPv6
|
|
|
|
|
|
|
|
from framework import VppTestCase
|
2024-03-11 10:38:46 +00:00
|
|
|
from config import config
|
|
|
|
|
|
|
|
import unittest
|
2021-02-14 11:37:02 -08:00
|
|
|
|
|
|
|
""" TestArping is a subclass of VPPTestCase classes.
|
|
|
|
|
|
|
|
Basic test for sanity check of arping.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2024-03-11 10:38:46 +00:00
|
|
|
@unittest.skipIf("arping" in config.excluded_plugins, "Exclude Arping plugin tests")
|
2021-02-14 11:37:02 -08:00
|
|
|
class TestArping(VppTestCase):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Arping Test Case"""
|
2021-02-14 11:37:02 -08:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(TestArping, cls).setUpClass()
|
|
|
|
try:
|
|
|
|
cls.create_pg_interfaces(range(2))
|
|
|
|
cls.interfaces = list(cls.pg_interfaces)
|
|
|
|
|
|
|
|
for i in cls.interfaces:
|
|
|
|
i.admin_up()
|
|
|
|
i.config_ip4()
|
|
|
|
i.config_ip6()
|
|
|
|
i.disable_ipv6_ra()
|
|
|
|
i.resolve_arp()
|
|
|
|
i.resolve_ndp()
|
|
|
|
except Exception:
|
|
|
|
super(TestArping, cls).tearDownClass()
|
|
|
|
raise
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(TestArping, cls).tearDownClass()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(TestArping, self).tearDown()
|
|
|
|
|
|
|
|
def show_commands_at_teardown(self):
|
|
|
|
self.logger.info(self.vapi.cli("show hardware"))
|
|
|
|
|
|
|
|
def verify_arping_request(self, p, src, dst):
|
|
|
|
arp = p[ARP]
|
|
|
|
self.assertEqual(arp.hwtype, 0x0001)
|
|
|
|
self.assertEqual(arp.ptype, 0x0800)
|
|
|
|
self.assertEqual(arp.hwlen, 6)
|
|
|
|
self.assertEqual(arp.op, 1)
|
|
|
|
self.assertEqual(arp.psrc, src)
|
|
|
|
self.assertEqual(arp.pdst, dst)
|
|
|
|
|
|
|
|
def verify_arping_ip6_ns(self, p, src, dst):
|
|
|
|
icmpv6 = p[ICMPv6ND_NS]
|
|
|
|
self.assertEqual(icmpv6.type, 135)
|
|
|
|
self.assertEqual(icmpv6.tgt, dst)
|
|
|
|
ipv6 = p[IPv6]
|
|
|
|
self.assertEqual(src, ipv6.src)
|
|
|
|
|
|
|
|
def verify_arping_ip6_na(self, p, src, dst):
|
|
|
|
icmpv6 = p[ICMPv6ND_NA]
|
|
|
|
self.assertEqual(icmpv6.type, 136)
|
|
|
|
self.assertEqual(icmpv6.tgt, dst)
|
|
|
|
ipv6 = p[IPv6]
|
|
|
|
self.assertEqual(src, ipv6.src)
|
|
|
|
|
|
|
|
def test_arping_ip4_arp_request_cli(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""arping IP4 arp request CLI test"""
|
2021-02-14 11:37:02 -08:00
|
|
|
try:
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
|
|
|
remote_ip4 = self.pg1.remote_ip4
|
|
|
|
|
|
|
|
ping_cmd = "arping " + remote_ip4 + "pg1 repeat 5 interval 0.1"
|
|
|
|
ret = self.vapi.cli(ping_cmd)
|
|
|
|
self.logger.info(ret)
|
|
|
|
|
|
|
|
ping_cmd = "arping " + remote_ip4 + "pg1"
|
|
|
|
ret = self.vapi.cli(ping_cmd)
|
|
|
|
self.logger.info(ret)
|
|
|
|
|
|
|
|
out = self.pg1.get_capture(6)
|
|
|
|
for p in out:
|
2022-04-26 19:02:15 +02:00
|
|
|
self.verify_arping_request(p, self.pg1.local_ip4, self.pg1.remote_ip4)
|
2021-02-14 11:37:02 -08:00
|
|
|
finally:
|
|
|
|
self.vapi.cli("show error")
|
|
|
|
|
|
|
|
def test_arping_ip4_garp_cli(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""arping ip4 gratuitous arp CLI test"""
|
2021-02-14 11:37:02 -08:00
|
|
|
try:
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ping_cmd = (
|
|
|
|
"arping gratuitous" + self.pg1.local_ip4 + "pg1 repeat 5 interval 0.1"
|
|
|
|
)
|
2021-02-14 11:37:02 -08:00
|
|
|
ret = self.vapi.cli(ping_cmd)
|
|
|
|
self.logger.info(ret)
|
|
|
|
|
|
|
|
ping_cmd = "arping gratuitous" + self.pg1.local_ip4 + "pg1"
|
|
|
|
ret = self.vapi.cli(ping_cmd)
|
|
|
|
self.logger.info(ret)
|
|
|
|
|
|
|
|
out = self.pg1.get_capture(6)
|
|
|
|
for p in out:
|
2022-04-26 19:02:15 +02:00
|
|
|
self.verify_arping_request(p, self.pg1.local_ip4, self.pg1.local_ip4)
|
2021-02-14 11:37:02 -08:00
|
|
|
finally:
|
|
|
|
self.vapi.cli("show error")
|
|
|
|
|
|
|
|
def test_arping_ip4_arp_request_api(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""arping ip4 arp request API test"""
|
2021-02-14 11:37:02 -08:00
|
|
|
try:
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
|
|
|
remote_ip4 = self.pg1.remote_ip4
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ret = self.vapi.arping(
|
|
|
|
address=remote_ip4,
|
|
|
|
sw_if_index=self.pg1.sw_if_index,
|
|
|
|
is_garp=0,
|
|
|
|
repeat=5,
|
|
|
|
interval=0.1,
|
|
|
|
)
|
2021-02-14 11:37:02 -08:00
|
|
|
self.logger.info(ret)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ret = self.vapi.arping(
|
|
|
|
address=remote_ip4, sw_if_index=self.pg1.sw_if_index, is_garp=0
|
|
|
|
)
|
2021-02-14 11:37:02 -08:00
|
|
|
self.logger.info(ret)
|
|
|
|
|
|
|
|
out = self.pg1.get_capture(6)
|
|
|
|
for p in out:
|
2022-04-26 19:02:15 +02:00
|
|
|
self.verify_arping_request(p, self.pg1.local_ip4, self.pg1.remote_ip4)
|
2021-02-14 11:37:02 -08:00
|
|
|
finally:
|
|
|
|
self.vapi.cli("show error")
|
|
|
|
|
|
|
|
def test_arping_ip4_garp_api(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""arping ip4 gratuitous arp API test"""
|
2021-02-14 11:37:02 -08:00
|
|
|
try:
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ret = self.vapi.arping(
|
|
|
|
address=self.pg1.local_ip4,
|
|
|
|
sw_if_index=self.pg1.sw_if_index,
|
|
|
|
is_garp=1,
|
|
|
|
repeat=5,
|
|
|
|
interval=0.1,
|
|
|
|
)
|
2021-02-14 11:37:02 -08:00
|
|
|
self.logger.info(ret)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ret = self.vapi.arping(
|
|
|
|
address=self.pg1.local_ip4, sw_if_index=self.pg1.sw_if_index, is_garp=1
|
|
|
|
)
|
2021-02-14 11:37:02 -08:00
|
|
|
self.logger.info(ret)
|
|
|
|
|
|
|
|
out = self.pg1.get_capture(6)
|
|
|
|
for p in out:
|
2022-04-26 19:02:15 +02:00
|
|
|
self.verify_arping_request(p, self.pg1.local_ip4, self.pg1.local_ip4)
|
2021-02-14 11:37:02 -08:00
|
|
|
finally:
|
|
|
|
self.vapi.cli("show error")
|
|
|
|
|
|
|
|
def test_arping_ip6_ns_cli(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""arping IP6 neighbor solicitation CLI test"""
|
2021-02-14 11:37:02 -08:00
|
|
|
try:
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
|
|
|
remote_ip6 = self.pg1.remote_ip6
|
|
|
|
|
|
|
|
ping_cmd = "arping " + remote_ip6 + "pg1 repeat 5 interval 0.1"
|
|
|
|
ret = self.vapi.cli(ping_cmd)
|
|
|
|
self.logger.info(ret)
|
|
|
|
|
|
|
|
ping_cmd = "arping " + remote_ip6 + "pg1"
|
|
|
|
ret = self.vapi.cli(ping_cmd)
|
|
|
|
self.logger.info(ret)
|
|
|
|
|
|
|
|
out = self.pg1.get_capture(6)
|
|
|
|
for p in out:
|
2022-04-26 19:02:15 +02:00
|
|
|
self.verify_arping_ip6_ns(p, self.pg1.local_ip6, self.pg1.remote_ip6)
|
2021-02-14 11:37:02 -08:00
|
|
|
finally:
|
|
|
|
self.vapi.cli("show error")
|
|
|
|
|
|
|
|
def test_arping_ip6_ns_api(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""arping ip6 neighbor solicitation API test"""
|
2021-02-14 11:37:02 -08:00
|
|
|
try:
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
|
|
|
remote_ip6 = self.pg1.remote_ip6
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ret = self.vapi.arping(
|
|
|
|
address=remote_ip6,
|
|
|
|
sw_if_index=self.pg1.sw_if_index,
|
|
|
|
is_garp=0,
|
|
|
|
repeat=5,
|
|
|
|
interval=0.1,
|
|
|
|
)
|
2021-02-14 11:37:02 -08:00
|
|
|
self.logger.info(ret)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ret = self.vapi.arping(
|
|
|
|
address=remote_ip6, sw_if_index=self.pg1.sw_if_index, is_garp=0
|
|
|
|
)
|
2021-02-14 11:37:02 -08:00
|
|
|
self.logger.info(ret)
|
|
|
|
|
|
|
|
out = self.pg1.get_capture(6)
|
|
|
|
for p in out:
|
2022-04-26 19:02:15 +02:00
|
|
|
self.verify_arping_ip6_ns(p, self.pg1.local_ip6, self.pg1.remote_ip6)
|
2021-02-14 11:37:02 -08:00
|
|
|
finally:
|
|
|
|
self.vapi.cli("show error")
|
|
|
|
|
|
|
|
def test_arping_ip6_na_cli(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""arping ip6 neighbor advertisement CLI test"""
|
2021-02-14 11:37:02 -08:00
|
|
|
try:
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ping_cmd = (
|
|
|
|
"arping gratuitous" + self.pg1.local_ip6 + "pg1 repeat 5 interval 0.1"
|
|
|
|
)
|
2021-02-14 11:37:02 -08:00
|
|
|
ret = self.vapi.cli(ping_cmd)
|
|
|
|
self.logger.info(ret)
|
|
|
|
|
|
|
|
ping_cmd = "arping gratuitous" + self.pg1.local_ip6 + "pg1"
|
|
|
|
ret = self.vapi.cli(ping_cmd)
|
|
|
|
self.logger.info(ret)
|
|
|
|
|
|
|
|
out = self.pg1.get_capture(6)
|
|
|
|
for p in out:
|
2022-04-26 19:02:15 +02:00
|
|
|
self.verify_arping_ip6_na(p, self.pg1.local_ip6, self.pg1.local_ip6)
|
2021-02-14 11:37:02 -08:00
|
|
|
finally:
|
|
|
|
self.vapi.cli("show error")
|
|
|
|
|
|
|
|
def test_arping_ip6_na_api(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""arping ip6 neighbor advertisement API test"""
|
2021-02-14 11:37:02 -08:00
|
|
|
try:
|
|
|
|
self.pg_enable_capture(self.pg_interfaces)
|
|
|
|
self.pg_start()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ret = self.vapi.arping(
|
|
|
|
address=self.pg1.local_ip6,
|
|
|
|
sw_if_index=self.pg1.sw_if_index,
|
|
|
|
is_garp=1,
|
|
|
|
repeat=5,
|
|
|
|
interval=0.1,
|
|
|
|
)
|
2021-02-14 11:37:02 -08:00
|
|
|
self.logger.info(ret)
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
ret = self.vapi.arping(
|
|
|
|
address=self.pg1.local_ip6, sw_if_index=self.pg1.sw_if_index, is_garp=1
|
|
|
|
)
|
2021-02-14 11:37:02 -08:00
|
|
|
self.logger.info(ret)
|
|
|
|
|
|
|
|
out = self.pg1.get_capture(6)
|
|
|
|
for p in out:
|
2022-04-26 19:02:15 +02:00
|
|
|
self.verify_arping_ip6_na(p, self.pg1.local_ip6, self.pg1.local_ip6)
|
2021-02-14 11:37:02 -08:00
|
|
|
finally:
|
|
|
|
self.vapi.cli("show error")
|
|
|
|
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
if __name__ == "__main__":
|
2021-02-14 11:37:02 -08:00
|
|
|
unittest.main(testRunner=VppTestRunner)
|