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