Andrew Yourtchenko | fa1456a | 2016-11-11 16:32:52 +0000 | [diff] [blame] | 1 | shell vppbuild |
| 2 | run vppbuild stty -echo |
| 3 | run vppbuild sudo -u ubuntu -i bash -c "(cd vpp && make plugins && echo ALLGOOD)" |
| 4 | expect vppbuild ALLGOOD |
| 5 | |
| 6 | shell s0 |
| 7 | shell s1 |
| 8 | shell s2 |
| 9 | |
| 10 | |
| 11 | cd s1 |
| 12 | unshare -n /bin/bash |
| 13 | /sbin/ifconfig -a |
| 14 | ^D^D^D |
| 15 | |
| 16 | cd s2 |
| 17 | unshare -n /bin/bash |
| 18 | /sbin/ifconfig -a |
| 19 | ^D^D^D |
| 20 | |
| 21 | |
| 22 | cd lua |
| 23 | |
| 24 | function 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)) |
| 36 | end |
| 37 | |
| 38 | function 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) |
| 52 | end |
| 53 | |
| 54 | ^D^D^D |
| 55 | run lua session_connect_with("s0", "s1") |
| 56 | run lua session_connect_with("s0", "s2") |
| 57 | |
| 58 | cd s1 |
| 59 | ip -6 addr add dev s1_s0 2001:db8:1::1/64 |
| 60 | ip -4 addr add dev s1_s0 192.0.2.1/24 |
| 61 | ip link set dev s1_s0 up promisc on |
| 62 | ^D^D^D |
| 63 | |
| 64 | cd s2 |
| 65 | ip -6 addr add dev s2_s0 2001:db8:1::2/64 |
| 66 | ip -6 addr add dev s2_s0 2001:db8:1::3/64 |
| 67 | ip -6 addr add dev s2_s0 2001:db8:1::4/64 |
| 68 | ip -4 addr add dev s2_s0 192.0.2.2/24 |
| 69 | ip -4 addr add dev s2_s0:1 192.0.2.3/24 |
| 70 | ip -4 addr add dev s2_s0:2 192.0.2.4/24 |
| 71 | ip link set dev s2_s0 up promisc on |
| 72 | ^D^D^D |
| 73 | |
| 74 | run s1 ip addr |
| 75 | run s2 ip addr |
| 76 | shell VPP |
| 77 | cd VPP |
| 78 | cd /home/ubuntu/vpp |
| 79 | make debug |
| 80 | r |
| 81 | ^D^D^D |
| 82 | expect VPP DBGvpp# |
| 83 | |
| 84 | cd lua |
| 85 | -- Initialization of the Lua environment for talking to VPP |
| 86 | vpp = require("vpp-lapi") |
| 87 | root_dir = "/home/ubuntu/vpp" |
| 88 | pneum_path = root_dir .. "/build-root/install-vpp_debug-native/vpp-api/lib64/libpneum.so" |
| 89 | vpp:init({ pneum_path = pneum_path }) |
| 90 | vpp:consume_api(root_dir .. "/build-root/install-vpp_debug-native/vlib-api/vlibmemory/memclnt.api") |
| 91 | vpp:consume_api(root_dir .. "/build-root/install-vpp_debug-native/vpp/vpp-api/vpe.api") |
| 92 | vpp:connect("aytest") |
| 93 | vpp:consume_api(root_dir .. "/plugins/acl-plugin/acl/acl.api", "acl") |
| 94 | |
| 95 | ^D^D^D |
| 96 | |
| 97 | cd lua |
| 98 | |
| 99 | reply = vpp:api_call("af_packet_create", { host_if_name = "s0_s1", hw_addr = "AAAAAA" }) |
| 100 | vpp_if_to_s1 = reply[1].sw_if_index |
| 101 | |
| 102 | reply = vpp:api_call("af_packet_create", { host_if_name = "s0_s2", hw_addr = "AAAAAA" }) |
| 103 | vpp_if_to_s2 = reply[1].sw_if_index |
| 104 | |
| 105 | ifaces = { vpp_if_to_s1, vpp_if_to_s2 } |
| 106 | |
| 107 | reply = vpp:api_call("sw_interface_set_flags", { sw_if_index = vpp_if_to_s1, admin_up_down = 1, link_up_down = 1 }) |
| 108 | print(vpp.dump(reply)) |
| 109 | reply = vpp:api_call("sw_interface_set_flags", { sw_if_index = vpp_if_to_s2, admin_up_down = 1, link_up_down = 1 }) |
| 110 | print(vpp.dump(reply)) |
| 111 | |
| 112 | bd_id = 42 |
| 113 | |
| 114 | reply = 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 }) |
| 115 | print(vpp.dump(reply)) |
| 116 | |
| 117 | for 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)) |
| 120 | end |
| 121 | |
| 122 | ^D^D^D |
| 123 | |
| 124 | run s1 ping -c 3 192.0.2.2 |
| 125 | expect s1 packet loss |
| 126 | run s1 ping -c 3 192.0.2.3 |
| 127 | expect s1 packet loss |
| 128 | run s1 ping -c 3 192.0.2.4 |
| 129 | expect s1 packet loss |
| 130 | run s1 ping6 -c 3 2001:db8:1::2 |
| 131 | expect s1 packet loss |
| 132 | run s1 ping6 -c 3 2001:db8:1::3 |
| 133 | expect s1 packet loss |
| 134 | run s1 ping6 -c 3 2001:db8:1::4 |
| 135 | expect s1 packet loss |
| 136 | |
| 137 | |
| 138 | cd lua |
| 139 | --- ACL testing |
| 140 | |
| 141 | --[[ temporary comment out |
| 142 | |
| 143 | reply = vpp:api_call("acl_del", { context = 42, acl_index = 230 }) |
| 144 | print(vpp.dump(reply)) |
| 145 | print("---") |
| 146 | |
| 147 | reply = vpp:api_call("acl_del", { context = 42, acl_index = 8 }) |
| 148 | print(vpp.dump(reply)) |
| 149 | print("---") |
| 150 | |
| 151 | reply = vpp:api_call("acl_del", { context = 42, acl_index = 15 }) |
| 152 | print(vpp.dump(reply)) |
| 153 | print("---") |
| 154 | |
| 155 | reply = vpp:api_call("acl_add", { context = 42, count = 2, r = { { is_permit = 1, is_ipv6 = 1 }, { is_permit = 0, is_ipv6 = 1 } } }) |
| 156 | print(vpp.dump(reply)) |
| 157 | print("---") |
| 158 | interface_acl_in = reply[1].acl_index |
| 159 | |
| 160 | reply = 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 } } }) |
| 161 | print(vpp.dump(reply)) |
| 162 | print("---") |
| 163 | interface_acl_out = reply[1].acl_index |
| 164 | |
| 165 | |
| 166 | reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = 0, is_add = 1, is_input = 1, acl_index = interface_acl_in }) |
| 167 | print(vpp.dump(reply)) |
| 168 | print("---") |
| 169 | |
| 170 | reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = 0, is_add = 1, is_input = 1, acl_index = interface_acl_in }) |
| 171 | print(vpp.dump(reply)) |
| 172 | print("---") |
| 173 | |
| 174 | reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = 0, is_add = 1, is_input = 0, acl_index = interface_acl_out }) |
| 175 | print(vpp.dump(reply)) |
| 176 | print("---") |
| 177 | |
| 178 | reply = vpp:api_call("acl_interface_add_del", { context = 42, sw_if_index = 0, is_add = 1, is_input = 0, acl_index = interface_acl_out }) |
| 179 | print(vpp.dump(reply)) |
| 180 | print("---") |
| 181 | |
| 182 | reply = vpp:api_call("acl_add", { context = 42, count = 0 }) |
| 183 | print(vpp.dump(reply)) |
| 184 | print("---") |
| 185 | |
| 186 | acl_index_to_delete = reply[1].acl_index |
| 187 | print("Deleting " .. tostring(acl_index_to_delete)) |
| 188 | reply = vpp:api_call("acl_del", { context = 42, acl_index = acl_index_to_delete }) |
| 189 | print(vpp.dump(reply)) |
| 190 | print("---") |
| 191 | |
| 192 | reply = vpp:api_call("acl_dump", { context = 42, sw_if_index = 0}) |
| 193 | for 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 | |
| 200 | end |
| 201 | print("---") |
| 202 | |
| 203 | reply = vpp:api_call("acl_del", { context = 42, acl_index = interface_acl_out }) |
| 204 | print(vpp.dump(reply)) |
| 205 | print("---") |
| 206 | reply = vpp:api_call("acl_del", { context = 42, acl_index = interface_acl_in }) |
| 207 | print(vpp.dump(reply)) |
| 208 | print("---") |
| 209 | |
| 210 | reply = vpp:api_call("acl_dump", { context = 42, sw_if_index = 0}) |
| 211 | print(vpp.dump(reply)) |
| 212 | print("---") |
| 213 | |
| 214 | reply = vpp:api_call("acl_dump", { context = 42, sw_if_index = 4294967295 }) |
| 215 | print(vpp.dump(reply)) |
| 216 | print("---") |
| 217 | |
| 218 | |
| 219 | ]] -- end of comment out |
| 220 | |
| 221 | ---- Should be nothing ^^ |
| 222 | r = { |
| 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 | |
| 230 | reply = vpp:api_call("acl_add", { context = 42, count = 5, r = r }) |
| 231 | print(vpp.dump(reply)) |
| 232 | print("---") |
| 233 | interface_acl_in = reply[1].acl_index |
| 234 | |
| 235 | reply = 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 } } }) |
| 236 | print(vpp.dump(reply)) |
| 237 | print("---") |
| 238 | interface_acl_out = reply[1].acl_in |
| 239 | |
| 240 | reply = 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 }) |
| 241 | print(vpp.dump(reply)) |
| 242 | print("---") |
| 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 | |
| 250 | run VPP clear trace |
| 251 | run VPP trace add af-packet-input 100 |
| 252 | run s1 ping6 -c 3 2001:db8:1::2 |
| 253 | expect s1 packet loss |
| 254 | run VPP show trace |
| 255 | expect VPP match: inacl 0 rule 0 |
| 256 | |
| 257 | run VPP clear trace |
| 258 | run VPP trace add af-packet-input 100 |
| 259 | run s1 ping6 -c 3 2001:db8:1::3 |
| 260 | expect s1 packet loss |
| 261 | run VPP show trace |
| 262 | expect VPP match: inacl 0 rule 1 |
| 263 | |
| 264 | run VPP clear trace |
| 265 | run VPP trace add af-packet-input 100 |
| 266 | run s1 ping6 -c 3 2001:db8:1::4 |
| 267 | expect s1 packet loss |
| 268 | run VPP show trace |
| 269 | expect VPP match: inacl 0 rule 2 |
| 270 | |
| 271 | run VPP clear trace |
| 272 | run VPP trace add af-packet-input 100 |
| 273 | run s1 ping -c 3 192.0.2.2 |
| 274 | expect s1 packet loss |
| 275 | run VPP show trace |
| 276 | expect VPP match: inacl 0 rule 3 |
| 277 | |
| 278 | run VPP clear trace |
| 279 | run VPP trace add af-packet-input 100 |
| 280 | run s1 ping -c 3 192.0.2.3 |
| 281 | expect s1 packet loss |
| 282 | run VPP show trace |
| 283 | expect VPP match: inacl 0 rule 4 |
| 284 | |
| 285 | |
| 286 | cd lua |
| 287 | |
| 288 | --- TEST OUTBOUND ACL |
| 289 | |
| 290 | r1 = { |
| 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 | |
| 295 | reply = vpp:api_call("acl_add", { context = 42, count = 3, r = r1 }) |
| 296 | print(vpp.dump(reply)) |
| 297 | print("---") |
| 298 | interface_acl_out = reply[1].acl_index |
| 299 | |
| 300 | 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 }) |
| 301 | print(vpp.dump(reply)) |
| 302 | print("---") |
| 303 | |
| 304 | |
| 305 | ^D^D^D |
| 306 | |
| 307 | run VPP clear trace |
| 308 | run VPP trace add af-packet-input 100 |
| 309 | run s1 ping6 -c 3 2001:db8:1::2 |
| 310 | expect s1 packet loss |
| 311 | run VPP show trace |
| 312 | expect VPP match: outacl 2 rule 0 |
| 313 | |
| 314 | run VPP clear trace |
| 315 | run VPP trace add af-packet-input 100 |
| 316 | run s1 ping6 -c 3 2001:db8:1::3 |
| 317 | expect s1 packet loss |
| 318 | run VPP show trace |
| 319 | expect VPP match: inacl 0 rule 1 |
| 320 | |
| 321 | run VPP clear trace |
| 322 | run VPP trace add af-packet-input 100 |
| 323 | run s1 ping6 -c 3 2001:db8:1::4 |
| 324 | expect s1 packet loss |
| 325 | run VPP show trace |
| 326 | expect VPP match: outacl 2 rule 1 |
| 327 | |
| 328 | run lua print("ALL GOOD!") |
| 329 | |