3 import time, argparse, sys, cmd, unittest
4 from ipaddress import *
6 parser = argparse.ArgumentParser(description="VPP MAP test")
7 parser.add_argument("-i", nargs="*", action="store", dest="inputdir")
8 args = parser.parse_args()
10 for dir in args.inputdir:
12 from vpp_papi import *
15 # 1:1 Shared IPv4 address, shared BR (16) VPP CLI
26 ip4_pfx = ip_network(ip4_pfx_str)
27 ip6_src = ip_address(ip6_src_str)
28 ip6_dst = ip_network(ip6_pfx_str)
29 ip6_nul = IPv6Address("0::0")
30 mod = ip4_pfx.num_addresses / 1024
32 for i in range(ip4_pfx.num_addresses):
48 # print "Return from map_add_domain", t
50 print("map_add_domain failed")
53 print(f"map_add_domain failed, {t}")
55 for psid in range(0x1 << int(psid_len)):
60 (ip6_dst[(i * (0x1 << int(psid_len))) + psid]).packed,
63 # print "Return from map_add_del_rule", r
65 if ip6_src_ecmp and not i % mod:
68 print(f"Running time: {time.clock() - a}")
71 class TestMAP(unittest.TestCase):
73 def test_delete_all(self):
74 t = map_domain_dump(0)
75 self.assertNotEqual(t, None)
76 print(f"Number of domains configured: {len(t)}")
78 ts = map_del_domain(0, d.domainindex)
79 self.assertNotEqual(ts, None)
80 t = map_domain_dump(0)
81 self.assertNotEqual(t, None)
82 print(f"Number of domains configured: {len(t)}")
83 self.assertEqual(len(t), 0)/
87 def test_a_million_rules(self):
88 ip4_pfx = "192.0.2.0/24"
89 ip6_pfx = "2001:db8::/32"
90 ip6_src = "2001:db8::1"
94 lw46_shared(ip4_pfx, ip6_pfx, ip6_src, ea_bits_len, psid_offset, psid_len)
98 # RX thread, that should sit on blocking vpe_api_read()
109 class RXThread(threading.Thread):
111 threading.Thread.__init__(self)
120 id = unpack(">H", msg[0:2])
121 size = unpack(">H", msg[2:4])
122 print(f"Received {id} of size {size}")
132 rxthread = RXThread()
133 rxthread.setDaemon(True)
135 print(f"Connect {connect_to_vpe('client124')}")
139 print("After thread started")
141 # pneum_kill_thread()
142 print("After thread killed")
144 # t = show_version(0)
145 # print "Result from show version", t
148 f"{timeit.timeit('t = show_version(0)', number=1000, setup='from __main__ import show_version')}"
151 # print timeit.timeit('control_ping(0)', number=10, setup="from __main__ import control_ping")
154 disconnect_from_vpe()
158 print(f"{t.program} {t.version}{t.builddate}{t.builddirectory}")
162 t = map_domain_dump(0)
164 print('show map domain failed')
167 print("IP6 prefix:",str(IPv6Address(d.ip6prefix)))
168 print( "IP4 prefix:",str(IPv4Address(d.ip4prefix)))
171 suite = unittest.TestLoader().loadTestsFromTestCase(TestMAP)
172 unittest.TextTestRunner(verbosity=2).run(suite)
174 disconnect_from_vpe()