blob: ac237ef9d90e2ee8e75015531da8d96f74dd001b [file] [log] [blame]
Andrew Yourtchenkofa1456a2016-11-11 16:32:52 +00001run lua -- collectgarbage("stop")
2
3shell vppbuild
4run vppbuild stty -echo
5run vppbuild sudo -u ubuntu -i bash -c "(cd vpp && make plugins && echo ALLGOOD)"
6expect vppbuild ALLGOOD
7
8shell s0
9shell s1
10shell s2
11
12
13cd s1
14unshare -n /bin/bash
15/sbin/ifconfig -a
16^D^D^D
17
18cd s2
19unshare -n /bin/bash
20/sbin/ifconfig -a
21^D^D^D
22
23
24cd lua
25
26function session_get_bash_pid(s)
27 if not has_session(s) then
28 return nil
29 end
30 local fname = "/tmp/lute-"..s.."-pid.txt"
31
32 session_exec(s, "echo $$ >" .. fname)
33 -- it's a dirty hack but it's quick
34 sleep(0.5)
35 local pid = io.lines(fname)()
36 print("Got pid for " .. s .. " : " .. tostring(pid))
37 return(tonumber(pid))
38end
39
40function session_connect_with(s0, s1)
41 -- local pid0 = tostring(session_get_bash_pid(s0))
42 local pid1 = tostring(session_get_bash_pid(s1))
43 local eth_options = { "rx", "tx", "sg", "tso", "ufo", "gso", "gro", "lro", "rxvlan", "txvlan", "rxhash" }
44 local this_end = s0 .. "_" .. s1
45 local other_end = s1 .. "_" .. s0
46 session_exec(s0, "ip link add name " .. this_end .. " type veth peer name " .. other_end)
47 session_exec(s0, "ip link set dev " .. this_end .. " up promisc on")
48 for i, option in ipairs(eth_options) do
49 session_exec(s0, "/sbin/ethtool --offload " .. this_end .. " " .. option .. " off")
50 session_exec(s0, "/sbin/ethtool --offload " .. other_end .. " " .. option .. " off")
51 end
52 session_exec(s0, "ip link set dev " .. other_end .. " up promisc on netns /proc/" .. pid1 .. "/ns/net")
53 sleep(0.5)
54end
55
56^D^D^D
57run lua session_connect_with("s0", "s1")
58run lua session_connect_with("s0", "s2")
59
60cd s1
61ip -6 addr add dev s1_s0 2001:db8:1::1/64
62ip -4 addr add dev s1_s0 192.0.2.1/24
63ip link set dev s1_s0 up promisc on
64^D^D^D
65
66cd s2
67ip -6 addr add dev s2_s0 2001:db8:1::2/64
68ip -6 addr add dev s2_s0 2001:db8:1::3/64
69ip -6 addr add dev s2_s0 2001:db8:1::4/64
70ip -4 addr add dev s2_s0 192.0.2.2/24
71ip -4 addr add dev s2_s0:1 192.0.2.3/24
72ip -4 addr add dev s2_s0:2 192.0.2.4/24
73ip link set dev s2_s0 up promisc on
74^D^D^D
75
76run s1 ip addr
77run s2 ip addr
78shell VPP
79cd VPP
80cd /home/ubuntu/vpp
81make debug
82r
83^D^D^D
84expect VPP DBGvpp#
85
86cd lua
87-- Initialization of the Lua environment for talking to VPP
88vpp = require("vpp-lapi")
89root_dir = "/home/ubuntu/vpp"
90pneum_path = root_dir .. "/build-root/install-vpp_debug-native/vpp-api/lib64/libpneum.so"
91vpp:init({ pneum_path = pneum_path })
92vpp:consume_api(root_dir .. "/build-root/install-vpp_debug-native/vlib-api/vlibmemory/memclnt.api")
93vpp:consume_api(root_dir .. "/build-root/install-vpp_debug-native/vpp/vpp-api/vpe.api")
94vpp:connect("aytest")
95vpp:consume_api(root_dir .. "/plugins/acl-plugin/acl/acl.api", "acl")
96
97^D^D^D
98
99cd lua
100
101reply = vpp:api_call("af_packet_create", { host_if_name = "s0_s1", hw_addr = "AAAAAA" })
102vpp_if_to_s1 = reply[1].sw_if_index
103
104reply = vpp:api_call("af_packet_create", { host_if_name = "s0_s2", hw_addr = "AAAAAA" })
105vpp_if_to_s2 = reply[1].sw_if_index
106
107ifaces = { vpp_if_to_s1, vpp_if_to_s2 }
108
109reply = vpp:api_call("sw_interface_set_flags", { sw_if_index = vpp_if_to_s1, admin_up_down = 1, link_up_down = 1 })
110print(vpp.dump(reply))
111reply = vpp:api_call("sw_interface_set_flags", { sw_if_index = vpp_if_to_s2, admin_up_down = 1, link_up_down = 1 })
112print(vpp.dump(reply))
113
114bd_id = 42
115
116reply = vpp:api_call("bridge_domain_add_del", { bd_id = bd_id, flood = 1, uu_flood = 1, forward = 1, learn = 1, arp_term = 0, is_add = 1 })
117print(vpp.dump(reply))
118
119for i, v in ipairs(ifaces) do
120 reply = vpp:api_call("sw_interface_set_l2_bridge", { rx_sw_if_index = v, bd_id = bd_id, shg = 0, bvi = 0, enable = 1 } )
121 print(vpp.dump(reply))
122end
123
124^D^D^D
125
126run s1 ping -c 3 192.0.2.2
127expect s1 packet loss
128run s1 ping -c 3 192.0.2.3
129expect s1 packet loss
130run s1 ping -c 3 192.0.2.4
131expect s1 packet loss
132run s1 ping6 -c 3 2001:db8:1::2
133expect s1 packet loss
134run s1 ping6 -c 3 2001:db8:1::3
135expect s1 packet loss
136run s1 ping6 -c 3 2001:db8:1::4
137expect s1 packet loss
138
139
140cd lua
141--- ACL testing
142
143--[[ temporary comment out
144
145reply = vpp:api_call("acl_del", { context = 42, acl_index = 230 })
146print(vpp.dump(reply))
147print("---")
148
149reply = vpp:api_call("acl_del", { context = 42, acl_index = 8 })
150print(vpp.dump(reply))
151print("---")
152
153reply = vpp:api_call("acl_del", { context = 42, acl_index = 15 })
154print(vpp.dump(reply))
155print("---")
156
157reply = vpp:api_call("acl_add", { context = 42, count = 2, r = { { is_permit = 1, is_ipv6 = 1 }, { is_permit = 0, is_ipv6 = 1 } } })
158print(vpp.dump(reply))
159print("---")
160interface_acl_in = reply[1].acl_index
161
162reply = vpp:api_call("acl_add", { context = 42, count = 3, r = { { is_permit = 1, is_ipv6 = 1 }, { is_permit = 0, is_ipv6 = 1 }, { is_permit = 1, is_ipv6 = 0 } } })
163print(vpp.dump(reply))
164print("---")
165interface_acl_out = reply[1].acl_index
166
167
168reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = 0, is_add = 1, is_input = 1, acl_index = interface_acl_in })
169print(vpp.dump(reply))
170print("---")
171
172reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = 0, is_add = 1, is_input = 1, acl_index = interface_acl_in })
173print(vpp.dump(reply))
174print("---")
175
176reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = 0, is_add = 1, is_input = 0, acl_index = interface_acl_out })
177print(vpp.dump(reply))
178print("---")
179
180reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = 0, is_add = 1, is_input = 0, acl_index = interface_acl_out })
181print(vpp.dump(reply))
182print("---")
183
184reply = vpp:api_call("acl_add", { context = 42, count = 0 })
185print(vpp.dump(reply))
186print("---")
187
188acl_index_to_delete = reply[1].acl_index
189print("Deleting " .. tostring(acl_index_to_delete))
190reply = vpp:api_call("acl_del", { context = 42, acl_index = acl_index_to_delete })
191print(vpp.dump(reply))
192print("---")
193
194reply = vpp:api_call("acl_dump", { context = 42, sw_if_index = 0})
195for ri, rv in ipairs(reply) do
196 print("Reply message #" .. tostring(ri))
197 print(vpp.dump(rv))
198 for ai, av in ipairs(rv.r) do
199 print("ACL rule #" .. tostring(ai) .. " : " .. vpp.dump(av))
200 end
201
202end
203print("---")
204
205reply = vpp:api_call("acl_del", { context = 42, acl_index = interface_acl_out })
206print(vpp.dump(reply))
207print("---")
208reply = vpp:api_call("acl_del", { context = 42, acl_index = interface_acl_in })
209print(vpp.dump(reply))
210print("---")
211
212reply = vpp:api_call("acl_dump", { context = 42, sw_if_index = 0})
213print(vpp.dump(reply))
214print("---")
215
216reply = vpp:api_call("acl_dump", { context = 42, sw_if_index = 4294967295 })
217print(vpp.dump(reply))
218print("---")
219
220
221]] -- end of comment out
222
223---- Should be nothing ^^
224r = {
225 { is_permit = 1, is_ipv6 = 1, dst_ip_addr = ip46("2001:db8:1::2"), dst_ip_prefix_len = 128 },
226 { is_permit = 0, is_ipv6 = 1, dst_ip_addr = ip46("2001:db8:1::3"), dst_ip_prefix_len = 128 },
227 { is_permit = 1, is_ipv6 = 1, dst_ip_addr = ip46("2001:db8::"), dst_ip_prefix_len = 32 },
228 { is_permit = 1, is_ipv6 = 0, dst_ip_addr = ip46("192.0.2.2"), dst_ip_prefix_len = 32},
229 { is_permit = 0, is_ipv6 = 0, dst_ip_addr = ip46("192.0.2.3"), dst_ip_prefix_len = 32 },
230}
231
232reply = vpp:api_call("acl_add", { context = 42, count = 5, r = r })
233print(vpp.dump(reply))
234print("---")
235interface_acl_in = reply[1].acl_index
236
237reply = vpp:api_call("acl_add", { context = 42, count = 3, r = { { is_permit = 1, is_ipv6 = 1 }, { is_permit = 0, is_ipv6 = 1 }, { is_permit = 1, is_ipv6 = 0 } } })
238print(vpp.dump(reply))
239print("---")
240interface_acl_out = reply[1].acl_in
241
242reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = vpp_if_to_s1, is_add = 1, is_input = 1, acl_index = interface_acl_in })
243print(vpp.dump(reply))
244print("---")
245
246--- TEST OUTBOUND ACL
247
248r1 = {
249 { is_permit = 1, is_ipv6 = 1, src_ip_addr = ip46("2001:db8:1::1"), src_ip_prefix_len = 128, dst_ip_addr = ip46("2001:db8:1::2"), dst_ip_prefix_len = 128 },
250 { is_permit = 0, is_ipv6 = 1, src_ip_addr = ip46("2001:db8:1::1"), src_ip_prefix_len = 128, dst_ip_addr = ip46("2001:db8:1::4"), dst_ip_prefix_len = 128 },
251 { is_permit = 2, is_ipv6 = 0 }
252}
253
254reply = vpp:api_call("acl_add", { context = 42, count = 3, r = r1 })
255print(vpp.dump(reply))
256print("---")
257interface_acl_out = reply[1].acl_index
258
259reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = vpp_if_to_s2, is_add = 1, is_input = 0, acl_index = interface_acl_out })
260print(vpp.dump(reply))
261print("---")
262
263r2 = {
264 { is_permit = 1, is_ipv6 = 1 },
265 { is_permit = 0, is_ipv6 = 0 }
266}
267
268reply = vpp:api_call("acl_add", { context = 42, count = 2, r = r2 })
269print(vpp.dump(reply))
270print("---")
271second_interface_acl_in = reply[1].acl_index
272
273reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = vpp_if_to_s2, is_add = 1, is_input = 1, acl_index = second_interface_acl_in })
274print(vpp.dump(reply))
275print("---")
276
277^D^D^D
278
279run VPP show classify tables
280run VPP clear trace
281run VPP trace add af-packet-input 100
282run s2 nc -v -l -p 22
283run s1 nc 192.0.2.2 22
284run s1 echo
285sleep 1
286run s1 break
287sleep 1
288run VPP show trace
289expect VPP match: outacl 2 rule 2
290run VPP show classify tables
291
292
293run VPP show classify tables
294run VPP clear trace
295run VPP trace add af-packet-input 100
296run s2 nc -v -l -p 22
297run s1 nc 192.0.2.2 22
298run s1 echo
299sleep 1
300run s1 break
301sleep 1
302run VPP show trace
303expect VPP match: outacl 2 rule 2
304run VPP show classify tables
305
306
307run lua print("ALL GOOD!")
308