blob: 21388d495260aefd7061a784f1ba64313a5c87aa [file] [log] [blame]
Ole Troan6855f6c2016-04-09 03:16:30 +02001#!/usr/bin/env python
2
3import time,argparse,sys,cmd, unittest
4from ipaddress import *
5
6parser = argparse.ArgumentParser(description='VPP MAP test')
7parser.add_argument('-i', nargs='*', action="store", dest="inputdir")
8args = parser.parse_args()
9
10for dir in args.inputdir:
11 sys.path.append(dir)
12from vpp_papi import *
13
14#
15# 1:1 Shared IPv4 address, shared BR (16) VPP CLI
16#
17def lw46_shared(ip4_pfx_str, ip6_pfx_str, ip6_src_str, ea_bits_len, psid_offset, psid_len, ip6_src_ecmp = False):
18 ip4_pfx = ip_network(ip4_pfx_str)
19 ip6_src = ip_address(ip6_src_str)
20 ip6_dst = ip_network(ip6_pfx_str)
21 ip6_nul = IPv6Address(u'0::0')
22 mod = ip4_pfx.num_addresses / 1024
23
24 for i in range(ip4_pfx.num_addresses):
25 a = time.clock()
26 t = map_add_domain(0, ip6_nul.packed, ip4_pfx[i].packed, ip6_src.packed, 0, 32, 128, ea_bits_len, psid_offset, psid_len, 0, 0)
27 #print "Return from map_add_domain", t
28 if t == None:
29 print "map_add_domain failed"
30 continue
31 if t.retval != 0:
32 print "map_add_domain failed", t
33 continue
34 for psid in range(0x1 << int(psid_len)):
35 r = map_add_del_rule(0, t.index, 1, (ip6_dst[(i * (0x1<<int(psid_len))) + psid]).packed, psid)
36 #print "Return from map_add_del_rule", r
37
38 if ip6_src_ecmp and not i % mod:
39 ip6_src = ip6_src + 1
40
41 print "Running time:", time.clock() - a
42
43class TestMAP(unittest.TestCase):
44 '''
45 def test_delete_all(self):
46 t = map_domain_dump(0)
47 self.assertNotEqual(t, None)
48 print "Number of domains configured: ", len(t)
49 for d in t:
50 ts = map_del_domain(0, d.domainindex)
51 self.assertNotEqual(ts, None)
52 t = map_domain_dump(0)
53 self.assertNotEqual(t, None)
54 print "Number of domains configured: ", len(t)
55 self.assertEqual(len(t), 0)
56
57 '''
58
59 def test_a_million_rules(self):
60 ip4_pfx = u'192.0.2.0/24'
61 ip6_pfx = u'2001:db8::/32'
62 ip6_src = u'2001:db8::1'
63 psid_offset = 6
64 psid_len = 6
65 ea_bits_len = 0
66 lw46_shared(ip4_pfx, ip6_pfx, ip6_src, ea_bits_len, psid_offset, psid_len)
67
68#
69# RX thread, that should sit on blocking vpe_api_read()
70
71#
72
73
74#
75#
76#
77import threading
78class RXThread (threading.Thread):
79 def __init__(self):
80 threading.Thread.__init__(self)
81
82 def run(self):
83 print "Starting "
84 i = 0
85 while True:
86 msg = vpe_api_read()
87 if msg:
88 #print msg
89 id = unpack('>H', msg[0:2])
90 size = unpack('>H', msg[2:4])
91 print "Received", id, "of size", size
92 i += 1
93 #del msg
94 continue
95
96 #time.sleep(0.001)
97 return
98
99# Create RX thread
100rxthread = RXThread()
101rxthread.setDaemon(True)
102
103print "Connect", connect_to_vpe("client124")
104import timeit
105rxthread.start()
106print "After thread started"
107
108#pneum_kill_thread()
109print "After thread killed"
110
111#t = show_version(0)
112#print "Result from show version", t
113
114print timeit.timeit('t = show_version(0)', number=1000, setup="from __main__ import show_version")
115time.sleep(10)
116#print timeit.timeit('control_ping(0)', number=10, setup="from __main__ import control_ping")
117
118
119disconnect_from_vpe()
120sys.exit()
121
122
123print t.program, t.version,t.builddate,t.builddirectory
124
125'''
126
127t = map_domain_dump(0)
128if not t:
129 print('show map domain failed')
130
131for d in t:
132 print("IP6 prefix:",str(IPv6Address(d.ip6prefix)))
133 print( "IP4 prefix:",str(IPv4Address(d.ip4prefix)))
134'''
135
136suite = unittest.TestLoader().loadTestsFromTestCase(TestMAP)
137unittest.TextTestRunner(verbosity=2).run(suite)
138
139disconnect_from_vpe()
140
141