2 """CRUD tests of APIs (Create, Read, Update, Delete) HLD:
4 - interface up/down/add/delete - interface type:
10 - tuntap (root privileges needed)
16 from scapy.layers.inet import IP, ICMP
17 from scapy.layers.l2 import Ether
19 from framework import VppTestCase, VppTestRunner
22 class TestLoopbackInterfaceCRUD(VppTestCase):
29 super(TestLoopbackInterfaceCRUD, cls).setUpClass()
31 cls.create_pg_interfaces(range(1))
32 for i in cls.pg_interfaces:
40 def create_icmp_stream(src_if, dst_ifs):
43 :param VppInterface src_if: Packets are send to this interface,
44 using this interfaces remote host.
45 :param list dst_ifs: IPv4 ICMP requests are send to interfaces
47 :return: List of generated packets.
51 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
52 IP(src=src_if.remote_ip4, dst=i.local_ip4) /
53 ICMP(id=i.sw_if_index, type='echo-request'))
57 def verify_icmp(self, capture, request_src_if, dst_ifs):
60 :param capture: Capture to verify.
61 :param VppInterface request_src_if: Interface where was send packets.
62 :param list dst_ifs: Interfaces where was generated IPv4 ICMP requests.
72 info = (ip.src, ip.dst, icmp.type, icmp.id)
73 rcvd_icmp_pkts.append(info)
76 # 0 - icmp echo response
77 info = (i.local_ip4, request_src_if.remote_ip4, 0, i.sw_if_index)
78 self.assertIn(info, rcvd_icmp_pkts)
82 loopbacks = self.create_loopback_interfaces(range(20))
84 i.local_ip4_prefix_len = 32
88 # read (check sw if dump, ip4 fib, ip6 fib)
89 if_dump = self.vapi.sw_interface_dump()
90 fib4_dump = self.vapi.ip_fib_dump()
92 self.assertTrue(i.is_interface_config_in_dump(if_dump))
93 self.assertTrue(i.is_ip4_entry_in_fib_dump(fib4_dump))
96 stream = self.create_icmp_stream(self.pg0, loopbacks)
97 self.pg0.add_stream(stream)
98 self.pg_enable_capture(self.pg_interfaces)
100 capture = self.pg0.get_capture(expected_count=len(stream))
102 self.verify_icmp(capture, self.pg0, loopbacks)
106 i.remove_vpp_config()
108 # read (check not in sw if dump, ip4 fib, ip6 fib)
109 if_dump = self.vapi.sw_interface_dump()
110 fib4_dump = self.vapi.ip_fib_dump()
112 self.assertFalse(i.is_interface_config_in_dump(if_dump))
113 self.assertFalse(i.is_ip4_entry_in_fib_dump(fib4_dump))
116 stream = self.create_icmp_stream(self.pg0, loopbacks)
117 self.pg0.add_stream(stream)
118 self.pg_enable_capture(self.pg_interfaces)
120 self.pg0.assert_nothing_captured()
124 loopbacks = self.create_loopback_interfaces(range(20))
126 i.local_ip4_prefix_len = 32
135 # read (check not in sw if dump, ip4 fib, ip6 fib)
136 if_dump = self.vapi.sw_interface_dump()
137 fib4_dump = self.vapi.ip_fib_dump()
139 self.assertTrue(i.is_interface_config_in_dump(if_dump))
140 self.assertFalse(i.is_ip4_entry_in_fib_dump(fib4_dump))
143 stream = self.create_icmp_stream(self.pg0, loopbacks)
144 self.pg0.add_stream(stream)
145 self.pg_enable_capture(self.pg_interfaces)
147 self.pg0.assert_nothing_captured()
150 if __name__ == '__main__':
151 unittest.main(testRunner=VppTestRunner)