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