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