]> git.proxmox.com Git - mirror_ovs.git/blame - tests/ovn.at
rhel/openvswitch.spec: Add SELinux policy.
[mirror_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
2c5cbb15
RB
11$foo $bar $baz $quuxquuxquux $_abcd_ $a.b.c.d $a123_.456
12$1 => error("`$' must be followed by a valid identifier.") 1
13
10b1662b
BP
14a/*b*/c => a c
15a//b c => a
16a/**/b => a b
17a/*/b => a error("`/*' without matching `*/'.")
18a/*/**/b => a b
19a/b => a error("`/' is only valid as part of `//' or `/*'.") b
20
210 1 12345 18446744073709551615
2218446744073709551616 => error("Decimal constants must be less than 2**64.")
239999999999999999999999 => error("Decimal constants must be less than 2**64.")
2401 => error("Decimal constants must not have leading zeros.")
25
260/0
270/1
281/0 => error("Value contains unmasked 1-bits.")
291/1
30128/384
311/3
321/ => error("Integer constant expected.")
33
341/0x123 => error("Value and mask have incompatible formats.")
35
360x1234
370x01234 => 0x1234
380x0 => 0
390x000 => 0
400xfedcba9876543210
410XFEDCBA9876543210 => 0xfedcba9876543210
420xfedcba9876543210fedcba9876543210
10b1662b
BP
430x0000fedcba9876543210fedcba9876543210 => 0xfedcba9876543210fedcba9876543210
440x => error("Hex digits expected following 0x.")
450X => error("Hex digits expected following 0X.")
460x0/0x0 => 0/0
470x0/0x1 => 0/0x1
480x1/0x0 => error("Value contains unmasked 1-bits.")
490xffff/0x1ffff
500x. => error("Invalid syntax in hexadecimal constant.")
51
52192.168.128.1 1.2.3.4 255.255.255.255 0.0.0.0
53256.1.2.3 => error("Invalid numeric constant.")
54192.168.0.0/16
55192.168.0.0/255.255.0.0 => 192.168.0.0/16
56192.168.0.0/255.255.255.0 => 192.168.0.0/24
57192.168.0.0/255.255.0.255
58192.168.0.0/255.0.0.0 => error("Value contains unmasked 1-bits.")
59192.168.0.0/32
60192.168.0.0/255.255.255.255 => 192.168.0.0/32
52c0fc39 611.2.3.4:5 => 1.2.3.4 : 5
10b1662b
BP
62
63::
64::1
65ff00::1234 => ff00::1234
662001:db8:85a3::8a2e:370:7334
672001:db8:85a3:0:0:8a2e:370:7334 => 2001:db8:85a3::8a2e:370:7334
682001:0db8:85a3:0000:0000:8a2e:0370:7334 => 2001:db8:85a3::8a2e:370:7334
69::ffff:192.0.2.128
70::ffff:c000:0280 => ::ffff:192.0.2.128
71::1/::1
72::1/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff => ::1/128
73::1/128
74ff00::/8
75ff00::/ff00:: => ff00::/8
76
7701:23:45:67:ab:cd
7801:23:45:67:AB:CD => 01:23:45:67:ab:cd
79fe:dc:ba:98:76:54
80FE:DC:ba:98:76:54 => fe:dc:ba:98:76:54
8101:00:00:00:00:00/01:00:00:00:00:00
82ff:ff:ff:ff:ff:ff/ff:ff:ff:ff:ff:ff
83fe:ff:ff:ff:ff:ff/ff:ff:ff:ff:ff:ff
84ff:ff:ff:ff:ff:ff/fe:ff:ff:ff:ff:ff => error("Value contains unmasked 1-bits.")
85fe:x => error("Invalid numeric constant.")
8600:01:02:03:04:x => error("Invalid numeric constant.")
87
a20c96c6 88# Test that operators are tokenized as expected, even without white space.
52c0fc39 89(){}[[]]==!=<<=>>=!&&||..,;=<->--: => ( ) { } [[ ]] == != < <= > >= ! && || .. , ; = <-> -- :
10b1662b
BP
90& => error("`&' is only valid as part of `&&'.")
91| => error("`|' is only valid as part of `||'.")
56091efe 92- => error("`-' is only valid as part of `--'.")
10b1662b
BP
93
94^ => error("Invalid character `^' in input.")
95])
96AT_CAPTURE_FILE([input.txt])
97sed 's/ =>.*//' test-cases.txt > input.txt
98sed 's/.* => //' test-cases.txt > expout
99AT_CHECK([ovstest test-ovn lex < input.txt], [0], [expout])
100AT_CLEANUP
e0840f11
BP
101
102AT_SETUP([ovn -- expression parser])
103dnl For lines without =>, input and expected output are identical.
104dnl For lines with =>, input precedes => and expected output follows =>.
105AT_DATA([test-cases.txt], [[
106eth.type == 0x800
107eth.type==0x800 => eth.type == 0x800
108eth.type[0..15] == 0x800 => eth.type == 0x800
109
110vlan.present
111vlan.present == 1 => vlan.present
112!(vlan.present == 0) => vlan.present
113!(vlan.present != 1) => vlan.present
114!vlan.present
115vlan.present == 0 => !vlan.present
116vlan.present != 1 => !vlan.present
117!(vlan.present == 1) => !vlan.present
118!(vlan.present != 0) => !vlan.present
119
120eth.dst[0]
121eth.dst[0] == 1 => eth.dst[0]
122eth.dst[0] != 0 => eth.dst[0]
123!(eth.dst[0] == 0) => eth.dst[0]
124!(eth.dst[0] != 1) => eth.dst[0]
125
126!eth.dst[0]
127eth.dst[0] == 0 => !eth.dst[0]
128eth.dst[0] != 1 => !eth.dst[0]
129!(eth.dst[0] == 1) => !eth.dst[0]
130!(eth.dst[0] != 0) => !eth.dst[0]
131
132vlan.tci[12..15] == 0x3
133vlan.tci == 0x3000/0xf000 => vlan.tci[12..15] == 0x3
134vlan.tci[12..15] != 0x3
135vlan.tci != 0x3000/0xf000 => vlan.tci[12..15] != 0x3
136
137!vlan.pcp => vlan.pcp == 0
138!(vlan.pcp) => vlan.pcp == 0
139vlan.pcp == 0x4
140vlan.pcp != 0x4
141vlan.pcp > 0x4
142vlan.pcp >= 0x4
143vlan.pcp < 0x4
144vlan.pcp <= 0x4
145!(vlan.pcp != 0x4) => vlan.pcp == 0x4
146!(vlan.pcp == 0x4) => vlan.pcp != 0x4
147!(vlan.pcp <= 0x4) => vlan.pcp > 0x4
148!(vlan.pcp < 0x4) => vlan.pcp >= 0x4
149!(vlan.pcp >= 0x4) => vlan.pcp < 0x4
150!(vlan.pcp > 0x4) => vlan.pcp <= 0x4
1510x4 == vlan.pcp => vlan.pcp == 0x4
1520x4 != vlan.pcp => vlan.pcp != 0x4
1530x4 < vlan.pcp => vlan.pcp > 0x4
1540x4 <= vlan.pcp => vlan.pcp >= 0x4
1550x4 > vlan.pcp => vlan.pcp < 0x4
1560x4 >= vlan.pcp => vlan.pcp <= 0x4
157!(0x4 != vlan.pcp) => vlan.pcp == 0x4
158!(0x4 == vlan.pcp) => vlan.pcp != 0x4
159!(0x4 >= vlan.pcp) => vlan.pcp > 0x4
160!(0x4 > vlan.pcp) => vlan.pcp >= 0x4
161!(0x4 <= vlan.pcp) => vlan.pcp < 0x4
162!(0x4 < vlan.pcp) => vlan.pcp <= 0x4
163
1641 < vlan.pcp < 4 => vlan.pcp > 0x1 && vlan.pcp < 0x4
1651 <= vlan.pcp <= 4 => vlan.pcp >= 0x1 && vlan.pcp <= 0x4
1661 < vlan.pcp <= 4 => vlan.pcp > 0x1 && vlan.pcp <= 0x4
1671 <= vlan.pcp < 4 => vlan.pcp >= 0x1 && vlan.pcp < 0x4
1681 <= vlan.pcp <= 4 => vlan.pcp >= 0x1 && vlan.pcp <= 0x4
1694 > vlan.pcp > 1 => vlan.pcp < 0x4 && vlan.pcp > 0x1
1704 >= vlan.pcp > 1 => vlan.pcp <= 0x4 && vlan.pcp > 0x1
1714 > vlan.pcp >= 1 => vlan.pcp < 0x4 && vlan.pcp >= 0x1
1724 >= vlan.pcp >= 1 => vlan.pcp <= 0x4 && vlan.pcp >= 0x1
173!(1 < vlan.pcp < 4) => vlan.pcp <= 0x1 || vlan.pcp >= 0x4
174!(1 <= vlan.pcp <= 4) => vlan.pcp < 0x1 || vlan.pcp > 0x4
175!(1 < vlan.pcp <= 4) => vlan.pcp <= 0x1 || vlan.pcp > 0x4
176!(1 <= vlan.pcp < 4) => vlan.pcp < 0x1 || vlan.pcp >= 0x4
177!(1 <= vlan.pcp <= 4) => vlan.pcp < 0x1 || vlan.pcp > 0x4
178!(4 > vlan.pcp > 1) => vlan.pcp >= 0x4 || vlan.pcp <= 0x1
179!(4 >= vlan.pcp > 1) => vlan.pcp > 0x4 || vlan.pcp <= 0x1
180!(4 > vlan.pcp >= 1) => vlan.pcp >= 0x4 || vlan.pcp < 0x1
181!(4 >= vlan.pcp >= 1) => vlan.pcp > 0x4 || vlan.pcp < 0x1
182
183vlan.pcp == {1, 2, 3, 4} => vlan.pcp == 0x1 || vlan.pcp == 0x2 || vlan.pcp == 0x3 || vlan.pcp == 0x4
184vlan.pcp == 1 || ((vlan.pcp == 2 || vlan.pcp == 3) || vlan.pcp == 4) => vlan.pcp == 0x1 || vlan.pcp == 0x2 || vlan.pcp == 0x3 || vlan.pcp == 0x4
185
186vlan.pcp != {1, 2, 3, 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
189vlan.pcp == 1 && !((vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && (vlan.pcp != 0x2 || vlan.pcp != 0x3 || vlan.pcp != 0x4)
190vlan.pcp == 1 && (!(vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && (vlan.pcp != 0x2 || vlan.pcp != 0x3) && vlan.pcp == 0x4
191vlan.pcp == 1 && !(!(vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && ((vlan.pcp == 0x2 && vlan.pcp == 0x3) || vlan.pcp != 0x4)
192
193ip4.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
194ip6.src == ::1 => ip6.src == 0x1
195
196ip4.src == 1.2.3.4 => ip4.src == 0x1020304
197ip4.src == ::1.2.3.4/::ffff:ffff => ip4.src == 0x1020304
198ip6.src == ::1 => ip6.src == 0x1
199
2001
2010
202!1 => 0
203!0 => 1
204
205inport == "eth0"
206!(inport != "eth0") => inport == "eth0"
207
3b7cb7e1
BP
208ip4.src == "eth0" => Integer field ip4.src is not compatible with string constant.
209inport == 1 => String field inport is not compatible with integer constant.
e0840f11
BP
210
211ip4.src > {1, 2, 3} => Only == and != operators may be used with value sets.
212eth.type > 0x800 => Only == and != operators may be used with nominal field eth.type.
213vlan.present > 0 => Only == and != operators may be used with Boolean field vlan.present.
214
215inport != "eth0" => Nominal field inport may only be tested for equality (taking enclosing `!' operators into account).
216!(inport == "eth0") => Nominal field inport may only be tested for equality (taking enclosing `!' operators into account).
217eth.type != 0x800 => Nominal field eth.type may only be tested for equality (taking enclosing `!' operators into account).
218!(eth.type == 0x800) => Nominal field eth.type may only be tested for equality (taking enclosing `!' operators into account).
219
220123 == 123 => Syntax error at `123' expecting field name.
221
2c5cbb15
RB
222$name => Syntax error at `$name' expecting address set name.
223
e0840f11
BP
224123 == xyzzy => Syntax error at `xyzzy' expecting field name.
225xyzzy == 1 => Syntax error at `xyzzy' expecting field name.
226
227inport[1] == 1 => Cannot select subfield of string field inport.
228
229eth.type[] == 1 => Syntax error at `@:>@' expecting small integer.
230eth.type[::1] == 1 => Syntax error at `::1' expecting small integer.
231eth.type[18446744073709551615] == 1 => Syntax error at `18446744073709551615' expecting small integer.
232
233eth.type[5!] => Syntax error at `!' expecting `@:>@'.
234
235eth.type[5..1] => Invalid bit range 5 to 1.
236
237eth.type[12..16] => Cannot select bits 12 to 16 of 16-bit field eth.type.
238
239eth.type[10] == 1 => Cannot select subfield of nominal field eth.type.
240
241eth.type => Explicit `!= 0' is required for inequality test of multibit field against 0.
242
243!(!(vlan.pcp)) => Explicit `!= 0' is required for inequality test of multibit field against 0.
244
245123 => Syntax error at end of input expecting relational operator.
246
247123 x => Syntax error at `x' expecting relational operator.
248
249{1, "eth0"} => Syntax error at `"eth0"' expecting integer.
250
251eth.type == xyzzy => Syntax error at `xyzzy' expecting constant.
252
253(1 x) => Syntax error at `x' expecting `)'.
254
255!0x800 != eth.type => Missing parentheses around operand of !.
256
257eth.type == 0x800 || eth.type == 0x86dd && ip.proto == 17 => && and || must be parenthesized when used together.
258
259eth.dst == {} => Syntax error at `}' expecting constant.
260
261eth.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).
262
3b7cb7e1 263ip4.src == ::1 => 128-bit constant is not compatible with 32-bit field ip4.src.
e0840f11
BP
264
2651 == 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
266
267eth.dst[40] x => Extra tokens at end of input.
ea382567
RB
268
269ip4.src == {1.2.3.4, $set1, $unknownset} => Syntax error at `$unknownset' expecting address set name.
270eth.src == {$set3, badmac, 00:00:00:00:00:01} => Syntax error at `badmac' expecting constant.
e0840f11
BP
271]])
272sed 's/ =>.*//' test-cases.txt > input.txt
273sed 's/.* => //' test-cases.txt > expout
274AT_CHECK([ovstest test-ovn parse-expr < input.txt], [0], [expout])
275AT_CLEANUP
276
277AT_SETUP([ovn -- expression annotation])
278dnl Input precedes =>, expected output follows =>.
279AT_DATA([test-cases.txt], [[
280ip4.src == 1.2.3.4 => ip4.src == 0x1020304 && eth.type == 0x800
281ip4.src != 1.2.3.4 => ip4.src != 0x1020304 && eth.type == 0x800
282ip.proto == 123 => ip.proto == 0x7b && (eth.type == 0x800 || eth.type == 0x86dd)
283ip.proto == {123, 234} => (ip.proto == 0x7b && (eth.type == 0x800 || eth.type == 0x86dd)) || (ip.proto == 0xea && (eth.type == 0x800 || eth.type == 0x86dd))
284ip4.src == 1.2.3.4 && ip4.dst == 5.6.7.8 => ip4.src == 0x1020304 && eth.type == 0x800 && ip4.dst == 0x5060708 && eth.type == 0x800
285
286ip => eth.type == 0x800 || eth.type == 0x86dd
287ip == 1 => eth.type == 0x800 || eth.type == 0x86dd
288ip[0] == 1 => eth.type == 0x800 || eth.type == 0x86dd
289ip > 0 => Only == and != operators may be used with nominal field ip.
290!ip => Nominal predicate ip may only be tested positively, e.g. `ip' or `ip == 1' but not `!ip' or `ip == 0'.
291ip == 0 => Nominal predicate ip may only be tested positively, e.g. `ip' or `ip == 1' but not `!ip' or `ip == 0'.
292
293vlan.present => vlan.tci[12]
294!vlan.present => !vlan.tci[12]
295
296!vlan.pcp => vlan.tci[13..15] == 0 && vlan.tci[12]
297vlan.pcp == 1 && vlan.vid == 2 => vlan.tci[13..15] == 0x1 && vlan.tci[12] && vlan.tci[0..11] == 0x2 && vlan.tci[12]
298!reg0 && !reg1 && !reg2 && !reg3 => xreg0[32..63] == 0 && xreg0[0..31] == 0 && xreg1[32..63] == 0 && xreg1[0..31] == 0
299
300ip.first_frag => ip.frag[0] && (eth.type == 0x800 || eth.type == 0x86dd) && (!ip.frag[1] || (eth.type != 0x800 && eth.type != 0x86dd))
301!ip.first_frag => !ip.frag[0] || (eth.type != 0x800 && eth.type != 0x86dd) || (ip.frag[1] && (eth.type == 0x800 || eth.type == 0x86dd))
302ip.later_frag => ip.frag[1] && (eth.type == 0x800 || eth.type == 0x86dd)
303
304bad_prereq != 0 => Error parsing expression `xyzzy' encountered as prerequisite or predicate of initial expression: Syntax error at `xyzzy' expecting field name.
305self_recurse != 0 => Error parsing expression `self_recurse != 0' encountered as prerequisite or predicate of initial expression: Recursive expansion of symbol `self_recurse'.
306mutual_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'.
307mutual_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'.
308]])
309sed 's/ =>.*//' test-cases.txt > input.txt
310sed 's/.* => //' test-cases.txt > expout
311AT_CHECK([ovstest test-ovn annotate-expr < input.txt], [0], [expout])
312AT_CLEANUP
313
9d4aecca 314AT_SETUP([ovn -- 1-term expression conversion])
e0840f11 315AT_CHECK([ovstest test-ovn exhaustive --operation=convert 1], [0],
9d4aecca 316 [Tested converting all 1-terminal expressions with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 2 string vars.
e0840f11
BP
317])
318AT_CLEANUP
319
9d4aecca 320AT_SETUP([ovn -- 2-term expression conversion])
e0840f11 321AT_CHECK([ovstest test-ovn exhaustive --operation=convert 2], [0],
9d4aecca 322 [Tested converting 570 expressions of 2 terminals with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 2 string vars.
e0840f11
BP
323])
324AT_CLEANUP
325
9d4aecca 326AT_SETUP([ovn -- 3-term expression conversion])
e0840f11 327AT_CHECK([ovstest test-ovn exhaustive --operation=convert --bits=2 3], [0],
9d4aecca 328 [Tested converting 62418 expressions of 3 terminals with 2 numeric vars (each 2 bits) in terms of operators == != < <= > >= and 2 string vars.
e0840f11
BP
329])
330AT_CLEANUP
331
9d4aecca
BP
332AT_SETUP([ovn -- 3-term numeric expression simplification])
333AT_CHECK([ovstest test-ovn exhaustive --operation=simplify --nvars=2 --svars=0 3], [0],
334 [Tested simplifying 477138 expressions of 3 terminals with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >=.
e0840f11
BP
335])
336AT_CLEANUP
337
9d4aecca
BP
338AT_SETUP([ovn -- 4-term string expression simplification])
339AT_CHECK([ovstest test-ovn exhaustive --operation=simplify --nvars=0 --svars=4 4], [0],
340 [Tested simplifying 21978 expressions of 4 terminals with 4 string vars.
e0840f11
BP
341])
342AT_CLEANUP
343
9d4aecca
BP
344AT_SETUP([ovn -- 3-term mixed expression simplification])
345AT_CHECK([ovstest test-ovn exhaustive --operation=simplify --nvars=1 --svars=1 3], [0],
346 [Tested simplifying 124410 expressions of 3 terminals with 1 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 1 string vars.
e0840f11
BP
347])
348AT_CLEANUP
349
9d4aecca
BP
350AT_SETUP([ovn -- 4-term numeric expression normalization])
351AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=3 --svars=0 --bits=1 4], [0],
352 [Tested normalizing 1207162 expressions of 4 terminals with 3 numeric vars (each 1 bits) in terms of operators == != < <= > >=.
e0840f11
BP
353])
354AT_CLEANUP
355
9d4aecca
BP
356AT_SETUP([ovn -- 4-term string expression normalization])
357AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=0 --svars=3 --bits=1 4], [0],
358 [Tested normalizing 11242 expressions of 4 terminals with 3 string vars.
359])
360AT_CLEANUP
361
362AT_SETUP([ovn -- 4-term mixed expression normalization])
363AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=1 --bits=1 --svars=2 4], [0],
364 [Tested normalizing 128282 expressions of 4 terminals with 1 numeric vars (each 1 bits) in terms of operators == != < <= > >= and 2 string vars.
365])
366AT_CLEANUP
367
368AT_SETUP([ovn -- 5-term numeric expression normalization])
369AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=3 --svars=0 --bits=1 --relops='==' 5], [0],
370 [Tested normalizing 368550 expressions of 5 terminals with 3 numeric vars (each 1 bits) in terms of operators ==.
371])
372AT_CLEANUP
373
374AT_SETUP([ovn -- 5-term string expression normalization])
375AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=0 --svars=3 --bits=1 --relops='==' 5], [0],
376 [Tested normalizing 368550 expressions of 5 terminals with 3 string vars.
377])
378AT_CLEANUP
379
380AT_SETUP([ovn -- 5-term mixed expression normalization])
381AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=1 --svars=1 --bits=1 --relops='==' 5], [0],
382 [Tested normalizing 116550 expressions of 5 terminals with 1 numeric vars (each 1 bits) in terms of operators == and 1 string vars.
383])
384AT_CLEANUP
385
386AT_SETUP([ovn -- 4-term numeric expressions to flows])
387AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=2 --svars=0 --bits=2 --relops='==' 4], [0],
388 [Tested converting to flows 128282 expressions of 4 terminals with 2 numeric vars (each 2 bits) in terms of operators ==.
389])
390AT_CLEANUP
391
392AT_SETUP([ovn -- 4-term string expressions to flows])
393AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=0 --svars=4 4], [0],
394 [Tested converting to flows 21978 expressions of 4 terminals with 4 string vars.
395])
396AT_CLEANUP
397
398AT_SETUP([ovn -- 4-term mixed expressions to flows])
399AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=1 --bits=2 --svars=1 --relops='==' 4], [0],
400 [Tested converting to flows 37994 expressions of 4 terminals with 1 numeric vars (each 2 bits) in terms of operators == and 1 string vars.
401])
402AT_CLEANUP
403
404AT_SETUP([ovn -- 3-term numeric expressions to flows])
405AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=3 --svars=0 --bits=3 --relops='==' 3], [0],
406 [Tested converting to flows 38394 expressions of 3 terminals with 3 numeric vars (each 3 bits) in terms of operators ==.
e0840f11
BP
407])
408AT_CLEANUP
f386a8a7
BP
409
410AT_SETUP([ovn -- converting expressions to flows -- string fields])
411expr_to_flow () {
412 echo "$1" | ovstest test-ovn expr-to-flows | sort
413}
cc5e28d8 414AT_CHECK([expr_to_flow 'inport == "eth0"'], [0], [reg14=0x5
f386a8a7 415])
cc5e28d8 416AT_CHECK([expr_to_flow 'inport == "eth1"'], [0], [reg14=0x6
f386a8a7
BP
417])
418AT_CHECK([expr_to_flow 'inport == "eth2"'], [0], [(no flows)
419])
420AT_CHECK([expr_to_flow 'inport == "eth0" && ip'], [0], [dnl
cc5e28d8
JP
421ip,reg14=0x5
422ipv6,reg14=0x5
f386a8a7
BP
423])
424AT_CHECK([expr_to_flow 'inport == "eth1" && ip'], [0], [dnl
cc5e28d8
JP
425ip,reg14=0x6
426ipv6,reg14=0x6
f386a8a7
BP
427])
428AT_CHECK([expr_to_flow 'inport == "eth2" && ip'], [0], [(no flows)
429])
430AT_CHECK([expr_to_flow 'inport == {"eth0", "eth1", "eth2", "LOCAL"}'], [0],
cc5e28d8
JP
431[reg14=0x5
432reg14=0x6
433reg14=0xfffe
f386a8a7
BP
434])
435AT_CHECK([expr_to_flow 'inport == {"eth0", "eth1", "eth2"} && ip'], [0], [dnl
cc5e28d8
JP
436ip,reg14=0x5
437ip,reg14=0x6
438ipv6,reg14=0x5
439ipv6,reg14=0x6
f386a8a7 440])
9d4aecca
BP
441AT_CHECK([expr_to_flow 'inport == "eth0" && inport == "eth1"'], [0], [dnl
442(no flows)
443])
f386a8a7 444AT_CLEANUP
3b7cb7e1 445
2c5cbb15
RB
446AT_SETUP([ovn -- converting expressions to flows -- address sets])
447expr_to_flow () {
448 echo "$1" | ovstest test-ovn expr-to-flows | sort
449}
450AT_CHECK([expr_to_flow 'ip4.src == {10.0.0.1, 10.0.0.2, 10.0.0.3}'], [0], [dnl
451ip,nw_src=10.0.0.1
452ip,nw_src=10.0.0.2
453ip,nw_src=10.0.0.3
454])
455AT_CHECK([expr_to_flow 'ip4.src == $set1'], [0], [dnl
456ip,nw_src=10.0.0.1
457ip,nw_src=10.0.0.2
458ip,nw_src=10.0.0.3
459])
460AT_CHECK([expr_to_flow 'ip4.src == {1.2.3.4, $set1}'], [0], [dnl
461ip,nw_src=1.2.3.4
462ip,nw_src=10.0.0.1
463ip,nw_src=10.0.0.2
464ip,nw_src=10.0.0.3
465])
466AT_CHECK([expr_to_flow 'ip4.src == {1.2.0.0/20, 5.5.5.0/24, $set1}'], [0], [dnl
467ip,nw_src=1.2.0.0/20
468ip,nw_src=10.0.0.1
469ip,nw_src=10.0.0.2
470ip,nw_src=10.0.0.3
471ip,nw_src=5.5.5.0/24
472])
473AT_CHECK([expr_to_flow 'ip6.src == {::1, ::2, ::3}'], [0], [dnl
474ipv6,ipv6_src=::1
475ipv6,ipv6_src=::2
476ipv6,ipv6_src=::3
477])
478AT_CHECK([expr_to_flow 'ip6.src == {::1, $set2, ::4}'], [0], [dnl
479ipv6,ipv6_src=::1
480ipv6,ipv6_src=::2
481ipv6,ipv6_src=::3
482ipv6,ipv6_src=::4
483])
484AT_CHECK([expr_to_flow 'eth.src == {00:00:00:00:00:01, 00:00:00:00:00:02, 00:00:00:00:00:03}'], [0], [dnl
485dl_src=00:00:00:00:00:01
486dl_src=00:00:00:00:00:02
487dl_src=00:00:00:00:00:03
488])
489AT_CHECK([expr_to_flow 'eth.src == {$set3}'], [0], [dnl
490dl_src=00:00:00:00:00:01
491dl_src=00:00:00:00:00:02
492dl_src=00:00:00:00:00:03
493])
ea382567
RB
494AT_CHECK([expr_to_flow 'eth.src == {00:00:00:00:00:01, $set3, ba:be:be:ef:de:ad, $set3}'], [0], [dnl
495dl_src=00:00:00:00:00:01
496dl_src=00:00:00:00:00:02
497dl_src=00:00:00:00:00:03
498dl_src=ba:be:be:ef:de:ad
499])
2c5cbb15
RB
500AT_CLEANUP
501
3b7cb7e1
BP
502AT_SETUP([ovn -- action parsing])
503dnl Text before => is input, text after => is expected output.
504AT_DATA([test-cases.txt], [[
5f822129 505# drop
3b7cb7e1 506drop; => actions=drop, prereqs=1
5f822129
BP
507drop; next; => Syntax error at `next' expecting end of input.
508next; drop; => Syntax error at `drop' expecting action.
509
510# output
511output; => actions=resubmit(,64), prereqs=1
512
513# next
558ec83d
BP
514next; => actions=resubmit(,27), prereqs=1
515next(0); => actions=resubmit(,16), prereqs=1
516next(15); => actions=resubmit(,31), prereqs=1
5f822129
BP
517
518next(); => Syntax error at `)' expecting small integer.
519next(10; => Syntax error at `;' expecting `)'.
520next(16); => "next" argument must be in range 0 to 15.
521
522# Loading a constant value.
3b7cb7e1
BP
523tcp.dst=80; => actions=set_field:80->tcp_dst, prereqs=ip.proto == 0x6 && (eth.type == 0x800 || eth.type == 0x86dd)
524eth.dst[40] = 1; => actions=set_field:01:00:00:00:00:00/01:00:00:00:00:00->eth_dst, prereqs=1
525vlan.pcp = 2; => actions=set_field:0x4000/0xe000->vlan_tci, prereqs=vlan.tci[12]
526vlan.tci[13..15] = 2; => actions=set_field:0x4000/0xe000->vlan_tci, prereqs=1
cc5e28d8 527inport = ""; => actions=set_field:0->reg14,set_field:0->in_port, prereqs=1
47f3b59b 528ip.ttl = 4; => actions=set_field:4->nw_ttl, prereqs=eth.type == 0x800 || eth.type == 0x86dd
cc5e28d8 529outport="eth0"; next; outport="LOCAL"; next; => actions=set_field:0x5->reg15,resubmit(,27),set_field:0xfffe->reg15,resubmit(,27), prereqs=1
558ec83d 530
3b7cb7e1
BP
531inport[1] = 1; => Cannot select subfield of string field inport.
532ip.proto[1] = 1; => Cannot select subfield of nominal field ip.proto.
8fb72d29 533eth.dst[40] == 1; => Syntax error at `==' expecting `=' or `<->'.
ce57ea75 534ip = 1; => Predicate symbol ip used where lvalue required.
3b7cb7e1
BP
535ip.proto = 6; => Field ip.proto is not modifiable.
536inport = {"a", "b"}; => Assignments require a single value.
537inport = {}; => Syntax error at `}' expecting constant.
538bad_prereq = 123; => Error parsing expression `xyzzy' encountered as prerequisite or predicate of initial expression: Syntax error at `xyzzy' expecting field name.
539self_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 540vlan.present = 0; => Predicate symbol vlan.present used where lvalue required.
5f822129
BP
541
542# Moving one field into another.
543reg0 = reg1; => actions=move:OXM_OF_PKT_REG0[0..31]->OXM_OF_PKT_REG0[32..63], prereqs=1
544vlan.pcp = reg0[0..2]; => actions=move:OXM_OF_PKT_REG0[32..34]->NXM_OF_VLAN_TCI[13..15], prereqs=vlan.tci[12]
545reg0[10] = vlan.pcp[1]; => actions=move:NXM_OF_VLAN_TCI[14]->OXM_OF_PKT_REG0[42], prereqs=vlan.tci[12]
cc5e28d8 546outport = inport; => actions=move:NXM_NX_REG14[]->NXM_NX_REG15[], prereqs=1
5f822129 547
ce57ea75 548reg0[0] = vlan.present; => Predicate symbol vlan.present used where lvalue required.
5ee054fb
BP
549reg0 = reg1[0..10]; => Can't assign 11-bit value to 32-bit destination.
550inport = reg0; => Can't assign integer field (reg0) to string field (inport).
551inport = big_string; => String fields inport and big_string are incompatible for assignment.
552ip.proto = reg0[0..7]; => Field ip.proto is not modifiable.
5f822129
BP
553
554# Exchanging fields.
555reg0 <-> 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
556vlan.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]
557reg0[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]
cc5e28d8 558outport <-> inport; => actions=push:NXM_NX_REG14[],push:NXM_NX_REG15[],pop:NXM_NX_REG14[],pop:NXM_NX_REG15[], prereqs=1
5f822129 559
ce57ea75 560reg0[0] <-> vlan.present; => Predicate symbol vlan.present used where lvalue required.
a20c96c6
BP
561reg0 <-> reg1[0..10]; => Can't exchange 32-bit field with 11-bit field.
562inport <-> reg0; => Can't exchange string field (inport) with integer field (reg0).
563inport <-> big_string; => String fields inport and big_string are incompatible for exchange.
564ip.proto <-> reg0[0..7]; => Field ip.proto is not modifiable.
565reg0[0..7] <-> ip.proto; => Field ip.proto is not modifiable.
5f822129
BP
566
567# TTL decrement.
568ip.ttl--; => actions=dec_ttl, prereqs=ip
47f3b59b 569ip.ttl => Syntax error at end of input expecting `--'.
5f822129 570
467085fd 571# load balancing.
cc5e28d8 572ct_lb; => actions=ct(table=27,zone=NXM_NX_REG13[0..15],nat), prereqs=ip
467085fd
GS
573ct_lb(); => Syntax error at `)' expecting IPv4 address.
574ct_lb(192.168.1.2:80, 192.168.1.3:80); => actions=group:1, prereqs=ip
575ct_lb(192.168.1.2, 192.168.1.3, ); => actions=group:2, prereqs=ip
576ct_lb(192.168.1.2:); => Syntax error at `)' expecting port number.
577ct_lb(192.168.1.2:123456); => Syntax error at `123456' expecting port number.
578ct_lb(foo); => Syntax error at `foo' expecting IPv4 address.
579
5f822129 580# conntrack
cc5e28d8
JP
581ct_next; => actions=ct(table=27,zone=NXM_NX_REG13[0..15]), prereqs=ip
582ct_commit; => actions=ct(commit,zone=NXM_NX_REG13[0..15]), prereqs=ip
583ct_commit(); => actions=ct(commit,zone=NXM_NX_REG13[0..15]), prereqs=ip
584ct_commit(ct_mark=1); => actions=ct(commit,zone=NXM_NX_REG13[0..15],exec(set_field:0x1->ct_mark)), prereqs=ip
585ct_commit(ct_mark=1/1); => actions=ct(commit,zone=NXM_NX_REG13[0..15],exec(set_field:0x1/0x1->ct_mark)), prereqs=ip
586ct_commit(ct_label=1); => actions=ct(commit,zone=NXM_NX_REG13[0..15],exec(set_field:0x1->ct_label)), prereqs=ip
587ct_commit(ct_label=1/1); => actions=ct(commit,zone=NXM_NX_REG13[0..15],exec(set_field:0x1/0x1->ct_label)), prereqs=ip
354b8f27
NS
588ct_commit(ct_label=0x01020304050607080910111213141516); => actions=ct(commit,zone=NXM_NX_REG13[0..15],exec(set_field:0x1020304050607080910111213141516->ct_label)), prereqs=ip
589ct_commit(ct_label=0x181716151413121110090807060504030201); => actions=ct(commit,zone=NXM_NX_REG13[0..15],exec(set_field:0x16151413121110090807060504030201->ct_label)), prereqs=ip
590ct_commit(ct_label=0x01000000000000000000000000000000/0x01000000000000000000000000000000); => actions=ct(commit,zone=NXM_NX_REG13[0..15],exec(set_field:0x1000000000000000000000000000000/0x1000000000000000000000000000000->ct_label)), prereqs=ip
591ct_commit(ct_label=18446744073709551615); => actions=ct(commit,zone=NXM_NX_REG13[0..15],exec(set_field:0xffffffffffffffff->ct_label)), prereqs=ip
592ct_commit(ct_label=18446744073709551616); => Decimal constants must be less than 2**64.
cc5e28d8 593ct_commit(ct_mark=1, ct_label=2); => actions=ct(commit,zone=NXM_NX_REG13[0..15],exec(set_field:0x1->ct_mark,set_field:0x2->ct_label)), prereqs=ip
5f822129 594
de297547 595# dnat
cc5e28d8
JP
596ct_dnat; => actions=ct(table=27,zone=NXM_NX_REG11[0..15],nat), prereqs=ip
597ct_dnat(192.168.1.2); => actions=ct(commit,table=27,zone=NXM_NX_REG11[0..15],nat(dst=192.168.1.2)), prereqs=ip
de297547
GS
598ct_dnat(192.168.1.2, 192.168.1.3); => Syntax error at `,' expecting `)'.
599ct_dnat(foo); => Syntax error at `foo' invalid ip.
600ct_dnat(foo, bar); => Syntax error at `foo' invalid ip.
601ct_dnat(); => Syntax error at `)' invalid ip.
602
603# snat
cc5e28d8
JP
604ct_snat; => actions=ct(zone=NXM_NX_REG12[0..15],nat), prereqs=ip
605ct_snat(192.168.1.2); => actions=ct(commit,table=27,zone=NXM_NX_REG12[0..15],nat(src=192.168.1.2)), prereqs=ip
de297547
GS
606ct_snat(192.168.1.2, 192.168.1.3); => Syntax error at `,' expecting `)'.
607ct_snat(foo); => Syntax error at `foo' invalid ip.
608ct_snat(foo, bar); => Syntax error at `foo' invalid ip.
609ct_snat(); => Syntax error at `)' invalid ip.
610
611
6335d074
BP
612# arp
613arp { 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
614
0bac7164
BP
615# get_arp
616get_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
cc5e28d8 617get_arp(inport, reg0); => actions=push:NXM_NX_REG15[],push:NXM_NX_REG0[],push:OXM_OF_PKT_REG0[32..63],push:NXM_NX_REG14[],pop:NXM_NX_REG15[],pop:NXM_NX_REG0[],set_field:00:00:00:00:00:00->eth_dst,resubmit(,65),pop:NXM_NX_REG0[],pop:NXM_NX_REG15[], prereqs=1
0bac7164
BP
618get_arp; => Syntax error at `;' expecting `('.
619get_arp(); => Syntax error at `)' expecting field name.
620get_arp(inport); => Syntax error at `)' expecting `,'.
621get_arp(inport ip4.dst); => Syntax error at `ip4.dst' expecting `,'.
622get_arp(inport, ip4.dst; => Syntax error at `;' expecting `)'.
623get_arp(inport, eth.dst); => Cannot use 48-bit field eth.dst[0..47] where 32-bit field is required.
624get_arp(inport, outport); => Cannot use string field outport where numeric field is required.
625get_arp(reg0, ip4.dst); => Cannot use numeric field reg0 where string field is required.
626
627# put_arp
628put_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
629
42814145
NS
630# put_dhcp_opts
631reg1[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
632reg2[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
633# offerip=10.0.0.4 --> 0a.00.00.04
634# router=10.0.0.1 --> 03.04.0a.00.00.01
635# netmask=255.255.255.0 --> 01.04.ff.ff.ff.00
636# mtu=1400 --> 1a.02.05.78
637# ip_forward_enable-1 --> 13.01.01
638# default_ttl=121 --> 17.01.79
639# dns_server={8.8.8.8,7.7.7.7} --> 06.08.08.08.08.08.07.07.07.07
640# classless_static_route= --> 79.14
641# {30.0.0.0/24,10.0.0.4 --> 18.1e.00.00.0a.00.00.04
642# 40.0.0.0/16,10.0.0.6 --> 10.28.00.0a.00.00.06
643# 0.0.0.0/0,10.0.0.1} --> 00.0a.00.00.01
644# ethernet_encap=1 --> 24.01.01
645# router_discovery=0 --> 1f.01.00
646reg0[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
647reg1[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.
648reg1[0] = put_dhcp_opts(); => Syntax error at `)'.
649reg1[0] = put_dhcp_opts(x = 1.2.3.4, router = 10.0.0.1); => Syntax error at `x' expecting offerip option.
650reg1[0] = put_dhcp_opts(offerip=1.2.3.4, "hi"); => Syntax error at `"hi"'.
651reg1[0] = put_dhcp_opts(offerip=1.2.3.4, xyzzy); => Syntax error at `xyzzy' expecting DHCP option name.
652reg1[0] = put_dhcp_opts(offerip="xyzzy"); => DHCP option offerip requires numeric value.
653reg1[0] = put_dhcp_opts(offerip=1.2.3.4, domain=1.2.3.4); => DHCP option domain requires string value.
654
e75451fe 655# na
cc5e28d8 656na { eth.src = 12:34:56:78:9a:bc; nd.tll = 12:34:56:78:9a:bc; outport = inport; inport = ""; /* Allow sending out inport. */ output; }; => actions=controller(userdata=00.00.00.03.00.00.00.00.00.19.00.10.80.00.08.06.12.34.56.78.9a.bc.00.00.00.19.00.10.80.00.42.06.12.34.56.78.9a.bc.00.00.ff.ff.00.18.00.00.23.20.00.06.00.20.00.00.00.00.00.01.1c.04.00.01.1e.04.00.19.00.10.00.01.1c.04.00.00.00.00.00.00.00.00.00.19.00.10.00.00.00.02.00.00.00.00.00.00.00.00.ff.ff.00.10.00.00.23.20.00.0e.ff.f8.40.00.00.00), prereqs=nd
e75451fe 657
5f822129
BP
658# Contradictionary prerequisites (allowed but not useful):
659ip4.src = ip6.src[0..31]; => actions=move:NXM_NX_IPV6_SRC[0..31]->NXM_OF_IP_SRC[], prereqs=eth.type == 0x800 && eth.type == 0x86dd
660ip4.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
661
662## Miscellaneous negative tests.
663; => Syntax error at `;'.
664xyzzy; => Syntax error at `xyzzy' expecting action.
665next; 123; => Syntax error at `123'.
666next; xyzzy; => Syntax error at `xyzzy' expecting action.
667next => Syntax error at end of input expecting ';'.
3b7cb7e1
BP
668]])
669sed 's/ =>.*//' test-cases.txt > input.txt
670sed 's/.* => //' test-cases.txt > expout
671AT_CHECK([ovstest test-ovn parse-actions < input.txt], [0], [expout])
672AT_CLEANUP
f295c17b
BP
673
674AT_BANNER([OVN end-to-end tests])
675
9975d7be
BP
676# 3 hypervisors, one logical switch, 3 logical ports per hypervisor
677AT_SETUP([ovn -- 3 HVs, 1 LS, 3 lports/HV])
57d143eb 678AT_KEYWORDS([ovnarp])
f295c17b
BP
679AT_SKIP_IF([test $HAVE_PYTHON = no])
680ovn_start
681
682# Create hypervisors hv[123].
9975d7be 683# Add vif1[123] to hv1, vif2[123] to hv2, vif3[123] to hv3.
f295c17b
BP
684# Add all of the vifs to a single logical switch lsw0.
685# Turn on port security on all the vifs except vif[123]1.
686# Make vif13, vif2[23], vif3[123] destinations for unknown MACs.
687# Add some ACLs for Ethertypes 1234, 1235, 1236.
ea46a4e9 688ovn-nbctl ls-add lsw0
f295c17b
BP
689net_add n1
690for i in 1 2 3; do
691 sim_add hv$i
692 as hv$i
693 ovs-vsctl add-br br-phys
694 ovn_attach n1 br-phys 192.168.0.$i
695
696 for j in 1 2 3; do
697 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 698 ovn-nbctl lsp-add lsw0 lp$i$j
4d5c43d5 699 if test $j = 1; then
31ed1192 700 ovn-nbctl lsp-set-addresses lp$i$j "f0:00:00:00:00:$i$j 192.168.0.$i$j" unknown
f295c17b 701 else
7dc88496
NS
702 if test $j = 3; then
703 ip_addrs="192.168.0.$i$j fe80::ea2a:eaff:fe28:$i$j/64 192.169.0.$i$j"
704 else
705 ip_addrs="192.168.0.$i$j"
706 fi
31ed1192
JP
707 ovn-nbctl lsp-set-addresses lp$i$j "f0:00:00:00:00:$i$j $ip_addrs"
708 ovn-nbctl lsp-set-port-security lp$i$j f0:00:00:00:00:$i$j
f295c17b
BP
709 fi
710 done
711done
712ovn-nbctl acl-add lsw0 from-lport 1000 'eth.type == 0x1234' drop
713ovn-nbctl acl-add lsw0 from-lport 1000 'eth.type == 0x1235 && inport == "lp11"' drop
714ovn-nbctl acl-add lsw0 to-lport 1000 'eth.type == 0x1236 && outport == "lp33"' drop
ea382567
RB
715ovn-nbctl create Address_Set name=set1 addresses=\"f0:00:00:00:00:11\",\"f0:00:00:00:00:21\",\"f0:00:00:00:00:31\"
716ovn-nbctl acl-add lsw0 to-lport 1000 'eth.type == 0x1237 && eth.src == $set1 && outport == "lp33"' drop
f295c17b
BP
717
718# Pre-populate the hypervisors' ARP tables so that we don't lose any
719# packets for ARP resolution (native tunneling doesn't queue packets
720# for ARP resolution).
721ovn_populate_arp
722
723# Allow some time for ovn-northd and ovn-controller to catch up.
724# XXX This should be more systematic.
725sleep 1
611099dc 726
57d143eb
HZ
727# Given the name of a logical port, prints the name of the hypervisor
728# on which it is located.
729vif_to_hv() {
730 echo hv${1%?}
731}
732
f295c17b
BP
733# test_packet INPORT DST SRC ETHTYPE OUTPORT...
734#
735# This shell function causes a packet to be received on INPORT. The packet's
736# content has Ethernet destination DST and source SRC (each exactly 12 hex
737# digits) and Ethernet type ETHTYPE (4 hex digits). The OUTPORTs (zero or
738# more) list the VIFs on which the packet should be received. INPORT and the
31ed1192 739# OUTPORTs are specified as logical switch port numbers, e.g. 11 for vif11.
f295c17b
BP
740trim_zeros() {
741 sed 's/\(00\)\{1,\}$//'
742}
743for i in 1 2 3; do
744 for j in 1 2 3; do
745 : > $i$j.expected
746 done
747done
748test_packet() {
749 local inport=$1 packet=$2$3$4; shift; shift; shift; shift
57d143eb 750 hv=`vif_to_hv $inport`
f295c17b
BP
751 vif=vif$inport
752 as $hv ovs-appctl netdev-dummy/receive $vif $packet
753 for outport; do
754 echo $packet | trim_zeros >> $outport.expected
755 done
756}
757
57d143eb
HZ
758# test_arp INPORT SHA SPA TPA [REPLY_HA]
759#
760# Causes a packet to be received on INPORT. The packet is an ARP
761# request with SHA, SPA, and TPA as specified. If REPLY_HA is provided, then
762# it should be the hardware address of the target to expect to receive in an
763# ARP reply; otherwise no reply is expected.
764#
31ed1192 765# INPORT is an logical switch port number, e.g. 11 for vif11.
57d143eb
HZ
766# SHA and REPLY_HA are each 12 hex digits.
767# SPA and TPA are each 8 hex digits.
768test_arp() {
769 local inport=$1 sha=$2 spa=$3 tpa=$4 reply_ha=$5
770 local request=ffffffffffff${sha}08060001080006040001${sha}${spa}ffffffffffff${tpa}
771 hv=`vif_to_hv $inport`
772 as $hv ovs-appctl netdev-dummy/receive vif$inport $request
773
92f9822b 774 if test X$reply_ha = X; then
57d143eb
HZ
775 # Expect to receive the broadcast ARP on the other logical switch ports
776 # if no reply is expected.
777 local i j
778 for i in 1 2 3; do
779 for j in 1 2 3; do
780 if test $i$j != $inport; then
781 echo $request >> $i$j.expected
782 fi
783 done
784 done
785 else
786 # Expect to receive the reply, if any.
787 local reply=${sha}${reply_ha}08060001080006040002${reply_ha}${tpa}${sha}${spa}
788 echo $reply >> $inport.expected
789 fi
790}
791
792ip_to_hex() {
793 printf "%02x%02x%02x%02x" "$@"
794}
795
f295c17b
BP
796# Send packets between all pairs of source and destination ports:
797#
31ed1192
JP
798# 1. Unicast packets are delivered to exactly one logical switch port
799# (except that packets destined to their input ports are dropped).
f295c17b 800#
31ed1192
JP
801# 2. Broadcast and multicast are delivered to all logical switch ports
802# except the input port.
f295c17b 803#
ea46a4e9 804# 3. When port security is turned on, the switch drops packets from the wrong
f295c17b
BP
805# MAC address.
806#
ea46a4e9 807# 4. The switch drops all packets with a VLAN tag.
f295c17b 808#
ea46a4e9 809# 5. The switch drops all packets with a multicast source address. (This only
f295c17b
BP
810# affects behavior when port security is turned off, since otherwise port
811# security would drop the packet anyway.)
812#
ea46a4e9 813# 6. The switch delivers packets with an unknown destination to logical
31ed1192
JP
814# switch ports with "unknown" among their MAC addresses (and port
815# security disabled).
f295c17b 816#
ea46a4e9 817# 7. The switch drops unicast packets that violate an ACL.
f295c17b 818#
ea46a4e9 819# 8. The switch drops multicast and broadcast packets that violate an ACL.
57d143eb
HZ
820#
821# 9. ARP requests to known IPs are responded directly.
822#
823# 10. No response to ARP requests for unknown IPs.
f295c17b
BP
824for is in 1 2 3; do
825 for js in 1 2 3; do
826 s=$is$js
827 bcast=
4d5c43d5
JP
828 unknown=
829 bacl2=
830 bacl3=
f295c17b
BP
831 for id in 1 2 3; do
832 for jd in 1 2 3; do
833 d=$id$jd
834
835 if test $d != $s; then unicast=$d; else unicast=; fi
836 test_packet $s f000000000$d f000000000$s $s$d $unicast #1
837
838 if test $d != $s && test $js = 1; then
4d5c43d5
JP
839 impersonate=$d
840 else
841 impersonate=
842 fi
f295c17b
BP
843 test_packet $s f000000000$d f00000000055 55$d $impersonate #3
844
4d5c43d5
JP
845 if test $d != $s && test $s != 11; then acl2=$d; else acl2=; fi
846 if test $d != $s && test $d != 33; then acl3=$d; else acl3=; fi
e137131a 847 if test $d = $s || (test $js = 1 && test $d = 33); then
ea382567
RB
848 # Source of 11, 21, or 31 and dest of 33 should be dropped
849 # due to the 4th ACL that uses address_set(set1).
850 acl4=
851 else
852 acl4=$d
853 fi
f295c17b
BP
854 test_packet $s f000000000$d f000000000$s 1234 #7, acl1
855 test_packet $s f000000000$d f000000000$s 1235 $acl2 #7, acl2
856 test_packet $s f000000000$d f000000000$s 1236 $acl3 #7, acl3
ea382567 857 test_packet $s f000000000$d f000000000$s 1237 $acl4 #7, acl4
f295c17b
BP
858
859 test_packet $s f000000000$d f00000000055 810000091234 #4
860 test_packet $s f000000000$d 0100000000$s $s$d #5
861
4d5c43d5
JP
862 if test $d != $s && test $jd = 1; then
863 unknown="$unknown $d"
864 fi
f295c17b
BP
865 bcast="$bcast $unicast"
866 bacl2="$bacl2 $acl2"
867 bacl3="$bacl3 $acl3"
57d143eb
HZ
868
869 sip=`ip_to_hex 192 168 0 $i$j`
870 tip=`ip_to_hex 192 168 0 $id$jd`
871 tip_unknown=`ip_to_hex 11 11 11 11`
872 test_arp $s f000000000$s $sip $tip f000000000$d #9
873 test_arp $s f000000000$s $sip $tip_unknown #10
7dc88496
NS
874
875 if test $jd = 3; then
31ed1192 876 # lsp[123]3 has an additional ip 192.169.0.[123]3.
7dc88496
NS
877 tip=`ip_to_hex 192 169 0 $id$jd`
878 test_arp $s f000000000$s $sip $tip f000000000$d #9
879 fi
f295c17b
BP
880 done
881 done
882
4d5c43d5 883 # Broadcast and multicast.
f295c17b
BP
884 test_packet $s ffffffffffff f000000000$s ${s}ff $bcast #2
885 test_packet $s 010000000000 f000000000$s ${s}ff $bcast #2
4d5c43d5 886 if test $js = 1; then
f295c17b
BP
887 bcast_impersonate=$bcast
888 else
4d5c43d5
JP
889 bcast_impersonate=
890 fi
f295c17b
BP
891 test_packet $s 010000000000 f00000000044 44ff $bcast_impersonate #3
892
893 test_packet $s f0000000ffff f000000000$s ${s}66 $unknown #6
894
895 test_packet $s ffffffffffff f000000000$s 1234 #8, acl1
896 test_packet $s ffffffffffff f000000000$s 1235 $bacl2 #8, acl2
897 test_packet $s ffffffffffff f000000000$s 1236 $bacl3 #8, acl3
898 test_packet $s 010000000000 f000000000$s 1234 #8, acl1
899 test_packet $s 010000000000 f000000000$s 1235 $bacl2 #8, acl2
900 test_packet $s 010000000000 f000000000$s 1236 $bacl3 #8, acl3
901 done
902done
903
7dc88496
NS
904# set address for lp13 with invalid characters.
905# lp13 should be configured with only 192.168.0.13.
31ed1192 906ovn-nbctl lsp-set-addresses lp13 "f0:00:00:00:00:13 192.168.0.13 invalid 192.169.0.13"
7dc88496
NS
907sip=`ip_to_hex 192 168 0 11`
908tip=`ip_to_hex 192 168 0 13`
909test_arp 11 f00000000011 $sip $tip f00000000013
910
911tip=`ip_to_hex 192 169 0 13`
912#arp request for 192.169.0.13 should be flooded
913test_arp 11 f00000000011 $sip $tip
914
f295c17b
BP
915# Allow some time for packet forwarding.
916# XXX This can be improved.
917sleep 1
918
91125642 919# dump information and flows with counters
bb0c41d3
RM
920ovn-sbctl dump-flows -- list multicast_group
921
922echo "------ hv1 dump ------"
923as hv1 ovs-vsctl show
924as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-int
925
926echo "------ hv2 dump ------"
927as hv2 ovs-vsctl show
928as hv2 ovs-ofctl -O OpenFlow13 dump-flows br-int
929
930echo "------ hv3 dump ------"
931as hv3 ovs-vsctl show
932as hv3 ovs-ofctl -O OpenFlow13 dump-flows br-int
f295c17b
BP
933# Now check the packets actually received against the ones expected.
934for i in 1 2 3; do
935 for j in 1 2 3; do
936 file=hv$i/vif$i$j-tx.pcap
937 echo $file
938 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" $file | trim_zeros > $i$j.packets
2172f32d
YT
939 sort $i$j.expected > expout
940 AT_CHECK([sort $i$j.packets], [0], [expout])
f295c17b
BP
941 echo
942 done
943done
fcde56f5 944
7a8f15e0 945OVN_CLEANUP([hv1],[hv2],[hv3])
d9c8c57c 946
f295c17b 947AT_CLEANUP
eb6b08eb 948
7277bc83
RB
949# 2 hypervisors, 4 logical ports per HV
950# 2 locally attached networks (one flat, one vlan tagged over same device)
951# 2 ports per HV on each network
e90aeb57 952AT_SETUP([ovn -- 2 HVs, 4 lports/HV, localnet ports])
d79fc5f4
RB
953AT_KEYWORDS([ovn-localnet])
954AT_SKIP_IF([test $HAVE_PYTHON = no])
955ovn_start
956
ea46a4e9
JP
957# In this test cases we create 3 switches, all connected to same
958# physical network (through br-phys on each HV). Each switch has
0ee7f7f1
HZ
959# VIF ports across 2 HVs. Each HV has 5 VIF ports. The first digit
960# of VIF port name indicates the hypervisor it is bound to, e.g.
961# lp23 means VIF 3 on hv2.
962#
ea46a4e9 963# Each switch's VLAN tag and their logical switch ports are:
0ee7f7f1
HZ
964# - ls1:
965# - untagged
ea46a4e9 966# - ports: lp11, lp12, lp21, lp22
0ee7f7f1
HZ
967#
968# - ls2:
969# - tagged with VLAN 101
ea46a4e9 970# - ports: lp13, lp14, lp23, lp24
0ee7f7f1
HZ
971# - ls3:
972# - untagged
ea46a4e9 973# - ports: lp15, lp25
0ee7f7f1 974#
ea46a4e9 975# Note: a localnet port is created for each switch to connect to
0ee7f7f1
HZ
976# physical network.
977
978for i in 1 2 3; do
ea46a4e9
JP
979 ls_name=ls$i
980 ovn-nbctl ls-add $ls_name
0ee7f7f1
HZ
981 ln_port_name=ln$i
982 if test $i -eq 2; then
ea46a4e9 983 ovn-nbctl lsp-add $ls_name $ln_port_name "" 101
0ee7f7f1 984 else
ea46a4e9 985 ovn-nbctl lsp-add $ls_name $ln_port_name
0ee7f7f1 986 fi
31ed1192
JP
987 ovn-nbctl lsp-set-addresses $ln_port_name unknown
988 ovn-nbctl lsp-set-type $ln_port_name localnet
989 ovn-nbctl lsp-set-options $ln_port_name network_name=phys
0ee7f7f1 990done
d79fc5f4
RB
991
992net_add n1
993for i in 1 2; do
994 sim_add hv$i
995 as hv$i
996 ovs-vsctl add-br br-phys
997 ovs-vsctl set open . external-ids:ovn-bridge-mappings=phys:br-phys
998 ovn_attach n1 br-phys 192.168.0.$i
999
0ee7f7f1 1000 for j in 1 2 3 4 5; do
d79fc5f4
RB
1001 ovs-vsctl add-port br-int vif$i$j -- \
1002 set Interface vif$i$j external-ids:iface-id=lp$i$j \
1003 options:tx_pcap=hv$i/vif$i$j-tx.pcap \
1004 options:rxq_pcap=hv$i/vif$i$j-rx.pcap \
1005 ofport-request=$i$j
1006
31ed1192 1007 lsp_name=lp$i$j
7277bc83 1008 if test $j -le 2; then
ea46a4e9 1009 ls_name=ls1
0ee7f7f1 1010 elif test $j -le 4; then
ea46a4e9 1011 ls_name=ls2
d79fc5f4 1012 else
ea46a4e9 1013 ls_name=ls3
d79fc5f4 1014 fi
d79fc5f4 1015
ea46a4e9 1016 ovn-nbctl lsp-add $ls_name $lsp_name
31ed1192
JP
1017 ovn-nbctl lsp-set-addresses $lsp_name f0:00:00:00:00:$i$j
1018 ovn-nbctl lsp-set-port-security $lsp_name f0:00:00:00:00:$i$j
d79fc5f4 1019
31ed1192 1020 OVS_WAIT_UNTIL([test x`ovn-nbctl lsp-get-up $lsp_name` = xup])
d79fc5f4
RB
1021 done
1022done
1023
1024ovn_populate_arp
1025
1026# XXX This is now the 3rd copy of these functions in this file ...
1027
1028# Given the name of a logical port, prints the name of the hypervisor
1029# on which it is located.
1030vif_to_hv() {
1031 echo hv${1%?}
1032}
1033#
1034# test_packet INPORT DST SRC ETHTYPE OUTPORT...
1035#
1036# This shell function causes a packet to be received on INPORT. The packet's
1037# content has Ethernet destination DST and source SRC (each exactly 12 hex
1038# digits) and Ethernet type ETHTYPE (4 hex digits). The OUTPORTs (zero or
1039# more) list the VIFs on which the packet should be received. INPORT and the
31ed1192 1040# OUTPORTs are specified as logical switch port numbers, e.g. 11 for vif11.
d79fc5f4
RB
1041trim_zeros() {
1042 sed 's/\(00\)\{1,\}$//'
1043}
1044for i in 1 2; do
0ee7f7f1 1045 for j in 1 2 3 4 5; do
d79fc5f4
RB
1046 : > $i$j.expected
1047 done
1048done
1049test_packet() {
1050 local inport=$1 src=$2 dst=$3 eth=$4; shift; shift; shift; shift
1051 local packet=${src}${dst}${eth}
1052 hv=`vif_to_hv $inport`
1053 vif=vif$inport
1054 as $hv ovs-appctl netdev-dummy/receive $vif $packet
1055 for outport; do
1056 echo $packet | trim_zeros >> $outport.expected
1057 done
1058}
1059
7277bc83
RB
1060# lp11 and lp21 are on the same network (phys, untagged)
1061# and on different hypervisors
d79fc5f4
RB
1062test_packet 11 f00000000021 f00000000011 1121 21
1063test_packet 21 f00000000011 f00000000021 2111 11
1064
7277bc83
RB
1065# lp11 and lp12 are on the same network (phys, untagged)
1066# and on the same hypervisor
e90aeb57
RB
1067test_packet 11 f00000000012 f00000000011 1112 12
1068test_packet 12 f00000000011 f00000000012 1211 11
7277bc83
RB
1069
1070# lp13 and lp23 are on the same network (phys, VLAN 101)
1071# and on different hypervisors
1072test_packet 13 f00000000023 f00000000013 1323 23
1073test_packet 23 f00000000013 f00000000023 2313 13
1074
1075# lp13 and lp14 are on the same network (phys, VLAN 101)
1076# and on the same hypervisor
e90aeb57
RB
1077test_packet 13 f00000000014 f00000000013 1314 14
1078test_packet 14 f00000000013 f00000000014 1413 13
d79fc5f4 1079
0ee7f7f1 1080# lp11 and lp15 are on the same network (phys, untagged),
ea46a4e9 1081# same hypervisor, and on different switches
0ee7f7f1
HZ
1082test_packet 11 f00000000015 f00000000011 1115 15
1083test_packet 15 f00000000011 f00000000015 1511 11
1084
1085# lp11 and lp25 are on the same network (phys, untagged),
ea46a4e9 1086# different hypervisors, and on different switches
0ee7f7f1
HZ
1087test_packet 11 f00000000025 f00000000011 1125 25
1088test_packet 25 f00000000011 f00000000025 2511 11
1089
d79fc5f4 1090# Ports that should not be able to communicate
7277bc83
RB
1091test_packet 11 f00000000013 f00000000011 1113
1092test_packet 11 f00000000023 f00000000011 1123
1093test_packet 21 f00000000013 f00000000021 2113
1094test_packet 21 f00000000023 f00000000021 2123
1095test_packet 13 f00000000011 f00000000013 1311
1096test_packet 13 f00000000021 f00000000013 1321
1097test_packet 23 f00000000011 f00000000023 2311
1098test_packet 23 f00000000021 f00000000023 2321
d79fc5f4
RB
1099
1100# Allow some time for packet forwarding.
1101# XXX This can be improved.
1102sleep 1
1103
1104# Dump a bunch of info helpful for debugging if there's a failure.
1105
1106echo "------ OVN dump ------"
1107ovn-nbctl show
1108ovn-sbctl show
1109
1110echo "------ hv1 dump ------"
1111as hv1 ovs-vsctl show
1112as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-int
1113
1114echo "------ hv2 dump ------"
1115as hv2 ovs-vsctl show
1116as hv2 ovs-ofctl -O OpenFlow13 dump-flows br-int
1117
1118# Now check the packets actually received against the ones expected.
1119for i in 1 2; do
0ee7f7f1 1120 for j in 1 2 3 4 5; do
d79fc5f4
RB
1121 file=hv$i/vif$i$j-tx.pcap
1122 echo $file
1123 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" $file | trim_zeros > $i$j.packets
1124 sort $i$j.expected > expout
1125 AT_CHECK([sort $i$j.packets], [0], [expout])
1126 echo
1127 done
1128done
1129
7a8f15e0 1130OVN_CLEANUP([hv1],[hv2])
d9c8c57c 1131
d79fc5f4
RB
1132AT_CLEANUP
1133
91125642
FF
1134AT_SETUP([ovn -- vtep: 3 HVs, 1 VIFs/HV, 1 GW, 1 LS])
1135AT_KEYWORDS([vtep])
eb6b08eb
JP
1136AT_SKIP_IF([test $HAVE_PYTHON = no])
1137ovn_start
1138
1139# Configure the Northbound database
ea46a4e9 1140ovn-nbctl ls-add lsw0
eb6b08eb 1141
31ed1192
JP
1142ovn-nbctl lsp-add lsw0 lp1
1143ovn-nbctl lsp-set-addresses lp1 f0:00:00:00:00:01
eb6b08eb 1144
31ed1192
JP
1145ovn-nbctl lsp-add lsw0 lp2
1146ovn-nbctl lsp-set-addresses lp2 f0:00:00:00:00:02
eb6b08eb 1147
31ed1192
JP
1148ovn-nbctl lsp-add lsw0 lp-vtep
1149ovn-nbctl lsp-set-type lp-vtep vtep
1150ovn-nbctl lsp-set-options lp-vtep vtep-physical-switch=br-vtep vtep-logical-switch=lsw0
1151ovn-nbctl lsp-set-addresses lp-vtep unknown
eb6b08eb
JP
1152
1153net_add n1 # Network to connect hv1, hv2, and vtep
1154net_add n2 # Network to connect vtep and hv3
1155
1156# Create hypervisor hv1 connected to n1
1157sim_add hv1
1158as hv1
1159ovs-vsctl add-br br-phys
1160ovn_attach n1 br-phys 192.168.0.1
1161ovs-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
1162
1163# Create hypervisor hv2 connected to n1
1164sim_add hv2
1165as hv2
1166ovs-vsctl add-br br-phys
1167ovn_attach n1 br-phys 192.168.0.2
1168ovs-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
1169
1170
1171# Start the vtep emulator with a leg in both networks
1172sim_add vtep
1173as vtep
1174
1175ovsdb-tool create "$ovs_base"/vtep/vtep.db "$abs_top_srcdir"/vtep/vtep.ovsschema || return 1
1176ovs-appctl -t ovsdb-server ovsdb-server/add-db "$ovs_base"/vtep/vtep.db
1177
1178ovs-vsctl add-br br-phys
1179net_attach n1 br-phys
1180
1181mac=`ovs-vsctl get Interface br-phys mac_in_use | sed s/\"//g`
1182arp_table="$arp_table $sandbox,br-phys,192.168.0.3,$mac"
1183ovs-appctl netdev-dummy/ip4addr br-phys 192.168.0.3/24 >/dev/null || return 1
1184ovs-appctl ovs/route/add 192.168.0.3/24 br-phys >/dev/null || return 1
1185
1186ovs-vsctl add-br br-vtep
1187net_attach n2 br-vtep
1188
1189vtep-ctl add-ps br-vtep
1190vtep-ctl set Physical_Switch br-vtep tunnel_ips=192.168.0.3
1191vtep-ctl add-ls lsw0
1192
1193start_daemon ovs-vtep br-vtep
1194start_daemon ovn-controller-vtep --vtep-db=unix:"$ovs_base"/vtep/db.sock --ovnsb-db=unix:"$ovs_base"/ovn-sb/ovn-sb.sock
1195
1196sleep 1
1197
1198vtep-ctl bind-ls br-vtep br-vtep_n2 0 lsw0
1199
1200sleep 1
1201
1202# Add hv3 on the other side of the vtep
1203sim_add hv3
1204as hv3
1205ovs-vsctl add-br br-phys
1206net_attach n2 br-phys
1207
1208ovs-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
1209
1210# Pre-populate the hypervisors' ARP tables so that we don't lose any
1211# packets for ARP resolution (native tunneling doesn't queue packets
1212# for ARP resolution).
1213ovn_populate_arp
1214
1215# Allow some time for ovn-northd and ovn-controller to catch up.
1216# XXX This should be more systematic.
1217sleep 1
6977df72 1218
eb6b08eb
JP
1219# test_packet INPORT DST SRC ETHTYPE OUTPORT...
1220#
1221# This shell function causes a packet to be received on INPORT. The packet's
1222# content has Ethernet destination DST and source SRC (each exactly 12 hex
1223# digits) and Ethernet type ETHTYPE (4 hex digits). The OUTPORTs (zero or
1224# more) list the VIFs on which the packet should be received. INPORT and the
31ed1192 1225# OUTPORTs are specified as logical switch port numbers, e.g. 1 for vif1.
eb6b08eb
JP
1226trim_zeros() {
1227 sed 's/\(00\)\{1,\}$//'
1228}
1229for i in 1 2 3; do
1230 : > $i.expected
1231done
1232test_packet() {
1233 local inport=$1 packet=$2$3$4; shift; shift; shift; shift
1234 #hv=hv`echo $inport | sed 's/^\(.\).*/\1/'`
1235 hv=hv$inport
1236 vif=vif$inport
1237 as $hv ovs-appctl netdev-dummy/receive $vif $packet
1238 for outport; do
1239 echo $packet | trim_zeros >> $outport.expected
1240 done
1241}
1242
1243# Send packets between all pairs of source and destination ports:
1244#
31ed1192
JP
1245# 1. Unicast packets are delivered to exactly one logical switch port
1246# (except that packets destined to their input ports are dropped).
eb6b08eb 1247#
31ed1192
JP
1248# 2. Broadcast and multicast are delivered to all logical switch ports
1249# except the input port.
eb6b08eb 1250#
ea46a4e9 1251# 3. The switch delivers packets with an unknown destination to logical
31ed1192
JP
1252# switch ports with "unknown" among their MAC addresses (and port
1253# security disabled).
eb6b08eb
JP
1254for s in 1 2 3; do
1255 bcast=
1256 unknown=
1257 for d in 1 2 3; do
1258 if test $d != $s; then unicast=$d; else unicast=; fi
1259 test_packet $s f0000000000$d f0000000000$s 00$s$d $unicast #1
1260
1261 # The vtep (vif3) is the only one configured for "unknown"
1262 if test $d != $s && test $d = 3; then
1263 unknown="$unknown $d"
1264 fi
1265 bcast="$bcast $unicast"
1266 done
1267
1268 # Broadcast and multicast.
46ed1382
DB
1269 test_packet $s ffffffffffff f0000000000$s 0${s}ff $bcast #2
1270 test_packet $s 010000000000 f0000000000$s 0${s}ff $bcast #2
eb6b08eb
JP
1271
1272 test_packet $s f0000000ffff f0000000000$s 0${s}66 $unknown #3
1273done
1274
1275# Allow some time for packet forwarding.
1276# XXX This can be improved.
1277sleep 1
1278
bb0c41d3
RM
1279# dump information with counters
1280echo "------ OVN dump ------"
1281ovn-nbctl show
1282ovn-sbctl show
1283
1284echo "------ hv1 dump ------"
1285as hv1 ovs-vsctl show
6195e2e7 1286as hv1 ovs-ofctl -O OpenFlow13 show br-int
bb0c41d3
RM
1287as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-int
1288
1289echo "------ hv2 dump ------"
1290as hv2 ovs-vsctl show
6195e2e7 1291as hv2 ovs-ofctl -O OpenFlow13 show br-int
bb0c41d3
RM
1292as hv2 ovs-ofctl -O OpenFlow13 dump-flows br-int
1293
1294echo "------ hv3 dump ------"
1295as hv3 ovs-vsctl show
6754e92d
FF
1296# note: hv3 has no logical port bind, thus it should not have br-int
1297AT_CHECK([as hv3 ovs-ofctl -O OpenFlow13 show br-int], [1], [],
1298[ovs-ofctl: br-int is not a bridge or a socket
1299])
bb0c41d3 1300
eb6b08eb
JP
1301# Now check the packets actually received against the ones expected.
1302for i in 1 2 3; do
1303 file=hv$i/vif$i-tx.pcap
1304 echo $file
1305 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" $file | trim_zeros > $i.packets
2172f32d
YT
1306 sort $i.expected > expout
1307 AT_CHECK([sort $i.packets], [0], [expout])
eb6b08eb
JP
1308 echo
1309done
fcde56f5
LR
1310
1311# Gracefully terminate daemons
7a8f15e0
LR
1312OVN_CLEANUP([hv1],[hv2],[vtep])
1313OVN_CLEANUP_VSWITCH([hv3])
d9c8c57c 1314
eb6b08eb 1315AT_CLEANUP
9975d7be 1316
184bc3ca
RB
1317# Similar test to "hardware GW"
1318AT_SETUP([ovn -- 3 HVs, 1 VIFs/HV, 1 software GW, 1 LS])
1319AT_SKIP_IF([test $HAVE_PYTHON = no])
1320ovn_start
1321
1322# Configure the Northbound database
1323ovn-nbctl ls-add lsw0
1324
1325ovn-nbctl lsp-add lsw0 lp1
1326ovn-nbctl lsp-set-addresses lp1 f0:00:00:00:00:01
1327
1328ovn-nbctl lsp-add lsw0 lp2
1329ovn-nbctl lsp-set-addresses lp2 f0:00:00:00:00:02
1330
1331ovn-nbctl lsp-add lsw0 lp-gw
1332ovn-nbctl lsp-set-type lp-gw l2gateway
62b87eab 1333ovn-nbctl lsp-set-options lp-gw network_name=physnet1 l2gateway-chassis=hv_gw
184bc3ca
RB
1334ovn-nbctl lsp-set-addresses lp-gw unknown
1335
1336net_add n1 # Network to connect hv1, hv2, and gw
1337net_add n2 # Network to connect gw and hv3
1338
1339# Create hypervisor hv1 connected to n1
1340sim_add hv1
1341as hv1
1342ovs-vsctl add-br br-phys
1343ovn_attach n1 br-phys 192.168.0.1
1344ovs-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
1345
1346# Create hypervisor hv2 connected to n1
1347sim_add hv2
1348as hv2
1349ovs-vsctl add-br br-phys
1350ovn_attach n1 br-phys 192.168.0.2
1351ovs-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
1352
1353# Create hypervisor hv_gw connected to n1 and n2
1354# connect br-phys bridge to n1; connect hv-gw bridge to n2
1355sim_add hv_gw
1356as hv_gw
1357ovs-vsctl add-br br-phys
1358ovn_attach n1 br-phys 192.168.0.3
1359ovs-vsctl add-br br-phys2
1360net_attach n2 br-phys2
1361ovs-vsctl set open . external_ids:ovn-bridge-mappings="physnet1:br-phys2"
1362
184bc3ca
RB
1363# Add hv3 on the other side of the GW
1364sim_add hv3
1365as hv3
1366ovs-vsctl add-br br-phys
1367net_attach n2 br-phys
1368ovs-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
1369
1370
1371# Pre-populate the hypervisors' ARP tables so that we don't lose any
1372# packets for ARP resolution (native tunneling doesn't queue packets
1373# for ARP resolution).
1374ovn_populate_arp
1375
1376# Allow some time for ovn-northd and ovn-controller to catch up.
1377# XXX This should be more systematic.
1378sleep 1
1379
1380# test_packet INPORT DST SRC ETHTYPE OUTPORT...
1381#
1382# This shell function causes a packet to be received on INPORT. The packet's
1383# content has Ethernet destination DST and source SRC (each exactly 12 hex
1384# digits) and Ethernet type ETHTYPE (4 hex digits). The OUTPORTs (zero or
1385# more) list the VIFs on which the packet should be received. INPORT and the
1386# OUTPORTs are specified as lport numbers, e.g. 1 for vif1.
1387trim_zeros() {
1388 sed 's/\(00\)\{1,\}$//'
1389}
1390for i in 1 2 3; do
1391 : > $i.expected
1392done
1393test_packet() {
1394 local inport=$1 packet=$2$3$4; shift; shift; shift; shift
1395 #hv=hv`echo $inport | sed 's/^\(.\).*/\1/'`
1396 hv=hv$inport
1397 vif=vif$inport
1398 as $hv ovs-appctl netdev-dummy/receive $vif $packet
1399 for outport; do
1400 echo $packet | trim_zeros >> $outport.expected
1401 done
1402}
1403
1404# Send packets between all pairs of source and destination ports:
1405#
1406# 1. Unicast packets are delivered to exactly one lport (except that packets
1407# destined to their input ports are dropped).
1408#
1409# 2. Broadcast and multicast are delivered to all lports except the input port.
1410#
1411# 3. The lswitch delivers packets with an unknown destination to lports with
1412# "unknown" among their MAC addresses (and port security disabled).
1413for s in 1 2 3 ; do
1414 bcast=
1415 unknown=
1416 for d in 1 2 3 ; do
1417 if test $d != $s; then unicast=$d; else unicast=; fi
1418 test_packet $s f0000000000$d f0000000000$s 00$s$d $unicast #1
1419
1420 # The vtep (vif3) is the only one configured for "unknown"
1421 if test $d != $s && test $d = 3; then
1422 unknown="$unknown $d"
1423 fi
1424 bcast="$bcast $unicast"
1425 done
1426
1427 test_packet $s ffffffffffff f0000000000$s 0${s}ff $bcast #2
1428 test_packet $s 010000000000 f0000000000$s 0${s}ff $bcast #3
1429 test_packet $s f0000000ffff f0000000000$s 0${s}66 $unknown #4
1430done
1431
1432# Allow some time for packet forwarding.
1433# XXX This can be improved.
1434sleep 3
1435
1436echo "------ ovn-nbctl show ------"
1437ovn-nbctl show
1438echo "------ ovn-sbctl show ------"
1439ovn-sbctl show
1440
1441echo "------ hv1 ------"
1442as hv1 ovs-vsctl show
1443echo "------ hv1 br-int ------"
1444as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-int
1445echo "------ hv1 br-phys ------"
1446as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-phys
1447
1448echo "------ hv2 ------"
1449as hv2 ovs-vsctl show
1450echo "------ hv2 br-int ------"
1451as hv2 ovs-ofctl -O OpenFlow13 dump-flows br-int
1452echo "------ hv2 br-phys ------"
1453as hv2 ovs-ofctl -O OpenFlow13 dump-flows br-phys
1454
1455echo "------ hv_gw ------"
1456as hv_gw ovs-vsctl show
1457echo "------ hv_gw br-phys ------"
1458as hv_gw ovs-ofctl -O OpenFlow13 dump-flows br-phys
1459echo "------ hv_gw br-phys2 ------"
1460as hv_gw ovs-ofctl -O OpenFlow13 dump-flows br-phys2
1461
1462echo "------ hv3 ------"
1463as hv3 ovs-vsctl show
1464echo "------ hv3 br-phys ------"
1465as hv3 ovs-ofctl -O OpenFlow13 dump-flows br-phys
1466
1467# Now check the packets actually received against the ones expected.
1468for i in 1 2 3; do
1469 file=hv$i/vif$i-tx.pcap
1470 echo $file
1471 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" $file | trim_zeros > $i.packets
1472 sort $i.expected > expout
1473 AT_CHECK([sort $i.packets], [0], [expout])
1474 echo
1475done
1476AT_CLEANUP
1477
9975d7be
BP
1478# 3 hypervisors, 3 logical switches with 3 logical ports each, 1 logical router
1479AT_SETUP([ovn -- 3 HVs, 3 LS, 3 lports/LS, 1 LR])
1480AT_SKIP_IF([test $HAVE_PYTHON = no])
1481ovn_start
1482
1483# Logical network:
1484#
1485# Three logical switches ls1, ls2, ls3.
86e98048
BP
1486# One logical router lr0 connected to ls[123],
1487# with nine subnets, three per logical switch:
1488#
1489# lrp11 on ls1 for subnet 192.168.11.0/24
1490# lrp12 on ls1 for subnet 192.168.12.0/24
1491# lrp13 on ls1 for subnet 192.168.13.0/24
1492# ...
1493# lrp33 on ls3 for subnet 192.168.33.0/24
1494#
1495# 27 VIFs, 9 per LS, 3 per subnet: lp[123][123][123], where the first two
1496# digits are the subnet and the last digit distinguishes the VIF.
9975d7be 1497for i in 1 2 3; do
ea46a4e9 1498 ovn-nbctl ls-add ls$i
9975d7be 1499 for j in 1 2 3; do
86e98048 1500 for k in 1 2 3; do
31ed1192
JP
1501 # Add "unknown" to MAC addresses for lp?11, so packets for
1502 # MAC-IP bindings discovered via ARP later have somewhere to go.
1503 if test $j$k = 11; then unknown=unknown; else unknown=; fi
1504
1505 ovn-nbctl \
1506 -- lsp-add ls$i lp$i$j$k \
1507 -- lsp-set-addresses lp$i$j$k "f0:00:00:00:0$i:$j$k \
1508 192.168.$i$j.$k" $unknown
86e98048
BP
1509 done
1510 done
1511done
1512
fa2a27b2 1513ovn-nbctl lr-add lr0
86e98048
BP
1514for i in 1 2 3; do
1515 for j in 1 2 3; do
bf44c2cd 1516 ovn-nbctl lrp-add lr0 lrp$i$j 00:00:00:00:ff:$i$j 192.168.$i$j.254/24
269ecccc 1517 ovn-nbctl \
31ed1192 1518 -- lsp-add ls$i lrp$i$j-attachment \
269ecccc 1519 -- set Logical_Switch_Port lrp$i$j-attachment type=router \
00007447 1520 options:router-port=lrp$i$j \
86e98048 1521 addresses='"00:00:00:00:ff:'$i$j'"'
9975d7be
BP
1522 done
1523done
1524
80f408f4 1525ovn-nbctl set Logical_Switch_Port lrp33-attachment \
57d143eb
HZ
1526 addresses='"00:00:00:00:ff:33 192.168.33.254"'
1527
9975d7be
BP
1528# Physical network:
1529#
1530# Three hypervisors hv[123].
86e98048
BP
1531# lp?1[123] spread across hv[123]: lp?11 on hv1, lp?12 on hv2, lp?13 on hv3.
1532# lp?2[123] spread across hv[23]: lp?21 and lp?22 on hv2, lp?23 on hv3.
1533# lp?3[123] all on hv3.
1534
9975d7be
BP
1535
1536# Given the name of a logical port, prints the name of the hypervisor
1537# on which it is located.
1538vif_to_hv() {
1539 case $1 in dnl (
86e98048
BP
1540 ?11) echo 1 ;; dnl (
1541 ?12 | ?21 | ?22) echo 2 ;; dnl (
1542 ?13 | ?23 | ?3?) echo 3 ;;
9975d7be
BP
1543 esac
1544}
1545
86e98048
BP
1546# Given the name of a logical port, prints the name of its logical router
1547# port, e.g. "vif_to_lrp 123" yields 12.
1548vif_to_lrp() {
1549 echo ${1%?}
1550}
1551
1552# Given the name of a logical port, prints the name of its logical
1553# switch, e.g. "vif_to_ls 123" yields 1.
e3393e3f 1554vif_to_ls() {
86e98048 1555 echo ${1%??}
e3393e3f
BP
1556}
1557
9975d7be
BP
1558net_add n1
1559for i in 1 2 3; do
1560 sim_add hv$i
1561 as hv$i
1562 ovs-vsctl add-br br-phys
1563 ovn_attach n1 br-phys 192.168.0.$i
1564done
1565for i in 1 2 3; do
1566 for j in 1 2 3; do
86e98048 1567 for k in 1 2 3; do
269ecccc
JP
1568 hv=`vif_to_hv $i$j$k`
1569 as hv$hv ovs-vsctl \
1570 -- add-port br-int vif$i$j$k \
1571 -- set Interface vif$i$j$k \
1572 external-ids:iface-id=lp$i$j$k \
1573 options:tx_pcap=hv$hv/vif$i$j$k-tx.pcap \
1574 options:rxq_pcap=hv$hv/vif$i$j$k-rx.pcap \
1575 ofport-request=$i$j$k
86e98048 1576 done
9975d7be
BP
1577 done
1578done
1579
1580# Pre-populate the hypervisors' ARP tables so that we don't lose any
1581# packets for ARP resolution (native tunneling doesn't queue packets
1582# for ARP resolution).
1583ovn_populate_arp
1584
1585# Allow some time for ovn-northd and ovn-controller to catch up.
1586# XXX This should be more systematic.
1587sleep 1
1588
e3393e3f 1589# test_ip INPORT SRC_MAC DST_MAC SRC_IP DST_IP OUTPORT...
9975d7be
BP
1590#
1591# This shell function causes a packet to be received on INPORT. The packet's
1592# content has Ethernet destination DST and source SRC (each exactly 12 hex
1593# digits) and Ethernet type ETHTYPE (4 hex digits). The OUTPORTs (zero or
1594# more) list the VIFs on which the packet should be received. INPORT and the
31ed1192 1595# OUTPORTs are specified as logical switch port numbers, e.g. 123 for vif123.
9975d7be
BP
1596trim_zeros() {
1597 sed 's/\(00\)\{1,\}$//'
1598}
1599for i in 1 2 3; do
1600 for j in 1 2 3; do
86e98048
BP
1601 for k in 1 2 3; do
1602 : > $i$j$k.expected
269ecccc 1603 done
9975d7be
BP
1604 done
1605done
e3393e3f 1606test_ip() {
9975d7be
BP
1607 # This packet has bad checksums but logical L3 routing doesn't check.
1608 local inport=$1 src_mac=$2 dst_mac=$3 src_ip=$4 dst_ip=$5
ba43992e 1609 local packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
9975d7be
BP
1610 shift; shift; shift; shift; shift
1611 hv=hv`vif_to_hv $inport`
1612 as $hv ovs-appctl netdev-dummy/receive vif$inport $packet
1613 #as $hv ovs-appctl ofproto/trace br-int in_port=$inport $packet
86e98048
BP
1614 in_ls=`vif_to_ls $inport`
1615 in_lrp=`vif_to_lrp $inport`
9975d7be 1616 for outport; do
269ecccc 1617 out_ls=`vif_to_ls $outport`
86e98048 1618 if test $in_ls = $out_ls; then
9975d7be
BP
1619 # Ports on the same logical switch receive exactly the same packet.
1620 echo $packet
1621 else
1622 # Routing decrements TTL and updates source and dest MAC
1623 # (and checksum).
269ecccc 1624 out_lrp=`vif_to_lrp $outport`
86e98048 1625 echo f00000000${outport}00000000ff${out_lrp}08004500001c00000000"3f1101"00${src_ip}${dst_ip}0035111100080000
9975d7be
BP
1626 fi | trim_zeros >> $outport.expected
1627 done
1628}
1629
e3393e3f 1630as hv1 ovs-vsctl --columns=name,ofport list interface
0bac7164
BP
1631as hv1 ovn-sbctl list port_binding
1632as hv1 ovn-sbctl list datapath_binding
9975d7be
BP
1633as hv1 ovn-sbctl dump-flows
1634as hv1 ovs-ofctl dump-flows br-int
1635
e3393e3f 1636# Send IP packets between all pairs of source and destination ports:
9975d7be 1637#
31ed1192
JP
1638# 1. Unicast IP packets are delivered to exactly one logical switch port
1639# (except that packets destined to their input ports are dropped).
9975d7be 1640#
31ed1192
JP
1641# 2. Broadcast IP packets are delivered to all logical switch ports
1642# except the input port.
86e98048
BP
1643ip_to_hex() {
1644 printf "%02x%02x%02x%02x" "$@"
1645}
9975d7be 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 bcast=
1650 s=$is$js$ks
1651 smac=f00000000$s
1652 sip=`ip_to_hex 192 168 $is$js $ks`
1653 for id in 1 2 3; do
1654 for jd in 1 2 3; do
1655 for kd in 1 2 3; do
1656 d=$id$jd$kd
1657 dip=`ip_to_hex 192 168 $id$jd $kd`
1658 if test $is = $id; then dmac=f00000000$d; else dmac=00000000ff$is$js; fi
1659 if test $d != $s; then unicast=$d; else unicast=; fi
1660
1661 test_ip $s $smac $dmac $sip $dip $unicast #1
1662
1663 if test $id = $is && test $d != $s; then bcast="$bcast $d"; fi
1664 done
1665 done
9975d7be 1666 done
269ecccc
JP
1667 test_ip $s $smac ffffffffffff $sip ffffffff $bcast #2
1668 done
1669 done
e3393e3f
BP
1670done
1671
0bac7164
BP
1672# 3. Send an IP packet from every logical port to every other subnet,
1673# to an IP address that does not have a static IP-MAC binding.
1674# This should generate a broadcast ARP request for the destination
1675# IP address in the destination subnet.
1676for is in 1 2 3; do
269ecccc
JP
1677 for js in 1 2 3; do
1678 for ks in 1 2 3; do
1679 s=$is$js$ks
1680 smac=f00000000$s
1681 sip=`ip_to_hex 192 168 $is$js $ks`
1682 for id in 1 2 3; do
1683 for jd in 1 2 3; do
1684 if test $is$js = $id$jd; then
1685 continue
1686 fi
1687
1688 # Send the packet.
1689 dmac=00000000ff$is$js
1690 # Calculate a 4th octet for the destination that is
1691 # unique per $s, avoids the .1 .2 .3 and .254 IP addresses
1692 # that have static MAC bindings, and fits in the range
1693 # 0-255.
1694 o4=`expr $is '*' 9 + $js '*' 3 + $ks + 10`
1695 dip=`ip_to_hex 192 168 $id$jd $o4`
1696 test_ip $s $smac $dmac $sip $dip
1697
1698 # Every LP on the destination subnet's lswitch should
1699 # receive the ARP request.
1700 lrmac=00000000ff$id$jd
1701 lrip=`ip_to_hex 192 168 $id$jd 254`
1702 arp=ffffffffffff${lrmac}08060001080006040001${lrmac}${lrip}000000000000${dip}
1703 for jd2 in 1 2 3; do
1704 for kd in 1 2 3; do
1705 echo $arp | trim_zeros >> $id$jd2$kd.expected
0bac7164 1706 done
269ecccc 1707 done
0bac7164 1708 done
269ecccc 1709 done
0bac7164 1710 done
269ecccc 1711 done
0bac7164
BP
1712done
1713
e3393e3f
BP
1714# test_arp INPORT SHA SPA TPA [REPLY_HA]
1715#
1716# Causes a packet to be received on INPORT. The packet is an ARP
1717# request with SHA, SPA, and TPA as specified. If REPLY_HA is provided, then
1718# it should be the hardware address of the target to expect to receive in an
1719# ARP reply; otherwise no reply is expected.
1720#
31ed1192 1721# INPORT is an logical switch port number, e.g. 11 for vif11.
e3393e3f
BP
1722# SHA and REPLY_HA are each 12 hex digits.
1723# SPA and TPA are each 8 hex digits.
1724test_arp() {
1725 local inport=$1 sha=$2 spa=$3 tpa=$4 reply_ha=$5
1726 local request=ffffffffffff${sha}08060001080006040001${sha}${spa}ffffffffffff${tpa}
1727 hv=hv`vif_to_hv $inport`
1728 as $hv ovs-appctl netdev-dummy/receive vif$inport $request
1729 #as $hv ovs-appctl ofproto/trace br-int in_port=$inport $request
1730
57d143eb 1731 # Expect to receive the broadcast ARP on the other logical switch ports if
ea46a4e9 1732 # IP address is not configured to the switch patch port.
e3393e3f 1733 local i=`vif_to_ls $inport`
86e98048 1734 local j k
e3393e3f 1735 for j in 1 2 3; do
86e98048 1736 for k in 1 2 3; do
ea46a4e9 1737 # 192.168.33.254 is configured to the switch patch port for lrp33,
57d143eb
HZ
1738 # so no ARP flooding expected for it.
1739 if test $i$j$k != $inport && test $tpa != `ip_to_hex 192 168 33 254`; then
86e98048
BP
1740 echo $request >> $i$j$k.expected
1741 fi
1742 done
e3393e3f
BP
1743 done
1744
1745 # Expect to receive the reply, if any.
1746 if test X$reply_ha != X; then
86e98048
BP
1747 lrp=`vif_to_lrp $inport`
1748 local reply=${sha}00000000ff${lrp}08060001080006040002${reply_ha}${tpa}${sha}${spa}
e3393e3f
BP
1749 echo $reply >> $inport.expected
1750 fi
1751}
1752
1753# Test router replies to ARP requests from all source ports:
1754#
0bac7164 1755# 4. Router replies to query for its MAC address from port's own IP address.
e3393e3f 1756#
0bac7164 1757# 5. Router replies to query for its MAC address from any random IP address
e3393e3f
BP
1758# in its subnet.
1759#
0bac7164 1760# 6. Router replies to query for its MAC address from another subnet.
e3393e3f 1761#
0bac7164 1762# 7. No reply to query for IP address other than router IP.
e3393e3f 1763for i in 1 2 3; do
269ecccc
JP
1764 for j in 1 2 3; do
1765 for k in 1 2 3; do
1766 smac=f00000000$i$j$k # Source MAC
1767 sip=`ip_to_hex 192 168 $i$j $k` # Source IP
1768 rip=`ip_to_hex 192 168 $i$j 254` # Router IP
1769 rmac=00000000ff$i$j # Router MAC
1770 otherip=`ip_to_hex 192 168 $i$j 55` # Some other IP in subnet
1771 test_arp $i$j$k $smac $sip $rip $rmac #4
1772 test_arp $i$j$k $smac $otherip $rip $rmac #5
1773 test_arp $i$j$k $smac 0a123456 $rip $rmac #6
1774 test_arp $i$j$k $smac $sip $otherip #7
0bac7164 1775 done
269ecccc 1776 done
0bac7164
BP
1777done
1778
1779# Allow some time for packet forwarding.
1780# XXX This can be improved.
1781sleep 1
1782
1783# 8. Generate an ARP reply for each of the IP addresses ARPed for
1784# earlier as #3.
1785#
1786# Here, the $s is the VIF that originated the ARP request and $d is
1787# the VIF that sends the ARP reply, which is somewhat backward but
1788# it means that $s and $d are the same as #3.
1789: > mac_bindings.expected
1790for is in 1 2 3; do
269ecccc
JP
1791 for js in 1 2 3; do
1792 for ks in 1 2 3; do
1793 s=$is$js$ks
1794 for id in 1 2 3; do
1795 for jd in 1 2 3; do
1796 if test $is$js = $id$jd; then
1797 continue
1798 fi
1799
1800 kd=1
1801 d=$id$jd$kd
1802
1803 o4=`expr $is '*' 9 + $js '*' 3 + $ks + 10`
1804 host_ip=`ip_to_hex 192 168 $id$jd $o4`
1805 host_mac=8000000000$o4
1806
1807 lrmac=00000000ff$id$jd
1808 lrip=`ip_to_hex 192 168 $id$jd 254`
1809
1810 arp=${lrmac}${host_mac}08060001080006040002${host_mac}${host_ip}${lrmac}${lrip}
1811
1812 echo
1813 echo
1814 echo
1815 hv=hv`vif_to_hv $d`
1816 as $hv ovs-appctl netdev-dummy/receive vif$d $arp
1817 #as $hv ovs-appctl ofproto/trace br-int in_port=$d $arp
1818 #as $hv ovs-ofctl dump-flows br-int table=19
1819
1820 host_ip_pretty=192.168.$id$jd.$o4
1821 host_mac_pretty=80:00:00:00:00:$o4
1822 echo lrp$id$jd,$host_ip_pretty,$host_mac_pretty >> mac_bindings.expected
86e98048 1823 done
269ecccc 1824 done
9975d7be 1825 done
269ecccc 1826 done
9975d7be 1827done
0bac7164 1828
9975d7be
BP
1829# Allow some time for packet forwarding.
1830# XXX This can be improved.
1831sleep 1
1832
0bac7164
BP
1833# 9. Send an IP packet from every logical port to every other subnet. These
1834# are the same packets already sent as #3, but now the destinations' IP-MAC
1835# bindings have been discovered via ARP, so instead of provoking an ARP
1836# request, these packets now get routed to their destinations (which don't
1837# have static MAC bindings, so they go to the port we've designated as
1838# accepting "unknown" MACs.)
1839for is in 1 2 3; do
269ecccc
JP
1840 for js in 1 2 3; do
1841 for ks in 1 2 3; do
1842 s=$is$js$ks
1843 smac=f00000000$s
1844 sip=`ip_to_hex 192 168 $is$js $ks`
1845 for id in 1 2 3; do
1846 for jd in 1 2 3; do
1847 if test $is$js = $id$jd; then
1848 continue
1849 fi
1850
1851 # Send the packet.
1852 dmac=00000000ff$is$js
1853 # Calculate a 4th octet for the destination that is
1854 # unique per $s, avoids the .1 .2 .3 and .254 IP addresses
1855 # that have static MAC bindings, and fits in the range
1856 # 0-255.
1857 o4=`expr $is '*' 9 + $js '*' 3 + $ks + 10`
1858 dip=`ip_to_hex 192 168 $id$jd $o4`
1859 test_ip $s $smac $dmac $sip $dip
1860
1861 # Expect the packet egress.
1862 host_mac=8000000000$o4
1863 outport=${id}11
1864 out_lrp=$id$jd
1865 echo ${host_mac}00000000ff${out_lrp}08004500001c00000000"3f1101"00${sip}${dip}0035111100080000 | trim_zeros >> $outport.expected
0bac7164 1866 done
269ecccc 1867 done
0bac7164 1868 done
269ecccc 1869 done
0bac7164
BP
1870done
1871
1872# Allow some time for packet forwarding.
1873# XXX This can be improved.
1874sleep 1
1875
1876ovn-sbctl -f csv -d bare --no-heading \
1877 -- --columns=logical_port,ip,mac list mac_binding > mac_bindings
1878
9975d7be
BP
1879# Now check the packets actually received against the ones expected.
1880for i in 1 2 3; do
1881 for j in 1 2 3; do
86e98048 1882 for k in 1 2 3; do
269ecccc
JP
1883 file=hv`vif_to_hv $i$j$k`/vif$i$j$k-tx.pcap
1884 echo $file
1885 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" $file | trim_zeros > $i$j$k.packets
1886 sort $i$j$k.expected > expout
1887 AT_CHECK([sort $i$j$k.packets], [0], [expout])
1888 echo
86e98048 1889 done
9975d7be
BP
1890 done
1891done
fcde56f5 1892
0bac7164
BP
1893# Check the MAC bindings against those expected.
1894AT_CHECK_UNQUOTED([sort < mac_bindings], [0], [`sort < mac_bindings.expected`
1895])
1896
fcde56f5 1897# Gracefully terminate daemons
7a8f15e0 1898OVN_CLEANUP([hv1], [hv2], [hv3])
eff49a56 1899
9975d7be 1900AT_CLEANUP
685f4dfe
NS
1901
1902# 3 hypervisors, one logical switch, 3 logical ports per hypervisor
1903AT_SETUP([ovn -- portsecurity : 3 HVs, 1 LS, 3 lports/HV])
1904AT_KEYWORDS([portsecurity])
1905AT_SKIP_IF([test $HAVE_PYTHON = no])
1906ovn_start
1907
1908# Create hypervisors hv[123].
1909# Add vif1[123] to hv1, vif2[123] to hv2, vif3[123] to hv3.
1910# Add all of the vifs to a single logical switch lsw0.
1911# Turn off port security on vifs vif[123]1
1912# Turn on l2 port security on vifs vif[123]2
1913# Turn of l2 and l3 port security on vifs vif[123]3
1914# Make vif13, vif2[23], vif3[123] destinations for unknown MACs.
ea46a4e9 1915ovn-nbctl ls-add lsw0
685f4dfe
NS
1916net_add n1
1917for i in 1 2 3; do
1918 sim_add hv$i
1919 as hv$i
1920 ovs-vsctl add-br br-phys
1921 ovn_attach n1 br-phys 192.168.0.$i
1922
1923 for j in 1 2 3; do
1924 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 1925 ovn-nbctl lsp-add lsw0 lp$i$j
685f4dfe 1926 if test $j = 1; then
31ed1192 1927 ovn-nbctl lsp-set-addresses lp$i$j "f0:00:00:00:00:$i$j 192.168.0.$i$j" unknown
685f4dfe 1928 elif test $j = 2; then
31ed1192
JP
1929 ovn-nbctl lsp-set-addresses lp$i$j "f0:00:00:00:00:$i$j 192.168.0.$i$j"
1930 ovn-nbctl lsp-set-port-security lp$i$j f0:00:00:00:00:$i$j
685f4dfe
NS
1931 else
1932 extra_addr="f0:00:00:00:0$i:$i$j fe80::ea2a:eaff:fe28:$i$j"
31ed1192
JP
1933 ovn-nbctl lsp-set-addresses lp$i$j "f0:00:00:00:00:$i$j 192.168.0.$i$j" "$extra_addr"
1934 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
1935 fi
1936 done
1937done
1938
685f4dfe
NS
1939# Pre-populate the hypervisors' ARP tables so that we don't lose any
1940# packets for ARP resolution (native tunneling doesn't queue packets
1941# for ARP resolution).
1942ovn_populate_arp
1943
1944# Allow some time for ovn-northd and ovn-controller to catch up.
1945# XXX This should be more systematic.
1946sleep 1
685f4dfe
NS
1947
1948# Given the name of a logical port, prints the name of the hypervisor
1949# on which it is located.
1950vif_to_hv() {
1951 echo hv${1%?}
1952}
1953
1954
1955trim_zeros() {
1956 sed 's/\(00\)\{1,\}$//'
1957}
1958for i in 1 2 3; do
1959 for j in 1 2 3; do
1960 : > $i$j.expected
1961 done
1962done
1963
1964# test_ip INPORT SRC_MAC DST_MAC SRC_IP DST_IP OUTPORT...
1965#
1966# This shell function causes an ip packet to be received on INPORT.
1967# The packet's content has Ethernet destination DST and source SRC
1968# (each exactly 12 hex digits) and Ethernet type ETHTYPE (4 hex digits).
1969# The OUTPORTs (zero or more) list the VIFs on which the packet should
31ed1192
JP
1970# be received. INPORT and the OUTPORTs are specified as logical switch
1971# port numbers, e.g. 11 for vif11.
685f4dfe
NS
1972test_ip() {
1973 # This packet has bad checksums but logical L3 routing doesn't check.
1974 local inport=$1 src_mac=$2 dst_mac=$3 src_ip=$4 dst_ip=$5
1975 local packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}003511110008
1976 shift; shift; shift; shift; shift
1977 hv=`vif_to_hv $inport`
1978 as $hv ovs-appctl netdev-dummy/receive vif$inport $packet
1979 #as $hv ovs-appctl ofproto/trace br-int in_port=$inport $packet
1980 for outport; do
1981 echo $packet | trim_zeros >> $outport.expected
1982 done
1983}
1984
1985# test_arp INPORT SHA SPA TPA DROP [REPLY_HA]
1986#
1987# Causes a packet to be received on INPORT. The packet is an ARP
1988# request with SHA, SPA, and TPA as specified. If REPLY_HA is provided, then
1989# it should be the hardware address of the target to expect to receive in an
1990# ARP reply; otherwise no reply is expected.
1991#
31ed1192 1992# INPORT is an logical switch port number, e.g. 11 for vif11.
685f4dfe
NS
1993# SHA and REPLY_HA are each 12 hex digits.
1994# SPA and TPA are each 8 hex digits.
1995test_arp() {
1996 local inport=$1 smac=$2 sha=$3 spa=$4 tpa=$5 drop=$6 reply_ha=$7
1997 local request=ffffffffffff${smac}08060001080006040001${sha}${spa}ffffffffffff${tpa}
1998 hv=`vif_to_hv $inport`
1999 as $hv ovs-appctl netdev-dummy/receive vif$inport $request
2000 #as $hv ovs-appctl ofproto/trace br-int in_port=$inport $request
2001 if test $drop != 1; then
e137131a 2002 if test X$reply_ha = X; then
685f4dfe
NS
2003 # Expect to receive the broadcast ARP on the other logical switch ports
2004 # if no reply is expected.
2005 local i j
2006 for i in 1 2 3; do
2007 for j in 1 2 3; do
2008 if test $i$j != $inport; then
2009 echo $request >> $i$j.expected
2010 fi
2011 done
2012 done
2013 else
2014 # Expect to receive the reply, if any.
2015 local reply=${smac}${reply_ha}08060001080006040002${reply_ha}${tpa}${sha}${spa}
2016 echo $reply >> $inport.expected
2017 fi
2018 fi
2019}
2020
2021# test_ipv6 INPORT SRC_MAC DST_MAC SRC_IP DST_IP OUTPORT...
2022# This function is similar to test_ip() except that it sends
2023# ipv6 packet
2024test_ipv6() {
2025 local inport=$1 src_mac=$2 dst_mac=$3 src_ip=$4 dst_ip=$5
2026 local packet=${dst_mac}${src_mac}86dd6000000000083aff${src_ip}${dst_ip}0000000000000000
2027 shift; shift; shift; shift; shift
2028 hv=`vif_to_hv $inport`
2029 as $hv ovs-appctl netdev-dummy/receive vif$inport $packet
2030 #as $hv ovs-appctl ofproto/trace br-int in_port=$inport $packet
2031 for outport; do
2032 echo $packet | trim_zeros >> $outport.expected
2033 done
2034}
2035
9e687b23
DL
2036# test_icmpv6 INPORT SRC_MAC DST_MAC SRC_IP DST_IP ICMP_TYPE OUTPORT...
2037# This function is similar to test_ipv6() except it specifies the ICMPv6 type
2038# of the test packet
2039test_icmpv6() {
2040 local inport=$1 src_mac=$2 dst_mac=$3 src_ip=$4 dst_ip=$5 icmp_type=$6
2041 local packet=${dst_mac}${src_mac}86dd6000000000083aff${src_ip}${dst_ip}${icmp_type}00000000000000
2042 shift; shift; shift; shift; shift; shift
2043 hv=`vif_to_hv $inport`
2044 as $hv ovs-appctl netdev-dummy/receive vif$inport $packet
2045 #as $hv ovs-appctl ofproto/trace br-int in_port=$inport $packet
2046 for outport; do
2047 echo $packet | trim_zeros >> $outport.expected
2048 done
2049}
2050
685f4dfe
NS
2051ip_to_hex() {
2052 printf "%02x%02x%02x%02x" "$@"
2053}
2054
2055# no port security
2056sip=`ip_to_hex 192 168 0 12`
2057tip=`ip_to_hex 192 168 0 13`
2058# the arp packet should be allowed even if lp[123]1 is
2059# not configured with mac f00000000023 and ip 192.168.0.12
2060for i in 1 2 3; do
2061 test_arp ${i}1 f00000000023 f00000000023 $sip $tip 0 f00000000013
2062 for j in 1 2 3; do
2063 if test $i != $j; then
2064 test_ip ${i}1 f000000000${i}1 f000000000${j}1 $sip $tip ${j}1
2065 fi
2066 done
2067done
2068
2069# l2 port security
2070sip=`ip_to_hex 192 168 0 12`
2071tip=`ip_to_hex 192 168 0 13`
2072
2073# arp packet should be allowed since lp22 is configured with
2074# mac f00000000022
2075test_arp 22 f00000000022 f00000000022 $sip $tip 0 f00000000013
2076
2077# arp packet should not be allowed since lp32 is not configured with
2078# mac f00000000021
2079test_arp 32 f00000000021 f00000000021 $sip $tip 1
2080
2081# arp packet with sha set to f00000000021 should not be allowed
2082# for lp12
2083test_arp 12 f00000000012 f00000000021 $sip $tip 1
2084
2085# ip packets should be allowed and received since lp[123]2 do not
2086# have l3 port security
2087sip=`ip_to_hex 192 168 0 55`
2088tip=`ip_to_hex 192 168 0 66`
2089for i in 1 2 3; do
2090 for j in 1 2 3; do
2091 if test $i != $j; then
2092 test_ip ${i}2 f000000000${i}2 f000000000${j}2 $sip $tip ${j}2
2093 fi
2094 done
2095done
2096
2097# ipv6 packets should be received by lp[123]2
2098# lp[123]1 can send ipv6 traffic as there is no port security
2099sip=fe800000000000000000000000000000
2100tip=ff020000000000000000000000000000
2101
2102for i in 1 2 3; do
2103 test_ipv6 ${i}1 f000000000${i}1 f000000000${i}2 $sip $tip ${i}2
2104done
2105
2106
2107# l2 and l3 port security
2108sip=`ip_to_hex 192 168 0 13`
2109tip=`ip_to_hex 192 168 0 22`
2110# arp packet should be allowed since lp13 is configured with
2111# f00000000013 and 192.168.0.13
2112test_arp 13 f00000000013 f00000000013 $sip $tip 0 f00000000022
2113
2114# the arp packet should be dropped because lp23 is not configured
2115# with mac f00000000022
2116sip=`ip_to_hex 192 168 0 13`
2117tip=`ip_to_hex 192 168 0 22`
2118test_arp 23 f00000000022 f00000000022 $sip $tip 1
2119
2120# the arp packet should be dropped because lp33 is not configured
2121# with ip 192.168.0.55
2122spa=`ip_to_hex 192 168 0 55`
2123tpa=`ip_to_hex 192 168 0 22`
2124test_arp 33 f00000000031 f00000000031 $spa $tpa 1
2125
2126# ip packets should not be received by lp[123]3 since
2127# l3 port security is enabled
2128sip=`ip_to_hex 192 168 0 55`
2129tip=`ip_to_hex 192 168 0 66`
2130for i in 1 2 3; do
2131 for j in 1 2 3; do
2132 test_ip ${i}2 f000000000${i}2 f000000000${j}3 $sip $tip
2133 done
2134done
2135
2136# ipv6 packets should be dropped for lp[123]3 since
2137# it is configured with only ipv4 address
2138sip=fe800000000000000000000000000000
2139tip=ff020000000000000000000000000000
2140
2141for i in 1 2 3; do
2142 test_ipv6 ${i}3 f000000000${i}3 f00000000022 $sip $tip
2143done
2144
2145# ipv6 packets should not be received by lp[123]3 with mac f000000000$[123]3
2146# lp[123]1 can send ipv6 traffic as there is no port security
2147for i in 1 2 3; do
2148 test_ipv6 ${i}1 f000000000${i}1 f000000000${i}3 $sip $tip
2149done
2150
2151# lp13 has extra port security with mac f0000000113 and ipv6 addr
2152# fe80::ea2a:eaff:fe28:0012
2153
2154# ipv4 packet should be dropped for lp13 with mac f0000000113
2155sip=`ip_to_hex 192 168 0 13`
2156tip=`ip_to_hex 192 168 0 23`
2157test_ip 13 f00000000113 f00000000023 $sip $tip
2158
2159# ipv6 packet should be received by lp[123]3 with mac f0000000{i}{i}3
2160# and ip6.dst as fe80::ea2a:eaff:fe28:0{i}{i}3.
2161# lp11 can send ipv6 traffic as there is no port security
2162sip=ee800000000000000000000000000000
2163for i in 1 2 3; do
2164 tip=fe80000000000000ea2aeafffe2800{i}3
2165 test_ipv6 11 f00000000011 f000000000{i}${i}3 $sip $tip {i}3
2166done
2167
2168
2169# ipv6 packet should not be received by lp33 with mac f0000000333
2170# and ip6.dst as fe80::ea2a:eaff:fe28:0023 as it is
2171# configured with fe80::ea2a:eaff:fe28:0033
2172# lp11 can send ipv6 traffic as there is no port security
2173
2174sip=ee800000000000000000000000000000
2175tip=fe80000000000000ea2aeafffe280023
2176test_ipv6 11 f00000000011 f00000000333 $sip $tip
2177
2178# ipv6 packet should be allowed for lp[123]3 with mac f0000000{i}{i}3
2179# and ip6.src fe80::ea2a:eaff:fe28:0{i}{i}3 and ip6.src ::.
2180# and should be dropped for any other ip6.src
2181# lp21 can receive ipv6 traffic as there is no port security
2182
2183tip=ee800000000000000000000000000000
2184for i in 1 2 3; do
2185 sip=fe80000000000000ea2aeafffe2800${i}3
2186 test_ipv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip $tip 21
2187
9e687b23 2188 # Test ICMPv6 MLD reports (v1 and v2) and NS for DAD
685f4dfe 2189 sip=00000000000000000000000000000000
9e687b23
DL
2190 test_icmpv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip ff020000000000000000000000160000 83 21
2191 test_icmpv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip ff020000000000000000000000160000 8f 21
2192 test_icmpv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip ff0200000000000000ea2aeafffe2800 87 21
2193 # Traffic to non-multicast traffic should be dropped
2194 test_icmpv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip $tip 83
2195 # Traffic of other ICMPv6 types should be dropped
2196 test_icmpv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip ff020000000000000000000000160000 80
685f4dfe
NS
2197
2198 # should be dropped
2199 sip=ae80000000000000ea2aeafffe2800aa
2200 test_ipv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip $tip
2201done
2202
31ed1192
JP
2203# configure lsp13 to send and received IPv4 packets with an address range
2204ovn-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 2205
8ff5a966
NS
2206sleep 2
2207
7d9d86ad
NS
2208sip=`ip_to_hex 10 0 0 13`
2209tip=`ip_to_hex 192 168 0 22`
31ed1192 2210# arp packet with inner ip 10.0.0.13 should be allowed for lsp13
7d9d86ad
NS
2211test_arp 13 f00000000013 f00000000013 $sip $tip 0 f00000000022
2212
2213sip=`ip_to_hex 10 0 0 14`
2214tip=`ip_to_hex 192 168 0 23`
31ed1192 2215# IPv4 packet from lsp13 with src ip 10.0.0.14 destined to lsp23
7d9d86ad
NS
2216# with dst ip 192.168.0.23 should be allowed
2217test_ip 13 f00000000013 f00000000023 $sip $tip 23
2218
2219sip=`ip_to_hex 192 168 0 33`
2220tip=`ip_to_hex 10 0 0 15`
31ed1192
JP
2221# IPv4 packet from lsp33 with src ip 192.168.0.33 destined to lsp13
2222# with dst ip 10.0.0.15 should be received by lsp13
7d9d86ad
NS
2223test_ip 33 f00000000033 f00000000013 $sip $tip 13
2224
2225sip=`ip_to_hex 192 168 0 33`
2226tip=`ip_to_hex 20 0 0 4`
31ed1192
JP
2227# IPv4 packet from lsp33 with src ip 192.168.0.33 destined to lsp13
2228# with dst ip 20.0.0.4 should be received by lsp13
7d9d86ad
NS
2229test_ip 33 f00000000033 f00000000013 $sip $tip 13
2230
2231sip=`ip_to_hex 192 168 0 33`
2232tip=`ip_to_hex 20 0 0 5`
31ed1192
JP
2233# IPv4 packet from lsp33 with src ip 192.168.0.33 destined to lsp13
2234# with dst ip 20.0.0.5 should not be received by lsp13
7d9d86ad
NS
2235test_ip 33 f00000000033 f00000000013 $sip $tip
2236
2237sip=`ip_to_hex 192 168 0 33`
2238tip=`ip_to_hex 20 0 0 255`
31ed1192
JP
2239# IPv4 packet from lsp33 with src ip 192.168.0.33 destined to lsp13
2240# with dst ip 20.0.0.255 should be received by lsp13
7d9d86ad
NS
2241test_ip 33 f00000000033 f00000000013 $sip $tip 13
2242
2243sip=`ip_to_hex 192 168 0 33`
2244tip=`ip_to_hex 192 168 0 255`
31ed1192
JP
2245# IPv4 packet from lsp33 with src ip 192.168.0.33 destined to lsp13
2246# with dst ip 192.168.0.255 should not be received by lsp13
7d9d86ad
NS
2247test_ip 33 f00000000033 f00000000013 $sip $tip
2248
2249sip=`ip_to_hex 192 168 0 33`
2250tip=`ip_to_hex 224 0 0 4`
31ed1192
JP
2251# IPv4 packet from lsp33 with src ip 192.168.0.33 destined to lsp13
2252# with dst ip 224.0.0.4 should be received by lsp13
7d9d86ad 2253test_ip 33 f00000000033 f00000000013 $sip $tip 13
685f4dfe
NS
2254
2255# Allow some time for packet forwarding.
2256
2257# XXX This can be improved.
2258sleep 1
2259
bb0c41d3
RM
2260#dump information including flow counters
2261ovn-nbctl show
2262ovn-sbctl dump-flows -- list multicast_group
2263
2264echo "------ hv1 dump ------"
2265as hv1 ovs-vsctl show
6195e2e7 2266as hv1 ovs-ofctl -O OpenFlow13 show br-int
bb0c41d3
RM
2267as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-int
2268
2269echo "------ hv2 dump ------"
2270as hv2 ovs-vsctl show
6195e2e7 2271as hv2 ovs-ofctl -O OpenFlow13 show br-int
bb0c41d3
RM
2272as hv2 ovs-ofctl -O OpenFlow13 dump-flows br-int
2273
2274echo "------ hv3 dump ------"
2275as hv3 ovs-vsctl show
6195e2e7 2276as hv3 ovs-ofctl -O OpenFlow13 show br-int
bb0c41d3
RM
2277as hv3 ovs-ofctl -O OpenFlow13 dump-flows br-int
2278
685f4dfe
NS
2279# Now check the packets actually received against the ones expected.
2280for i in 1 2 3; do
2281 for j in 1 2 3; do
2282 file=hv$i/vif$i$j-tx.pcap
2283 echo $file
2284 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" $file | trim_zeros > $i$j.packets
2285 sort $i$j.expected > expout
2286 AT_CHECK([sort $i$j.packets], [0], [expout])
2287 echo
2288 done
2289done
2290
7a8f15e0 2291OVN_CLEANUP([hv1],[hv2],[hv3])
d9c8c57c 2292
685f4dfe 2293AT_CLEANUP
509afdc3
GS
2294
2295AT_SETUP([ovn -- 2 HVs, 2 LS, 1 lport/LS, 2 peer LRs])
2296AT_KEYWORDS([ovnpeer])
2297AT_SKIP_IF([test $HAVE_PYTHON = no])
2298ovn_start
2299
2300# Logical network:
2301# Two LRs - R1 and R2 that are connected to each other as peers in 20.0.0.0/24
2302# network. R1 has a switchs ls1 (191.168.1.0/24) connected to it.
2303# R2 has ls2 (172.16.1.0/24) connected to it.
2304
fa2a27b2
JP
2305ovn-nbctl lr-add R1
2306ovn-nbctl lr-add R2
509afdc3 2307
ea46a4e9
JP
2308ovn-nbctl ls-add ls1
2309ovn-nbctl ls-add ls2
509afdc3
GS
2310
2311# Connect ls1 to R1
bf44c2cd 2312ovn-nbctl lrp-add R1 ls1 00:00:00:01:02:03 192.168.1.1/24
509afdc3 2313
31ed1192 2314ovn-nbctl lsp-add ls1 rp-ls1 -- set Logical_Switch_Port rp-ls1 type=router \
31114af7 2315 options:router-port=ls1 addresses=\"00:00:00:01:02:03\"
509afdc3
GS
2316
2317# Connect ls2 to R2
bf44c2cd 2318ovn-nbctl lrp-add R2 ls2 00:00:00:01:02:04 172.16.1.1/24
509afdc3 2319
31ed1192 2320ovn-nbctl lsp-add ls2 rp-ls2 -- set Logical_Switch_Port rp-ls2 type=router \
31114af7 2321 options:router-port=ls2 addresses=\"00:00:00:01:02:04\"
509afdc3
GS
2322
2323# Connect R1 to R2
4685e523
JP
2324ovn-nbctl lrp-add R1 R1_R2 00:00:00:02:03:04 20.0.0.1/24 peer=R2_R1
2325ovn-nbctl lrp-add R2 R2_R1 00:00:00:02:03:05 20.0.0.2/24 peer=R1_R2
509afdc3 2326
6d9ecfa9
JP
2327ovn-nbctl lr-route-add R1 "0.0.0.0/0" 20.0.0.2
2328ovn-nbctl lr-route-add R2 "0.0.0.0/0" 20.0.0.1
509afdc3
GS
2329
2330# Create logical port ls1-lp1 in ls1
31ed1192
JP
2331ovn-nbctl lsp-add ls1 ls1-lp1 \
2332-- lsp-set-addresses ls1-lp1 "f0:00:00:01:02:03 192.168.1.2"
509afdc3
GS
2333
2334# Create logical port ls2-lp1 in ls2
31ed1192
JP
2335ovn-nbctl lsp-add ls2 ls2-lp1 \
2336-- lsp-set-addresses ls2-lp1 "f0:00:00:01:02:04 172.16.1.2"
509afdc3
GS
2337
2338# Create two hypervisor and create OVS ports corresponding to logical ports.
2339net_add n1
2340
2341sim_add hv1
2342as hv1
2343ovs-vsctl add-br br-phys
2344ovn_attach n1 br-phys 192.168.0.1
2345ovs-vsctl -- add-port br-int hv1-vif1 -- \
2346 set interface hv1-vif1 external-ids:iface-id=ls1-lp1 \
2347 options:tx_pcap=hv1/vif1-tx.pcap \
2348 options:rxq_pcap=hv1/vif1-rx.pcap \
2349 ofport-request=1
2350
2351sim_add hv2
2352as hv2
2353ovs-vsctl add-br br-phys
2354ovn_attach n1 br-phys 192.168.0.2
2355ovs-vsctl -- add-port br-int hv2-vif1 -- \
2356 set interface hv2-vif1 external-ids:iface-id=ls2-lp1 \
2357 options:tx_pcap=hv2/vif1-tx.pcap \
2358 options:rxq_pcap=hv2/vif1-rx.pcap \
2359 ofport-request=1
2360
2361
2362# Pre-populate the hypervisors' ARP tables so that we don't lose any
2363# packets for ARP resolution (native tunneling doesn't queue packets
2364# for ARP resolution).
2365ovn_populate_arp
2366
2367# Allow some time for ovn-northd and ovn-controller to catch up.
2368# XXX This should be more systematic.
2369sleep 1
2370
2371# Send ip packets between the two ports.
2372ip_to_hex() {
2373 printf "%02x%02x%02x%02x" "$@"
2374}
2375trim_zeros() {
2376 sed 's/\(00\)\{1,\}$//'
2377}
2378
2379# Packet to send.
2380src_mac="f00000010203"
2381dst_mac="000000010203"
2382src_ip=`ip_to_hex 192 168 1 2`
2383dst_ip=`ip_to_hex 172 16 1 2`
2384packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
2385as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet
2386
2387
2388echo "---------NB dump-----"
2389ovn-nbctl show
2390echo "---------------------"
2391ovn-nbctl list logical_router
2392echo "---------------------"
2393ovn-nbctl list logical_router_port
2394echo "---------------------"
2395
2396echo "---------SB dump-----"
2397ovn-sbctl list datapath_binding
2398echo "---------------------"
2399ovn-sbctl list port_binding
2400echo "---------------------"
2401
2402echo "------ hv1 dump ----------"
8dab1022 2403as hv1 ovs-ofctl show br-int
509afdc3
GS
2404as hv1 ovs-ofctl dump-flows br-int
2405echo "------ hv2 dump ----------"
8dab1022 2406as hv2 ovs-ofctl show br-int
509afdc3
GS
2407as hv2 ovs-ofctl dump-flows br-int
2408
2409# Packet to Expect
2410src_mac="000000010204"
2411dst_mac="f00000010204"
2412expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000
2413
2414$PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv2/vif1-tx.pcap | trim_zeros > received.packets
2415echo $expected | trim_zeros > expout
2416AT_CHECK([cat received.packets], [0], [expout])
2417
7a8f15e0 2418OVN_CLEANUP([hv1],[hv2])
509afdc3
GS
2419
2420AT_CLEANUP
5412db30
J
2421
2422
4685e523
JP
2423AT_SETUP([ovn -- 1 HV, 1 LS, 2 lport/LS, 1 LR])
2424AT_KEYWORDS([router-admin-state])
2425AT_SKIP_IF([test $HAVE_PYTHON = no])
2426ovn_start
2427
2428# Logical network:
2429# One LR - R1 has switch ls1 with two subnets attached to it (191.168.1.0/24
2430# and 172.16.1.0/24) connected to it.
2431
2432ovn-nbctl lr-add R1
2433
2434ovn-nbctl ls-add ls1
2435
2436# Connect ls1 to R1
bf44c2cd 2437ovn-nbctl lrp-add R1 ls1 00:00:00:01:02:03 192.168.1.1/24 172.16.1.1/24
4685e523
JP
2438ovn-nbctl lsp-add ls1 rp-ls1 -- set Logical_Switch_Port rp-ls1 type=router \
2439 options:router-port=ls1 addresses=\"00:00:00:01:02:03\"
2440
2441# Create logical port ls1-lp1 in ls1
2442ovn-nbctl lsp-add ls1 ls1-lp1 \
2443 -- lsp-set-addresses ls1-lp1 "f0:00:00:01:02:03 192.168.1.2"
2444
2445# Create logical port ls1-lp2 in ls1
2446ovn-nbctl lsp-add ls1 ls1-lp2 \
2447 -- lsp-set-addresses ls1-lp2 "f0:00:00:01:02:04 172.16.1.2"
2448
2449# Create one hypervisor and create OVS ports corresponding to logical ports.
2450net_add n1
2451
2452sim_add hv1
2453as hv1
2454ovs-vsctl add-br br-phys
2455ovn_attach n1 br-phys 192.168.0.1
2456ovs-vsctl -- add-port br-int vif1 -- \
2457 set interface vif1 external-ids:iface-id=ls1-lp1 \
2458 options:tx_pcap=hv1/vif1-tx.pcap \
2459 options:rxq_pcap=hv1/vif1-rx.pcap \
2460 ofport-request=1
2461
2462ovs-vsctl -- add-port br-int vif2 -- \
2463 set interface vif2 external-ids:iface-id=ls1-lp2 \
2464 options:tx_pcap=hv1/vif2-tx.pcap \
2465 options:rxq_pcap=hv1/vif2-rx.pcap \
2466 ofport-request=1
2467
2468
2469# Allow some time for ovn-northd and ovn-controller to catch up.
2470# XXX This should be more systematic.
2471sleep 1
2472
2473# Send ip packets between the two ports.
2474ip_to_hex() {
2475 printf "%02x%02x%02x%02x" "$@"
2476}
2477trim_zeros() {
2478 sed 's/\(00\)\{1,\}$//'
2479}
2480
2481# Packet to send.
2482src_mac="f00000010203"
2483dst_mac="000000010203"
2484src_ip=`ip_to_hex 192 168 1 2`
2485dst_ip=`ip_to_hex 172 16 1 2`
2486packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
2487as hv1 ovs-appctl netdev-dummy/receive vif1 $packet
2488
2489
2490echo "---------NB dump-----"
2491ovn-nbctl show
2492echo "---------------------"
2493ovn-nbctl list logical_router
2494echo "---------------------"
2495ovn-nbctl list logical_router_port
2496echo "---------------------"
2497
2498echo "---------SB dump-----"
2499ovn-sbctl list datapath_binding
2500echo "---------------------"
2501ovn-sbctl list logical_flow
2502echo "---------------------"
2503
2504echo "------ hv1 dump ----------"
2505as hv1 ovs-ofctl dump-flows br-int
2506
2507
2508#Disable router R1
2509ovn-nbctl set Logical_Router R1 enabled=false
2510
2511echo "---------SB dump-----"
2512ovn-sbctl list datapath_binding
2513echo "---------------------"
2514ovn-sbctl list logical_flow
2515echo "---------------------"
2516
2517echo "------ hv1 dump ----------"
2518as hv1 ovs-ofctl dump-flows br-int
2519
2520as hv1 ovs-appctl netdev-dummy/receive vif1 $packet
2521
2522# Packet to Expect
2523expect_src_mac="000000010203"
2524expect_dst_mac="f00000010204"
2525expected=${expect_dst_mac}${expect_src_mac}08004500001c000000003f110100${src_ip}${dst_ip}0035111100080000
2526
2527$PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif2-tx.pcap | trim_zeros > received.packets
2528echo $expected | trim_zeros > expout
2529AT_CHECK([cat received.packets], [0], [expout])
2530
2531
2532as hv1
2533OVS_APP_EXIT_AND_WAIT([ovn-controller])
2534OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2535OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2536
2537as ovn-sb
2538OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2539
2540as ovn-nb
2541OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2542
2543as northd
2544OVS_APP_EXIT_AND_WAIT([ovn-northd])
2545
2546as main
2547OVS_APP_EXIT_AND_WAIT([ovs-vswitchd])
2548OVS_APP_EXIT_AND_WAIT([ovsdb-server])
2549
2550AT_CLEANUP
2551
2552
2553AT_SETUP([ovn -- 1 HV, 2 LSs, 1 lport/LS, 1 LR])
5412db30
J
2554AT_KEYWORDS([router-admin-state])
2555AT_SKIP_IF([test $HAVE_PYTHON = no])
2556ovn_start
2557
2558# Logical network:
2559# One LR - R1 has switch ls1 (191.168.1.0/24) connected to it,
2560# and has switch ls2 (172.16.1.0/24) connected to it.
2561
fa2a27b2 2562ovn-nbctl lr-add R1
5412db30 2563
ea46a4e9
JP
2564ovn-nbctl ls-add ls1
2565ovn-nbctl ls-add ls2
5412db30
J
2566
2567# Connect ls1 to R1
bf44c2cd 2568ovn-nbctl lrp-add R1 ls1 00:00:00:01:02:03 192.168.1.1/24
31ed1192 2569ovn-nbctl lsp-add ls1 rp-ls1 -- set Logical_Switch_Port rp-ls1 type=router \
31114af7 2570 options:router-port=ls1 addresses=\"00:00:00:01:02:03\"
5412db30
J
2571
2572# Connect ls2 to R1
bf44c2cd 2573ovn-nbctl lrp-add R1 ls2 00:00:00:01:02:04 172.16.1.1/24
31ed1192 2574ovn-nbctl lsp-add ls2 rp-ls2 -- set Logical_Switch_Port rp-ls2 type=router \
31114af7 2575 options:router-port=ls2 addresses=\"00:00:00:01:02:04\"
5412db30
J
2576
2577# Create logical port ls1-lp1 in ls1
31ed1192
JP
2578ovn-nbctl lsp-add ls1 ls1-lp1 \
2579-- lsp-set-addresses ls1-lp1 "f0:00:00:01:02:03 192.168.1.2"
5412db30
J
2580
2581# Create logical port ls2-lp1 in ls2
31ed1192
JP
2582ovn-nbctl lsp-add ls2 ls2-lp1 \
2583-- lsp-set-addresses ls2-lp1 "f0:00:00:01:02:04 172.16.1.2"
5412db30
J
2584
2585# Create one hypervisor and create OVS ports corresponding to logical ports.
2586net_add n1
2587
2588sim_add hv1
2589as hv1
2590ovs-vsctl add-br br-phys
2591ovn_attach n1 br-phys 192.168.0.1
2592ovs-vsctl -- add-port br-int vif1 -- \
2593 set interface vif1 external-ids:iface-id=ls1-lp1 \
2594 options:tx_pcap=hv1/vif1-tx.pcap \
2595 options:rxq_pcap=hv1/vif1-rx.pcap \
2596 ofport-request=1
2597
2598ovs-vsctl -- add-port br-int vif2 -- \
2599 set interface vif2 external-ids:iface-id=ls2-lp1 \
2600 options:tx_pcap=hv1/vif2-tx.pcap \
2601 options:rxq_pcap=hv1/vif2-rx.pcap \
2602 ofport-request=1
2603
2604
2605# Allow some time for ovn-northd and ovn-controller to catch up.
2606# XXX This should be more systematic.
2607sleep 1
2608
2609# Send ip packets between the two ports.
2610ip_to_hex() {
2611 printf "%02x%02x%02x%02x" "$@"
2612}
2613trim_zeros() {
2614 sed 's/\(00\)\{1,\}$//'
2615}
2616
2617# Packet to send.
2618src_mac="f00000010203"
2619dst_mac="000000010203"
2620src_ip=`ip_to_hex 192 168 1 2`
2621dst_ip=`ip_to_hex 172 16 1 2`
2622packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
2623as hv1 ovs-appctl netdev-dummy/receive vif1 $packet
2624
2625
2626echo "---------NB dump-----"
2627ovn-nbctl show
2628echo "---------------------"
2629ovn-nbctl list logical_router
2630echo "---------------------"
2631ovn-nbctl list logical_router_port
2632echo "---------------------"
2633
2634echo "---------SB dump-----"
2635ovn-sbctl list datapath_binding
2636echo "---------------------"
2637ovn-sbctl list logical_flow
2638echo "---------------------"
2639
2640echo "------ hv1 dump ----------"
2641as hv1 ovs-ofctl dump-flows br-int
2642
5412db30
J
2643#Disable router R1
2644ovn-nbctl set Logical_Router R1 enabled=false
2645
2646echo "---------SB dump-----"
2647ovn-sbctl list datapath_binding
2648echo "---------------------"
2649ovn-sbctl list logical_flow
2650echo "---------------------"
2651
2652echo "------ hv1 dump ----------"
2653as hv1 ovs-ofctl dump-flows br-int
2654
a1361a6e
LR
2655# Allow some time for the disabling of logical router R1 to propagate.
2656# XXX This should be more systematic.
2657sleep 1
2658
5412db30
J
2659as hv1 ovs-appctl netdev-dummy/receive vif1 $packet
2660
2661# Packet to Expect
2662expect_src_mac="000000010204"
2663expect_dst_mac="f00000010204"
2664expected=${expect_dst_mac}${expect_src_mac}08004500001c000000003f110100${src_ip}${dst_ip}0035111100080000
2665
2666$PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif2-tx.pcap | trim_zeros > received.packets
2667echo $expected | trim_zeros > expout
2668AT_CHECK([cat received.packets], [0], [expout])
2669
2670
7a8f15e0 2671OVN_CLEANUP([hv1])
5412db30
J
2672
2673AT_CLEANUP
2674
28dc3fe9
SR
2675AT_SETUP([ovn -- 2 HVs, 3 LS, 1 lport/LS, 2 peer LRs, static routes])
2676AT_KEYWORDS([ovnstaticroutespeer])
2677AT_SKIP_IF([test $HAVE_PYTHON = no])
2678ovn_start
2679
2680# Logical network:
2681# Two LRs - R1 and R2 that are connected to each other as peers in 20.0.0.0/24
2682# network. R1 has switchess foo (192.168.1.0/24)
2683# connected to it.
2684# R2 has alice (172.16.1.0/24) and bob (172.16.2.0/24) connected to it.
2685
fa2a27b2
JP
2686ovn-nbctl lr-add R1
2687ovn-nbctl lr-add R2
28dc3fe9 2688
ea46a4e9
JP
2689ovn-nbctl ls-add foo
2690ovn-nbctl ls-add alice
2691ovn-nbctl ls-add bob
28dc3fe9
SR
2692
2693# Connect foo to R1
bf44c2cd 2694ovn-nbctl lrp-add R1 foo 00:00:00:01:02:03 192.168.1.1/24
31ed1192 2695ovn-nbctl lsp-add foo rp-foo -- set Logical_Switch_Port rp-foo type=router \
31114af7 2696 options:router-port=foo addresses=\"00:00:00:01:02:03\"
28dc3fe9
SR
2697
2698# Connect alice to R2
bf44c2cd 2699ovn-nbctl lrp-add R2 alice 00:00:00:01:02:04 172.16.1.1/24
31ed1192 2700ovn-nbctl lsp-add alice rp-alice -- set Logical_Switch_Port rp-alice \
80f408f4 2701 type=router options:router-port=alice addresses=\"00:00:00:01:02:04\"
28dc3fe9
SR
2702
2703# Connect bob to R2
bf44c2cd 2704ovn-nbctl lrp-add R2 bob 00:00:00:01:02:05 172.16.2.1/24
31ed1192 2705ovn-nbctl lsp-add bob rp-bob -- set Logical_Switch_Port rp-bob type=router \
31114af7 2706 options:router-port=bob addresses=\"00:00:00:01:02:05\"
28dc3fe9
SR
2707
2708# Connect R1 to R2
4685e523
JP
2709ovn-nbctl lrp-add R1 R1_R2 00:00:00:02:03:04 20.0.0.1/24 peer=R2_R1
2710ovn-nbctl lrp-add R2 R2_R1 00:00:00:02:03:05 20.0.0.2/24 peer=R1_R2
28dc3fe9
SR
2711
2712#install static routes
e48ccf3c
JP
2713ovn-nbctl lr-route-add R1 172.16.1.0/24 20.0.0.2
2714ovn-nbctl lr-route-add R2 172.16.2.0/24 20.0.0.2 R1_R2
2715ovn-nbctl lr-route-add R2 192.168.1.0/24 20.0.0.1
28dc3fe9
SR
2716
2717# Create logical port foo1 in foo
31ed1192
JP
2718ovn-nbctl lsp-add foo foo1 \
2719-- lsp-set-addresses foo1 "f0:00:00:01:02:03 192.168.1.2"
28dc3fe9
SR
2720
2721# Create logical port alice1 in alice
31ed1192
JP
2722ovn-nbctl lsp-add alice alice1 \
2723-- lsp-set-addresses alice1 "f0:00:00:01:02:04 172.16.1.2"
28dc3fe9
SR
2724
2725# Create logical port bob1 in bob
31ed1192
JP
2726ovn-nbctl lsp-add bob bob1 \
2727-- lsp-set-addresses bob1 "f0:00:00:01:02:05 172.16.2.2"
28dc3fe9
SR
2728
2729# Create two hypervisor and create OVS ports corresponding to logical ports.
2730net_add n1
2731
2732sim_add hv1
2733as hv1
2734ovs-vsctl add-br br-phys
2735ovn_attach n1 br-phys 192.168.0.1
2736ovs-vsctl -- add-port br-int hv1-vif1 -- \
2737 set interface hv1-vif1 external-ids:iface-id=foo1 \
2738 options:tx_pcap=hv1/vif1-tx.pcap \
2739 options:rxq_pcap=hv1/vif1-rx.pcap \
2740 ofport-request=1
2741
2742ovs-vsctl -- add-port br-int hv1-vif2 -- \
2743 set interface hv1-vif2 external-ids:iface-id=alice1 \
2744 options:tx_pcap=hv1/vif2-tx.pcap \
2745 options:rxq_pcap=hv1/vif2-rx.pcap \
2746 ofport-request=2
2747
2748sim_add hv2
2749as hv2
2750ovs-vsctl add-br br-phys
2751ovn_attach n1 br-phys 192.168.0.2
2752ovs-vsctl -- add-port br-int hv2-vif1 -- \
2753 set interface hv2-vif1 external-ids:iface-id=bob1 \
2754 options:tx_pcap=hv2/vif1-tx.pcap \
2755 options:rxq_pcap=hv2/vif1-rx.pcap \
2756 ofport-request=1
2757
2758
2759# Pre-populate the hypervisors' ARP tables so that we don't lose any
2760# packets for ARP resolution (native tunneling doesn't queue packets
2761# for ARP resolution).
2762ovn_populate_arp
2763
2764# Allow some time for ovn-northd and ovn-controller to catch up.
2765# XXX This should be more systematic.
2766sleep 1
2767
2768ip_to_hex() {
2769 printf "%02x%02x%02x%02x" "$@"
2770}
2771trim_zeros() {
2772 sed 's/\(00\)\{1,\}$//'
2773}
2774
2775# Send ip packets between foo1 and alice1
2776src_mac="f00000010203"
2777dst_mac="000000010203"
2778src_ip=`ip_to_hex 192 168 1 2`
2779dst_ip=`ip_to_hex 172 16 1 2`
2780packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
2781as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet
2782
2783# Send ip packets between foo1 and bob1
2784src_mac="f00000010203"
2785dst_mac="000000010203"
2786src_ip=`ip_to_hex 192 168 1 2`
2787dst_ip=`ip_to_hex 172 16 2 2`
2788packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
2789as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet
2790
2791echo "---------NB dump-----"
2792ovn-nbctl show
2793echo "---------------------"
2794ovn-nbctl list logical_router
2795echo "---------------------"
2796ovn-nbctl list logical_router_port
2797echo "---------------------"
2798
2799echo "---------SB dump-----"
2800ovn-sbctl list datapath_binding
2801echo "---------------------"
2802ovn-sbctl list port_binding
2803echo "---------------------"
2804
2805echo "------ hv1 dump ----------"
2806as hv1 ovs-ofctl dump-flows br-int
2807echo "------ hv2 dump ----------"
2808as hv2 ovs-ofctl dump-flows br-int
2809
2810# Packet to Expect at bob1
2811src_mac="000000010205"
2812dst_mac="f00000010205"
2813src_ip=`ip_to_hex 192 168 1 2`
2814dst_ip=`ip_to_hex 172 16 2 2`
2815expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000
2816
2817$PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv2/vif1-tx.pcap | trim_zeros > received.packets
2818echo $expected | trim_zeros > expout
2819AT_CHECK([cat received.packets], [0], [expout])
2820
2821# Packet to Expect at alice1
2822src_mac="000000010204"
2823dst_mac="f00000010204"
2824src_ip=`ip_to_hex 192 168 1 2`
2825dst_ip=`ip_to_hex 172 16 1 2`
2826expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000
2827
2828$PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif2-tx.pcap | trim_zeros > received1.packets
2829echo $expected | trim_zeros > expout
2830AT_CHECK([cat received1.packets], [0], [expout])
2831
7a8f15e0 2832OVN_CLEANUP([hv1],[hv2])
28dc3fe9
SR
2833
2834AT_CLEANUP
5412db30 2835
0ee8aaf6
RR
2836AT_SETUP([ovn -- send gratuitous arp on localnet])
2837AT_KEYWORDS([ovn])
d08dbed7 2838AT_SKIP_IF([test $HAVE_PYTHON = no])
0ee8aaf6 2839ovn_start
ea46a4e9 2840ovn-nbctl ls-add lsw0
0ee8aaf6
RR
2841net_add n1
2842sim_add hv
2843as hv
2844ovs-vsctl \
2845 -- add-br br-phys \
2846 -- add-br br-eth0
2847
2848ovn_attach n1 br-phys 192.168.0.1
2849
2850AT_CHECK([ovs-vsctl set Open_vSwitch . external-ids:ovn-bridge-mappings=physnet1:br-eth0])
2851AT_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])
2852
2853# Create a vif.
31ed1192
JP
2854AT_CHECK([ovn-nbctl lsp-add lsw0 localvif1])
2855AT_CHECK([ovn-nbctl lsp-set-addresses localvif1 "f0:00:00:00:00:01 192.168.1.2"])
2856AT_CHECK([ovn-nbctl lsp-set-port-security localvif1 "f0:00:00:00:00:01"])
0ee8aaf6
RR
2857
2858# Create a localnet port.
31ed1192
JP
2859AT_CHECK([ovn-nbctl lsp-add lsw0 ln_port])
2860AT_CHECK([ovn-nbctl lsp-set-addresses ln_port unknown])
2861AT_CHECK([ovn-nbctl lsp-set-type ln_port localnet])
2862AT_CHECK([ovn-nbctl lsp-set-options ln_port network_name=physnet1])
0ee8aaf6
RR
2863
2864AT_CHECK([ovs-vsctl add-port br-int localvif1 -- set Interface localvif1 external_ids:iface-id=localvif1])
2865
2866# Wait for packet to be received.
2867OVS_WAIT_UNTIL([test `wc -c < "hv/snoopvif-tx.pcap"` -ge 50])
2868trim_zeros() {
2869 sed 's/\(00\)\{1,\}$//'
2870}
2871$PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv/snoopvif-tx.pcap | trim_zeros > packets
2872expected="fffffffffffff0000000000108060001080006040001f00000000001c0a80102000000000000c0a80102"
2873echo $expected > expout
2874AT_CHECK([sort packets], [0], [expout])
2875cat packets
2876
2877# Delete the localnet ports.
2878AT_CHECK([ovs-vsctl del-port localvif1])
31ed1192 2879AT_CHECK([ovn-nbctl lsp-del ln_port])
0ee8aaf6 2880
7a8f15e0 2881OVN_CLEANUP([hv])
0ee8aaf6
RR
2882
2883AT_CLEANUP
75cf9d2b
GS
2884
2885AT_SETUP([ovn -- 2 HVs, 3 LRs connected via LS, static routes])
2886AT_KEYWORDS([ovnstaticroutes])
2887AT_SKIP_IF([test $HAVE_PYTHON = no])
2888ovn_start
2889
2890# Logical network:
2891# Three LRs - R1, R2 and R3 that are connected to each other via LS "join"
2892# in 20.0.0.0/24 network. R1 has switchess foo (192.168.1.0/24)
2893# connected to it. R2 has alice (172.16.1.0/24) and R3 has bob (10.32.1.0/24)
2894# connected to it.
2895
fa2a27b2
JP
2896ovn-nbctl lr-add R1
2897ovn-nbctl lr-add R2
2898ovn-nbctl lr-add R3
75cf9d2b 2899
ea46a4e9
JP
2900ovn-nbctl ls-add foo
2901ovn-nbctl ls-add alice
2902ovn-nbctl ls-add bob
2903ovn-nbctl ls-add join
75cf9d2b
GS
2904
2905# Connect foo to R1
31114af7 2906ovn-nbctl lrp-add R1 foo 00:00:01:01:02:03 192.168.1.1/24
31ed1192 2907ovn-nbctl lsp-add foo rp-foo -- set Logical_Switch_Port rp-foo type=router \
31114af7 2908 options:router-port=foo addresses=\"00:00:01:01:02:03\"
75cf9d2b
GS
2909
2910# Connect alice to R2
31114af7 2911ovn-nbctl lrp-add R2 alice 00:00:02:01:02:03 172.16.1.1/24
31ed1192 2912ovn-nbctl lsp-add alice rp-alice -- set Logical_Switch_Port rp-alice \
80f408f4 2913 type=router options:router-port=alice addresses=\"00:00:02:01:02:03\"
75cf9d2b
GS
2914
2915# Connect bob to R3
31114af7 2916ovn-nbctl lrp-add R3 bob 00:00:03:01:02:03 10.32.1.1/24
31ed1192 2917ovn-nbctl lsp-add bob rp-bob -- set Logical_Switch_Port rp-bob \
80f408f4 2918 type=router options:router-port=bob addresses=\"00:00:03:01:02:03\"
75cf9d2b
GS
2919
2920# Connect R1 to join
31114af7 2921ovn-nbctl lrp-add R1 R1_join 00:00:04:01:02:03 20.0.0.1/24
31ed1192 2922ovn-nbctl lsp-add join r1-join -- set Logical_Switch_Port r1-join \
80f408f4 2923 type=router options:router-port=R1_join addresses='"00:00:04:01:02:03"'
75cf9d2b
GS
2924
2925# Connect R2 to join
31114af7 2926ovn-nbctl lrp-add R2 R2_join 00:00:04:01:02:04 20.0.0.2/24
31ed1192 2927ovn-nbctl lsp-add join r2-join -- set Logical_Switch_Port r2-join \
80f408f4 2928 type=router options:router-port=R2_join addresses='"00:00:04:01:02:04"'
75cf9d2b
GS
2929
2930# Connect R3 to join
31114af7 2931ovn-nbctl lrp-add R3 R3_join 00:00:04:01:02:05 20.0.0.3/24
31ed1192 2932ovn-nbctl lsp-add join r3-join -- set Logical_Switch_Port r3-join \
80f408f4 2933 type=router options:router-port=R3_join addresses='"00:00:04:01:02:05"'
75cf9d2b
GS
2934
2935#install static routes
e48ccf3c
JP
2936ovn-nbctl lr-route-add R1 172.16.1.0/24 20.0.0.2
2937ovn-nbctl lr-route-add R1 10.32.1.0/24 20.0.0.3
75cf9d2b 2938
e48ccf3c
JP
2939ovn-nbctl lr-route-add R2 192.168.1.0/24 20.0.0.1
2940ovn-nbctl lr-route-add R2 10.32.1.0/24 20.0.0.3
75cf9d2b 2941
e48ccf3c
JP
2942ovn-nbctl lr-route-add R3 192.168.1.0/24 20.0.0.1
2943ovn-nbctl lr-route-add R3 172.16.1.0/24 20.0.0.2
75cf9d2b
GS
2944
2945# Create logical port foo1 in foo
31ed1192
JP
2946ovn-nbctl lsp-add foo foo1 \
2947-- lsp-set-addresses foo1 "f0:00:00:01:02:03 192.168.1.2"
75cf9d2b
GS
2948
2949# Create logical port alice1 in alice
31ed1192
JP
2950ovn-nbctl lsp-add alice alice1 \
2951-- lsp-set-addresses alice1 "f0:00:00:01:02:04 172.16.1.2"
75cf9d2b
GS
2952
2953# Create logical port bob1 in bob
31ed1192
JP
2954ovn-nbctl lsp-add bob bob1 \
2955-- lsp-set-addresses bob1 "f0:00:00:01:02:05 10.32.1.2"
75cf9d2b
GS
2956
2957# Create two hypervisor and create OVS ports corresponding to logical ports.
2958net_add n1
2959
2960sim_add hv1
2961as hv1
2962ovs-vsctl add-br br-phys
2963ovn_attach n1 br-phys 192.168.0.1
2964ovs-vsctl -- add-port br-int hv1-vif1 -- \
2965 set interface hv1-vif1 external-ids:iface-id=foo1 \
2966 options:tx_pcap=hv1/vif1-tx.pcap \
2967 options:rxq_pcap=hv1/vif1-rx.pcap \
2968 ofport-request=1
2969
2970ovs-vsctl -- add-port br-int hv1-vif2 -- \
2971 set interface hv1-vif2 external-ids:iface-id=alice1 \
2972 options:tx_pcap=hv1/vif2-tx.pcap \
2973 options:rxq_pcap=hv1/vif2-rx.pcap \
2974 ofport-request=2
2975
2976sim_add hv2
2977as hv2
2978ovs-vsctl add-br br-phys
2979ovn_attach n1 br-phys 192.168.0.2
2980ovs-vsctl -- add-port br-int hv2-vif1 -- \
2981 set interface hv2-vif1 external-ids:iface-id=bob1 \
2982 options:tx_pcap=hv2/vif1-tx.pcap \
2983 options:rxq_pcap=hv2/vif1-rx.pcap \
2984 ofport-request=1
2985
2986
2987# Pre-populate the hypervisors' ARP tables so that we don't lose any
2988# packets for ARP resolution (native tunneling doesn't queue packets
2989# for ARP resolution).
2990ovn_populate_arp
2991
2992# Allow some time for ovn-northd and ovn-controller to catch up.
2993# XXX This should be more systematic.
2994sleep 1
2995
2996ip_to_hex() {
2997 printf "%02x%02x%02x%02x" "$@"
2998}
2999trim_zeros() {
3000 sed 's/\(00\)\{1,\}$//'
3001}
3002
3003# Send ip packets between foo1 and alice1
3004src_mac="f00000010203"
3005dst_mac="000001010203"
3006src_ip=`ip_to_hex 192 168 1 2`
3007dst_ip=`ip_to_hex 172 16 1 2`
3008packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
3009as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet
3010as hv1 ovs-appctl ofproto/trace br-int in_port=1 $packet
3011
3012# Send ip packets between foo1 and bob1
3013src_mac="f00000010203"
3014dst_mac="000001010203"
3015src_ip=`ip_to_hex 192 168 1 2`
3016dst_ip=`ip_to_hex 10 32 1 2`
3017packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
3018as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet
3019
3020echo "---------NB dump-----"
3021ovn-nbctl show
3022echo "---------------------"
3023ovn-nbctl list logical_router
3024echo "---------------------"
3025ovn-nbctl list logical_router_port
3026echo "---------------------"
3027
3028echo "---------SB dump-----"
3029ovn-sbctl list datapath_binding
3030echo "---------------------"
3031ovn-sbctl list port_binding
3032echo "---------------------"
3033ovn-sbctl dump-flows
3034echo "---------------------"
3035
3036echo "------ hv1 dump ----------"
3037as hv1 ovs-ofctl show br-int
3038as hv1 ovs-ofctl dump-flows br-int
3039echo "------ hv2 dump ----------"
3040as hv2 ovs-ofctl show br-int
3041as hv2 ovs-ofctl dump-flows br-int
3042echo "----------------------------"
3043
3044# Packet to Expect at bob1
3045src_mac="000003010203"
3046dst_mac="f00000010205"
3047src_ip=`ip_to_hex 192 168 1 2`
3048dst_ip=`ip_to_hex 10 32 1 2`
3049expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000
3050
3051$PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv2/vif1-tx.pcap | trim_zeros > received.packets
3052echo $expected | trim_zeros > expout
3053AT_CHECK([cat received.packets], [0], [expout])
3054
3055# Packet to Expect at alice1
3056src_mac="000002010203"
3057dst_mac="f00000010204"
3058src_ip=`ip_to_hex 192 168 1 2`
3059dst_ip=`ip_to_hex 172 16 1 2`
3060expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000
3061
3062$PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif2-tx.pcap | trim_zeros > received1.packets
3063echo $expected | trim_zeros > expout
3064AT_CHECK([cat received1.packets], [0], [expout])
3065
7a8f15e0 3066OVN_CLEANUP([hv1],[hv2])
75cf9d2b
GS
3067
3068AT_CLEANUP
c1645003 3069
c1645003
GS
3070AT_SETUP([ovn -- 2 HVs, 2 LRs connected via LS, gateway router])
3071AT_KEYWORDS([ovngatewayrouter])
3072AT_SKIP_IF([test $HAVE_PYTHON = no])
3073ovn_start
3074
3075# Logical network:
3076# Two LRs - R1 and R2 that are connected to each other via LS "join"
3077# in 20.0.0.0/24 network. R1 has switchess foo (192.168.1.0/24)
3078# connected to it. R2 has alice (172.16.1.0/24) connected to it.
3079# R2 is a gateway router.
3080
3081
3082
3083# Create two hypervisor and create OVS ports corresponding to logical ports.
3084net_add n1
3085
3086sim_add hv1
3087as hv1
3088ovs-vsctl add-br br-phys
3089ovn_attach n1 br-phys 192.168.0.1
3090ovs-vsctl -- add-port br-int hv1-vif1 -- \
3091 set interface hv1-vif1 external-ids:iface-id=foo1 \
3092 options:tx_pcap=hv1/vif1-tx.pcap \
3093 options:rxq_pcap=hv1/vif1-rx.pcap \
3094 ofport-request=1
3095
3096
3097sim_add hv2
3098as hv2
3099ovs-vsctl add-br br-phys
3100ovn_attach n1 br-phys 192.168.0.2
3101ovs-vsctl -- add-port br-int hv2-vif1 -- \
3102 set interface hv2-vif1 external-ids:iface-id=alice1 \
3103 options:tx_pcap=hv2/vif1-tx.pcap \
3104 options:rxq_pcap=hv2/vif1-rx.pcap \
3105 ofport-request=1
3106
3107# Pre-populate the hypervisors' ARP tables so that we don't lose any
3108# packets for ARP resolution (native tunneling doesn't queue packets
3109# for ARP resolution).
3110ovn_populate_arp
3111
3112ovn-nbctl create Logical_Router name=R1
3113ovn-nbctl create Logical_Router name=R2 options:chassis="hv2"
3114
ea46a4e9
JP
3115ovn-nbctl ls-add foo
3116ovn-nbctl ls-add alice
3117ovn-nbctl ls-add join
c1645003
GS
3118
3119# Connect foo to R1
31114af7 3120ovn-nbctl lrp-add R1 foo 00:00:01:01:02:03 192.168.1.1/24
31ed1192 3121ovn-nbctl lsp-add foo rp-foo -- set Logical_Switch_Port rp-foo \
80f408f4 3122 type=router options:router-port=foo addresses=\"00:00:01:01:02:03\"
c1645003
GS
3123
3124# Connect alice to R2
31114af7 3125ovn-nbctl lrp-add R2 alice 00:00:02:01:02:03 172.16.1.1/24
31ed1192 3126ovn-nbctl lsp-add alice rp-alice -- set Logical_Switch_Port rp-alice \
80f408f4 3127 type=router options:router-port=alice addresses=\"00:00:02:01:02:03\"
c1645003
GS
3128
3129# Connect R1 to join
31114af7 3130ovn-nbctl lrp-add R1 R1_join 00:00:04:01:02:03 20.0.0.1/24
31ed1192 3131ovn-nbctl lsp-add join r1-join -- set Logical_Switch_Port r1-join \
80f408f4 3132 type=router options:router-port=R1_join addresses='"00:00:04:01:02:03"'
c1645003
GS
3133
3134# Connect R2 to join
31114af7 3135ovn-nbctl lrp-add R2 R2_join 00:00:04:01:02:04 20.0.0.2/24
31ed1192 3136ovn-nbctl lsp-add join r2-join -- set Logical_Switch_Port r2-join \
80f408f4 3137 type=router options:router-port=R2_join addresses='"00:00:04:01:02:04"'
c1645003
GS
3138
3139
3140#install static routes
3141ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \
3142ip_prefix=172.16.1.0/24 nexthop=20.0.0.2 -- add Logical_Router \
3143R1 static_routes @lrt
3144
3145ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \
3146ip_prefix=192.168.1.0/24 nexthop=20.0.0.1 -- add Logical_Router \
3147R2 static_routes @lrt
3148
3149# Create logical port foo1 in foo
31ed1192
JP
3150ovn-nbctl lsp-add foo foo1 \
3151-- lsp-set-addresses foo1 "f0:00:00:01:02:03 192.168.1.2"
c1645003
GS
3152
3153# Create logical port alice1 in alice
31ed1192
JP
3154ovn-nbctl lsp-add alice alice1 \
3155-- lsp-set-addresses alice1 "f0:00:00:01:02:04 172.16.1.2"
c1645003
GS
3156
3157
3158# Allow some time for ovn-northd and ovn-controller to catch up.
3159# XXX This should be more systematic.
3160sleep 2
3161
3162ip_to_hex() {
3163 printf "%02x%02x%02x%02x" "$@"
3164}
3165trim_zeros() {
3166 sed 's/\(00\)\{1,\}$//'
3167}
3168
3169# Send ip packets between foo1 and alice1
3170src_mac="f00000010203"
3171dst_mac="000001010203"
3172src_ip=`ip_to_hex 192 168 1 2`
3173dst_ip=`ip_to_hex 172 16 1 2`
3174packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000
3175
3176echo "---------NB dump-----"
3177ovn-nbctl show
3178echo "---------------------"
3179ovn-nbctl list logical_router
3180echo "---------------------"
3181ovn-nbctl list logical_router_port
3182echo "---------------------"
3183
3184echo "---------SB dump-----"
3185ovn-sbctl list datapath_binding
3186echo "---------------------"
3187ovn-sbctl list port_binding
3188echo "---------------------"
3189ovn-sbctl dump-flows
3190echo "---------------------"
3191ovn-sbctl list chassis
3192ovn-sbctl list encap
3193echo "---------------------"
3194
c1645003
GS
3195# Packet to Expect at alice1
3196src_mac="000002010203"
3197dst_mac="f00000010204"
3198src_ip=`ip_to_hex 192 168 1 2`
3199dst_ip=`ip_to_hex 172 16 1 2`
3200expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000
3201
3202
3203as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet
3204as hv1 ovs-appctl ofproto/trace br-int in_port=1 $packet
3205
ab39371d
RM
3206echo "------ hv1 dump after packet 1 ----------"
3207as hv1 ovs-ofctl show br-int
3208as hv1 ovs-ofctl dump-flows br-int
3209echo "------ hv2 dump after packet 1 ----------"
3210as hv2 ovs-ofctl show br-int
3211as hv2 ovs-ofctl dump-flows br-int
3212echo "----------------------------"
3213
c1645003
GS
3214$PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv2/vif1-tx.pcap | trim_zeros > received1.packets
3215echo $expected | trim_zeros > expout
3216AT_CHECK([cat received1.packets], [0], [expout])
3217
34114cf8
GS
3218# Delete the router and re-create it. Things should work as before.
3219ovn-nbctl lr-del R2
3220ovn-nbctl create Logical_Router name=R2 options:chassis="hv2"
3221# Connect alice to R2
3222ovn-nbctl lrp-add R2 alice 00:00:02:01:02:03 172.16.1.1/24
3223# Connect R2 to join
3224ovn-nbctl lrp-add R2 R2_join 00:00:04:01:02:04 20.0.0.2/24
3225
3226ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \
3227ip_prefix=192.168.1.0/24 nexthop=20.0.0.1 -- add Logical_Router \
3228R2 static_routes @lrt
3229
3230# Wait for ovn-controller to catch up.
3231sleep 1
3232
3233# Send the packet again.
3234as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet
ab39371d
RM
3235
3236echo "------ hv1 dump after packet 2 ----------"
3237as hv1 ovs-ofctl show br-int
3238as hv1 ovs-ofctl dump-flows br-int
3239echo "------ hv2 dump after packet 2 ----------"
3240as hv2 ovs-ofctl show br-int
3241as hv2 ovs-ofctl dump-flows br-int
3242echo "----------------------------"
3243
34114cf8
GS
3244$PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv2/vif1-tx.pcap | trim_zeros > received1.packets
3245echo $expected | trim_zeros >> expout
3246AT_CHECK([cat received1.packets], [0], [expout])
3247
7a8f15e0 3248OVN_CLEANUP([hv1],[hv2])
c1645003
GS
3249
3250AT_CLEANUP
bb3c4568
FF
3251
3252AT_SETUP([ovn -- icmp_reply: 1 HVs, 2 LSs, 1 lport/LS, 1 LR])
3253AT_KEYWORDS([router-icmp-reply])
3254AT_SKIP_IF([test $HAVE_PYTHON = no])
3255ovn_start
3256
3257# Logical network:
3258# One LR - R1 has switch ls1 (191.168.1.0/24) connected to it,
3259# and has switch ls2 (172.16.1.0/24) connected to it.
3260
fa2a27b2 3261ovn-nbctl lr-add R1
bb3c4568 3262
ea46a4e9
JP
3263ovn-nbctl ls-add ls1
3264ovn-nbctl ls-add ls2
bb3c4568
FF
3265
3266# Connect ls1 to R1
31114af7 3267ovn-nbctl lrp-add R1 ls1 00:00:00:01:02:f1 192.168.1.1/24
31ed1192 3268ovn-nbctl lsp-add ls1 rp-ls1 -- set Logical_Switch_Port rp-ls1 \
80f408f4 3269 type=router options:router-port=ls1 addresses=\"00:00:00:01:02:f1\"
bb3c4568
FF
3270
3271# Connect ls2 to R1
31114af7 3272ovn-nbctl lrp-add R1 ls2 00:00:00:01:02:f2 172.16.1.1/24
31ed1192 3273ovn-nbctl lsp-add ls2 rp-ls2 -- set Logical_Switch_Port rp-ls2 \
80f408f4 3274 type=router options:router-port=ls2 addresses=\"00:00:00:01:02:f2\"
bb3c4568
FF
3275
3276# Create logical port ls1-lp1 in ls1
31ed1192
JP
3277ovn-nbctl lsp-add ls1 ls1-lp1 \
3278-- lsp-set-addresses ls1-lp1 "00:00:00:01:02:03 192.168.1.2"
bb3c4568
FF
3279
3280# Create logical port ls2-lp1 in ls2
31ed1192
JP
3281ovn-nbctl lsp-add ls2 ls2-lp1 \
3282-- lsp-set-addresses ls2-lp1 "00:00:00:01:02:04 172.16.1.2"
bb3c4568
FF
3283
3284# Create one hypervisor and create OVS ports corresponding to logical ports.
3285net_add n1
3286
3287sim_add hv1
3288as hv1
3289ovs-vsctl add-br br-phys
3290ovn_attach n1 br-phys 192.168.0.1
3291ovs-vsctl -- add-port br-int vif1 -- \
3292 set interface vif1 external-ids:iface-id=ls1-lp1 \
3293 options:tx_pcap=hv1/vif1-tx.pcap \
3294 options:rxq_pcap=hv1/vif1-rx.pcap \
3295 ofport-request=1
3296
3297ovs-vsctl -- add-port br-int vif2 -- \
3298 set interface vif2 external-ids:iface-id=ls2-lp1 \
3299 options:tx_pcap=hv1/vif2-tx.pcap \
3300 options:rxq_pcap=hv1/vif2-rx.pcap \
3301 ofport-request=1
3302
3303
3304# Allow some time for ovn-northd and ovn-controller to catch up.
3305# XXX This should be more systematic.
3306sleep 1
3307
3308
3309ip_to_hex() {
3310 printf "%02x%02x%02x%02x" "$@"
3311}
3312trim_zeros() {
3313 sed 's/\(00\)\{1,\}$//'
3314}
3315for i in 1 2; do
3316 : > vif$i.expected
3317done
3318# test_ipv4_icmp_request INPORT ETH_SRC ETH_DST IPV4_SRC IPV4_DST IP_CHKSUM ICMP_CHKSUM [EXP_IP_CHKSUM EXP_ICMP_CHKSUM]
3319#
3320# Causes a packet to be received on INPORT. The packet is an ICMPv4
3321# request with ETH_SRC, ETH_DST, IPV4_SRC, IPV4_DST, IP_CHSUM and
3322# ICMP_CHKSUM as specified. If EXP_IP_CHKSUM and EXP_ICMP_CHKSUM are
3323# provided, then it should be the ip and icmp checksums of the packet
3324# responded; otherwise, no reply is expected.
3325# In the absence of an ip checksum calculation helpers, this relies
3326# on the caller to provide the checksums for the ip and icmp headers.
3327# XXX This should be more systematic.
3328#
3329# INPORT is an lport number, e.g. 11 for vif11.
3330# ETH_SRC and ETH_DST are each 12 hex digits.
3331# IPV4_SRC and IPV4_DST are each 8 hex digits.
3332# IP_CHSUM and ICMP_CHKSUM are each 4 hex digits.
3333# EXP_IP_CHSUM and EXP_ICMP_CHKSUM are each 4 hex digits.
3334test_ipv4_icmp_request() {
3335 local inport=$1 eth_src=$2 eth_dst=$3 ipv4_src=$4 ipv4_dst=$5 ip_chksum=$6 icmp_chksum=$7
3336 local exp_ip_chksum=$8 exp_icmp_chksum=$9
3337 shift; shift; shift; shift; shift; shift; shift
3338 shift; shift
3339
3340 # Use ttl to exercise section 4.2.2.9 of RFC1812
3341 local ip_ttl=01
3342 local icmp_id=5fbf
3343 local icmp_seq=0001
3344 local icmp_data=$(seq 1 56 | xargs printf "%02x")
3345 local icmp_type_code_request=0800
3346 local icmp_payload=${icmp_type_code_request}${icmp_chksum}${icmp_id}${icmp_seq}${icmp_data}
3347 local packet=${eth_dst}${eth_src}08004500005400004000${ip_ttl}01${ip_chksum}${ipv4_src}${ipv4_dst}${icmp_payload}
3348
3349 as hv1 ovs-appctl netdev-dummy/receive vif$inport $packet
3350 if test X$exp_icmp_chksum != X; then
3351 # Expect to receive the reply, if any. In same port where packet was sent.
3352 # Note: src and dst fields are expected to be reversed.
3353 local icmp_type_code_response=0000
3354 local reply_icmp_ttl=fe
3355 local reply_icmp_payload=${icmp_type_code_response}${exp_icmp_chksum}${icmp_id}${icmp_seq}${icmp_data}
3356 local reply=${eth_src}${eth_dst}08004500005400004000${reply_icmp_ttl}01${exp_ip_chksum}${ipv4_dst}${ipv4_src}${reply_icmp_payload}
3357 echo $reply >> vif$inport.expected
3358 fi
3359}
3360
3361# Send ping packet to router's ip addresses, from each of the 2 logical ports.
3362rtr_l1_ip=$(ip_to_hex 192 168 1 1)
3363rtr_l2_ip=$(ip_to_hex 172 16 1 1)
3364l1_ip=$(ip_to_hex 192 168 1 2)
3365l2_ip=$(ip_to_hex 172 16 1 2)
3366
3367# Ping router ip address that is on same subnet as the logical port
3368test_ipv4_icmp_request 1 000000010203 0000000102f1 $l1_ip $rtr_l1_ip 0000 8510 02ff 8d10
3369test_ipv4_icmp_request 2 000000010204 0000000102f2 $l2_ip $rtr_l2_ip 0000 8510 02ff 8d10
3370
3371# Ping router ip address that is on the other side of the logical ports
3372test_ipv4_icmp_request 1 000000010203 0000000102f1 $l1_ip $rtr_l2_ip 0000 8510 02ff 8d10
3373test_ipv4_icmp_request 2 000000010204 0000000102f2 $l2_ip $rtr_l1_ip 0000 8510 02ff 8d10
3374
3375echo "---------NB dump-----"
3376ovn-nbctl show
3377echo "---------------------"
3378ovn-nbctl list logical_router
3379echo "---------------------"
3380ovn-nbctl list logical_router_port
3381echo "---------------------"
3382
3383echo "---------SB dump-----"
3384ovn-sbctl list datapath_binding
3385echo "---------------------"
3386ovn-sbctl list logical_flow
3387echo "---------------------"
3388
3389echo "------ hv1 dump ----------"
3390as hv1 ovs-ofctl dump-flows br-int
3391
3392# Now check the packets actually received against the ones expected.
3393for inport in 1 2; do
3394 file=hv1/vif${inport}-tx.pcap
3395 echo $file
3396 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" $file | trim_zeros > received.packets
3397 cat vif$inport.expected | trim_zeros > expout
3398 AT_CHECK([cat received.packets], [0], [expout])
3399done
3400
7a8f15e0 3401OVN_CLEANUP([hv1])
bb3c4568
FF
3402
3403AT_CLEANUP
94f79fcb
RB
3404
3405# 1 hypervisor, 1 port
3406# make sure that the port state is properly set to up and back down
3407# when created and deleted.
3408AT_SETUP([ovn -- port state up and down])
3409AT_KEYWORDS([ovn])
3410ovn_start
3411
3412ovn-nbctl ls-add ls1
3413ovn-nbctl lsp-add ls1 lp1
3414ovn-nbctl lsp-set-addresses lp1 unknown
3415
3416net_add n1
3417sim_add hv1
3418as hv1 ovs-vsctl add-br br-phys
3419as hv1 ovn_attach n1 br-phys 192.168.0.1
3420
3421as hv1 ovs-vsctl add-port br-int vif1 -- set Interface vif1 external-ids:iface-id=lp1
3422OVS_WAIT_UNTIL([test x`ovn-nbctl lsp-get-up lp1` = xup])
3423
3424as hv1 ovs-vsctl del-port br-int vif1
3425OVS_WAIT_UNTIL([test x`ovn-nbctl lsp-get-up lp1` = xdown])
3426
7a8f15e0 3427OVN_CLEANUP([hv1])
94f79fcb 3428
94f79fcb 3429AT_CLEANUP
e75451fe
ZKL
3430
3431AT_SETUP([ovn -- nd ])
3432AT_KEYWORDS([ovn-nd])
3433AT_SKIP_IF([test $HAVE_PYTHON = no])
3434ovn_start
3435
3436#TODO: since patch port for IPv6 logical router port is not ready not,
3437# so we are not going to test vifs on different lswitches cases. Try
3438# to update for that once relevant stuff implemented.
3439
3440# In this test cases we create 1 lswitch, it has 2 VIF ports attached
3441# with. NS packet we test, from one VIF for another VIF, will be replied
3442# by local ovn-controller, but not by target VIF.
3443
3444# Create hypervisors and logical switch lsw0.
3445ovn-nbctl ls-add lsw0
3446net_add n1
3447sim_add hv1
3448as hv1
3449ovs-vsctl add-br br-phys
3450ovn_attach n1 br-phys 192.168.0.2
3451
3452# Add vif1 to hv1 and lsw0, turn on l2 port security on vif1.
3453ovs-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
3454ovn-nbctl lsp-add lsw0 lp1
3455ovn-nbctl lsp-set-addresses lp1 "fa:16:3e:94:05:98 192.168.0.3 fd81:ce49:a948:0:f816:3eff:fe94:598"
3456ovn-nbctl lsp-set-port-security lp1 "fa:16:3e:94:05:98 192.168.0.3 fd81:ce49:a948:0:f816:3eff:fe94:598"
3457
3458# Add vif2 to hv1 and lsw0, turn on l2 port security on vif2.
3459ovs-vsctl add-port br-int vif2 -- set Interface vif2 external-ids:iface-id=lp2 options:tx_pcap=hv1/vif2-tx.pcap options:rxq_pcap=hv1/vif2-rx.pcap ofport-request=2
3460ovn-nbctl lsp-add lsw0 lp2
3461ovn-nbctl lsp-set-addresses lp2 "fa:16:3e:a1:f9:ae 192.168.0.4 fd81:ce49:a948:0:f816:3eff:fea1:f9ae"
3462ovn-nbctl lsp-set-port-security lp2 "fa:16:3e:a1:f9:ae 192.168.0.4 fd81:ce49:a948:0:f816:3eff:fea1:f9ae"
3463
3464# Add ACL rule for ICMPv6 on lsw0
3465ovn-nbctl acl-add lsw0 from-lport 1002 'ip6 && icmp6' allow-related
3466ovn-nbctl acl-add lsw0 to-lport 1002 'outport == "lp1" && ip6 && icmp6' allow-related
3467ovn-nbctl acl-add lsw0 to-lport 1002 'outport == "lp2" && ip6 && icmp6' allow-related
3468
3469# Allow some time for ovn-northd and ovn-controller to catch up.
3470# XXX This should be more systematic.
3471sleep 1
3472
3473# Given the name of a logical port, prints the name of the hypervisor
3474# on which it is located.
3475vif_to_hv() {
3476 echo hv1${1%?}
3477}
3478trim_zeros() {
3479 sed 's/\(00\)\{1,\}$//'
3480}
3481for i in 1 2; do
3482 : > $i.expected
3483done
3484
3485# Complete Neighbor Solicitation packet and Neighbor Advertisement packet
3486# vif1 -> NS -> vif2. vif1 <- NA <- ovn-controller.
3487# vif2 will not receive NS packet, since ovn-controller will reply for it.
3488ns_packet=3333ffa1f9aefa163e94059886dd6000000000203afffd81ce49a9480000f8163efffe940598fd81ce49a9480000f8163efffea1f9ae8700e01160000000fd81ce49a9480000f8163efffea1f9ae0101fa163e940598
3489na_packet=fa163e940598fa163ea1f9ae86dd6000000000203afffd81ce49a9480000f8163efffea1f9aefd81ce49a9480000f8163efffe9405988800e9ed60000000fd81ce49a9480000f8163efffea1f9ae0201fa163ea1f9ae
3490
3491as hv1 ovs-appctl netdev-dummy/receive vif1 $ns_packet
3492echo $na_packet | trim_zeros >> 1.expected
3493
3494sleep 1
3495
3496echo "------ hv1 dump ------"
3497as hv1 ovs-vsctl show
3498as hv1 ovs-ofctl -O OpenFlow13 show br-int
3499as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-int
3500
3501for i in 1 2; do
3502 file=hv1/vif$i-tx.pcap
3503 echo $file
3504 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" $file | trim_zeros > $i.packets
3505 cat $i.expected > expout
3506 AT_CHECK([cat $i.packets], [0], [expout])
3507done
3508
7a8f15e0 3509OVN_CLEANUP([hv1])
e75451fe
ZKL
3510
3511AT_CLEANUP
7417d147
RM
3512
3513AT_SETUP([ovn -- address sets modification/removal smoke test])
3514AT_KEYWORDS([ovn-addr])
3515ovn_start
3516
3517net_add n1
3518
3519sim_add hv1
3520as hv1
3521ovs-vsctl add-br br-phys
3522ovn_attach n1 br-phys 192.168.0.1
3523
3524row=`ovn-nbctl create Address_Set name=set1 addresses=\"1.1.1.1\"`
3525ovn-nbctl set Address_Set $row name=set1 addresses=\"1.1.1.1,1.1.1.2\"
3526ovn-nbctl destroy Address_Set $row
3527
3528sleep 1
3529
3530# A bug previously existed in the address set support code
3531# that caused ovn-controller to crash after an address set
3532# was updated and then removed. This test case ensures
3533# that ovn-controller is at least still running after
3534# creating, updating, and deleting an address set.
3535AT_CHECK([ovs-appctl -t ovn-controller version], [0], [ignore])
3536
3537OVN_CLEANUP([hv1])
3538
3539AT_CLEANUP