1 AT_BANNER([OVN components])
3 AT_SETUP([ovn -- lexer])
4 dnl For lines without =>, input and expected output are identical.
5 dnl For lines with =>, input precedes => and expected output follows =>.
6 AT_DATA([test-cases.txt], [dnl
7 foo bar baz quuxquuxquux _abcd_ a.b.c.d a123_.456
8 "abc\u0020def" => "abc def"
9 " => error("Input ends inside quoted string.")dnl "
14 a/*/b => a error("`/*' without matching `*/'.")
16 a/b => a error("`/' is only valid as part of `//' or `/*'.") b
18 0 1 12345 18446744073709551615
19 18446744073709551616 => error("Decimal constants must be less than 2**64.")
20 9999999999999999999999 => error("Decimal constants must be less than 2**64.")
21 01 => error("Decimal constants must not have leading zeros.")
25 1/0 => error("Value contains unmasked 1-bits.")
29 1/ => error("Integer constant expected.")
31 1/0x123 => error("Value and mask have incompatible formats.")
38 0XFEDCBA9876543210 => 0xfedcba9876543210
39 0xfedcba9876543210fedcba9876543210
40 0x0000fedcba9876543210fedcba9876543210 => 0xfedcba9876543210fedcba9876543210
41 0x => error("Hex digits expected following 0x.")
42 0X => error("Hex digits expected following 0X.")
45 0x1/0x0 => error("Value contains unmasked 1-bits.")
47 0x. => error("Invalid syntax in hexadecimal constant.")
49 192.168.128.1 1.2.3.4 255.255.255.255 0.0.0.0
50 256.1.2.3 => error("Invalid numeric constant.")
52 192.168.0.0/255.255.0.0 => 192.168.0.0/16
53 192.168.0.0/255.255.255.0 => 192.168.0.0/24
54 192.168.0.0/255.255.0.255
55 192.168.0.0/255.0.0.0 => error("Value contains unmasked 1-bits.")
57 192.168.0.0/255.255.255.255 => 192.168.0.0/32
61 ff00::1234 => ff00::1234
62 2001:db8:85a3::8a2e:370:7334
63 2001:db8:85a3:0:0:8a2e:370:7334 => 2001:db8:85a3::8a2e:370:7334
64 2001:0db8:85a3:0000:0000:8a2e:0370:7334 => 2001:db8:85a3::8a2e:370:7334
66 ::ffff:c000:0280 => ::ffff:192.0.2.128
68 ::1/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff => ::1/128
71 ff00::/ff00:: => ff00::/8
74 01:23:45:67:AB:CD => 01:23:45:67:ab:cd
76 FE:DC:ba:98:76:54 => fe:dc:ba:98:76:54
77 01:00:00:00:00:00/01:00:00:00:00:00
78 ff:ff:ff:ff:ff:ff/ff:ff:ff:ff:ff:ff
79 fe:ff:ff:ff:ff:ff/ff:ff:ff:ff:ff:ff
80 ff:ff:ff:ff:ff:ff/fe:ff:ff:ff:ff:ff => error("Value contains unmasked 1-bits.")
81 fe:x => error("Invalid numeric constant.")
82 00:01:02:03:04:x => error("Invalid numeric constant.")
84 # Test that operators are tokenized as expected, even without white space.
85 (){}[[]]==!=<<=>>=!&&||..,;=<->-- => ( ) { } [[ ]] == != < <= > >= ! && || .. , ; = <-> --
86 & => error("`&' is only valid as part of `&&'.")
87 | => error("`|' is only valid as part of `||'.")
88 - => error("`-' is only valid as part of `--'.")
90 ^ => error("Invalid character `^' in input.")
92 AT_CAPTURE_FILE([input.txt])
93 sed 's/ =>.*//' test-cases.txt > input.txt
94 sed 's/.* => //' test-cases.txt > expout
95 AT_CHECK([ovstest test-ovn lex < input.txt], [0], [expout])
98 AT_SETUP([ovn -- expression parser])
99 dnl For lines without =>, input and expected output are identical.
100 dnl For lines with =>, input precedes => and expected output follows =>.
101 AT_DATA([test-cases.txt], [[
103 eth.type==0x800 => eth.type == 0x800
104 eth.type[0..15] == 0x800 => eth.type == 0x800
107 vlan.present == 1 => vlan.present
108 !(vlan.present == 0) => vlan.present
109 !(vlan.present != 1) => vlan.present
111 vlan.present == 0 => !vlan.present
112 vlan.present != 1 => !vlan.present
113 !(vlan.present == 1) => !vlan.present
114 !(vlan.present != 0) => !vlan.present
117 eth.dst[0] == 1 => eth.dst[0]
118 eth.dst[0] != 0 => eth.dst[0]
119 !(eth.dst[0] == 0) => eth.dst[0]
120 !(eth.dst[0] != 1) => eth.dst[0]
123 eth.dst[0] == 0 => !eth.dst[0]
124 eth.dst[0] != 1 => !eth.dst[0]
125 !(eth.dst[0] == 1) => !eth.dst[0]
126 !(eth.dst[0] != 0) => !eth.dst[0]
128 vlan.tci[12..15] == 0x3
129 vlan.tci == 0x3000/0xf000 => vlan.tci[12..15] == 0x3
130 vlan.tci[12..15] != 0x3
131 vlan.tci != 0x3000/0xf000 => vlan.tci[12..15] != 0x3
133 !vlan.pcp => vlan.pcp == 0
134 !(vlan.pcp) => vlan.pcp == 0
141 !(vlan.pcp != 0x4) => vlan.pcp == 0x4
142 !(vlan.pcp == 0x4) => vlan.pcp != 0x4
143 !(vlan.pcp <= 0x4) => vlan.pcp > 0x4
144 !(vlan.pcp < 0x4) => vlan.pcp >= 0x4
145 !(vlan.pcp >= 0x4) => vlan.pcp < 0x4
146 !(vlan.pcp > 0x4) => vlan.pcp <= 0x4
147 0x4 == vlan.pcp => vlan.pcp == 0x4
148 0x4 != vlan.pcp => vlan.pcp != 0x4
149 0x4 < vlan.pcp => vlan.pcp > 0x4
150 0x4 <= vlan.pcp => vlan.pcp >= 0x4
151 0x4 > vlan.pcp => vlan.pcp < 0x4
152 0x4 >= vlan.pcp => vlan.pcp <= 0x4
153 !(0x4 != vlan.pcp) => vlan.pcp == 0x4
154 !(0x4 == vlan.pcp) => vlan.pcp != 0x4
155 !(0x4 >= vlan.pcp) => vlan.pcp > 0x4
156 !(0x4 > vlan.pcp) => vlan.pcp >= 0x4
157 !(0x4 <= vlan.pcp) => vlan.pcp < 0x4
158 !(0x4 < vlan.pcp) => vlan.pcp <= 0x4
160 1 < vlan.pcp < 4 => vlan.pcp > 0x1 && vlan.pcp < 0x4
161 1 <= vlan.pcp <= 4 => vlan.pcp >= 0x1 && vlan.pcp <= 0x4
162 1 < vlan.pcp <= 4 => vlan.pcp > 0x1 && vlan.pcp <= 0x4
163 1 <= vlan.pcp < 4 => vlan.pcp >= 0x1 && vlan.pcp < 0x4
164 1 <= vlan.pcp <= 4 => vlan.pcp >= 0x1 && vlan.pcp <= 0x4
165 4 > vlan.pcp > 1 => vlan.pcp < 0x4 && vlan.pcp > 0x1
166 4 >= vlan.pcp > 1 => vlan.pcp <= 0x4 && vlan.pcp > 0x1
167 4 > vlan.pcp >= 1 => vlan.pcp < 0x4 && vlan.pcp >= 0x1
168 4 >= vlan.pcp >= 1 => vlan.pcp <= 0x4 && vlan.pcp >= 0x1
169 !(1 < vlan.pcp < 4) => vlan.pcp <= 0x1 || vlan.pcp >= 0x4
170 !(1 <= vlan.pcp <= 4) => vlan.pcp < 0x1 || vlan.pcp > 0x4
171 !(1 < vlan.pcp <= 4) => vlan.pcp <= 0x1 || vlan.pcp > 0x4
172 !(1 <= vlan.pcp < 4) => vlan.pcp < 0x1 || vlan.pcp >= 0x4
173 !(1 <= vlan.pcp <= 4) => vlan.pcp < 0x1 || vlan.pcp > 0x4
174 !(4 > vlan.pcp > 1) => vlan.pcp >= 0x4 || vlan.pcp <= 0x1
175 !(4 >= vlan.pcp > 1) => vlan.pcp > 0x4 || vlan.pcp <= 0x1
176 !(4 > vlan.pcp >= 1) => vlan.pcp >= 0x4 || vlan.pcp < 0x1
177 !(4 >= vlan.pcp >= 1) => vlan.pcp > 0x4 || vlan.pcp < 0x1
179 vlan.pcp == {1, 2, 3, 4} => vlan.pcp == 0x1 || vlan.pcp == 0x2 || vlan.pcp == 0x3 || vlan.pcp == 0x4
180 vlan.pcp == 1 || ((vlan.pcp == 2 || vlan.pcp == 3) || vlan.pcp == 4) => vlan.pcp == 0x1 || vlan.pcp == 0x2 || vlan.pcp == 0x3 || vlan.pcp == 0x4
182 vlan.pcp != {1, 2, 3, 4} => vlan.pcp != 0x1 && vlan.pcp != 0x2 && vlan.pcp != 0x3 && vlan.pcp != 0x4
183 vlan.pcp == 1 && ((vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && vlan.pcp == 0x2 && vlan.pcp == 0x3 && vlan.pcp == 0x4
185 vlan.pcp == 1 && !((vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && (vlan.pcp != 0x2 || vlan.pcp != 0x3 || vlan.pcp != 0x4)
186 vlan.pcp == 1 && (!(vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && (vlan.pcp != 0x2 || vlan.pcp != 0x3) && vlan.pcp == 0x4
187 vlan.pcp == 1 && !(!(vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && ((vlan.pcp == 0x2 && vlan.pcp == 0x3) || vlan.pcp != 0x4)
189 ip4.src == {10.0.0.0/8, 192.168.0.0/16, 172.16.20.0/24, 8.8.8.8} => ip4.src[24..31] == 0xa || ip4.src[16..31] == 0xc0a8 || ip4.src[8..31] == 0xac1014 || ip4.src == 0x8080808
190 ip6.src == ::1 => ip6.src == 0x1
192 ip4.src == 1.2.3.4 => ip4.src == 0x1020304
193 ip4.src == ::1.2.3.4/::ffff:ffff => ip4.src == 0x1020304
194 ip6.src == ::1 => ip6.src == 0x1
202 !(inport != "eth0") => inport == "eth0"
204 ip4.src == "eth0" => Integer field ip4.src is not compatible with string constant.
205 inport == 1 => String field inport is not compatible with integer constant.
207 ip4.src > {1, 2, 3} => Only == and != operators may be used with value sets.
208 eth.type > 0x800 => Only == and != operators may be used with nominal field eth.type.
209 vlan.present > 0 => Only == and != operators may be used with Boolean field vlan.present.
211 inport != "eth0" => Nominal field inport may only be tested for equality (taking enclosing `!' operators into account).
212 !(inport == "eth0") => Nominal field inport may only be tested for equality (taking enclosing `!' operators into account).
213 eth.type != 0x800 => Nominal field eth.type may only be tested for equality (taking enclosing `!' operators into account).
214 !(eth.type == 0x800) => Nominal field eth.type may only be tested for equality (taking enclosing `!' operators into account).
216 123 == 123 => Syntax error at `123' expecting field name.
218 123 == xyzzy => Syntax error at `xyzzy' expecting field name.
219 xyzzy == 1 => Syntax error at `xyzzy' expecting field name.
221 inport[1] == 1 => Cannot select subfield of string field inport.
223 eth.type[] == 1 => Syntax error at `@:>@' expecting small integer.
224 eth.type[::1] == 1 => Syntax error at `::1' expecting small integer.
225 eth.type[18446744073709551615] == 1 => Syntax error at `18446744073709551615' expecting small integer.
227 eth.type[5!] => Syntax error at `!' expecting `@:>@'.
229 eth.type[5..1] => Invalid bit range 5 to 1.
231 eth.type[12..16] => Cannot select bits 12 to 16 of 16-bit field eth.type.
233 eth.type[10] == 1 => Cannot select subfield of nominal field eth.type.
235 eth.type => Explicit `!= 0' is required for inequality test of multibit field against 0.
237 !(!(vlan.pcp)) => Explicit `!= 0' is required for inequality test of multibit field against 0.
239 123 => Syntax error at end of input expecting relational operator.
241 123 x => Syntax error at `x' expecting relational operator.
243 {1, "eth0"} => Syntax error at `"eth0"' expecting integer.
245 eth.type == xyzzy => Syntax error at `xyzzy' expecting constant.
247 (1 x) => Syntax error at `x' expecting `)'.
249 !0x800 != eth.type => Missing parentheses around operand of !.
251 eth.type == 0x800 || eth.type == 0x86dd && ip.proto == 17 => && and || must be parenthesized when used together.
253 eth.dst == {} => Syntax error at `}' expecting constant.
255 eth.src > 00:00:00:00:11:11/00:00:00:00:ff:ff => Only == and != operators may be used with masked constants. Consider using subfields instead (e.g. eth.src[0..15] > 0x1111 in place of eth.src > 00:00:00:00:11:11/00:00:00:00:ff:ff).
257 ip4.src == ::1 => 128-bit constant is not compatible with 32-bit field ip4.src.
259 1 == eth.type == 2 => Range expressions must have the form `x < field < y' or `x > field > y', with each `<' optionally replaced by `<=' or `>' by `>=').
261 eth.dst[40] x => Extra tokens at end of input.
263 sed 's/ =>.*//' test-cases.txt > input.txt
264 sed 's/.* => //' test-cases.txt > expout
265 AT_CHECK([ovstest test-ovn parse-expr < input.txt], [0], [expout])
268 AT_SETUP([ovn -- expression annotation])
269 dnl Input precedes =>, expected output follows =>.
270 AT_DATA([test-cases.txt], [[
271 ip4.src == 1.2.3.4 => ip4.src == 0x1020304 && eth.type == 0x800
272 ip4.src != 1.2.3.4 => ip4.src != 0x1020304 && eth.type == 0x800
273 ip.proto == 123 => ip.proto == 0x7b && (eth.type == 0x800 || eth.type == 0x86dd)
274 ip.proto == {123, 234} => (ip.proto == 0x7b && (eth.type == 0x800 || eth.type == 0x86dd)) || (ip.proto == 0xea && (eth.type == 0x800 || eth.type == 0x86dd))
275 ip4.src == 1.2.3.4 && ip4.dst == 5.6.7.8 => ip4.src == 0x1020304 && eth.type == 0x800 && ip4.dst == 0x5060708 && eth.type == 0x800
277 ip => eth.type == 0x800 || eth.type == 0x86dd
278 ip == 1 => eth.type == 0x800 || eth.type == 0x86dd
279 ip[0] == 1 => eth.type == 0x800 || eth.type == 0x86dd
280 ip > 0 => Only == and != operators may be used with nominal field ip.
281 !ip => Nominal predicate ip may only be tested positively, e.g. `ip' or `ip == 1' but not `!ip' or `ip == 0'.
282 ip == 0 => Nominal predicate ip may only be tested positively, e.g. `ip' or `ip == 1' but not `!ip' or `ip == 0'.
284 vlan.present => vlan.tci[12]
285 !vlan.present => !vlan.tci[12]
287 !vlan.pcp => vlan.tci[13..15] == 0 && vlan.tci[12]
288 vlan.pcp == 1 && vlan.vid == 2 => vlan.tci[13..15] == 0x1 && vlan.tci[12] && vlan.tci[0..11] == 0x2 && vlan.tci[12]
289 !reg0 && !reg1 && !reg2 && !reg3 => xreg0[32..63] == 0 && xreg0[0..31] == 0 && xreg1[32..63] == 0 && xreg1[0..31] == 0
291 ip.first_frag => ip.frag[0] && (eth.type == 0x800 || eth.type == 0x86dd) && (!ip.frag[1] || (eth.type != 0x800 && eth.type != 0x86dd))
292 !ip.first_frag => !ip.frag[0] || (eth.type != 0x800 && eth.type != 0x86dd) || (ip.frag[1] && (eth.type == 0x800 || eth.type == 0x86dd))
293 ip.later_frag => ip.frag[1] && (eth.type == 0x800 || eth.type == 0x86dd)
295 bad_prereq != 0 => Error parsing expression `xyzzy' encountered as prerequisite or predicate of initial expression: Syntax error at `xyzzy' expecting field name.
296 self_recurse != 0 => Error parsing expression `self_recurse != 0' encountered as prerequisite or predicate of initial expression: Recursive expansion of symbol `self_recurse'.
297 mutual_recurse_1 != 0 => Error parsing expression `mutual_recurse_2 != 0' encountered as prerequisite or predicate of initial expression: Error parsing expression `mutual_recurse_1 != 0' encountered as prerequisite or predicate of initial expression: Recursive expansion of symbol `mutual_recurse_1'.
298 mutual_recurse_2 != 0 => Error parsing expression `mutual_recurse_1 != 0' encountered as prerequisite or predicate of initial expression: Error parsing expression `mutual_recurse_2 != 0' encountered as prerequisite or predicate of initial expression: Recursive expansion of symbol `mutual_recurse_2'.
300 sed 's/ =>.*//' test-cases.txt > input.txt
301 sed 's/.* => //' test-cases.txt > expout
302 AT_CHECK([ovstest test-ovn annotate-expr < input.txt], [0], [expout])
305 AT_SETUP([ovn -- 1-term expression conversion])
306 AT_CHECK([ovstest test-ovn exhaustive --operation=convert 1], [0],
307 [Tested converting all 1-terminal expressions with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 2 string vars.
311 AT_SETUP([ovn -- 2-term expression conversion])
312 AT_CHECK([ovstest test-ovn exhaustive --operation=convert 2], [0],
313 [Tested converting 570 expressions of 2 terminals with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 2 string vars.
317 AT_SETUP([ovn -- 3-term expression conversion])
318 AT_CHECK([ovstest test-ovn exhaustive --operation=convert --bits=2 3], [0],
319 [Tested converting 62418 expressions of 3 terminals with 2 numeric vars (each 2 bits) in terms of operators == != < <= > >= and 2 string vars.
323 AT_SETUP([ovn -- 3-term numeric expression simplification])
324 AT_CHECK([ovstest test-ovn exhaustive --operation=simplify --nvars=2 --svars=0 3], [0],
325 [Tested simplifying 477138 expressions of 3 terminals with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >=.
329 AT_SETUP([ovn -- 4-term string expression simplification])
330 AT_CHECK([ovstest test-ovn exhaustive --operation=simplify --nvars=0 --svars=4 4], [0],
331 [Tested simplifying 21978 expressions of 4 terminals with 4 string vars.
335 AT_SETUP([ovn -- 3-term mixed expression simplification])
336 AT_CHECK([ovstest test-ovn exhaustive --operation=simplify --nvars=1 --svars=1 3], [0],
337 [Tested simplifying 124410 expressions of 3 terminals with 1 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 1 string vars.
341 AT_SETUP([ovn -- 4-term numeric expression normalization])
342 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=3 --svars=0 --bits=1 4], [0],
343 [Tested normalizing 1207162 expressions of 4 terminals with 3 numeric vars (each 1 bits) in terms of operators == != < <= > >=.
347 AT_SETUP([ovn -- 4-term string expression normalization])
348 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=0 --svars=3 --bits=1 4], [0],
349 [Tested normalizing 11242 expressions of 4 terminals with 3 string vars.
353 AT_SETUP([ovn -- 4-term mixed expression normalization])
354 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=1 --bits=1 --svars=2 4], [0],
355 [Tested normalizing 128282 expressions of 4 terminals with 1 numeric vars (each 1 bits) in terms of operators == != < <= > >= and 2 string vars.
359 AT_SETUP([ovn -- 5-term numeric expression normalization])
360 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=3 --svars=0 --bits=1 --relops='==' 5], [0],
361 [Tested normalizing 368550 expressions of 5 terminals with 3 numeric vars (each 1 bits) in terms of operators ==.
365 AT_SETUP([ovn -- 5-term string expression normalization])
366 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=0 --svars=3 --bits=1 --relops='==' 5], [0],
367 [Tested normalizing 368550 expressions of 5 terminals with 3 string vars.
371 AT_SETUP([ovn -- 5-term mixed expression normalization])
372 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=1 --svars=1 --bits=1 --relops='==' 5], [0],
373 [Tested normalizing 116550 expressions of 5 terminals with 1 numeric vars (each 1 bits) in terms of operators == and 1 string vars.
377 AT_SETUP([ovn -- 4-term numeric expressions to flows])
378 AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=2 --svars=0 --bits=2 --relops='==' 4], [0],
379 [Tested converting to flows 128282 expressions of 4 terminals with 2 numeric vars (each 2 bits) in terms of operators ==.
383 AT_SETUP([ovn -- 4-term string expressions to flows])
384 AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=0 --svars=4 4], [0],
385 [Tested converting to flows 21978 expressions of 4 terminals with 4 string vars.
389 AT_SETUP([ovn -- 4-term mixed expressions to flows])
390 AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=1 --bits=2 --svars=1 --relops='==' 4], [0],
391 [Tested converting to flows 37994 expressions of 4 terminals with 1 numeric vars (each 2 bits) in terms of operators == and 1 string vars.
395 AT_SETUP([ovn -- 3-term numeric expressions to flows])
396 AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=3 --svars=0 --bits=3 --relops='==' 3], [0],
397 [Tested converting to flows 38394 expressions of 3 terminals with 3 numeric vars (each 3 bits) in terms of operators ==.
401 AT_SETUP([ovn -- converting expressions to flows -- string fields])
403 echo "$1" | ovstest test-ovn expr-to-flows | sort
405 AT_CHECK([expr_to_flow 'inport == "eth0"'], [0], [reg6=0x5
407 AT_CHECK([expr_to_flow 'inport == "eth1"'], [0], [reg6=0x6
409 AT_CHECK([expr_to_flow 'inport == "eth2"'], [0], [(no flows)
411 AT_CHECK([expr_to_flow 'inport == "eth0" && ip'], [0], [dnl
415 AT_CHECK([expr_to_flow 'inport == "eth1" && ip'], [0], [dnl
419 AT_CHECK([expr_to_flow 'inport == "eth2" && ip'], [0], [(no flows)
421 AT_CHECK([expr_to_flow 'inport == {"eth0", "eth1", "eth2", "LOCAL"}'], [0],
426 AT_CHECK([expr_to_flow 'inport == {"eth0", "eth1", "eth2"} && ip'], [0], [dnl
432 AT_CHECK([expr_to_flow 'inport == "eth0" && inport == "eth1"'], [0], [dnl
437 AT_SETUP([ovn -- action parsing])
438 dnl Text before => is input, text after => is expected output.
439 AT_DATA([test-cases.txt], [[
441 drop; => actions=drop, prereqs=1
442 drop; next; => Syntax error at `next' expecting end of input.
443 next; drop; => Syntax error at `drop' expecting action.
446 output; => actions=resubmit(,64), prereqs=1
449 next; => actions=resubmit(,27), prereqs=1
450 next(0); => actions=resubmit(,16), prereqs=1
451 next(15); => actions=resubmit(,31), prereqs=1
453 next(); => Syntax error at `)' expecting small integer.
454 next(10; => Syntax error at `;' expecting `)'.
455 next(16); => "next" argument must be in range 0 to 15.
457 # Loading a constant value.
458 tcp.dst=80; => actions=set_field:80->tcp_dst, prereqs=ip.proto == 0x6 && (eth.type == 0x800 || eth.type == 0x86dd)
459 eth.dst[40] = 1; => actions=set_field:01:00:00:00:00:00/01:00:00:00:00:00->eth_dst, prereqs=1
460 vlan.pcp = 2; => actions=set_field:0x4000/0xe000->vlan_tci, prereqs=vlan.tci[12]
461 vlan.tci[13..15] = 2; => actions=set_field:0x4000/0xe000->vlan_tci, prereqs=1
462 inport = ""; => actions=set_field:0->reg6,set_field:0->in_port, prereqs=1
463 ip.ttl = 4; => actions=set_field:4->nw_ttl, prereqs=eth.type == 0x800 || eth.type == 0x86dd
464 outport="eth0"; next; outport="LOCAL"; next; => actions=set_field:0x5->reg7,resubmit(,27),set_field:0xfffe->reg7,resubmit(,27), prereqs=1
466 inport[1] = 1; => Cannot select subfield of string field inport.
467 ip.proto[1] = 1; => Cannot select subfield of nominal field ip.proto.
468 eth.dst[40] == 1; => Syntax error at `==' expecting `=' or `<->'.
469 ip = 1; => Predicate symbol ip used where lvalue required.
470 ip.proto = 6; => Field ip.proto is not modifiable.
471 inport = {"a", "b"}; => Assignments require a single value.
472 inport = {}; => Syntax error at `}' expecting constant.
473 bad_prereq = 123; => Error parsing expression `xyzzy' encountered as prerequisite or predicate of initial expression: Syntax error at `xyzzy' expecting field name.
474 self_recurse = 123; => Error parsing expression `self_recurse != 0' encountered as prerequisite or predicate of initial expression: Error parsing expression `self_recurse != 0' encountered as prerequisite or predicate of initial expression: Recursive expansion of symbol `self_recurse'.
475 vlan.present = 0; => Predicate symbol vlan.present used where lvalue required.
477 # Moving one field into another.
478 reg0 = reg1; => actions=move:OXM_OF_PKT_REG0[0..31]->OXM_OF_PKT_REG0[32..63], prereqs=1
479 vlan.pcp = reg0[0..2]; => actions=move:OXM_OF_PKT_REG0[32..34]->NXM_OF_VLAN_TCI[13..15], prereqs=vlan.tci[12]
480 reg0[10] = vlan.pcp[1]; => actions=move:NXM_OF_VLAN_TCI[14]->OXM_OF_PKT_REG0[42], prereqs=vlan.tci[12]
481 outport = inport; => actions=move:NXM_NX_REG6[]->NXM_NX_REG7[], prereqs=1
483 reg0[0] = vlan.present; => Predicate symbol vlan.present used where lvalue required.
484 reg0 = reg1[0..10]; => Can't assign 11-bit value to 32-bit destination.
485 inport = reg0; => Can't assign integer field (reg0) to string field (inport).
486 inport = big_string; => String fields inport and big_string are incompatible for assignment.
487 ip.proto = reg0[0..7]; => Field ip.proto is not modifiable.
490 reg0 <-> reg1; => actions=push:OXM_OF_PKT_REG0[0..31],push:OXM_OF_PKT_REG0[32..63],pop:OXM_OF_PKT_REG0[0..31],pop:OXM_OF_PKT_REG0[32..63], prereqs=1
491 vlan.pcp <-> reg0[0..2]; => actions=push:OXM_OF_PKT_REG0[32..34],push:NXM_OF_VLAN_TCI[13..15],pop:OXM_OF_PKT_REG0[32..34],pop:NXM_OF_VLAN_TCI[13..15], prereqs=vlan.tci[12]
492 reg0[10] <-> vlan.pcp[1]; => actions=push:NXM_OF_VLAN_TCI[14],push:OXM_OF_PKT_REG0[42],pop:NXM_OF_VLAN_TCI[14],pop:OXM_OF_PKT_REG0[42], prereqs=vlan.tci[12]
493 outport <-> inport; => actions=push:NXM_NX_REG6[],push:NXM_NX_REG7[],pop:NXM_NX_REG6[],pop:NXM_NX_REG7[], prereqs=1
495 reg0[0] <-> vlan.present; => Predicate symbol vlan.present used where lvalue required.
496 reg0 <-> reg1[0..10]; => Can't exchange 32-bit field with 11-bit field.
497 inport <-> reg0; => Can't exchange string field (inport) with integer field (reg0).
498 inport <-> big_string; => String fields inport and big_string are incompatible for exchange.
499 ip.proto <-> reg0[0..7]; => Field ip.proto is not modifiable.
500 reg0[0..7] <-> ip.proto; => Field ip.proto is not modifiable.
503 ip.ttl--; => actions=dec_ttl, prereqs=ip
504 ip.ttl => Syntax error at end of input expecting `--'.
507 ct_next; => actions=ct(table=27,zone=NXM_NX_REG5[0..15]), prereqs=ip
508 ct_commit; => actions=ct(commit,zone=NXM_NX_REG5[0..15]), prereqs=ip
509 ct_commit(); => actions=ct(commit,zone=NXM_NX_REG5[0..15]), prereqs=ip
510 ct_commit(ct_mark=1); => actions=ct(commit,zone=NXM_NX_REG5[0..15],exec(set_field:0x1->ct_mark)), prereqs=ip
511 ct_commit(ct_mark=1/1); => actions=ct(commit,zone=NXM_NX_REG5[0..15],exec(set_field:0x1/0x1->ct_mark)), prereqs=ip
512 ct_commit(ct_label=1); => actions=ct(commit,zone=NXM_NX_REG5[0..15],exec(set_field:0x1->ct_label)), prereqs=ip
513 ct_commit(ct_label=1/1); => actions=ct(commit,zone=NXM_NX_REG5[0..15],exec(set_field:0x1/0x1->ct_label)), prereqs=ip
514 ct_commit(ct_mark=1, ct_label=2); => actions=ct(commit,zone=NXM_NX_REG5[0..15],exec(set_field:0x1->ct_mark,set_field:0x2->ct_label)), prereqs=ip
517 ct_dnat; => actions=ct(table=27,zone=NXM_NX_REG3[0..15],nat), prereqs=ip
518 ct_dnat(192.168.1.2); => actions=ct(commit,table=27,zone=NXM_NX_REG3[0..15],nat(dst=192.168.1.2)), prereqs=ip
519 ct_dnat(192.168.1.2, 192.168.1.3); => Syntax error at `,' expecting `)'.
520 ct_dnat(foo); => Syntax error at `foo' invalid ip.
521 ct_dnat(foo, bar); => Syntax error at `foo' invalid ip.
522 ct_dnat(); => Syntax error at `)' invalid ip.
525 ct_snat; => actions=ct(zone=NXM_NX_REG4[0..15],nat), prereqs=ip
526 ct_snat(192.168.1.2); => actions=ct(commit,table=27,zone=NXM_NX_REG4[0..15],nat(src=192.168.1.2)), prereqs=ip
527 ct_snat(192.168.1.2, 192.168.1.3); => Syntax error at `,' expecting `)'.
528 ct_snat(foo); => Syntax error at `foo' invalid ip.
529 ct_snat(foo, bar); => Syntax error at `foo' invalid ip.
530 ct_snat(); => Syntax error at `)' invalid ip.
534 arp { eth.dst = ff:ff:ff:ff:ff:ff; output; }; => actions=controller(userdata=00.00.00.00.00.00.00.00.00.19.00.10.80.00.06.06.ff.ff.ff.ff.ff.ff.00.00.ff.ff.00.10.00.00.23.20.00.0e.ff.f8.40.00.00.00), prereqs=ip4
537 get_arp(outport, ip4.dst); => actions=push:NXM_NX_REG0[],push:NXM_OF_IP_DST[],pop:NXM_NX_REG0[],set_field:00:00:00:00:00:00->eth_dst,resubmit(,65),pop:NXM_NX_REG0[], prereqs=eth.type == 0x800
538 get_arp(inport, reg0); => actions=push:NXM_NX_REG7[],push:NXM_NX_REG0[],push:OXM_OF_PKT_REG0[32..63],push:NXM_NX_REG6[],pop:NXM_NX_REG7[],pop:NXM_NX_REG0[],set_field:00:00:00:00:00:00->eth_dst,resubmit(,65),pop:NXM_NX_REG0[],pop:NXM_NX_REG7[], prereqs=1
539 get_arp; => Syntax error at `;' expecting `('.
540 get_arp(); => Syntax error at `)' expecting field name.
541 get_arp(inport); => Syntax error at `)' expecting `,'.
542 get_arp(inport ip4.dst); => Syntax error at `ip4.dst' expecting `,'.
543 get_arp(inport, ip4.dst; => Syntax error at `;' expecting `)'.
544 get_arp(inport, eth.dst); => Cannot use 48-bit field eth.dst[0..47] where 32-bit field is required.
545 get_arp(inport, outport); => Cannot use string field outport where numeric field is required.
546 get_arp(reg0, ip4.dst); => Cannot use numeric field reg0 where string field is required.
549 put_arp(inport, arp.spa, arp.sha); => actions=push:NXM_NX_REG0[],push:NXM_OF_ETH_SRC[],push:NXM_NX_ARP_SHA[],push:NXM_OF_ARP_SPA[],pop:NXM_NX_REG0[],pop:NXM_OF_ETH_SRC[],controller(userdata=00.00.00.01.00.00.00.00),pop:NXM_OF_ETH_SRC[],pop:NXM_NX_REG0[], prereqs=eth.type == 0x806 && eth.type == 0x806
552 reg1[0] = put_dhcp_opts(offerip = 1.2.3.4, router = 10.0.0.1); => actions=controller(userdata=00.00.00.02.00.00.00.00.80.01.00.08.00.00.00.00.01.02.03.04.03.04.0a.00.00.01,pause), prereqs=1
553 reg2[5] = put_dhcp_opts(offerip=10.0.0.4,router=10.0.0.1,netmask=255.255.254.0,mtu=1400,domain="ovn.org"); => actions=controller(userdata=00.00.00.02.00.00.00.00.80.01.02.08.00.00.00.25.0a.00.00.04.03.04.0a.00.00.01.01.04.ff.ff.fe.00.1a.02.05.78.0f.07.6f.76.6e.2e.6f.72.67,pause), prereqs=1
554 # offerip=10.0.0.4 --> 0a.00.00.04
555 # router=10.0.0.1 --> 03.04.0a.00.00.01
556 # netmask=255.255.255.0 --> 01.04.ff.ff.ff.00
557 # mtu=1400 --> 1a.02.05.78
558 # ip_forward_enable-1 --> 13.01.01
559 # default_ttl=121 --> 17.01.79
560 # dns_server={8.8.8.8,7.7.7.7} --> 06.08.08.08.08.08.07.07.07.07
561 # classless_static_route= --> 79.14
562 # {30.0.0.0/24,10.0.0.4 --> 18.1e.00.00.0a.00.00.04
563 # 40.0.0.0/16,10.0.0.6 --> 10.28.00.0a.00.00.06
564 # 0.0.0.0/0,10.0.0.1} --> 00.0a.00.00.01
565 # ethernet_encap=1 --> 24.01.01
566 # router_discovery=0 --> 1f.01.00
567 reg0[15] = put_dhcp_opts(offerip=10.0.0.4,router=10.0.0.1,netmask=255.255.255.0,mtu=1400,ip_forward_enable=1,default_ttl=121,dns_server={8.8.8.8,7.7.7.7},classless_static_route={30.0.0.0/24,10.0.0.4,40.0.0.0/16,10.0.0.6,0.0.0.0/0,10.0.0.1},ethernet_encap=1,router_discovery=0); => actions=controller(userdata=00.00.00.02.00.00.00.00.80.01.00.08.00.00.00.2f.0a.00.00.04.03.04.0a.00.00.01.01.04.ff.ff.ff.00.1a.02.05.78.13.01.01.17.01.79.06.08.08.08.08.08.07.07.07.07.79.14.18.1e.00.00.0a.00.00.04.10.28.00.0a.00.00.06.00.0a.00.00.01.24.01.01.1f.01.00,pause), prereqs=1
568 reg1[0..1] = put_dhcp_opts(offerip = 1.2.3.4, router = 10.0.0.1); => Cannot use 2-bit field reg1[0..1] where 1-bit field is required.
569 reg1[0] = put_dhcp_opts(); => Syntax error at `)'.
570 reg1[0] = put_dhcp_opts(x = 1.2.3.4, router = 10.0.0.1); => Syntax error at `x' expecting offerip option.
571 reg1[0] = put_dhcp_opts(offerip=1.2.3.4, "hi"); => Syntax error at `"hi"'.
572 reg1[0] = put_dhcp_opts(offerip=1.2.3.4, xyzzy); => Syntax error at `xyzzy' expecting DHCP option name.
573 reg1[0] = put_dhcp_opts(offerip="xyzzy"); => DHCP option offerip requires numeric value.
574 reg1[0] = put_dhcp_opts(offerip=1.2.3.4, domain=1.2.3.4); => DHCP option domain requires string value.
576 # Contradictionary prerequisites (allowed but not useful):
577 ip4.src = ip6.src[0..31]; => actions=move:NXM_NX_IPV6_SRC[0..31]->NXM_OF_IP_SRC[], prereqs=eth.type == 0x800 && eth.type == 0x86dd
578 ip4.src <-> ip6.src[0..31]; => actions=push:NXM_NX_IPV6_SRC[0..31],push:NXM_OF_IP_SRC[],pop:NXM_NX_IPV6_SRC[0..31],pop:NXM_OF_IP_SRC[], prereqs=eth.type == 0x800 && eth.type == 0x86dd
580 ## Miscellaneous negative tests.
581 ; => Syntax error at `;'.
582 xyzzy; => Syntax error at `xyzzy' expecting action.
583 next; 123; => Syntax error at `123'.
584 next; xyzzy; => Syntax error at `xyzzy' expecting action.
585 next => Syntax error at end of input expecting ';'.
587 sed 's/ =>.*//' test-cases.txt > input.txt
588 sed 's/.* => //' test-cases.txt > expout
589 AT_CHECK([ovstest test-ovn parse-actions < input.txt], [0], [expout])
592 AT_BANNER([OVN end-to-end tests])
594 # 3 hypervisors, one logical switch, 3 logical ports per hypervisor
595 AT_SETUP([ovn -- 3 HVs, 1 LS, 3 lports/HV])
596 AT_KEYWORDS([ovnarp])
597 AT_SKIP_IF([test $HAVE_PYTHON = no])
600 # Create hypervisors hv[123].
601 # Add vif1[123] to hv1, vif2[123] to hv2, vif3[123] to hv3.
602 # Add all of the vifs to a single logical switch lsw0.
603 # Turn on port security on all the vifs except vif[123]1.
604 # Make vif13, vif2[23], vif3[123] destinations for unknown MACs.
605 # Add some ACLs for Ethertypes 1234, 1235, 1236.
606 ovn-nbctl ls-add lsw0
611 ovs-vsctl add-br br-phys
612 ovn_attach n1 br-phys 192.168.0.$i
615 ovs-vsctl add-port br-int vif$i$j -- set Interface vif$i$j external-ids:iface-id=lp$i$j options:tx_pcap=hv$i/vif$i$j-tx.pcap options:rxq_pcap=hv$i/vif$i$j-rx.pcap ofport-request=$i$j
616 ovn-nbctl lsp-add lsw0 lp$i$j
618 ovn-nbctl lsp-set-addresses lp$i$j "f0:00:00:00:00:$i$j 192.168.0.$i$j" unknown
621 ip_addrs="192.168.0.$i$j fe80::ea2a:eaff:fe28:$i$j/64 192.169.0.$i$j"
623 ip_addrs="192.168.0.$i$j"
625 ovn-nbctl lsp-set-addresses lp$i$j "f0:00:00:00:00:$i$j $ip_addrs"
626 ovn-nbctl lsp-set-port-security lp$i$j f0:00:00:00:00:$i$j
630 ovn-nbctl acl-add lsw0 from-lport 1000 'eth.type == 0x1234' drop
631 ovn-nbctl acl-add lsw0 from-lport 1000 'eth.type == 0x1235 && inport == "lp11"' drop
632 ovn-nbctl acl-add lsw0 to-lport 1000 'eth.type == 0x1236 && outport == "lp33"' drop
634 # Pre-populate the hypervisors' ARP tables so that we don't lose any
635 # packets for ARP resolution (native tunneling doesn't queue packets
636 # for ARP resolution).
639 # Allow some time for ovn-northd and ovn-controller to catch up.
640 # XXX This should be more systematic.
643 # Given the name of a logical port, prints the name of the hypervisor
644 # on which it is located.
649 # test_packet INPORT DST SRC ETHTYPE OUTPORT...
651 # This shell function causes a packet to be received on INPORT. The packet's
652 # content has Ethernet destination DST and source SRC (each exactly 12 hex
653 # digits) and Ethernet type ETHTYPE (4 hex digits). The OUTPORTs (zero or
654 # more) list the VIFs on which the packet should be received. INPORT and the
655 # OUTPORTs are specified as logical switch port numbers, e.g. 11 for vif11.
657 sed 's/\(00\)\{1,\}$//'
665 local inport=$1 packet=$2$3$4; shift; shift; shift; shift
666 hv=`vif_to_hv $inport`
668 as $hv ovs-appctl netdev-dummy/receive $vif $packet
670 echo $packet | trim_zeros >> $outport.expected
674 # test_arp INPORT SHA SPA TPA [REPLY_HA]
676 # Causes a packet to be received on INPORT. The packet is an ARP
677 # request with SHA, SPA, and TPA as specified. If REPLY_HA is provided, then
678 # it should be the hardware address of the target to expect to receive in an
679 # ARP reply; otherwise no reply is expected.
681 # INPORT is an logical switch port number, e.g. 11 for vif11.
682 # SHA and REPLY_HA are each 12 hex digits.
683 # SPA and TPA are each 8 hex digits.
685 local inport=$1 sha=$2 spa=$3 tpa=$4 reply_ha=$5
686 local request=ffffffffffff${sha}08060001080006040001${sha}${spa}ffffffffffff${tpa}
687 hv=`vif_to_hv $inport`
688 as $hv ovs-appctl netdev-dummy/receive vif$inport $request
690 if test X$reply_ha = X; then
691 # Expect to receive the broadcast ARP on the other logical switch ports
692 # if no reply is expected.
696 if test $i$j != $inport; then
697 echo $request >> $i$j.expected
702 # Expect to receive the reply, if any.
703 local reply=${sha}${reply_ha}08060001080006040002${reply_ha}${tpa}${sha}${spa}
704 echo $reply >> $inport.expected
709 printf "%02x%02x%02x%02x" "$@"
712 # Send packets between all pairs of source and destination ports:
714 # 1. Unicast packets are delivered to exactly one logical switch port
715 # (except that packets destined to their input ports are dropped).
717 # 2. Broadcast and multicast are delivered to all logical switch ports
718 # except the input port.
720 # 3. When port security is turned on, the switch drops packets from the wrong
723 # 4. The switch drops all packets with a VLAN tag.
725 # 5. The switch drops all packets with a multicast source address. (This only
726 # affects behavior when port security is turned off, since otherwise port
727 # security would drop the packet anyway.)
729 # 6. The switch delivers packets with an unknown destination to logical
730 # switch ports with "unknown" among their MAC addresses (and port
731 # security disabled).
733 # 7. The switch drops unicast packets that violate an ACL.
735 # 8. The switch drops multicast and broadcast packets that violate an ACL.
737 # 9. ARP requests to known IPs are responded directly.
739 # 10. No response to ARP requests for unknown IPs.
751 if test $d != $s; then unicast=$d; else unicast=; fi
752 test_packet $s f000000000$d f000000000$s $s$d $unicast #1
754 if test $d != $s && test $js = 1; then
759 test_packet $s f000000000$d f00000000055 55$d $impersonate #3
761 if test $d != $s && test $s != 11; then acl2=$d; else acl2=; fi
762 if test $d != $s && test $d != 33; then acl3=$d; else acl3=; fi
763 test_packet $s f000000000$d f000000000$s 1234 #7, acl1
764 test_packet $s f000000000$d f000000000$s 1235 $acl2 #7, acl2
765 test_packet $s f000000000$d f000000000$s 1236 $acl3 #7, acl3
767 test_packet $s f000000000$d f00000000055 810000091234 #4
768 test_packet $s f000000000$d 0100000000$s $s$d #5
770 if test $d != $s && test $jd = 1; then
771 unknown="$unknown $d"
773 bcast="$bcast $unicast"
777 sip=`ip_to_hex 192 168 0 $i$j`
778 tip=`ip_to_hex 192 168 0 $id$jd`
779 tip_unknown=`ip_to_hex 11 11 11 11`
780 test_arp $s f000000000$s $sip $tip f000000000$d #9
781 test_arp $s f000000000$s $sip $tip_unknown #10
783 if test $jd = 3; then
784 # lsp[123]3 has an additional ip 192.169.0.[123]3.
785 tip=`ip_to_hex 192 169 0 $id$jd`
786 test_arp $s f000000000$s $sip $tip f000000000$d #9
791 # Broadcast and multicast.
792 test_packet $s ffffffffffff f000000000$s ${s}ff $bcast #2
793 test_packet $s 010000000000 f000000000$s ${s}ff $bcast #2
794 if test $js = 1; then
795 bcast_impersonate=$bcast
799 test_packet $s 010000000000 f00000000044 44ff $bcast_impersonate #3
801 test_packet $s f0000000ffff f000000000$s ${s}66 $unknown #6
803 test_packet $s ffffffffffff f000000000$s 1234 #8, acl1
804 test_packet $s ffffffffffff f000000000$s 1235 $bacl2 #8, acl2
805 test_packet $s ffffffffffff f000000000$s 1236 $bacl3 #8, acl3
806 test_packet $s 010000000000 f000000000$s 1234 #8, acl1
807 test_packet $s 010000000000 f000000000$s 1235 $bacl2 #8, acl2
808 test_packet $s 010000000000 f000000000$s 1236 $bacl3 #8, acl3
812 # set address for lp13 with invalid characters.
813 # lp13 should be configured with only 192.168.0.13.
814 ovn-nbctl lsp-set-addresses lp13 "f0:00:00:00:00:13 192.168.0.13 invalid 192.169.0.13"
815 sip=`ip_to_hex 192 168 0 11`
816 tip=`ip_to_hex 192 168 0 13`
817 test_arp 11 f00000000011 $sip $tip f00000000013
819 tip=`ip_to_hex 192 169 0 13`
820 #arp request for 192.169.0.13 should be flooded
821 test_arp 11 f00000000011 $sip $tip
823 # Allow some time for packet forwarding.
824 # XXX This can be improved.
827 # dump information and flows with counters
828 ovn-sbctl dump-flows -- list multicast_group
830 echo "------ hv1 dump ------"
831 as hv1 ovs-vsctl show
832 as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-int
834 echo "------ hv2 dump ------"
835 as hv2 ovs-vsctl show
836 as hv2 ovs-ofctl -O OpenFlow13 dump-flows br-int
838 echo "------ hv3 dump ------"
839 as hv3 ovs-vsctl show
840 as hv3 ovs-ofctl -O OpenFlow13 dump-flows br-int
841 # Now check the packets actually received against the ones expected.
844 file=hv$i/vif$i$j-tx.pcap
846 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" $file | trim_zeros > $i$j.packets
847 sort $i$j.expected > expout
848 AT_CHECK([sort $i$j.packets], [0], [expout])
853 # Gracefully terminate daemons
854 for sim in hv1 hv2 hv3; do
856 OVS_APP_EXIT_AND_WAIT([ovn-controller])
857 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
858 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
862 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
865 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
868 OVS_APP_EXIT_AND_WAIT([ovn-northd])
871 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
872 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
876 # 2 hypervisors, 4 logical ports per HV
877 # 2 locally attached networks (one flat, one vlan tagged over same device)
878 # 2 ports per HV on each network
879 AT_SETUP([ovn -- 2 HVs, 4 lports/HV, localnet ports])
880 AT_KEYWORDS([ovn-localnet])
881 AT_SKIP_IF([test $HAVE_PYTHON = no])
884 # In this test cases we create 3 switches, all connected to same
885 # physical network (through br-phys on each HV). Each switch has
886 # VIF ports across 2 HVs. Each HV has 5 VIF ports. The first digit
887 # of VIF port name indicates the hypervisor it is bound to, e.g.
888 # lp23 means VIF 3 on hv2.
890 # Each switch's VLAN tag and their logical switch ports are:
893 # - ports: lp11, lp12, lp21, lp22
896 # - tagged with VLAN 101
897 # - ports: lp13, lp14, lp23, lp24
900 # - ports: lp15, lp25
902 # Note: a localnet port is created for each switch to connect to
907 ovn-nbctl ls-add $ls_name
909 if test $i -eq 2; then
910 ovn-nbctl lsp-add $ls_name $ln_port_name "" 101
912 ovn-nbctl lsp-add $ls_name $ln_port_name
914 ovn-nbctl lsp-set-addresses $ln_port_name unknown
915 ovn-nbctl lsp-set-type $ln_port_name localnet
916 ovn-nbctl lsp-set-options $ln_port_name network_name=phys
923 ovs-vsctl add-br br-phys
924 ovs-vsctl set open . external-ids:ovn-bridge-mappings=phys:br-phys
925 ovn_attach n1 br-phys 192.168.0.$i
927 for j in 1 2 3 4 5; do
928 ovs-vsctl add-port br-int vif$i$j -- \
929 set Interface vif$i$j external-ids:iface-id=lp$i$j \
930 options:tx_pcap=hv$i/vif$i$j-tx.pcap \
931 options:rxq_pcap=hv$i/vif$i$j-rx.pcap \
935 if test $j -le 2; then
937 elif test $j -le 4; then
943 ovn-nbctl lsp-add $ls_name $lsp_name
944 ovn-nbctl lsp-set-addresses $lsp_name f0:00:00:00:00:$i$j
945 ovn-nbctl lsp-set-port-security $lsp_name f0:00:00:00:00:$i$j
947 OVS_WAIT_UNTIL([test x`ovn-nbctl lsp-get-up $lsp_name` = xup])
953 # XXX This is now the 3rd copy of these functions in this file ...
955 # Given the name of a logical port, prints the name of the hypervisor
956 # on which it is located.
961 # test_packet INPORT DST SRC ETHTYPE OUTPORT...
963 # This shell function causes a packet to be received on INPORT. The packet's
964 # content has Ethernet destination DST and source SRC (each exactly 12 hex
965 # digits) and Ethernet type ETHTYPE (4 hex digits). The OUTPORTs (zero or
966 # more) list the VIFs on which the packet should be received. INPORT and the
967 # OUTPORTs are specified as logical switch port numbers, e.g. 11 for vif11.
969 sed 's/\(00\)\{1,\}$//'
972 for j in 1 2 3 4 5; do
977 local inport=$1 src=$2 dst=$3 eth=$4; shift; shift; shift; shift
978 local packet=${src}${dst}${eth}
979 hv=`vif_to_hv $inport`
981 as $hv ovs-appctl netdev-dummy/receive $vif $packet
983 echo $packet | trim_zeros >> $outport.expected
987 # lp11 and lp21 are on the same network (phys, untagged)
988 # and on different hypervisors
989 test_packet 11 f00000000021 f00000000011 1121 21
990 test_packet 21 f00000000011 f00000000021 2111 11
992 # lp11 and lp12 are on the same network (phys, untagged)
993 # and on the same hypervisor
994 test_packet 11 f00000000012 f00000000011 1112 12
995 test_packet 12 f00000000011 f00000000012 1211 11
997 # lp13 and lp23 are on the same network (phys, VLAN 101)
998 # and on different hypervisors
999 test_packet 13 f00000000023 f00000000013 1323 23
1000 test_packet 23 f00000000013 f00000000023 2313 13
1002 # lp13 and lp14 are on the same network (phys, VLAN 101)
1003 # and on the same hypervisor
1004 test_packet 13 f00000000014 f00000000013 1314 14
1005 test_packet 14 f00000000013 f00000000014 1413 13
1007 # lp11 and lp15 are on the same network (phys, untagged),
1008 # same hypervisor, and on different switches
1009 test_packet 11 f00000000015 f00000000011 1115 15
1010 test_packet 15 f00000000011 f00000000015 1511 11
1012 # lp11 and lp25 are on the same network (phys, untagged),
1013 # different hypervisors, and on different switches
1014 test_packet 11 f00000000025 f00000000011 1125 25
1015 test_packet 25 f00000000011 f00000000025 2511 11
1017 # Ports that should not be able to communicate
1018 test_packet 11 f00000000013 f00000000011 1113
1019 test_packet 11 f00000000023 f00000000011 1123
1020 test_packet 21 f00000000013 f00000000021 2113
1021 test_packet 21 f00000000023 f00000000021 2123
1022 test_packet 13 f00000000011 f00000000013 1311
1023 test_packet 13 f00000000021 f00000000013 1321
1024 test_packet 23 f00000000011 f00000000023 2311
1025 test_packet 23 f00000000021 f00000000023 2321
1027 # Allow some time for packet forwarding.
1028 # XXX This can be improved.
1031 # Dump a bunch of info helpful for debugging if there's a failure.
1033 echo "------ OVN dump ------"
1037 echo "------ hv1 dump ------"
1038 as hv1 ovs-vsctl show
1039 as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-int
1041 echo "------ hv2 dump ------"
1042 as hv2 ovs-vsctl show
1043 as hv2 ovs-ofctl -O OpenFlow13 dump-flows br-int
1045 # Now check the packets actually received against the ones expected.
1047 for j in 1 2 3 4 5; do
1048 file=hv$i/vif$i$j-tx.pcap
1050 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" $file | trim_zeros > $i$j.packets
1051 sort $i$j.expected > expout
1052 AT_CHECK([sort $i$j.packets], [0], [expout])
1057 # Gracefully terminate daemons
1058 for sim in hv1 hv2; do
1060 OVS_APP_EXIT_AND_WAIT([ovn-controller])
1061 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
1062 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1066 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1069 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1072 OVS_APP_EXIT_AND_WAIT([ovn-northd])
1075 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
1076 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1079 AT_SETUP([ovn -- vtep: 3 HVs, 1 VIFs/HV, 1 GW, 1 LS])
1081 AT_SKIP_IF([test $HAVE_PYTHON = no])
1084 # Configure the Northbound database
1085 ovn-nbctl ls-add lsw0
1087 ovn-nbctl lsp-add lsw0 lp1
1088 ovn-nbctl lsp-set-addresses lp1 f0:00:00:00:00:01
1090 ovn-nbctl lsp-add lsw0 lp2
1091 ovn-nbctl lsp-set-addresses lp2 f0:00:00:00:00:02
1093 ovn-nbctl lsp-add lsw0 lp-vtep
1094 ovn-nbctl lsp-set-type lp-vtep vtep
1095 ovn-nbctl lsp-set-options lp-vtep vtep-physical-switch=br-vtep vtep-logical-switch=lsw0
1096 ovn-nbctl lsp-set-addresses lp-vtep unknown
1098 net_add n1 # Network to connect hv1, hv2, and vtep
1099 net_add n2 # Network to connect vtep and hv3
1101 # Create hypervisor hv1 connected to n1
1104 ovs-vsctl add-br br-phys
1105 ovn_attach n1 br-phys 192.168.0.1
1106 ovs-vsctl add-port br-int vif1 -- set Interface vif1 external-ids:iface-id=lp1 options:tx_pcap=hv1/vif1-tx.pcap options:rxq_pcap=hv1/vif1-rx.pcap ofport-request=1
1108 # Create hypervisor hv2 connected to n1
1111 ovs-vsctl add-br br-phys
1112 ovn_attach n1 br-phys 192.168.0.2
1113 ovs-vsctl add-port br-int vif2 -- set Interface vif2 external-ids:iface-id=lp2 options:tx_pcap=hv2/vif2-tx.pcap options:rxq_pcap=hv2/vif2-rx.pcap ofport-request=1
1116 # Start the vtep emulator with a leg in both networks
1120 ovsdb-tool create "$ovs_base"/vtep/vtep.db "$abs_top_srcdir"/vtep/vtep.ovsschema || return 1
1121 ovs-appctl -t ovsdb-server ovsdb-server/add-db "$ovs_base"/vtep/vtep.db
1123 ovs-vsctl add-br br-phys
1124 net_attach n1 br-phys
1126 mac=`ovs-vsctl get Interface br-phys mac_in_use | sed s/\"//g`
1127 arp_table="$arp_table $sandbox,br-phys,192.168.0.3,$mac"
1128 ovs-appctl netdev-dummy/ip4addr br-phys 192.168.0.3/24 >/dev/null || return 1
1129 ovs-appctl ovs/route/add 192.168.0.3/24 br-phys >/dev/null || return 1
1131 ovs-vsctl add-br br-vtep
1132 net_attach n2 br-vtep
1134 vtep-ctl add-ps br-vtep
1135 vtep-ctl set Physical_Switch br-vtep tunnel_ips=192.168.0.3
1136 vtep-ctl add-ls lsw0
1138 start_daemon ovs-vtep br-vtep
1139 start_daemon ovn-controller-vtep --vtep-db=unix:"$ovs_base"/vtep/db.sock --ovnsb-db=unix:"$ovs_base"/ovn-sb/ovn-sb.sock
1143 vtep-ctl bind-ls br-vtep br-vtep_n2 0 lsw0
1147 # Add hv3 on the other side of the vtep
1150 ovs-vsctl add-br br-phys
1151 net_attach n2 br-phys
1153 ovs-vsctl add-port br-phys vif3 -- set Interface vif3 options:tx_pcap=hv3/vif3-tx.pcap options:rxq_pcap=hv3/vif3-rx.pcap ofport-request=1
1155 # Pre-populate the hypervisors' ARP tables so that we don't lose any
1156 # packets for ARP resolution (native tunneling doesn't queue packets
1157 # for ARP resolution).
1160 # Allow some time for ovn-northd and ovn-controller to catch up.
1161 # XXX This should be more systematic.
1164 # test_packet INPORT DST SRC ETHTYPE OUTPORT...
1166 # This shell function causes a packet to be received on INPORT. The packet's
1167 # content has Ethernet destination DST and source SRC (each exactly 12 hex
1168 # digits) and Ethernet type ETHTYPE (4 hex digits). The OUTPORTs (zero or
1169 # more) list the VIFs on which the packet should be received. INPORT and the
1170 # OUTPORTs are specified as logical switch port numbers, e.g. 1 for vif1.
1172 sed 's/\(00\)\{1,\}$//'
1178 local inport=$1 packet=$2$3$4; shift; shift; shift; shift
1179 #hv=hv`echo $inport | sed 's/^\(.\).*/\1/'`
1182 as $hv ovs-appctl netdev-dummy/receive $vif $packet
1184 echo $packet | trim_zeros >> $outport.expected
1188 # Send packets between all pairs of source and destination ports:
1190 # 1. Unicast packets are delivered to exactly one logical switch port
1191 # (except that packets destined to their input ports are dropped).
1193 # 2. Broadcast and multicast are delivered to all logical switch ports
1194 # except the input port.
1196 # 3. The switch delivers packets with an unknown destination to logical
1197 # switch ports with "unknown" among their MAC addresses (and port
1198 # security disabled).
1203 if test $d != $s; then unicast=$d; else unicast=; fi
1204 test_packet $s f0000000000$d f0000000000$s 00$s$d $unicast #1
1206 # The vtep (vif3) is the only one configured for "unknown"
1207 if test $d != $s && test $d = 3; then
1208 unknown="$unknown $d"
1210 bcast="$bcast $unicast"
1213 # Broadcast and multicast.
1214 test_packet $s ffffffffffff f0000000000$s 0${s}ff $bcast #2
1215 test_packet $s 010000000000 f0000000000$s 0${s}ff $bcast #2
1217 test_packet $s f0000000ffff f0000000000$s 0${s}66 $unknown #3
1220 # Allow some time for packet forwarding.
1221 # XXX This can be improved.
1224 # dump information with counters
1225 echo "------ OVN dump ------"
1229 echo "------ hv1 dump ------"
1230 as hv1 ovs-vsctl show
1231 as hv1 ovs-ofctl -O OpenFlow13 show br-int
1232 as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-int
1234 echo "------ hv2 dump ------"
1235 as hv2 ovs-vsctl show
1236 as hv2 ovs-ofctl -O OpenFlow13 show br-int
1237 as hv2 ovs-ofctl -O OpenFlow13 dump-flows br-int
1239 echo "------ hv3 dump ------"
1240 as hv3 ovs-vsctl show
1241 # note: hv3 has no logical port bind, thus it should not have br-int
1242 AT_CHECK([as hv3 ovs-ofctl -O OpenFlow13 show br-int], [1], [],
1243 [ovs-ofctl: br-int is not a bridge or a socket
1246 # Now check the packets actually received against the ones expected.
1248 file=hv$i/vif$i-tx.pcap
1250 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" $file | trim_zeros > $i.packets
1251 sort $i.expected > expout
1252 AT_CHECK([sort $i.packets], [0], [expout])
1256 # Gracefully terminate daemons
1258 OVS_APP_EXIT_AND_WAIT([ovn-controller-vtep])
1259 OVS_APP_EXIT_AND_WAIT([ovs-vtep])
1262 OVS_APP_EXIT_AND_WAIT([ovn-controller])
1265 OVS_APP_EXIT_AND_WAIT([ovn-controller])
1268 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1271 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1274 OVS_APP_EXIT_AND_WAIT([ovn-northd])
1276 for sim in hv1 hv2 hv3 vtep main; do
1278 for daemon in ovs-vswitchd ovsdb-server; do
1279 OVS_APP_EXIT_AND_WAIT([$daemon])
1284 # 3 hypervisors, 3 logical switches with 3 logical ports each, 1 logical router
1285 AT_SETUP([ovn -- 3 HVs, 3 LS, 3 lports/LS, 1 LR])
1286 AT_SKIP_IF([test $HAVE_PYTHON = no])
1291 # Three logical switches ls1, ls2, ls3.
1292 # One logical router lr0 connected to ls[123],
1293 # with nine subnets, three per logical switch:
1295 # lrp11 on ls1 for subnet 192.168.11.0/24
1296 # lrp12 on ls1 for subnet 192.168.12.0/24
1297 # lrp13 on ls1 for subnet 192.168.13.0/24
1299 # lrp33 on ls3 for subnet 192.168.33.0/24
1301 # 27 VIFs, 9 per LS, 3 per subnet: lp[123][123][123], where the first two
1302 # digits are the subnet and the last digit distinguishes the VIF.
1304 ovn-nbctl ls-add ls$i
1307 # Add "unknown" to MAC addresses for lp?11, so packets for
1308 # MAC-IP bindings discovered via ARP later have somewhere to go.
1309 if test $j$k = 11; then unknown=unknown; else unknown=; fi
1312 -- lsp-add ls$i lp$i$j$k \
1313 -- lsp-set-addresses lp$i$j$k "f0:00:00:00:0$i:$j$k \
1314 192.168.$i$j.$k" $unknown
1319 ovn-nbctl lr-add lr0
1322 ovn-nbctl lrp-add lr0 lrp$i$j 00:00:00:00:ff:$i$j \
1323 192.168.$i$j.254/24 lrp$i$j-attachment
1325 -- lsp-add ls$i lrp$i$j-attachment \
1326 -- set Logical_Switch_Port lrp$i$j-attachment type=router \
1327 options:router-port=lrp$i$j \
1328 addresses='"00:00:00:00:ff:'$i$j'"'
1332 ovn-nbctl set Logical_Switch_Port lrp33-attachment \
1333 addresses='"00:00:00:00:ff:33 192.168.33.254"'
1337 # Three hypervisors hv[123].
1338 # lp?1[123] spread across hv[123]: lp?11 on hv1, lp?12 on hv2, lp?13 on hv3.
1339 # lp?2[123] spread across hv[23]: lp?21 and lp?22 on hv2, lp?23 on hv3.
1340 # lp?3[123] all on hv3.
1343 # Given the name of a logical port, prints the name of the hypervisor
1344 # on which it is located.
1347 ?11) echo 1 ;; dnl (
1348 ?12 | ?21 | ?22) echo 2 ;; dnl (
1349 ?13 | ?23 | ?3?) echo 3 ;;
1353 # Given the name of a logical port, prints the name of its logical router
1354 # port, e.g. "vif_to_lrp 123" yields 12.
1359 # Given the name of a logical port, prints the name of its logical
1360 # switch, e.g. "vif_to_ls 123" yields 1.
1369 ovs-vsctl add-br br-phys
1370 ovn_attach n1 br-phys 192.168.0.$i
1375 hv=`vif_to_hv $i$j$k`
1376 as hv$hv ovs-vsctl \
1377 -- add-port br-int vif$i$j$k \
1378 -- set Interface vif$i$j$k \
1379 external-ids:iface-id=lp$i$j$k \
1380 options:tx_pcap=hv$hv/vif$i$j$k-tx.pcap \
1381 options:rxq_pcap=hv$hv/vif$i$j$k-rx.pcap \
1382 ofport-request=$i$j$k
1387 # Pre-populate the hypervisors' ARP tables so that we don't lose any
1388 # packets for ARP resolution (native tunneling doesn't queue packets
1389 # for ARP resolution).
1392 # Allow some time for ovn-northd and ovn-controller to catch up.
1393 # XXX This should be more systematic.
1396 # test_ip INPORT SRC_MAC DST_MAC SRC_IP DST_IP OUTPORT...
1398 # This shell function causes a packet to be received on INPORT. The packet's
1399 # content has Ethernet destination DST and source SRC (each exactly 12 hex
1400 # digits) and Ethernet type ETHTYPE (4 hex digits). The OUTPORTs (zero or
1401 # more) list the VIFs on which the packet should be received. INPORT and the
1402 # OUTPORTs are specified as logical switch port numbers, e.g. 123 for vif123.
1404 sed 's/\(00\)\{1,\}$//'
1414 # This packet has bad checksums but logical L3 routing doesn't check.
1415 local inport=$1 src_mac=$2 dst_mac=$3 src_ip=$4 dst_ip=$5
1416 local packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
1417 shift; shift; shift; shift; shift
1418 hv=hv`vif_to_hv $inport`
1419 as $hv ovs-appctl netdev-dummy/receive vif$inport $packet
1420 #as $hv ovs-appctl ofproto/trace br-int in_port=$inport $packet
1421 in_ls=`vif_to_ls $inport`
1422 in_lrp=`vif_to_lrp $inport`
1424 out_ls=`vif_to_ls $outport`
1425 if test $in_ls = $out_ls; then
1426 # Ports on the same logical switch receive exactly the same packet.
1429 # Routing decrements TTL and updates source and dest MAC
1431 out_lrp=`vif_to_lrp $outport`
1432 echo f00000000${outport}00000000ff${out_lrp}08004500001c00000000"3f1101"00${src_ip}${dst_ip}0035111100080000
1433 fi | trim_zeros >> $outport.expected
1437 as hv1 ovs-vsctl --columns=name,ofport list interface
1438 as hv1 ovn-sbctl list port_binding
1439 as hv1 ovn-sbctl list datapath_binding
1440 as hv1 ovn-sbctl dump-flows
1441 as hv1 ovs-ofctl dump-flows br-int
1443 # Send IP packets between all pairs of source and destination ports:
1445 # 1. Unicast IP packets are delivered to exactly one logical switch port
1446 # (except that packets destined to their input ports are dropped).
1448 # 2. Broadcast IP packets are delivered to all logical switch ports
1449 # except the input port.
1451 printf "%02x%02x%02x%02x" "$@"
1459 sip=`ip_to_hex 192 168 $is$js $ks`
1464 dip=`ip_to_hex 192 168 $id$jd $kd`
1465 if test $is = $id; then dmac=f00000000$d; else dmac=00000000ff$is$js; fi
1466 if test $d != $s; then unicast=$d; else unicast=; fi
1468 test_ip $s $smac $dmac $sip $dip $unicast #1
1470 if test $id = $is && test $d != $s; then bcast="$bcast $d"; fi
1474 test_ip $s $smac ffffffffffff $sip ffffffff $bcast #2
1479 # 3. Send an IP packet from every logical port to every other subnet,
1480 # to an IP address that does not have a static IP-MAC binding.
1481 # This should generate a broadcast ARP request for the destination
1482 # IP address in the destination subnet.
1488 sip=`ip_to_hex 192 168 $is$js $ks`
1491 if test $is$js = $id$jd; then
1496 dmac=00000000ff$is$js
1497 # Calculate a 4th octet for the destination that is
1498 # unique per $s, avoids the .1 .2 .3 and .254 IP addresses
1499 # that have static MAC bindings, and fits in the range
1501 o4=`expr $is '*' 9 + $js '*' 3 + $ks + 10`
1502 dip=`ip_to_hex 192 168 $id$jd $o4`
1503 test_ip $s $smac $dmac $sip $dip
1505 # Every LP on the destination subnet's lswitch should
1506 # receive the ARP request.
1507 lrmac=00000000ff$id$jd
1508 lrip=`ip_to_hex 192 168 $id$jd 254`
1509 arp=ffffffffffff${lrmac}08060001080006040001${lrmac}${lrip}000000000000${dip}
1510 for jd2 in 1 2 3; do
1512 echo $arp | trim_zeros >> $id$jd2$kd.expected
1521 # test_arp INPORT SHA SPA TPA [REPLY_HA]
1523 # Causes a packet to be received on INPORT. The packet is an ARP
1524 # request with SHA, SPA, and TPA as specified. If REPLY_HA is provided, then
1525 # it should be the hardware address of the target to expect to receive in an
1526 # ARP reply; otherwise no reply is expected.
1528 # INPORT is an logical switch port number, e.g. 11 for vif11.
1529 # SHA and REPLY_HA are each 12 hex digits.
1530 # SPA and TPA are each 8 hex digits.
1532 local inport=$1 sha=$2 spa=$3 tpa=$4 reply_ha=$5
1533 local request=ffffffffffff${sha}08060001080006040001${sha}${spa}ffffffffffff${tpa}
1534 hv=hv`vif_to_hv $inport`
1535 as $hv ovs-appctl netdev-dummy/receive vif$inport $request
1536 #as $hv ovs-appctl ofproto/trace br-int in_port=$inport $request
1538 # Expect to receive the broadcast ARP on the other logical switch ports if
1539 # IP address is not configured to the switch patch port.
1540 local i=`vif_to_ls $inport`
1544 # 192.168.33.254 is configured to the switch patch port for lrp33,
1545 # so no ARP flooding expected for it.
1546 if test $i$j$k != $inport && test $tpa != `ip_to_hex 192 168 33 254`; then
1547 echo $request >> $i$j$k.expected
1552 # Expect to receive the reply, if any.
1553 if test X$reply_ha != X; then
1554 lrp=`vif_to_lrp $inport`
1555 local reply=${sha}00000000ff${lrp}08060001080006040002${reply_ha}${tpa}${sha}${spa}
1556 echo $reply >> $inport.expected
1560 # Test router replies to ARP requests from all source ports:
1562 # 4. Router replies to query for its MAC address from port's own IP address.
1564 # 5. Router replies to query for its MAC address from any random IP address
1567 # 6. Router replies to query for its MAC address from another subnet.
1569 # 7. No reply to query for IP address other than router IP.
1573 smac=f00000000$i$j$k # Source MAC
1574 sip=`ip_to_hex 192 168 $i$j $k` # Source IP
1575 rip=`ip_to_hex 192 168 $i$j 254` # Router IP
1576 rmac=00000000ff$i$j # Router MAC
1577 otherip=`ip_to_hex 192 168 $i$j 55` # Some other IP in subnet
1578 test_arp $i$j$k $smac $sip $rip $rmac #4
1579 test_arp $i$j$k $smac $otherip $rip $rmac #5
1580 test_arp $i$j$k $smac 0a123456 $rip $rmac #6
1581 test_arp $i$j$k $smac $sip $otherip #7
1586 # Allow some time for packet forwarding.
1587 # XXX This can be improved.
1590 # 8. Generate an ARP reply for each of the IP addresses ARPed for
1593 # Here, the $s is the VIF that originated the ARP request and $d is
1594 # the VIF that sends the ARP reply, which is somewhat backward but
1595 # it means that $s and $d are the same as #3.
1596 : > mac_bindings.expected
1603 if test $is$js = $id$jd; then
1610 o4=`expr $is '*' 9 + $js '*' 3 + $ks + 10`
1611 host_ip=`ip_to_hex 192 168 $id$jd $o4`
1612 host_mac=8000000000$o4
1614 lrmac=00000000ff$id$jd
1615 lrip=`ip_to_hex 192 168 $id$jd 254`
1617 arp=${lrmac}${host_mac}08060001080006040002${host_mac}${host_ip}${lrmac}${lrip}
1623 as $hv ovs-appctl netdev-dummy/receive vif$d $arp
1624 #as $hv ovs-appctl ofproto/trace br-int in_port=$d $arp
1625 #as $hv ovs-ofctl dump-flows br-int table=19
1627 host_ip_pretty=192.168.$id$jd.$o4
1628 host_mac_pretty=80:00:00:00:00:$o4
1629 echo lrp$id$jd,$host_ip_pretty,$host_mac_pretty >> mac_bindings.expected
1636 # Allow some time for packet forwarding.
1637 # XXX This can be improved.
1640 # 9. Send an IP packet from every logical port to every other subnet. These
1641 # are the same packets already sent as #3, but now the destinations' IP-MAC
1642 # bindings have been discovered via ARP, so instead of provoking an ARP
1643 # request, these packets now get routed to their destinations (which don't
1644 # have static MAC bindings, so they go to the port we've designated as
1645 # accepting "unknown" MACs.)
1651 sip=`ip_to_hex 192 168 $is$js $ks`
1654 if test $is$js = $id$jd; then
1659 dmac=00000000ff$is$js
1660 # Calculate a 4th octet for the destination that is
1661 # unique per $s, avoids the .1 .2 .3 and .254 IP addresses
1662 # that have static MAC bindings, and fits in the range
1664 o4=`expr $is '*' 9 + $js '*' 3 + $ks + 10`
1665 dip=`ip_to_hex 192 168 $id$jd $o4`
1666 test_ip $s $smac $dmac $sip $dip
1668 # Expect the packet egress.
1669 host_mac=8000000000$o4
1672 echo ${host_mac}00000000ff${out_lrp}08004500001c00000000"3f1101"00${sip}${dip}0035111100080000 | trim_zeros >> $outport.expected
1679 # Allow some time for packet forwarding.
1680 # XXX This can be improved.
1683 ovn-sbctl -f csv -d bare --no-heading \
1684 -- --columns=logical_port,ip,mac list mac_binding > mac_bindings
1686 # Now check the packets actually received against the ones expected.
1690 file=hv`vif_to_hv $i$j$k`/vif$i$j$k-tx.pcap
1692 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" $file | trim_zeros > $i$j$k.packets
1693 sort $i$j$k.expected > expout
1694 AT_CHECK([sort $i$j$k.packets], [0], [expout])
1700 # Check the MAC bindings against those expected.
1701 AT_CHECK_UNQUOTED([sort < mac_bindings], [0], [`sort < mac_bindings.expected`
1704 # Gracefully terminate daemons
1705 for daemon in ovn-controller ovn-northd ovsdb-server; do
1706 ovs-appctl -t $daemon exit
1710 # 3 hypervisors, one logical switch, 3 logical ports per hypervisor
1711 AT_SETUP([ovn -- portsecurity : 3 HVs, 1 LS, 3 lports/HV])
1712 AT_KEYWORDS([portsecurity])
1713 AT_SKIP_IF([test $HAVE_PYTHON = no])
1716 # Create hypervisors hv[123].
1717 # Add vif1[123] to hv1, vif2[123] to hv2, vif3[123] to hv3.
1718 # Add all of the vifs to a single logical switch lsw0.
1719 # Turn off port security on vifs vif[123]1
1720 # Turn on l2 port security on vifs vif[123]2
1721 # Turn of l2 and l3 port security on vifs vif[123]3
1722 # Make vif13, vif2[23], vif3[123] destinations for unknown MACs.
1723 ovn-nbctl ls-add lsw0
1728 ovs-vsctl add-br br-phys
1729 ovn_attach n1 br-phys 192.168.0.$i
1732 ovs-vsctl add-port br-int vif$i$j -- set Interface vif$i$j external-ids:iface-id=lp$i$j options:tx_pcap=hv$i/vif$i$j-tx.pcap options:rxq_pcap=hv$i/vif$i$j-rx.pcap ofport-request=$i$j
1733 ovn-nbctl lsp-add lsw0 lp$i$j
1734 if test $j = 1; then
1735 ovn-nbctl lsp-set-addresses lp$i$j "f0:00:00:00:00:$i$j 192.168.0.$i$j" unknown
1736 elif test $j = 2; then
1737 ovn-nbctl lsp-set-addresses lp$i$j "f0:00:00:00:00:$i$j 192.168.0.$i$j"
1738 ovn-nbctl lsp-set-port-security lp$i$j f0:00:00:00:00:$i$j
1740 extra_addr="f0:00:00:00:0$i:$i$j fe80::ea2a:eaff:fe28:$i$j"
1741 ovn-nbctl lsp-set-addresses lp$i$j "f0:00:00:00:00:$i$j 192.168.0.$i$j" "$extra_addr"
1742 ovn-nbctl lsp-set-port-security lp$i$j "f0:00:00:00:00:$i$j 192.168.0.$i$j" "$extra_addr"
1747 # Pre-populate the hypervisors' ARP tables so that we don't lose any
1748 # packets for ARP resolution (native tunneling doesn't queue packets
1749 # for ARP resolution).
1752 # Allow some time for ovn-northd and ovn-controller to catch up.
1753 # XXX This should be more systematic.
1756 # Given the name of a logical port, prints the name of the hypervisor
1757 # on which it is located.
1764 sed 's/\(00\)\{1,\}$//'
1772 # test_ip INPORT SRC_MAC DST_MAC SRC_IP DST_IP OUTPORT...
1774 # This shell function causes an ip packet to be received on INPORT.
1775 # The packet's content has Ethernet destination DST and source SRC
1776 # (each exactly 12 hex digits) and Ethernet type ETHTYPE (4 hex digits).
1777 # The OUTPORTs (zero or more) list the VIFs on which the packet should
1778 # be received. INPORT and the OUTPORTs are specified as logical switch
1779 # port numbers, e.g. 11 for vif11.
1781 # This packet has bad checksums but logical L3 routing doesn't check.
1782 local inport=$1 src_mac=$2 dst_mac=$3 src_ip=$4 dst_ip=$5
1783 local packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}003511110008
1784 shift; shift; shift; shift; shift
1785 hv=`vif_to_hv $inport`
1786 as $hv ovs-appctl netdev-dummy/receive vif$inport $packet
1787 #as $hv ovs-appctl ofproto/trace br-int in_port=$inport $packet
1789 echo $packet | trim_zeros >> $outport.expected
1793 # test_arp INPORT SHA SPA TPA DROP [REPLY_HA]
1795 # Causes a packet to be received on INPORT. The packet is an ARP
1796 # request with SHA, SPA, and TPA as specified. If REPLY_HA is provided, then
1797 # it should be the hardware address of the target to expect to receive in an
1798 # ARP reply; otherwise no reply is expected.
1800 # INPORT is an logical switch port number, e.g. 11 for vif11.
1801 # SHA and REPLY_HA are each 12 hex digits.
1802 # SPA and TPA are each 8 hex digits.
1804 local inport=$1 smac=$2 sha=$3 spa=$4 tpa=$5 drop=$6 reply_ha=$7
1805 local request=ffffffffffff${smac}08060001080006040001${sha}${spa}ffffffffffff${tpa}
1806 hv=`vif_to_hv $inport`
1807 as $hv ovs-appctl netdev-dummy/receive vif$inport $request
1808 #as $hv ovs-appctl ofproto/trace br-int in_port=$inport $request
1809 if test $drop != 1; then
1810 if test X$reply_ha == X; then
1811 # Expect to receive the broadcast ARP on the other logical switch ports
1812 # if no reply is expected.
1816 if test $i$j != $inport; then
1817 echo $request >> $i$j.expected
1822 # Expect to receive the reply, if any.
1823 local reply=${smac}${reply_ha}08060001080006040002${reply_ha}${tpa}${sha}${spa}
1824 echo $reply >> $inport.expected
1829 # test_ipv6 INPORT SRC_MAC DST_MAC SRC_IP DST_IP OUTPORT...
1830 # This function is similar to test_ip() except that it sends
1833 local inport=$1 src_mac=$2 dst_mac=$3 src_ip=$4 dst_ip=$5
1834 local packet=${dst_mac}${src_mac}86dd6000000000083aff${src_ip}${dst_ip}0000000000000000
1835 shift; shift; shift; shift; shift
1836 hv=`vif_to_hv $inport`
1837 as $hv ovs-appctl netdev-dummy/receive vif$inport $packet
1838 #as $hv ovs-appctl ofproto/trace br-int in_port=$inport $packet
1840 echo $packet | trim_zeros >> $outport.expected
1844 # test_icmpv6 INPORT SRC_MAC DST_MAC SRC_IP DST_IP ICMP_TYPE OUTPORT...
1845 # This function is similar to test_ipv6() except it specifies the ICMPv6 type
1846 # of the test packet
1848 local inport=$1 src_mac=$2 dst_mac=$3 src_ip=$4 dst_ip=$5 icmp_type=$6
1849 local packet=${dst_mac}${src_mac}86dd6000000000083aff${src_ip}${dst_ip}${icmp_type}00000000000000
1850 shift; shift; shift; shift; shift; shift
1851 hv=`vif_to_hv $inport`
1852 as $hv ovs-appctl netdev-dummy/receive vif$inport $packet
1853 #as $hv ovs-appctl ofproto/trace br-int in_port=$inport $packet
1855 echo $packet | trim_zeros >> $outport.expected
1860 printf "%02x%02x%02x%02x" "$@"
1864 sip=`ip_to_hex 192 168 0 12`
1865 tip=`ip_to_hex 192 168 0 13`
1866 # the arp packet should be allowed even if lp[123]1 is
1867 # not configured with mac f00000000023 and ip 192.168.0.12
1869 test_arp ${i}1 f00000000023 f00000000023 $sip $tip 0 f00000000013
1871 if test $i != $j; then
1872 test_ip ${i}1 f000000000${i}1 f000000000${j}1 $sip $tip ${j}1
1878 sip=`ip_to_hex 192 168 0 12`
1879 tip=`ip_to_hex 192 168 0 13`
1881 # arp packet should be allowed since lp22 is configured with
1883 test_arp 22 f00000000022 f00000000022 $sip $tip 0 f00000000013
1885 # arp packet should not be allowed since lp32 is not configured with
1887 test_arp 32 f00000000021 f00000000021 $sip $tip 1
1889 # arp packet with sha set to f00000000021 should not be allowed
1891 test_arp 12 f00000000012 f00000000021 $sip $tip 1
1893 # ip packets should be allowed and received since lp[123]2 do not
1894 # have l3 port security
1895 sip=`ip_to_hex 192 168 0 55`
1896 tip=`ip_to_hex 192 168 0 66`
1899 if test $i != $j; then
1900 test_ip ${i}2 f000000000${i}2 f000000000${j}2 $sip $tip ${j}2
1905 # ipv6 packets should be received by lp[123]2
1906 # lp[123]1 can send ipv6 traffic as there is no port security
1907 sip=fe800000000000000000000000000000
1908 tip=ff020000000000000000000000000000
1911 test_ipv6 ${i}1 f000000000${i}1 f000000000${i}2 $sip $tip ${i}2
1915 # l2 and l3 port security
1916 sip=`ip_to_hex 192 168 0 13`
1917 tip=`ip_to_hex 192 168 0 22`
1918 # arp packet should be allowed since lp13 is configured with
1919 # f00000000013 and 192.168.0.13
1920 test_arp 13 f00000000013 f00000000013 $sip $tip 0 f00000000022
1922 # the arp packet should be dropped because lp23 is not configured
1923 # with mac f00000000022
1924 sip=`ip_to_hex 192 168 0 13`
1925 tip=`ip_to_hex 192 168 0 22`
1926 test_arp 23 f00000000022 f00000000022 $sip $tip 1
1928 # the arp packet should be dropped because lp33 is not configured
1929 # with ip 192.168.0.55
1930 spa=`ip_to_hex 192 168 0 55`
1931 tpa=`ip_to_hex 192 168 0 22`
1932 test_arp 33 f00000000031 f00000000031 $spa $tpa 1
1934 # ip packets should not be received by lp[123]3 since
1935 # l3 port security is enabled
1936 sip=`ip_to_hex 192 168 0 55`
1937 tip=`ip_to_hex 192 168 0 66`
1940 test_ip ${i}2 f000000000${i}2 f000000000${j}3 $sip $tip
1944 # ipv6 packets should be dropped for lp[123]3 since
1945 # it is configured with only ipv4 address
1946 sip=fe800000000000000000000000000000
1947 tip=ff020000000000000000000000000000
1950 test_ipv6 ${i}3 f000000000${i}3 f00000000022 $sip $tip
1953 # ipv6 packets should not be received by lp[123]3 with mac f000000000$[123]3
1954 # lp[123]1 can send ipv6 traffic as there is no port security
1956 test_ipv6 ${i}1 f000000000${i}1 f000000000${i}3 $sip $tip
1959 # lp13 has extra port security with mac f0000000113 and ipv6 addr
1960 # fe80::ea2a:eaff:fe28:0012
1962 # ipv4 packet should be dropped for lp13 with mac f0000000113
1963 sip=`ip_to_hex 192 168 0 13`
1964 tip=`ip_to_hex 192 168 0 23`
1965 test_ip 13 f00000000113 f00000000023 $sip $tip
1967 # ipv6 packet should be received by lp[123]3 with mac f0000000{i}{i}3
1968 # and ip6.dst as fe80::ea2a:eaff:fe28:0{i}{i}3.
1969 # lp11 can send ipv6 traffic as there is no port security
1970 sip=ee800000000000000000000000000000
1972 tip=fe80000000000000ea2aeafffe2800{i}3
1973 test_ipv6 11 f00000000011 f000000000{i}${i}3 $sip $tip {i}3
1977 # ipv6 packet should not be received by lp33 with mac f0000000333
1978 # and ip6.dst as fe80::ea2a:eaff:fe28:0023 as it is
1979 # configured with fe80::ea2a:eaff:fe28:0033
1980 # lp11 can send ipv6 traffic as there is no port security
1982 sip=ee800000000000000000000000000000
1983 tip=fe80000000000000ea2aeafffe280023
1984 test_ipv6 11 f00000000011 f00000000333 $sip $tip
1986 # ipv6 packet should be allowed for lp[123]3 with mac f0000000{i}{i}3
1987 # and ip6.src fe80::ea2a:eaff:fe28:0{i}{i}3 and ip6.src ::.
1988 # and should be dropped for any other ip6.src
1989 # lp21 can receive ipv6 traffic as there is no port security
1991 tip=ee800000000000000000000000000000
1993 sip=fe80000000000000ea2aeafffe2800${i}3
1994 test_ipv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip $tip 21
1996 # Test ICMPv6 MLD reports (v1 and v2) and NS for DAD
1997 sip=00000000000000000000000000000000
1998 test_icmpv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip ff020000000000000000000000160000 83 21
1999 test_icmpv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip ff020000000000000000000000160000 8f 21
2000 test_icmpv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip ff0200000000000000ea2aeafffe2800 87 21
2001 # Traffic to non-multicast traffic should be dropped
2002 test_icmpv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip $tip 83
2003 # Traffic of other ICMPv6 types should be dropped
2004 test_icmpv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip ff020000000000000000000000160000 80
2007 sip=ae80000000000000ea2aeafffe2800aa
2008 test_ipv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip $tip
2011 # configure lsp13 to send and received IPv4 packets with an address range
2012 ovn-nbctl lsp-set-port-security lp13 "f0:00:00:00:00:13 192.168.0.13 20.0.0.4/24 10.0.0.0/24"
2016 sip=`ip_to_hex 10 0 0 13`
2017 tip=`ip_to_hex 192 168 0 22`
2018 # arp packet with inner ip 10.0.0.13 should be allowed for lsp13
2019 test_arp 13 f00000000013 f00000000013 $sip $tip 0 f00000000022
2021 sip=`ip_to_hex 10 0 0 14`
2022 tip=`ip_to_hex 192 168 0 23`
2023 # IPv4 packet from lsp13 with src ip 10.0.0.14 destined to lsp23
2024 # with dst ip 192.168.0.23 should be allowed
2025 test_ip 13 f00000000013 f00000000023 $sip $tip 23
2027 sip=`ip_to_hex 192 168 0 33`
2028 tip=`ip_to_hex 10 0 0 15`
2029 # IPv4 packet from lsp33 with src ip 192.168.0.33 destined to lsp13
2030 # with dst ip 10.0.0.15 should be received by lsp13
2031 test_ip 33 f00000000033 f00000000013 $sip $tip 13
2033 sip=`ip_to_hex 192 168 0 33`
2034 tip=`ip_to_hex 20 0 0 4`
2035 # IPv4 packet from lsp33 with src ip 192.168.0.33 destined to lsp13
2036 # with dst ip 20.0.0.4 should be received by lsp13
2037 test_ip 33 f00000000033 f00000000013 $sip $tip 13
2039 sip=`ip_to_hex 192 168 0 33`
2040 tip=`ip_to_hex 20 0 0 5`
2041 # IPv4 packet from lsp33 with src ip 192.168.0.33 destined to lsp13
2042 # with dst ip 20.0.0.5 should not be received by lsp13
2043 test_ip 33 f00000000033 f00000000013 $sip $tip
2045 sip=`ip_to_hex 192 168 0 33`
2046 tip=`ip_to_hex 20 0 0 255`
2047 # IPv4 packet from lsp33 with src ip 192.168.0.33 destined to lsp13
2048 # with dst ip 20.0.0.255 should be received by lsp13
2049 test_ip 33 f00000000033 f00000000013 $sip $tip 13
2051 sip=`ip_to_hex 192 168 0 33`
2052 tip=`ip_to_hex 192 168 0 255`
2053 # IPv4 packet from lsp33 with src ip 192.168.0.33 destined to lsp13
2054 # with dst ip 192.168.0.255 should not be received by lsp13
2055 test_ip 33 f00000000033 f00000000013 $sip $tip
2057 sip=`ip_to_hex 192 168 0 33`
2058 tip=`ip_to_hex 224 0 0 4`
2059 # IPv4 packet from lsp33 with src ip 192.168.0.33 destined to lsp13
2060 # with dst ip 224.0.0.4 should be received by lsp13
2061 test_ip 33 f00000000033 f00000000013 $sip $tip 13
2063 # Allow some time for packet forwarding.
2065 # XXX This can be improved.
2068 #dump information including flow counters
2070 ovn-sbctl dump-flows -- list multicast_group
2072 echo "------ hv1 dump ------"
2073 as hv1 ovs-vsctl show
2074 as hv1 ovs-ofctl -O OpenFlow13 show br-int
2075 as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-int
2077 echo "------ hv2 dump ------"
2078 as hv2 ovs-vsctl show
2079 as hv2 ovs-ofctl -O OpenFlow13 show br-int
2080 as hv2 ovs-ofctl -O OpenFlow13 dump-flows br-int
2082 echo "------ hv3 dump ------"
2083 as hv3 ovs-vsctl show
2084 as hv3 ovs-ofctl -O OpenFlow13 show br-int
2085 as hv3 ovs-ofctl -O OpenFlow13 dump-flows br-int
2087 # Now check the packets actually received against the ones expected.
2090 file=hv$i/vif$i$j-tx.pcap
2092 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" $file | trim_zeros > $i$j.packets
2093 sort $i$j.expected > expout
2094 AT_CHECK([sort $i$j.packets], [0], [expout])
2099 # Gracefully terminate daemons
2100 for sim in hv1 hv2 hv3; do
2102 OVS_APP_EXIT_AND_WAIT([ovn-controller])
2103 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2104 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2108 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2111 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2114 OVS_APP_EXIT_AND_WAIT([ovn-northd])
2117 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2118 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2122 AT_SETUP([ovn -- 2 HVs, 2 LS, 1 lport/LS, 2 peer LRs])
2123 AT_KEYWORDS([ovnpeer])
2124 AT_SKIP_IF([test $HAVE_PYTHON = no])
2128 # Two LRs - R1 and R2 that are connected to each other as peers in 20.0.0.0/24
2129 # network. R1 has a switchs ls1 (191.168.1.0/24) connected to it.
2130 # R2 has ls2 (172.16.1.0/24) connected to it.
2135 ovn-nbctl ls-add ls1
2136 ovn-nbctl ls-add ls2
2139 ovn-nbctl lrp-add R1 ls1 00:00:00:01:02:03 192.168.1.1/24 rp-ls1
2141 ovn-nbctl lsp-add ls1 rp-ls1 -- set Logical_Switch_Port rp-ls1 type=router \
2142 options:router-port=ls1 addresses=\"00:00:00:01:02:03\"
2145 ovn-nbctl lrp-add R2 ls2 00:00:00:01:02:04 172.16.1.1/24 rp-ls2
2147 ovn-nbctl lsp-add ls2 rp-ls2 -- set Logical_Switch_Port rp-ls2 type=router \
2148 options:router-port=ls2 addresses=\"00:00:00:01:02:04\"
2151 ovn-nbctl lrp-add R1 R1_R2 00:00:00:02:03:04 20.0.0.1/24 R2_R1
2152 ovn-nbctl lrp-add R2 R2_R1 00:00:00:02:03:05 20.0.0.2/24 R1_R2
2154 ovn-nbctl set Logical_Router R1 default_gw="20.0.0.2"
2155 ovn-nbctl set Logical_Router R2 default_gw="20.0.0.1"
2157 # Create logical port ls1-lp1 in ls1
2158 ovn-nbctl lsp-add ls1 ls1-lp1 \
2159 -- lsp-set-addresses ls1-lp1 "f0:00:00:01:02:03 192.168.1.2"
2161 # Create logical port ls2-lp1 in ls2
2162 ovn-nbctl lsp-add ls2 ls2-lp1 \
2163 -- lsp-set-addresses ls2-lp1 "f0:00:00:01:02:04 172.16.1.2"
2165 # Create two hypervisor and create OVS ports corresponding to logical ports.
2170 ovs-vsctl add-br br-phys
2171 ovn_attach n1 br-phys 192.168.0.1
2172 ovs-vsctl -- add-port br-int hv1-vif1 -- \
2173 set interface hv1-vif1 external-ids:iface-id=ls1-lp1 \
2174 options:tx_pcap=hv1/vif1-tx.pcap \
2175 options:rxq_pcap=hv1/vif1-rx.pcap \
2180 ovs-vsctl add-br br-phys
2181 ovn_attach n1 br-phys 192.168.0.2
2182 ovs-vsctl -- add-port br-int hv2-vif1 -- \
2183 set interface hv2-vif1 external-ids:iface-id=ls2-lp1 \
2184 options:tx_pcap=hv2/vif1-tx.pcap \
2185 options:rxq_pcap=hv2/vif1-rx.pcap \
2189 # Pre-populate the hypervisors' ARP tables so that we don't lose any
2190 # packets for ARP resolution (native tunneling doesn't queue packets
2191 # for ARP resolution).
2194 # Allow some time for ovn-northd and ovn-controller to catch up.
2195 # XXX This should be more systematic.
2198 # Send ip packets between the two ports.
2200 printf "%02x%02x%02x%02x" "$@"
2203 sed 's/\(00\)\{1,\}$//'
2207 src_mac="f00000010203"
2208 dst_mac="000000010203"
2209 src_ip=`ip_to_hex 192 168 1 2`
2210 dst_ip=`ip_to_hex 172 16 1 2`
2211 packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
2212 as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet
2215 echo "---------NB dump-----"
2217 echo "---------------------"
2218 ovn-nbctl list logical_router
2219 echo "---------------------"
2220 ovn-nbctl list logical_router_port
2221 echo "---------------------"
2223 echo "---------SB dump-----"
2224 ovn-sbctl list datapath_binding
2225 echo "---------------------"
2226 ovn-sbctl list port_binding
2227 echo "---------------------"
2229 echo "------ hv1 dump ----------"
2230 as hv1 ovs-ofctl show br-int
2231 as hv1 ovs-ofctl dump-flows br-int
2232 echo "------ hv2 dump ----------"
2233 as hv2 ovs-ofctl show br-int
2234 as hv2 ovs-ofctl dump-flows br-int
2237 src_mac="000000010204"
2238 dst_mac="f00000010204"
2239 expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000
2241 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv2/vif1-tx.pcap | trim_zeros > received.packets
2242 echo $expected | trim_zeros > expout
2243 AT_CHECK([cat received.packets], [0], [expout])
2245 for sim in hv1 hv2; do
2247 OVS_APP_EXIT_AND_WAIT([ovn-controller])
2248 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2249 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2253 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2256 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2259 OVS_APP_EXIT_AND_WAIT([ovn-northd])
2262 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2263 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2268 AT_SETUP([ovn -- 1 HVs, 2 LSs, 1 lport/LS, 1 LR])
2269 AT_KEYWORDS([router-admin-state])
2270 AT_SKIP_IF([test $HAVE_PYTHON = no])
2274 # One LR - R1 has switch ls1 (191.168.1.0/24) connected to it,
2275 # and has switch ls2 (172.16.1.0/24) connected to it.
2279 ovn-nbctl ls-add ls1
2280 ovn-nbctl ls-add ls2
2283 ovn-nbctl lrp-add R1 ls1 00:00:00:01:02:03 192.168.1.1/24 rp-ls1
2284 ovn-nbctl lsp-add ls1 rp-ls1 -- set Logical_Switch_Port rp-ls1 type=router \
2285 options:router-port=ls1 addresses=\"00:00:00:01:02:03\"
2288 ovn-nbctl lrp-add R1 ls2 00:00:00:01:02:04 172.16.1.1/24 rp-ls2
2289 ovn-nbctl lsp-add ls2 rp-ls2 -- set Logical_Switch_Port rp-ls2 type=router \
2290 options:router-port=ls2 addresses=\"00:00:00:01:02:04\"
2292 # Create logical port ls1-lp1 in ls1
2293 ovn-nbctl lsp-add ls1 ls1-lp1 \
2294 -- lsp-set-addresses ls1-lp1 "f0:00:00:01:02:03 192.168.1.2"
2296 # Create logical port ls2-lp1 in ls2
2297 ovn-nbctl lsp-add ls2 ls2-lp1 \
2298 -- lsp-set-addresses ls2-lp1 "f0:00:00:01:02:04 172.16.1.2"
2300 # Create one hypervisor and create OVS ports corresponding to logical ports.
2305 ovs-vsctl add-br br-phys
2306 ovn_attach n1 br-phys 192.168.0.1
2307 ovs-vsctl -- add-port br-int vif1 -- \
2308 set interface vif1 external-ids:iface-id=ls1-lp1 \
2309 options:tx_pcap=hv1/vif1-tx.pcap \
2310 options:rxq_pcap=hv1/vif1-rx.pcap \
2313 ovs-vsctl -- add-port br-int vif2 -- \
2314 set interface vif2 external-ids:iface-id=ls2-lp1 \
2315 options:tx_pcap=hv1/vif2-tx.pcap \
2316 options:rxq_pcap=hv1/vif2-rx.pcap \
2320 # Allow some time for ovn-northd and ovn-controller to catch up.
2321 # XXX This should be more systematic.
2324 # Send ip packets between the two ports.
2326 printf "%02x%02x%02x%02x" "$@"
2329 sed 's/\(00\)\{1,\}$//'
2333 src_mac="f00000010203"
2334 dst_mac="000000010203"
2335 src_ip=`ip_to_hex 192 168 1 2`
2336 dst_ip=`ip_to_hex 172 16 1 2`
2337 packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
2338 as hv1 ovs-appctl netdev-dummy/receive vif1 $packet
2341 echo "---------NB dump-----"
2343 echo "---------------------"
2344 ovn-nbctl list logical_router
2345 echo "---------------------"
2346 ovn-nbctl list logical_router_port
2347 echo "---------------------"
2349 echo "---------SB dump-----"
2350 ovn-sbctl list datapath_binding
2351 echo "---------------------"
2352 ovn-sbctl list logical_flow
2353 echo "---------------------"
2355 echo "------ hv1 dump ----------"
2356 as hv1 ovs-ofctl dump-flows br-int
2360 ovn-nbctl set Logical_Router R1 enabled=false
2362 echo "---------SB dump-----"
2363 ovn-sbctl list datapath_binding
2364 echo "---------------------"
2365 ovn-sbctl list logical_flow
2366 echo "---------------------"
2368 echo "------ hv1 dump ----------"
2369 as hv1 ovs-ofctl dump-flows br-int
2371 # Allow some time for the disabling of logical router R1 to propagate.
2372 # XXX This should be more systematic.
2375 as hv1 ovs-appctl netdev-dummy/receive vif1 $packet
2378 expect_src_mac="000000010204"
2379 expect_dst_mac="f00000010204"
2380 expected=${expect_dst_mac}${expect_src_mac}08004500001c000000003f110100${src_ip}${dst_ip}0035111100080000
2382 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif2-tx.pcap | trim_zeros > received.packets
2383 echo $expected | trim_zeros > expout
2384 AT_CHECK([cat received.packets], [0], [expout])
2388 OVS_APP_EXIT_AND_WAIT([ovn-controller])
2389 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2390 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2393 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2396 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2399 OVS_APP_EXIT_AND_WAIT([ovn-northd])
2402 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2403 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2407 AT_SETUP([ovn -- 2 HVs, 3 LS, 1 lport/LS, 2 peer LRs, static routes])
2408 AT_KEYWORDS([ovnstaticroutespeer])
2409 AT_SKIP_IF([test $HAVE_PYTHON = no])
2413 # Two LRs - R1 and R2 that are connected to each other as peers in 20.0.0.0/24
2414 # network. R1 has switchess foo (192.168.1.0/24)
2416 # R2 has alice (172.16.1.0/24) and bob (172.16.2.0/24) connected to it.
2421 ovn-nbctl ls-add foo
2422 ovn-nbctl ls-add alice
2423 ovn-nbctl ls-add bob
2426 ovn-nbctl lrp-add R1 foo 00:00:00:01:02:03 192.168.1.1/24 rp-foo
2427 ovn-nbctl lsp-add foo rp-foo -- set Logical_Switch_Port rp-foo type=router \
2428 options:router-port=foo addresses=\"00:00:00:01:02:03\"
2430 # Connect alice to R2
2431 ovn-nbctl lrp-add R2 alice 00:00:00:01:02:04 172.16.1.1/24 rp-alice
2432 ovn-nbctl lsp-add alice rp-alice -- set Logical_Switch_Port rp-alice \
2433 type=router options:router-port=alice addresses=\"00:00:00:01:02:04\"
2436 ovn-nbctl lrp-add R2 bob 00:00:00:01:02:05 172.16.2.1/24 rp-bob
2437 ovn-nbctl lsp-add bob rp-bob -- set Logical_Switch_Port rp-bob type=router \
2438 options:router-port=bob addresses=\"00:00:00:01:02:05\"
2441 ovn-nbctl lrp-add R1 R1_R2 00:00:00:02:03:04 20.0.0.1/24 R2_R1
2442 ovn-nbctl lrp-add R2 R2_R1 00:00:00:02:03:05 20.0.0.2/24 R1_R2
2444 #install static routes
2445 ovn-nbctl lr-route-add R1 172.16.1.0/24 20.0.0.2
2446 ovn-nbctl lr-route-add R2 172.16.2.0/24 20.0.0.2 R1_R2
2447 ovn-nbctl lr-route-add R2 192.168.1.0/24 20.0.0.1
2449 # Create logical port foo1 in foo
2450 ovn-nbctl lsp-add foo foo1 \
2451 -- lsp-set-addresses foo1 "f0:00:00:01:02:03 192.168.1.2"
2453 # Create logical port alice1 in alice
2454 ovn-nbctl lsp-add alice alice1 \
2455 -- lsp-set-addresses alice1 "f0:00:00:01:02:04 172.16.1.2"
2457 # Create logical port bob1 in bob
2458 ovn-nbctl lsp-add bob bob1 \
2459 -- lsp-set-addresses bob1 "f0:00:00:01:02:05 172.16.2.2"
2461 # Create two hypervisor and create OVS ports corresponding to logical ports.
2466 ovs-vsctl add-br br-phys
2467 ovn_attach n1 br-phys 192.168.0.1
2468 ovs-vsctl -- add-port br-int hv1-vif1 -- \
2469 set interface hv1-vif1 external-ids:iface-id=foo1 \
2470 options:tx_pcap=hv1/vif1-tx.pcap \
2471 options:rxq_pcap=hv1/vif1-rx.pcap \
2474 ovs-vsctl -- add-port br-int hv1-vif2 -- \
2475 set interface hv1-vif2 external-ids:iface-id=alice1 \
2476 options:tx_pcap=hv1/vif2-tx.pcap \
2477 options:rxq_pcap=hv1/vif2-rx.pcap \
2482 ovs-vsctl add-br br-phys
2483 ovn_attach n1 br-phys 192.168.0.2
2484 ovs-vsctl -- add-port br-int hv2-vif1 -- \
2485 set interface hv2-vif1 external-ids:iface-id=bob1 \
2486 options:tx_pcap=hv2/vif1-tx.pcap \
2487 options:rxq_pcap=hv2/vif1-rx.pcap \
2491 # Pre-populate the hypervisors' ARP tables so that we don't lose any
2492 # packets for ARP resolution (native tunneling doesn't queue packets
2493 # for ARP resolution).
2496 # Allow some time for ovn-northd and ovn-controller to catch up.
2497 # XXX This should be more systematic.
2501 printf "%02x%02x%02x%02x" "$@"
2504 sed 's/\(00\)\{1,\}$//'
2507 # Send ip packets between foo1 and alice1
2508 src_mac="f00000010203"
2509 dst_mac="000000010203"
2510 src_ip=`ip_to_hex 192 168 1 2`
2511 dst_ip=`ip_to_hex 172 16 1 2`
2512 packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
2513 as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet
2515 # Send ip packets between foo1 and bob1
2516 src_mac="f00000010203"
2517 dst_mac="000000010203"
2518 src_ip=`ip_to_hex 192 168 1 2`
2519 dst_ip=`ip_to_hex 172 16 2 2`
2520 packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
2521 as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet
2523 echo "---------NB dump-----"
2525 echo "---------------------"
2526 ovn-nbctl list logical_router
2527 echo "---------------------"
2528 ovn-nbctl list logical_router_port
2529 echo "---------------------"
2531 echo "---------SB dump-----"
2532 ovn-sbctl list datapath_binding
2533 echo "---------------------"
2534 ovn-sbctl list port_binding
2535 echo "---------------------"
2537 echo "------ hv1 dump ----------"
2538 as hv1 ovs-ofctl dump-flows br-int
2539 echo "------ hv2 dump ----------"
2540 as hv2 ovs-ofctl dump-flows br-int
2542 # Packet to Expect at bob1
2543 src_mac="000000010205"
2544 dst_mac="f00000010205"
2545 src_ip=`ip_to_hex 192 168 1 2`
2546 dst_ip=`ip_to_hex 172 16 2 2`
2547 expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000
2549 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv2/vif1-tx.pcap | trim_zeros > received.packets
2550 echo $expected | trim_zeros > expout
2551 AT_CHECK([cat received.packets], [0], [expout])
2553 # Packet to Expect at alice1
2554 src_mac="000000010204"
2555 dst_mac="f00000010204"
2556 src_ip=`ip_to_hex 192 168 1 2`
2557 dst_ip=`ip_to_hex 172 16 1 2`
2558 expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000
2560 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif2-tx.pcap | trim_zeros > received1.packets
2561 echo $expected | trim_zeros > expout
2562 AT_CHECK([cat received1.packets], [0], [expout])
2564 for sim in hv1 hv2; do
2566 OVS_APP_EXIT_AND_WAIT([ovn-controller])
2567 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2568 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2572 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2575 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2578 OVS_APP_EXIT_AND_WAIT([ovn-northd])
2581 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2582 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2586 AT_SETUP([ovn -- send gratuitous arp on localnet])
2589 ovn-nbctl ls-add lsw0
2597 ovn_attach n1 br-phys 192.168.0.1
2599 AT_CHECK([ovs-vsctl set Open_vSwitch . external-ids:ovn-bridge-mappings=physnet1:br-eth0])
2600 AT_CHECK([ovs-vsctl add-port br-eth0 snoopvif -- set Interface snoopvif options:tx_pcap=hv/snoopvif-tx.pcap options:rxq_pcap=hv/snoopvif-rx.pcap])
2603 AT_CHECK([ovn-nbctl lsp-add lsw0 localvif1])
2604 AT_CHECK([ovn-nbctl lsp-set-addresses localvif1 "f0:00:00:00:00:01 192.168.1.2"])
2605 AT_CHECK([ovn-nbctl lsp-set-port-security localvif1 "f0:00:00:00:00:01"])
2607 # Create a localnet port.
2608 AT_CHECK([ovn-nbctl lsp-add lsw0 ln_port])
2609 AT_CHECK([ovn-nbctl lsp-set-addresses ln_port unknown])
2610 AT_CHECK([ovn-nbctl lsp-set-type ln_port localnet])
2611 AT_CHECK([ovn-nbctl lsp-set-options ln_port network_name=physnet1])
2613 AT_CHECK([ovs-vsctl add-port br-int localvif1 -- set Interface localvif1 external_ids:iface-id=localvif1])
2615 # Wait for packet to be received.
2616 OVS_WAIT_UNTIL([test `wc -c < "hv/snoopvif-tx.pcap"` -ge 50])
2618 sed 's/\(00\)\{1,\}$//'
2620 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv/snoopvif-tx.pcap | trim_zeros > packets
2621 expected="fffffffffffff0000000000108060001080006040001f00000000001c0a80102000000000000c0a80102"
2622 echo $expected > expout
2623 AT_CHECK([sort packets], [0], [expout])
2626 # Delete the localnet ports.
2627 AT_CHECK([ovs-vsctl del-port localvif1])
2628 AT_CHECK([ovn-nbctl lsp-del ln_port])
2631 OVS_APP_EXIT_AND_WAIT([ovn-controller])
2632 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2633 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2636 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2639 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2642 OVS_APP_EXIT_AND_WAIT([ovn-northd])
2645 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2646 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2650 AT_SETUP([ovn -- 2 HVs, 3 LRs connected via LS, static routes])
2651 AT_KEYWORDS([ovnstaticroutes])
2652 AT_SKIP_IF([test $HAVE_PYTHON = no])
2656 # Three LRs - R1, R2 and R3 that are connected to each other via LS "join"
2657 # in 20.0.0.0/24 network. R1 has switchess foo (192.168.1.0/24)
2658 # connected to it. R2 has alice (172.16.1.0/24) and R3 has bob (10.32.1.0/24)
2665 ovn-nbctl ls-add foo
2666 ovn-nbctl ls-add alice
2667 ovn-nbctl ls-add bob
2668 ovn-nbctl ls-add join
2671 ovn-nbctl lrp-add R1 foo 00:00:01:01:02:03 192.168.1.1/24
2672 ovn-nbctl lsp-add foo rp-foo -- set Logical_Switch_Port rp-foo type=router \
2673 options:router-port=foo addresses=\"00:00:01:01:02:03\"
2675 # Connect alice to R2
2676 ovn-nbctl lrp-add R2 alice 00:00:02:01:02:03 172.16.1.1/24
2677 ovn-nbctl lsp-add alice rp-alice -- set Logical_Switch_Port rp-alice \
2678 type=router options:router-port=alice addresses=\"00:00:02:01:02:03\"
2681 ovn-nbctl lrp-add R3 bob 00:00:03:01:02:03 10.32.1.1/24
2682 ovn-nbctl lsp-add bob rp-bob -- set Logical_Switch_Port rp-bob \
2683 type=router options:router-port=bob addresses=\"00:00:03:01:02:03\"
2685 # Connect R1 to join
2686 ovn-nbctl lrp-add R1 R1_join 00:00:04:01:02:03 20.0.0.1/24
2687 ovn-nbctl lsp-add join r1-join -- set Logical_Switch_Port r1-join \
2688 type=router options:router-port=R1_join addresses='"00:00:04:01:02:03"'
2690 # Connect R2 to join
2691 ovn-nbctl lrp-add R2 R2_join 00:00:04:01:02:04 20.0.0.2/24
2692 ovn-nbctl lsp-add join r2-join -- set Logical_Switch_Port r2-join \
2693 type=router options:router-port=R2_join addresses='"00:00:04:01:02:04"'
2695 # Connect R3 to join
2696 ovn-nbctl lrp-add R3 R3_join 00:00:04:01:02:05 20.0.0.3/24
2697 ovn-nbctl lsp-add join r3-join -- set Logical_Switch_Port r3-join \
2698 type=router options:router-port=R3_join addresses='"00:00:04:01:02:05"'
2700 #install static routes
2701 ovn-nbctl lr-route-add R1 172.16.1.0/24 20.0.0.2
2702 ovn-nbctl lr-route-add R1 10.32.1.0/24 20.0.0.3
2704 ovn-nbctl lr-route-add R2 192.168.1.0/24 20.0.0.1
2705 ovn-nbctl lr-route-add R2 10.32.1.0/24 20.0.0.3
2707 ovn-nbctl lr-route-add R3 192.168.1.0/24 20.0.0.1
2708 ovn-nbctl lr-route-add R3 172.16.1.0/24 20.0.0.2
2710 # Create logical port foo1 in foo
2711 ovn-nbctl lsp-add foo foo1 \
2712 -- lsp-set-addresses foo1 "f0:00:00:01:02:03 192.168.1.2"
2714 # Create logical port alice1 in alice
2715 ovn-nbctl lsp-add alice alice1 \
2716 -- lsp-set-addresses alice1 "f0:00:00:01:02:04 172.16.1.2"
2718 # Create logical port bob1 in bob
2719 ovn-nbctl lsp-add bob bob1 \
2720 -- lsp-set-addresses bob1 "f0:00:00:01:02:05 10.32.1.2"
2722 # Create two hypervisor and create OVS ports corresponding to logical ports.
2727 ovs-vsctl add-br br-phys
2728 ovn_attach n1 br-phys 192.168.0.1
2729 ovs-vsctl -- add-port br-int hv1-vif1 -- \
2730 set interface hv1-vif1 external-ids:iface-id=foo1 \
2731 options:tx_pcap=hv1/vif1-tx.pcap \
2732 options:rxq_pcap=hv1/vif1-rx.pcap \
2735 ovs-vsctl -- add-port br-int hv1-vif2 -- \
2736 set interface hv1-vif2 external-ids:iface-id=alice1 \
2737 options:tx_pcap=hv1/vif2-tx.pcap \
2738 options:rxq_pcap=hv1/vif2-rx.pcap \
2743 ovs-vsctl add-br br-phys
2744 ovn_attach n1 br-phys 192.168.0.2
2745 ovs-vsctl -- add-port br-int hv2-vif1 -- \
2746 set interface hv2-vif1 external-ids:iface-id=bob1 \
2747 options:tx_pcap=hv2/vif1-tx.pcap \
2748 options:rxq_pcap=hv2/vif1-rx.pcap \
2752 # Pre-populate the hypervisors' ARP tables so that we don't lose any
2753 # packets for ARP resolution (native tunneling doesn't queue packets
2754 # for ARP resolution).
2757 # Allow some time for ovn-northd and ovn-controller to catch up.
2758 # XXX This should be more systematic.
2762 printf "%02x%02x%02x%02x" "$@"
2765 sed 's/\(00\)\{1,\}$//'
2768 # Send ip packets between foo1 and alice1
2769 src_mac="f00000010203"
2770 dst_mac="000001010203"
2771 src_ip=`ip_to_hex 192 168 1 2`
2772 dst_ip=`ip_to_hex 172 16 1 2`
2773 packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
2774 as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet
2775 as hv1 ovs-appctl ofproto/trace br-int in_port=1 $packet
2777 # Send ip packets between foo1 and bob1
2778 src_mac="f00000010203"
2779 dst_mac="000001010203"
2780 src_ip=`ip_to_hex 192 168 1 2`
2781 dst_ip=`ip_to_hex 10 32 1 2`
2782 packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
2783 as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet
2785 echo "---------NB dump-----"
2787 echo "---------------------"
2788 ovn-nbctl list logical_router
2789 echo "---------------------"
2790 ovn-nbctl list logical_router_port
2791 echo "---------------------"
2793 echo "---------SB dump-----"
2794 ovn-sbctl list datapath_binding
2795 echo "---------------------"
2796 ovn-sbctl list port_binding
2797 echo "---------------------"
2798 ovn-sbctl dump-flows
2799 echo "---------------------"
2801 echo "------ hv1 dump ----------"
2802 as hv1 ovs-ofctl show br-int
2803 as hv1 ovs-ofctl dump-flows br-int
2804 echo "------ hv2 dump ----------"
2805 as hv2 ovs-ofctl show br-int
2806 as hv2 ovs-ofctl dump-flows br-int
2807 echo "----------------------------"
2809 # Packet to Expect at bob1
2810 src_mac="000003010203"
2811 dst_mac="f00000010205"
2812 src_ip=`ip_to_hex 192 168 1 2`
2813 dst_ip=`ip_to_hex 10 32 1 2`
2814 expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000
2816 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv2/vif1-tx.pcap | trim_zeros > received.packets
2817 echo $expected | trim_zeros > expout
2818 AT_CHECK([cat received.packets], [0], [expout])
2820 # Packet to Expect at alice1
2821 src_mac="000002010203"
2822 dst_mac="f00000010204"
2823 src_ip=`ip_to_hex 192 168 1 2`
2824 dst_ip=`ip_to_hex 172 16 1 2`
2825 expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000
2827 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif2-tx.pcap | trim_zeros > received1.packets
2828 echo $expected | trim_zeros > expout
2829 AT_CHECK([cat received1.packets], [0], [expout])
2831 for sim in hv1 hv2; do
2833 OVS_APP_EXIT_AND_WAIT([ovn-controller])
2834 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2835 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2839 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2842 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2845 OVS_APP_EXIT_AND_WAIT([ovn-northd])
2848 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2849 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2853 AT_SETUP([ovn -- 2 HVs, 2 LRs connected via LS, gateway router])
2854 AT_KEYWORDS([ovngatewayrouter])
2855 AT_SKIP_IF([test $HAVE_PYTHON = no])
2859 # Two LRs - R1 and R2 that are connected to each other via LS "join"
2860 # in 20.0.0.0/24 network. R1 has switchess foo (192.168.1.0/24)
2861 # connected to it. R2 has alice (172.16.1.0/24) connected to it.
2862 # R2 is a gateway router.
2866 # Create two hypervisor and create OVS ports corresponding to logical ports.
2871 ovs-vsctl add-br br-phys
2872 ovn_attach n1 br-phys 192.168.0.1
2873 ovs-vsctl -- add-port br-int hv1-vif1 -- \
2874 set interface hv1-vif1 external-ids:iface-id=foo1 \
2875 options:tx_pcap=hv1/vif1-tx.pcap \
2876 options:rxq_pcap=hv1/vif1-rx.pcap \
2882 ovs-vsctl add-br br-phys
2883 ovn_attach n1 br-phys 192.168.0.2
2884 ovs-vsctl -- add-port br-int hv2-vif1 -- \
2885 set interface hv2-vif1 external-ids:iface-id=alice1 \
2886 options:tx_pcap=hv2/vif1-tx.pcap \
2887 options:rxq_pcap=hv2/vif1-rx.pcap \
2890 # Pre-populate the hypervisors' ARP tables so that we don't lose any
2891 # packets for ARP resolution (native tunneling doesn't queue packets
2892 # for ARP resolution).
2895 ovn-nbctl create Logical_Router name=R1
2896 ovn-nbctl create Logical_Router name=R2 options:chassis="hv2"
2898 ovn-nbctl ls-add foo
2899 ovn-nbctl ls-add alice
2900 ovn-nbctl ls-add join
2903 ovn-nbctl lrp-add R1 foo 00:00:01:01:02:03 192.168.1.1/24
2904 ovn-nbctl lsp-add foo rp-foo -- set Logical_Switch_Port rp-foo \
2905 type=router options:router-port=foo addresses=\"00:00:01:01:02:03\"
2907 # Connect alice to R2
2908 ovn-nbctl lrp-add R2 alice 00:00:02:01:02:03 172.16.1.1/24
2909 ovn-nbctl lsp-add alice rp-alice -- set Logical_Switch_Port rp-alice \
2910 type=router options:router-port=alice addresses=\"00:00:02:01:02:03\"
2912 # Connect R1 to join
2913 ovn-nbctl lrp-add R1 R1_join 00:00:04:01:02:03 20.0.0.1/24
2914 ovn-nbctl lsp-add join r1-join -- set Logical_Switch_Port r1-join \
2915 type=router options:router-port=R1_join addresses='"00:00:04:01:02:03"'
2917 # Connect R2 to join
2918 ovn-nbctl lrp-add R2 R2_join 00:00:04:01:02:04 20.0.0.2/24
2919 ovn-nbctl lsp-add join r2-join -- set Logical_Switch_Port r2-join \
2920 type=router options:router-port=R2_join addresses='"00:00:04:01:02:04"'
2923 #install static routes
2924 ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \
2925 ip_prefix=172.16.1.0/24 nexthop=20.0.0.2 -- add Logical_Router \
2926 R1 static_routes @lrt
2928 ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \
2929 ip_prefix=192.168.1.0/24 nexthop=20.0.0.1 -- add Logical_Router \
2930 R2 static_routes @lrt
2932 # Create logical port foo1 in foo
2933 ovn-nbctl lsp-add foo foo1 \
2934 -- lsp-set-addresses foo1 "f0:00:00:01:02:03 192.168.1.2"
2936 # Create logical port alice1 in alice
2937 ovn-nbctl lsp-add alice alice1 \
2938 -- lsp-set-addresses alice1 "f0:00:00:01:02:04 172.16.1.2"
2941 # Allow some time for ovn-northd and ovn-controller to catch up.
2942 # XXX This should be more systematic.
2946 printf "%02x%02x%02x%02x" "$@"
2949 sed 's/\(00\)\{1,\}$//'
2952 # Send ip packets between foo1 and alice1
2953 src_mac="f00000010203"
2954 dst_mac="000001010203"
2955 src_ip=`ip_to_hex 192 168 1 2`
2956 dst_ip=`ip_to_hex 172 16 1 2`
2957 packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
2959 echo "---------NB dump-----"
2961 echo "---------------------"
2962 ovn-nbctl list logical_router
2963 echo "---------------------"
2964 ovn-nbctl list logical_router_port
2965 echo "---------------------"
2967 echo "---------SB dump-----"
2968 ovn-sbctl list datapath_binding
2969 echo "---------------------"
2970 ovn-sbctl list port_binding
2971 echo "---------------------"
2972 ovn-sbctl dump-flows
2973 echo "---------------------"
2974 ovn-sbctl list chassis
2975 ovn-sbctl list encap
2976 echo "---------------------"
2978 echo "------ hv1 dump ----------"
2979 as hv1 ovs-ofctl show br-int
2980 as hv1 ovs-ofctl dump-flows br-int
2981 echo "------ hv2 dump ----------"
2982 as hv2 ovs-ofctl show br-int
2983 as hv2 ovs-ofctl dump-flows br-int
2984 echo "----------------------------"
2986 # Packet to Expect at alice1
2987 src_mac="000002010203"
2988 dst_mac="f00000010204"
2989 src_ip=`ip_to_hex 192 168 1 2`
2990 dst_ip=`ip_to_hex 172 16 1 2`
2991 expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000
2994 as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet
2995 as hv1 ovs-appctl ofproto/trace br-int in_port=1 $packet
2997 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv2/vif1-tx.pcap | trim_zeros > received1.packets
2998 echo $expected | trim_zeros > expout
2999 AT_CHECK([cat received1.packets], [0], [expout])
3001 for sim in hv1 hv2; do
3003 OVS_APP_EXIT_AND_WAIT([ovn-controller])
3004 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
3005 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3009 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3012 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3015 OVS_APP_EXIT_AND_WAIT([ovn-northd])
3018 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
3019 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3023 AT_SETUP([ovn -- icmp_reply: 1 HVs, 2 LSs, 1 lport/LS, 1 LR])
3024 AT_KEYWORDS([router-icmp-reply])
3025 AT_SKIP_IF([test $HAVE_PYTHON = no])
3029 # One LR - R1 has switch ls1 (191.168.1.0/24) connected to it,
3030 # and has switch ls2 (172.16.1.0/24) connected to it.
3034 ovn-nbctl ls-add ls1
3035 ovn-nbctl ls-add ls2
3038 ovn-nbctl lrp-add R1 ls1 00:00:00:01:02:f1 192.168.1.1/24
3039 ovn-nbctl lsp-add ls1 rp-ls1 -- set Logical_Switch_Port rp-ls1 \
3040 type=router options:router-port=ls1 addresses=\"00:00:00:01:02:f1\"
3043 ovn-nbctl lrp-add R1 ls2 00:00:00:01:02:f2 172.16.1.1/24
3044 ovn-nbctl lsp-add ls2 rp-ls2 -- set Logical_Switch_Port rp-ls2 \
3045 type=router options:router-port=ls2 addresses=\"00:00:00:01:02:f2\"
3047 # Create logical port ls1-lp1 in ls1
3048 ovn-nbctl lsp-add ls1 ls1-lp1 \
3049 -- lsp-set-addresses ls1-lp1 "00:00:00:01:02:03 192.168.1.2"
3051 # Create logical port ls2-lp1 in ls2
3052 ovn-nbctl lsp-add ls2 ls2-lp1 \
3053 -- lsp-set-addresses ls2-lp1 "00:00:00:01:02:04 172.16.1.2"
3055 # Create one hypervisor and create OVS ports corresponding to logical ports.
3060 ovs-vsctl add-br br-phys
3061 ovn_attach n1 br-phys 192.168.0.1
3062 ovs-vsctl -- add-port br-int vif1 -- \
3063 set interface vif1 external-ids:iface-id=ls1-lp1 \
3064 options:tx_pcap=hv1/vif1-tx.pcap \
3065 options:rxq_pcap=hv1/vif1-rx.pcap \
3068 ovs-vsctl -- add-port br-int vif2 -- \
3069 set interface vif2 external-ids:iface-id=ls2-lp1 \
3070 options:tx_pcap=hv1/vif2-tx.pcap \
3071 options:rxq_pcap=hv1/vif2-rx.pcap \
3075 # Allow some time for ovn-northd and ovn-controller to catch up.
3076 # XXX This should be more systematic.
3081 printf "%02x%02x%02x%02x" "$@"
3084 sed 's/\(00\)\{1,\}$//'
3089 # test_ipv4_icmp_request INPORT ETH_SRC ETH_DST IPV4_SRC IPV4_DST IP_CHKSUM ICMP_CHKSUM [EXP_IP_CHKSUM EXP_ICMP_CHKSUM]
3091 # Causes a packet to be received on INPORT. The packet is an ICMPv4
3092 # request with ETH_SRC, ETH_DST, IPV4_SRC, IPV4_DST, IP_CHSUM and
3093 # ICMP_CHKSUM as specified. If EXP_IP_CHKSUM and EXP_ICMP_CHKSUM are
3094 # provided, then it should be the ip and icmp checksums of the packet
3095 # responded; otherwise, no reply is expected.
3096 # In the absence of an ip checksum calculation helpers, this relies
3097 # on the caller to provide the checksums for the ip and icmp headers.
3098 # XXX This should be more systematic.
3100 # INPORT is an lport number, e.g. 11 for vif11.
3101 # ETH_SRC and ETH_DST are each 12 hex digits.
3102 # IPV4_SRC and IPV4_DST are each 8 hex digits.
3103 # IP_CHSUM and ICMP_CHKSUM are each 4 hex digits.
3104 # EXP_IP_CHSUM and EXP_ICMP_CHKSUM are each 4 hex digits.
3105 test_ipv4_icmp_request() {
3106 local inport=$1 eth_src=$2 eth_dst=$3 ipv4_src=$4 ipv4_dst=$5 ip_chksum=$6 icmp_chksum=$7
3107 local exp_ip_chksum=$8 exp_icmp_chksum=$9
3108 shift; shift; shift; shift; shift; shift; shift
3111 # Use ttl to exercise section 4.2.2.9 of RFC1812
3115 local icmp_data=$(seq 1 56 | xargs printf "%02x")
3116 local icmp_type_code_request=0800
3117 local icmp_payload=${icmp_type_code_request}${icmp_chksum}${icmp_id}${icmp_seq}${icmp_data}
3118 local packet=${eth_dst}${eth_src}08004500005400004000${ip_ttl}01${ip_chksum}${ipv4_src}${ipv4_dst}${icmp_payload}
3120 as hv1 ovs-appctl netdev-dummy/receive vif$inport $packet
3121 if test X$exp_icmp_chksum != X; then
3122 # Expect to receive the reply, if any. In same port where packet was sent.
3123 # Note: src and dst fields are expected to be reversed.
3124 local icmp_type_code_response=0000
3125 local reply_icmp_ttl=fe
3126 local reply_icmp_payload=${icmp_type_code_response}${exp_icmp_chksum}${icmp_id}${icmp_seq}${icmp_data}
3127 local reply=${eth_src}${eth_dst}08004500005400004000${reply_icmp_ttl}01${exp_ip_chksum}${ipv4_dst}${ipv4_src}${reply_icmp_payload}
3128 echo $reply >> vif$inport.expected
3132 # Send ping packet to router's ip addresses, from each of the 2 logical ports.
3133 rtr_l1_ip=$(ip_to_hex 192 168 1 1)
3134 rtr_l2_ip=$(ip_to_hex 172 16 1 1)
3135 l1_ip=$(ip_to_hex 192 168 1 2)
3136 l2_ip=$(ip_to_hex 172 16 1 2)
3138 # Ping router ip address that is on same subnet as the logical port
3139 test_ipv4_icmp_request 1 000000010203 0000000102f1 $l1_ip $rtr_l1_ip 0000 8510 02ff 8d10
3140 test_ipv4_icmp_request 2 000000010204 0000000102f2 $l2_ip $rtr_l2_ip 0000 8510 02ff 8d10
3142 # Ping router ip address that is on the other side of the logical ports
3143 test_ipv4_icmp_request 1 000000010203 0000000102f1 $l1_ip $rtr_l2_ip 0000 8510 02ff 8d10
3144 test_ipv4_icmp_request 2 000000010204 0000000102f2 $l2_ip $rtr_l1_ip 0000 8510 02ff 8d10
3146 echo "---------NB dump-----"
3148 echo "---------------------"
3149 ovn-nbctl list logical_router
3150 echo "---------------------"
3151 ovn-nbctl list logical_router_port
3152 echo "---------------------"
3154 echo "---------SB dump-----"
3155 ovn-sbctl list datapath_binding
3156 echo "---------------------"
3157 ovn-sbctl list logical_flow
3158 echo "---------------------"
3160 echo "------ hv1 dump ----------"
3161 as hv1 ovs-ofctl dump-flows br-int
3163 # Now check the packets actually received against the ones expected.
3164 for inport in 1 2; do
3165 file=hv1/vif${inport}-tx.pcap
3167 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" $file | trim_zeros > received.packets
3168 cat vif$inport.expected | trim_zeros > expout
3169 AT_CHECK([cat received.packets], [0], [expout])
3173 OVS_APP_EXIT_AND_WAIT([ovn-controller])
3174 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
3175 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3178 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3181 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3184 OVS_APP_EXIT_AND_WAIT([ovn-northd])
3187 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
3188 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3192 # 1 hypervisor, 1 port
3193 # make sure that the port state is properly set to up and back down
3194 # when created and deleted.
3195 AT_SETUP([ovn -- port state up and down])
3199 ovn-nbctl ls-add ls1
3200 ovn-nbctl lsp-add ls1 lp1
3201 ovn-nbctl lsp-set-addresses lp1 unknown
3205 as hv1 ovs-vsctl add-br br-phys
3206 as hv1 ovn_attach n1 br-phys 192.168.0.1
3208 as hv1 ovs-vsctl add-port br-int vif1 -- set Interface vif1 external-ids:iface-id=lp1
3209 OVS_WAIT_UNTIL([test x`ovn-nbctl lsp-get-up lp1` = xup])
3211 as hv1 ovs-vsctl del-port br-int vif1
3212 OVS_WAIT_UNTIL([test x`ovn-nbctl lsp-get-up lp1` = xdown])
3215 OVS_APP_EXIT_AND_WAIT([ovn-controller])
3216 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
3217 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3220 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3223 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3226 OVS_APP_EXIT_AND_WAIT([ovn-northd])
3229 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
3230 OVS_APP_EXIT_AND_WAIT([ovsdb-server])