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