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