ovn-sbctl: Use environment var OVN_SB_DB to find the database by default.
[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
89 ^ => error("Invalid character `^' in input.")
90 ])
91 AT_CAPTURE_FILE([input.txt])
92 sed 's/ =>.*//' test-cases.txt > input.txt
93 sed 's/.* => //' test-cases.txt > expout
94 AT_CHECK([ovstest test-ovn lex < input.txt], [0], [expout])
95 AT_CLEANUP
96
97 AT_SETUP([ovn -- expression parser])
98 dnl For lines without =>, input and expected output are identical.
99 dnl For lines with =>, input precedes => and expected output follows =>.
100 AT_DATA([test-cases.txt], [[
101 eth.type == 0x800
102 eth.type==0x800 => eth.type == 0x800
103 eth.type[0..15] == 0x800 => eth.type == 0x800
104
105 vlan.present
106 vlan.present == 1 => vlan.present
107 !(vlan.present == 0) => vlan.present
108 !(vlan.present != 1) => vlan.present
109 !vlan.present
110 vlan.present == 0 => !vlan.present
111 vlan.present != 1 => !vlan.present
112 !(vlan.present == 1) => !vlan.present
113 !(vlan.present != 0) => !vlan.present
114
115 eth.dst[0]
116 eth.dst[0] == 1 => eth.dst[0]
117 eth.dst[0] != 0 => eth.dst[0]
118 !(eth.dst[0] == 0) => eth.dst[0]
119 !(eth.dst[0] != 1) => eth.dst[0]
120
121 !eth.dst[0]
122 eth.dst[0] == 0 => !eth.dst[0]
123 eth.dst[0] != 1 => !eth.dst[0]
124 !(eth.dst[0] == 1) => !eth.dst[0]
125 !(eth.dst[0] != 0) => !eth.dst[0]
126
127 vlan.tci[12..15] == 0x3
128 vlan.tci == 0x3000/0xf000 => vlan.tci[12..15] == 0x3
129 vlan.tci[12..15] != 0x3
130 vlan.tci != 0x3000/0xf000 => vlan.tci[12..15] != 0x3
131
132 !vlan.pcp => vlan.pcp == 0
133 !(vlan.pcp) => vlan.pcp == 0
134 vlan.pcp == 0x4
135 vlan.pcp != 0x4
136 vlan.pcp > 0x4
137 vlan.pcp >= 0x4
138 vlan.pcp < 0x4
139 vlan.pcp <= 0x4
140 !(vlan.pcp != 0x4) => 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 0x4 == vlan.pcp => 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
159 1 < vlan.pcp < 4 => vlan.pcp > 0x1 && vlan.pcp < 0x4
160 1 <= vlan.pcp <= 4 => vlan.pcp >= 0x1 && vlan.pcp <= 0x4
161 1 < vlan.pcp <= 4 => vlan.pcp > 0x1 && vlan.pcp <= 0x4
162 1 <= vlan.pcp < 4 => vlan.pcp >= 0x1 && vlan.pcp < 0x4
163 1 <= vlan.pcp <= 4 => vlan.pcp >= 0x1 && vlan.pcp <= 0x4
164 4 > vlan.pcp > 1 => vlan.pcp < 0x4 && vlan.pcp > 0x1
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 !(1 < vlan.pcp < 4) => vlan.pcp <= 0x1 || vlan.pcp >= 0x4
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 !(4 > vlan.pcp > 1) => vlan.pcp >= 0x4 || vlan.pcp <= 0x1
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
178 vlan.pcp == {1, 2, 3, 4} => vlan.pcp == 0x1 || vlan.pcp == 0x2 || vlan.pcp == 0x3 || vlan.pcp == 0x4
179 vlan.pcp == 1 || ((vlan.pcp == 2 || vlan.pcp == 3) || vlan.pcp == 4) => vlan.pcp == 0x1 || vlan.pcp == 0x2 || vlan.pcp == 0x3 || vlan.pcp == 0x4
180
181 vlan.pcp != {1, 2, 3, 4} => vlan.pcp != 0x1 && vlan.pcp != 0x2 && vlan.pcp != 0x3 && vlan.pcp != 0x4
182 vlan.pcp == 1 && ((vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && vlan.pcp == 0x2 && vlan.pcp == 0x3 && vlan.pcp == 0x4
183
184 vlan.pcp == 1 && !((vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && (vlan.pcp != 0x2 || vlan.pcp != 0x3 || vlan.pcp != 0x4)
185 vlan.pcp == 1 && (!(vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && (vlan.pcp != 0x2 || vlan.pcp != 0x3) && vlan.pcp == 0x4
186 vlan.pcp == 1 && !(!(vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && ((vlan.pcp == 0x2 && vlan.pcp == 0x3) || vlan.pcp != 0x4)
187
188 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
189 ip6.src == ::1 => ip6.src == 0x1
190
191 ip4.src == 1.2.3.4 => ip4.src == 0x1020304
192 ip4.src == ::1.2.3.4/::ffff:ffff => ip4.src == 0x1020304
193 ip6.src == ::1 => ip6.src == 0x1
194
195 1
196 0
197 !1 => 0
198 !0 => 1
199
200 inport == "eth0"
201 !(inport != "eth0") => inport == "eth0"
202
203 ip4.src == "eth0" => Integer field ip4.src is not compatible with string constant.
204 inport == 1 => String field inport is not compatible with integer constant.
205
206 ip4.src > {1, 2, 3} => Only == and != operators may be used with value sets.
207 eth.type > 0x800 => Only == and != operators may be used with nominal field eth.type.
208 vlan.present > 0 => Only == and != operators may be used with Boolean field vlan.present.
209
210 inport != "eth0" => Nominal field inport may only be tested for equality (taking enclosing `!' operators into account).
211 !(inport == "eth0") => Nominal field inport may only be tested for equality (taking enclosing `!' operators into account).
212 eth.type != 0x800 => Nominal field eth.type 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
215 123 == 123 => Syntax error at `123' expecting field name.
216
217 123 == xyzzy => Syntax error at `xyzzy' expecting field name.
218 xyzzy == 1 => Syntax error at `xyzzy' expecting field name.
219
220 inport[1] == 1 => Cannot select subfield of string field inport.
221
222 eth.type[] == 1 => Syntax error at `@:>@' expecting small integer.
223 eth.type[::1] == 1 => Syntax error at `::1' expecting small integer.
224 eth.type[18446744073709551615] == 1 => Syntax error at `18446744073709551615' expecting small integer.
225
226 eth.type[5!] => Syntax error at `!' expecting `@:>@'.
227
228 eth.type[5..1] => Invalid bit range 5 to 1.
229
230 eth.type[12..16] => Cannot select bits 12 to 16 of 16-bit field eth.type.
231
232 eth.type[10] == 1 => Cannot select subfield of nominal field eth.type.
233
234 eth.type => Explicit `!= 0' is required for inequality test of multibit field against 0.
235
236 !(!(vlan.pcp)) => Explicit `!= 0' is required for inequality test of multibit field against 0.
237
238 123 => Syntax error at end of input expecting relational operator.
239
240 123 x => Syntax error at `x' expecting relational operator.
241
242 {1, "eth0"} => Syntax error at `"eth0"' expecting integer.
243
244 eth.type == xyzzy => Syntax error at `xyzzy' expecting constant.
245
246 (1 x) => Syntax error at `x' expecting `)'.
247
248 !0x800 != eth.type => Missing parentheses around operand of !.
249
250 eth.type == 0x800 || eth.type == 0x86dd && ip.proto == 17 => && and || must be parenthesized when used together.
251
252 eth.dst == {} => Syntax error at `}' expecting constant.
253
254 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).
255
256 ip4.src == ::1 => 128-bit constant is not compatible with 32-bit field ip4.src.
257
258 1 == eth.type == 2 => Range expressions must have the form `x < field < y' or `x > field > y', with each `<' optionally replaced by `<=' or `>' by `>=').
259
260 eth.dst[40] x => Extra tokens at end of input.
261 ]])
262 sed 's/ =>.*//' test-cases.txt > input.txt
263 sed 's/.* => //' test-cases.txt > expout
264 AT_CHECK([ovstest test-ovn parse-expr < input.txt], [0], [expout])
265 AT_CLEANUP
266
267 AT_SETUP([ovn -- expression annotation])
268 dnl Input precedes =>, expected output follows =>.
269 AT_DATA([test-cases.txt], [[
270 ip4.src == 1.2.3.4 => ip4.src == 0x1020304 && eth.type == 0x800
271 ip4.src != 1.2.3.4 => ip4.src != 0x1020304 && eth.type == 0x800
272 ip.proto == 123 => ip.proto == 0x7b && (eth.type == 0x800 || eth.type == 0x86dd)
273 ip.proto == {123, 234} => (ip.proto == 0x7b && (eth.type == 0x800 || eth.type == 0x86dd)) || (ip.proto == 0xea && (eth.type == 0x800 || eth.type == 0x86dd))
274 ip4.src == 1.2.3.4 && ip4.dst == 5.6.7.8 => ip4.src == 0x1020304 && eth.type == 0x800 && ip4.dst == 0x5060708 && eth.type == 0x800
275
276 ip => eth.type == 0x800 || eth.type == 0x86dd
277 ip == 1 => eth.type == 0x800 || eth.type == 0x86dd
278 ip[0] == 1 => eth.type == 0x800 || eth.type == 0x86dd
279 ip > 0 => Only == and != operators may be used with nominal field ip.
280 !ip => Nominal predicate ip may only be tested positively, e.g. `ip' or `ip == 1' but not `!ip' or `ip == 0'.
281 ip == 0 => Nominal predicate ip may only be tested positively, e.g. `ip' or `ip == 1' but not `!ip' or `ip == 0'.
282
283 vlan.present => vlan.tci[12]
284 !vlan.present => !vlan.tci[12]
285
286 !vlan.pcp => vlan.tci[13..15] == 0 && vlan.tci[12]
287 vlan.pcp == 1 && vlan.vid == 2 => vlan.tci[13..15] == 0x1 && vlan.tci[12] && vlan.tci[0..11] == 0x2 && vlan.tci[12]
288 !reg0 && !reg1 && !reg2 && !reg3 => xreg0[32..63] == 0 && xreg0[0..31] == 0 && xreg1[32..63] == 0 && xreg1[0..31] == 0
289
290 ip.first_frag => ip.frag[0] && (eth.type == 0x800 || eth.type == 0x86dd) && (!ip.frag[1] || (eth.type != 0x800 && eth.type != 0x86dd))
291 !ip.first_frag => !ip.frag[0] || (eth.type != 0x800 && eth.type != 0x86dd) || (ip.frag[1] && (eth.type == 0x800 || eth.type == 0x86dd))
292 ip.later_frag => ip.frag[1] && (eth.type == 0x800 || eth.type == 0x86dd)
293
294 bad_prereq != 0 => Error parsing expression `xyzzy' encountered as prerequisite or predicate of initial expression: Syntax error at `xyzzy' expecting field name.
295 self_recurse != 0 => Error parsing expression `self_recurse != 0' encountered as prerequisite or predicate of initial expression: Recursive expansion of symbol `self_recurse'.
296 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'.
297 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'.
298 ]])
299 sed 's/ =>.*//' test-cases.txt > input.txt
300 sed 's/.* => //' test-cases.txt > expout
301 AT_CHECK([ovstest test-ovn annotate-expr < input.txt], [0], [expout])
302 AT_CLEANUP
303
304 AT_SETUP([ovn -- 1-term expression conversion])
305 AT_CHECK([ovstest test-ovn exhaustive --operation=convert 1], [0],
306   [Tested converting all 1-terminal expressions with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 2 string vars.
307 ])
308 AT_CLEANUP
309
310 AT_SETUP([ovn -- 2-term expression conversion])
311 AT_CHECK([ovstest test-ovn exhaustive --operation=convert 2], [0],
312   [Tested converting 570 expressions of 2 terminals with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 2 string vars.
313 ])
314 AT_CLEANUP
315
316 AT_SETUP([ovn -- 3-term expression conversion])
317 AT_CHECK([ovstest test-ovn exhaustive --operation=convert --bits=2 3], [0],
318   [Tested converting 62418 expressions of 3 terminals with 2 numeric vars (each 2 bits) in terms of operators == != < <= > >= and 2 string vars.
319 ])
320 AT_CLEANUP
321
322 AT_SETUP([ovn -- 3-term numeric expression simplification])
323 AT_CHECK([ovstest test-ovn exhaustive --operation=simplify --nvars=2 --svars=0 3], [0],
324   [Tested simplifying 477138 expressions of 3 terminals with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >=.
325 ])
326 AT_CLEANUP
327
328 AT_SETUP([ovn -- 4-term string expression simplification])
329 AT_CHECK([ovstest test-ovn exhaustive --operation=simplify --nvars=0 --svars=4 4], [0],
330   [Tested simplifying 21978 expressions of 4 terminals with 4 string vars.
331 ])
332 AT_CLEANUP
333
334 AT_SETUP([ovn -- 3-term mixed expression simplification])
335 AT_CHECK([ovstest test-ovn exhaustive --operation=simplify --nvars=1 --svars=1 3], [0],
336   [Tested simplifying 124410 expressions of 3 terminals with 1 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 1 string vars.
337 ])
338 AT_CLEANUP
339
340 AT_SETUP([ovn -- 4-term numeric expression normalization])
341 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=3 --svars=0 --bits=1 4], [0],
342   [Tested normalizing 1207162 expressions of 4 terminals with 3 numeric vars (each 1 bits) in terms of operators == != < <= > >=.
343 ])
344 AT_CLEANUP
345
346 AT_SETUP([ovn -- 4-term string expression normalization])
347 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=0 --svars=3 --bits=1 4], [0],
348   [Tested normalizing 11242 expressions of 4 terminals with 3 string vars.
349 ])
350 AT_CLEANUP
351
352 AT_SETUP([ovn -- 4-term mixed expression normalization])
353 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=1 --bits=1 --svars=2 4], [0],
354   [Tested normalizing 128282 expressions of 4 terminals with 1 numeric vars (each 1 bits) in terms of operators == != < <= > >= and 2 string vars.
355 ])
356 AT_CLEANUP
357
358 AT_SETUP([ovn -- 5-term numeric expression normalization])
359 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=3 --svars=0 --bits=1 --relops='==' 5], [0],
360   [Tested normalizing 368550 expressions of 5 terminals with 3 numeric vars (each 1 bits) in terms of operators ==.
361 ])
362 AT_CLEANUP
363
364 AT_SETUP([ovn -- 5-term string expression normalization])
365 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=0 --svars=3 --bits=1 --relops='==' 5], [0],
366   [Tested normalizing 368550 expressions of 5 terminals with 3 string vars.
367 ])
368 AT_CLEANUP
369
370 AT_SETUP([ovn -- 5-term mixed expression normalization])
371 AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=1 --svars=1 --bits=1 --relops='==' 5], [0],
372   [Tested normalizing 116550 expressions of 5 terminals with 1 numeric vars (each 1 bits) in terms of operators == and 1 string vars.
373 ])
374 AT_CLEANUP
375
376 AT_SETUP([ovn -- 4-term numeric expressions to flows])
377 AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=2 --svars=0 --bits=2 --relops='==' 4], [0],
378   [Tested converting to flows 128282 expressions of 4 terminals with 2 numeric vars (each 2 bits) in terms of operators ==.
379 ])
380 AT_CLEANUP
381
382 AT_SETUP([ovn -- 4-term string expressions to flows])
383 AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=0 --svars=4 4], [0],
384   [Tested converting to flows 21978 expressions of 4 terminals with 4 string vars.
385 ])
386 AT_CLEANUP
387
388 AT_SETUP([ovn -- 4-term mixed expressions to flows])
389 AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=1 --bits=2 --svars=1 --relops='==' 4], [0],
390   [Tested converting to flows 37994 expressions of 4 terminals with 1 numeric vars (each 2 bits) in terms of operators == and 1 string vars.
391 ])
392 AT_CLEANUP
393
394 AT_SETUP([ovn -- 3-term numeric expressions to flows])
395 AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=3 --svars=0 --bits=3 --relops='==' 3], [0],
396   [Tested converting to flows 38394 expressions of 3 terminals with 3 numeric vars (each 3 bits) in terms of operators ==.
397 ])
398 AT_CLEANUP
399
400 AT_SETUP([ovn -- converting expressions to flows -- string fields])
401 expr_to_flow () {
402     echo "$1" | ovstest test-ovn expr-to-flows | sort
403 }
404 AT_CHECK([expr_to_flow 'inport == "eth0"'], [0], [reg6=0x5
405 ])
406 AT_CHECK([expr_to_flow 'inport == "eth1"'], [0], [reg6=0x6
407 ])
408 AT_CHECK([expr_to_flow 'inport == "eth2"'], [0], [(no flows)
409 ])
410 AT_CHECK([expr_to_flow 'inport == "eth0" && ip'], [0], [dnl
411 ip,reg6=0x5
412 ipv6,reg6=0x5
413 ])
414 AT_CHECK([expr_to_flow 'inport == "eth1" && ip'], [0], [dnl
415 ip,reg6=0x6
416 ipv6,reg6=0x6
417 ])
418 AT_CHECK([expr_to_flow 'inport == "eth2" && ip'], [0], [(no flows)
419 ])
420 AT_CHECK([expr_to_flow 'inport == {"eth0", "eth1", "eth2", "LOCAL"}'], [0],
421 [reg6=0x5
422 reg6=0x6
423 reg6=0xfffe
424 ])
425 AT_CHECK([expr_to_flow 'inport == {"eth0", "eth1", "eth2"} && ip'], [0], [dnl
426 ip,reg6=0x5
427 ip,reg6=0x6
428 ipv6,reg6=0x5
429 ipv6,reg6=0x6
430 ])
431 AT_CHECK([expr_to_flow 'inport == "eth0" && inport == "eth1"'], [0], [dnl
432 (no flows)
433 ])
434 AT_CLEANUP
435
436 AT_SETUP([ovn -- action parsing])
437 dnl Text before => is input, text after => is expected output.
438 AT_DATA([test-cases.txt], [[
439 # Positive tests.
440 drop; => actions=drop, prereqs=1
441 next; => actions=resubmit(,11), prereqs=1
442 output; => actions=resubmit(,64), prereqs=1
443 outport="eth0"; next; outport="LOCAL"; next; => actions=set_field:0x5->reg7,resubmit(,11),set_field:0xfffe->reg7,resubmit(,11), prereqs=1
444 tcp.dst=80; => actions=set_field:80->tcp_dst, prereqs=ip.proto == 0x6 && (eth.type == 0x800 || eth.type == 0x86dd)
445 eth.dst[40] = 1; => actions=set_field:01:00:00:00:00:00/01:00:00:00:00:00->eth_dst, prereqs=1
446 vlan.pcp = 2; => actions=set_field:0x4000/0xe000->vlan_tci, prereqs=vlan.tci[12]
447 vlan.tci[13..15] = 2; => actions=set_field:0x4000/0xe000->vlan_tci, prereqs=1
448 reg0 = reg1; => actions=move:OXM_OF_PKT_REG0[0..31]->OXM_OF_PKT_REG0[32..63], prereqs=1
449 vlan.pcp = reg0[0..2]; => actions=move:OXM_OF_PKT_REG0[32..34]->NXM_OF_VLAN_TCI[13..15], prereqs=vlan.tci[12]
450 reg0[10] = vlan.pcp[1]; => actions=move:NXM_OF_VLAN_TCI[14]->OXM_OF_PKT_REG0[42], prereqs=vlan.tci[12]
451 outport = inport; => actions=move:NXM_NX_REG6[]->NXM_NX_REG7[], prereqs=1
452 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
453 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]
454 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]
455 outport <-> inport; => actions=push:NXM_NX_REG6[],push:NXM_NX_REG7[],pop:NXM_NX_REG6[],pop:NXM_NX_REG7[], prereqs=1
456 # Contradictionary prerequisites (allowed but not useful):
457 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
458 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
459
460 ## Negative tests.
461
462 ; => Syntax error at `;'.
463 xyzzy; => Syntax error at `xyzzy' expecting action.
464 next; 123; => Syntax error at `123'.
465 next; xyzzy; => Syntax error at `xyzzy' expecting action.
466
467 # "drop;" must be on its own:
468 drop; next; => Syntax error at `next' expecting end of input.
469 next; drop; => Syntax error at `drop' expecting action.
470
471 # Missing ";":
472 next => Syntax error at end of input expecting ';'.
473
474 inport[1] = 1; => Cannot select subfield of string field inport.
475 ip.proto[1] = 1; => Cannot select subfield of nominal field ip.proto.
476 eth.dst[40] == 1; => Syntax error at `==' expecting `='.
477 ip = 1; => Predicate symbol ip cannot be used in assignment.
478 ip.proto = 6; => Field ip.proto is not modifiable.
479 inport = {"a", "b"}; => Assignments require a single value.
480 inport = {}; => Syntax error at `}' expecting constant.
481 bad_prereq = 123; => Error parsing expression `xyzzy' encountered as prerequisite or predicate of initial expression: Syntax error at `xyzzy' expecting field name.
482 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'.
483 vlan.present = 0; => Predicate symbol vlan.present cannot be used in assignment.
484 reg0[0] = vlan.present; => Predicate symbol vlan.present cannot be used in assignment.
485 reg0 = reg1[0..10]; => Can't assign 11-bit value to 32-bit destination.
486 inport = reg0; => Can't assign integer field (reg0) to string field (inport).
487 inport = big_string; => String fields inport and big_string are incompatible for assignment.
488 ip.proto = reg0[0..7]; => Field ip.proto is not modifiable.
489 reg0[0] <-> vlan.present; => Predicate symbol vlan.present cannot be used in exchange.
490 reg0 <-> reg1[0..10]; => Can't exchange 32-bit field with 11-bit field.
491 inport <-> reg0; => Can't exchange string field (inport) with integer field (reg0).
492 inport <-> big_string; => String fields inport and big_string are incompatible for exchange.
493 ip.proto <-> reg0[0..7]; => Field ip.proto is not modifiable.
494 reg0[0..7] <-> ip.proto; => Field ip.proto is not modifiable.
495 ]])
496 sed 's/ =>.*//' test-cases.txt > input.txt
497 sed 's/.* => //' test-cases.txt > expout
498 AT_CHECK([ovstest test-ovn parse-actions < input.txt], [0], [expout])
499 AT_CLEANUP
500
501 AT_BANNER([OVN end-to-end tests])
502
503 AT_SETUP([ovn -- 3 HVs, 3 VIFs/HV, 1 logical switch])
504 AT_SKIP_IF([test $HAVE_PYTHON = no])
505 ovn_start
506
507 # Create hypervisors hv[123].
508 # Add vif1[123] to hv1, vif2[123] to hv2, vif3[123].
509 # Add all of the vifs to a single logical switch lsw0.
510 # Turn on port security on all the vifs except vif[123]1.
511 # Make vif13, vif2[23], vif3[123] destinations for unknown MACs.
512 # Add some ACLs for Ethertypes 1234, 1235, 1236.
513 ovn-nbctl lswitch-add lsw0
514 net_add n1
515 for i in 1 2 3; do
516     sim_add hv$i
517     as hv$i
518     ovs-vsctl add-br br-phys
519     ovn_attach n1 br-phys 192.168.0.$i
520
521     for j in 1 2 3; do
522         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
523         ovn-nbctl lport-add lsw0 lp$i$j
524         if test $j = 1; then
525             ovn-nbctl lport-set-macs lp$i$j f0:00:00:00:00:$i$j unknown
526         else
527             ovn-nbctl lport-set-macs lp$i$j f0:00:00:00:00:$i$j
528             ovn-nbctl lport-set-port-security lp$i$j f0:00:00:00:00:$i$j
529         fi
530     done
531 done
532 ovn-nbctl acl-add lsw0 from-lport 1000 'eth.type == 0x1234' drop
533 ovn-nbctl acl-add lsw0 from-lport 1000 'eth.type == 0x1235 && inport == "lp11"' drop
534 ovn-nbctl acl-add lsw0 to-lport 1000 'eth.type == 0x1236 && outport == "lp33"' drop
535
536 # Pre-populate the hypervisors' ARP tables so that we don't lose any
537 # packets for ARP resolution (native tunneling doesn't queue packets
538 # for ARP resolution).
539 ovn_populate_arp
540
541 # Allow some time for ovn-northd and ovn-controller to catch up.
542 # XXX This should be more systematic.
543 sleep 1
544 ovn-sbctl dump-flows -- list multicast_group
545
546 # test_packet INPORT DST SRC ETHTYPE OUTPORT...
547 #
548 # This shell function causes a packet to be received on INPORT.  The packet's
549 # content has Ethernet destination DST and source SRC (each exactly 12 hex
550 # digits) and Ethernet type ETHTYPE (4 hex digits).  The OUTPORTs (zero or
551 # more) list the VIFs on which the packet should be received.  INPORT and the
552 # OUTPORTs are specified as lport numbers, e.g. 11 for vif11.
553 trim_zeros() {
554     sed 's/\(00\)\{1,\}$//'
555 }
556 for i in 1 2 3; do
557     for j in 1 2 3; do
558         : > $i$j.expected
559     done
560 done
561 test_packet() {
562     local inport=$1 packet=$2$3$4; shift; shift; shift; shift
563     hv=hv`echo $inport | sed 's/^\(.\).*/\1/'`
564     vif=vif$inport
565     as $hv ovs-appctl netdev-dummy/receive $vif $packet
566     for outport; do
567         echo $packet | trim_zeros >> $outport.expected
568     done
569 }
570
571 # Send packets between all pairs of source and destination ports:
572 #
573 # 1. Unicast packets are delivered to exactly one lport (except that packets
574 #    destined to their input ports are dropped).
575 #
576 # 2. Broadcast and multicast are delivered to all lports except the input port.
577 #
578 # 3. When port security is turned on, the lswitch drops packets from the wrong
579 #    MAC address.
580 #
581 # 4. The lswitch drops all packets with a VLAN tag.
582 #
583 # 5. The lswitch drops all packets with a multicast source address.  (This only
584 #    affects behavior when port security is turned off, since otherwise port
585 #    security would drop the packet anyway.)
586 #
587 # 6. The lswitch delivers packets with an unknown destination to lports with
588 #    "unknown" among their MAC addresses (and port security disabled).
589 #
590 # 7. The lswitch drops unicast packets that violate an ACL.
591 #
592 # 8. The lswitch drops multicast and broadcast packets that violate an ACL.
593 for is in 1 2 3; do
594     for js in 1 2 3; do
595         s=$is$js
596         bcast=
597         unknown=
598         bacl2=
599         bacl3=
600         for id in 1 2 3; do
601             for jd in 1 2 3; do
602                 d=$id$jd
603
604                 if test $d != $s; then unicast=$d; else unicast=; fi
605                 test_packet $s f000000000$d f000000000$s $s$d $unicast     #1
606
607                 if test $d != $s && test $js = 1; then
608                     impersonate=$d
609                 else
610                     impersonate=
611                 fi
612                 test_packet $s f000000000$d f00000000055 55$d $impersonate #3
613
614                 if test $d != $s && test $s != 11; then acl2=$d; else acl2=; fi
615                 if test $d != $s && test $d != 33; then acl3=$d; else acl3=; fi
616                 test_packet $s f000000000$d f000000000$s 1234        #7, acl1
617                 test_packet $s f000000000$d f000000000$s 1235 $acl2  #7, acl2
618                 test_packet $s f000000000$d f000000000$s 1236 $acl3  #7, acl3
619
620                 test_packet $s f000000000$d f00000000055 810000091234      #4
621                 test_packet $s f000000000$d 0100000000$s $s$d              #5
622
623                 if test $d != $s && test $jd = 1; then
624                     unknown="$unknown $d"
625                 fi
626                 bcast="$bcast $unicast"
627                 bacl2="$bacl2 $acl2"
628                 bacl3="$bacl3 $acl3"
629             done
630         done
631
632         # Broadcast and multicast.
633         test_packet $s ffffffffffff f000000000$s ${s}ff $bcast             #2
634         test_packet $s 010000000000 f000000000$s ${s}ff $bcast             #2
635         if test $js = 1; then
636             bcast_impersonate=$bcast
637         else
638             bcast_impersonate=
639         fi
640         test_packet $s 010000000000 f00000000044 44ff $bcast_impersonate   #3
641
642         test_packet $s f0000000ffff f000000000$s ${s}66 $unknown           #6
643
644         test_packet $s ffffffffffff f000000000$s 1234                #8, acl1
645         test_packet $s ffffffffffff f000000000$s 1235 $bacl2         #8, acl2
646         test_packet $s ffffffffffff f000000000$s 1236 $bacl3         #8, acl3
647         test_packet $s 010000000000 f000000000$s 1234                #8, acl1
648         test_packet $s 010000000000 f000000000$s 1235 $bacl2         #8, acl2
649         test_packet $s 010000000000 f000000000$s 1236 $bacl3         #8, acl3
650     done
651 done
652
653 # Allow some time for packet forwarding.
654 # XXX This can be improved.
655 sleep 1
656
657 # Now check the packets actually received against the ones expected.
658 for i in 1 2 3; do
659     for j in 1 2 3; do
660         file=hv$i/vif$i$j-tx.pcap
661         echo $file
662         $PYTHON "$top_srcdir/utilities/ovs-pcap.in" $file | trim_zeros > $i$j.packets
663         cp $i$j.expected expout
664         AT_CHECK([cat $i$j.packets], [0], [expout])
665         echo
666     done
667 done
668 AT_CLEANUP