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 *
16 # 1:1 Shared IPv4 address, shared BR (16) VPP CLI
27 ip4_pfx = ip_network(ip4_pfx_str)
28 ip6_src = ip_address(ip6_src_str)
29 ip6_dst = ip_network(ip6_pfx_str)
30 ip6_nul = IPv6Address("0::0")
31 mod = ip4_pfx.num_addresses / 1024
33 for i in range(ip4_pfx.num_addresses):
49 # print "Return from map_add_domain", t
51 print("map_add_domain failed")
54 print(f"map_add_domain failed, {t}")
56 for psid in range(0x1 << int(psid_len)):
61 (ip6_dst[(i * (0x1 << int(psid_len))) + psid]).packed,
64 # print "Return from map_add_del_rule", r
66 if ip6_src_ecmp and not i % mod:
69 print(f"Running time: {time.clock() - a}")
72 class TestMAP(unittest.TestCase):
74 def test_delete_all(self):
75 t = map_domain_dump(0)
76 self.assertNotEqual(t, None)
77 print(f"Number of domains configured: {len(t)}")
79 ts = map_del_domain(0, d.domainindex)
80 self.assertNotEqual(ts, None)
81 t = map_domain_dump(0)
82 self.assertNotEqual(t, None)
83 print(f"Number of domains configured: {len(t)}")
84 self.assertEqual(len(t), 0)/
88 def test_a_million_rules(self):
89 ip4_pfx = "192.0.2.0/24"
90 ip6_pfx = "2001:db8::/32"
91 ip6_src = "2001:db8::1"
95 lw46_shared(ip4_pfx, ip6_pfx, ip6_src, ea_bits_len, psid_offset, psid_len)
99 # RX thread, that should sit on blocking vpe_api_read()
110 class RXThread(threading.Thread):
112 threading.Thread.__init__(self)
121 id = unpack(">H", msg[0:2])
122 size = unpack(">H", msg[2:4])
123 print(f"Received {id} of size {size}")
133 rxthread = RXThread()
134 rxthread.setDaemon(True)
136 print(f"Connect {connect_to_vpe('client124')}")
140 print("After thread started")
142 # pneum_kill_thread()
143 print("After thread killed")
145 # t = show_version(0)
146 # print "Result from show version", t
149 f"{timeit.timeit('t = show_version(0)', number=1000, setup='from __main__ import show_version')}"
152 # print timeit.timeit('control_ping(0)', number=10, setup="from __main__ import control_ping")
155 disconnect_from_vpe()
159 print(f"{t.program} {t.version}{t.builddate}{t.builddirectory}")
163 t = map_domain_dump(0)
165 print('show map domain failed')
168 print("IP6 prefix:",str(IPv6Address(d.ip6prefix)))
169 print( "IP4 prefix:",str(IPv4Address(d.ip4prefix)))
172 suite = unittest.TestLoader().loadTestsFromTestCase(TestMAP)
173 unittest.TextTestRunner(verbosity=2).run(suite)
175 disconnect_from_vpe()