]> git.proxmox.com Git - ovs.git/blame - tests/ovn.at
datapath: Only set mark and labels with a commit flag.
[ovs.git] / tests / ovn.at
CommitLineData
f295c17b 1AT_BANNER([OVN components])
10b1662b
BP
2
3AT_SETUP([ovn -- lexer])
4dnl For lines without =>, input and expected output are identical.
5dnl For lines with =>, input precedes => and expected output follows =>.
6AT_DATA([test-cases.txt], [dnl
7foo bar baz quuxquuxquux _abcd_ a.b.c.d a123_.456
8"abc\u0020def" => "abc def"
9" => error("Input ends inside quoted string.")dnl "
10
11a/*b*/c => a c
12a//b c => a
13a/**/b => a b
14a/*/b => a error("`/*' without matching `*/'.")
15a/*/**/b => a b
16a/b => a error("`/' is only valid as part of `//' or `/*'.") b
17
180 1 12345 18446744073709551615
1918446744073709551616 => error("Decimal constants must be less than 2**64.")
209999999999999999999999 => error("Decimal constants must be less than 2**64.")
2101 => error("Decimal constants must not have leading zeros.")
22
230/0
240/1
251/0 => error("Value contains unmasked 1-bits.")
261/1
27128/384
281/3
291/ => error("Integer constant expected.")
30
311/0x123 => error("Value and mask have incompatible formats.")
32
330x1234
340x01234 => 0x1234
350x0 => 0
360x000 => 0
370xfedcba9876543210
380XFEDCBA9876543210 => 0xfedcba9876543210
390xfedcba9876543210fedcba9876543210
10b1662b
BP
400x0000fedcba9876543210fedcba9876543210 => 0xfedcba9876543210fedcba9876543210
410x => error("Hex digits expected following 0x.")
420X => error("Hex digits expected following 0X.")
430x0/0x0 => 0/0
440x0/0x1 => 0/0x1
450x1/0x0 => error("Value contains unmasked 1-bits.")
460xffff/0x1ffff
470x. => error("Invalid syntax in hexadecimal constant.")
48
49192.168.128.1 1.2.3.4 255.255.255.255 0.0.0.0
50256.1.2.3 => error("Invalid numeric constant.")
51192.168.0.0/16
52192.168.0.0/255.255.0.0 => 192.168.0.0/16
53192.168.0.0/255.255.255.0 => 192.168.0.0/24
54192.168.0.0/255.255.0.255
55192.168.0.0/255.0.0.0 => error("Value contains unmasked 1-bits.")
56192.168.0.0/32
57192.168.0.0/255.255.255.255 => 192.168.0.0/32
58
59::
60::1
61ff00::1234 => ff00::1234
622001:db8:85a3::8a2e:370:7334
632001:db8:85a3:0:0:8a2e:370:7334 => 2001:db8:85a3::8a2e:370:7334
642001:0db8:85a3:0000:0000:8a2e:0370:7334 => 2001:db8:85a3::8a2e:370:7334
65::ffff:192.0.2.128
66::ffff:c000:0280 => ::ffff:192.0.2.128
67::1/::1
68::1/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff => ::1/128
69::1/128
70ff00::/8
71ff00::/ff00:: => ff00::/8
72
7301:23:45:67:ab:cd
7401:23:45:67:AB:CD => 01:23:45:67:ab:cd
75fe:dc:ba:98:76:54
76FE:DC:ba:98:76:54 => fe:dc:ba:98:76:54
7701:00:00:00:00:00/01:00:00:00:00:00
78ff:ff:ff:ff:ff:ff/ff:ff:ff:ff:ff:ff
79fe:ff:ff:ff:ff:ff/ff:ff:ff:ff:ff:ff
80ff:ff:ff:ff:ff:ff/fe:ff:ff:ff:ff:ff => error("Value contains unmasked 1-bits.")
81fe:x => error("Invalid numeric constant.")
8200:01:02:03:04:x => error("Invalid numeric constant.")
83
a20c96c6 84# Test that operators are tokenized as expected, even without white space.
56091efe 85(){}[[]]==!=<<=>>=!&&||..,;=<->-- => ( ) { } [[ ]] == != < <= > >= ! && || .. , ; = <-> --
10b1662b
BP
86& => error("`&' is only valid as part of `&&'.")
87| => error("`|' is only valid as part of `||'.")
56091efe 88- => error("`-' is only valid as part of `--'.")
10b1662b
BP
89
90^ => error("Invalid character `^' in input.")
91])
92AT_CAPTURE_FILE([input.txt])
93sed 's/ =>.*//' test-cases.txt > input.txt
94sed 's/.* => //' test-cases.txt > expout
95AT_CHECK([ovstest test-ovn lex < input.txt], [0], [expout])
96AT_CLEANUP
e0840f11
BP
97
98AT_SETUP([ovn -- expression parser])
99dnl For lines without =>, input and expected output are identical.
100dnl For lines with =>, input precedes => and expected output follows =>.
101AT_DATA([test-cases.txt], [[
102eth.type == 0x800
103eth.type==0x800 => eth.type == 0x800
104eth.type[0..15] == 0x800 => eth.type == 0x800
105
106vlan.present
107vlan.present == 1 => vlan.present
108!(vlan.present == 0) => vlan.present
109!(vlan.present != 1) => vlan.present
110!vlan.present
111vlan.present == 0 => !vlan.present
112vlan.present != 1 => !vlan.present
113!(vlan.present == 1) => !vlan.present
114!(vlan.present != 0) => !vlan.present
115
116eth.dst[0]
117eth.dst[0] == 1 => eth.dst[0]
118eth.dst[0] != 0 => eth.dst[0]
119!(eth.dst[0] == 0) => eth.dst[0]
120!(eth.dst[0] != 1) => eth.dst[0]
121
122!eth.dst[0]
123eth.dst[0] == 0 => !eth.dst[0]
124eth.dst[0] != 1 => !eth.dst[0]
125!(eth.dst[0] == 1) => !eth.dst[0]
126!(eth.dst[0] != 0) => !eth.dst[0]
127
128vlan.tci[12..15] == 0x3
129vlan.tci == 0x3000/0xf000 => vlan.tci[12..15] == 0x3
130vlan.tci[12..15] != 0x3
131vlan.tci != 0x3000/0xf000 => vlan.tci[12..15] != 0x3
132
133!vlan.pcp => vlan.pcp == 0
134!(vlan.pcp) => vlan.pcp == 0
135vlan.pcp == 0x4
136vlan.pcp != 0x4
137vlan.pcp > 0x4
138vlan.pcp >= 0x4
139vlan.pcp < 0x4
140vlan.pcp <= 0x4
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
1470x4 == vlan.pcp => vlan.pcp == 0x4
1480x4 != vlan.pcp => vlan.pcp != 0x4
1490x4 < vlan.pcp => vlan.pcp > 0x4
1500x4 <= vlan.pcp => vlan.pcp >= 0x4
1510x4 > vlan.pcp => vlan.pcp < 0x4
1520x4 >= 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
159
1601 < vlan.pcp < 4 => vlan.pcp > 0x1 && vlan.pcp < 0x4
1611 <= vlan.pcp <= 4 => vlan.pcp >= 0x1 && vlan.pcp <= 0x4
1621 < vlan.pcp <= 4 => vlan.pcp > 0x1 && vlan.pcp <= 0x4
1631 <= vlan.pcp < 4 => vlan.pcp >= 0x1 && vlan.pcp < 0x4
1641 <= vlan.pcp <= 4 => vlan.pcp >= 0x1 && vlan.pcp <= 0x4
1654 > vlan.pcp > 1 => vlan.pcp < 0x4 && vlan.pcp > 0x1
1664 >= vlan.pcp > 1 => vlan.pcp <= 0x4 && vlan.pcp > 0x1
1674 > vlan.pcp >= 1 => vlan.pcp < 0x4 && vlan.pcp >= 0x1
1684 >= 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
178
179vlan.pcp == {1, 2, 3, 4} => vlan.pcp == 0x1 || vlan.pcp == 0x2 || vlan.pcp == 0x3 || vlan.pcp == 0x4
180vlan.pcp == 1 || ((vlan.pcp == 2 || vlan.pcp == 3) || vlan.pcp == 4) => vlan.pcp == 0x1 || vlan.pcp == 0x2 || vlan.pcp == 0x3 || vlan.pcp == 0x4
181
182vlan.pcp != {1, 2, 3, 4} => vlan.pcp != 0x1 && vlan.pcp != 0x2 && vlan.pcp != 0x3 && vlan.pcp != 0x4
183vlan.pcp == 1 && ((vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && vlan.pcp == 0x2 && vlan.pcp == 0x3 && vlan.pcp == 0x4
184
185vlan.pcp == 1 && !((vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && (vlan.pcp != 0x2 || vlan.pcp != 0x3 || vlan.pcp != 0x4)
186vlan.pcp == 1 && (!(vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && (vlan.pcp != 0x2 || vlan.pcp != 0x3) && vlan.pcp == 0x4
187vlan.pcp == 1 && !(!(vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && ((vlan.pcp == 0x2 && vlan.pcp == 0x3) || vlan.pcp != 0x4)
188
189ip4.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
190ip6.src == ::1 => ip6.src == 0x1
191
192ip4.src == 1.2.3.4 => ip4.src == 0x1020304
193ip4.src == ::1.2.3.4/::ffff:ffff => ip4.src == 0x1020304
194ip6.src == ::1 => ip6.src == 0x1
195
1961
1970
198!1 => 0
199!0 => 1
200
201inport == "eth0"
202!(inport != "eth0") => inport == "eth0"
203
3b7cb7e1
BP
204ip4.src == "eth0" => Integer field ip4.src is not compatible with string constant.
205inport == 1 => String field inport is not compatible with integer constant.
e0840f11
BP
206
207ip4.src > {1, 2, 3} => Only == and != operators may be used with value sets.
208eth.type > 0x800 => Only == and != operators may be used with nominal field eth.type.
209vlan.present > 0 => Only == and != operators may be used with Boolean field vlan.present.
210
211inport != "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).
213eth.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).
215
216123 == 123 => Syntax error at `123' expecting field name.
217
218123 == xyzzy => Syntax error at `xyzzy' expecting field name.
219xyzzy == 1 => Syntax error at `xyzzy' expecting field name.
220
221inport[1] == 1 => Cannot select subfield of string field inport.
222
223eth.type[] == 1 => Syntax error at `@:>@' expecting small integer.
224eth.type[::1] == 1 => Syntax error at `::1' expecting small integer.
225eth.type[18446744073709551615] == 1 => Syntax error at `18446744073709551615' expecting small integer.
226
227eth.type[5!] => Syntax error at `!' expecting `@:>@'.
228
229eth.type[5..1] => Invalid bit range 5 to 1.
230
231eth.type[12..16] => Cannot select bits 12 to 16 of 16-bit field eth.type.
232
233eth.type[10] == 1 => Cannot select subfield of nominal field eth.type.
234
235eth.type => Explicit `!= 0' is required for inequality test of multibit field against 0.
236
237!(!(vlan.pcp)) => Explicit `!= 0' is required for inequality test of multibit field against 0.
238
239123 => Syntax error at end of input expecting relational operator.
240
241123 x => Syntax error at `x' expecting relational operator.
242
243{1, "eth0"} => Syntax error at `"eth0"' expecting integer.
244
245eth.type == xyzzy => Syntax error at `xyzzy' expecting constant.
246
247(1 x) => Syntax error at `x' expecting `)'.
248
249!0x800 != eth.type => Missing parentheses around operand of !.
250
251eth.type == 0x800 || eth.type == 0x86dd && ip.proto == 17 => && and || must be parenthesized when used together.
252
253eth.dst == {} => Syntax error at `}' expecting constant.
254
255eth.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).
256
3b7cb7e1 257ip4.src == ::1 => 128-bit constant is not compatible with 32-bit field ip4.src.
e0840f11
BP
258
2591 == eth.type == 2 => Range expressions must have the form `x < field < y' or `x > field > y', with each `<' optionally replaced by `<=' or `>' by `>=').
8b34ccda
JS
260
261eth.dst[40] x => Extra tokens at end of input.
e0840f11
BP
262]])
263sed 's/ =>.*//' test-cases.txt > input.txt
264sed 's/.* => //' test-cases.txt > expout
265AT_CHECK([ovstest test-ovn parse-expr < input.txt], [0], [expout])
266AT_CLEANUP
267
268AT_SETUP([ovn -- expression annotation])
269dnl Input precedes =>, expected output follows =>.
270AT_DATA([test-cases.txt], [[
271ip4.src == 1.2.3.4 => ip4.src == 0x1020304 && eth.type == 0x800
272ip4.src != 1.2.3.4 => ip4.src != 0x1020304 && eth.type == 0x800
273ip.proto == 123 => ip.proto == 0x7b && (eth.type == 0x800 || eth.type == 0x86dd)
274ip.proto == {123, 234} => (ip.proto == 0x7b && (eth.type == 0x800 || eth.type == 0x86dd)) || (ip.proto == 0xea && (eth.type == 0x800 || eth.type == 0x86dd))
275ip4.src == 1.2.3.4 && ip4.dst == 5.6.7.8 => ip4.src == 0x1020304 && eth.type == 0x800 && ip4.dst == 0x5060708 && eth.type == 0x800
276
277ip => eth.type == 0x800 || eth.type == 0x86dd
278ip == 1 => eth.type == 0x800 || eth.type == 0x86dd
279ip[0] == 1 => eth.type == 0x800 || eth.type == 0x86dd
280ip > 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'.
282ip == 0 => Nominal predicate ip may only be tested positively, e.g. `ip' or `ip == 1' but not `!ip' or `ip == 0'.
283
284vlan.present => vlan.tci[12]
285!vlan.present => !vlan.tci[12]
286
287!vlan.pcp => vlan.tci[13..15] == 0 && vlan.tci[12]
288vlan.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
290
291ip.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))
293ip.later_frag => ip.frag[1] && (eth.type == 0x800 || eth.type == 0x86dd)
294
295bad_prereq != 0 => Error parsing expression `xyzzy' encountered as prerequisite or predicate of initial expression: Syntax error at `xyzzy' expecting field name.
296self_recurse != 0 => Error parsing expression `self_recurse != 0' encountered as prerequisite or predicate of initial expression: Recursive expansion of symbol `self_recurse'.
297mutual_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'.
298mutual_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'.
299]])
300sed 's/ =>.*//' test-cases.txt > input.txt
301sed 's/.* => //' test-cases.txt > expout
302AT_CHECK([ovstest test-ovn annotate-expr < input.txt], [0], [expout])
303AT_CLEANUP
304
9d4aecca 305AT_SETUP([ovn -- 1-term expression conversion])
e0840f11 306AT_CHECK([ovstest test-ovn exhaustive --operation=convert 1], [0],
9d4aecca 307 [Tested converting all 1-terminal expressions with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 2 string vars.
e0840f11
BP
308])
309AT_CLEANUP
310
9d4aecca 311AT_SETUP([ovn -- 2-term expression conversion])
e0840f11 312AT_CHECK([ovstest test-ovn exhaustive --operation=convert 2], [0],
9d4aecca 313 [Tested converting 570 expressions of 2 terminals with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 2 string vars.
e0840f11
BP
314])
315AT_CLEANUP
316
9d4aecca 317AT_SETUP([ovn -- 3-term expression conversion])
e0840f11 318AT_CHECK([ovstest test-ovn exhaustive --operation=convert --bits=2 3], [0],
9d4aecca 319 [Tested converting 62418 expressions of 3 terminals with 2 numeric vars (each 2 bits) in terms of operators == != < <= > >= and 2 string vars.
e0840f11
BP
320])
321AT_CLEANUP
322
9d4aecca
BP
323AT_SETUP([ovn -- 3-term numeric expression simplification])
324AT_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 == != < <= > >=.
e0840f11
BP
326])
327AT_CLEANUP
328
9d4aecca
BP
329AT_SETUP([ovn -- 4-term string expression simplification])
330AT_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.
e0840f11
BP
332])
333AT_CLEANUP
334
9d4aecca
BP
335AT_SETUP([ovn -- 3-term mixed expression simplification])
336AT_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.
e0840f11
BP
338])
339AT_CLEANUP
340
9d4aecca
BP
341AT_SETUP([ovn -- 4-term numeric expression normalization])
342AT_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 == != < <= > >=.
e0840f11
BP
344])
345AT_CLEANUP
346
9d4aecca
BP
347AT_SETUP([ovn -- 4-term string expression normalization])
348AT_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.
350])
351AT_CLEANUP
352
353AT_SETUP([ovn -- 4-term mixed expression normalization])
354AT_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.
356])
357AT_CLEANUP
358
359AT_SETUP([ovn -- 5-term numeric expression normalization])
360AT_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 ==.
362])
363AT_CLEANUP
364
365AT_SETUP([ovn -- 5-term string expression normalization])
366AT_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.
368])
369AT_CLEANUP
370
371AT_SETUP([ovn -- 5-term mixed expression normalization])
372AT_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.
374])
375AT_CLEANUP
376
377AT_SETUP([ovn -- 4-term numeric expressions to flows])
378AT_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 ==.
380])
381AT_CLEANUP
382
383AT_SETUP([ovn -- 4-term string expressions to flows])
384AT_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.
386])
387AT_CLEANUP
388
389AT_SETUP([ovn -- 4-term mixed expressions to flows])
390AT_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.
392])
393AT_CLEANUP
394
395AT_SETUP([ovn -- 3-term numeric expressions to flows])
396AT_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 ==.
e0840f11
BP
398])
399AT_CLEANUP
f386a8a7
BP
400
401AT_SETUP([ovn -- converting expressions to flows -- string fields])
402expr_to_flow () {
403 echo "$1" | ovstest test-ovn expr-to-flows | sort
404}
3b7cb7e1 405AT_CHECK([expr_to_flow 'inport == "eth0"'], [0], [reg6=0x5
f386a8a7 406])
3b7cb7e1 407AT_CHECK([expr_to_flow 'inport == "eth1"'], [0], [reg6=0x6
f386a8a7
BP
408])
409AT_CHECK([expr_to_flow 'inport == "eth2"'], [0], [(no flows)
410])
411AT_CHECK([expr_to_flow 'inport == "eth0" && ip'], [0], [dnl
3b7cb7e1
BP
412ip,reg6=0x5
413ipv6,reg6=0x5
f386a8a7
BP
414])
415AT_CHECK([expr_to_flow 'inport == "eth1" && ip'], [0], [dnl
3b7cb7e1
BP
416ip,reg6=0x6
417ipv6,reg6=0x6
f386a8a7
BP
418])
419AT_CHECK([expr_to_flow 'inport == "eth2" && ip'], [0], [(no flows)
420])
421AT_CHECK([expr_to_flow 'inport == {"eth0", "eth1", "eth2", "LOCAL"}'], [0],
3b7cb7e1
BP
422[reg6=0x5
423reg6=0x6
424reg6=0xfffe
f386a8a7
BP
425])
426AT_CHECK([expr_to_flow 'inport == {"eth0", "eth1", "eth2"} && ip'], [0], [dnl
3b7cb7e1
BP
427ip,reg6=0x5
428ip,reg6=0x6
429ipv6,reg6=0x5
430ipv6,reg6=0x6
f386a8a7 431])
9d4aecca
BP
432AT_CHECK([expr_to_flow 'inport == "eth0" && inport == "eth1"'], [0], [dnl
433(no flows)
434])
f386a8a7 435AT_CLEANUP
3b7cb7e1
BP
436
437AT_SETUP([ovn -- action parsing])
438dnl Text before => is input, text after => is expected output.
439AT_DATA([test-cases.txt], [[
5f822129 440# drop
3b7cb7e1 441drop; => actions=drop, prereqs=1
5f822129
BP
442drop; next; => Syntax error at `next' expecting end of input.
443next; drop; => Syntax error at `drop' expecting action.
444
445# output
446output; => actions=resubmit(,64), prereqs=1
447
448# next
558ec83d
BP
449next; => actions=resubmit(,27), prereqs=1
450next(0); => actions=resubmit(,16), prereqs=1
451next(15); => actions=resubmit(,31), prereqs=1
5f822129
BP
452
453next(); => Syntax error at `)' expecting small integer.
454next(10; => Syntax error at `;' expecting `)'.
455next(16); => "next" argument must be in range 0 to 15.
456
457# Loading a constant value.
3b7cb7e1
BP
458tcp.dst=80; => actions=set_field:80->tcp_dst, prereqs=ip.proto == 0x6 && (eth.type == 0x800 || eth.type == 0x86dd)
459eth.dst[40] = 1; => actions=set_field:01:00:00:00:00:00/01:00:00:00:00:00->eth_dst, prereqs=1
460vlan.pcp = 2; => actions=set_field:0x4000/0xe000->vlan_tci, prereqs=vlan.tci[12]
461vlan.tci[13..15] = 2; => actions=set_field:0x4000/0xe000->vlan_tci, prereqs=1
b4970837 462inport = ""; => actions=set_field:0->reg6,set_field:0->in_port, prereqs=1
47f3b59b 463ip.ttl = 4; => actions=set_field:4->nw_ttl, prereqs=eth.type == 0x800 || eth.type == 0x86dd
5f822129 464outport="eth0"; next; outport="LOCAL"; next; => actions=set_field:0x5->reg7,resubmit(,27),set_field:0xfffe->reg7,resubmit(,27), prereqs=1
558ec83d 465
3b7cb7e1
BP
466inport[1] = 1; => Cannot select subfield of string field inport.
467ip.proto[1] = 1; => Cannot select subfield of nominal field ip.proto.
8fb72d29 468eth.dst[40] == 1; => Syntax error at `==' expecting `=' or `<->'.
ce57ea75 469ip = 1; => Predicate symbol ip used where lvalue required.
3b7cb7e1
BP
470ip.proto = 6; => Field ip.proto is not modifiable.
471inport = {"a", "b"}; => Assignments require a single value.
472inport = {}; => Syntax error at `}' expecting constant.
473bad_prereq = 123; => Error parsing expression `xyzzy' encountered as prerequisite or predicate of initial expression: Syntax error at `xyzzy' expecting field name.
474self_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'.
ce57ea75 475vlan.present = 0; => Predicate symbol vlan.present used where lvalue required.
5f822129
BP
476
477# Moving one field into another.
478reg0 = reg1; => actions=move:OXM_OF_PKT_REG0[0..31]->OXM_OF_PKT_REG0[32..63], prereqs=1
479vlan.pcp = reg0[0..2]; => actions=move:OXM_OF_PKT_REG0[32..34]->NXM_OF_VLAN_TCI[13..15], prereqs=vlan.tci[12]
480reg0[10] = vlan.pcp[1]; => actions=move:NXM_OF_VLAN_TCI[14]->OXM_OF_PKT_REG0[42], prereqs=vlan.tci[12]
481outport = inport; => actions=move:NXM_NX_REG6[]->NXM_NX_REG7[], prereqs=1
482
ce57ea75 483reg0[0] = vlan.present; => Predicate symbol vlan.present used where lvalue required.
5ee054fb
BP
484reg0 = reg1[0..10]; => Can't assign 11-bit value to 32-bit destination.
485inport = reg0; => Can't assign integer field (reg0) to string field (inport).
486inport = big_string; => String fields inport and big_string are incompatible for assignment.
487ip.proto = reg0[0..7]; => Field ip.proto is not modifiable.
5f822129
BP
488
489# Exchanging fields.
490reg0 <-> 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
491vlan.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]
492reg0[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]
493outport <-> inport; => actions=push:NXM_NX_REG6[],push:NXM_NX_REG7[],pop:NXM_NX_REG6[],pop:NXM_NX_REG7[], prereqs=1
494
ce57ea75 495reg0[0] <-> vlan.present; => Predicate symbol vlan.present used where lvalue required.
a20c96c6
BP
496reg0 <-> reg1[0..10]; => Can't exchange 32-bit field with 11-bit field.
497inport <-> reg0; => Can't exchange string field (inport) with integer field (reg0).
498inport <-> big_string; => String fields inport and big_string are incompatible for exchange.
499ip.proto <-> reg0[0..7]; => Field ip.proto is not modifiable.
500reg0[0..7] <-> ip.proto; => Field ip.proto is not modifiable.
5f822129
BP
501
502# TTL decrement.
503ip.ttl--; => actions=dec_ttl, prereqs=ip
47f3b59b 504ip.ttl => Syntax error at end of input expecting `--'.
5f822129
BP
505
506# conntrack
507ct_next; => actions=ct(table=27,zone=NXM_NX_REG5[0..15]), prereqs=ip
508ct_commit; => actions=ct(commit,zone=NXM_NX_REG5[0..15]), prereqs=ip
a9e1b66f
RB
509ct_commit(); => actions=ct(commit,zone=NXM_NX_REG5[0..15]), prereqs=ip
510ct_commit(ct_mark=1); => actions=ct(commit,zone=NXM_NX_REG5[0..15],exec(set_field:0x1->ct_mark)), prereqs=ip
511ct_commit(ct_mark=1/1); => actions=ct(commit,zone=NXM_NX_REG5[0..15],exec(set_field:0x1/0x1->ct_mark)), prereqs=ip
512ct_commit(ct_label=1); => actions=ct(commit,zone=NXM_NX_REG5[0..15],exec(set_field:0x1->ct_label)), prereqs=ip
513ct_commit(ct_label=1/1); => actions=ct(commit,zone=NXM_NX_REG5[0..15],exec(set_field:0x1/0x1->ct_label)), prereqs=ip
514ct_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
5f822129 515
de297547
GS
516# dnat
517ct_dnat; => actions=ct(table=27,zone=NXM_NX_REG3[0..15],nat), prereqs=ip
518ct_dnat(192.168.1.2); => actions=ct(commit,table=27,zone=NXM_NX_REG3[0..15],nat(dst=192.168.1.2)), prereqs=ip
519ct_dnat(192.168.1.2, 192.168.1.3); => Syntax error at `,' expecting `)'.
520ct_dnat(foo); => Syntax error at `foo' invalid ip.
521ct_dnat(foo, bar); => Syntax error at `foo' invalid ip.
522ct_dnat(); => Syntax error at `)' invalid ip.
523
524# snat
525ct_snat; => actions=ct(zone=NXM_NX_REG4[0..15],nat), prereqs=ip
526ct_snat(192.168.1.2); => actions=ct(commit,table=27,zone=NXM_NX_REG4[0..15],nat(src=192.168.1.2)), prereqs=ip
527ct_snat(192.168.1.2, 192.168.1.3); => Syntax error at `,' expecting `)'.
528ct_snat(foo); => Syntax error at `foo' invalid ip.
529ct_snat(foo, bar); => Syntax error at `foo' invalid ip.
530ct_snat(); => Syntax error at `)' invalid ip.
531
532
6335d074
BP
533# arp
534arp { 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
535
0bac7164
BP
536# get_arp
537get_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
538get_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
539get_arp; => Syntax error at `;' expecting `('.
540get_arp(); => Syntax error at `)' expecting field name.
541get_arp(inport); => Syntax error at `)' expecting `,'.
542get_arp(inport ip4.dst); => Syntax error at `ip4.dst' expecting `,'.
543get_arp(inport, ip4.dst; => Syntax error at `;' expecting `)'.
544get_arp(inport, eth.dst); => Cannot use 48-bit field eth.dst[0..47] where 32-bit field is required.
545get_arp(inport, outport); => Cannot use string field outport where numeric field is required.
546get_arp(reg0, ip4.dst); => Cannot use numeric field reg0 where string field is required.
547
548# put_arp
549put_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
550
42814145
NS
551# put_dhcp_opts
552reg1[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
553reg2[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
567reg0[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
568reg1[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.
569reg1[0] = put_dhcp_opts(); => Syntax error at `)'.
570reg1[0] = put_dhcp_opts(x = 1.2.3.4, router = 10.0.0.1); => Syntax error at `x' expecting offerip option.
571reg1[0] = put_dhcp_opts(offerip=1.2.3.4, "hi"); => Syntax error at `"hi"'.
572reg1[0] = put_dhcp_opts(offerip=1.2.3.4, xyzzy); => Syntax error at `xyzzy' expecting DHCP option name.
573reg1[0] = put_dhcp_opts(offerip="xyzzy"); => DHCP option offerip requires numeric value.
574reg1[0] = put_dhcp_opts(offerip=1.2.3.4, domain=1.2.3.4); => DHCP option domain requires string value.
575
5f822129
BP
576# Contradictionary prerequisites (allowed but not useful):
577ip4.src = ip6.src[0..31]; => actions=move:NXM_NX_IPV6_SRC[0..31]->NXM_OF_IP_SRC[], prereqs=eth.type == 0x800 && eth.type == 0x86dd
578ip4.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
579
580## Miscellaneous negative tests.
581; => Syntax error at `;'.
582xyzzy; => Syntax error at `xyzzy' expecting action.
583next; 123; => Syntax error at `123'.
584next; xyzzy; => Syntax error at `xyzzy' expecting action.
585next => Syntax error at end of input expecting ';'.
3b7cb7e1
BP
586]])
587sed 's/ =>.*//' test-cases.txt > input.txt
588sed 's/.* => //' test-cases.txt > expout
589AT_CHECK([ovstest test-ovn parse-actions < input.txt], [0], [expout])
590AT_CLEANUP
f295c17b
BP
591
592AT_BANNER([OVN end-to-end tests])
593
9975d7be
BP
594# 3 hypervisors, one logical switch, 3 logical ports per hypervisor
595AT_SETUP([ovn -- 3 HVs, 1 LS, 3 lports/HV])
57d143eb 596AT_KEYWORDS([ovnarp])
f295c17b
BP
597AT_SKIP_IF([test $HAVE_PYTHON = no])
598ovn_start
599
600# Create hypervisors hv[123].
9975d7be 601# Add vif1[123] to hv1, vif2[123] to hv2, vif3[123] to hv3.
f295c17b
BP
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.
ea46a4e9 606ovn-nbctl ls-add lsw0
f295c17b
BP
607net_add n1
608for i in 1 2 3; do
609 sim_add hv$i
610 as hv$i
611 ovs-vsctl add-br br-phys
612 ovn_attach n1 br-phys 192.168.0.$i
613
614 for j in 1 2 3; do
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
31ed1192 616 ovn-nbctl lsp-add lsw0 lp$i$j
4d5c43d5 617 if test $j = 1; then
31ed1192 618 ovn-nbctl lsp-set-addresses lp$i$j "f0:00:00:00:00:$i$j 192.168.0.$i$j" unknown
f295c17b 619 else
7dc88496
NS
620 if test $j = 3; then
621 ip_addrs="192.168.0.$i$j fe80::ea2a:eaff:fe28:$i$j/64 192.169.0.$i$j"
622 else
623 ip_addrs="192.168.0.$i$j"
624 fi
31ed1192
JP
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
f295c17b
BP
627 fi
628 done
629done
630ovn-nbctl acl-add lsw0 from-lport 1000 'eth.type == 0x1234' drop
631ovn-nbctl acl-add lsw0 from-lport 1000 'eth.type == 0x1235 && inport == "lp11"' drop
632ovn-nbctl acl-add lsw0 to-lport 1000 'eth.type == 0x1236 && outport == "lp33"' drop
633
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).
637ovn_populate_arp
638
639# Allow some time for ovn-northd and ovn-controller to catch up.
640# XXX This should be more systematic.
641sleep 1
611099dc 642
57d143eb
HZ
643# Given the name of a logical port, prints the name of the hypervisor
644# on which it is located.
645vif_to_hv() {
646 echo hv${1%?}
647}
648
f295c17b
BP
649# test_packet INPORT DST SRC ETHTYPE OUTPORT...
650#
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
31ed1192 655# OUTPORTs are specified as logical switch port numbers, e.g. 11 for vif11.
f295c17b
BP
656trim_zeros() {
657 sed 's/\(00\)\{1,\}$//'
658}
659for i in 1 2 3; do
660 for j in 1 2 3; do
661 : > $i$j.expected
662 done
663done
664test_packet() {
665 local inport=$1 packet=$2$3$4; shift; shift; shift; shift
57d143eb 666 hv=`vif_to_hv $inport`
f295c17b
BP
667 vif=vif$inport
668 as $hv ovs-appctl netdev-dummy/receive $vif $packet
669 for outport; do
670 echo $packet | trim_zeros >> $outport.expected
671 done
672}
673
57d143eb
HZ
674# test_arp INPORT SHA SPA TPA [REPLY_HA]
675#
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.
680#
31ed1192 681# INPORT is an logical switch port number, e.g. 11 for vif11.
57d143eb
HZ
682# SHA and REPLY_HA are each 12 hex digits.
683# SPA and TPA are each 8 hex digits.
684test_arp() {
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
689
92f9822b 690 if test X$reply_ha = X; then
57d143eb
HZ
691 # Expect to receive the broadcast ARP on the other logical switch ports
692 # if no reply is expected.
693 local i j
694 for i in 1 2 3; do
695 for j in 1 2 3; do
696 if test $i$j != $inport; then
697 echo $request >> $i$j.expected
698 fi
699 done
700 done
701 else
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
705 fi
706}
707
708ip_to_hex() {
709 printf "%02x%02x%02x%02x" "$@"
710}
711
f295c17b
BP
712# Send packets between all pairs of source and destination ports:
713#
31ed1192
JP
714# 1. Unicast packets are delivered to exactly one logical switch port
715# (except that packets destined to their input ports are dropped).
f295c17b 716#
31ed1192
JP
717# 2. Broadcast and multicast are delivered to all logical switch ports
718# except the input port.
f295c17b 719#
ea46a4e9 720# 3. When port security is turned on, the switch drops packets from the wrong
f295c17b
BP
721# MAC address.
722#
ea46a4e9 723# 4. The switch drops all packets with a VLAN tag.
f295c17b 724#
ea46a4e9 725# 5. The switch drops all packets with a multicast source address. (This only
f295c17b
BP
726# affects behavior when port security is turned off, since otherwise port
727# security would drop the packet anyway.)
728#
ea46a4e9 729# 6. The switch delivers packets with an unknown destination to logical
31ed1192
JP
730# switch ports with "unknown" among their MAC addresses (and port
731# security disabled).
f295c17b 732#
ea46a4e9 733# 7. The switch drops unicast packets that violate an ACL.
f295c17b 734#
ea46a4e9 735# 8. The switch drops multicast and broadcast packets that violate an ACL.
57d143eb
HZ
736#
737# 9. ARP requests to known IPs are responded directly.
738#
739# 10. No response to ARP requests for unknown IPs.
f295c17b
BP
740for is in 1 2 3; do
741 for js in 1 2 3; do
742 s=$is$js
743 bcast=
4d5c43d5
JP
744 unknown=
745 bacl2=
746 bacl3=
f295c17b
BP
747 for id in 1 2 3; do
748 for jd in 1 2 3; do
749 d=$id$jd
750
751 if test $d != $s; then unicast=$d; else unicast=; fi
752 test_packet $s f000000000$d f000000000$s $s$d $unicast #1
753
754 if test $d != $s && test $js = 1; then
4d5c43d5
JP
755 impersonate=$d
756 else
757 impersonate=
758 fi
f295c17b
BP
759 test_packet $s f000000000$d f00000000055 55$d $impersonate #3
760
4d5c43d5
JP
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
f295c17b
BP
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
766
767 test_packet $s f000000000$d f00000000055 810000091234 #4
768 test_packet $s f000000000$d 0100000000$s $s$d #5
769
4d5c43d5
JP
770 if test $d != $s && test $jd = 1; then
771 unknown="$unknown $d"
772 fi
f295c17b
BP
773 bcast="$bcast $unicast"
774 bacl2="$bacl2 $acl2"
775 bacl3="$bacl3 $acl3"
57d143eb
HZ
776
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
7dc88496
NS
782
783 if test $jd = 3; then
31ed1192 784 # lsp[123]3 has an additional ip 192.169.0.[123]3.
7dc88496
NS
785 tip=`ip_to_hex 192 169 0 $id$jd`
786 test_arp $s f000000000$s $sip $tip f000000000$d #9
787 fi
f295c17b
BP
788 done
789 done
790
4d5c43d5 791 # Broadcast and multicast.
f295c17b
BP
792 test_packet $s ffffffffffff f000000000$s ${s}ff $bcast #2
793 test_packet $s 010000000000 f000000000$s ${s}ff $bcast #2
4d5c43d5 794 if test $js = 1; then
f295c17b
BP
795 bcast_impersonate=$bcast
796 else
4d5c43d5
JP
797 bcast_impersonate=
798 fi
f295c17b
BP
799 test_packet $s 010000000000 f00000000044 44ff $bcast_impersonate #3
800
801 test_packet $s f0000000ffff f000000000$s ${s}66 $unknown #6
802
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
809 done
810done
811
7dc88496
NS
812# set address for lp13 with invalid characters.
813# lp13 should be configured with only 192.168.0.13.
31ed1192 814ovn-nbctl lsp-set-addresses lp13 "f0:00:00:00:00:13 192.168.0.13 invalid 192.169.0.13"
7dc88496
NS
815sip=`ip_to_hex 192 168 0 11`
816tip=`ip_to_hex 192 168 0 13`
817test_arp 11 f00000000011 $sip $tip f00000000013
818
819tip=`ip_to_hex 192 169 0 13`
820#arp request for 192.169.0.13 should be flooded
821test_arp 11 f00000000011 $sip $tip
822
f295c17b
BP
823# Allow some time for packet forwarding.
824# XXX This can be improved.
825sleep 1
826
91125642 827# dump information and flows with counters
bb0c41d3
RM
828ovn-sbctl dump-flows -- list multicast_group
829
830echo "------ hv1 dump ------"
831as hv1 ovs-vsctl show
832as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-int
833
834echo "------ hv2 dump ------"
835as hv2 ovs-vsctl show
836as hv2 ovs-ofctl -O OpenFlow13 dump-flows br-int
837
838echo "------ hv3 dump ------"
839as hv3 ovs-vsctl show
840as hv3 ovs-ofctl -O OpenFlow13 dump-flows br-int
f295c17b
BP
841# Now check the packets actually received against the ones expected.
842for i in 1 2 3; do
843 for j in 1 2 3; do
844 file=hv$i/vif$i$j-tx.pcap
845 echo $file
846 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" $file | trim_zeros > $i$j.packets
2172f32d
YT
847 sort $i$j.expected > expout
848 AT_CHECK([sort $i$j.packets], [0], [expout])
f295c17b
BP
849 echo
850 done
851done
fcde56f5
LR
852
853# Gracefully terminate daemons
d9c8c57c
LR
854for sim in hv1 hv2 hv3; do
855 as $sim
856 OVS_APP_EXIT_AND_WAIT([ovn-controller])
857 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
858 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
fcde56f5 859done
d9c8c57c
LR
860
861as ovn-sb
862OVS_APP_EXIT_AND_WAIT([ovsdb-server])
863
864as ovn-nb
865OVS_APP_EXIT_AND_WAIT([ovsdb-server])
866
867as northd
868OVS_APP_EXIT_AND_WAIT([ovn-northd])
869
870as main
871OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
872OVS_APP_EXIT_AND_WAIT([ovsdb-server])
873
f295c17b 874AT_CLEANUP
eb6b08eb 875
7277bc83
RB
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
e90aeb57 879AT_SETUP([ovn -- 2 HVs, 4 lports/HV, localnet ports])
d79fc5f4
RB
880AT_KEYWORDS([ovn-localnet])
881AT_SKIP_IF([test $HAVE_PYTHON = no])
882ovn_start
883
ea46a4e9
JP
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
0ee7f7f1
HZ
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.
889#
ea46a4e9 890# Each switch's VLAN tag and their logical switch ports are:
0ee7f7f1
HZ
891# - ls1:
892# - untagged
ea46a4e9 893# - ports: lp11, lp12, lp21, lp22
0ee7f7f1
HZ
894#
895# - ls2:
896# - tagged with VLAN 101
ea46a4e9 897# - ports: lp13, lp14, lp23, lp24
0ee7f7f1
HZ
898# - ls3:
899# - untagged
ea46a4e9 900# - ports: lp15, lp25
0ee7f7f1 901#
ea46a4e9 902# Note: a localnet port is created for each switch to connect to
0ee7f7f1
HZ
903# physical network.
904
905for i in 1 2 3; do
ea46a4e9
JP
906 ls_name=ls$i
907 ovn-nbctl ls-add $ls_name
0ee7f7f1
HZ
908 ln_port_name=ln$i
909 if test $i -eq 2; then
ea46a4e9 910 ovn-nbctl lsp-add $ls_name $ln_port_name "" 101
0ee7f7f1 911 else
ea46a4e9 912 ovn-nbctl lsp-add $ls_name $ln_port_name
0ee7f7f1 913 fi
31ed1192
JP
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
0ee7f7f1 917done
d79fc5f4
RB
918
919net_add n1
920for i in 1 2; do
921 sim_add hv$i
922 as hv$i
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
926
0ee7f7f1 927 for j in 1 2 3 4 5; do
d79fc5f4
RB
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 \
932 ofport-request=$i$j
933
31ed1192 934 lsp_name=lp$i$j
7277bc83 935 if test $j -le 2; then
ea46a4e9 936 ls_name=ls1
0ee7f7f1 937 elif test $j -le 4; then
ea46a4e9 938 ls_name=ls2
d79fc5f4 939 else
ea46a4e9 940 ls_name=ls3
d79fc5f4 941 fi
d79fc5f4 942
ea46a4e9 943 ovn-nbctl lsp-add $ls_name $lsp_name
31ed1192
JP
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
d79fc5f4 946
31ed1192 947 OVS_WAIT_UNTIL([test x`ovn-nbctl lsp-get-up $lsp_name` = xup])
d79fc5f4
RB
948 done
949done
950
951ovn_populate_arp
952
953# XXX This is now the 3rd copy of these functions in this file ...
954
955# Given the name of a logical port, prints the name of the hypervisor
956# on which it is located.
957vif_to_hv() {
958 echo hv${1%?}
959}
960#
961# test_packet INPORT DST SRC ETHTYPE OUTPORT...
962#
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
31ed1192 967# OUTPORTs are specified as logical switch port numbers, e.g. 11 for vif11.
d79fc5f4
RB
968trim_zeros() {
969 sed 's/\(00\)\{1,\}$//'
970}
971for i in 1 2; do
0ee7f7f1 972 for j in 1 2 3 4 5; do
d79fc5f4
RB
973 : > $i$j.expected
974 done
975done
976test_packet() {
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`
980 vif=vif$inport
981 as $hv ovs-appctl netdev-dummy/receive $vif $packet
982 for outport; do
983 echo $packet | trim_zeros >> $outport.expected
984 done
985}
986
7277bc83
RB
987# lp11 and lp21 are on the same network (phys, untagged)
988# and on different hypervisors
d79fc5f4
RB
989test_packet 11 f00000000021 f00000000011 1121 21
990test_packet 21 f00000000011 f00000000021 2111 11
991
7277bc83
RB
992# lp11 and lp12 are on the same network (phys, untagged)
993# and on the same hypervisor
e90aeb57
RB
994test_packet 11 f00000000012 f00000000011 1112 12
995test_packet 12 f00000000011 f00000000012 1211 11
7277bc83
RB
996
997# lp13 and lp23 are on the same network (phys, VLAN 101)
998# and on different hypervisors
999test_packet 13 f00000000023 f00000000013 1323 23
1000test_packet 23 f00000000013 f00000000023 2313 13
1001
1002# lp13 and lp14 are on the same network (phys, VLAN 101)
1003# and on the same hypervisor
e90aeb57
RB
1004test_packet 13 f00000000014 f00000000013 1314 14
1005test_packet 14 f00000000013 f00000000014 1413 13
d79fc5f4 1006
0ee7f7f1 1007# lp11 and lp15 are on the same network (phys, untagged),
ea46a4e9 1008# same hypervisor, and on different switches
0ee7f7f1
HZ
1009test_packet 11 f00000000015 f00000000011 1115 15
1010test_packet 15 f00000000011 f00000000015 1511 11
1011
1012# lp11 and lp25 are on the same network (phys, untagged),
ea46a4e9 1013# different hypervisors, and on different switches
0ee7f7f1
HZ
1014test_packet 11 f00000000025 f00000000011 1125 25
1015test_packet 25 f00000000011 f00000000025 2511 11
1016
d79fc5f4 1017# Ports that should not be able to communicate
7277bc83
RB
1018test_packet 11 f00000000013 f00000000011 1113
1019test_packet 11 f00000000023 f00000000011 1123
1020test_packet 21 f00000000013 f00000000021 2113
1021test_packet 21 f00000000023 f00000000021 2123
1022test_packet 13 f00000000011 f00000000013 1311
1023test_packet 13 f00000000021 f00000000013 1321
1024test_packet 23 f00000000011 f00000000023 2311
1025test_packet 23 f00000000021 f00000000023 2321
d79fc5f4
RB
1026
1027# Allow some time for packet forwarding.
1028# XXX This can be improved.
1029sleep 1
1030
1031# Dump a bunch of info helpful for debugging if there's a failure.
1032
1033echo "------ OVN dump ------"
1034ovn-nbctl show
1035ovn-sbctl show
1036
1037echo "------ hv1 dump ------"
1038as hv1 ovs-vsctl show
1039as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-int
1040
1041echo "------ hv2 dump ------"
1042as hv2 ovs-vsctl show
1043as hv2 ovs-ofctl -O OpenFlow13 dump-flows br-int
1044
1045# Now check the packets actually received against the ones expected.
1046for i in 1 2; do
0ee7f7f1 1047 for j in 1 2 3 4 5; do
d79fc5f4
RB
1048 file=hv$i/vif$i$j-tx.pcap
1049 echo $file
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])
1053 echo
1054 done
1055done
1056
fcde56f5 1057# Gracefully terminate daemons
d9c8c57c
LR
1058for sim in hv1 hv2; do
1059 as $sim
1060 OVS_APP_EXIT_AND_WAIT([ovn-controller])
1061 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
1062 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
fcde56f5 1063done
d9c8c57c
LR
1064
1065as ovn-sb
1066OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1067
1068as ovn-nb
1069OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1070
1071as northd
1072OVS_APP_EXIT_AND_WAIT([ovn-northd])
1073
1074as main
1075OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
1076OVS_APP_EXIT_AND_WAIT([ovsdb-server])
d79fc5f4
RB
1077AT_CLEANUP
1078
91125642
FF
1079AT_SETUP([ovn -- vtep: 3 HVs, 1 VIFs/HV, 1 GW, 1 LS])
1080AT_KEYWORDS([vtep])
eb6b08eb
JP
1081AT_SKIP_IF([test $HAVE_PYTHON = no])
1082ovn_start
1083
1084# Configure the Northbound database
ea46a4e9 1085ovn-nbctl ls-add lsw0
eb6b08eb 1086
31ed1192
JP
1087ovn-nbctl lsp-add lsw0 lp1
1088ovn-nbctl lsp-set-addresses lp1 f0:00:00:00:00:01
eb6b08eb 1089
31ed1192
JP
1090ovn-nbctl lsp-add lsw0 lp2
1091ovn-nbctl lsp-set-addresses lp2 f0:00:00:00:00:02
eb6b08eb 1092
31ed1192
JP
1093ovn-nbctl lsp-add lsw0 lp-vtep
1094ovn-nbctl lsp-set-type lp-vtep vtep
1095ovn-nbctl lsp-set-options lp-vtep vtep-physical-switch=br-vtep vtep-logical-switch=lsw0
1096ovn-nbctl lsp-set-addresses lp-vtep unknown
eb6b08eb
JP
1097
1098net_add n1 # Network to connect hv1, hv2, and vtep
1099net_add n2 # Network to connect vtep and hv3
1100
1101# Create hypervisor hv1 connected to n1
1102sim_add hv1
1103as hv1
1104ovs-vsctl add-br br-phys
1105ovn_attach n1 br-phys 192.168.0.1
1106ovs-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
1107
1108# Create hypervisor hv2 connected to n1
1109sim_add hv2
1110as hv2
1111ovs-vsctl add-br br-phys
1112ovn_attach n1 br-phys 192.168.0.2
1113ovs-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
1114
1115
1116# Start the vtep emulator with a leg in both networks
1117sim_add vtep
1118as vtep
1119
1120ovsdb-tool create "$ovs_base"/vtep/vtep.db "$abs_top_srcdir"/vtep/vtep.ovsschema || return 1
1121ovs-appctl -t ovsdb-server ovsdb-server/add-db "$ovs_base"/vtep/vtep.db
1122
1123ovs-vsctl add-br br-phys
1124net_attach n1 br-phys
1125
1126mac=`ovs-vsctl get Interface br-phys mac_in_use | sed s/\"//g`
1127arp_table="$arp_table $sandbox,br-phys,192.168.0.3,$mac"
1128ovs-appctl netdev-dummy/ip4addr br-phys 192.168.0.3/24 >/dev/null || return 1
1129ovs-appctl ovs/route/add 192.168.0.3/24 br-phys >/dev/null || return 1
1130
1131ovs-vsctl add-br br-vtep
1132net_attach n2 br-vtep
1133
1134vtep-ctl add-ps br-vtep
1135vtep-ctl set Physical_Switch br-vtep tunnel_ips=192.168.0.3
1136vtep-ctl add-ls lsw0
1137
1138start_daemon ovs-vtep br-vtep
1139start_daemon ovn-controller-vtep --vtep-db=unix:"$ovs_base"/vtep/db.sock --ovnsb-db=unix:"$ovs_base"/ovn-sb/ovn-sb.sock
1140
1141sleep 1
1142
1143vtep-ctl bind-ls br-vtep br-vtep_n2 0 lsw0
1144
1145sleep 1
1146
1147# Add hv3 on the other side of the vtep
1148sim_add hv3
1149as hv3
1150ovs-vsctl add-br br-phys
1151net_attach n2 br-phys
1152
1153ovs-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
1154
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).
1158ovn_populate_arp
1159
1160# Allow some time for ovn-northd and ovn-controller to catch up.
1161# XXX This should be more systematic.
1162sleep 1
6977df72 1163
eb6b08eb
JP
1164# test_packet INPORT DST SRC ETHTYPE OUTPORT...
1165#
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
31ed1192 1170# OUTPORTs are specified as logical switch port numbers, e.g. 1 for vif1.
eb6b08eb
JP
1171trim_zeros() {
1172 sed 's/\(00\)\{1,\}$//'
1173}
1174for i in 1 2 3; do
1175 : > $i.expected
1176done
1177test_packet() {
1178 local inport=$1 packet=$2$3$4; shift; shift; shift; shift
1179 #hv=hv`echo $inport | sed 's/^\(.\).*/\1/'`
1180 hv=hv$inport
1181 vif=vif$inport
1182 as $hv ovs-appctl netdev-dummy/receive $vif $packet
1183 for outport; do
1184 echo $packet | trim_zeros >> $outport.expected
1185 done
1186}
1187
1188# Send packets between all pairs of source and destination ports:
1189#
31ed1192
JP
1190# 1. Unicast packets are delivered to exactly one logical switch port
1191# (except that packets destined to their input ports are dropped).
eb6b08eb 1192#
31ed1192
JP
1193# 2. Broadcast and multicast are delivered to all logical switch ports
1194# except the input port.
eb6b08eb 1195#
ea46a4e9 1196# 3. The switch delivers packets with an unknown destination to logical
31ed1192
JP
1197# switch ports with "unknown" among their MAC addresses (and port
1198# security disabled).
eb6b08eb
JP
1199for s in 1 2 3; do
1200 bcast=
1201 unknown=
1202 for d in 1 2 3; do
1203 if test $d != $s; then unicast=$d; else unicast=; fi
1204 test_packet $s f0000000000$d f0000000000$s 00$s$d $unicast #1
1205
1206 # The vtep (vif3) is the only one configured for "unknown"
1207 if test $d != $s && test $d = 3; then
1208 unknown="$unknown $d"
1209 fi
1210 bcast="$bcast $unicast"
1211 done
1212
1213 # Broadcast and multicast.
46ed1382
DB
1214 test_packet $s ffffffffffff f0000000000$s 0${s}ff $bcast #2
1215 test_packet $s 010000000000 f0000000000$s 0${s}ff $bcast #2
eb6b08eb
JP
1216
1217 test_packet $s f0000000ffff f0000000000$s 0${s}66 $unknown #3
1218done
1219
1220# Allow some time for packet forwarding.
1221# XXX This can be improved.
1222sleep 1
1223
bb0c41d3
RM
1224# dump information with counters
1225echo "------ OVN dump ------"
1226ovn-nbctl show
1227ovn-sbctl show
1228
1229echo "------ hv1 dump ------"
1230as hv1 ovs-vsctl show
6195e2e7 1231as hv1 ovs-ofctl -O OpenFlow13 show br-int
bb0c41d3
RM
1232as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-int
1233
1234echo "------ hv2 dump ------"
1235as hv2 ovs-vsctl show
6195e2e7 1236as hv2 ovs-ofctl -O OpenFlow13 show br-int
bb0c41d3
RM
1237as hv2 ovs-ofctl -O OpenFlow13 dump-flows br-int
1238
1239echo "------ hv3 dump ------"
1240as hv3 ovs-vsctl show
6754e92d
FF
1241# note: hv3 has no logical port bind, thus it should not have br-int
1242AT_CHECK([as hv3 ovs-ofctl -O OpenFlow13 show br-int], [1], [],
1243[ovs-ofctl: br-int is not a bridge or a socket
1244])
bb0c41d3 1245
eb6b08eb
JP
1246# Now check the packets actually received against the ones expected.
1247for i in 1 2 3; do
1248 file=hv$i/vif$i-tx.pcap
1249 echo $file
1250 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" $file | trim_zeros > $i.packets
2172f32d
YT
1251 sort $i.expected > expout
1252 AT_CHECK([sort $i.packets], [0], [expout])
eb6b08eb
JP
1253 echo
1254done
fcde56f5
LR
1255
1256# Gracefully terminate daemons
d9c8c57c
LR
1257as vtep
1258OVS_APP_EXIT_AND_WAIT([ovn-controller-vtep])
1259OVS_APP_EXIT_AND_WAIT([ovs-vtep])
1260
1261as hv1
1262OVS_APP_EXIT_AND_WAIT([ovn-controller])
1263
1264as hv2
1265OVS_APP_EXIT_AND_WAIT([ovn-controller])
1266
1267as ovn-sb
1268OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1269
1270as ovn-nb
1271OVS_APP_EXIT_AND_WAIT([ovsdb-server])
1272
1273as northd
1274OVS_APP_EXIT_AND_WAIT([ovn-northd])
1275
1276for sim in hv1 hv2 hv3 vtep main; do
1277 as $sim
1278 for daemon in ovs-vswitchd ovsdb-server; do
1279 OVS_APP_EXIT_AND_WAIT([$daemon])
1280 done
fcde56f5 1281done
eb6b08eb 1282AT_CLEANUP
9975d7be
BP
1283
1284# 3 hypervisors, 3 logical switches with 3 logical ports each, 1 logical router
1285AT_SETUP([ovn -- 3 HVs, 3 LS, 3 lports/LS, 1 LR])
1286AT_SKIP_IF([test $HAVE_PYTHON = no])
1287ovn_start
1288
1289# Logical network:
1290#
1291# Three logical switches ls1, ls2, ls3.
86e98048
BP
1292# One logical router lr0 connected to ls[123],
1293# with nine subnets, three per logical switch:
1294#
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
1298# ...
1299# lrp33 on ls3 for subnet 192.168.33.0/24
1300#
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.
9975d7be 1303for i in 1 2 3; do
ea46a4e9 1304 ovn-nbctl ls-add ls$i
9975d7be 1305 for j in 1 2 3; do
86e98048 1306 for k in 1 2 3; do
31ed1192
JP
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
1310
1311 ovn-nbctl \
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
86e98048
BP
1315 done
1316 done
1317done
1318
fa2a27b2 1319ovn-nbctl lr-add lr0
86e98048
BP
1320for i in 1 2 3; do
1321 for j in 1 2 3; do
269ecccc 1322 ovn-nbctl lrp-add lr0 lrp$i$j 00:00:00:00:ff:$i$j \
31114af7 1323 192.168.$i$j.254/24 lrp$i$j-attachment
269ecccc 1324 ovn-nbctl \
31ed1192 1325 -- lsp-add ls$i lrp$i$j-attachment \
269ecccc 1326 -- set Logical_Switch_Port lrp$i$j-attachment type=router \
00007447 1327 options:router-port=lrp$i$j \
86e98048 1328 addresses='"00:00:00:00:ff:'$i$j'"'
9975d7be
BP
1329 done
1330done
1331
80f408f4 1332ovn-nbctl set Logical_Switch_Port lrp33-attachment \
57d143eb
HZ
1333 addresses='"00:00:00:00:ff:33 192.168.33.254"'
1334
9975d7be
BP
1335# Physical network:
1336#
1337# Three hypervisors hv[123].
86e98048
BP
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.
1341
9975d7be
BP
1342
1343# Given the name of a logical port, prints the name of the hypervisor
1344# on which it is located.
1345vif_to_hv() {
1346 case $1 in dnl (
86e98048
BP
1347 ?11) echo 1 ;; dnl (
1348 ?12 | ?21 | ?22) echo 2 ;; dnl (
1349 ?13 | ?23 | ?3?) echo 3 ;;
9975d7be
BP
1350 esac
1351}
1352
86e98048
BP
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.
1355vif_to_lrp() {
1356 echo ${1%?}
1357}
1358
1359# Given the name of a logical port, prints the name of its logical
1360# switch, e.g. "vif_to_ls 123" yields 1.
e3393e3f 1361vif_to_ls() {
86e98048 1362 echo ${1%??}
e3393e3f
BP
1363}
1364
9975d7be
BP
1365net_add n1
1366for i in 1 2 3; do
1367 sim_add hv$i
1368 as hv$i
1369 ovs-vsctl add-br br-phys
1370 ovn_attach n1 br-phys 192.168.0.$i
1371done
1372for i in 1 2 3; do
1373 for j in 1 2 3; do
86e98048 1374 for k in 1 2 3; do
269ecccc
JP
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
86e98048 1383 done
9975d7be
BP
1384 done
1385done
1386
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).
1390ovn_populate_arp
1391
1392# Allow some time for ovn-northd and ovn-controller to catch up.
1393# XXX This should be more systematic.
1394sleep 1
1395
e3393e3f 1396# test_ip INPORT SRC_MAC DST_MAC SRC_IP DST_IP OUTPORT...
9975d7be
BP
1397#
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
31ed1192 1402# OUTPORTs are specified as logical switch port numbers, e.g. 123 for vif123.
9975d7be
BP
1403trim_zeros() {
1404 sed 's/\(00\)\{1,\}$//'
1405}
1406for i in 1 2 3; do
1407 for j in 1 2 3; do
86e98048
BP
1408 for k in 1 2 3; do
1409 : > $i$j$k.expected
269ecccc 1410 done
9975d7be
BP
1411 done
1412done
e3393e3f 1413test_ip() {
9975d7be
BP
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
ba43992e 1416 local packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
9975d7be
BP
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
86e98048
BP
1421 in_ls=`vif_to_ls $inport`
1422 in_lrp=`vif_to_lrp $inport`
9975d7be 1423 for outport; do
269ecccc 1424 out_ls=`vif_to_ls $outport`
86e98048 1425 if test $in_ls = $out_ls; then
9975d7be
BP
1426 # Ports on the same logical switch receive exactly the same packet.
1427 echo $packet
1428 else
1429 # Routing decrements TTL and updates source and dest MAC
1430 # (and checksum).
269ecccc 1431 out_lrp=`vif_to_lrp $outport`
86e98048 1432 echo f00000000${outport}00000000ff${out_lrp}08004500001c00000000"3f1101"00${src_ip}${dst_ip}0035111100080000
9975d7be
BP
1433 fi | trim_zeros >> $outport.expected
1434 done
1435}
1436
e3393e3f 1437as hv1 ovs-vsctl --columns=name,ofport list interface
0bac7164
BP
1438as hv1 ovn-sbctl list port_binding
1439as hv1 ovn-sbctl list datapath_binding
9975d7be
BP
1440as hv1 ovn-sbctl dump-flows
1441as hv1 ovs-ofctl dump-flows br-int
1442
e3393e3f 1443# Send IP packets between all pairs of source and destination ports:
9975d7be 1444#
31ed1192
JP
1445# 1. Unicast IP packets are delivered to exactly one logical switch port
1446# (except that packets destined to their input ports are dropped).
9975d7be 1447#
31ed1192
JP
1448# 2. Broadcast IP packets are delivered to all logical switch ports
1449# except the input port.
86e98048
BP
1450ip_to_hex() {
1451 printf "%02x%02x%02x%02x" "$@"
1452}
9975d7be 1453for is in 1 2 3; do
269ecccc
JP
1454 for js in 1 2 3; do
1455 for ks in 1 2 3; do
1456 bcast=
1457 s=$is$js$ks
1458 smac=f00000000$s
1459 sip=`ip_to_hex 192 168 $is$js $ks`
1460 for id in 1 2 3; do
1461 for jd in 1 2 3; do
1462 for kd in 1 2 3; do
1463 d=$id$jd$kd
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
1467
1468 test_ip $s $smac $dmac $sip $dip $unicast #1
1469
1470 if test $id = $is && test $d != $s; then bcast="$bcast $d"; fi
1471 done
1472 done
9975d7be 1473 done
269ecccc
JP
1474 test_ip $s $smac ffffffffffff $sip ffffffff $bcast #2
1475 done
1476 done
e3393e3f
BP
1477done
1478
0bac7164
BP
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.
1483for is in 1 2 3; do
269ecccc
JP
1484 for js in 1 2 3; do
1485 for ks in 1 2 3; do
1486 s=$is$js$ks
1487 smac=f00000000$s
1488 sip=`ip_to_hex 192 168 $is$js $ks`
1489 for id in 1 2 3; do
1490 for jd in 1 2 3; do
1491 if test $is$js = $id$jd; then
1492 continue
1493 fi
1494
1495 # Send the packet.
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
1500 # 0-255.
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
1504
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
1511 for kd in 1 2 3; do
1512 echo $arp | trim_zeros >> $id$jd2$kd.expected
0bac7164 1513 done
269ecccc 1514 done
0bac7164 1515 done
269ecccc 1516 done
0bac7164 1517 done
269ecccc 1518 done
0bac7164
BP
1519done
1520
e3393e3f
BP
1521# test_arp INPORT SHA SPA TPA [REPLY_HA]
1522#
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.
1527#
31ed1192 1528# INPORT is an logical switch port number, e.g. 11 for vif11.
e3393e3f
BP
1529# SHA and REPLY_HA are each 12 hex digits.
1530# SPA and TPA are each 8 hex digits.
1531test_arp() {
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
1537
57d143eb 1538 # Expect to receive the broadcast ARP on the other logical switch ports if
ea46a4e9 1539 # IP address is not configured to the switch patch port.
e3393e3f 1540 local i=`vif_to_ls $inport`
86e98048 1541 local j k
e3393e3f 1542 for j in 1 2 3; do
86e98048 1543 for k in 1 2 3; do
ea46a4e9 1544 # 192.168.33.254 is configured to the switch patch port for lrp33,
57d143eb
HZ
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
86e98048
BP
1547 echo $request >> $i$j$k.expected
1548 fi
1549 done
e3393e3f
BP
1550 done
1551
1552 # Expect to receive the reply, if any.
1553 if test X$reply_ha != X; then
86e98048
BP
1554 lrp=`vif_to_lrp $inport`
1555 local reply=${sha}00000000ff${lrp}08060001080006040002${reply_ha}${tpa}${sha}${spa}
e3393e3f
BP
1556 echo $reply >> $inport.expected
1557 fi
1558}
1559
1560# Test router replies to ARP requests from all source ports:
1561#
0bac7164 1562# 4. Router replies to query for its MAC address from port's own IP address.
e3393e3f 1563#
0bac7164 1564# 5. Router replies to query for its MAC address from any random IP address
e3393e3f
BP
1565# in its subnet.
1566#
0bac7164 1567# 6. Router replies to query for its MAC address from another subnet.
e3393e3f 1568#
0bac7164 1569# 7. No reply to query for IP address other than router IP.
e3393e3f 1570for i in 1 2 3; do
269ecccc
JP
1571 for j in 1 2 3; do
1572 for k in 1 2 3; do
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
0bac7164 1582 done
269ecccc 1583 done
0bac7164
BP
1584done
1585
1586# Allow some time for packet forwarding.
1587# XXX This can be improved.
1588sleep 1
1589
1590# 8. Generate an ARP reply for each of the IP addresses ARPed for
1591# earlier as #3.
1592#
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
1597for is in 1 2 3; do
269ecccc
JP
1598 for js in 1 2 3; do
1599 for ks in 1 2 3; do
1600 s=$is$js$ks
1601 for id in 1 2 3; do
1602 for jd in 1 2 3; do
1603 if test $is$js = $id$jd; then
1604 continue
1605 fi
1606
1607 kd=1
1608 d=$id$jd$kd
1609
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
1613
1614 lrmac=00000000ff$id$jd
1615 lrip=`ip_to_hex 192 168 $id$jd 254`
1616
1617 arp=${lrmac}${host_mac}08060001080006040002${host_mac}${host_ip}${lrmac}${lrip}
1618
1619 echo
1620 echo
1621 echo
1622 hv=hv`vif_to_hv $d`
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
1626
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
86e98048 1630 done
269ecccc 1631 done
9975d7be 1632 done
269ecccc 1633 done
9975d7be 1634done
0bac7164 1635
9975d7be
BP
1636# Allow some time for packet forwarding.
1637# XXX This can be improved.
1638sleep 1
1639
0bac7164
BP
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.)
1646for is in 1 2 3; do
269ecccc
JP
1647 for js in 1 2 3; do
1648 for ks in 1 2 3; do
1649 s=$is$js$ks
1650 smac=f00000000$s
1651 sip=`ip_to_hex 192 168 $is$js $ks`
1652 for id in 1 2 3; do
1653 for jd in 1 2 3; do
1654 if test $is$js = $id$jd; then
1655 continue
1656 fi
1657
1658 # Send the packet.
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
1663 # 0-255.
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
1667
1668 # Expect the packet egress.
1669 host_mac=8000000000$o4
1670 outport=${id}11
1671 out_lrp=$id$jd
1672 echo ${host_mac}00000000ff${out_lrp}08004500001c00000000"3f1101"00${sip}${dip}0035111100080000 | trim_zeros >> $outport.expected
0bac7164 1673 done
269ecccc 1674 done
0bac7164 1675 done
269ecccc 1676 done
0bac7164
BP
1677done
1678
1679# Allow some time for packet forwarding.
1680# XXX This can be improved.
1681sleep 1
1682
1683ovn-sbctl -f csv -d bare --no-heading \
1684 -- --columns=logical_port,ip,mac list mac_binding > mac_bindings
1685
9975d7be
BP
1686# Now check the packets actually received against the ones expected.
1687for i in 1 2 3; do
1688 for j in 1 2 3; do
86e98048 1689 for k in 1 2 3; do
269ecccc
JP
1690 file=hv`vif_to_hv $i$j$k`/vif$i$j$k-tx.pcap
1691 echo $file
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])
1695 echo
86e98048 1696 done
9975d7be
BP
1697 done
1698done
fcde56f5 1699
0bac7164
BP
1700# Check the MAC bindings against those expected.
1701AT_CHECK_UNQUOTED([sort < mac_bindings], [0], [`sort < mac_bindings.expected`
1702])
1703
fcde56f5
LR
1704# Gracefully terminate daemons
1705for daemon in ovn-controller ovn-northd ovsdb-server; do
1706 ovs-appctl -t $daemon exit
1707done
9975d7be 1708AT_CLEANUP
685f4dfe
NS
1709
1710# 3 hypervisors, one logical switch, 3 logical ports per hypervisor
1711AT_SETUP([ovn -- portsecurity : 3 HVs, 1 LS, 3 lports/HV])
1712AT_KEYWORDS([portsecurity])
1713AT_SKIP_IF([test $HAVE_PYTHON = no])
1714ovn_start
1715
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.
ea46a4e9 1723ovn-nbctl ls-add lsw0
685f4dfe
NS
1724net_add n1
1725for i in 1 2 3; do
1726 sim_add hv$i
1727 as hv$i
1728 ovs-vsctl add-br br-phys
1729 ovn_attach n1 br-phys 192.168.0.$i
1730
1731 for j in 1 2 3; do
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
31ed1192 1733 ovn-nbctl lsp-add lsw0 lp$i$j
685f4dfe 1734 if test $j = 1; then
31ed1192 1735 ovn-nbctl lsp-set-addresses lp$i$j "f0:00:00:00:00:$i$j 192.168.0.$i$j" unknown
685f4dfe 1736 elif test $j = 2; then
31ed1192
JP
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
685f4dfe
NS
1739 else
1740 extra_addr="f0:00:00:00:0$i:$i$j fe80::ea2a:eaff:fe28:$i$j"
31ed1192
JP
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"
685f4dfe
NS
1743 fi
1744 done
1745done
1746
685f4dfe
NS
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).
1750ovn_populate_arp
1751
1752# Allow some time for ovn-northd and ovn-controller to catch up.
1753# XXX This should be more systematic.
1754sleep 1
685f4dfe
NS
1755
1756# Given the name of a logical port, prints the name of the hypervisor
1757# on which it is located.
1758vif_to_hv() {
1759 echo hv${1%?}
1760}
1761
1762
1763trim_zeros() {
1764 sed 's/\(00\)\{1,\}$//'
1765}
1766for i in 1 2 3; do
1767 for j in 1 2 3; do
1768 : > $i$j.expected
1769 done
1770done
1771
1772# test_ip INPORT SRC_MAC DST_MAC SRC_IP DST_IP OUTPORT...
1773#
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
31ed1192
JP
1778# be received. INPORT and the OUTPORTs are specified as logical switch
1779# port numbers, e.g. 11 for vif11.
685f4dfe
NS
1780test_ip() {
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
1788 for outport; do
1789 echo $packet | trim_zeros >> $outport.expected
1790 done
1791}
1792
1793# test_arp INPORT SHA SPA TPA DROP [REPLY_HA]
1794#
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.
1799#
31ed1192 1800# INPORT is an logical switch port number, e.g. 11 for vif11.
685f4dfe
NS
1801# SHA and REPLY_HA are each 12 hex digits.
1802# SPA and TPA are each 8 hex digits.
1803test_arp() {
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.
1813 local i j
1814 for i in 1 2 3; do
1815 for j in 1 2 3; do
1816 if test $i$j != $inport; then
1817 echo $request >> $i$j.expected
1818 fi
1819 done
1820 done
1821 else
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
1825 fi
1826 fi
1827}
1828
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
1831# ipv6 packet
1832test_ipv6() {
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
1839 for outport; do
1840 echo $packet | trim_zeros >> $outport.expected
1841 done
1842}
1843
9e687b23
DL
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
1847test_icmpv6() {
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
1854 for outport; do
1855 echo $packet | trim_zeros >> $outport.expected
1856 done
1857}
1858
685f4dfe
NS
1859ip_to_hex() {
1860 printf "%02x%02x%02x%02x" "$@"
1861}
1862
1863# no port security
1864sip=`ip_to_hex 192 168 0 12`
1865tip=`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
1868for i in 1 2 3; do
1869 test_arp ${i}1 f00000000023 f00000000023 $sip $tip 0 f00000000013
1870 for j in 1 2 3; do
1871 if test $i != $j; then
1872 test_ip ${i}1 f000000000${i}1 f000000000${j}1 $sip $tip ${j}1
1873 fi
1874 done
1875done
1876
1877# l2 port security
1878sip=`ip_to_hex 192 168 0 12`
1879tip=`ip_to_hex 192 168 0 13`
1880
1881# arp packet should be allowed since lp22 is configured with
1882# mac f00000000022
1883test_arp 22 f00000000022 f00000000022 $sip $tip 0 f00000000013
1884
1885# arp packet should not be allowed since lp32 is not configured with
1886# mac f00000000021
1887test_arp 32 f00000000021 f00000000021 $sip $tip 1
1888
1889# arp packet with sha set to f00000000021 should not be allowed
1890# for lp12
1891test_arp 12 f00000000012 f00000000021 $sip $tip 1
1892
1893# ip packets should be allowed and received since lp[123]2 do not
1894# have l3 port security
1895sip=`ip_to_hex 192 168 0 55`
1896tip=`ip_to_hex 192 168 0 66`
1897for i in 1 2 3; do
1898 for j in 1 2 3; do
1899 if test $i != $j; then
1900 test_ip ${i}2 f000000000${i}2 f000000000${j}2 $sip $tip ${j}2
1901 fi
1902 done
1903done
1904
1905# ipv6 packets should be received by lp[123]2
1906# lp[123]1 can send ipv6 traffic as there is no port security
1907sip=fe800000000000000000000000000000
1908tip=ff020000000000000000000000000000
1909
1910for i in 1 2 3; do
1911 test_ipv6 ${i}1 f000000000${i}1 f000000000${i}2 $sip $tip ${i}2
1912done
1913
1914
1915# l2 and l3 port security
1916sip=`ip_to_hex 192 168 0 13`
1917tip=`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
1920test_arp 13 f00000000013 f00000000013 $sip $tip 0 f00000000022
1921
1922# the arp packet should be dropped because lp23 is not configured
1923# with mac f00000000022
1924sip=`ip_to_hex 192 168 0 13`
1925tip=`ip_to_hex 192 168 0 22`
1926test_arp 23 f00000000022 f00000000022 $sip $tip 1
1927
1928# the arp packet should be dropped because lp33 is not configured
1929# with ip 192.168.0.55
1930spa=`ip_to_hex 192 168 0 55`
1931tpa=`ip_to_hex 192 168 0 22`
1932test_arp 33 f00000000031 f00000000031 $spa $tpa 1
1933
1934# ip packets should not be received by lp[123]3 since
1935# l3 port security is enabled
1936sip=`ip_to_hex 192 168 0 55`
1937tip=`ip_to_hex 192 168 0 66`
1938for i in 1 2 3; do
1939 for j in 1 2 3; do
1940 test_ip ${i}2 f000000000${i}2 f000000000${j}3 $sip $tip
1941 done
1942done
1943
1944# ipv6 packets should be dropped for lp[123]3 since
1945# it is configured with only ipv4 address
1946sip=fe800000000000000000000000000000
1947tip=ff020000000000000000000000000000
1948
1949for i in 1 2 3; do
1950 test_ipv6 ${i}3 f000000000${i}3 f00000000022 $sip $tip
1951done
1952
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
1955for i in 1 2 3; do
1956 test_ipv6 ${i}1 f000000000${i}1 f000000000${i}3 $sip $tip
1957done
1958
1959# lp13 has extra port security with mac f0000000113 and ipv6 addr
1960# fe80::ea2a:eaff:fe28:0012
1961
1962# ipv4 packet should be dropped for lp13 with mac f0000000113
1963sip=`ip_to_hex 192 168 0 13`
1964tip=`ip_to_hex 192 168 0 23`
1965test_ip 13 f00000000113 f00000000023 $sip $tip
1966
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
1970sip=ee800000000000000000000000000000
1971for i in 1 2 3; do
1972 tip=fe80000000000000ea2aeafffe2800{i}3
1973 test_ipv6 11 f00000000011 f000000000{i}${i}3 $sip $tip {i}3
1974done
1975
1976
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
1981
1982sip=ee800000000000000000000000000000
1983tip=fe80000000000000ea2aeafffe280023
1984test_ipv6 11 f00000000011 f00000000333 $sip $tip
1985
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
1990
1991tip=ee800000000000000000000000000000
1992for i in 1 2 3; do
1993 sip=fe80000000000000ea2aeafffe2800${i}3
1994 test_ipv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip $tip 21
1995
9e687b23 1996 # Test ICMPv6 MLD reports (v1 and v2) and NS for DAD
685f4dfe 1997 sip=00000000000000000000000000000000
9e687b23
DL
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
685f4dfe
NS
2005
2006 # should be dropped
2007 sip=ae80000000000000ea2aeafffe2800aa
2008 test_ipv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip $tip
2009done
2010
31ed1192
JP
2011# configure lsp13 to send and received IPv4 packets with an address range
2012ovn-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"
7d9d86ad 2013
8ff5a966
NS
2014sleep 2
2015
7d9d86ad
NS
2016sip=`ip_to_hex 10 0 0 13`
2017tip=`ip_to_hex 192 168 0 22`
31ed1192 2018# arp packet with inner ip 10.0.0.13 should be allowed for lsp13
7d9d86ad
NS
2019test_arp 13 f00000000013 f00000000013 $sip $tip 0 f00000000022
2020
2021sip=`ip_to_hex 10 0 0 14`
2022tip=`ip_to_hex 192 168 0 23`
31ed1192 2023# IPv4 packet from lsp13 with src ip 10.0.0.14 destined to lsp23
7d9d86ad
NS
2024# with dst ip 192.168.0.23 should be allowed
2025test_ip 13 f00000000013 f00000000023 $sip $tip 23
2026
2027sip=`ip_to_hex 192 168 0 33`
2028tip=`ip_to_hex 10 0 0 15`
31ed1192
JP
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
7d9d86ad
NS
2031test_ip 33 f00000000033 f00000000013 $sip $tip 13
2032
2033sip=`ip_to_hex 192 168 0 33`
2034tip=`ip_to_hex 20 0 0 4`
31ed1192
JP
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
7d9d86ad
NS
2037test_ip 33 f00000000033 f00000000013 $sip $tip 13
2038
2039sip=`ip_to_hex 192 168 0 33`
2040tip=`ip_to_hex 20 0 0 5`
31ed1192
JP
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
7d9d86ad
NS
2043test_ip 33 f00000000033 f00000000013 $sip $tip
2044
2045sip=`ip_to_hex 192 168 0 33`
2046tip=`ip_to_hex 20 0 0 255`
31ed1192
JP
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
7d9d86ad
NS
2049test_ip 33 f00000000033 f00000000013 $sip $tip 13
2050
2051sip=`ip_to_hex 192 168 0 33`
2052tip=`ip_to_hex 192 168 0 255`
31ed1192
JP
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
7d9d86ad
NS
2055test_ip 33 f00000000033 f00000000013 $sip $tip
2056
2057sip=`ip_to_hex 192 168 0 33`
2058tip=`ip_to_hex 224 0 0 4`
31ed1192
JP
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
7d9d86ad 2061test_ip 33 f00000000033 f00000000013 $sip $tip 13
685f4dfe
NS
2062
2063# Allow some time for packet forwarding.
2064
2065# XXX This can be improved.
2066sleep 1
2067
bb0c41d3
RM
2068#dump information including flow counters
2069ovn-nbctl show
2070ovn-sbctl dump-flows -- list multicast_group
2071
2072echo "------ hv1 dump ------"
2073as hv1 ovs-vsctl show
6195e2e7 2074as hv1 ovs-ofctl -O OpenFlow13 show br-int
bb0c41d3
RM
2075as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-int
2076
2077echo "------ hv2 dump ------"
2078as hv2 ovs-vsctl show
6195e2e7 2079as hv2 ovs-ofctl -O OpenFlow13 show br-int
bb0c41d3
RM
2080as hv2 ovs-ofctl -O OpenFlow13 dump-flows br-int
2081
2082echo "------ hv3 dump ------"
2083as hv3 ovs-vsctl show
6195e2e7 2084as hv3 ovs-ofctl -O OpenFlow13 show br-int
bb0c41d3
RM
2085as hv3 ovs-ofctl -O OpenFlow13 dump-flows br-int
2086
685f4dfe
NS
2087# Now check the packets actually received against the ones expected.
2088for i in 1 2 3; do
2089 for j in 1 2 3; do
2090 file=hv$i/vif$i$j-tx.pcap
2091 echo $file
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])
2095 echo
2096 done
2097done
2098
2099# Gracefully terminate daemons
d9c8c57c
LR
2100for sim in hv1 hv2 hv3; do
2101 as $sim
2102 OVS_APP_EXIT_AND_WAIT([ovn-controller])
2103 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2104 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
685f4dfe 2105done
d9c8c57c
LR
2106
2107as ovn-sb
2108OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2109
2110as ovn-nb
2111OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2112
2113as northd
2114OVS_APP_EXIT_AND_WAIT([ovn-northd])
2115
2116as main
2117OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2118OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2119
685f4dfe 2120AT_CLEANUP
509afdc3
GS
2121
2122AT_SETUP([ovn -- 2 HVs, 2 LS, 1 lport/LS, 2 peer LRs])
2123AT_KEYWORDS([ovnpeer])
2124AT_SKIP_IF([test $HAVE_PYTHON = no])
2125ovn_start
2126
2127# Logical network:
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.
2131
fa2a27b2
JP
2132ovn-nbctl lr-add R1
2133ovn-nbctl lr-add R2
509afdc3 2134
ea46a4e9
JP
2135ovn-nbctl ls-add ls1
2136ovn-nbctl ls-add ls2
509afdc3
GS
2137
2138# Connect ls1 to R1
31114af7 2139ovn-nbctl lrp-add R1 ls1 00:00:00:01:02:03 192.168.1.1/24 rp-ls1
509afdc3 2140
31ed1192 2141ovn-nbctl lsp-add ls1 rp-ls1 -- set Logical_Switch_Port rp-ls1 type=router \
31114af7 2142 options:router-port=ls1 addresses=\"00:00:00:01:02:03\"
509afdc3
GS
2143
2144# Connect ls2 to R2
31114af7 2145ovn-nbctl lrp-add R2 ls2 00:00:00:01:02:04 172.16.1.1/24 rp-ls2
509afdc3 2146
31ed1192 2147ovn-nbctl lsp-add ls2 rp-ls2 -- set Logical_Switch_Port rp-ls2 type=router \
31114af7 2148 options:router-port=ls2 addresses=\"00:00:00:01:02:04\"
509afdc3
GS
2149
2150# Connect R1 to R2
31114af7
JP
2151ovn-nbctl lrp-add R1 R1_R2 00:00:00:02:03:04 20.0.0.1/24 R2_R1
2152ovn-nbctl lrp-add R2 R2_R1 00:00:00:02:03:05 20.0.0.2/24 R1_R2
509afdc3
GS
2153
2154ovn-nbctl set Logical_Router R1 default_gw="20.0.0.2"
2155ovn-nbctl set Logical_Router R2 default_gw="20.0.0.1"
2156
2157# Create logical port ls1-lp1 in ls1
31ed1192
JP
2158ovn-nbctl lsp-add ls1 ls1-lp1 \
2159-- lsp-set-addresses ls1-lp1 "f0:00:00:01:02:03 192.168.1.2"
509afdc3
GS
2160
2161# Create logical port ls2-lp1 in ls2
31ed1192
JP
2162ovn-nbctl lsp-add ls2 ls2-lp1 \
2163-- lsp-set-addresses ls2-lp1 "f0:00:00:01:02:04 172.16.1.2"
509afdc3
GS
2164
2165# Create two hypervisor and create OVS ports corresponding to logical ports.
2166net_add n1
2167
2168sim_add hv1
2169as hv1
2170ovs-vsctl add-br br-phys
2171ovn_attach n1 br-phys 192.168.0.1
2172ovs-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 \
2176 ofport-request=1
2177
2178sim_add hv2
2179as hv2
2180ovs-vsctl add-br br-phys
2181ovn_attach n1 br-phys 192.168.0.2
2182ovs-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 \
2186 ofport-request=1
2187
2188
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).
2192ovn_populate_arp
2193
2194# Allow some time for ovn-northd and ovn-controller to catch up.
2195# XXX This should be more systematic.
2196sleep 1
2197
2198# Send ip packets between the two ports.
2199ip_to_hex() {
2200 printf "%02x%02x%02x%02x" "$@"
2201}
2202trim_zeros() {
2203 sed 's/\(00\)\{1,\}$//'
2204}
2205
2206# Packet to send.
2207src_mac="f00000010203"
2208dst_mac="000000010203"
2209src_ip=`ip_to_hex 192 168 1 2`
2210dst_ip=`ip_to_hex 172 16 1 2`
2211packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
2212as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet
2213
2214
2215echo "---------NB dump-----"
2216ovn-nbctl show
2217echo "---------------------"
2218ovn-nbctl list logical_router
2219echo "---------------------"
2220ovn-nbctl list logical_router_port
2221echo "---------------------"
2222
2223echo "---------SB dump-----"
2224ovn-sbctl list datapath_binding
2225echo "---------------------"
2226ovn-sbctl list port_binding
2227echo "---------------------"
2228
2229echo "------ hv1 dump ----------"
8dab1022 2230as hv1 ovs-ofctl show br-int
509afdc3
GS
2231as hv1 ovs-ofctl dump-flows br-int
2232echo "------ hv2 dump ----------"
8dab1022 2233as hv2 ovs-ofctl show br-int
509afdc3
GS
2234as hv2 ovs-ofctl dump-flows br-int
2235
2236# Packet to Expect
2237src_mac="000000010204"
2238dst_mac="f00000010204"
2239expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000
2240
2241$PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv2/vif1-tx.pcap | trim_zeros > received.packets
2242echo $expected | trim_zeros > expout
2243AT_CHECK([cat received.packets], [0], [expout])
2244
2245for sim in hv1 hv2; do
2246 as $sim
2247 OVS_APP_EXIT_AND_WAIT([ovn-controller])
2248 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2249 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2250done
2251
2252as ovn-sb
2253OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2254
2255as ovn-nb
2256OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2257
2258as northd
2259OVS_APP_EXIT_AND_WAIT([ovn-northd])
2260
2261as main
2262OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2263OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2264
2265AT_CLEANUP
5412db30
J
2266
2267
2268AT_SETUP([ovn -- 1 HVs, 2 LSs, 1 lport/LS, 1 LR])
2269AT_KEYWORDS([router-admin-state])
2270AT_SKIP_IF([test $HAVE_PYTHON = no])
2271ovn_start
2272
2273# Logical network:
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.
2276
fa2a27b2 2277ovn-nbctl lr-add R1
5412db30 2278
ea46a4e9
JP
2279ovn-nbctl ls-add ls1
2280ovn-nbctl ls-add ls2
5412db30
J
2281
2282# Connect ls1 to R1
31114af7 2283ovn-nbctl lrp-add R1 ls1 00:00:00:01:02:03 192.168.1.1/24 rp-ls1
31ed1192 2284ovn-nbctl lsp-add ls1 rp-ls1 -- set Logical_Switch_Port rp-ls1 type=router \
31114af7 2285 options:router-port=ls1 addresses=\"00:00:00:01:02:03\"
5412db30
J
2286
2287# Connect ls2 to R1
31114af7 2288ovn-nbctl lrp-add R1 ls2 00:00:00:01:02:04 172.16.1.1/24 rp-ls2
31ed1192 2289ovn-nbctl lsp-add ls2 rp-ls2 -- set Logical_Switch_Port rp-ls2 type=router \
31114af7 2290 options:router-port=ls2 addresses=\"00:00:00:01:02:04\"
5412db30
J
2291
2292# Create logical port ls1-lp1 in ls1
31ed1192
JP
2293ovn-nbctl lsp-add ls1 ls1-lp1 \
2294-- lsp-set-addresses ls1-lp1 "f0:00:00:01:02:03 192.168.1.2"
5412db30
J
2295
2296# Create logical port ls2-lp1 in ls2
31ed1192
JP
2297ovn-nbctl lsp-add ls2 ls2-lp1 \
2298-- lsp-set-addresses ls2-lp1 "f0:00:00:01:02:04 172.16.1.2"
5412db30
J
2299
2300# Create one hypervisor and create OVS ports corresponding to logical ports.
2301net_add n1
2302
2303sim_add hv1
2304as hv1
2305ovs-vsctl add-br br-phys
2306ovn_attach n1 br-phys 192.168.0.1
2307ovs-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 \
2311 ofport-request=1
2312
2313ovs-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 \
2317 ofport-request=1
2318
2319
2320# Allow some time for ovn-northd and ovn-controller to catch up.
2321# XXX This should be more systematic.
2322sleep 1
2323
2324# Send ip packets between the two ports.
2325ip_to_hex() {
2326 printf "%02x%02x%02x%02x" "$@"
2327}
2328trim_zeros() {
2329 sed 's/\(00\)\{1,\}$//'
2330}
2331
2332# Packet to send.
2333src_mac="f00000010203"
2334dst_mac="000000010203"
2335src_ip=`ip_to_hex 192 168 1 2`
2336dst_ip=`ip_to_hex 172 16 1 2`
2337packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
2338as hv1 ovs-appctl netdev-dummy/receive vif1 $packet
2339
2340
2341echo "---------NB dump-----"
2342ovn-nbctl show
2343echo "---------------------"
2344ovn-nbctl list logical_router
2345echo "---------------------"
2346ovn-nbctl list logical_router_port
2347echo "---------------------"
2348
2349echo "---------SB dump-----"
2350ovn-sbctl list datapath_binding
2351echo "---------------------"
2352ovn-sbctl list logical_flow
2353echo "---------------------"
2354
2355echo "------ hv1 dump ----------"
2356as hv1 ovs-ofctl dump-flows br-int
2357
2358
2359#Disable router R1
2360ovn-nbctl set Logical_Router R1 enabled=false
2361
2362echo "---------SB dump-----"
2363ovn-sbctl list datapath_binding
2364echo "---------------------"
2365ovn-sbctl list logical_flow
2366echo "---------------------"
2367
2368echo "------ hv1 dump ----------"
2369as hv1 ovs-ofctl dump-flows br-int
2370
a1361a6e
LR
2371# Allow some time for the disabling of logical router R1 to propagate.
2372# XXX This should be more systematic.
2373sleep 1
2374
5412db30
J
2375as hv1 ovs-appctl netdev-dummy/receive vif1 $packet
2376
2377# Packet to Expect
2378expect_src_mac="000000010204"
2379expect_dst_mac="f00000010204"
2380expected=${expect_dst_mac}${expect_src_mac}08004500001c000000003f110100${src_ip}${dst_ip}0035111100080000
2381
2382$PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif2-tx.pcap | trim_zeros > received.packets
2383echo $expected | trim_zeros > expout
2384AT_CHECK([cat received.packets], [0], [expout])
2385
2386
2387as hv1
2388OVS_APP_EXIT_AND_WAIT([ovn-controller])
2389OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2390OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2391
2392as ovn-sb
2393OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2394
2395as ovn-nb
2396OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2397
2398as northd
2399OVS_APP_EXIT_AND_WAIT([ovn-northd])
2400
2401as main
2402OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2403OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2404
2405AT_CLEANUP
2406
28dc3fe9
SR
2407AT_SETUP([ovn -- 2 HVs, 3 LS, 1 lport/LS, 2 peer LRs, static routes])
2408AT_KEYWORDS([ovnstaticroutespeer])
2409AT_SKIP_IF([test $HAVE_PYTHON = no])
2410ovn_start
2411
2412# Logical network:
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)
2415# connected to it.
2416# R2 has alice (172.16.1.0/24) and bob (172.16.2.0/24) connected to it.
2417
fa2a27b2
JP
2418ovn-nbctl lr-add R1
2419ovn-nbctl lr-add R2
28dc3fe9 2420
ea46a4e9
JP
2421ovn-nbctl ls-add foo
2422ovn-nbctl ls-add alice
2423ovn-nbctl ls-add bob
28dc3fe9
SR
2424
2425# Connect foo to R1
31114af7 2426ovn-nbctl lrp-add R1 foo 00:00:00:01:02:03 192.168.1.1/24 rp-foo
31ed1192 2427ovn-nbctl lsp-add foo rp-foo -- set Logical_Switch_Port rp-foo type=router \
31114af7 2428 options:router-port=foo addresses=\"00:00:00:01:02:03\"
28dc3fe9
SR
2429
2430# Connect alice to R2
31114af7 2431ovn-nbctl lrp-add R2 alice 00:00:00:01:02:04 172.16.1.1/24 rp-alice
31ed1192 2432ovn-nbctl lsp-add alice rp-alice -- set Logical_Switch_Port rp-alice \
80f408f4 2433 type=router options:router-port=alice addresses=\"00:00:00:01:02:04\"
28dc3fe9
SR
2434
2435# Connect bob to R2
31114af7 2436ovn-nbctl lrp-add R2 bob 00:00:00:01:02:05 172.16.2.1/24 rp-bob
31ed1192 2437ovn-nbctl lsp-add bob rp-bob -- set Logical_Switch_Port rp-bob type=router \
31114af7 2438 options:router-port=bob addresses=\"00:00:00:01:02:05\"
28dc3fe9
SR
2439
2440# Connect R1 to R2
31114af7
JP
2441ovn-nbctl lrp-add R1 R1_R2 00:00:00:02:03:04 20.0.0.1/24 R2_R1
2442ovn-nbctl lrp-add R2 R2_R1 00:00:00:02:03:05 20.0.0.2/24 R1_R2
28dc3fe9
SR
2443
2444#install static routes
e48ccf3c
JP
2445ovn-nbctl lr-route-add R1 172.16.1.0/24 20.0.0.2
2446ovn-nbctl lr-route-add R2 172.16.2.0/24 20.0.0.2 R1_R2
2447ovn-nbctl lr-route-add R2 192.168.1.0/24 20.0.0.1
28dc3fe9
SR
2448
2449# Create logical port foo1 in foo
31ed1192
JP
2450ovn-nbctl lsp-add foo foo1 \
2451-- lsp-set-addresses foo1 "f0:00:00:01:02:03 192.168.1.2"
28dc3fe9
SR
2452
2453# Create logical port alice1 in alice
31ed1192
JP
2454ovn-nbctl lsp-add alice alice1 \
2455-- lsp-set-addresses alice1 "f0:00:00:01:02:04 172.16.1.2"
28dc3fe9
SR
2456
2457# Create logical port bob1 in bob
31ed1192
JP
2458ovn-nbctl lsp-add bob bob1 \
2459-- lsp-set-addresses bob1 "f0:00:00:01:02:05 172.16.2.2"
28dc3fe9
SR
2460
2461# Create two hypervisor and create OVS ports corresponding to logical ports.
2462net_add n1
2463
2464sim_add hv1
2465as hv1
2466ovs-vsctl add-br br-phys
2467ovn_attach n1 br-phys 192.168.0.1
2468ovs-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 \
2472 ofport-request=1
2473
2474ovs-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 \
2478 ofport-request=2
2479
2480sim_add hv2
2481as hv2
2482ovs-vsctl add-br br-phys
2483ovn_attach n1 br-phys 192.168.0.2
2484ovs-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 \
2488 ofport-request=1
2489
2490
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).
2494ovn_populate_arp
2495
2496# Allow some time for ovn-northd and ovn-controller to catch up.
2497# XXX This should be more systematic.
2498sleep 1
2499
2500ip_to_hex() {
2501 printf "%02x%02x%02x%02x" "$@"
2502}
2503trim_zeros() {
2504 sed 's/\(00\)\{1,\}$//'
2505}
2506
2507# Send ip packets between foo1 and alice1
2508src_mac="f00000010203"
2509dst_mac="000000010203"
2510src_ip=`ip_to_hex 192 168 1 2`
2511dst_ip=`ip_to_hex 172 16 1 2`
2512packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
2513as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet
2514
2515# Send ip packets between foo1 and bob1
2516src_mac="f00000010203"
2517dst_mac="000000010203"
2518src_ip=`ip_to_hex 192 168 1 2`
2519dst_ip=`ip_to_hex 172 16 2 2`
2520packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
2521as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet
2522
2523echo "---------NB dump-----"
2524ovn-nbctl show
2525echo "---------------------"
2526ovn-nbctl list logical_router
2527echo "---------------------"
2528ovn-nbctl list logical_router_port
2529echo "---------------------"
2530
2531echo "---------SB dump-----"
2532ovn-sbctl list datapath_binding
2533echo "---------------------"
2534ovn-sbctl list port_binding
2535echo "---------------------"
2536
2537echo "------ hv1 dump ----------"
2538as hv1 ovs-ofctl dump-flows br-int
2539echo "------ hv2 dump ----------"
2540as hv2 ovs-ofctl dump-flows br-int
2541
2542# Packet to Expect at bob1
2543src_mac="000000010205"
2544dst_mac="f00000010205"
2545src_ip=`ip_to_hex 192 168 1 2`
2546dst_ip=`ip_to_hex 172 16 2 2`
2547expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000
2548
2549$PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv2/vif1-tx.pcap | trim_zeros > received.packets
2550echo $expected | trim_zeros > expout
2551AT_CHECK([cat received.packets], [0], [expout])
2552
2553# Packet to Expect at alice1
2554src_mac="000000010204"
2555dst_mac="f00000010204"
2556src_ip=`ip_to_hex 192 168 1 2`
2557dst_ip=`ip_to_hex 172 16 1 2`
2558expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000
2559
2560$PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif2-tx.pcap | trim_zeros > received1.packets
2561echo $expected | trim_zeros > expout
2562AT_CHECK([cat received1.packets], [0], [expout])
2563
2564for sim in hv1 hv2; do
2565 as $sim
2566 OVS_APP_EXIT_AND_WAIT([ovn-controller])
2567 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2568 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2569done
2570
2571as ovn-sb
2572OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2573
2574as ovn-nb
2575OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2576
2577as northd
2578OVS_APP_EXIT_AND_WAIT([ovn-northd])
2579
2580as main
2581OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2582OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2583
2584AT_CLEANUP
5412db30 2585
0ee8aaf6
RR
2586AT_SETUP([ovn -- send gratuitous arp on localnet])
2587AT_KEYWORDS([ovn])
2588ovn_start
ea46a4e9 2589ovn-nbctl ls-add lsw0
0ee8aaf6
RR
2590net_add n1
2591sim_add hv
2592as hv
2593ovs-vsctl \
2594 -- add-br br-phys \
2595 -- add-br br-eth0
2596
2597ovn_attach n1 br-phys 192.168.0.1
2598
2599AT_CHECK([ovs-vsctl set Open_vSwitch . external-ids:ovn-bridge-mappings=physnet1:br-eth0])
2600AT_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])
2601
2602# Create a vif.
31ed1192
JP
2603AT_CHECK([ovn-nbctl lsp-add lsw0 localvif1])
2604AT_CHECK([ovn-nbctl lsp-set-addresses localvif1 "f0:00:00:00:00:01 192.168.1.2"])
2605AT_CHECK([ovn-nbctl lsp-set-port-security localvif1 "f0:00:00:00:00:01"])
0ee8aaf6
RR
2606
2607# Create a localnet port.
31ed1192
JP
2608AT_CHECK([ovn-nbctl lsp-add lsw0 ln_port])
2609AT_CHECK([ovn-nbctl lsp-set-addresses ln_port unknown])
2610AT_CHECK([ovn-nbctl lsp-set-type ln_port localnet])
2611AT_CHECK([ovn-nbctl lsp-set-options ln_port network_name=physnet1])
0ee8aaf6
RR
2612
2613AT_CHECK([ovs-vsctl add-port br-int localvif1 -- set Interface localvif1 external_ids:iface-id=localvif1])
2614
2615# Wait for packet to be received.
2616OVS_WAIT_UNTIL([test `wc -c < "hv/snoopvif-tx.pcap"` -ge 50])
2617trim_zeros() {
2618 sed 's/\(00\)\{1,\}$//'
2619}
2620$PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv/snoopvif-tx.pcap | trim_zeros > packets
2621expected="fffffffffffff0000000000108060001080006040001f00000000001c0a80102000000000000c0a80102"
2622echo $expected > expout
2623AT_CHECK([sort packets], [0], [expout])
2624cat packets
2625
2626# Delete the localnet ports.
2627AT_CHECK([ovs-vsctl del-port localvif1])
31ed1192 2628AT_CHECK([ovn-nbctl lsp-del ln_port])
0ee8aaf6
RR
2629
2630as hv
2631OVS_APP_EXIT_AND_WAIT([ovn-controller])
2632OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2633OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2634
2635as ovn-sb
2636OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2637
2638as ovn-nb
2639OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2640
2641as northd
2642OVS_APP_EXIT_AND_WAIT([ovn-northd])
2643
2644as main
2645OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2646OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2647
2648AT_CLEANUP
75cf9d2b
GS
2649
2650AT_SETUP([ovn -- 2 HVs, 3 LRs connected via LS, static routes])
2651AT_KEYWORDS([ovnstaticroutes])
2652AT_SKIP_IF([test $HAVE_PYTHON = no])
2653ovn_start
2654
2655# Logical network:
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)
2659# connected to it.
2660
fa2a27b2
JP
2661ovn-nbctl lr-add R1
2662ovn-nbctl lr-add R2
2663ovn-nbctl lr-add R3
75cf9d2b 2664
ea46a4e9
JP
2665ovn-nbctl ls-add foo
2666ovn-nbctl ls-add alice
2667ovn-nbctl ls-add bob
2668ovn-nbctl ls-add join
75cf9d2b
GS
2669
2670# Connect foo to R1
31114af7 2671ovn-nbctl lrp-add R1 foo 00:00:01:01:02:03 192.168.1.1/24
31ed1192 2672ovn-nbctl lsp-add foo rp-foo -- set Logical_Switch_Port rp-foo type=router \
31114af7 2673 options:router-port=foo addresses=\"00:00:01:01:02:03\"
75cf9d2b
GS
2674
2675# Connect alice to R2
31114af7 2676ovn-nbctl lrp-add R2 alice 00:00:02:01:02:03 172.16.1.1/24
31ed1192 2677ovn-nbctl lsp-add alice rp-alice -- set Logical_Switch_Port rp-alice \
80f408f4 2678 type=router options:router-port=alice addresses=\"00:00:02:01:02:03\"
75cf9d2b
GS
2679
2680# Connect bob to R3
31114af7 2681ovn-nbctl lrp-add R3 bob 00:00:03:01:02:03 10.32.1.1/24
31ed1192 2682ovn-nbctl lsp-add bob rp-bob -- set Logical_Switch_Port rp-bob \
80f408f4 2683 type=router options:router-port=bob addresses=\"00:00:03:01:02:03\"
75cf9d2b
GS
2684
2685# Connect R1 to join
31114af7 2686ovn-nbctl lrp-add R1 R1_join 00:00:04:01:02:03 20.0.0.1/24
31ed1192 2687ovn-nbctl lsp-add join r1-join -- set Logical_Switch_Port r1-join \
80f408f4 2688 type=router options:router-port=R1_join addresses='"00:00:04:01:02:03"'
75cf9d2b
GS
2689
2690# Connect R2 to join
31114af7 2691ovn-nbctl lrp-add R2 R2_join 00:00:04:01:02:04 20.0.0.2/24
31ed1192 2692ovn-nbctl lsp-add join r2-join -- set Logical_Switch_Port r2-join \
80f408f4 2693 type=router options:router-port=R2_join addresses='"00:00:04:01:02:04"'
75cf9d2b
GS
2694
2695# Connect R3 to join
31114af7 2696ovn-nbctl lrp-add R3 R3_join 00:00:04:01:02:05 20.0.0.3/24
31ed1192 2697ovn-nbctl lsp-add join r3-join -- set Logical_Switch_Port r3-join \
80f408f4 2698 type=router options:router-port=R3_join addresses='"00:00:04:01:02:05"'
75cf9d2b
GS
2699
2700#install static routes
e48ccf3c
JP
2701ovn-nbctl lr-route-add R1 172.16.1.0/24 20.0.0.2
2702ovn-nbctl lr-route-add R1 10.32.1.0/24 20.0.0.3
75cf9d2b 2703
e48ccf3c
JP
2704ovn-nbctl lr-route-add R2 192.168.1.0/24 20.0.0.1
2705ovn-nbctl lr-route-add R2 10.32.1.0/24 20.0.0.3
75cf9d2b 2706
e48ccf3c
JP
2707ovn-nbctl lr-route-add R3 192.168.1.0/24 20.0.0.1
2708ovn-nbctl lr-route-add R3 172.16.1.0/24 20.0.0.2
75cf9d2b
GS
2709
2710# Create logical port foo1 in foo
31ed1192
JP
2711ovn-nbctl lsp-add foo foo1 \
2712-- lsp-set-addresses foo1 "f0:00:00:01:02:03 192.168.1.2"
75cf9d2b
GS
2713
2714# Create logical port alice1 in alice
31ed1192
JP
2715ovn-nbctl lsp-add alice alice1 \
2716-- lsp-set-addresses alice1 "f0:00:00:01:02:04 172.16.1.2"
75cf9d2b
GS
2717
2718# Create logical port bob1 in bob
31ed1192
JP
2719ovn-nbctl lsp-add bob bob1 \
2720-- lsp-set-addresses bob1 "f0:00:00:01:02:05 10.32.1.2"
75cf9d2b
GS
2721
2722# Create two hypervisor and create OVS ports corresponding to logical ports.
2723net_add n1
2724
2725sim_add hv1
2726as hv1
2727ovs-vsctl add-br br-phys
2728ovn_attach n1 br-phys 192.168.0.1
2729ovs-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 \
2733 ofport-request=1
2734
2735ovs-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 \
2739 ofport-request=2
2740
2741sim_add hv2
2742as hv2
2743ovs-vsctl add-br br-phys
2744ovn_attach n1 br-phys 192.168.0.2
2745ovs-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 \
2749 ofport-request=1
2750
2751
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).
2755ovn_populate_arp
2756
2757# Allow some time for ovn-northd and ovn-controller to catch up.
2758# XXX This should be more systematic.
2759sleep 1
2760
2761ip_to_hex() {
2762 printf "%02x%02x%02x%02x" "$@"
2763}
2764trim_zeros() {
2765 sed 's/\(00\)\{1,\}$//'
2766}
2767
2768# Send ip packets between foo1 and alice1
2769src_mac="f00000010203"
2770dst_mac="000001010203"
2771src_ip=`ip_to_hex 192 168 1 2`
2772dst_ip=`ip_to_hex 172 16 1 2`
2773packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
2774as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet
2775as hv1 ovs-appctl ofproto/trace br-int in_port=1 $packet
2776
2777# Send ip packets between foo1 and bob1
2778src_mac="f00000010203"
2779dst_mac="000001010203"
2780src_ip=`ip_to_hex 192 168 1 2`
2781dst_ip=`ip_to_hex 10 32 1 2`
2782packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
2783as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet
2784
2785echo "---------NB dump-----"
2786ovn-nbctl show
2787echo "---------------------"
2788ovn-nbctl list logical_router
2789echo "---------------------"
2790ovn-nbctl list logical_router_port
2791echo "---------------------"
2792
2793echo "---------SB dump-----"
2794ovn-sbctl list datapath_binding
2795echo "---------------------"
2796ovn-sbctl list port_binding
2797echo "---------------------"
2798ovn-sbctl dump-flows
2799echo "---------------------"
2800
2801echo "------ hv1 dump ----------"
2802as hv1 ovs-ofctl show br-int
2803as hv1 ovs-ofctl dump-flows br-int
2804echo "------ hv2 dump ----------"
2805as hv2 ovs-ofctl show br-int
2806as hv2 ovs-ofctl dump-flows br-int
2807echo "----------------------------"
2808
2809# Packet to Expect at bob1
2810src_mac="000003010203"
2811dst_mac="f00000010205"
2812src_ip=`ip_to_hex 192 168 1 2`
2813dst_ip=`ip_to_hex 10 32 1 2`
2814expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000
2815
2816$PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv2/vif1-tx.pcap | trim_zeros > received.packets
2817echo $expected | trim_zeros > expout
2818AT_CHECK([cat received.packets], [0], [expout])
2819
2820# Packet to Expect at alice1
2821src_mac="000002010203"
2822dst_mac="f00000010204"
2823src_ip=`ip_to_hex 192 168 1 2`
2824dst_ip=`ip_to_hex 172 16 1 2`
2825expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000
2826
2827$PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif2-tx.pcap | trim_zeros > received1.packets
2828echo $expected | trim_zeros > expout
2829AT_CHECK([cat received1.packets], [0], [expout])
2830
2831for sim in hv1 hv2; do
2832 as $sim
2833 OVS_APP_EXIT_AND_WAIT([ovn-controller])
2834 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2835 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2836done
2837
2838as ovn-sb
2839OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2840
2841as ovn-nb
2842OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2843
2844as northd
2845OVS_APP_EXIT_AND_WAIT([ovn-northd])
2846
2847as main
2848OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2849OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2850
2851AT_CLEANUP
c1645003 2852
c1645003
GS
2853AT_SETUP([ovn -- 2 HVs, 2 LRs connected via LS, gateway router])
2854AT_KEYWORDS([ovngatewayrouter])
2855AT_SKIP_IF([test $HAVE_PYTHON = no])
2856ovn_start
2857
2858# Logical network:
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.
2863
2864
2865
2866# Create two hypervisor and create OVS ports corresponding to logical ports.
2867net_add n1
2868
2869sim_add hv1
2870as hv1
2871ovs-vsctl add-br br-phys
2872ovn_attach n1 br-phys 192.168.0.1
2873ovs-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 \
2877 ofport-request=1
2878
2879
2880sim_add hv2
2881as hv2
2882ovs-vsctl add-br br-phys
2883ovn_attach n1 br-phys 192.168.0.2
2884ovs-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 \
2888 ofport-request=1
2889
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).
2893ovn_populate_arp
2894
2895ovn-nbctl create Logical_Router name=R1
2896ovn-nbctl create Logical_Router name=R2 options:chassis="hv2"
2897
ea46a4e9
JP
2898ovn-nbctl ls-add foo
2899ovn-nbctl ls-add alice
2900ovn-nbctl ls-add join
c1645003
GS
2901
2902# Connect foo to R1
31114af7 2903ovn-nbctl lrp-add R1 foo 00:00:01:01:02:03 192.168.1.1/24
31ed1192 2904ovn-nbctl lsp-add foo rp-foo -- set Logical_Switch_Port rp-foo \
80f408f4 2905 type=router options:router-port=foo addresses=\"00:00:01:01:02:03\"
c1645003
GS
2906
2907# Connect alice to R2
31114af7 2908ovn-nbctl lrp-add R2 alice 00:00:02:01:02:03 172.16.1.1/24
31ed1192 2909ovn-nbctl lsp-add alice rp-alice -- set Logical_Switch_Port rp-alice \
80f408f4 2910 type=router options:router-port=alice addresses=\"00:00:02:01:02:03\"
c1645003
GS
2911
2912# Connect R1 to join
31114af7 2913ovn-nbctl lrp-add R1 R1_join 00:00:04:01:02:03 20.0.0.1/24
31ed1192 2914ovn-nbctl lsp-add join r1-join -- set Logical_Switch_Port r1-join \
80f408f4 2915 type=router options:router-port=R1_join addresses='"00:00:04:01:02:03"'
c1645003
GS
2916
2917# Connect R2 to join
31114af7 2918ovn-nbctl lrp-add R2 R2_join 00:00:04:01:02:04 20.0.0.2/24
31ed1192 2919ovn-nbctl lsp-add join r2-join -- set Logical_Switch_Port r2-join \
80f408f4 2920 type=router options:router-port=R2_join addresses='"00:00:04:01:02:04"'
c1645003
GS
2921
2922
2923#install static routes
2924ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \
2925ip_prefix=172.16.1.0/24 nexthop=20.0.0.2 -- add Logical_Router \
2926R1 static_routes @lrt
2927
2928ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \
2929ip_prefix=192.168.1.0/24 nexthop=20.0.0.1 -- add Logical_Router \
2930R2 static_routes @lrt
2931
2932# Create logical port foo1 in foo
31ed1192
JP
2933ovn-nbctl lsp-add foo foo1 \
2934-- lsp-set-addresses foo1 "f0:00:00:01:02:03 192.168.1.2"
c1645003
GS
2935
2936# Create logical port alice1 in alice
31ed1192
JP
2937ovn-nbctl lsp-add alice alice1 \
2938-- lsp-set-addresses alice1 "f0:00:00:01:02:04 172.16.1.2"
c1645003
GS
2939
2940
2941# Allow some time for ovn-northd and ovn-controller to catch up.
2942# XXX This should be more systematic.
2943sleep 2
2944
2945ip_to_hex() {
2946 printf "%02x%02x%02x%02x" "$@"
2947}
2948trim_zeros() {
2949 sed 's/\(00\)\{1,\}$//'
2950}
2951
2952# Send ip packets between foo1 and alice1
2953src_mac="f00000010203"
2954dst_mac="000001010203"
2955src_ip=`ip_to_hex 192 168 1 2`
2956dst_ip=`ip_to_hex 172 16 1 2`
2957packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
2958
2959echo "---------NB dump-----"
2960ovn-nbctl show
2961echo "---------------------"
2962ovn-nbctl list logical_router
2963echo "---------------------"
2964ovn-nbctl list logical_router_port
2965echo "---------------------"
2966
2967echo "---------SB dump-----"
2968ovn-sbctl list datapath_binding
2969echo "---------------------"
2970ovn-sbctl list port_binding
2971echo "---------------------"
2972ovn-sbctl dump-flows
2973echo "---------------------"
2974ovn-sbctl list chassis
2975ovn-sbctl list encap
2976echo "---------------------"
2977
2978echo "------ hv1 dump ----------"
2979as hv1 ovs-ofctl show br-int
2980as hv1 ovs-ofctl dump-flows br-int
2981echo "------ hv2 dump ----------"
2982as hv2 ovs-ofctl show br-int
2983as hv2 ovs-ofctl dump-flows br-int
2984echo "----------------------------"
2985
2986# Packet to Expect at alice1
2987src_mac="000002010203"
2988dst_mac="f00000010204"
2989src_ip=`ip_to_hex 192 168 1 2`
2990dst_ip=`ip_to_hex 172 16 1 2`
2991expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000
2992
2993
2994as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet
2995as hv1 ovs-appctl ofproto/trace br-int in_port=1 $packet
2996
2997$PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv2/vif1-tx.pcap | trim_zeros > received1.packets
2998echo $expected | trim_zeros > expout
2999AT_CHECK([cat received1.packets], [0], [expout])
3000
3001for sim in hv1 hv2; do
3002 as $sim
3003 OVS_APP_EXIT_AND_WAIT([ovn-controller])
3004 OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
3005 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3006done
3007
3008as ovn-sb
3009OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3010
3011as ovn-nb
3012OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3013
3014as northd
3015OVS_APP_EXIT_AND_WAIT([ovn-northd])
3016
3017as main
3018OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
3019OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3020
3021AT_CLEANUP
bb3c4568
FF
3022
3023AT_SETUP([ovn -- icmp_reply: 1 HVs, 2 LSs, 1 lport/LS, 1 LR])
3024AT_KEYWORDS([router-icmp-reply])
3025AT_SKIP_IF([test $HAVE_PYTHON = no])
3026ovn_start
3027
3028# Logical network:
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.
3031
fa2a27b2 3032ovn-nbctl lr-add R1
bb3c4568 3033
ea46a4e9
JP
3034ovn-nbctl ls-add ls1
3035ovn-nbctl ls-add ls2
bb3c4568
FF
3036
3037# Connect ls1 to R1
31114af7 3038ovn-nbctl lrp-add R1 ls1 00:00:00:01:02:f1 192.168.1.1/24
31ed1192 3039ovn-nbctl lsp-add ls1 rp-ls1 -- set Logical_Switch_Port rp-ls1 \
80f408f4 3040 type=router options:router-port=ls1 addresses=\"00:00:00:01:02:f1\"
bb3c4568
FF
3041
3042# Connect ls2 to R1
31114af7 3043ovn-nbctl lrp-add R1 ls2 00:00:00:01:02:f2 172.16.1.1/24
31ed1192 3044ovn-nbctl lsp-add ls2 rp-ls2 -- set Logical_Switch_Port rp-ls2 \
80f408f4 3045 type=router options:router-port=ls2 addresses=\"00:00:00:01:02:f2\"
bb3c4568
FF
3046
3047# Create logical port ls1-lp1 in ls1
31ed1192
JP
3048ovn-nbctl lsp-add ls1 ls1-lp1 \
3049-- lsp-set-addresses ls1-lp1 "00:00:00:01:02:03 192.168.1.2"
bb3c4568
FF
3050
3051# Create logical port ls2-lp1 in ls2
31ed1192
JP
3052ovn-nbctl lsp-add ls2 ls2-lp1 \
3053-- lsp-set-addresses ls2-lp1 "00:00:00:01:02:04 172.16.1.2"
bb3c4568
FF
3054
3055# Create one hypervisor and create OVS ports corresponding to logical ports.
3056net_add n1
3057
3058sim_add hv1
3059as hv1
3060ovs-vsctl add-br br-phys
3061ovn_attach n1 br-phys 192.168.0.1
3062ovs-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 \
3066 ofport-request=1
3067
3068ovs-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 \
3072 ofport-request=1
3073
3074
3075# Allow some time for ovn-northd and ovn-controller to catch up.
3076# XXX This should be more systematic.
3077sleep 1
3078
3079
3080ip_to_hex() {
3081 printf "%02x%02x%02x%02x" "$@"
3082}
3083trim_zeros() {
3084 sed 's/\(00\)\{1,\}$//'
3085}
3086for i in 1 2; do
3087 : > vif$i.expected
3088done
3089# test_ipv4_icmp_request INPORT ETH_SRC ETH_DST IPV4_SRC IPV4_DST IP_CHKSUM ICMP_CHKSUM [EXP_IP_CHKSUM EXP_ICMP_CHKSUM]
3090#
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.
3099#
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.
3105test_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
3109 shift; shift
3110
3111 # Use ttl to exercise section 4.2.2.9 of RFC1812
3112 local ip_ttl=01
3113 local icmp_id=5fbf
3114 local icmp_seq=0001
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}
3119
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
3129 fi
3130}
3131
3132# Send ping packet to router's ip addresses, from each of the 2 logical ports.
3133rtr_l1_ip=$(ip_to_hex 192 168 1 1)
3134rtr_l2_ip=$(ip_to_hex 172 16 1 1)
3135l1_ip=$(ip_to_hex 192 168 1 2)
3136l2_ip=$(ip_to_hex 172 16 1 2)
3137
3138# Ping router ip address that is on same subnet as the logical port
3139test_ipv4_icmp_request 1 000000010203 0000000102f1 $l1_ip $rtr_l1_ip 0000 8510 02ff 8d10
3140test_ipv4_icmp_request 2 000000010204 0000000102f2 $l2_ip $rtr_l2_ip 0000 8510 02ff 8d10
3141
3142# Ping router ip address that is on the other side of the logical ports
3143test_ipv4_icmp_request 1 000000010203 0000000102f1 $l1_ip $rtr_l2_ip 0000 8510 02ff 8d10
3144test_ipv4_icmp_request 2 000000010204 0000000102f2 $l2_ip $rtr_l1_ip 0000 8510 02ff 8d10
3145
3146echo "---------NB dump-----"
3147ovn-nbctl show
3148echo "---------------------"
3149ovn-nbctl list logical_router
3150echo "---------------------"
3151ovn-nbctl list logical_router_port
3152echo "---------------------"
3153
3154echo "---------SB dump-----"
3155ovn-sbctl list datapath_binding
3156echo "---------------------"
3157ovn-sbctl list logical_flow
3158echo "---------------------"
3159
3160echo "------ hv1 dump ----------"
3161as hv1 ovs-ofctl dump-flows br-int
3162
3163# Now check the packets actually received against the ones expected.
3164for inport in 1 2; do
3165 file=hv1/vif${inport}-tx.pcap
3166 echo $file
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])
3170done
3171
3172as hv1
3173OVS_APP_EXIT_AND_WAIT([ovn-controller])
3174OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
3175OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3176
3177as ovn-sb
3178OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3179
3180as ovn-nb
3181OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3182
3183as northd
3184OVS_APP_EXIT_AND_WAIT([ovn-northd])
3185
3186as main
3187OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
3188OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3189
3190AT_CLEANUP
94f79fcb
RB
3191
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.
3195AT_SETUP([ovn -- port state up and down])
3196AT_KEYWORDS([ovn])
3197ovn_start
3198
3199ovn-nbctl ls-add ls1
3200ovn-nbctl lsp-add ls1 lp1
3201ovn-nbctl lsp-set-addresses lp1 unknown
3202
3203net_add n1
3204sim_add hv1
3205as hv1 ovs-vsctl add-br br-phys
3206as hv1 ovn_attach n1 br-phys 192.168.0.1
3207
3208as hv1 ovs-vsctl add-port br-int vif1 -- set Interface vif1 external-ids:iface-id=lp1
3209OVS_WAIT_UNTIL([test x`ovn-nbctl lsp-get-up lp1` = xup])
3210
3211as hv1 ovs-vsctl del-port br-int vif1
3212OVS_WAIT_UNTIL([test x`ovn-nbctl lsp-get-up lp1` = xdown])
3213
3214as hv1
3215OVS_APP_EXIT_AND_WAIT([ovn-controller])
3216OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
3217OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3218
3219as ovn-sb
3220OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3221
3222as ovn-nb
3223OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3224
3225as northd
3226OVS_APP_EXIT_AND_WAIT([ovn-northd])
3227
3228as main
3229OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
3230OVS_APP_EXIT_AND_WAIT([ovsdb-server])
3231AT_CLEANUP