]>
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 () { | |
abb37b6b FF |
21 | $PYTHON "$top_srcdir/utilities/ovs-pcap.in" $rcv_pcap > $rcv_text |
22 | rcv_n=`wc -l < "$rcv_text"` | |
23 | test $rcv_n -ge $exp_n | |
49d7c759 BP |
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], | |
858c2f76 GS |
165 | [[ct.dnat = ct_state[7] |
166 | ct.est = ct_state[1] | |
2277b860 BP |
167 | ct.inv = ct_state[4] |
168 | ct.new = ct_state[0] | |
169 | ct.rel = ct_state[2] | |
170 | ct.rpl = ct_state[3] | |
858c2f76 | 171 | ct.snat = ct_state[6] |
2277b860 BP |
172 | ct.trk = ct_state[5] |
173 | ct_label = NXM_NX_CT_LABEL | |
b73db61d | 174 | ct_label.blocked = ct_label[0] |
2277b860 BP |
175 | ct_mark = NXM_NX_CT_MARK |
176 | ct_state = NXM_NX_CT_STATE | |
177 | ]]) | |
178 | AT_CLEANUP | |
179 | ||
42d36b58 AZ |
180 | AT_SETUP([ovn -- compsition]) |
181 | AT_CHECK([ovstest test-ovn composition 2], [0], [ignore]) | |
182 | AT_CLEANUP | |
183 | ||
e0840f11 BP |
184 | AT_SETUP([ovn -- expression parser]) |
185 | dnl For lines without =>, input and expected output are identical. | |
186 | dnl For lines with =>, input precedes => and expected output follows =>. | |
187 | AT_DATA([test-cases.txt], [[ | |
188 | eth.type == 0x800 | |
189 | eth.type==0x800 => eth.type == 0x800 | |
190 | eth.type[0..15] == 0x800 => eth.type == 0x800 | |
191 | ||
192 | vlan.present | |
193 | vlan.present == 1 => vlan.present | |
194 | !(vlan.present == 0) => vlan.present | |
195 | !(vlan.present != 1) => vlan.present | |
196 | !vlan.present | |
197 | vlan.present == 0 => !vlan.present | |
198 | vlan.present != 1 => !vlan.present | |
199 | !(vlan.present == 1) => !vlan.present | |
200 | !(vlan.present != 0) => !vlan.present | |
201 | ||
202 | eth.dst[0] | |
203 | eth.dst[0] == 1 => eth.dst[0] | |
204 | eth.dst[0] != 0 => eth.dst[0] | |
205 | !(eth.dst[0] == 0) => eth.dst[0] | |
206 | !(eth.dst[0] != 1) => eth.dst[0] | |
207 | ||
208 | !eth.dst[0] | |
209 | eth.dst[0] == 0 => !eth.dst[0] | |
210 | eth.dst[0] != 1 => !eth.dst[0] | |
211 | !(eth.dst[0] == 1) => !eth.dst[0] | |
212 | !(eth.dst[0] != 0) => !eth.dst[0] | |
213 | ||
214 | vlan.tci[12..15] == 0x3 | |
215 | vlan.tci == 0x3000/0xf000 => vlan.tci[12..15] == 0x3 | |
216 | vlan.tci[12..15] != 0x3 | |
217 | vlan.tci != 0x3000/0xf000 => vlan.tci[12..15] != 0x3 | |
218 | ||
219 | !vlan.pcp => vlan.pcp == 0 | |
220 | !(vlan.pcp) => vlan.pcp == 0 | |
221 | vlan.pcp == 0x4 | |
222 | vlan.pcp != 0x4 | |
223 | vlan.pcp > 0x4 | |
224 | vlan.pcp >= 0x4 | |
225 | vlan.pcp < 0x4 | |
226 | vlan.pcp <= 0x4 | |
227 | !(vlan.pcp != 0x4) => vlan.pcp == 0x4 | |
228 | !(vlan.pcp == 0x4) => vlan.pcp != 0x4 | |
229 | !(vlan.pcp <= 0x4) => vlan.pcp > 0x4 | |
230 | !(vlan.pcp < 0x4) => vlan.pcp >= 0x4 | |
231 | !(vlan.pcp >= 0x4) => vlan.pcp < 0x4 | |
232 | !(vlan.pcp > 0x4) => 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 | 0x4 >= vlan.pcp => vlan.pcp <= 0x4 | |
239 | !(0x4 != vlan.pcp) => vlan.pcp == 0x4 | |
240 | !(0x4 == vlan.pcp) => vlan.pcp != 0x4 | |
241 | !(0x4 >= vlan.pcp) => vlan.pcp > 0x4 | |
242 | !(0x4 > vlan.pcp) => vlan.pcp >= 0x4 | |
243 | !(0x4 <= vlan.pcp) => vlan.pcp < 0x4 | |
244 | !(0x4 < vlan.pcp) => vlan.pcp <= 0x4 | |
245 | ||
246 | 1 < vlan.pcp < 4 => vlan.pcp > 0x1 && vlan.pcp < 0x4 | |
247 | 1 <= vlan.pcp <= 4 => vlan.pcp >= 0x1 && vlan.pcp <= 0x4 | |
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 | 4 > vlan.pcp > 1 => vlan.pcp < 0x4 && vlan.pcp > 0x1 | |
252 | 4 >= vlan.pcp > 1 => vlan.pcp <= 0x4 && vlan.pcp > 0x1 | |
253 | 4 > vlan.pcp >= 1 => vlan.pcp < 0x4 && vlan.pcp >= 0x1 | |
254 | 4 >= vlan.pcp >= 1 => vlan.pcp <= 0x4 && vlan.pcp >= 0x1 | |
255 | !(1 < vlan.pcp < 4) => vlan.pcp <= 0x1 || vlan.pcp >= 0x4 | |
256 | !(1 <= vlan.pcp <= 4) => vlan.pcp < 0x1 || vlan.pcp > 0x4 | |
257 | !(1 < vlan.pcp <= 4) => vlan.pcp <= 0x1 || vlan.pcp > 0x4 | |
258 | !(1 <= vlan.pcp < 4) => vlan.pcp < 0x1 || vlan.pcp >= 0x4 | |
259 | !(1 <= vlan.pcp <= 4) => vlan.pcp < 0x1 || vlan.pcp > 0x4 | |
260 | !(4 > vlan.pcp > 1) => vlan.pcp >= 0x4 || vlan.pcp <= 0x1 | |
261 | !(4 >= vlan.pcp > 1) => vlan.pcp > 0x4 || vlan.pcp <= 0x1 | |
262 | !(4 > vlan.pcp >= 1) => vlan.pcp >= 0x4 || vlan.pcp < 0x1 | |
263 | !(4 >= vlan.pcp >= 1) => vlan.pcp > 0x4 || vlan.pcp < 0x1 | |
264 | ||
265 | vlan.pcp == {1, 2, 3, 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 | vlan.pcp != {1, 2, 3, 4} => vlan.pcp != 0x1 && vlan.pcp != 0x2 && vlan.pcp != 0x3 && vlan.pcp != 0x4 | |
269 | vlan.pcp == 1 && ((vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && vlan.pcp == 0x2 && vlan.pcp == 0x3 && vlan.pcp == 0x4 | |
270 | ||
271 | vlan.pcp == 1 && !((vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && (vlan.pcp != 0x2 || vlan.pcp != 0x3 || vlan.pcp != 0x4) | |
272 | vlan.pcp == 1 && (!(vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && (vlan.pcp != 0x2 || vlan.pcp != 0x3) && vlan.pcp == 0x4 | |
273 | vlan.pcp == 1 && !(!(vlan.pcp == 2 && vlan.pcp == 3) && vlan.pcp == 4) => vlan.pcp == 0x1 && ((vlan.pcp == 0x2 && vlan.pcp == 0x3) || vlan.pcp != 0x4) | |
274 | ||
275 | 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 | |
276 | ip6.src == ::1 => ip6.src == 0x1 | |
277 | ||
278 | ip4.src == 1.2.3.4 => ip4.src == 0x1020304 | |
279 | ip4.src == ::1.2.3.4/::ffff:ffff => ip4.src == 0x1020304 | |
280 | ip6.src == ::1 => ip6.src == 0x1 | |
281 | ||
282 | 1 | |
283 | 0 | |
284 | !1 => 0 | |
285 | !0 => 1 | |
286 | ||
287 | inport == "eth0" | |
288 | !(inport != "eth0") => inport == "eth0" | |
289 | ||
3b7cb7e1 BP |
290 | ip4.src == "eth0" => Integer field ip4.src is not compatible with string constant. |
291 | inport == 1 => String field inport is not compatible with integer constant. | |
76da94b5 | 292 | ip4.src = 1.2.3.4 => Syntax error at `=' expecting relational operator. |
e0840f11 BP |
293 | |
294 | ip4.src > {1, 2, 3} => Only == and != operators may be used with value sets. | |
295 | eth.type > 0x800 => Only == and != operators may be used with nominal field eth.type. | |
296 | vlan.present > 0 => Only == and != operators may be used with Boolean field vlan.present. | |
297 | ||
298 | inport != "eth0" => Nominal field inport may only be tested for equality (taking enclosing `!' operators into account). | |
299 | !(inport == "eth0") => Nominal field inport may only be tested for equality (taking enclosing `!' operators into account). | |
300 | eth.type != 0x800 => Nominal field eth.type may only be tested for equality (taking enclosing `!' operators into account). | |
301 | !(eth.type == 0x800) => Nominal field eth.type may only be tested for equality (taking enclosing `!' operators into account). | |
76da94b5 | 302 | inport = "eth0" => Syntax error at `=' expecting relational operator. |
e0840f11 BP |
303 | |
304 | 123 == 123 => Syntax error at `123' expecting field name. | |
305 | ||
2c5cbb15 RB |
306 | $name => Syntax error at `$name' expecting address set name. |
307 | ||
e0840f11 BP |
308 | 123 == xyzzy => Syntax error at `xyzzy' expecting field name. |
309 | xyzzy == 1 => Syntax error at `xyzzy' expecting field name. | |
310 | ||
311 | inport[1] == 1 => Cannot select subfield of string field inport. | |
312 | ||
313 | eth.type[] == 1 => Syntax error at `@:>@' expecting small integer. | |
314 | eth.type[::1] == 1 => Syntax error at `::1' expecting small integer. | |
315 | eth.type[18446744073709551615] == 1 => Syntax error at `18446744073709551615' expecting small integer. | |
316 | ||
317 | eth.type[5!] => Syntax error at `!' expecting `@:>@'. | |
318 | ||
319 | eth.type[5..1] => Invalid bit range 5 to 1. | |
320 | ||
321 | eth.type[12..16] => Cannot select bits 12 to 16 of 16-bit field eth.type. | |
322 | ||
323 | eth.type[10] == 1 => Cannot select subfield of nominal field eth.type. | |
324 | ||
325 | eth.type => Explicit `!= 0' is required for inequality test of multibit field against 0. | |
326 | ||
327 | !(!(vlan.pcp)) => Explicit `!= 0' is required for inequality test of multibit field against 0. | |
328 | ||
329 | 123 => Syntax error at end of input expecting relational operator. | |
330 | ||
331 | 123 x => Syntax error at `x' expecting relational operator. | |
332 | ||
333 | {1, "eth0"} => Syntax error at `"eth0"' expecting integer. | |
334 | ||
335 | eth.type == xyzzy => Syntax error at `xyzzy' expecting constant. | |
336 | ||
337 | (1 x) => Syntax error at `x' expecting `)'. | |
338 | ||
339 | !0x800 != eth.type => Missing parentheses around operand of !. | |
340 | ||
341 | eth.type == 0x800 || eth.type == 0x86dd && ip.proto == 17 => && and || must be parenthesized when used together. | |
342 | ||
343 | eth.dst == {} => Syntax error at `}' expecting constant. | |
344 | ||
345 | 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). | |
346 | ||
3b7cb7e1 | 347 | ip4.src == ::1 => 128-bit constant is not compatible with 32-bit field ip4.src. |
e0840f11 BP |
348 | |
349 | 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 | 350 | |
9aef3c1b | 351 | eth.dst[40] x => Syntax error at `x' expecting end of input. |
ea382567 RB |
352 | |
353 | ip4.src == {1.2.3.4, $set1, $unknownset} => Syntax error at `$unknownset' expecting address set name. | |
354 | eth.src == {$set3, badmac, 00:00:00:00:00:01} => Syntax error at `badmac' expecting constant. | |
e0840f11 BP |
355 | ]]) |
356 | sed 's/ =>.*//' test-cases.txt > input.txt | |
357 | sed 's/.* => //' test-cases.txt > expout | |
358 | AT_CHECK([ovstest test-ovn parse-expr < input.txt], [0], [expout]) | |
359 | AT_CLEANUP | |
360 | ||
361 | AT_SETUP([ovn -- expression annotation]) | |
362 | dnl Input precedes =>, expected output follows =>. | |
363 | AT_DATA([test-cases.txt], [[ | |
364 | ip4.src == 1.2.3.4 => ip4.src == 0x1020304 && eth.type == 0x800 | |
365 | ip4.src != 1.2.3.4 => ip4.src != 0x1020304 && eth.type == 0x800 | |
366 | ip.proto == 123 => ip.proto == 0x7b && (eth.type == 0x800 || eth.type == 0x86dd) | |
367 | ip.proto == {123, 234} => (ip.proto == 0x7b && (eth.type == 0x800 || eth.type == 0x86dd)) || (ip.proto == 0xea && (eth.type == 0x800 || eth.type == 0x86dd)) | |
368 | ip4.src == 1.2.3.4 && ip4.dst == 5.6.7.8 => ip4.src == 0x1020304 && eth.type == 0x800 && ip4.dst == 0x5060708 && eth.type == 0x800 | |
369 | ||
370 | ip => eth.type == 0x800 || eth.type == 0x86dd | |
371 | ip == 1 => eth.type == 0x800 || eth.type == 0x86dd | |
372 | ip[0] == 1 => eth.type == 0x800 || eth.type == 0x86dd | |
373 | ip > 0 => Only == and != operators may be used with nominal field ip. | |
374 | !ip => Nominal predicate ip may only be tested positively, e.g. `ip' or `ip == 1' but not `!ip' or `ip == 0'. | |
375 | ip == 0 => Nominal predicate ip may only be tested positively, e.g. `ip' or `ip == 1' but not `!ip' or `ip == 0'. | |
376 | ||
377 | vlan.present => vlan.tci[12] | |
378 | !vlan.present => !vlan.tci[12] | |
379 | ||
380 | !vlan.pcp => vlan.tci[13..15] == 0 && vlan.tci[12] | |
381 | vlan.pcp == 1 && vlan.vid == 2 => vlan.tci[13..15] == 0x1 && vlan.tci[12] && vlan.tci[0..11] == 0x2 && vlan.tci[12] | |
7700eea0 | 382 | !reg0 && !reg1 && !reg2 && !reg3 => xxreg0[96..127] == 0 && xxreg0[64..95] == 0 && xxreg0[32..63] == 0 && xxreg0[0..31] == 0 |
e0840f11 BP |
383 | |
384 | ip.first_frag => ip.frag[0] && (eth.type == 0x800 || eth.type == 0x86dd) && (!ip.frag[1] || (eth.type != 0x800 && eth.type != 0x86dd)) | |
385 | !ip.first_frag => !ip.frag[0] || (eth.type != 0x800 && eth.type != 0x86dd) || (ip.frag[1] && (eth.type == 0x800 || eth.type == 0x86dd)) | |
386 | ip.later_frag => ip.frag[1] && (eth.type == 0x800 || eth.type == 0x86dd) | |
387 | ||
388 | bad_prereq != 0 => Error parsing expression `xyzzy' encountered as prerequisite or predicate of initial expression: Syntax error at `xyzzy' expecting field name. | |
389 | self_recurse != 0 => Error parsing expression `self_recurse != 0' encountered as prerequisite or predicate of initial expression: Recursive expansion of symbol `self_recurse'. | |
390 | 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'. | |
391 | 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'. | |
392 | ]]) | |
393 | sed 's/ =>.*//' test-cases.txt > input.txt | |
394 | sed 's/.* => //' test-cases.txt > expout | |
395 | AT_CHECK([ovstest test-ovn annotate-expr < input.txt], [0], [expout]) | |
396 | AT_CLEANUP | |
397 | ||
9d4aecca | 398 | AT_SETUP([ovn -- 1-term expression conversion]) |
e0840f11 | 399 | AT_CHECK([ovstest test-ovn exhaustive --operation=convert 1], [0], |
9d4aecca | 400 | [Tested converting all 1-terminal expressions with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 2 string vars. |
e0840f11 BP |
401 | ]) |
402 | AT_CLEANUP | |
403 | ||
9d4aecca | 404 | AT_SETUP([ovn -- 2-term expression conversion]) |
e0840f11 | 405 | AT_CHECK([ovstest test-ovn exhaustive --operation=convert 2], [0], |
8c3caa2c | 406 | [Tested converting 578 expressions of 2 terminals with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 2 string vars. |
e0840f11 BP |
407 | ]) |
408 | AT_CLEANUP | |
409 | ||
9d4aecca | 410 | AT_SETUP([ovn -- 3-term expression conversion]) |
e0840f11 | 411 | AT_CHECK([ovstest test-ovn exhaustive --operation=convert --bits=2 3], [0], |
8c3caa2c | 412 | [Tested converting 67410 expressions of 3 terminals with 2 numeric vars (each 2 bits) in terms of operators == != < <= > >= and 2 string vars. |
e0840f11 BP |
413 | ]) |
414 | AT_CLEANUP | |
415 | ||
9d4aecca BP |
416 | AT_SETUP([ovn -- 3-term numeric expression simplification]) |
417 | AT_CHECK([ovstest test-ovn exhaustive --operation=simplify --nvars=2 --svars=0 3], [0], | |
8c3caa2c | 418 | [Tested simplifying 490770 expressions of 3 terminals with 2 numeric vars (each 3 bits) in terms of operators == != < <= > >=. |
e0840f11 BP |
419 | ]) |
420 | AT_CLEANUP | |
421 | ||
9d4aecca BP |
422 | AT_SETUP([ovn -- 4-term string expression simplification]) |
423 | AT_CHECK([ovstest test-ovn exhaustive --operation=simplify --nvars=0 --svars=4 4], [0], | |
424 | [Tested simplifying 21978 expressions of 4 terminals with 4 string vars. | |
e0840f11 BP |
425 | ]) |
426 | AT_CLEANUP | |
427 | ||
9d4aecca BP |
428 | AT_SETUP([ovn -- 3-term mixed expression simplification]) |
429 | AT_CHECK([ovstest test-ovn exhaustive --operation=simplify --nvars=1 --svars=1 3], [0], | |
8c3caa2c | 430 | [Tested simplifying 127890 expressions of 3 terminals with 1 numeric vars (each 3 bits) in terms of operators == != < <= > >= and 1 string vars. |
e0840f11 BP |
431 | ]) |
432 | AT_CLEANUP | |
433 | ||
97ba1d55 BP |
434 | AT_SETUP([ovn -- simplification special cases]) |
435 | simplify() { | |
436 | echo "$1" | ovstest test-ovn simplify-expr | |
437 | } | |
438 | AT_CHECK([simplify 'eth.dst == 0/0'], [0], [1 | |
439 | ]) | |
a3d79068 BP |
440 | AT_CHECK([simplify 'eth.dst != 0/0'], [0], [0 |
441 | ]) | |
33f15d17 BP |
442 | AT_CHECK([simplify 'tcp.dst >= 0'], [0], |
443 | [ip.proto == 0x6 && (eth.type == 0x800 || eth.type == 0x86dd) | |
444 | ]) | |
445 | AT_CHECK([simplify 'tcp.dst <= 65535'], [0], | |
446 | [ip.proto == 0x6 && (eth.type == 0x800 || eth.type == 0x86dd) | |
447 | ]) | |
448 | AT_CHECK([simplify 'tcp.dst > 0'], [0], | |
449 | [[(tcp.dst[0] || tcp.dst[1] || tcp.dst[2] || tcp.dst[3] || tcp.dst[4] || tcp.dst[5] || tcp.dst[6] || tcp.dst[7] || tcp.dst[8] || tcp.dst[9] || tcp.dst[10] || tcp.dst[11] || tcp.dst[12] || tcp.dst[13] || tcp.dst[14] || tcp.dst[15]) && ip.proto == 0x6 && (eth.type == 0x800 || eth.type == 0x86dd) | |
450 | ]]) | |
451 | AT_CHECK([simplify 'tcp.dst < 65535'], [0], | |
452 | [[(!tcp.dst[0] || !tcp.dst[1] || !tcp.dst[2] || !tcp.dst[3] || !tcp.dst[4] || !tcp.dst[5] || !tcp.dst[6] || !tcp.dst[7] || !tcp.dst[8] || !tcp.dst[9] || !tcp.dst[10] || !tcp.dst[11] || !tcp.dst[12] || !tcp.dst[13] || !tcp.dst[14] || !tcp.dst[15]) && ip.proto == 0x6 && (eth.type == 0x800 || eth.type == 0x86dd) | |
453 | ]]) | |
97ba1d55 BP |
454 | AT_CLEANUP |
455 | ||
9d4aecca BP |
456 | AT_SETUP([ovn -- 4-term numeric expression normalization]) |
457 | AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=3 --svars=0 --bits=1 4], [0], | |
8c3caa2c | 458 | [Tested normalizing 1874026 expressions of 4 terminals with 3 numeric vars (each 1 bits) in terms of operators == != < <= > >=. |
e0840f11 BP |
459 | ]) |
460 | AT_CLEANUP | |
461 | ||
9d4aecca BP |
462 | AT_SETUP([ovn -- 4-term string expression normalization]) |
463 | AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=0 --svars=3 --bits=1 4], [0], | |
464 | [Tested normalizing 11242 expressions of 4 terminals with 3 string vars. | |
465 | ]) | |
466 | AT_CLEANUP | |
467 | ||
468 | AT_SETUP([ovn -- 4-term mixed expression normalization]) | |
469 | AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=1 --bits=1 --svars=2 4], [0], | |
8c3caa2c | 470 | [Tested normalizing 175978 expressions of 4 terminals with 1 numeric vars (each 1 bits) in terms of operators == != < <= > >= and 2 string vars. |
9d4aecca BP |
471 | ]) |
472 | AT_CLEANUP | |
473 | ||
474 | AT_SETUP([ovn -- 5-term numeric expression normalization]) | |
475 | AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=3 --svars=0 --bits=1 --relops='==' 5], [0], | |
8c3caa2c | 476 | [Tested normalizing 1317600 expressions of 5 terminals with 3 numeric vars (each 1 bits) in terms of operators ==. |
9d4aecca BP |
477 | ]) |
478 | AT_CLEANUP | |
479 | ||
480 | AT_SETUP([ovn -- 5-term string expression normalization]) | |
481 | AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=0 --svars=3 --bits=1 --relops='==' 5], [0], | |
482 | [Tested normalizing 368550 expressions of 5 terminals with 3 string vars. | |
483 | ]) | |
484 | AT_CLEANUP | |
485 | ||
486 | AT_SETUP([ovn -- 5-term mixed expression normalization]) | |
487 | AT_CHECK([ovstest test-ovn exhaustive --operation=normalize --nvars=1 --svars=1 --bits=1 --relops='==' 5], [0], | |
8c3caa2c | 488 | [Tested normalizing 216000 expressions of 5 terminals with 1 numeric vars (each 1 bits) in terms of operators == and 1 string vars. |
9d4aecca BP |
489 | ]) |
490 | AT_CLEANUP | |
491 | ||
492 | AT_SETUP([ovn -- 4-term numeric expressions to flows]) | |
8c3caa2c | 493 | AT_KEYWORDS([expression]) |
9d4aecca | 494 | AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=2 --svars=0 --bits=2 --relops='==' 4], [0], |
8c3caa2c | 495 | [Tested converting to flows 175978 expressions of 4 terminals with 2 numeric vars (each 2 bits) in terms of operators ==. |
9d4aecca BP |
496 | ]) |
497 | AT_CLEANUP | |
498 | ||
499 | AT_SETUP([ovn -- 4-term string expressions to flows]) | |
8c3caa2c | 500 | AT_KEYWORDS([expression]) |
9d4aecca BP |
501 | AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=0 --svars=4 4], [0], |
502 | [Tested converting to flows 21978 expressions of 4 terminals with 4 string vars. | |
503 | ]) | |
504 | AT_CLEANUP | |
505 | ||
506 | AT_SETUP([ovn -- 4-term mixed expressions to flows]) | |
8c3caa2c | 507 | AT_KEYWORDS([expression]) |
9d4aecca | 508 | AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=1 --bits=2 --svars=1 --relops='==' 4], [0], |
8c3caa2c | 509 | [Tested converting to flows 48312 expressions of 4 terminals with 1 numeric vars (each 2 bits) in terms of operators == and 1 string vars. |
9d4aecca BP |
510 | ]) |
511 | AT_CLEANUP | |
512 | ||
513 | AT_SETUP([ovn -- 3-term numeric expressions to flows]) | |
8c3caa2c | 514 | AT_KEYWORDS([expression]) |
9d4aecca | 515 | AT_CHECK([ovstest test-ovn exhaustive --operation=flow --nvars=3 --svars=0 --bits=3 --relops='==' 3], [0], |
8c3caa2c | 516 | [Tested converting to flows 41328 expressions of 3 terminals with 3 numeric vars (each 3 bits) in terms of operators ==. |
e0840f11 BP |
517 | ]) |
518 | AT_CLEANUP | |
f386a8a7 BP |
519 | |
520 | AT_SETUP([ovn -- converting expressions to flows -- string fields]) | |
8c3caa2c | 521 | AT_KEYWORDS([expression]) |
f386a8a7 BP |
522 | expr_to_flow () { |
523 | echo "$1" | ovstest test-ovn expr-to-flows | sort | |
524 | } | |
cc5e28d8 | 525 | AT_CHECK([expr_to_flow 'inport == "eth0"'], [0], [reg14=0x5 |
f386a8a7 | 526 | ]) |
cc5e28d8 | 527 | AT_CHECK([expr_to_flow 'inport == "eth1"'], [0], [reg14=0x6 |
f386a8a7 BP |
528 | ]) |
529 | AT_CHECK([expr_to_flow 'inport == "eth2"'], [0], [(no flows) | |
530 | ]) | |
531 | AT_CHECK([expr_to_flow 'inport == "eth0" && ip'], [0], [dnl | |
cc5e28d8 JP |
532 | ip,reg14=0x5 |
533 | ipv6,reg14=0x5 | |
f386a8a7 BP |
534 | ]) |
535 | AT_CHECK([expr_to_flow 'inport == "eth1" && ip'], [0], [dnl | |
cc5e28d8 JP |
536 | ip,reg14=0x6 |
537 | ipv6,reg14=0x6 | |
f386a8a7 BP |
538 | ]) |
539 | AT_CHECK([expr_to_flow 'inport == "eth2" && ip'], [0], [(no flows) | |
540 | ]) | |
541 | AT_CHECK([expr_to_flow 'inport == {"eth0", "eth1", "eth2", "LOCAL"}'], [0], | |
cc5e28d8 JP |
542 | [reg14=0x5 |
543 | reg14=0x6 | |
544 | reg14=0xfffe | |
f386a8a7 BP |
545 | ]) |
546 | AT_CHECK([expr_to_flow 'inport == {"eth0", "eth1", "eth2"} && ip'], [0], [dnl | |
cc5e28d8 JP |
547 | ip,reg14=0x5 |
548 | ip,reg14=0x6 | |
549 | ipv6,reg14=0x5 | |
550 | ipv6,reg14=0x6 | |
f386a8a7 | 551 | ]) |
9d4aecca BP |
552 | AT_CHECK([expr_to_flow 'inport == "eth0" && inport == "eth1"'], [0], [dnl |
553 | (no flows) | |
554 | ]) | |
f386a8a7 | 555 | AT_CLEANUP |
3b7cb7e1 | 556 | |
2c5cbb15 | 557 | AT_SETUP([ovn -- converting expressions to flows -- address sets]) |
8c3caa2c | 558 | AT_KEYWORDS([expression]) |
2c5cbb15 RB |
559 | expr_to_flow () { |
560 | echo "$1" | ovstest test-ovn expr-to-flows | sort | |
561 | } | |
562 | AT_CHECK([expr_to_flow 'ip4.src == {10.0.0.1, 10.0.0.2, 10.0.0.3}'], [0], [dnl | |
563 | ip,nw_src=10.0.0.1 | |
564 | ip,nw_src=10.0.0.2 | |
565 | ip,nw_src=10.0.0.3 | |
566 | ]) | |
567 | AT_CHECK([expr_to_flow 'ip4.src == $set1'], [0], [dnl | |
568 | ip,nw_src=10.0.0.1 | |
569 | ip,nw_src=10.0.0.2 | |
570 | ip,nw_src=10.0.0.3 | |
571 | ]) | |
572 | AT_CHECK([expr_to_flow 'ip4.src == {1.2.3.4, $set1}'], [0], [dnl | |
573 | ip,nw_src=1.2.3.4 | |
574 | ip,nw_src=10.0.0.1 | |
575 | ip,nw_src=10.0.0.2 | |
576 | ip,nw_src=10.0.0.3 | |
577 | ]) | |
578 | AT_CHECK([expr_to_flow 'ip4.src == {1.2.0.0/20, 5.5.5.0/24, $set1}'], [0], [dnl | |
579 | ip,nw_src=1.2.0.0/20 | |
580 | ip,nw_src=10.0.0.1 | |
581 | ip,nw_src=10.0.0.2 | |
582 | ip,nw_src=10.0.0.3 | |
583 | ip,nw_src=5.5.5.0/24 | |
584 | ]) | |
585 | AT_CHECK([expr_to_flow 'ip6.src == {::1, ::2, ::3}'], [0], [dnl | |
586 | ipv6,ipv6_src=::1 | |
587 | ipv6,ipv6_src=::2 | |
588 | ipv6,ipv6_src=::3 | |
589 | ]) | |
590 | AT_CHECK([expr_to_flow 'ip6.src == {::1, $set2, ::4}'], [0], [dnl | |
591 | ipv6,ipv6_src=::1 | |
592 | ipv6,ipv6_src=::2 | |
593 | ipv6,ipv6_src=::3 | |
594 | ipv6,ipv6_src=::4 | |
595 | ]) | |
596 | 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 | |
597 | dl_src=00:00:00:00:00:01 | |
598 | dl_src=00:00:00:00:00:02 | |
599 | dl_src=00:00:00:00:00:03 | |
600 | ]) | |
601 | AT_CHECK([expr_to_flow 'eth.src == {$set3}'], [0], [dnl | |
602 | dl_src=00:00:00:00:00:01 | |
603 | dl_src=00:00:00:00:00:02 | |
604 | dl_src=00:00:00:00:00:03 | |
605 | ]) | |
ea382567 RB |
606 | AT_CHECK([expr_to_flow 'eth.src == {00:00:00:00:00:01, $set3, ba:be:be:ef:de:ad, $set3}'], [0], [dnl |
607 | dl_src=00:00:00:00:00:01 | |
608 | dl_src=00:00:00:00:00:02 | |
609 | dl_src=00:00:00:00:00:03 | |
610 | dl_src=ba:be:be:ef:de:ad | |
611 | ]) | |
2c5cbb15 RB |
612 | AT_CLEANUP |
613 | ||
3b7cb7e1 | 614 | AT_SETUP([ovn -- action parsing]) |
d5a76da4 BP |
615 | dnl Unindented text is input (a set of OVN logical actions). |
616 | dnl Indented text is expected output. | |
617 | AT_DATA([test-cases.txt], | |
618 | [[# drop | |
619 | drop; | |
620 | encodes as drop | |
621 | drop; next; | |
622 | Syntax error at `next' expecting end of input. | |
623 | next; drop; | |
624 | Syntax error at `drop' expecting action. | |
5f822129 BP |
625 | |
626 | # output | |
d5a76da4 BP |
627 | output; |
628 | encodes as resubmit(,64) | |
5f822129 BP |
629 | |
630 | # next | |
d5a76da4 BP |
631 | next; |
632 | formats as next(11); | |
633 | encodes as resubmit(,27) | |
634 | next(11); | |
635 | encodes as resubmit(,27) | |
636 | next(0); | |
637 | encodes as resubmit(,16) | |
638 | next(15); | |
639 | encodes as resubmit(,31) | |
640 | ||
641 | next(); | |
642 | Syntax error at `)' expecting small integer. | |
643 | next(10; | |
644 | Syntax error at `;' expecting `)'. | |
645 | next(16); | |
646 | "next" argument must be in range 0 to 15. | |
5f822129 BP |
647 | |
648 | # Loading a constant value. | |
d5a76da4 BP |
649 | tcp.dst=80; |
650 | formats as tcp.dst = 80; | |
651 | encodes as set_field:80->tcp_dst | |
652 | has prereqs ip.proto == 0x6 && (eth.type == 0x800 || eth.type == 0x86dd) | |
653 | eth.dst[40] = 1; | |
654 | encodes as set_field:01:00:00:00:00:00/01:00:00:00:00:00->eth_dst | |
655 | vlan.pcp = 2; | |
656 | encodes as set_field:0x4000/0xe000->vlan_tci | |
657 | has prereqs vlan.tci[12] | |
658 | vlan.tci[13..15] = 2; | |
659 | encodes as set_field:0x4000/0xe000->vlan_tci | |
660 | inport = ""; | |
661 | encodes as set_field:0->reg14 | |
662 | ip.ttl=4; | |
663 | formats as ip.ttl = 4; | |
664 | encodes as set_field:4->nw_ttl | |
665 | has prereqs eth.type == 0x800 || eth.type == 0x86dd | |
666 | outport="eth0"; next; outport="LOCAL"; next; | |
667 | formats as outport = "eth0"; next(11); outport = "LOCAL"; next(11); | |
668 | encodes as set_field:0x5->reg15,resubmit(,27),set_field:0xfffe->reg15,resubmit(,27) | |
669 | ||
670 | inport[1] = 1; | |
671 | Cannot select subfield of string field inport. | |
672 | ip.proto[1] = 1; | |
673 | Cannot select subfield of nominal field ip.proto. | |
674 | eth.dst[40] == 1; | |
675 | Syntax error at `==' expecting `=' or `<->'. | |
676 | ip = 1; | |
677 | Predicate symbol ip used where lvalue required. | |
678 | ip.proto = 6; | |
679 | Field ip.proto is not modifiable. | |
680 | inport = {"a", "b"}; | |
681 | Syntax error at `{' expecting constant. | |
682 | inport = {}; | |
683 | Syntax error at `{' expecting constant. | |
684 | bad_prereq = 123; | |
685 | Error parsing expression `xyzzy' encountered as prerequisite or predicate of initial expression: Syntax error at `xyzzy' expecting field name. | |
686 | self_recurse = 123; | |
687 | 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'. | |
688 | vlan.present = 0; | |
689 | Predicate symbol vlan.present used where lvalue required. | |
5f822129 BP |
690 | |
691 | # Moving one field into another. | |
d5a76da4 BP |
692 | reg0=reg1; |
693 | formats as reg0 = reg1; | |
694 | encodes as move:NXM_NX_XXREG0[64..95]->NXM_NX_XXREG0[96..127] | |
695 | vlan.pcp = reg0[0..2]; | |
696 | encodes as move:NXM_NX_XXREG0[96..98]->NXM_OF_VLAN_TCI[13..15] | |
697 | has prereqs vlan.tci[12] | |
698 | reg0[10] = vlan.pcp[1]; | |
699 | encodes as move:NXM_OF_VLAN_TCI[14]->NXM_NX_XXREG0[106] | |
700 | has prereqs vlan.tci[12] | |
701 | outport = inport; | |
702 | encodes as move:NXM_NX_REG14[]->NXM_NX_REG15[] | |
703 | ||
704 | reg0[0] = vlan.present; | |
705 | Predicate symbol vlan.present used where lvalue required. | |
706 | reg0 = reg1[0..10]; | |
707 | Can't assign 11-bit value to 32-bit destination. | |
708 | inport = reg0; | |
709 | Can't assign integer field (reg0) to string field (inport). | |
710 | inport = big_string; | |
711 | String fields inport and big_string are incompatible for assignment. | |
712 | ip.proto = reg0[0..7]; | |
713 | Field ip.proto is not modifiable. | |
5f822129 BP |
714 | |
715 | # Exchanging fields. | |
d5a76da4 BP |
716 | reg0 <-> reg1; |
717 | encodes as push:NXM_NX_XXREG0[64..95],push:NXM_NX_XXREG0[96..127],pop:NXM_NX_XXREG0[64..95],pop:NXM_NX_XXREG0[96..127] | |
718 | vlan.pcp <-> reg0[0..2]; | |
719 | encodes as 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] | |
720 | has prereqs vlan.tci[12] | |
721 | reg0[10] <-> vlan.pcp[1]; | |
722 | encodes as push:NXM_OF_VLAN_TCI[14],push:NXM_NX_XXREG0[106],pop:NXM_OF_VLAN_TCI[14],pop:NXM_NX_XXREG0[106] | |
723 | has prereqs vlan.tci[12] | |
724 | outport <-> inport; | |
725 | encodes as push:NXM_NX_REG14[],push:NXM_NX_REG15[],pop:NXM_NX_REG14[],pop:NXM_NX_REG15[] | |
726 | ||
727 | reg0[0] <-> vlan.present; | |
728 | Predicate symbol vlan.present used where lvalue required. | |
729 | reg0 <-> reg1[0..10]; | |
730 | Can't exchange 32-bit field with 11-bit field. | |
731 | inport <-> reg0; | |
732 | Can't exchange string field (inport) with integer field (reg0). | |
733 | inport <-> big_string; | |
734 | String fields inport and big_string are incompatible for exchange. | |
735 | ip.proto <-> reg0[0..7]; | |
736 | Field ip.proto is not modifiable. | |
737 | reg0[0..7] <-> ip.proto; | |
738 | Field ip.proto is not modifiable. | |
5f822129 BP |
739 | |
740 | # TTL decrement. | |
d5a76da4 BP |
741 | ip.ttl--; |
742 | encodes as dec_ttl | |
743 | has prereqs ip | |
744 | ip.ttl | |
745 | Syntax error at end of input expecting `--'. | |
5f822129 | 746 | |
467085fd | 747 | # load balancing. |
d5a76da4 BP |
748 | ct_lb; |
749 | encodes as ct(table=27,zone=NXM_NX_REG13[0..15],nat) | |
750 | has prereqs ip | |
751 | ct_lb(); | |
752 | formats as ct_lb; | |
753 | encodes as ct(table=27,zone=NXM_NX_REG13[0..15],nat) | |
754 | has prereqs ip | |
755 | ct_lb(192.168.1.2:80, 192.168.1.3:80); | |
756 | encodes as group:1 | |
757 | has prereqs ip | |
758 | ct_lb(192.168.1.2, 192.168.1.3, ); | |
759 | formats as ct_lb(192.168.1.2, 192.168.1.3); | |
760 | encodes as group:2 | |
761 | has prereqs ip | |
762 | ||
763 | ct_lb(192.168.1.2:); | |
764 | Syntax error at `)' expecting port number. | |
765 | ct_lb(192.168.1.2:123456); | |
766 | Syntax error at `123456' expecting port number. | |
767 | ct_lb(foo); | |
768 | Syntax error at `foo' expecting IPv4 address. | |
769 | ||
770 | # ct_next | |
771 | ct_next; | |
772 | encodes as ct(table=27,zone=NXM_NX_REG13[0..15]) | |
773 | has prereqs ip | |
774 | ||
775 | # ct_commit | |
776 | ct_commit; | |
777 | encodes as ct(commit,zone=NXM_NX_REG13[0..15]) | |
778 | has prereqs ip | |
779 | ct_commit(); | |
780 | formats as ct_commit; | |
781 | encodes as ct(commit,zone=NXM_NX_REG13[0..15]) | |
782 | has prereqs ip | |
783 | ct_commit(ct_mark=1); | |
784 | formats as ct_commit(ct_mark=0x1); | |
785 | encodes as ct(commit,zone=NXM_NX_REG13[0..15],exec(set_field:0x1->ct_mark)) | |
786 | has prereqs ip | |
787 | ct_commit(ct_mark=1/1); | |
788 | formats as ct_commit(ct_mark=0x1/0x1); | |
789 | encodes as ct(commit,zone=NXM_NX_REG13[0..15],exec(set_field:0x1/0x1->ct_mark)) | |
790 | has prereqs ip | |
791 | ct_commit(ct_label=1); | |
792 | formats as ct_commit(ct_label=0x1); | |
793 | encodes as ct(commit,zone=NXM_NX_REG13[0..15],exec(set_field:0x1->ct_label)) | |
794 | has prereqs ip | |
795 | ct_commit(ct_label=1/1); | |
796 | formats as ct_commit(ct_label=0x1/0x1); | |
797 | encodes as ct(commit,zone=NXM_NX_REG13[0..15],exec(set_field:0x1/0x1->ct_label)) | |
798 | has prereqs ip | |
799 | ct_commit(ct_mark=1, ct_label=2); | |
800 | formats as ct_commit(ct_mark=0x1, ct_label=0x2); | |
801 | encodes as ct(commit,zone=NXM_NX_REG13[0..15],exec(set_field:0x1->ct_mark,set_field:0x2->ct_label)) | |
802 | has prereqs ip | |
803 | ||
804 | ct_commit(ct_label=0x01020304050607080910111213141516); | |
805 | formats as ct_commit(ct_label=0x1020304050607080910111213141516); | |
806 | encodes as ct(commit,zone=NXM_NX_REG13[0..15],exec(set_field:0x1020304050607080910111213141516->ct_label)) | |
807 | has prereqs ip | |
808 | ct_commit(ct_label=0x181716151413121110090807060504030201); | |
809 | formats as ct_commit(ct_label=0x16151413121110090807060504030201); | |
810 | encodes as ct(commit,zone=NXM_NX_REG13[0..15],exec(set_field:0x16151413121110090807060504030201->ct_label)) | |
811 | has prereqs ip | |
812 | ct_commit(ct_label=0x1000000000000000000000000000000/0x1000000000000000000000000000000); | |
813 | encodes as ct(commit,zone=NXM_NX_REG13[0..15],exec(set_field:0x1000000000000000000000000000000/0x1000000000000000000000000000000->ct_label)) | |
814 | has prereqs ip | |
815 | ct_commit(ct_label=18446744073709551615); | |
816 | formats as ct_commit(ct_label=0xffffffffffffffff); | |
817 | encodes as ct(commit,zone=NXM_NX_REG13[0..15],exec(set_field:0xffffffffffffffff->ct_label)) | |
818 | has prereqs ip | |
819 | ct_commit(ct_label=18446744073709551616); | |
820 | Decimal constants must be less than 2**64. | |
821 | ||
822 | # ct_dnat | |
823 | ct_dnat; | |
824 | encodes as ct(table=27,zone=NXM_NX_REG11[0..15],nat) | |
825 | has prereqs ip | |
826 | ct_dnat(192.168.1.2); | |
827 | encodes as ct(commit,table=27,zone=NXM_NX_REG11[0..15],nat(dst=192.168.1.2)) | |
828 | has prereqs ip | |
829 | ||
830 | ct_dnat(192.168.1.2, 192.168.1.3); | |
831 | Syntax error at `,' expecting `)'. | |
832 | ct_dnat(foo); | |
833 | Syntax error at `foo' expecting IPv4 address. | |
834 | ct_dnat(foo, bar); | |
835 | Syntax error at `foo' expecting IPv4 address. | |
836 | ct_dnat(); | |
837 | Syntax error at `)' expecting IPv4 address. | |
838 | ||
839 | # ct_snat | |
840 | ct_snat; | |
841 | encodes as ct(zone=NXM_NX_REG12[0..15],nat) | |
842 | has prereqs ip | |
843 | ct_snat(192.168.1.2); | |
844 | encodes as ct(commit,table=27,zone=NXM_NX_REG12[0..15],nat(src=192.168.1.2)) | |
845 | has prereqs ip | |
846 | ||
847 | ct_snat(192.168.1.2, 192.168.1.3); | |
848 | Syntax error at `,' expecting `)'. | |
849 | ct_snat(foo); | |
850 | Syntax error at `foo' expecting IPv4 address. | |
851 | ct_snat(foo, bar); | |
852 | Syntax error at `foo' expecting IPv4 address. | |
853 | ct_snat(); | |
854 | Syntax error at `)' expecting IPv4 address. | |
de297547 | 855 | |
6335d074 | 856 | # arp |
d5a76da4 BP |
857 | arp { eth.dst = ff:ff:ff:ff:ff:ff; output; }; |
858 | encodes as 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) | |
859 | has prereqs ip4 | |
6335d074 | 860 | |
0bac7164 | 861 | # get_arp |
d5a76da4 BP |
862 | get_arp(outport, ip4.dst); |
863 | encodes as 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[] | |
864 | has prereqs eth.type == 0x800 | |
865 | get_arp(inport, reg0); | |
866 | encodes as 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[] | |
867 | ||
868 | get_arp; | |
869 | Syntax error at `;' expecting `('. | |
870 | get_arp(); | |
871 | Syntax error at `)' expecting field name. | |
872 | get_arp(inport); | |
873 | Syntax error at `)' expecting `,'. | |
874 | get_arp(inport ip4.dst); | |
875 | Syntax error at `ip4.dst' expecting `,'. | |
876 | get_arp(inport, ip4.dst; | |
877 | Syntax error at `;' expecting `)'. | |
878 | get_arp(inport, eth.dst); | |
879 | Cannot use 48-bit field eth.dst[0..47] where 32-bit field is required. | |
880 | get_arp(inport, outport); | |
881 | Cannot use string field outport where numeric field is required. | |
882 | get_arp(reg0, ip4.dst); | |
883 | Cannot use numeric field reg0 where string field is required. | |
0bac7164 BP |
884 | |
885 | # put_arp | |
d5a76da4 BP |
886 | put_arp(inport, arp.spa, arp.sha); |
887 | encodes as 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[] | |
888 | has prereqs eth.type == 0x806 && eth.type == 0x806 | |
0bac7164 | 889 | |
42814145 | 890 | # put_dhcp_opts |
d5a76da4 BP |
891 | reg1[0] = put_dhcp_opts(offerip = 1.2.3.4, router = 10.0.0.1); |
892 | encodes as 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) | |
893 | 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"); | |
894 | formats as 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"); | |
895 | encodes as 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) | |
896 | 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); | |
897 | formats as 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); | |
898 | encodes as 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) | |
899 | ||
900 | reg1[0..1] = put_dhcp_opts(offerip = 1.2.3.4, router = 10.0.0.1); | |
901 | Cannot use 2-bit field reg1[0..1] where 1-bit field is required. | |
902 | reg1[0] = put_dhcp_opts(); | |
903 | put_dhcp_opts requires offerip to be specified. | |
904 | reg1[0] = put_dhcp_opts(x = 1.2.3.4, router = 10.0.0.1); | |
905 | Syntax error at `x' expecting DHCPv4 option name. | |
906 | reg1[0] = put_dhcp_opts(router = 10.0.0.1); | |
907 | put_dhcp_opts requires offerip to be specified. | |
908 | reg1[0] = put_dhcp_opts(offerip=1.2.3.4, "hi"); | |
909 | Syntax error at `"hi"'. | |
910 | reg1[0] = put_dhcp_opts(offerip=1.2.3.4, xyzzy); | |
911 | Syntax error at `xyzzy' expecting DHCPv4 option name. | |
912 | reg1[0] = put_dhcp_opts(offerip="xyzzy"); | |
913 | DHCPv4 option offerip requires numeric value. | |
914 | reg1[0] = put_dhcp_opts(offerip=1.2.3.4, domain=1.2.3.4); | |
915 | DHCPv4 option domain requires string value. | |
42814145 | 916 | |
f8a8db39 | 917 | # nd_na |
d5a76da4 BP |
918 | 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; }; |
919 | formats as nd_na { eth.src = 12:34:56:78:9a:bc; nd.tll = 12:34:56:78:9a:bc; outport = inport; inport = ""; output; }; | |
920 | encodes as 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) | |
921 | has prereqs nd_ns | |
e75451fe | 922 | |
c34a87b6 | 923 | # get_nd |
d5a76da4 BP |
924 | get_nd(outport, ip6.dst); |
925 | encodes as 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[] | |
926 | has prereqs eth.type == 0x86dd | |
927 | get_nd(inport, xxreg0); | |
928 | encodes as 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[] | |
929 | get_nd; | |
930 | Syntax error at `;' expecting `('. | |
931 | get_nd(); | |
932 | Syntax error at `)' expecting field name. | |
933 | get_nd(inport); | |
934 | Syntax error at `)' expecting `,'. | |
935 | get_nd(inport ip6.dst); | |
936 | Syntax error at `ip6.dst' expecting `,'. | |
937 | get_nd(inport, ip6.dst; | |
938 | Syntax error at `;' expecting `)'. | |
939 | get_nd(inport, eth.dst); | |
940 | Cannot use 48-bit field eth.dst[0..47] where 128-bit field is required. | |
941 | get_nd(inport, outport); | |
942 | Cannot use string field outport where numeric field is required. | |
943 | get_nd(xxreg0, ip6.dst); | |
944 | Cannot use numeric field xxreg0 where string field is required. | |
c34a87b6 JP |
945 | |
946 | # put_nd | |
d5a76da4 BP |
947 | put_nd(inport, nd.target, nd.sll); |
948 | encodes as 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[] | |
949 | has 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) | |
c34a87b6 | 950 | |
01cfdb2f | 951 | # put_dhcpv6_opts |
d5a76da4 | 952 | reg1[0] = put_dhcpv6_opts(ia_addr = ae70::4, server_id = 00:00:00:00:10:02); |
a55dacac | 953 | encodes as controller(userdata=00.00.00.05.00.00.00.00.00.01.de.10.00.00.00.40.00.05.00.10.ae.70.00.00.00.00.00.00.00.00.00.00.00.00.00.04.00.02.00.06.00.00.00.00.10.02,pause) |
d5a76da4 BP |
954 | reg1[0] = put_dhcpv6_opts(); |
955 | encodes as controller(userdata=00.00.00.05.00.00.00.00.00.01.de.10.00.00.00.40,pause) | |
956 | reg1[0] = put_dhcpv6_opts(dns_server={ae70::1,ae70::2}); | |
957 | formats as reg1[0] = put_dhcpv6_opts(dns_server = {ae70::1, ae70::2}); | |
a55dacac | 958 | encodes as controller(userdata=00.00.00.05.00.00.00.00.00.01.de.10.00.00.00.40.00.17.00.20.ae.70.00.00.00.00.00.00.00.00.00.00.00.00.00.01.ae.70.00.00.00.00.00.00.00.00.00.00.00.00.00.02,pause) |
40df4566 ZKL |
959 | reg1[0] = put_dhcpv6_opts(server_id=12:34:56:78:9a:bc, dns_server={ae70::1,ae89::2}); |
960 | formats as reg1[0] = put_dhcpv6_opts(server_id = 12:34:56:78:9a:bc, dns_server = {ae70::1, ae89::2}); | |
a55dacac | 961 | encodes as controller(userdata=00.00.00.05.00.00.00.00.00.01.de.10.00.00.00.40.00.02.00.06.12.34.56.78.9a.bc.00.17.00.20.ae.70.00.00.00.00.00.00.00.00.00.00.00.00.00.01.ae.89.00.00.00.00.00.00.00.00.00.00.00.00.00.02,pause) |
d5a76da4 | 962 | reg1[0] = put_dhcpv6_opts(domain_search = "ovn.org"); |
a55dacac | 963 | encodes as controller(userdata=00.00.00.05.00.00.00.00.00.01.de.10.00.00.00.40.00.18.00.07.6f.76.6e.2e.6f.72.67,pause) |
d5a76da4 BP |
964 | reg1[0] = put_dhcpv6_opts(x = 1.2.3.4); |
965 | Syntax error at `x' expecting DHCPv6 option name. | |
966 | reg1[0] = put_dhcpv6_opts(ia_addr=ae70::4, "hi"); | |
967 | Syntax error at `"hi"'. | |
968 | reg1[0] = put_dhcpv6_opts(ia_addr=ae70::4, xyzzy); | |
969 | Syntax error at `xyzzy' expecting DHCPv6 option name. | |
970 | reg1[0] = put_dhcpv6_opts(ia_addr="ae70::4"); | |
971 | DHCPv6 option ia_addr requires numeric value. | |
972 | reg1[0] = put_dhcpv6_opts(ia_addr=ae70::4, domain_search=ae70::1); | |
973 | DHCPv6 option domain_search requires string value. | |
01cfdb2f | 974 | |
a6095f81 BS |
975 | # set_queue |
976 | set_queue(0); | |
977 | encodes as set_queue:0 | |
978 | set_queue(61440); | |
979 | encodes as set_queue:61440 | |
980 | set_queue(65535); | |
981 | Queue ID 65535 for set_queue is not in valid range 0 to 61440. | |
982 | ||
5f822129 | 983 | # Contradictionary prerequisites (allowed but not useful): |
d5a76da4 BP |
984 | ip4.src = ip6.src[0..31]; |
985 | encodes as move:NXM_NX_IPV6_SRC[0..31]->NXM_OF_IP_SRC[] | |
986 | has prereqs eth.type == 0x800 && eth.type == 0x86dd | |
987 | ip4.src <-> ip6.src[0..31]; | |
988 | encodes as push:NXM_NX_IPV6_SRC[0..31],push:NXM_OF_IP_SRC[],pop:NXM_NX_IPV6_SRC[0..31],pop:NXM_OF_IP_SRC[] | |
989 | has prereqs eth.type == 0x800 && eth.type == 0x86dd | |
990 | ||
991 | # Miscellaneous negative tests. | |
992 | ; | |
993 | Syntax error at `;'. | |
994 | xyzzy; | |
995 | Syntax error at `xyzzy' expecting action. | |
996 | next; 123; | |
997 | Syntax error at `123'. | |
998 | next; xyzzy; | |
999 | Syntax error at `xyzzy' expecting action. | |
1000 | next | |
9aef3c1b | 1001 | Syntax error at end of input expecting `;'. |
3b7cb7e1 | 1002 | ]]) |
d5a76da4 BP |
1003 | sed '/^[[ ]]/d' test-cases.txt > input.txt |
1004 | cp test-cases.txt expout | |
3b7cb7e1 BP |
1005 | AT_CHECK([ovstest test-ovn parse-actions < input.txt], [0], [expout]) |
1006 | AT_CLEANUP | |
f295c17b BP |
1007 | |
1008 | AT_BANNER([OVN end-to-end tests]) | |
1009 | ||
9975d7be BP |
1010 | # 3 hypervisors, one logical switch, 3 logical ports per hypervisor |
1011 | AT_SETUP([ovn -- 3 HVs, 1 LS, 3 lports/HV]) | |
57d143eb | 1012 | AT_KEYWORDS([ovnarp]) |
f295c17b BP |
1013 | AT_SKIP_IF([test $HAVE_PYTHON = no]) |
1014 | ovn_start | |
1015 | ||
1016 | # Create hypervisors hv[123]. | |
9975d7be | 1017 | # Add vif1[123] to hv1, vif2[123] to hv2, vif3[123] to hv3. |
f295c17b BP |
1018 | # Add all of the vifs to a single logical switch lsw0. |
1019 | # Turn on port security on all the vifs except vif[123]1. | |
1020 | # Make vif13, vif2[23], vif3[123] destinations for unknown MACs. | |
1021 | # Add some ACLs for Ethertypes 1234, 1235, 1236. | |
ea46a4e9 | 1022 | ovn-nbctl ls-add lsw0 |
f295c17b BP |
1023 | net_add n1 |
1024 | for i in 1 2 3; do | |
1025 | sim_add hv$i | |
1026 | as hv$i | |
1027 | ovs-vsctl add-br br-phys | |
1028 | ovn_attach n1 br-phys 192.168.0.$i | |
1029 | ||
1030 | for j in 1 2 3; do | |
1031 | 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 | 1032 | ovn-nbctl lsp-add lsw0 lp$i$j |
4d5c43d5 | 1033 | if test $j = 1; then |
31ed1192 | 1034 | ovn-nbctl lsp-set-addresses lp$i$j "f0:00:00:00:00:$i$j 192.168.0.$i$j" unknown |
f295c17b | 1035 | else |
7dc88496 NS |
1036 | if test $j = 3; then |
1037 | ip_addrs="192.168.0.$i$j fe80::ea2a:eaff:fe28:$i$j/64 192.169.0.$i$j" | |
1038 | else | |
1039 | ip_addrs="192.168.0.$i$j" | |
1040 | fi | |
31ed1192 JP |
1041 | ovn-nbctl lsp-set-addresses lp$i$j "f0:00:00:00:00:$i$j $ip_addrs" |
1042 | ovn-nbctl lsp-set-port-security lp$i$j f0:00:00:00:00:$i$j | |
f295c17b BP |
1043 | fi |
1044 | done | |
1045 | done | |
1046 | ovn-nbctl acl-add lsw0 from-lport 1000 'eth.type == 0x1234' drop | |
1047 | ovn-nbctl acl-add lsw0 from-lport 1000 'eth.type == 0x1235 && inport == "lp11"' drop | |
1048 | ovn-nbctl acl-add lsw0 to-lport 1000 'eth.type == 0x1236 && outport == "lp33"' drop | |
ea382567 RB |
1049 | 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\" |
1050 | ovn-nbctl acl-add lsw0 to-lport 1000 'eth.type == 0x1237 && eth.src == $set1 && outport == "lp33"' drop | |
f295c17b BP |
1051 | |
1052 | # Pre-populate the hypervisors' ARP tables so that we don't lose any | |
1053 | # packets for ARP resolution (native tunneling doesn't queue packets | |
1054 | # for ARP resolution). | |
1055 | ovn_populate_arp | |
1056 | ||
1057 | # Allow some time for ovn-northd and ovn-controller to catch up. | |
1058 | # XXX This should be more systematic. | |
1059 | sleep 1 | |
611099dc | 1060 | |
fc6f9978 HZ |
1061 | # Make sure there is no attempt to adding duplicated flows by ovn-controller |
1062 | AT_FAIL_IF([test -n "`grep duplicate hv1/ovn-controller.log`"]) | |
1063 | AT_FAIL_IF([test -n "`grep duplicate hv2/ovn-controller.log`"]) | |
1064 | AT_FAIL_IF([test -n "`grep duplicate hv3/ovn-controller.log`"]) | |
1065 | ||
57d143eb HZ |
1066 | # Given the name of a logical port, prints the name of the hypervisor |
1067 | # on which it is located. | |
1068 | vif_to_hv() { | |
1069 | echo hv${1%?} | |
1070 | } | |
1071 | ||
f295c17b BP |
1072 | # test_packet INPORT DST SRC ETHTYPE OUTPORT... |
1073 | # | |
1074 | # This shell function causes a packet to be received on INPORT. The packet's | |
1075 | # content has Ethernet destination DST and source SRC (each exactly 12 hex | |
1076 | # digits) and Ethernet type ETHTYPE (4 hex digits). The OUTPORTs (zero or | |
1077 | # more) list the VIFs on which the packet should be received. INPORT and the | |
31ed1192 | 1078 | # OUTPORTs are specified as logical switch port numbers, e.g. 11 for vif11. |
f295c17b BP |
1079 | for i in 1 2 3; do |
1080 | for j in 1 2 3; do | |
1081 | : > $i$j.expected | |
1082 | done | |
1083 | done | |
1084 | test_packet() { | |
1085 | local inport=$1 packet=$2$3$4; shift; shift; shift; shift | |
57d143eb | 1086 | hv=`vif_to_hv $inport` |
f295c17b BP |
1087 | vif=vif$inport |
1088 | as $hv ovs-appctl netdev-dummy/receive $vif $packet | |
1089 | for outport; do | |
e4543cfe | 1090 | echo $packet >> $outport.expected |
f295c17b BP |
1091 | done |
1092 | } | |
1093 | ||
57d143eb HZ |
1094 | # test_arp INPORT SHA SPA TPA [REPLY_HA] |
1095 | # | |
1096 | # Causes a packet to be received on INPORT. The packet is an ARP | |
1097 | # request with SHA, SPA, and TPA as specified. If REPLY_HA is provided, then | |
1098 | # it should be the hardware address of the target to expect to receive in an | |
1099 | # ARP reply; otherwise no reply is expected. | |
1100 | # | |
31ed1192 | 1101 | # INPORT is an logical switch port number, e.g. 11 for vif11. |
57d143eb HZ |
1102 | # SHA and REPLY_HA are each 12 hex digits. |
1103 | # SPA and TPA are each 8 hex digits. | |
1104 | test_arp() { | |
1105 | local inport=$1 sha=$2 spa=$3 tpa=$4 reply_ha=$5 | |
1106 | local request=ffffffffffff${sha}08060001080006040001${sha}${spa}ffffffffffff${tpa} | |
1107 | hv=`vif_to_hv $inport` | |
1108 | as $hv ovs-appctl netdev-dummy/receive vif$inport $request | |
1109 | ||
92f9822b | 1110 | if test X$reply_ha = X; then |
57d143eb HZ |
1111 | # Expect to receive the broadcast ARP on the other logical switch ports |
1112 | # if no reply is expected. | |
1113 | local i j | |
1114 | for i in 1 2 3; do | |
1115 | for j in 1 2 3; do | |
1116 | if test $i$j != $inport; then | |
1117 | echo $request >> $i$j.expected | |
1118 | fi | |
1119 | done | |
1120 | done | |
1121 | else | |
1122 | # Expect to receive the reply, if any. | |
1123 | local reply=${sha}${reply_ha}08060001080006040002${reply_ha}${tpa}${sha}${spa} | |
1124 | echo $reply >> $inport.expected | |
1125 | fi | |
1126 | } | |
1127 | ||
1128 | ip_to_hex() { | |
1129 | printf "%02x%02x%02x%02x" "$@" | |
1130 | } | |
1131 | ||
f295c17b BP |
1132 | # Send packets between all pairs of source and destination ports: |
1133 | # | |
31ed1192 JP |
1134 | # 1. Unicast packets are delivered to exactly one logical switch port |
1135 | # (except that packets destined to their input ports are dropped). | |
f295c17b | 1136 | # |
31ed1192 JP |
1137 | # 2. Broadcast and multicast are delivered to all logical switch ports |
1138 | # except the input port. | |
f295c17b | 1139 | # |
ea46a4e9 | 1140 | # 3. When port security is turned on, the switch drops packets from the wrong |
f295c17b BP |
1141 | # MAC address. |
1142 | # | |
ea46a4e9 | 1143 | # 4. The switch drops all packets with a VLAN tag. |
f295c17b | 1144 | # |
ea46a4e9 | 1145 | # 5. The switch drops all packets with a multicast source address. (This only |
f295c17b BP |
1146 | # affects behavior when port security is turned off, since otherwise port |
1147 | # security would drop the packet anyway.) | |
1148 | # | |
ea46a4e9 | 1149 | # 6. The switch delivers packets with an unknown destination to logical |
31ed1192 JP |
1150 | # switch ports with "unknown" among their MAC addresses (and port |
1151 | # security disabled). | |
f295c17b | 1152 | # |
ea46a4e9 | 1153 | # 7. The switch drops unicast packets that violate an ACL. |
f295c17b | 1154 | # |
ea46a4e9 | 1155 | # 8. The switch drops multicast and broadcast packets that violate an ACL. |
57d143eb | 1156 | # |
9fcb6a18 BP |
1157 | # 9. OVN generates responses to ARP requests for known IPs, except for |
1158 | # requests from a port for the port's own IP. | |
57d143eb HZ |
1159 | # |
1160 | # 10. No response to ARP requests for unknown IPs. | |
4acd1e87 | 1161 | |
f295c17b BP |
1162 | for is in 1 2 3; do |
1163 | for js in 1 2 3; do | |
1164 | s=$is$js | |
1165 | bcast= | |
4d5c43d5 JP |
1166 | unknown= |
1167 | bacl2= | |
1168 | bacl3= | |
f295c17b BP |
1169 | for id in 1 2 3; do |
1170 | for jd in 1 2 3; do | |
1171 | d=$id$jd | |
1172 | ||
1173 | if test $d != $s; then unicast=$d; else unicast=; fi | |
1174 | test_packet $s f000000000$d f000000000$s $s$d $unicast #1 | |
1175 | ||
1176 | if test $d != $s && test $js = 1; then | |
4d5c43d5 JP |
1177 | impersonate=$d |
1178 | else | |
1179 | impersonate= | |
1180 | fi | |
f295c17b BP |
1181 | test_packet $s f000000000$d f00000000055 55$d $impersonate #3 |
1182 | ||
4d5c43d5 JP |
1183 | if test $d != $s && test $s != 11; then acl2=$d; else acl2=; fi |
1184 | if test $d != $s && test $d != 33; then acl3=$d; else acl3=; fi | |
e137131a | 1185 | if test $d = $s || (test $js = 1 && test $d = 33); then |
ea382567 RB |
1186 | # Source of 11, 21, or 31 and dest of 33 should be dropped |
1187 | # due to the 4th ACL that uses address_set(set1). | |
1188 | acl4= | |
1189 | else | |
1190 | acl4=$d | |
1191 | fi | |
f295c17b BP |
1192 | test_packet $s f000000000$d f000000000$s 1234 #7, acl1 |
1193 | test_packet $s f000000000$d f000000000$s 1235 $acl2 #7, acl2 | |
1194 | test_packet $s f000000000$d f000000000$s 1236 $acl3 #7, acl3 | |
ea382567 | 1195 | test_packet $s f000000000$d f000000000$s 1237 $acl4 #7, acl4 |
f295c17b BP |
1196 | |
1197 | test_packet $s f000000000$d f00000000055 810000091234 #4 | |
1198 | test_packet $s f000000000$d 0100000000$s $s$d #5 | |
1199 | ||
4d5c43d5 JP |
1200 | if test $d != $s && test $jd = 1; then |
1201 | unknown="$unknown $d" | |
1202 | fi | |
f295c17b BP |
1203 | bcast="$bcast $unicast" |
1204 | bacl2="$bacl2 $acl2" | |
1205 | bacl3="$bacl3 $acl3" | |
57d143eb HZ |
1206 | |
1207 | sip=`ip_to_hex 192 168 0 $i$j` | |
1208 | tip=`ip_to_hex 192 168 0 $id$jd` | |
1209 | tip_unknown=`ip_to_hex 11 11 11 11` | |
9fcb6a18 BP |
1210 | if test $d != $s; then |
1211 | reply_ha=f000000000$d | |
1212 | else | |
1213 | reply_ha= | |
1214 | fi | |
1215 | test_arp $s f000000000$s $sip $tip $reply_ha #9 | |
57d143eb | 1216 | test_arp $s f000000000$s $sip $tip_unknown #10 |
7dc88496 NS |
1217 | |
1218 | if test $jd = 3; then | |
31ed1192 | 1219 | # lsp[123]3 has an additional ip 192.169.0.[123]3. |
7dc88496 | 1220 | tip=`ip_to_hex 192 169 0 $id$jd` |
9fcb6a18 | 1221 | test_arp $s f000000000$s $sip $tip $reply_ha #9 |
7dc88496 | 1222 | fi |
f295c17b BP |
1223 | done |
1224 | done | |
1225 | ||
4d5c43d5 | 1226 | # Broadcast and multicast. |
f295c17b BP |
1227 | test_packet $s ffffffffffff f000000000$s ${s}ff $bcast #2 |
1228 | test_packet $s 010000000000 f000000000$s ${s}ff $bcast #2 | |
4d5c43d5 | 1229 | if test $js = 1; then |
f295c17b BP |
1230 | bcast_impersonate=$bcast |
1231 | else | |
4d5c43d5 JP |
1232 | bcast_impersonate= |
1233 | fi | |
f295c17b BP |
1234 | test_packet $s 010000000000 f00000000044 44ff $bcast_impersonate #3 |
1235 | ||
1236 | test_packet $s f0000000ffff f000000000$s ${s}66 $unknown #6 | |
1237 | ||
1238 | test_packet $s ffffffffffff f000000000$s 1234 #8, acl1 | |
1239 | test_packet $s ffffffffffff f000000000$s 1235 $bacl2 #8, acl2 | |
1240 | test_packet $s ffffffffffff f000000000$s 1236 $bacl3 #8, acl3 | |
1241 | test_packet $s 010000000000 f000000000$s 1234 #8, acl1 | |
1242 | test_packet $s 010000000000 f000000000$s 1235 $bacl2 #8, acl2 | |
1243 | test_packet $s 010000000000 f000000000$s 1236 $bacl3 #8, acl3 | |
1244 | done | |
1245 | done | |
1246 | ||
7dc88496 NS |
1247 | # set address for lp13 with invalid characters. |
1248 | # lp13 should be configured with only 192.168.0.13. | |
31ed1192 | 1249 | ovn-nbctl lsp-set-addresses lp13 "f0:00:00:00:00:13 192.168.0.13 invalid 192.169.0.13" |
3b8cd0ea BP |
1250 | |
1251 | # Allow some time for ovn-northd and ovn-controller to catch up. | |
1252 | # XXX This should be more systematic. | |
1253 | sleep 1 | |
1254 | ||
7dc88496 NS |
1255 | sip=`ip_to_hex 192 168 0 11` |
1256 | tip=`ip_to_hex 192 168 0 13` | |
1257 | test_arp 11 f00000000011 $sip $tip f00000000013 | |
1258 | ||
1259 | tip=`ip_to_hex 192 169 0 13` | |
1260 | #arp request for 192.169.0.13 should be flooded | |
1261 | test_arp 11 f00000000011 $sip $tip | |
1262 | ||
91125642 | 1263 | # dump information and flows with counters |
bb0c41d3 RM |
1264 | ovn-sbctl dump-flows -- list multicast_group |
1265 | ||
1266 | echo "------ hv1 dump ------" | |
1267 | as hv1 ovs-vsctl show | |
1268 | as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-int | |
1269 | ||
1270 | echo "------ hv2 dump ------" | |
1271 | as hv2 ovs-vsctl show | |
1272 | as hv2 ovs-ofctl -O OpenFlow13 dump-flows br-int | |
1273 | ||
1274 | echo "------ hv3 dump ------" | |
1275 | as hv3 ovs-vsctl show | |
1276 | as hv3 ovs-ofctl -O OpenFlow13 dump-flows br-int | |
49d7c759 | 1277 | |
f295c17b BP |
1278 | # Now check the packets actually received against the ones expected. |
1279 | for i in 1 2 3; do | |
1280 | for j in 1 2 3; do | |
49d7c759 | 1281 | OVN_CHECK_PACKETS([hv$i/vif$i$j-tx.pcap], [$i$j.expected]) |
f295c17b BP |
1282 | done |
1283 | done | |
fcde56f5 | 1284 | |
7a8f15e0 | 1285 | OVN_CLEANUP([hv1],[hv2],[hv3]) |
d9c8c57c | 1286 | |
f295c17b | 1287 | AT_CLEANUP |
eb6b08eb | 1288 | |
4acd1e87 BP |
1289 | AT_SETUP([ovn -- trace 1 LS, 3 LSPs]) |
1290 | AT_SKIP_IF([test $HAVE_PYTHON = no]) | |
1291 | ovn_start | |
1292 | ||
1293 | # Create a logical switch and some logical ports. | |
1294 | # Turn on port security on all lports except ls1. | |
1295 | # Make ls1 a destination for unknown MACs. | |
1296 | # Add some ACLs for Ethertypes 1234, 1235, 1236. | |
1297 | ovn-nbctl ls-add lsw0 | |
1298 | ovn-sbctl chassis-add hv0 geneve 127.0.0.1 | |
1299 | for i in 1 2 3; do | |
1300 | ovn-nbctl lsp-add lsw0 lp$i | |
7979c444 BP |
1301 | done |
1302 | ovn-nbctl --wait=sb sync | |
1303 | for i in 1 2 3; do | |
4acd1e87 BP |
1304 | ovn-sbctl lsp-bind lp$i hv0 |
1305 | if test $i = 1; then | |
abb37b6b | 1306 | ovn-nbctl lsp-set-addresses lp$i "f0:00:00:00:00:0$i 192.168.0.$i" unknown |
4acd1e87 | 1307 | else |
abb37b6b FF |
1308 | if test $i = 3; then |
1309 | ip_addrs="192.168.0.$i fe80::ea2a:eaff:fe28:$i/64 192.169.0.$i" | |
1310 | else | |
1311 | ip_addrs="192.168.0.$i" | |
1312 | fi | |
1313 | ovn-nbctl lsp-set-addresses lp$i "f0:00:00:00:00:$i $ip_addrs" | |
1314 | ovn-nbctl lsp-set-port-security lp$i f0:00:00:00:00:$i | |
4acd1e87 BP |
1315 | fi |
1316 | done | |
1317 | ovn-nbctl acl-add lsw0 from-lport 1000 'eth.type == 0x1234' drop | |
1318 | ovn-nbctl acl-add lsw0 from-lport 1000 'eth.type == 0x1235 && inport == "lp1"' drop | |
1319 | ovn-nbctl acl-add lsw0 to-lport 1000 'eth.type == 0x1236 && outport == "lp3"' drop | |
1320 | ovn-nbctl create Address_Set name=set1 addresses=\"f0:00:00:00:00:01\",\"f0:00:00:00:00:02\" | |
1321 | ovn-nbctl acl-add lsw0 to-lport 1000 'eth.type == 0x1237 && eth.src == $set1 && outport == "lp3"' drop | |
1322 | ||
1323 | ovn-nbctl --wait=sb sync | |
1324 | on_exit 'kill `cat ovn-trace.pid`' | |
1325 | ovn-trace --detach --pidfile --no-chdir | |
1326 | ||
1327 | # test_packet INPORT DST SRC [-vlan] [-eth TYPE] OUTPORT... | |
1328 | # | |
1329 | # This shell function causes a packet to be received on INPORT. The packet's | |
1330 | # content has Ethernet destination DST and source SRC (each exactly 12 hex | |
1331 | # digits) and Ethernet type ETHTYPE (4 hex digits). The OUTPORTs (zero or | |
1332 | # more) list the VIFs on which the packet should be received. INPORT and the | |
1333 | # OUTPORTs are specified as logical switch port numbers, e.g. 11 for vif11. | |
1334 | test_packet() { | |
1335 | local inport=$1 eth_dst=$2 eth_src=$3; shift; shift; shift | |
1336 | uflow="inport==\"lp$inport\" && eth.dst==$eth_dst && eth.src==$eth_src" | |
1337 | while :; do | |
abb37b6b FF |
1338 | case $1 in # ( |
1339 | -vlan) uflow="$uflow && vlan.vid == 1234"; shift ;; # ( | |
1340 | -eth) uflow="$uflow && eth.type == 0x$2"; shift; shift ;; # ( | |
1341 | *) break ;; | |
1342 | esac | |
4acd1e87 BP |
1343 | done |
1344 | for outport; do | |
abb37b6b | 1345 | echo "output(\"lp$outport\");" |
4acd1e87 BP |
1346 | done > expout |
1347 | ||
1348 | AT_CAPTURE_FILE([trace]) | |
1349 | AT_CHECK([ovs-appctl -t ovn-trace trace --all lsw0 "$uflow" | tee trace | sed '1,/Minimal trace/d'], [0], [expout]) | |
1350 | } | |
1351 | ||
1352 | # test_arp INPORT SHA SPA TPA [REPLY_HA] | |
1353 | # | |
1354 | # Causes a packet to be received on INPORT. The packet is an ARP | |
1355 | # request with SHA, SPA, and TPA as specified. If REPLY_HA is provided, then | |
1356 | # it should be the hardware address of the target to expect to receive in an | |
1357 | # ARP reply; otherwise no reply is expected. | |
1358 | # | |
1359 | # INPORT is an logical switch port number, e.g. 11 for vif11. | |
1360 | # SHA and REPLY_HA are each 12 hex digits. | |
1361 | # SPA and TPA are each 8 hex digits. | |
1362 | test_arp() { | |
1363 | local inport=$1 sha=$2 spa=$3 tpa=$4 reply_ha=$5 | |
1364 | ||
1365 | local request="inport == \"lp$inport\" | |
1366 | && eth.dst == ff:ff:ff:ff:ff:ff && eth.src == $sha | |
1367 | && arp.op == 1 && arp.sha == $sha && arp.spa == $spa | |
abb37b6b | 1368 | && arp.tha == ff:ff:ff:ff:ff:ff && arp.tpa == $tpa" |
4acd1e87 BP |
1369 | |
1370 | if test -z "$reply_ha"; then | |
1371 | reply= | |
abb37b6b FF |
1372 | local i |
1373 | for i in 1 2 3; do | |
1374 | if test $i != $inport; then | |
1375 | reply="${reply}output(\"lp$i\"); | |
4acd1e87 | 1376 | " |
abb37b6b FF |
1377 | fi |
1378 | done | |
4acd1e87 BP |
1379 | else |
1380 | reply="\ | |
1381 | eth.dst = $sha; | |
1382 | eth.src = $reply_ha; | |
1383 | arp.op = 2; | |
1384 | arp.tha = $sha; | |
1385 | arp.sha = $reply_ha; | |
1386 | arp.tpa = $spa; | |
1387 | arp.spa = $tpa; | |
1388 | output(\"lp$inport\"); | |
1389 | " | |
1390 | fi | |
1391 | ||
1392 | AT_CAPTURE_FILE([trace]) | |
1393 | AT_CHECK_UNQUOTED([ovs-appctl -t ovn-trace trace --all lsw0 "$request" | tee trace | sed '1,/Minimal trace/d'], [0], [$reply]) | |
1394 | } | |
1395 | ||
1396 | # Send packets between all pairs of source and destination ports: | |
1397 | # | |
1398 | # 1. Unicast packets are delivered to exactly one logical switch port | |
1399 | # (except that packets destined to their input ports are dropped). | |
1400 | # | |
1401 | # 2. Broadcast and multicast are delivered to all logical switch ports | |
1402 | # except the input port. | |
1403 | # | |
1404 | # 3. When port security is turned on, the switch drops packets from the wrong | |
1405 | # MAC address. | |
1406 | # | |
1407 | # 4. The switch drops all packets with a VLAN tag. | |
1408 | # | |
1409 | # 5. The switch drops all packets with a multicast source address. (This only | |
1410 | # affects behavior when port security is turned off, since otherwise port | |
1411 | # security would drop the packet anyway.) | |
1412 | # | |
1413 | # 6. The switch delivers packets with an unknown destination to logical | |
1414 | # switch ports with "unknown" among their MAC addresses (and port | |
1415 | # security disabled). | |
1416 | # | |
1417 | # 7. The switch drops unicast packets that violate an ACL. | |
1418 | # | |
1419 | # 8. The switch drops multicast and broadcast packets that violate an ACL. | |
1420 | # | |
9fcb6a18 BP |
1421 | # 9. OVN generates responses to ARP requests for known IPs, except for |
1422 | # requests from a port for the port's own IP. | |
4acd1e87 BP |
1423 | # |
1424 | # 10. No response to ARP requests for unknown IPs. | |
1425 | ||
1426 | for s in 1 2 3; do | |
1427 | bcast= | |
1428 | unknown= | |
1429 | bacl2= | |
1430 | bacl3= | |
1431 | for d in 1 2 3; do | |
abb37b6b FF |
1432 | echo |
1433 | echo "lp$s -> lp$d" | |
1434 | if test $d != $s; then unicast=$d; else unicast=; fi | |
1435 | test_packet $s f0:00:00:00:00:0$d f0:00:00:00:00:0$s $unicast #1 | |
1436 | ||
1437 | if test $d != $s && test $s = 1; then | |
1438 | impersonate=$d | |
1439 | else | |
1440 | impersonate= | |
1441 | fi | |
1442 | test_packet $s f0:00:00:00:00:0$d f0:00:00:00:00:55 $impersonate #3 | |
1443 | ||
1444 | if test $d != $s && test $s != 1; then acl2=$d; else acl2=; fi | |
1445 | if test $d != $s && test $d != 3; then acl3=$d; else acl3=; fi | |
1446 | if test $d = $s || ( (test $s = 1 || test $s = 2) && test $d = 3); then | |
1447 | # Source of 1 or 2 and dest of 3 should be dropped | |
1448 | # due to the 4th ACL that uses address_set(set1). | |
1449 | acl4= | |
1450 | else | |
1451 | acl4=$d | |
1452 | fi | |
1453 | ||
1454 | #7, acl1 to acl4: | |
1455 | test_packet $s f0:00:00:00:00:0$d f0:00:00:00:00:0$s -eth 1234 | |
1456 | test_packet $s f0:00:00:00:00:0$d f0:00:00:00:00:0$s -eth 1235 $acl2 | |
1457 | test_packet $s f0:00:00:00:00:0$d f0:00:00:00:00:0$s -eth 1236 $acl3 | |
1458 | test_packet $s f0:00:00:00:00:0$d f0:00:00:00:00:0$s -eth 1237 $acl4 | |
1459 | ||
1460 | test_packet $s f0:00:00:00:00:0$d f0:00:00:00:00:55 -vlan #4 | |
1461 | test_packet $s f0:00:00:00:00:0$d 01:00:00:00:00:0$s #5 | |
1462 | ||
1463 | if test $d != $s && test $d = 1; then | |
1464 | unknown="$unknown $d" | |
1465 | fi | |
1466 | bcast="$bcast $unicast" | |
1467 | bacl2="$bacl2 $acl2" | |
1468 | bacl3="$bacl3 $acl3" | |
1469 | ||
1470 | sip=192.168.0.$s | |
1471 | tip=192.168.0.$d | |
1472 | tip_unknown=11.11.11.11 | |
9fcb6a18 BP |
1473 | if test $d != $s; then reply_ha=f0:00:00:00:00:0$d; else reply_ha=; fi |
1474 | test_arp $s f0:00:00:00:00:0$s $sip $tip $reply_ha #9 | |
abb37b6b FF |
1475 | test_arp $s f0:00:00:00:00:0$s $sip $tip_unknown #10 |
1476 | ||
1477 | if test $d = 3; then | |
1478 | # lp3 has an additional ip 192.169.0.[123]3. | |
1479 | tip=192.169.0.$d | |
9fcb6a18 | 1480 | test_arp $s f0:00:00:00:00:0$s $sip $tip $reply_ha #9 |
abb37b6b | 1481 | fi |
4acd1e87 BP |
1482 | done |
1483 | ||
1484 | # Broadcast and multicast. | |
1485 | test_packet $s ff:ff:ff:ff:ff:ff f0:00:00:00:00:0$s $bcast #2 | |
1486 | test_packet $s 01:00:00:00:00:00 f0:00:00:00:00:0$s $bcast #2 | |
1487 | if test $s = 1; then | |
abb37b6b | 1488 | bcast_impersonate=$bcast |
4acd1e87 | 1489 | else |
abb37b6b | 1490 | bcast_impersonate= |
4acd1e87 BP |
1491 | fi |
1492 | test_packet $s 01:00:00:00:00:00 f0:00:00:00:00:44 $bcast_impersonate #3 | |
1493 | ||
1494 | test_packet $s f0:00:00:00:ff:ff f0:00:00:00:00:0$s $unknown #6 | |
1495 | ||
1496 | #8, acl1 to acl3: | |
1497 | test_packet $s ff:ff:ff:ff:ff:ff f0:00:00:00:00:0$s -eth 1234 | |
1498 | test_packet $s ff:ff:ff:ff:ff:ff f0:00:00:00:00:0$s -eth 1235 $bacl2 | |
1499 | test_packet $s ff:ff:ff:ff:ff:ff f0:00:00:00:00:0$s -eth 1236 $bacl3 | |
1500 | ||
1501 | #8, acl1 to acl3: | |
1502 | test_packet $s 01:00:00:00:00:00 f0:00:00:00:00:0$s -eth 1234 | |
1503 | test_packet $s 01:00:00:00:00:00 f0:00:00:00:00:0$s -eth 1235 $bacl2 | |
1504 | test_packet $s 01:00:00:00:00:00 f0:00:00:00:00:0$s -eth 1236 $bacl3 | |
1505 | done | |
1506 | ||
1507 | AT_CLEANUP | |
1508 | ||
7277bc83 RB |
1509 | # 2 hypervisors, 4 logical ports per HV |
1510 | # 2 locally attached networks (one flat, one vlan tagged over same device) | |
1511 | # 2 ports per HV on each network | |
e90aeb57 | 1512 | AT_SETUP([ovn -- 2 HVs, 4 lports/HV, localnet ports]) |
d79fc5f4 RB |
1513 | AT_SKIP_IF([test $HAVE_PYTHON = no]) |
1514 | ovn_start | |
1515 | ||
ea46a4e9 JP |
1516 | # In this test cases we create 3 switches, all connected to same |
1517 | # physical network (through br-phys on each HV). Each switch has | |
0ee7f7f1 HZ |
1518 | # VIF ports across 2 HVs. Each HV has 5 VIF ports. The first digit |
1519 | # of VIF port name indicates the hypervisor it is bound to, e.g. | |
1520 | # lp23 means VIF 3 on hv2. | |
1521 | # | |
ea46a4e9 | 1522 | # Each switch's VLAN tag and their logical switch ports are: |
0ee7f7f1 HZ |
1523 | # - ls1: |
1524 | # - untagged | |
ea46a4e9 | 1525 | # - ports: lp11, lp12, lp21, lp22 |
0ee7f7f1 HZ |
1526 | # |
1527 | # - ls2: | |
1528 | # - tagged with VLAN 101 | |
ea46a4e9 | 1529 | # - ports: lp13, lp14, lp23, lp24 |
0ee7f7f1 HZ |
1530 | # - ls3: |
1531 | # - untagged | |
ea46a4e9 | 1532 | # - ports: lp15, lp25 |
0ee7f7f1 | 1533 | # |
ea46a4e9 | 1534 | # Note: a localnet port is created for each switch to connect to |
0ee7f7f1 HZ |
1535 | # physical network. |
1536 | ||
1537 | for i in 1 2 3; do | |
ea46a4e9 JP |
1538 | ls_name=ls$i |
1539 | ovn-nbctl ls-add $ls_name | |
0ee7f7f1 HZ |
1540 | ln_port_name=ln$i |
1541 | if test $i -eq 2; then | |
ea46a4e9 | 1542 | ovn-nbctl lsp-add $ls_name $ln_port_name "" 101 |
0ee7f7f1 | 1543 | else |
ea46a4e9 | 1544 | ovn-nbctl lsp-add $ls_name $ln_port_name |
0ee7f7f1 | 1545 | fi |
31ed1192 JP |
1546 | ovn-nbctl lsp-set-addresses $ln_port_name unknown |
1547 | ovn-nbctl lsp-set-type $ln_port_name localnet | |
1548 | ovn-nbctl lsp-set-options $ln_port_name network_name=phys | |
0ee7f7f1 | 1549 | done |
d79fc5f4 | 1550 | |
69b72264 BP |
1551 | # lsp_to_ls LSP |
1552 | # | |
1553 | # Prints the name of the logical switch that contains LSP. | |
1554 | lsp_to_ls () { | |
1555 | case $1 in dnl ( | |
1556 | lp?[[12]]) echo ls1 ;; dnl ( | |
1557 | lp?[[34]]) echo ls2 ;; dnl ( | |
1558 | lp?5) echo ls3 ;; dnl ( | |
1559 | *) AT_FAIL_IF([:]) ;; | |
1560 | esac | |
1561 | } | |
1562 | ||
d79fc5f4 RB |
1563 | net_add n1 |
1564 | for i in 1 2; do | |
1565 | sim_add hv$i | |
1566 | as hv$i | |
1567 | ovs-vsctl add-br br-phys | |
1568 | ovs-vsctl set open . external-ids:ovn-bridge-mappings=phys:br-phys | |
1569 | ovn_attach n1 br-phys 192.168.0.$i | |
1570 | ||
0ee7f7f1 | 1571 | for j in 1 2 3 4 5; do |
d79fc5f4 RB |
1572 | ovs-vsctl add-port br-int vif$i$j -- \ |
1573 | set Interface vif$i$j external-ids:iface-id=lp$i$j \ | |
1574 | options:tx_pcap=hv$i/vif$i$j-tx.pcap \ | |
1575 | options:rxq_pcap=hv$i/vif$i$j-rx.pcap \ | |
1576 | ofport-request=$i$j | |
1577 | ||
31ed1192 | 1578 | lsp_name=lp$i$j |
69b72264 | 1579 | ls_name=$(lsp_to_ls $lsp_name) |
d79fc5f4 | 1580 | |
ea46a4e9 | 1581 | ovn-nbctl lsp-add $ls_name $lsp_name |
31ed1192 JP |
1582 | ovn-nbctl lsp-set-addresses $lsp_name f0:00:00:00:00:$i$j |
1583 | ovn-nbctl lsp-set-port-security $lsp_name f0:00:00:00:00:$i$j | |
d79fc5f4 | 1584 | |
31ed1192 | 1585 | OVS_WAIT_UNTIL([test x`ovn-nbctl lsp-get-up $lsp_name` = xup]) |
d79fc5f4 RB |
1586 | done |
1587 | done | |
69b72264 BP |
1588 | ovn-nbctl --wait=sb sync |
1589 | ovn-sbctl dump-flows | |
d79fc5f4 RB |
1590 | |
1591 | ovn_populate_arp | |
1592 | ||
1593 | # XXX This is now the 3rd copy of these functions in this file ... | |
1594 | ||
1595 | # Given the name of a logical port, prints the name of the hypervisor | |
1596 | # on which it is located. | |
1597 | vif_to_hv() { | |
1598 | echo hv${1%?} | |
1599 | } | |
1600 | # | |
69b72264 | 1601 | # test_packet INPORT DST SRC ETHTYPE EOUT LOUT |
d79fc5f4 RB |
1602 | # |
1603 | # This shell function causes a packet to be received on INPORT. The packet's | |
1604 | # content has Ethernet destination DST and source SRC (each exactly 12 hex | |
69b72264 BP |
1605 | # digits) and Ethernet type ETHTYPE (4 hex digits). INPORT is specified as |
1606 | # logical switch port numbers, e.g. 11 for vif11. | |
1607 | # | |
1608 | # EOUT is the end-to-end output port, that is, where the packet will end up | |
1609 | # after possibly bouncing through one or more localnet ports. LOUT is the | |
1610 | # logical output port, which might be a localnet port, as seen by ovn-trace | |
1611 | # (which doesn't know what localnet ports are connected to and therefore can't | |
1612 | # figure out the end-to-end answer). | |
d79fc5f4 | 1613 | for i in 1 2; do |
0ee7f7f1 | 1614 | for j in 1 2 3 4 5; do |
d79fc5f4 RB |
1615 | : > $i$j.expected |
1616 | done | |
1617 | done | |
1618 | test_packet() { | |
69b72264 BP |
1619 | local inport=$1 dst=$2 src=$3 eth=$4 eout=$5 lout=$6 |
1620 | echo "$@" | |
1621 | ||
1622 | # First try tracing the packet. | |
1623 | uflow="inport==\"lp$inport\" && eth.dst==$dst && eth.src==$src && eth.type==0x$eth" | |
1624 | if test $lout != drop; then | |
1625 | echo "output(\"$lout\");" | |
1626 | fi > expout | |
1627 | AT_CAPTURE_FILE([trace]) | |
1628 | AT_CHECK([ovn-trace --all $(lsp_to_ls lp$inport) "$uflow" | tee trace | sed '1,/Minimal trace/d'], [0], [expout]) | |
1629 | ||
1630 | # Then actually send a packet, for an end-to-end test. | |
1631 | local packet=$(echo $dst$src | sed 's/://g')${eth} | |
d79fc5f4 RB |
1632 | hv=`vif_to_hv $inport` |
1633 | vif=vif$inport | |
1634 | as $hv ovs-appctl netdev-dummy/receive $vif $packet | |
69b72264 BP |
1635 | if test $eout != drop; then |
1636 | echo $packet >> ${eout#lp}.expected | |
1637 | fi | |
d79fc5f4 RB |
1638 | } |
1639 | ||
7277bc83 RB |
1640 | # lp11 and lp21 are on the same network (phys, untagged) |
1641 | # and on different hypervisors | |
69b72264 BP |
1642 | test_packet 11 f0:00:00:00:00:21 f0:00:00:00:00:11 1121 lp21 lp21 |
1643 | test_packet 21 f0:00:00:00:00:11 f0:00:00:00:00:21 2111 lp11 lp11 | |
d79fc5f4 | 1644 | |
7277bc83 RB |
1645 | # lp11 and lp12 are on the same network (phys, untagged) |
1646 | # and on the same hypervisor | |
69b72264 BP |
1647 | test_packet 11 f0:00:00:00:00:12 f0:00:00:00:00:11 1112 lp12 lp12 |
1648 | test_packet 12 f0:00:00:00:00:11 f0:00:00:00:00:12 1211 lp11 lp11 | |
7277bc83 RB |
1649 | |
1650 | # lp13 and lp23 are on the same network (phys, VLAN 101) | |
1651 | # and on different hypervisors | |
69b72264 BP |
1652 | test_packet 13 f0:00:00:00:00:23 f0:00:00:00:00:13 1323 lp23 lp23 |
1653 | test_packet 23 f0:00:00:00:00:13 f0:00:00:00:00:23 2313 lp13 lp13 | |
7277bc83 RB |
1654 | |
1655 | # lp13 and lp14 are on the same network (phys, VLAN 101) | |
1656 | # and on the same hypervisor | |
69b72264 BP |
1657 | test_packet 13 f0:00:00:00:00:14 f0:00:00:00:00:13 1314 lp14 lp14 |
1658 | test_packet 14 f0:00:00:00:00:13 f0:00:00:00:00:14 1413 lp13 lp13 | |
d79fc5f4 | 1659 | |
0ee7f7f1 | 1660 | # lp11 and lp15 are on the same network (phys, untagged), |
ea46a4e9 | 1661 | # same hypervisor, and on different switches |
69b72264 BP |
1662 | test_packet 11 f0:00:00:00:00:15 f0:00:00:00:00:11 1115 lp15 ln1 |
1663 | test_packet 15 f0:00:00:00:00:11 f0:00:00:00:00:15 1511 lp11 ln3 | |
0ee7f7f1 HZ |
1664 | |
1665 | # lp11 and lp25 are on the same network (phys, untagged), | |
ea46a4e9 | 1666 | # different hypervisors, and on different switches |
69b72264 BP |
1667 | test_packet 11 f0:00:00:00:00:25 f0:00:00:00:00:11 1125 lp25 ln1 |
1668 | test_packet 25 f0:00:00:00:00:11 f0:00:00:00:00:25 2511 lp11 ln3 | |
0ee7f7f1 | 1669 | |
d79fc5f4 | 1670 | # Ports that should not be able to communicate |
69b72264 BP |
1671 | test_packet 11 f0:00:00:00:00:13 f0:00:00:00:00:11 1113 drop ln1 |
1672 | test_packet 11 f0:00:00:00:00:23 f0:00:00:00:00:11 1123 drop ln1 | |
1673 | test_packet 21 f0:00:00:00:00:13 f0:00:00:00:00:21 2113 drop ln1 | |
1674 | test_packet 21 f0:00:00:00:00:23 f0:00:00:00:00:21 2123 drop ln1 | |
1675 | test_packet 13 f0:00:00:00:00:11 f0:00:00:00:00:13 1311 drop ln2 | |
1676 | test_packet 13 f0:00:00:00:00:21 f0:00:00:00:00:13 1321 drop ln2 | |
1677 | test_packet 23 f0:00:00:00:00:11 f0:00:00:00:00:23 2311 drop ln2 | |
1678 | test_packet 23 f0:00:00:00:00:21 f0:00:00:00:00:23 2321 drop ln2 | |
d79fc5f4 | 1679 | |
d79fc5f4 RB |
1680 | # Dump a bunch of info helpful for debugging if there's a failure. |
1681 | ||
1682 | echo "------ OVN dump ------" | |
1683 | ovn-nbctl show | |
1684 | ovn-sbctl show | |
1685 | ||
1686 | echo "------ hv1 dump ------" | |
1687 | as hv1 ovs-vsctl show | |
1688 | as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-int | |
1689 | ||
1690 | echo "------ hv2 dump ------" | |
1691 | as hv2 ovs-vsctl show | |
1692 | as hv2 ovs-ofctl -O OpenFlow13 dump-flows br-int | |
1693 | ||
1694 | # Now check the packets actually received against the ones expected. | |
1695 | for i in 1 2; do | |
0ee7f7f1 | 1696 | for j in 1 2 3 4 5; do |
49d7c759 | 1697 | OVN_CHECK_PACKETS([hv$i/vif$i$j-tx.pcap], [$i$j.expected]) |
d79fc5f4 RB |
1698 | done |
1699 | done | |
1700 | ||
7a8f15e0 | 1701 | OVN_CLEANUP([hv1],[hv2]) |
d9c8c57c | 1702 | |
d79fc5f4 RB |
1703 | AT_CLEANUP |
1704 | ||
91125642 FF |
1705 | AT_SETUP([ovn -- vtep: 3 HVs, 1 VIFs/HV, 1 GW, 1 LS]) |
1706 | AT_KEYWORDS([vtep]) | |
eb6b08eb JP |
1707 | AT_SKIP_IF([test $HAVE_PYTHON = no]) |
1708 | ovn_start | |
1709 | ||
1710 | # Configure the Northbound database | |
ea46a4e9 | 1711 | ovn-nbctl ls-add lsw0 |
eb6b08eb | 1712 | |
31ed1192 JP |
1713 | ovn-nbctl lsp-add lsw0 lp1 |
1714 | ovn-nbctl lsp-set-addresses lp1 f0:00:00:00:00:01 | |
eb6b08eb | 1715 | |
31ed1192 JP |
1716 | ovn-nbctl lsp-add lsw0 lp2 |
1717 | ovn-nbctl lsp-set-addresses lp2 f0:00:00:00:00:02 | |
eb6b08eb | 1718 | |
31ed1192 JP |
1719 | ovn-nbctl lsp-add lsw0 lp-vtep |
1720 | ovn-nbctl lsp-set-type lp-vtep vtep | |
1721 | ovn-nbctl lsp-set-options lp-vtep vtep-physical-switch=br-vtep vtep-logical-switch=lsw0 | |
1722 | ovn-nbctl lsp-set-addresses lp-vtep unknown | |
eb6b08eb | 1723 | |
77adbb62 DB |
1724 | # lpr, lr and lrp1 are used for the ARP request handling test only. |
1725 | ovn-nbctl lsp-add lsw0 lpr | |
1726 | ovn-nbctl lr-add lr | |
1727 | ovn-nbctl lrp-add lr lrp1 f0:00:00:00:00:f1 192.168.1.1/24 | |
1728 | ovn-nbctl set Logical_Switch_Port lpr type=router \ | |
1729 | options:router-port=lrp1 \ | |
1730 | addresses='"f0:00:00:00:00:f1 192.168.1.1"' | |
1731 | ||
1732 | ||
eb6b08eb JP |
1733 | net_add n1 # Network to connect hv1, hv2, and vtep |
1734 | net_add n2 # Network to connect vtep and hv3 | |
1735 | ||
1736 | # Create hypervisor hv1 connected to n1 | |
1737 | sim_add hv1 | |
1738 | as hv1 | |
1739 | ovs-vsctl add-br br-phys | |
1740 | ovn_attach n1 br-phys 192.168.0.1 | |
1741 | 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 | |
1742 | ||
1743 | # Create hypervisor hv2 connected to n1 | |
1744 | sim_add hv2 | |
1745 | as hv2 | |
1746 | ovs-vsctl add-br br-phys | |
1747 | ovn_attach n1 br-phys 192.168.0.2 | |
1748 | 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 | |
1749 | ||
1750 | ||
1751 | # Start the vtep emulator with a leg in both networks | |
1752 | sim_add vtep | |
1753 | as vtep | |
1754 | ||
1755 | ovsdb-tool create "$ovs_base"/vtep/vtep.db "$abs_top_srcdir"/vtep/vtep.ovsschema || return 1 | |
1756 | ovs-appctl -t ovsdb-server ovsdb-server/add-db "$ovs_base"/vtep/vtep.db | |
1757 | ||
1758 | ovs-vsctl add-br br-phys | |
1759 | net_attach n1 br-phys | |
1760 | ||
1761 | mac=`ovs-vsctl get Interface br-phys mac_in_use | sed s/\"//g` | |
1762 | arp_table="$arp_table $sandbox,br-phys,192.168.0.3,$mac" | |
1763 | ovs-appctl netdev-dummy/ip4addr br-phys 192.168.0.3/24 >/dev/null || return 1 | |
1764 | ovs-appctl ovs/route/add 192.168.0.3/24 br-phys >/dev/null || return 1 | |
1765 | ||
1766 | ovs-vsctl add-br br-vtep | |
1767 | net_attach n2 br-vtep | |
1768 | ||
1769 | vtep-ctl add-ps br-vtep | |
1770 | vtep-ctl set Physical_Switch br-vtep tunnel_ips=192.168.0.3 | |
1771 | vtep-ctl add-ls lsw0 | |
1772 | ||
1773 | start_daemon ovs-vtep br-vtep | |
1774 | start_daemon ovn-controller-vtep --vtep-db=unix:"$ovs_base"/vtep/db.sock --ovnsb-db=unix:"$ovs_base"/ovn-sb/ovn-sb.sock | |
1775 | ||
1776 | sleep 1 | |
1777 | ||
1778 | vtep-ctl bind-ls br-vtep br-vtep_n2 0 lsw0 | |
1779 | ||
475f0a2c DB |
1780 | OVS_WAIT_UNTIL([test -n "`as vtep vtep-ctl get-replication-mode lsw0 | |
1781 | grep -- source`"]) | |
1782 | # It takes more time for the update to be processed by ovs-vtep. | |
eb6b08eb JP |
1783 | sleep 1 |
1784 | ||
1785 | # Add hv3 on the other side of the vtep | |
1786 | sim_add hv3 | |
1787 | as hv3 | |
1788 | ovs-vsctl add-br br-phys | |
1789 | net_attach n2 br-phys | |
1790 | ||
1791 | 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 | |
1792 | ||
1793 | # Pre-populate the hypervisors' ARP tables so that we don't lose any | |
1794 | # packets for ARP resolution (native tunneling doesn't queue packets | |
1795 | # for ARP resolution). | |
1796 | ovn_populate_arp | |
1797 | ||
1798 | # Allow some time for ovn-northd and ovn-controller to catch up. | |
1799 | # XXX This should be more systematic. | |
1800 | sleep 1 | |
6977df72 | 1801 | |
eb6b08eb JP |
1802 | # test_packet INPORT DST SRC ETHTYPE OUTPORT... |
1803 | # | |
1804 | # This shell function causes a packet to be received on INPORT. The packet's | |
1805 | # content has Ethernet destination DST and source SRC (each exactly 12 hex | |
1806 | # digits) and Ethernet type ETHTYPE (4 hex digits). The OUTPORTs (zero or | |
1807 | # more) list the VIFs on which the packet should be received. INPORT and the | |
31ed1192 | 1808 | # OUTPORTs are specified as logical switch port numbers, e.g. 1 for vif1. |
eb6b08eb JP |
1809 | for i in 1 2 3; do |
1810 | : > $i.expected | |
1811 | done | |
1812 | test_packet() { | |
1813 | local inport=$1 packet=$2$3$4; shift; shift; shift; shift | |
1814 | #hv=hv`echo $inport | sed 's/^\(.\).*/\1/'` | |
1815 | hv=hv$inport | |
1816 | vif=vif$inport | |
1817 | as $hv ovs-appctl netdev-dummy/receive $vif $packet | |
1818 | for outport; do | |
e4543cfe | 1819 | echo $packet >> $outport.expected |
eb6b08eb JP |
1820 | done |
1821 | } | |
1822 | ||
1823 | # Send packets between all pairs of source and destination ports: | |
1824 | # | |
31ed1192 JP |
1825 | # 1. Unicast packets are delivered to exactly one logical switch port |
1826 | # (except that packets destined to their input ports are dropped). | |
eb6b08eb | 1827 | # |
31ed1192 JP |
1828 | # 2. Broadcast and multicast are delivered to all logical switch ports |
1829 | # except the input port. | |
eb6b08eb | 1830 | # |
ea46a4e9 | 1831 | # 3. The switch delivers packets with an unknown destination to logical |
31ed1192 JP |
1832 | # switch ports with "unknown" among their MAC addresses (and port |
1833 | # security disabled). | |
eb6b08eb JP |
1834 | for s in 1 2 3; do |
1835 | bcast= | |
1836 | unknown= | |
1837 | for d in 1 2 3; do | |
1838 | if test $d != $s; then unicast=$d; else unicast=; fi | |
1839 | test_packet $s f0000000000$d f0000000000$s 00$s$d $unicast #1 | |
1840 | ||
1841 | # The vtep (vif3) is the only one configured for "unknown" | |
1842 | if test $d != $s && test $d = 3; then | |
1843 | unknown="$unknown $d" | |
1844 | fi | |
1845 | bcast="$bcast $unicast" | |
1846 | done | |
1847 | ||
1848 | # Broadcast and multicast. | |
46ed1382 DB |
1849 | test_packet $s ffffffffffff f0000000000$s 0${s}ff $bcast #2 |
1850 | test_packet $s 010000000000 f0000000000$s 0${s}ff $bcast #2 | |
eb6b08eb JP |
1851 | |
1852 | test_packet $s f0000000ffff f0000000000$s 0${s}66 $unknown #3 | |
1853 | done | |
1854 | ||
77adbb62 DB |
1855 | # ARP request should not be responded to by logical switch router |
1856 | # type arp responder on HV1 and HV2 and should reach directly to | |
1857 | # vif1 and vif2 | |
1858 | ip_to_hex() { | |
1859 | printf "%02x%02x%02x%02x" "$@" | |
1860 | } | |
1861 | sha=f00000000003 | |
1862 | spa=`ip_to_hex 192 168 1 2` | |
1863 | tpa=`ip_to_hex 192 168 1 1` | |
1864 | request=ffffffffffff${sha}08060001080006040001${sha}${spa}ffffffffffff${tpa} | |
1865 | as hv3 ovs-appctl netdev-dummy/receive vif3 $request | |
1866 | echo $request >> 1.expected | |
1867 | echo $request >> 2.expected | |
1868 | ||
bb0c41d3 RM |
1869 | # dump information with counters |
1870 | echo "------ OVN dump ------" | |
1871 | ovn-nbctl show | |
1872 | ovn-sbctl show | |
1873 | ||
77adbb62 DB |
1874 | echo "---------SB dump-----" |
1875 | ovn-sbctl list datapath_binding | |
1876 | echo "---------------------" | |
1877 | ovn-sbctl list port_binding | |
1878 | echo "---------------------" | |
1879 | ovn-sbctl dump-flows | |
1880 | ||
bb0c41d3 RM |
1881 | echo "------ hv1 dump ------" |
1882 | as hv1 ovs-vsctl show | |
6195e2e7 | 1883 | as hv1 ovs-ofctl -O OpenFlow13 show br-int |
bb0c41d3 RM |
1884 | as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-int |
1885 | ||
1886 | echo "------ hv2 dump ------" | |
1887 | as hv2 ovs-vsctl show | |
6195e2e7 | 1888 | as hv2 ovs-ofctl -O OpenFlow13 show br-int |
bb0c41d3 RM |
1889 | as hv2 ovs-ofctl -O OpenFlow13 dump-flows br-int |
1890 | ||
1891 | echo "------ hv3 dump ------" | |
1892 | as hv3 ovs-vsctl show | |
6754e92d FF |
1893 | # note: hv3 has no logical port bind, thus it should not have br-int |
1894 | AT_CHECK([as hv3 ovs-ofctl -O OpenFlow13 show br-int], [1], [], | |
1895 | [ovs-ofctl: br-int is not a bridge or a socket | |
1896 | ]) | |
bb0c41d3 | 1897 | |
eb6b08eb JP |
1898 | # Now check the packets actually received against the ones expected. |
1899 | for i in 1 2 3; do | |
49d7c759 | 1900 | OVN_CHECK_PACKETS([hv$i/vif$i-tx.pcap], [$i.expected]) |
eb6b08eb | 1901 | done |
fcde56f5 LR |
1902 | |
1903 | # Gracefully terminate daemons | |
7a8f15e0 LR |
1904 | OVN_CLEANUP([hv1],[hv2],[vtep]) |
1905 | OVN_CLEANUP_VSWITCH([hv3]) | |
d9c8c57c | 1906 | |
eb6b08eb | 1907 | AT_CLEANUP |
9975d7be | 1908 | |
184bc3ca RB |
1909 | # Similar test to "hardware GW" |
1910 | AT_SETUP([ovn -- 3 HVs, 1 VIFs/HV, 1 software GW, 1 LS]) | |
1911 | AT_SKIP_IF([test $HAVE_PYTHON = no]) | |
1912 | ovn_start | |
1913 | ||
1914 | # Configure the Northbound database | |
1915 | ovn-nbctl ls-add lsw0 | |
1916 | ||
1917 | ovn-nbctl lsp-add lsw0 lp1 | |
1918 | ovn-nbctl lsp-set-addresses lp1 f0:00:00:00:00:01 | |
1919 | ||
1920 | ovn-nbctl lsp-add lsw0 lp2 | |
1921 | ovn-nbctl lsp-set-addresses lp2 f0:00:00:00:00:02 | |
1922 | ||
1923 | ovn-nbctl lsp-add lsw0 lp-gw | |
1924 | ovn-nbctl lsp-set-type lp-gw l2gateway | |
62b87eab | 1925 | ovn-nbctl lsp-set-options lp-gw network_name=physnet1 l2gateway-chassis=hv_gw |
184bc3ca RB |
1926 | ovn-nbctl lsp-set-addresses lp-gw unknown |
1927 | ||
1928 | net_add n1 # Network to connect hv1, hv2, and gw | |
1929 | net_add n2 # Network to connect gw and hv3 | |
1930 | ||
1931 | # Create hypervisor hv1 connected to n1 | |
1932 | sim_add hv1 | |
1933 | as hv1 | |
1934 | ovs-vsctl add-br br-phys | |
1935 | ovn_attach n1 br-phys 192.168.0.1 | |
1936 | 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 | |
1937 | ||
1938 | # Create hypervisor hv2 connected to n1 | |
1939 | sim_add hv2 | |
1940 | as hv2 | |
1941 | ovs-vsctl add-br br-phys | |
1942 | ovn_attach n1 br-phys 192.168.0.2 | |
1943 | 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 | |
1944 | ||
1945 | # Create hypervisor hv_gw connected to n1 and n2 | |
1946 | # connect br-phys bridge to n1; connect hv-gw bridge to n2 | |
1947 | sim_add hv_gw | |
1948 | as hv_gw | |
1949 | ovs-vsctl add-br br-phys | |
1950 | ovn_attach n1 br-phys 192.168.0.3 | |
1951 | ovs-vsctl add-br br-phys2 | |
1952 | net_attach n2 br-phys2 | |
1953 | ovs-vsctl set open . external_ids:ovn-bridge-mappings="physnet1:br-phys2" | |
1954 | ||
184bc3ca RB |
1955 | # Add hv3 on the other side of the GW |
1956 | sim_add hv3 | |
1957 | as hv3 | |
1958 | ovs-vsctl add-br br-phys | |
1959 | net_attach n2 br-phys | |
1960 | 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 | |
1961 | ||
1962 | ||
1963 | # Pre-populate the hypervisors' ARP tables so that we don't lose any | |
1964 | # packets for ARP resolution (native tunneling doesn't queue packets | |
1965 | # for ARP resolution). | |
1966 | ovn_populate_arp | |
1967 | ||
1968 | # Allow some time for ovn-northd and ovn-controller to catch up. | |
1969 | # XXX This should be more systematic. | |
1970 | sleep 1 | |
1971 | ||
1972 | # test_packet INPORT DST SRC ETHTYPE OUTPORT... | |
1973 | # | |
1974 | # This shell function causes a packet to be received on INPORT. The packet's | |
1975 | # content has Ethernet destination DST and source SRC (each exactly 12 hex | |
1976 | # digits) and Ethernet type ETHTYPE (4 hex digits). The OUTPORTs (zero or | |
1977 | # more) list the VIFs on which the packet should be received. INPORT and the | |
1978 | # OUTPORTs are specified as lport numbers, e.g. 1 for vif1. | |
184bc3ca RB |
1979 | for i in 1 2 3; do |
1980 | : > $i.expected | |
1981 | done | |
1982 | test_packet() { | |
1983 | local inport=$1 packet=$2$3$4; shift; shift; shift; shift | |
1984 | #hv=hv`echo $inport | sed 's/^\(.\).*/\1/'` | |
1985 | hv=hv$inport | |
1986 | vif=vif$inport | |
1987 | as $hv ovs-appctl netdev-dummy/receive $vif $packet | |
1988 | for outport; do | |
e4543cfe | 1989 | echo $packet >> $outport.expected |
184bc3ca RB |
1990 | done |
1991 | } | |
1992 | ||
1993 | # Send packets between all pairs of source and destination ports: | |
1994 | # | |
1995 | # 1. Unicast packets are delivered to exactly one lport (except that packets | |
1996 | # destined to their input ports are dropped). | |
1997 | # | |
1998 | # 2. Broadcast and multicast are delivered to all lports except the input port. | |
1999 | # | |
2000 | # 3. The lswitch delivers packets with an unknown destination to lports with | |
2001 | # "unknown" among their MAC addresses (and port security disabled). | |
2002 | for s in 1 2 3 ; do | |
2003 | bcast= | |
2004 | unknown= | |
2005 | for d in 1 2 3 ; do | |
2006 | if test $d != $s; then unicast=$d; else unicast=; fi | |
2007 | test_packet $s f0000000000$d f0000000000$s 00$s$d $unicast #1 | |
2008 | ||
2009 | # The vtep (vif3) is the only one configured for "unknown" | |
2010 | if test $d != $s && test $d = 3; then | |
2011 | unknown="$unknown $d" | |
2012 | fi | |
2013 | bcast="$bcast $unicast" | |
2014 | done | |
2015 | ||
2016 | test_packet $s ffffffffffff f0000000000$s 0${s}ff $bcast #2 | |
2017 | test_packet $s 010000000000 f0000000000$s 0${s}ff $bcast #3 | |
2018 | test_packet $s f0000000ffff f0000000000$s 0${s}66 $unknown #4 | |
2019 | done | |
2020 | ||
184bc3ca RB |
2021 | echo "------ ovn-nbctl show ------" |
2022 | ovn-nbctl show | |
2023 | echo "------ ovn-sbctl show ------" | |
2024 | ovn-sbctl show | |
2025 | ||
2026 | echo "------ hv1 ------" | |
2027 | as hv1 ovs-vsctl show | |
2028 | echo "------ hv1 br-int ------" | |
2029 | as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-int | |
2030 | echo "------ hv1 br-phys ------" | |
2031 | as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-phys | |
2032 | ||
2033 | echo "------ hv2 ------" | |
2034 | as hv2 ovs-vsctl show | |
2035 | echo "------ hv2 br-int ------" | |
2036 | as hv2 ovs-ofctl -O OpenFlow13 dump-flows br-int | |
2037 | echo "------ hv2 br-phys ------" | |
2038 | as hv2 ovs-ofctl -O OpenFlow13 dump-flows br-phys | |
2039 | ||
2040 | echo "------ hv_gw ------" | |
2041 | as hv_gw ovs-vsctl show | |
2042 | echo "------ hv_gw br-phys ------" | |
2043 | as hv_gw ovs-ofctl -O OpenFlow13 dump-flows br-phys | |
2044 | echo "------ hv_gw br-phys2 ------" | |
2045 | as hv_gw ovs-ofctl -O OpenFlow13 dump-flows br-phys2 | |
2046 | ||
2047 | echo "------ hv3 ------" | |
2048 | as hv3 ovs-vsctl show | |
2049 | echo "------ hv3 br-phys ------" | |
2050 | as hv3 ovs-ofctl -O OpenFlow13 dump-flows br-phys | |
2051 | ||
2052 | # Now check the packets actually received against the ones expected. | |
2053 | for i in 1 2 3; do | |
49d7c759 | 2054 | OVN_CHECK_PACKETS([hv$i/vif$i-tx.pcap], [$i.expected]) |
184bc3ca RB |
2055 | done |
2056 | AT_CLEANUP | |
2057 | ||
9975d7be BP |
2058 | # 3 hypervisors, 3 logical switches with 3 logical ports each, 1 logical router |
2059 | AT_SETUP([ovn -- 3 HVs, 3 LS, 3 lports/LS, 1 LR]) | |
2060 | AT_SKIP_IF([test $HAVE_PYTHON = no]) | |
2061 | ovn_start | |
2062 | ||
2063 | # Logical network: | |
2064 | # | |
2065 | # Three logical switches ls1, ls2, ls3. | |
86e98048 BP |
2066 | # One logical router lr0 connected to ls[123], |
2067 | # with nine subnets, three per logical switch: | |
2068 | # | |
2069 | # lrp11 on ls1 for subnet 192.168.11.0/24 | |
2070 | # lrp12 on ls1 for subnet 192.168.12.0/24 | |
2071 | # lrp13 on ls1 for subnet 192.168.13.0/24 | |
2072 | # ... | |
2073 | # lrp33 on ls3 for subnet 192.168.33.0/24 | |
2074 | # | |
2075 | # 27 VIFs, 9 per LS, 3 per subnet: lp[123][123][123], where the first two | |
2076 | # digits are the subnet and the last digit distinguishes the VIF. | |
9975d7be | 2077 | for i in 1 2 3; do |
ea46a4e9 | 2078 | ovn-nbctl ls-add ls$i |
9975d7be | 2079 | for j in 1 2 3; do |
86e98048 | 2080 | for k in 1 2 3; do |
31ed1192 JP |
2081 | # Add "unknown" to MAC addresses for lp?11, so packets for |
2082 | # MAC-IP bindings discovered via ARP later have somewhere to go. | |
2083 | if test $j$k = 11; then unknown=unknown; else unknown=; fi | |
2084 | ||
2085 | ovn-nbctl \ | |
2086 | -- lsp-add ls$i lp$i$j$k \ | |
2087 | -- lsp-set-addresses lp$i$j$k "f0:00:00:00:0$i:$j$k \ | |
2088 | 192.168.$i$j.$k" $unknown | |
86e98048 BP |
2089 | done |
2090 | done | |
2091 | done | |
2092 | ||
fa2a27b2 | 2093 | ovn-nbctl lr-add lr0 |
86e98048 BP |
2094 | for i in 1 2 3; do |
2095 | for j in 1 2 3; do | |
bf44c2cd | 2096 | ovn-nbctl lrp-add lr0 lrp$i$j 00:00:00:00:ff:$i$j 192.168.$i$j.254/24 |
269ecccc | 2097 | ovn-nbctl \ |
31ed1192 | 2098 | -- lsp-add ls$i lrp$i$j-attachment \ |
269ecccc | 2099 | -- set Logical_Switch_Port lrp$i$j-attachment type=router \ |
00007447 | 2100 | options:router-port=lrp$i$j \ |
86e98048 | 2101 | addresses='"00:00:00:00:ff:'$i$j'"' |
9975d7be BP |
2102 | done |
2103 | done | |
2104 | ||
80f408f4 | 2105 | ovn-nbctl set Logical_Switch_Port lrp33-attachment \ |
57d143eb HZ |
2106 | addresses='"00:00:00:00:ff:33 192.168.33.254"' |
2107 | ||
9975d7be BP |
2108 | # Physical network: |
2109 | # | |
2110 | # Three hypervisors hv[123]. | |
86e98048 BP |
2111 | # lp?1[123] spread across hv[123]: lp?11 on hv1, lp?12 on hv2, lp?13 on hv3. |
2112 | # lp?2[123] spread across hv[23]: lp?21 and lp?22 on hv2, lp?23 on hv3. | |
2113 | # lp?3[123] all on hv3. | |
2114 | ||
9975d7be BP |
2115 | |
2116 | # Given the name of a logical port, prints the name of the hypervisor | |
2117 | # on which it is located. | |
2118 | vif_to_hv() { | |
2119 | case $1 in dnl ( | |
86e98048 BP |
2120 | ?11) echo 1 ;; dnl ( |
2121 | ?12 | ?21 | ?22) echo 2 ;; dnl ( | |
2122 | ?13 | ?23 | ?3?) echo 3 ;; | |
9975d7be BP |
2123 | esac |
2124 | } | |
2125 | ||
86e98048 BP |
2126 | # Given the name of a logical port, prints the name of its logical router |
2127 | # port, e.g. "vif_to_lrp 123" yields 12. | |
2128 | vif_to_lrp() { | |
2129 | echo ${1%?} | |
2130 | } | |
2131 | ||
2132 | # Given the name of a logical port, prints the name of its logical | |
2133 | # switch, e.g. "vif_to_ls 123" yields 1. | |
e3393e3f | 2134 | vif_to_ls() { |
86e98048 | 2135 | echo ${1%??} |
e3393e3f BP |
2136 | } |
2137 | ||
9975d7be BP |
2138 | net_add n1 |
2139 | for i in 1 2 3; do | |
2140 | sim_add hv$i | |
2141 | as hv$i | |
2142 | ovs-vsctl add-br br-phys | |
2143 | ovn_attach n1 br-phys 192.168.0.$i | |
2144 | done | |
2145 | for i in 1 2 3; do | |
2146 | for j in 1 2 3; do | |
86e98048 | 2147 | for k in 1 2 3; do |
269ecccc JP |
2148 | hv=`vif_to_hv $i$j$k` |
2149 | as hv$hv ovs-vsctl \ | |
2150 | -- add-port br-int vif$i$j$k \ | |
2151 | -- set Interface vif$i$j$k \ | |
2152 | external-ids:iface-id=lp$i$j$k \ | |
2153 | options:tx_pcap=hv$hv/vif$i$j$k-tx.pcap \ | |
2154 | options:rxq_pcap=hv$hv/vif$i$j$k-rx.pcap \ | |
2155 | ofport-request=$i$j$k | |
86e98048 | 2156 | done |
9975d7be BP |
2157 | done |
2158 | done | |
2159 | ||
2160 | # Pre-populate the hypervisors' ARP tables so that we don't lose any | |
2161 | # packets for ARP resolution (native tunneling doesn't queue packets | |
2162 | # for ARP resolution). | |
2163 | ovn_populate_arp | |
2164 | ||
2165 | # Allow some time for ovn-northd and ovn-controller to catch up. | |
2166 | # XXX This should be more systematic. | |
2167 | sleep 1 | |
2168 | ||
e3393e3f | 2169 | # test_ip INPORT SRC_MAC DST_MAC SRC_IP DST_IP OUTPORT... |
9975d7be BP |
2170 | # |
2171 | # This shell function causes a packet to be received on INPORT. The packet's | |
2172 | # content has Ethernet destination DST and source SRC (each exactly 12 hex | |
2173 | # digits) and Ethernet type ETHTYPE (4 hex digits). The OUTPORTs (zero or | |
2174 | # more) list the VIFs on which the packet should be received. INPORT and the | |
31ed1192 | 2175 | # OUTPORTs are specified as logical switch port numbers, e.g. 123 for vif123. |
9975d7be BP |
2176 | for i in 1 2 3; do |
2177 | for j in 1 2 3; do | |
86e98048 BP |
2178 | for k in 1 2 3; do |
2179 | : > $i$j$k.expected | |
269ecccc | 2180 | done |
9975d7be BP |
2181 | done |
2182 | done | |
e3393e3f | 2183 | test_ip() { |
9975d7be BP |
2184 | # This packet has bad checksums but logical L3 routing doesn't check. |
2185 | local inport=$1 src_mac=$2 dst_mac=$3 src_ip=$4 dst_ip=$5 | |
ba43992e | 2186 | local packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 |
9975d7be BP |
2187 | shift; shift; shift; shift; shift |
2188 | hv=hv`vif_to_hv $inport` | |
2189 | as $hv ovs-appctl netdev-dummy/receive vif$inport $packet | |
2190 | #as $hv ovs-appctl ofproto/trace br-int in_port=$inport $packet | |
86e98048 BP |
2191 | in_ls=`vif_to_ls $inport` |
2192 | in_lrp=`vif_to_lrp $inport` | |
9975d7be | 2193 | for outport; do |
269ecccc | 2194 | out_ls=`vif_to_ls $outport` |
86e98048 | 2195 | if test $in_ls = $out_ls; then |
9975d7be BP |
2196 | # Ports on the same logical switch receive exactly the same packet. |
2197 | echo $packet | |
2198 | else | |
2199 | # Routing decrements TTL and updates source and dest MAC | |
2200 | # (and checksum). | |
269ecccc | 2201 | out_lrp=`vif_to_lrp $outport` |
86e98048 | 2202 | echo f00000000${outport}00000000ff${out_lrp}08004500001c00000000"3f1101"00${src_ip}${dst_ip}0035111100080000 |
e4543cfe | 2203 | fi >> $outport.expected |
9975d7be BP |
2204 | done |
2205 | } | |
2206 | ||
e3393e3f | 2207 | as hv1 ovs-vsctl --columns=name,ofport list interface |
0bac7164 BP |
2208 | as hv1 ovn-sbctl list port_binding |
2209 | as hv1 ovn-sbctl list datapath_binding | |
9975d7be BP |
2210 | as hv1 ovn-sbctl dump-flows |
2211 | as hv1 ovs-ofctl dump-flows br-int | |
2212 | ||
e3393e3f | 2213 | # Send IP packets between all pairs of source and destination ports: |
9975d7be | 2214 | # |
31ed1192 JP |
2215 | # 1. Unicast IP packets are delivered to exactly one logical switch port |
2216 | # (except that packets destined to their input ports are dropped). | |
9975d7be | 2217 | # |
31ed1192 JP |
2218 | # 2. Broadcast IP packets are delivered to all logical switch ports |
2219 | # except the input port. | |
86e98048 BP |
2220 | ip_to_hex() { |
2221 | printf "%02x%02x%02x%02x" "$@" | |
2222 | } | |
9975d7be | 2223 | for is in 1 2 3; do |
269ecccc JP |
2224 | for js in 1 2 3; do |
2225 | for ks in 1 2 3; do | |
2226 | bcast= | |
2227 | s=$is$js$ks | |
2228 | smac=f00000000$s | |
2229 | sip=`ip_to_hex 192 168 $is$js $ks` | |
2230 | for id in 1 2 3; do | |
2231 | for jd in 1 2 3; do | |
2232 | for kd in 1 2 3; do | |
2233 | d=$id$jd$kd | |
2234 | dip=`ip_to_hex 192 168 $id$jd $kd` | |
2235 | if test $is = $id; then dmac=f00000000$d; else dmac=00000000ff$is$js; fi | |
2236 | if test $d != $s; then unicast=$d; else unicast=; fi | |
2237 | ||
2238 | test_ip $s $smac $dmac $sip $dip $unicast #1 | |
2239 | ||
2240 | if test $id = $is && test $d != $s; then bcast="$bcast $d"; fi | |
2241 | done | |
2242 | done | |
9975d7be | 2243 | done |
269ecccc JP |
2244 | test_ip $s $smac ffffffffffff $sip ffffffff $bcast #2 |
2245 | done | |
2246 | done | |
e3393e3f BP |
2247 | done |
2248 | ||
0bac7164 BP |
2249 | # 3. Send an IP packet from every logical port to every other subnet, |
2250 | # to an IP address that does not have a static IP-MAC binding. | |
2251 | # This should generate a broadcast ARP request for the destination | |
2252 | # IP address in the destination subnet. | |
2253 | for is in 1 2 3; do | |
269ecccc JP |
2254 | for js in 1 2 3; do |
2255 | for ks in 1 2 3; do | |
2256 | s=$is$js$ks | |
2257 | smac=f00000000$s | |
2258 | sip=`ip_to_hex 192 168 $is$js $ks` | |
2259 | for id in 1 2 3; do | |
2260 | for jd in 1 2 3; do | |
2261 | if test $is$js = $id$jd; then | |
2262 | continue | |
2263 | fi | |
2264 | ||
2265 | # Send the packet. | |
2266 | dmac=00000000ff$is$js | |
2267 | # Calculate a 4th octet for the destination that is | |
2268 | # unique per $s, avoids the .1 .2 .3 and .254 IP addresses | |
2269 | # that have static MAC bindings, and fits in the range | |
2270 | # 0-255. | |
2271 | o4=`expr $is '*' 9 + $js '*' 3 + $ks + 10` | |
2272 | dip=`ip_to_hex 192 168 $id$jd $o4` | |
2273 | test_ip $s $smac $dmac $sip $dip | |
2274 | ||
2275 | # Every LP on the destination subnet's lswitch should | |
2276 | # receive the ARP request. | |
2277 | lrmac=00000000ff$id$jd | |
2278 | lrip=`ip_to_hex 192 168 $id$jd 254` | |
2279 | arp=ffffffffffff${lrmac}08060001080006040001${lrmac}${lrip}000000000000${dip} | |
2280 | for jd2 in 1 2 3; do | |
2281 | for kd in 1 2 3; do | |
e4543cfe | 2282 | echo $arp >> $id$jd2$kd.expected |
0bac7164 | 2283 | done |
269ecccc | 2284 | done |
0bac7164 | 2285 | done |
269ecccc | 2286 | done |
0bac7164 | 2287 | done |
269ecccc | 2288 | done |
0bac7164 BP |
2289 | done |
2290 | ||
e3393e3f BP |
2291 | # test_arp INPORT SHA SPA TPA [REPLY_HA] |
2292 | # | |
2293 | # Causes a packet to be received on INPORT. The packet is an ARP | |
2294 | # request with SHA, SPA, and TPA as specified. If REPLY_HA is provided, then | |
2295 | # it should be the hardware address of the target to expect to receive in an | |
2296 | # ARP reply; otherwise no reply is expected. | |
2297 | # | |
31ed1192 | 2298 | # INPORT is an logical switch port number, e.g. 11 for vif11. |
e3393e3f BP |
2299 | # SHA and REPLY_HA are each 12 hex digits. |
2300 | # SPA and TPA are each 8 hex digits. | |
2301 | test_arp() { | |
2302 | local inport=$1 sha=$2 spa=$3 tpa=$4 reply_ha=$5 | |
2303 | local request=ffffffffffff${sha}08060001080006040001${sha}${spa}ffffffffffff${tpa} | |
2304 | hv=hv`vif_to_hv $inport` | |
2305 | as $hv ovs-appctl netdev-dummy/receive vif$inport $request | |
2306 | #as $hv ovs-appctl ofproto/trace br-int in_port=$inport $request | |
2307 | ||
57d143eb | 2308 | # Expect to receive the broadcast ARP on the other logical switch ports if |
ea46a4e9 | 2309 | # IP address is not configured to the switch patch port. |
e3393e3f | 2310 | local i=`vif_to_ls $inport` |
86e98048 | 2311 | local j k |
e3393e3f | 2312 | for j in 1 2 3; do |
86e98048 | 2313 | for k in 1 2 3; do |
ea46a4e9 | 2314 | # 192.168.33.254 is configured to the switch patch port for lrp33, |
57d143eb HZ |
2315 | # so no ARP flooding expected for it. |
2316 | if test $i$j$k != $inport && test $tpa != `ip_to_hex 192 168 33 254`; then | |
86e98048 BP |
2317 | echo $request >> $i$j$k.expected |
2318 | fi | |
2319 | done | |
e3393e3f BP |
2320 | done |
2321 | ||
2322 | # Expect to receive the reply, if any. | |
2323 | if test X$reply_ha != X; then | |
86e98048 BP |
2324 | lrp=`vif_to_lrp $inport` |
2325 | local reply=${sha}00000000ff${lrp}08060001080006040002${reply_ha}${tpa}${sha}${spa} | |
e3393e3f BP |
2326 | echo $reply >> $inport.expected |
2327 | fi | |
2328 | } | |
2329 | ||
2330 | # Test router replies to ARP requests from all source ports: | |
2331 | # | |
0bac7164 | 2332 | # 4. Router replies to query for its MAC address from port's own IP address. |
e3393e3f | 2333 | # |
0bac7164 | 2334 | # 5. Router replies to query for its MAC address from any random IP address |
e3393e3f BP |
2335 | # in its subnet. |
2336 | # | |
0bac7164 | 2337 | # 6. Router replies to query for its MAC address from another subnet. |
e3393e3f | 2338 | # |
0bac7164 | 2339 | # 7. No reply to query for IP address other than router IP. |
e3393e3f | 2340 | for i in 1 2 3; do |
269ecccc JP |
2341 | for j in 1 2 3; do |
2342 | for k in 1 2 3; do | |
2343 | smac=f00000000$i$j$k # Source MAC | |
2344 | sip=`ip_to_hex 192 168 $i$j $k` # Source IP | |
2345 | rip=`ip_to_hex 192 168 $i$j 254` # Router IP | |
2346 | rmac=00000000ff$i$j # Router MAC | |
2347 | otherip=`ip_to_hex 192 168 $i$j 55` # Some other IP in subnet | |
2348 | test_arp $i$j$k $smac $sip $rip $rmac #4 | |
2349 | test_arp $i$j$k $smac $otherip $rip $rmac #5 | |
2350 | test_arp $i$j$k $smac 0a123456 $rip $rmac #6 | |
2351 | test_arp $i$j$k $smac $sip $otherip #7 | |
0bac7164 | 2352 | done |
269ecccc | 2353 | done |
0bac7164 BP |
2354 | done |
2355 | ||
2356 | # Allow some time for packet forwarding. | |
2357 | # XXX This can be improved. | |
2358 | sleep 1 | |
2359 | ||
2360 | # 8. Generate an ARP reply for each of the IP addresses ARPed for | |
2361 | # earlier as #3. | |
2362 | # | |
2363 | # Here, the $s is the VIF that originated the ARP request and $d is | |
2364 | # the VIF that sends the ARP reply, which is somewhat backward but | |
2365 | # it means that $s and $d are the same as #3. | |
2366 | : > mac_bindings.expected | |
2367 | for is in 1 2 3; do | |
269ecccc JP |
2368 | for js in 1 2 3; do |
2369 | for ks in 1 2 3; do | |
2370 | s=$is$js$ks | |
2371 | for id in 1 2 3; do | |
2372 | for jd in 1 2 3; do | |
2373 | if test $is$js = $id$jd; then | |
2374 | continue | |
2375 | fi | |
2376 | ||
2377 | kd=1 | |
2378 | d=$id$jd$kd | |
2379 | ||
2380 | o4=`expr $is '*' 9 + $js '*' 3 + $ks + 10` | |
2381 | host_ip=`ip_to_hex 192 168 $id$jd $o4` | |
2382 | host_mac=8000000000$o4 | |
2383 | ||
2384 | lrmac=00000000ff$id$jd | |
2385 | lrip=`ip_to_hex 192 168 $id$jd 254` | |
2386 | ||
2387 | arp=${lrmac}${host_mac}08060001080006040002${host_mac}${host_ip}${lrmac}${lrip} | |
2388 | ||
2389 | echo | |
2390 | echo | |
2391 | echo | |
2392 | hv=hv`vif_to_hv $d` | |
2393 | as $hv ovs-appctl netdev-dummy/receive vif$d $arp | |
2394 | #as $hv ovs-appctl ofproto/trace br-int in_port=$d $arp | |
2395 | #as $hv ovs-ofctl dump-flows br-int table=19 | |
2396 | ||
2397 | host_ip_pretty=192.168.$id$jd.$o4 | |
2398 | host_mac_pretty=80:00:00:00:00:$o4 | |
2399 | echo lrp$id$jd,$host_ip_pretty,$host_mac_pretty >> mac_bindings.expected | |
86e98048 | 2400 | done |
269ecccc | 2401 | done |
9975d7be | 2402 | done |
269ecccc | 2403 | done |
9975d7be | 2404 | done |
0bac7164 | 2405 | |
9975d7be BP |
2406 | # Allow some time for packet forwarding. |
2407 | # XXX This can be improved. | |
2408 | sleep 1 | |
2409 | ||
0bac7164 BP |
2410 | # 9. Send an IP packet from every logical port to every other subnet. These |
2411 | # are the same packets already sent as #3, but now the destinations' IP-MAC | |
2412 | # bindings have been discovered via ARP, so instead of provoking an ARP | |
2413 | # request, these packets now get routed to their destinations (which don't | |
2414 | # have static MAC bindings, so they go to the port we've designated as | |
2415 | # accepting "unknown" MACs.) | |
2416 | for is in 1 2 3; do | |
269ecccc JP |
2417 | for js in 1 2 3; do |
2418 | for ks in 1 2 3; do | |
2419 | s=$is$js$ks | |
2420 | smac=f00000000$s | |
2421 | sip=`ip_to_hex 192 168 $is$js $ks` | |
2422 | for id in 1 2 3; do | |
2423 | for jd in 1 2 3; do | |
2424 | if test $is$js = $id$jd; then | |
2425 | continue | |
2426 | fi | |
2427 | ||
2428 | # Send the packet. | |
2429 | dmac=00000000ff$is$js | |
2430 | # Calculate a 4th octet for the destination that is | |
2431 | # unique per $s, avoids the .1 .2 .3 and .254 IP addresses | |
2432 | # that have static MAC bindings, and fits in the range | |
2433 | # 0-255. | |
2434 | o4=`expr $is '*' 9 + $js '*' 3 + $ks + 10` | |
2435 | dip=`ip_to_hex 192 168 $id$jd $o4` | |
2436 | test_ip $s $smac $dmac $sip $dip | |
2437 | ||
2438 | # Expect the packet egress. | |
2439 | host_mac=8000000000$o4 | |
2440 | outport=${id}11 | |
2441 | out_lrp=$id$jd | |
e4543cfe | 2442 | echo ${host_mac}00000000ff${out_lrp}08004500001c00000000"3f1101"00${sip}${dip}0035111100080000 >> $outport.expected |
0bac7164 | 2443 | done |
269ecccc | 2444 | done |
0bac7164 | 2445 | done |
269ecccc | 2446 | done |
0bac7164 BP |
2447 | done |
2448 | ||
0bac7164 BP |
2449 | ovn-sbctl -f csv -d bare --no-heading \ |
2450 | -- --columns=logical_port,ip,mac list mac_binding > mac_bindings | |
2451 | ||
9975d7be BP |
2452 | # Now check the packets actually received against the ones expected. |
2453 | for i in 1 2 3; do | |
2454 | for j in 1 2 3; do | |
86e98048 | 2455 | for k in 1 2 3; do |
abb37b6b FF |
2456 | OVN_CHECK_PACKETS([hv`vif_to_hv $i$j$k`/vif$i$j$k-tx.pcap], |
2457 | [$i$j$k.expected]) | |
86e98048 | 2458 | done |
9975d7be BP |
2459 | done |
2460 | done | |
fcde56f5 | 2461 | |
0bac7164 BP |
2462 | # Check the MAC bindings against those expected. |
2463 | AT_CHECK_UNQUOTED([sort < mac_bindings], [0], [`sort < mac_bindings.expected` | |
2464 | ]) | |
2465 | ||
fcde56f5 | 2466 | # Gracefully terminate daemons |
7a8f15e0 | 2467 | OVN_CLEANUP([hv1], [hv2], [hv3]) |
eff49a56 | 2468 | |
9975d7be | 2469 | AT_CLEANUP |
685f4dfe NS |
2470 | |
2471 | # 3 hypervisors, one logical switch, 3 logical ports per hypervisor | |
2472 | AT_SETUP([ovn -- portsecurity : 3 HVs, 1 LS, 3 lports/HV]) | |
685f4dfe NS |
2473 | AT_SKIP_IF([test $HAVE_PYTHON = no]) |
2474 | ovn_start | |
2475 | ||
2476 | # Create hypervisors hv[123]. | |
2477 | # Add vif1[123] to hv1, vif2[123] to hv2, vif3[123] to hv3. | |
2478 | # Add all of the vifs to a single logical switch lsw0. | |
2479 | # Turn off port security on vifs vif[123]1 | |
2480 | # Turn on l2 port security on vifs vif[123]2 | |
2481 | # Turn of l2 and l3 port security on vifs vif[123]3 | |
2482 | # Make vif13, vif2[23], vif3[123] destinations for unknown MACs. | |
ea46a4e9 | 2483 | ovn-nbctl ls-add lsw0 |
685f4dfe NS |
2484 | net_add n1 |
2485 | for i in 1 2 3; do | |
2486 | sim_add hv$i | |
2487 | as hv$i | |
2488 | ovs-vsctl add-br br-phys | |
2489 | ovn_attach n1 br-phys 192.168.0.$i | |
2490 | ||
2491 | for j in 1 2 3; do | |
2492 | 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 | 2493 | ovn-nbctl lsp-add lsw0 lp$i$j |
685f4dfe | 2494 | if test $j = 1; then |
31ed1192 | 2495 | ovn-nbctl lsp-set-addresses lp$i$j "f0:00:00:00:00:$i$j 192.168.0.$i$j" unknown |
685f4dfe | 2496 | elif test $j = 2; then |
31ed1192 JP |
2497 | ovn-nbctl lsp-set-addresses lp$i$j "f0:00:00:00:00:$i$j 192.168.0.$i$j" |
2498 | ovn-nbctl lsp-set-port-security lp$i$j f0:00:00:00:00:$i$j | |
685f4dfe NS |
2499 | else |
2500 | extra_addr="f0:00:00:00:0$i:$i$j fe80::ea2a:eaff:fe28:$i$j" | |
31ed1192 JP |
2501 | ovn-nbctl lsp-set-addresses lp$i$j "f0:00:00:00:00:$i$j 192.168.0.$i$j" "$extra_addr" |
2502 | 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 |
2503 | fi |
2504 | done | |
2505 | done | |
2506 | ||
685f4dfe NS |
2507 | # Pre-populate the hypervisors' ARP tables so that we don't lose any |
2508 | # packets for ARP resolution (native tunneling doesn't queue packets | |
2509 | # for ARP resolution). | |
2510 | ovn_populate_arp | |
2511 | ||
2512 | # Allow some time for ovn-northd and ovn-controller to catch up. | |
2513 | # XXX This should be more systematic. | |
2514 | sleep 1 | |
685f4dfe NS |
2515 | |
2516 | # Given the name of a logical port, prints the name of the hypervisor | |
2517 | # on which it is located. | |
2518 | vif_to_hv() { | |
2519 | echo hv${1%?} | |
2520 | } | |
2521 | ||
685f4dfe NS |
2522 | for i in 1 2 3; do |
2523 | for j in 1 2 3; do | |
2524 | : > $i$j.expected | |
2525 | done | |
2526 | done | |
2527 | ||
2528 | # test_ip INPORT SRC_MAC DST_MAC SRC_IP DST_IP OUTPORT... | |
2529 | # | |
2530 | # This shell function causes an ip packet to be received on INPORT. | |
2531 | # The packet's content has Ethernet destination DST and source SRC | |
2532 | # (each exactly 12 hex digits) and Ethernet type ETHTYPE (4 hex digits). | |
2533 | # The OUTPORTs (zero or more) list the VIFs on which the packet should | |
31ed1192 JP |
2534 | # be received. INPORT and the OUTPORTs are specified as logical switch |
2535 | # port numbers, e.g. 11 for vif11. | |
685f4dfe NS |
2536 | test_ip() { |
2537 | # This packet has bad checksums but logical L3 routing doesn't check. | |
2538 | local inport=$1 src_mac=$2 dst_mac=$3 src_ip=$4 dst_ip=$5 | |
efe179e0 | 2539 | local packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 |
685f4dfe NS |
2540 | shift; shift; shift; shift; shift |
2541 | hv=`vif_to_hv $inport` | |
2542 | as $hv ovs-appctl netdev-dummy/receive vif$inport $packet | |
2543 | #as $hv ovs-appctl ofproto/trace br-int in_port=$inport $packet | |
2544 | for outport; do | |
e4543cfe | 2545 | echo $packet >> $outport.expected |
685f4dfe NS |
2546 | done |
2547 | } | |
2548 | ||
2549 | # test_arp INPORT SHA SPA TPA DROP [REPLY_HA] | |
2550 | # | |
2551 | # Causes a packet to be received on INPORT. The packet is an ARP | |
2552 | # request with SHA, SPA, and TPA as specified. If REPLY_HA is provided, then | |
2553 | # it should be the hardware address of the target to expect to receive in an | |
2554 | # ARP reply; otherwise no reply is expected. | |
2555 | # | |
31ed1192 | 2556 | # INPORT is an logical switch port number, e.g. 11 for vif11. |
685f4dfe NS |
2557 | # SHA and REPLY_HA are each 12 hex digits. |
2558 | # SPA and TPA are each 8 hex digits. | |
2559 | test_arp() { | |
2560 | local inport=$1 smac=$2 sha=$3 spa=$4 tpa=$5 drop=$6 reply_ha=$7 | |
2561 | local request=ffffffffffff${smac}08060001080006040001${sha}${spa}ffffffffffff${tpa} | |
2562 | hv=`vif_to_hv $inport` | |
2563 | as $hv ovs-appctl netdev-dummy/receive vif$inport $request | |
2564 | #as $hv ovs-appctl ofproto/trace br-int in_port=$inport $request | |
2565 | if test $drop != 1; then | |
e137131a | 2566 | if test X$reply_ha = X; then |
685f4dfe NS |
2567 | # Expect to receive the broadcast ARP on the other logical switch ports |
2568 | # if no reply is expected. | |
2569 | local i j | |
2570 | for i in 1 2 3; do | |
2571 | for j in 1 2 3; do | |
2572 | if test $i$j != $inport; then | |
2573 | echo $request >> $i$j.expected | |
2574 | fi | |
2575 | done | |
2576 | done | |
2577 | else | |
2578 | # Expect to receive the reply, if any. | |
2579 | local reply=${smac}${reply_ha}08060001080006040002${reply_ha}${tpa}${sha}${spa} | |
2580 | echo $reply >> $inport.expected | |
2581 | fi | |
2582 | fi | |
2583 | } | |
2584 | ||
2585 | # test_ipv6 INPORT SRC_MAC DST_MAC SRC_IP DST_IP OUTPORT... | |
2586 | # This function is similar to test_ip() except that it sends | |
2587 | # ipv6 packet | |
2588 | test_ipv6() { | |
2589 | local inport=$1 src_mac=$2 dst_mac=$3 src_ip=$4 dst_ip=$5 | |
2590 | local packet=${dst_mac}${src_mac}86dd6000000000083aff${src_ip}${dst_ip}0000000000000000 | |
2591 | shift; shift; shift; shift; shift | |
2592 | hv=`vif_to_hv $inport` | |
2593 | as $hv ovs-appctl netdev-dummy/receive vif$inport $packet | |
2594 | #as $hv ovs-appctl ofproto/trace br-int in_port=$inport $packet | |
2595 | for outport; do | |
e4543cfe | 2596 | echo $packet >> $outport.expected |
685f4dfe NS |
2597 | done |
2598 | } | |
2599 | ||
9e687b23 DL |
2600 | # test_icmpv6 INPORT SRC_MAC DST_MAC SRC_IP DST_IP ICMP_TYPE OUTPORT... |
2601 | # This function is similar to test_ipv6() except it specifies the ICMPv6 type | |
2602 | # of the test packet | |
2603 | test_icmpv6() { | |
2604 | local inport=$1 src_mac=$2 dst_mac=$3 src_ip=$4 dst_ip=$5 icmp_type=$6 | |
2605 | local packet=${dst_mac}${src_mac}86dd6000000000083aff${src_ip}${dst_ip}${icmp_type}00000000000000 | |
2606 | shift; shift; shift; shift; shift; shift | |
2607 | hv=`vif_to_hv $inport` | |
2608 | as $hv ovs-appctl netdev-dummy/receive vif$inport $packet | |
2609 | #as $hv ovs-appctl ofproto/trace br-int in_port=$inport $packet | |
2610 | for outport; do | |
e4543cfe | 2611 | echo $packet >> $outport.expected |
9e687b23 DL |
2612 | done |
2613 | } | |
2614 | ||
685f4dfe NS |
2615 | ip_to_hex() { |
2616 | printf "%02x%02x%02x%02x" "$@" | |
2617 | } | |
2618 | ||
2619 | # no port security | |
2620 | sip=`ip_to_hex 192 168 0 12` | |
2621 | tip=`ip_to_hex 192 168 0 13` | |
2622 | # the arp packet should be allowed even if lp[123]1 is | |
2623 | # not configured with mac f00000000023 and ip 192.168.0.12 | |
2624 | for i in 1 2 3; do | |
2625 | test_arp ${i}1 f00000000023 f00000000023 $sip $tip 0 f00000000013 | |
2626 | for j in 1 2 3; do | |
2627 | if test $i != $j; then | |
2628 | test_ip ${i}1 f000000000${i}1 f000000000${j}1 $sip $tip ${j}1 | |
2629 | fi | |
2630 | done | |
2631 | done | |
2632 | ||
2633 | # l2 port security | |
2634 | sip=`ip_to_hex 192 168 0 12` | |
2635 | tip=`ip_to_hex 192 168 0 13` | |
2636 | ||
2637 | # arp packet should be allowed since lp22 is configured with | |
2638 | # mac f00000000022 | |
2639 | test_arp 22 f00000000022 f00000000022 $sip $tip 0 f00000000013 | |
2640 | ||
2641 | # arp packet should not be allowed since lp32 is not configured with | |
2642 | # mac f00000000021 | |
2643 | test_arp 32 f00000000021 f00000000021 $sip $tip 1 | |
2644 | ||
2645 | # arp packet with sha set to f00000000021 should not be allowed | |
2646 | # for lp12 | |
2647 | test_arp 12 f00000000012 f00000000021 $sip $tip 1 | |
2648 | ||
2649 | # ip packets should be allowed and received since lp[123]2 do not | |
2650 | # have l3 port security | |
2651 | sip=`ip_to_hex 192 168 0 55` | |
2652 | tip=`ip_to_hex 192 168 0 66` | |
2653 | for i in 1 2 3; do | |
2654 | for j in 1 2 3; do | |
2655 | if test $i != $j; then | |
2656 | test_ip ${i}2 f000000000${i}2 f000000000${j}2 $sip $tip ${j}2 | |
2657 | fi | |
2658 | done | |
2659 | done | |
2660 | ||
2661 | # ipv6 packets should be received by lp[123]2 | |
2662 | # lp[123]1 can send ipv6 traffic as there is no port security | |
2663 | sip=fe800000000000000000000000000000 | |
2664 | tip=ff020000000000000000000000000000 | |
2665 | ||
2666 | for i in 1 2 3; do | |
2667 | test_ipv6 ${i}1 f000000000${i}1 f000000000${i}2 $sip $tip ${i}2 | |
2668 | done | |
2669 | ||
2670 | ||
2671 | # l2 and l3 port security | |
2672 | sip=`ip_to_hex 192 168 0 13` | |
2673 | tip=`ip_to_hex 192 168 0 22` | |
2674 | # arp packet should be allowed since lp13 is configured with | |
2675 | # f00000000013 and 192.168.0.13 | |
2676 | test_arp 13 f00000000013 f00000000013 $sip $tip 0 f00000000022 | |
2677 | ||
2678 | # the arp packet should be dropped because lp23 is not configured | |
2679 | # with mac f00000000022 | |
2680 | sip=`ip_to_hex 192 168 0 13` | |
2681 | tip=`ip_to_hex 192 168 0 22` | |
2682 | test_arp 23 f00000000022 f00000000022 $sip $tip 1 | |
2683 | ||
2684 | # the arp packet should be dropped because lp33 is not configured | |
2685 | # with ip 192.168.0.55 | |
2686 | spa=`ip_to_hex 192 168 0 55` | |
2687 | tpa=`ip_to_hex 192 168 0 22` | |
2688 | test_arp 33 f00000000031 f00000000031 $spa $tpa 1 | |
2689 | ||
2690 | # ip packets should not be received by lp[123]3 since | |
2691 | # l3 port security is enabled | |
2692 | sip=`ip_to_hex 192 168 0 55` | |
2693 | tip=`ip_to_hex 192 168 0 66` | |
2694 | for i in 1 2 3; do | |
2695 | for j in 1 2 3; do | |
2696 | test_ip ${i}2 f000000000${i}2 f000000000${j}3 $sip $tip | |
2697 | done | |
2698 | done | |
2699 | ||
2700 | # ipv6 packets should be dropped for lp[123]3 since | |
2701 | # it is configured with only ipv4 address | |
2702 | sip=fe800000000000000000000000000000 | |
2703 | tip=ff020000000000000000000000000000 | |
2704 | ||
2705 | for i in 1 2 3; do | |
2706 | test_ipv6 ${i}3 f000000000${i}3 f00000000022 $sip $tip | |
2707 | done | |
2708 | ||
2709 | # ipv6 packets should not be received by lp[123]3 with mac f000000000$[123]3 | |
2710 | # lp[123]1 can send ipv6 traffic as there is no port security | |
2711 | for i in 1 2 3; do | |
2712 | test_ipv6 ${i}1 f000000000${i}1 f000000000${i}3 $sip $tip | |
2713 | done | |
2714 | ||
2715 | # lp13 has extra port security with mac f0000000113 and ipv6 addr | |
2716 | # fe80::ea2a:eaff:fe28:0012 | |
2717 | ||
2718 | # ipv4 packet should be dropped for lp13 with mac f0000000113 | |
2719 | sip=`ip_to_hex 192 168 0 13` | |
2720 | tip=`ip_to_hex 192 168 0 23` | |
2721 | test_ip 13 f00000000113 f00000000023 $sip $tip | |
2722 | ||
6d53e8a9 BP |
2723 | # ipv6 packet should be received by lp[123]3 with mac f00000000${i}${i}3 |
2724 | # and ip6.dst as fe80::ea2a:eaff:fe28:0${i}${i}3. | |
685f4dfe NS |
2725 | # lp11 can send ipv6 traffic as there is no port security |
2726 | sip=ee800000000000000000000000000000 | |
2727 | for i in 1 2 3; do | |
6d53e8a9 BP |
2728 | tip=fe80000000000000ea2aeafffe2800${i}3 |
2729 | test_ipv6 11 f00000000011 f00000000${i}${i}3 $sip $tip ${i}3 | |
685f4dfe NS |
2730 | done |
2731 | ||
2732 | ||
2733 | # ipv6 packet should not be received by lp33 with mac f0000000333 | |
2734 | # and ip6.dst as fe80::ea2a:eaff:fe28:0023 as it is | |
2735 | # configured with fe80::ea2a:eaff:fe28:0033 | |
2736 | # lp11 can send ipv6 traffic as there is no port security | |
2737 | ||
2738 | sip=ee800000000000000000000000000000 | |
2739 | tip=fe80000000000000ea2aeafffe280023 | |
2740 | test_ipv6 11 f00000000011 f00000000333 $sip $tip | |
2741 | ||
6d53e8a9 BP |
2742 | # ipv6 packet should be allowed for lp[123]3 with mac f0000000${i}${i}3 |
2743 | # and ip6.src fe80::ea2a:eaff:fe28:0${i}${i}3 and ip6.src ::. | |
685f4dfe NS |
2744 | # and should be dropped for any other ip6.src |
2745 | # lp21 can receive ipv6 traffic as there is no port security | |
2746 | ||
2747 | tip=ee800000000000000000000000000000 | |
2748 | for i in 1 2 3; do | |
2749 | sip=fe80000000000000ea2aeafffe2800${i}3 | |
2750 | test_ipv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip $tip 21 | |
2751 | ||
9e687b23 | 2752 | # Test ICMPv6 MLD reports (v1 and v2) and NS for DAD |
685f4dfe | 2753 | sip=00000000000000000000000000000000 |
9e687b23 DL |
2754 | test_icmpv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip ff020000000000000000000000160000 83 21 |
2755 | test_icmpv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip ff020000000000000000000000160000 8f 21 | |
2756 | test_icmpv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip ff0200000000000000ea2aeafffe2800 87 21 | |
2757 | # Traffic to non-multicast traffic should be dropped | |
2758 | test_icmpv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip $tip 83 | |
2759 | # Traffic of other ICMPv6 types should be dropped | |
2760 | test_icmpv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip ff020000000000000000000000160000 80 | |
685f4dfe NS |
2761 | |
2762 | # should be dropped | |
2763 | sip=ae80000000000000ea2aeafffe2800aa | |
2764 | test_ipv6 ${i}3 f00000000${i}${i}3 f00000000021 $sip $tip | |
2765 | done | |
2766 | ||
31ed1192 JP |
2767 | # configure lsp13 to send and received IPv4 packets with an address range |
2768 | 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 | 2769 | |
8ff5a966 NS |
2770 | sleep 2 |
2771 | ||
7d9d86ad NS |
2772 | sip=`ip_to_hex 10 0 0 13` |
2773 | tip=`ip_to_hex 192 168 0 22` | |
31ed1192 | 2774 | # arp packet with inner ip 10.0.0.13 should be allowed for lsp13 |
7d9d86ad NS |
2775 | test_arp 13 f00000000013 f00000000013 $sip $tip 0 f00000000022 |
2776 | ||
2777 | sip=`ip_to_hex 10 0 0 14` | |
2778 | tip=`ip_to_hex 192 168 0 23` | |
31ed1192 | 2779 | # IPv4 packet from lsp13 with src ip 10.0.0.14 destined to lsp23 |
7d9d86ad NS |
2780 | # with dst ip 192.168.0.23 should be allowed |
2781 | test_ip 13 f00000000013 f00000000023 $sip $tip 23 | |
2782 | ||
2783 | sip=`ip_to_hex 192 168 0 33` | |
2784 | tip=`ip_to_hex 10 0 0 15` | |
31ed1192 JP |
2785 | # IPv4 packet from lsp33 with src ip 192.168.0.33 destined to lsp13 |
2786 | # with dst ip 10.0.0.15 should be received by lsp13 | |
7d9d86ad NS |
2787 | test_ip 33 f00000000033 f00000000013 $sip $tip 13 |
2788 | ||
2789 | sip=`ip_to_hex 192 168 0 33` | |
2790 | tip=`ip_to_hex 20 0 0 4` | |
31ed1192 JP |
2791 | # IPv4 packet from lsp33 with src ip 192.168.0.33 destined to lsp13 |
2792 | # with dst ip 20.0.0.4 should be received by lsp13 | |
7d9d86ad NS |
2793 | test_ip 33 f00000000033 f00000000013 $sip $tip 13 |
2794 | ||
2795 | sip=`ip_to_hex 192 168 0 33` | |
2796 | tip=`ip_to_hex 20 0 0 5` | |
31ed1192 JP |
2797 | # IPv4 packet from lsp33 with src ip 192.168.0.33 destined to lsp13 |
2798 | # with dst ip 20.0.0.5 should not be received by lsp13 | |
7d9d86ad NS |
2799 | test_ip 33 f00000000033 f00000000013 $sip $tip |
2800 | ||
2801 | sip=`ip_to_hex 192 168 0 33` | |
2802 | tip=`ip_to_hex 20 0 0 255` | |
31ed1192 JP |
2803 | # IPv4 packet from lsp33 with src ip 192.168.0.33 destined to lsp13 |
2804 | # with dst ip 20.0.0.255 should be received by lsp13 | |
7d9d86ad NS |
2805 | test_ip 33 f00000000033 f00000000013 $sip $tip 13 |
2806 | ||
2807 | sip=`ip_to_hex 192 168 0 33` | |
2808 | tip=`ip_to_hex 192 168 0 255` | |
31ed1192 JP |
2809 | # IPv4 packet from lsp33 with src ip 192.168.0.33 destined to lsp13 |
2810 | # with dst ip 192.168.0.255 should not be received by lsp13 | |
7d9d86ad NS |
2811 | test_ip 33 f00000000033 f00000000013 $sip $tip |
2812 | ||
2813 | sip=`ip_to_hex 192 168 0 33` | |
2814 | tip=`ip_to_hex 224 0 0 4` | |
31ed1192 JP |
2815 | # IPv4 packet from lsp33 with src ip 192.168.0.33 destined to lsp13 |
2816 | # with dst ip 224.0.0.4 should be received by lsp13 | |
7d9d86ad | 2817 | test_ip 33 f00000000033 f00000000013 $sip $tip 13 |
685f4dfe | 2818 | |
bb0c41d3 RM |
2819 | #dump information including flow counters |
2820 | ovn-nbctl show | |
2821 | ovn-sbctl dump-flows -- list multicast_group | |
2822 | ||
2823 | echo "------ hv1 dump ------" | |
2824 | as hv1 ovs-vsctl show | |
6195e2e7 | 2825 | as hv1 ovs-ofctl -O OpenFlow13 show br-int |
bb0c41d3 RM |
2826 | as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-int |
2827 | ||
2828 | echo "------ hv2 dump ------" | |
2829 | as hv2 ovs-vsctl show | |
6195e2e7 | 2830 | as hv2 ovs-ofctl -O OpenFlow13 show br-int |
bb0c41d3 RM |
2831 | as hv2 ovs-ofctl -O OpenFlow13 dump-flows br-int |
2832 | ||
2833 | echo "------ hv3 dump ------" | |
2834 | as hv3 ovs-vsctl show | |
6195e2e7 | 2835 | as hv3 ovs-ofctl -O OpenFlow13 show br-int |
bb0c41d3 RM |
2836 | as hv3 ovs-ofctl -O OpenFlow13 dump-flows br-int |
2837 | ||
685f4dfe NS |
2838 | # Now check the packets actually received against the ones expected. |
2839 | for i in 1 2 3; do | |
2840 | for j in 1 2 3; do | |
49d7c759 | 2841 | OVN_CHECK_PACKETS([hv$i/vif$i$j-tx.pcap], [$i$j.expected]) |
685f4dfe NS |
2842 | done |
2843 | done | |
2844 | ||
7a8f15e0 | 2845 | OVN_CLEANUP([hv1],[hv2],[hv3]) |
d9c8c57c | 2846 | |
685f4dfe | 2847 | AT_CLEANUP |
509afdc3 GS |
2848 | |
2849 | AT_SETUP([ovn -- 2 HVs, 2 LS, 1 lport/LS, 2 peer LRs]) | |
509afdc3 GS |
2850 | AT_SKIP_IF([test $HAVE_PYTHON = no]) |
2851 | ovn_start | |
2852 | ||
2853 | # Logical network: | |
2854 | # Two LRs - R1 and R2 that are connected to each other as peers in 20.0.0.0/24 | |
2855 | # network. R1 has a switchs ls1 (191.168.1.0/24) connected to it. | |
2856 | # R2 has ls2 (172.16.1.0/24) connected to it. | |
2857 | ||
fa2a27b2 JP |
2858 | ovn-nbctl lr-add R1 |
2859 | ovn-nbctl lr-add R2 | |
509afdc3 | 2860 | |
ea46a4e9 JP |
2861 | ovn-nbctl ls-add ls1 |
2862 | ovn-nbctl ls-add ls2 | |
509afdc3 GS |
2863 | |
2864 | # Connect ls1 to R1 | |
bf44c2cd | 2865 | ovn-nbctl lrp-add R1 ls1 00:00:00:01:02:03 192.168.1.1/24 |
509afdc3 | 2866 | |
31ed1192 | 2867 | ovn-nbctl lsp-add ls1 rp-ls1 -- set Logical_Switch_Port rp-ls1 type=router \ |
31114af7 | 2868 | options:router-port=ls1 addresses=\"00:00:00:01:02:03\" |
509afdc3 GS |
2869 | |
2870 | # Connect ls2 to R2 | |
bf44c2cd | 2871 | ovn-nbctl lrp-add R2 ls2 00:00:00:01:02:04 172.16.1.1/24 |
509afdc3 | 2872 | |
31ed1192 | 2873 | ovn-nbctl lsp-add ls2 rp-ls2 -- set Logical_Switch_Port rp-ls2 type=router \ |
31114af7 | 2874 | options:router-port=ls2 addresses=\"00:00:00:01:02:04\" |
509afdc3 GS |
2875 | |
2876 | # Connect R1 to R2 | |
4685e523 JP |
2877 | ovn-nbctl lrp-add R1 R1_R2 00:00:00:02:03:04 20.0.0.1/24 peer=R2_R1 |
2878 | ovn-nbctl lrp-add R2 R2_R1 00:00:00:02:03:05 20.0.0.2/24 peer=R1_R2 | |
509afdc3 | 2879 | |
6d9ecfa9 JP |
2880 | ovn-nbctl lr-route-add R1 "0.0.0.0/0" 20.0.0.2 |
2881 | ovn-nbctl lr-route-add R2 "0.0.0.0/0" 20.0.0.1 | |
509afdc3 GS |
2882 | |
2883 | # Create logical port ls1-lp1 in ls1 | |
31ed1192 JP |
2884 | ovn-nbctl lsp-add ls1 ls1-lp1 \ |
2885 | -- lsp-set-addresses ls1-lp1 "f0:00:00:01:02:03 192.168.1.2" | |
509afdc3 GS |
2886 | |
2887 | # Create logical port ls2-lp1 in ls2 | |
31ed1192 JP |
2888 | ovn-nbctl lsp-add ls2 ls2-lp1 \ |
2889 | -- lsp-set-addresses ls2-lp1 "f0:00:00:01:02:04 172.16.1.2" | |
509afdc3 GS |
2890 | |
2891 | # Create two hypervisor and create OVS ports corresponding to logical ports. | |
2892 | net_add n1 | |
2893 | ||
2894 | sim_add hv1 | |
2895 | as hv1 | |
2896 | ovs-vsctl add-br br-phys | |
2897 | ovn_attach n1 br-phys 192.168.0.1 | |
2898 | ovs-vsctl -- add-port br-int hv1-vif1 -- \ | |
2899 | set interface hv1-vif1 external-ids:iface-id=ls1-lp1 \ | |
2900 | options:tx_pcap=hv1/vif1-tx.pcap \ | |
2901 | options:rxq_pcap=hv1/vif1-rx.pcap \ | |
2902 | ofport-request=1 | |
2903 | ||
2904 | sim_add hv2 | |
2905 | as hv2 | |
2906 | ovs-vsctl add-br br-phys | |
2907 | ovn_attach n1 br-phys 192.168.0.2 | |
2908 | ovs-vsctl -- add-port br-int hv2-vif1 -- \ | |
2909 | set interface hv2-vif1 external-ids:iface-id=ls2-lp1 \ | |
2910 | options:tx_pcap=hv2/vif1-tx.pcap \ | |
2911 | options:rxq_pcap=hv2/vif1-rx.pcap \ | |
2912 | ofport-request=1 | |
2913 | ||
2914 | ||
2915 | # Pre-populate the hypervisors' ARP tables so that we don't lose any | |
2916 | # packets for ARP resolution (native tunneling doesn't queue packets | |
2917 | # for ARP resolution). | |
2918 | ovn_populate_arp | |
2919 | ||
2920 | # Allow some time for ovn-northd and ovn-controller to catch up. | |
2921 | # XXX This should be more systematic. | |
2922 | sleep 1 | |
2923 | ||
2924 | # Send ip packets between the two ports. | |
2925 | ip_to_hex() { | |
2926 | printf "%02x%02x%02x%02x" "$@" | |
2927 | } | |
509afdc3 GS |
2928 | |
2929 | # Packet to send. | |
2930 | src_mac="f00000010203" | |
2931 | dst_mac="000000010203" | |
2932 | src_ip=`ip_to_hex 192 168 1 2` | |
2933 | dst_ip=`ip_to_hex 172 16 1 2` | |
2934 | packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
2935 | as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet | |
2936 | ||
2937 | ||
2938 | echo "---------NB dump-----" | |
2939 | ovn-nbctl show | |
2940 | echo "---------------------" | |
2941 | ovn-nbctl list logical_router | |
2942 | echo "---------------------" | |
2943 | ovn-nbctl list logical_router_port | |
2944 | echo "---------------------" | |
2945 | ||
2946 | echo "---------SB dump-----" | |
2947 | ovn-sbctl list datapath_binding | |
2948 | echo "---------------------" | |
2949 | ovn-sbctl list port_binding | |
2950 | echo "---------------------" | |
2951 | ||
2952 | echo "------ hv1 dump ----------" | |
8dab1022 | 2953 | as hv1 ovs-ofctl show br-int |
509afdc3 GS |
2954 | as hv1 ovs-ofctl dump-flows br-int |
2955 | echo "------ hv2 dump ----------" | |
8dab1022 | 2956 | as hv2 ovs-ofctl show br-int |
509afdc3 GS |
2957 | as hv2 ovs-ofctl dump-flows br-int |
2958 | ||
2959 | # Packet to Expect | |
2960 | src_mac="000000010204" | |
2961 | dst_mac="f00000010204" | |
49d7c759 | 2962 | echo "${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000" > expected |
509afdc3 | 2963 | |
49d7c759 | 2964 | OVN_CHECK_PACKETS([hv2/vif1-tx.pcap], [expected]) |
509afdc3 | 2965 | |
7a8f15e0 | 2966 | OVN_CLEANUP([hv1],[hv2]) |
509afdc3 GS |
2967 | |
2968 | AT_CLEANUP | |
5412db30 J |
2969 | |
2970 | ||
4685e523 JP |
2971 | AT_SETUP([ovn -- 1 HV, 1 LS, 2 lport/LS, 1 LR]) |
2972 | AT_KEYWORDS([router-admin-state]) | |
2973 | AT_SKIP_IF([test $HAVE_PYTHON = no]) | |
2974 | ovn_start | |
2975 | ||
2976 | # Logical network: | |
2977 | # One LR - R1 has switch ls1 with two subnets attached to it (191.168.1.0/24 | |
2978 | # and 172.16.1.0/24) connected to it. | |
2979 | ||
2980 | ovn-nbctl lr-add R1 | |
2981 | ||
2982 | ovn-nbctl ls-add ls1 | |
2983 | ||
2984 | # Connect ls1 to R1 | |
bf44c2cd | 2985 | ovn-nbctl lrp-add R1 ls1 00:00:00:01:02:03 192.168.1.1/24 172.16.1.1/24 |
4685e523 JP |
2986 | ovn-nbctl lsp-add ls1 rp-ls1 -- set Logical_Switch_Port rp-ls1 type=router \ |
2987 | options:router-port=ls1 addresses=\"00:00:00:01:02:03\" | |
2988 | ||
2989 | # Create logical port ls1-lp1 in ls1 | |
2990 | ovn-nbctl lsp-add ls1 ls1-lp1 \ | |
2991 | -- lsp-set-addresses ls1-lp1 "f0:00:00:01:02:03 192.168.1.2" | |
2992 | ||
2993 | # Create logical port ls1-lp2 in ls1 | |
2994 | ovn-nbctl lsp-add ls1 ls1-lp2 \ | |
2995 | -- lsp-set-addresses ls1-lp2 "f0:00:00:01:02:04 172.16.1.2" | |
2996 | ||
2997 | # Create one hypervisor and create OVS ports corresponding to logical ports. | |
2998 | net_add n1 | |
2999 | ||
3000 | sim_add hv1 | |
3001 | as hv1 | |
3002 | ovs-vsctl add-br br-phys | |
3003 | ovn_attach n1 br-phys 192.168.0.1 | |
3004 | ovs-vsctl -- add-port br-int vif1 -- \ | |
3005 | set interface vif1 external-ids:iface-id=ls1-lp1 \ | |
3006 | options:tx_pcap=hv1/vif1-tx.pcap \ | |
3007 | options:rxq_pcap=hv1/vif1-rx.pcap \ | |
3008 | ofport-request=1 | |
3009 | ||
3010 | ovs-vsctl -- add-port br-int vif2 -- \ | |
3011 | set interface vif2 external-ids:iface-id=ls1-lp2 \ | |
3012 | options:tx_pcap=hv1/vif2-tx.pcap \ | |
3013 | options:rxq_pcap=hv1/vif2-rx.pcap \ | |
3014 | ofport-request=1 | |
3015 | ||
3016 | ||
3017 | # Allow some time for ovn-northd and ovn-controller to catch up. | |
3018 | # XXX This should be more systematic. | |
3019 | sleep 1 | |
3020 | ||
3021 | # Send ip packets between the two ports. | |
3022 | ip_to_hex() { | |
3023 | printf "%02x%02x%02x%02x" "$@" | |
3024 | } | |
4685e523 JP |
3025 | |
3026 | # Packet to send. | |
3027 | src_mac="f00000010203" | |
3028 | dst_mac="000000010203" | |
3029 | src_ip=`ip_to_hex 192 168 1 2` | |
3030 | dst_ip=`ip_to_hex 172 16 1 2` | |
3031 | packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
3032 | as hv1 ovs-appctl netdev-dummy/receive vif1 $packet | |
3033 | ||
3034 | ||
3035 | echo "---------NB dump-----" | |
3036 | ovn-nbctl show | |
3037 | echo "---------------------" | |
3038 | ovn-nbctl list logical_router | |
3039 | echo "---------------------" | |
3040 | ovn-nbctl list logical_router_port | |
3041 | echo "---------------------" | |
3042 | ||
3043 | echo "---------SB dump-----" | |
3044 | ovn-sbctl list datapath_binding | |
3045 | echo "---------------------" | |
3046 | ovn-sbctl list logical_flow | |
3047 | echo "---------------------" | |
3048 | ||
3049 | echo "------ hv1 dump ----------" | |
3050 | as hv1 ovs-ofctl dump-flows br-int | |
3051 | ||
3052 | ||
3053 | #Disable router R1 | |
3054 | ovn-nbctl set Logical_Router R1 enabled=false | |
3055 | ||
3b8cd0ea BP |
3056 | # Allow some time for ovn-northd and ovn-controller to catch up. |
3057 | # XXX This should be more systematic. | |
3058 | sleep 1 | |
3059 | ||
4685e523 JP |
3060 | echo "---------SB dump-----" |
3061 | ovn-sbctl list datapath_binding | |
3062 | echo "---------------------" | |
3063 | ovn-sbctl list logical_flow | |
3064 | echo "---------------------" | |
3065 | ||
3066 | echo "------ hv1 dump ----------" | |
3067 | as hv1 ovs-ofctl dump-flows br-int | |
3068 | ||
3069 | as hv1 ovs-appctl netdev-dummy/receive vif1 $packet | |
3070 | ||
3071 | # Packet to Expect | |
3072 | expect_src_mac="000000010203" | |
3073 | expect_dst_mac="f00000010204" | |
49d7c759 | 3074 | echo "${expect_dst_mac}${expect_src_mac}08004500001c000000003f110100${src_ip}${dst_ip}0035111100080000" > expected |
4685e523 | 3075 | |
49d7c759 | 3076 | OVN_CHECK_PACKETS([hv1/vif2-tx.pcap], [expected]) |
4685e523 JP |
3077 | |
3078 | ||
3079 | as hv1 | |
3080 | OVS_APP_EXIT_AND_WAIT([ovn-controller]) | |
3081 | OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) | |
3082 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
3083 | ||
3084 | as ovn-sb | |
3085 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
3086 | ||
3087 | as ovn-nb | |
3088 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
3089 | ||
3090 | as northd | |
3091 | OVS_APP_EXIT_AND_WAIT([ovn-northd]) | |
3092 | ||
3093 | as main | |
3094 | OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) | |
3095 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
3096 | ||
3097 | AT_CLEANUP | |
3098 | ||
3099 | ||
3100 | AT_SETUP([ovn -- 1 HV, 2 LSs, 1 lport/LS, 1 LR]) | |
5412db30 J |
3101 | AT_KEYWORDS([router-admin-state]) |
3102 | AT_SKIP_IF([test $HAVE_PYTHON = no]) | |
3103 | ovn_start | |
3104 | ||
3105 | # Logical network: | |
3106 | # One LR - R1 has switch ls1 (191.168.1.0/24) connected to it, | |
3107 | # and has switch ls2 (172.16.1.0/24) connected to it. | |
3108 | ||
fa2a27b2 | 3109 | ovn-nbctl lr-add R1 |
5412db30 | 3110 | |
ea46a4e9 JP |
3111 | ovn-nbctl ls-add ls1 |
3112 | ovn-nbctl ls-add ls2 | |
5412db30 J |
3113 | |
3114 | # Connect ls1 to R1 | |
bf44c2cd | 3115 | ovn-nbctl lrp-add R1 ls1 00:00:00:01:02:03 192.168.1.1/24 |
31ed1192 | 3116 | ovn-nbctl lsp-add ls1 rp-ls1 -- set Logical_Switch_Port rp-ls1 type=router \ |
31114af7 | 3117 | options:router-port=ls1 addresses=\"00:00:00:01:02:03\" |
5412db30 J |
3118 | |
3119 | # Connect ls2 to R1 | |
bf44c2cd | 3120 | ovn-nbctl lrp-add R1 ls2 00:00:00:01:02:04 172.16.1.1/24 |
31ed1192 | 3121 | ovn-nbctl lsp-add ls2 rp-ls2 -- set Logical_Switch_Port rp-ls2 type=router \ |
31114af7 | 3122 | options:router-port=ls2 addresses=\"00:00:00:01:02:04\" |
5412db30 J |
3123 | |
3124 | # Create logical port ls1-lp1 in ls1 | |
31ed1192 JP |
3125 | ovn-nbctl lsp-add ls1 ls1-lp1 \ |
3126 | -- lsp-set-addresses ls1-lp1 "f0:00:00:01:02:03 192.168.1.2" | |
5412db30 J |
3127 | |
3128 | # Create logical port ls2-lp1 in ls2 | |
31ed1192 JP |
3129 | ovn-nbctl lsp-add ls2 ls2-lp1 \ |
3130 | -- lsp-set-addresses ls2-lp1 "f0:00:00:01:02:04 172.16.1.2" | |
5412db30 J |
3131 | |
3132 | # Create one hypervisor and create OVS ports corresponding to logical ports. | |
3133 | net_add n1 | |
3134 | ||
3135 | sim_add hv1 | |
3136 | as hv1 | |
3137 | ovs-vsctl add-br br-phys | |
3138 | ovn_attach n1 br-phys 192.168.0.1 | |
3139 | ovs-vsctl -- add-port br-int vif1 -- \ | |
3140 | set interface vif1 external-ids:iface-id=ls1-lp1 \ | |
3141 | options:tx_pcap=hv1/vif1-tx.pcap \ | |
3142 | options:rxq_pcap=hv1/vif1-rx.pcap \ | |
3143 | ofport-request=1 | |
3144 | ||
3145 | ovs-vsctl -- add-port br-int vif2 -- \ | |
3146 | set interface vif2 external-ids:iface-id=ls2-lp1 \ | |
3147 | options:tx_pcap=hv1/vif2-tx.pcap \ | |
3148 | options:rxq_pcap=hv1/vif2-rx.pcap \ | |
3149 | ofport-request=1 | |
3150 | ||
3151 | ||
3152 | # Allow some time for ovn-northd and ovn-controller to catch up. | |
3153 | # XXX This should be more systematic. | |
3154 | sleep 1 | |
3155 | ||
3156 | # Send ip packets between the two ports. | |
3157 | ip_to_hex() { | |
3158 | printf "%02x%02x%02x%02x" "$@" | |
3159 | } | |
5412db30 J |
3160 | |
3161 | # Packet to send. | |
3162 | src_mac="f00000010203" | |
3163 | dst_mac="000000010203" | |
3164 | src_ip=`ip_to_hex 192 168 1 2` | |
3165 | dst_ip=`ip_to_hex 172 16 1 2` | |
3166 | packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
3167 | as hv1 ovs-appctl netdev-dummy/receive vif1 $packet | |
3168 | ||
3169 | ||
3170 | echo "---------NB dump-----" | |
3171 | ovn-nbctl show | |
3172 | echo "---------------------" | |
3173 | ovn-nbctl list logical_router | |
3174 | echo "---------------------" | |
3175 | ovn-nbctl list logical_router_port | |
3176 | echo "---------------------" | |
3177 | ||
3178 | echo "---------SB dump-----" | |
3179 | ovn-sbctl list datapath_binding | |
3180 | echo "---------------------" | |
3181 | ovn-sbctl list logical_flow | |
3182 | echo "---------------------" | |
3183 | ||
3184 | echo "------ hv1 dump ----------" | |
3185 | as hv1 ovs-ofctl dump-flows br-int | |
3186 | ||
5412db30 J |
3187 | #Disable router R1 |
3188 | ovn-nbctl set Logical_Router R1 enabled=false | |
3189 | ||
3190 | echo "---------SB dump-----" | |
3191 | ovn-sbctl list datapath_binding | |
3192 | echo "---------------------" | |
3193 | ovn-sbctl list logical_flow | |
3194 | echo "---------------------" | |
3195 | ||
3196 | echo "------ hv1 dump ----------" | |
3197 | as hv1 ovs-ofctl dump-flows br-int | |
3198 | ||
a1361a6e LR |
3199 | # Allow some time for the disabling of logical router R1 to propagate. |
3200 | # XXX This should be more systematic. | |
3201 | sleep 1 | |
3202 | ||
5412db30 J |
3203 | as hv1 ovs-appctl netdev-dummy/receive vif1 $packet |
3204 | ||
3205 | # Packet to Expect | |
3206 | expect_src_mac="000000010204" | |
3207 | expect_dst_mac="f00000010204" | |
49d7c759 | 3208 | echo "${expect_dst_mac}${expect_src_mac}08004500001c000000003f110100${src_ip}${dst_ip}0035111100080000" > expected |
5412db30 | 3209 | |
49d7c759 | 3210 | OVN_CHECK_PACKETS([hv1/vif2-tx.pcap], [expected]) |
5412db30 | 3211 | |
7a8f15e0 | 3212 | OVN_CLEANUP([hv1]) |
5412db30 J |
3213 | |
3214 | AT_CLEANUP | |
3215 | ||
28dc3fe9 | 3216 | AT_SETUP([ovn -- 2 HVs, 3 LS, 1 lport/LS, 2 peer LRs, static routes]) |
28dc3fe9 SR |
3217 | AT_SKIP_IF([test $HAVE_PYTHON = no]) |
3218 | ovn_start | |
3219 | ||
3220 | # Logical network: | |
3221 | # Two LRs - R1 and R2 that are connected to each other as peers in 20.0.0.0/24 | |
3222 | # network. R1 has switchess foo (192.168.1.0/24) | |
3223 | # connected to it. | |
3224 | # R2 has alice (172.16.1.0/24) and bob (172.16.2.0/24) connected to it. | |
3225 | ||
fa2a27b2 JP |
3226 | ovn-nbctl lr-add R1 |
3227 | ovn-nbctl lr-add R2 | |
28dc3fe9 | 3228 | |
ea46a4e9 JP |
3229 | ovn-nbctl ls-add foo |
3230 | ovn-nbctl ls-add alice | |
3231 | ovn-nbctl ls-add bob | |
28dc3fe9 SR |
3232 | |
3233 | # Connect foo to R1 | |
bf44c2cd | 3234 | ovn-nbctl lrp-add R1 foo 00:00:00:01:02:03 192.168.1.1/24 |
31ed1192 | 3235 | ovn-nbctl lsp-add foo rp-foo -- set Logical_Switch_Port rp-foo type=router \ |
31114af7 | 3236 | options:router-port=foo addresses=\"00:00:00:01:02:03\" |
28dc3fe9 SR |
3237 | |
3238 | # Connect alice to R2 | |
bf44c2cd | 3239 | ovn-nbctl lrp-add R2 alice 00:00:00:01:02:04 172.16.1.1/24 |
31ed1192 | 3240 | ovn-nbctl lsp-add alice rp-alice -- set Logical_Switch_Port rp-alice \ |
80f408f4 | 3241 | type=router options:router-port=alice addresses=\"00:00:00:01:02:04\" |
28dc3fe9 SR |
3242 | |
3243 | # Connect bob to R2 | |
bf44c2cd | 3244 | ovn-nbctl lrp-add R2 bob 00:00:00:01:02:05 172.16.2.1/24 |
31ed1192 | 3245 | ovn-nbctl lsp-add bob rp-bob -- set Logical_Switch_Port rp-bob type=router \ |
31114af7 | 3246 | options:router-port=bob addresses=\"00:00:00:01:02:05\" |
28dc3fe9 SR |
3247 | |
3248 | # Connect R1 to R2 | |
4685e523 JP |
3249 | ovn-nbctl lrp-add R1 R1_R2 00:00:00:02:03:04 20.0.0.1/24 peer=R2_R1 |
3250 | ovn-nbctl lrp-add R2 R2_R1 00:00:00:02:03:05 20.0.0.2/24 peer=R1_R2 | |
28dc3fe9 SR |
3251 | |
3252 | #install static routes | |
e48ccf3c JP |
3253 | ovn-nbctl lr-route-add R1 172.16.1.0/24 20.0.0.2 |
3254 | ovn-nbctl lr-route-add R2 172.16.2.0/24 20.0.0.2 R1_R2 | |
3255 | ovn-nbctl lr-route-add R2 192.168.1.0/24 20.0.0.1 | |
28dc3fe9 SR |
3256 | |
3257 | # Create logical port foo1 in foo | |
31ed1192 JP |
3258 | ovn-nbctl lsp-add foo foo1 \ |
3259 | -- lsp-set-addresses foo1 "f0:00:00:01:02:03 192.168.1.2" | |
28dc3fe9 SR |
3260 | |
3261 | # Create logical port alice1 in alice | |
31ed1192 JP |
3262 | ovn-nbctl lsp-add alice alice1 \ |
3263 | -- lsp-set-addresses alice1 "f0:00:00:01:02:04 172.16.1.2" | |
28dc3fe9 SR |
3264 | |
3265 | # Create logical port bob1 in bob | |
31ed1192 JP |
3266 | ovn-nbctl lsp-add bob bob1 \ |
3267 | -- lsp-set-addresses bob1 "f0:00:00:01:02:05 172.16.2.2" | |
28dc3fe9 SR |
3268 | |
3269 | # Create two hypervisor and create OVS ports corresponding to logical ports. | |
3270 | net_add n1 | |
3271 | ||
3272 | sim_add hv1 | |
3273 | as hv1 | |
3274 | ovs-vsctl add-br br-phys | |
3275 | ovn_attach n1 br-phys 192.168.0.1 | |
3276 | ovs-vsctl -- add-port br-int hv1-vif1 -- \ | |
3277 | set interface hv1-vif1 external-ids:iface-id=foo1 \ | |
3278 | options:tx_pcap=hv1/vif1-tx.pcap \ | |
3279 | options:rxq_pcap=hv1/vif1-rx.pcap \ | |
3280 | ofport-request=1 | |
3281 | ||
3282 | ovs-vsctl -- add-port br-int hv1-vif2 -- \ | |
3283 | set interface hv1-vif2 external-ids:iface-id=alice1 \ | |
3284 | options:tx_pcap=hv1/vif2-tx.pcap \ | |
3285 | options:rxq_pcap=hv1/vif2-rx.pcap \ | |
3286 | ofport-request=2 | |
3287 | ||
3288 | sim_add hv2 | |
3289 | as hv2 | |
3290 | ovs-vsctl add-br br-phys | |
3291 | ovn_attach n1 br-phys 192.168.0.2 | |
3292 | ovs-vsctl -- add-port br-int hv2-vif1 -- \ | |
3293 | set interface hv2-vif1 external-ids:iface-id=bob1 \ | |
3294 | options:tx_pcap=hv2/vif1-tx.pcap \ | |
3295 | options:rxq_pcap=hv2/vif1-rx.pcap \ | |
3296 | ofport-request=1 | |
3297 | ||
3298 | ||
3299 | # Pre-populate the hypervisors' ARP tables so that we don't lose any | |
3300 | # packets for ARP resolution (native tunneling doesn't queue packets | |
3301 | # for ARP resolution). | |
3302 | ovn_populate_arp | |
3303 | ||
3304 | # Allow some time for ovn-northd and ovn-controller to catch up. | |
3305 | # XXX This should be more systematic. | |
3306 | sleep 1 | |
3307 | ||
3308 | ip_to_hex() { | |
3309 | printf "%02x%02x%02x%02x" "$@" | |
3310 | } | |
28dc3fe9 SR |
3311 | |
3312 | # Send ip packets between foo1 and alice1 | |
3313 | src_mac="f00000010203" | |
3314 | dst_mac="000000010203" | |
3315 | src_ip=`ip_to_hex 192 168 1 2` | |
3316 | dst_ip=`ip_to_hex 172 16 1 2` | |
3317 | packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
3318 | as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet | |
3319 | ||
3320 | # Send ip packets between foo1 and bob1 | |
3321 | src_mac="f00000010203" | |
3322 | dst_mac="000000010203" | |
3323 | src_ip=`ip_to_hex 192 168 1 2` | |
3324 | dst_ip=`ip_to_hex 172 16 2 2` | |
3325 | packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
3326 | as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet | |
3327 | ||
3328 | echo "---------NB dump-----" | |
3329 | ovn-nbctl show | |
3330 | echo "---------------------" | |
3331 | ovn-nbctl list logical_router | |
3332 | echo "---------------------" | |
3333 | ovn-nbctl list logical_router_port | |
3334 | echo "---------------------" | |
3335 | ||
3336 | echo "---------SB dump-----" | |
3337 | ovn-sbctl list datapath_binding | |
3338 | echo "---------------------" | |
3339 | ovn-sbctl list port_binding | |
3340 | echo "---------------------" | |
3341 | ||
3342 | echo "------ hv1 dump ----------" | |
3343 | as hv1 ovs-ofctl dump-flows br-int | |
3344 | echo "------ hv2 dump ----------" | |
3345 | as hv2 ovs-ofctl dump-flows br-int | |
3346 | ||
3347 | # Packet to Expect at bob1 | |
3348 | src_mac="000000010205" | |
3349 | dst_mac="f00000010205" | |
3350 | src_ip=`ip_to_hex 192 168 1 2` | |
3351 | dst_ip=`ip_to_hex 172 16 2 2` | |
49d7c759 | 3352 | echo "${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000" > expected |
28dc3fe9 | 3353 | |
49d7c759 | 3354 | OVN_CHECK_PACKETS([hv2/vif1-tx.pcap], [expected]) |
28dc3fe9 SR |
3355 | |
3356 | # Packet to Expect at alice1 | |
3357 | src_mac="000000010204" | |
3358 | dst_mac="f00000010204" | |
3359 | src_ip=`ip_to_hex 192 168 1 2` | |
3360 | dst_ip=`ip_to_hex 172 16 1 2` | |
49d7c759 | 3361 | echo "${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000" > expected |
28dc3fe9 | 3362 | |
49d7c759 | 3363 | OVN_CHECK_PACKETS([hv1/vif2-tx.pcap], [expected]) |
28dc3fe9 | 3364 | |
7a8f15e0 | 3365 | OVN_CLEANUP([hv1],[hv2]) |
28dc3fe9 SR |
3366 | |
3367 | AT_CLEANUP | |
5412db30 | 3368 | |
0ee8aaf6 | 3369 | AT_SETUP([ovn -- send gratuitous arp on localnet]) |
d08dbed7 | 3370 | AT_SKIP_IF([test $HAVE_PYTHON = no]) |
0ee8aaf6 | 3371 | ovn_start |
ea46a4e9 | 3372 | ovn-nbctl ls-add lsw0 |
0ee8aaf6 RR |
3373 | net_add n1 |
3374 | sim_add hv | |
3375 | as hv | |
3376 | ovs-vsctl \ | |
3377 | -- add-br br-phys \ | |
3378 | -- add-br br-eth0 | |
3379 | ||
3380 | ovn_attach n1 br-phys 192.168.0.1 | |
3381 | ||
3382 | AT_CHECK([ovs-vsctl set Open_vSwitch . external-ids:ovn-bridge-mappings=physnet1:br-eth0]) | |
3383 | 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]) | |
3384 | ||
3385 | # Create a vif. | |
31ed1192 JP |
3386 | AT_CHECK([ovn-nbctl lsp-add lsw0 localvif1]) |
3387 | AT_CHECK([ovn-nbctl lsp-set-addresses localvif1 "f0:00:00:00:00:01 192.168.1.2"]) | |
3388 | AT_CHECK([ovn-nbctl lsp-set-port-security localvif1 "f0:00:00:00:00:01"]) | |
0ee8aaf6 RR |
3389 | |
3390 | # Create a localnet port. | |
31ed1192 JP |
3391 | AT_CHECK([ovn-nbctl lsp-add lsw0 ln_port]) |
3392 | AT_CHECK([ovn-nbctl lsp-set-addresses ln_port unknown]) | |
3393 | AT_CHECK([ovn-nbctl lsp-set-type ln_port localnet]) | |
3394 | AT_CHECK([ovn-nbctl lsp-set-options ln_port network_name=physnet1]) | |
0ee8aaf6 RR |
3395 | |
3396 | AT_CHECK([ovs-vsctl add-port br-int localvif1 -- set Interface localvif1 external_ids:iface-id=localvif1]) | |
3397 | ||
3398 | # Wait for packet to be received. | |
49d7c759 BP |
3399 | echo "fffffffffffff0000000000108060001080006040001f00000000001c0a80102000000000000c0a80102" > expected |
3400 | OVN_CHECK_PACKETS([hv/snoopvif-tx.pcap], [expected]) | |
0ee8aaf6 RR |
3401 | |
3402 | # Delete the localnet ports. | |
3403 | AT_CHECK([ovs-vsctl del-port localvif1]) | |
31ed1192 | 3404 | AT_CHECK([ovn-nbctl lsp-del ln_port]) |
0ee8aaf6 | 3405 | |
7a8f15e0 | 3406 | OVN_CLEANUP([hv]) |
0ee8aaf6 RR |
3407 | |
3408 | AT_CLEANUP | |
75cf9d2b GS |
3409 | |
3410 | AT_SETUP([ovn -- 2 HVs, 3 LRs connected via LS, static routes]) | |
75cf9d2b GS |
3411 | AT_SKIP_IF([test $HAVE_PYTHON = no]) |
3412 | ovn_start | |
3413 | ||
3414 | # Logical network: | |
3415 | # Three LRs - R1, R2 and R3 that are connected to each other via LS "join" | |
3416 | # in 20.0.0.0/24 network. R1 has switchess foo (192.168.1.0/24) | |
3417 | # connected to it. R2 has alice (172.16.1.0/24) and R3 has bob (10.32.1.0/24) | |
3418 | # connected to it. | |
3419 | ||
fa2a27b2 JP |
3420 | ovn-nbctl lr-add R1 |
3421 | ovn-nbctl lr-add R2 | |
3422 | ovn-nbctl lr-add R3 | |
75cf9d2b | 3423 | |
ea46a4e9 JP |
3424 | ovn-nbctl ls-add foo |
3425 | ovn-nbctl ls-add alice | |
3426 | ovn-nbctl ls-add bob | |
3427 | ovn-nbctl ls-add join | |
75cf9d2b GS |
3428 | |
3429 | # Connect foo to R1 | |
31114af7 | 3430 | ovn-nbctl lrp-add R1 foo 00:00:01:01:02:03 192.168.1.1/24 |
31ed1192 | 3431 | ovn-nbctl lsp-add foo rp-foo -- set Logical_Switch_Port rp-foo type=router \ |
31114af7 | 3432 | options:router-port=foo addresses=\"00:00:01:01:02:03\" |
75cf9d2b GS |
3433 | |
3434 | # Connect alice to R2 | |
31114af7 | 3435 | ovn-nbctl lrp-add R2 alice 00:00:02:01:02:03 172.16.1.1/24 |
31ed1192 | 3436 | ovn-nbctl lsp-add alice rp-alice -- set Logical_Switch_Port rp-alice \ |
80f408f4 | 3437 | type=router options:router-port=alice addresses=\"00:00:02:01:02:03\" |
75cf9d2b GS |
3438 | |
3439 | # Connect bob to R3 | |
31114af7 | 3440 | ovn-nbctl lrp-add R3 bob 00:00:03:01:02:03 10.32.1.1/24 |
31ed1192 | 3441 | ovn-nbctl lsp-add bob rp-bob -- set Logical_Switch_Port rp-bob \ |
80f408f4 | 3442 | type=router options:router-port=bob addresses=\"00:00:03:01:02:03\" |
75cf9d2b GS |
3443 | |
3444 | # Connect R1 to join | |
31114af7 | 3445 | ovn-nbctl lrp-add R1 R1_join 00:00:04:01:02:03 20.0.0.1/24 |
31ed1192 | 3446 | ovn-nbctl lsp-add join r1-join -- set Logical_Switch_Port r1-join \ |
80f408f4 | 3447 | type=router options:router-port=R1_join addresses='"00:00:04:01:02:03"' |
75cf9d2b GS |
3448 | |
3449 | # Connect R2 to join | |
31114af7 | 3450 | ovn-nbctl lrp-add R2 R2_join 00:00:04:01:02:04 20.0.0.2/24 |
31ed1192 | 3451 | ovn-nbctl lsp-add join r2-join -- set Logical_Switch_Port r2-join \ |
80f408f4 | 3452 | type=router options:router-port=R2_join addresses='"00:00:04:01:02:04"' |
75cf9d2b GS |
3453 | |
3454 | # Connect R3 to join | |
31114af7 | 3455 | ovn-nbctl lrp-add R3 R3_join 00:00:04:01:02:05 20.0.0.3/24 |
31ed1192 | 3456 | ovn-nbctl lsp-add join r3-join -- set Logical_Switch_Port r3-join \ |
80f408f4 | 3457 | type=router options:router-port=R3_join addresses='"00:00:04:01:02:05"' |
75cf9d2b GS |
3458 | |
3459 | #install static routes | |
e48ccf3c JP |
3460 | ovn-nbctl lr-route-add R1 172.16.1.0/24 20.0.0.2 |
3461 | ovn-nbctl lr-route-add R1 10.32.1.0/24 20.0.0.3 | |
75cf9d2b | 3462 | |
e48ccf3c JP |
3463 | ovn-nbctl lr-route-add R2 192.168.1.0/24 20.0.0.1 |
3464 | ovn-nbctl lr-route-add R2 10.32.1.0/24 20.0.0.3 | |
75cf9d2b | 3465 | |
e48ccf3c JP |
3466 | ovn-nbctl lr-route-add R3 192.168.1.0/24 20.0.0.1 |
3467 | ovn-nbctl lr-route-add R3 172.16.1.0/24 20.0.0.2 | |
75cf9d2b GS |
3468 | |
3469 | # Create logical port foo1 in foo | |
31ed1192 JP |
3470 | ovn-nbctl lsp-add foo foo1 \ |
3471 | -- lsp-set-addresses foo1 "f0:00:00:01:02:03 192.168.1.2" | |
75cf9d2b GS |
3472 | |
3473 | # Create logical port alice1 in alice | |
31ed1192 JP |
3474 | ovn-nbctl lsp-add alice alice1 \ |
3475 | -- lsp-set-addresses alice1 "f0:00:00:01:02:04 172.16.1.2" | |
75cf9d2b GS |
3476 | |
3477 | # Create logical port bob1 in bob | |
31ed1192 JP |
3478 | ovn-nbctl lsp-add bob bob1 \ |
3479 | -- lsp-set-addresses bob1 "f0:00:00:01:02:05 10.32.1.2" | |
75cf9d2b GS |
3480 | |
3481 | # Create two hypervisor and create OVS ports corresponding to logical ports. | |
3482 | net_add n1 | |
3483 | ||
3484 | sim_add hv1 | |
3485 | as hv1 | |
3486 | ovs-vsctl add-br br-phys | |
3487 | ovn_attach n1 br-phys 192.168.0.1 | |
3488 | ovs-vsctl -- add-port br-int hv1-vif1 -- \ | |
3489 | set interface hv1-vif1 external-ids:iface-id=foo1 \ | |
3490 | options:tx_pcap=hv1/vif1-tx.pcap \ | |
3491 | options:rxq_pcap=hv1/vif1-rx.pcap \ | |
3492 | ofport-request=1 | |
3493 | ||
3494 | ovs-vsctl -- add-port br-int hv1-vif2 -- \ | |
3495 | set interface hv1-vif2 external-ids:iface-id=alice1 \ | |
3496 | options:tx_pcap=hv1/vif2-tx.pcap \ | |
3497 | options:rxq_pcap=hv1/vif2-rx.pcap \ | |
3498 | ofport-request=2 | |
3499 | ||
3500 | sim_add hv2 | |
3501 | as hv2 | |
3502 | ovs-vsctl add-br br-phys | |
3503 | ovn_attach n1 br-phys 192.168.0.2 | |
3504 | ovs-vsctl -- add-port br-int hv2-vif1 -- \ | |
3505 | set interface hv2-vif1 external-ids:iface-id=bob1 \ | |
3506 | options:tx_pcap=hv2/vif1-tx.pcap \ | |
3507 | options:rxq_pcap=hv2/vif1-rx.pcap \ | |
3508 | ofport-request=1 | |
3509 | ||
3510 | ||
3511 | # Pre-populate the hypervisors' ARP tables so that we don't lose any | |
3512 | # packets for ARP resolution (native tunneling doesn't queue packets | |
3513 | # for ARP resolution). | |
3514 | ovn_populate_arp | |
3515 | ||
3516 | # Allow some time for ovn-northd and ovn-controller to catch up. | |
3517 | # XXX This should be more systematic. | |
3518 | sleep 1 | |
3519 | ||
3520 | ip_to_hex() { | |
3521 | printf "%02x%02x%02x%02x" "$@" | |
3522 | } | |
75cf9d2b GS |
3523 | |
3524 | # Send ip packets between foo1 and alice1 | |
3525 | src_mac="f00000010203" | |
3526 | dst_mac="000001010203" | |
3527 | src_ip=`ip_to_hex 192 168 1 2` | |
3528 | dst_ip=`ip_to_hex 172 16 1 2` | |
3529 | packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
3530 | as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet | |
3531 | as hv1 ovs-appctl ofproto/trace br-int in_port=1 $packet | |
3532 | ||
3533 | # Send ip packets between foo1 and bob1 | |
3534 | src_mac="f00000010203" | |
3535 | dst_mac="000001010203" | |
3536 | src_ip=`ip_to_hex 192 168 1 2` | |
3537 | dst_ip=`ip_to_hex 10 32 1 2` | |
3538 | packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
3539 | as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet | |
3540 | ||
3541 | echo "---------NB dump-----" | |
3542 | ovn-nbctl show | |
3543 | echo "---------------------" | |
3544 | ovn-nbctl list logical_router | |
3545 | echo "---------------------" | |
3546 | ovn-nbctl list logical_router_port | |
3547 | echo "---------------------" | |
3548 | ||
3549 | echo "---------SB dump-----" | |
3550 | ovn-sbctl list datapath_binding | |
3551 | echo "---------------------" | |
3552 | ovn-sbctl list port_binding | |
3553 | echo "---------------------" | |
3554 | ovn-sbctl dump-flows | |
3555 | echo "---------------------" | |
3556 | ||
3557 | echo "------ hv1 dump ----------" | |
3558 | as hv1 ovs-ofctl show br-int | |
3559 | as hv1 ovs-ofctl dump-flows br-int | |
3560 | echo "------ hv2 dump ----------" | |
3561 | as hv2 ovs-ofctl show br-int | |
3562 | as hv2 ovs-ofctl dump-flows br-int | |
3563 | echo "----------------------------" | |
3564 | ||
3565 | # Packet to Expect at bob1 | |
3566 | src_mac="000003010203" | |
3567 | dst_mac="f00000010205" | |
3568 | src_ip=`ip_to_hex 192 168 1 2` | |
3569 | dst_ip=`ip_to_hex 10 32 1 2` | |
49d7c759 | 3570 | echo "${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000" > expected |
75cf9d2b | 3571 | |
49d7c759 | 3572 | OVN_CHECK_PACKETS([hv2/vif1-tx.pcap], [expected]) |
75cf9d2b GS |
3573 | |
3574 | # Packet to Expect at alice1 | |
3575 | src_mac="000002010203" | |
3576 | dst_mac="f00000010204" | |
3577 | src_ip=`ip_to_hex 192 168 1 2` | |
3578 | dst_ip=`ip_to_hex 172 16 1 2` | |
49d7c759 | 3579 | echo "${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000" > expected |
75cf9d2b | 3580 | |
49d7c759 | 3581 | OVN_CHECK_PACKETS([hv1/vif2-tx.pcap], [expected]) |
75cf9d2b | 3582 | |
7a8f15e0 | 3583 | OVN_CLEANUP([hv1],[hv2]) |
75cf9d2b GS |
3584 | |
3585 | AT_CLEANUP | |
c1645003 | 3586 | |
281977f7 | 3587 | AT_SETUP([ovn -- dhcpv4 : 1 HV, 2 LS, 2 LSPs/LS]) |
281977f7 NS |
3588 | AT_SKIP_IF([test $HAVE_PYTHON = no]) |
3589 | ovn_start | |
3590 | ||
3591 | ovn-nbctl ls-add ls1 | |
3592 | ||
3593 | ovn-nbctl lsp-add ls1 ls1-lp1 \ | |
3594 | -- lsp-set-addresses ls1-lp1 "f0:00:00:00:00:01 10.0.0.4" | |
3595 | ||
3596 | ovn-nbctl lsp-set-port-security ls1-lp1 "f0:00:00:00:00:01 10.0.0.4" | |
3597 | ||
3598 | ovn-nbctl lsp-add ls1 ls1-lp2 \ | |
3599 | -- lsp-set-addresses ls1-lp2 "f0:00:00:00:00:02 10.0.0.6 20.0.0.4" | |
3600 | ||
3601 | ovn-nbctl lsp-set-port-security ls1-lp2 "f0:00:00:00:00:02 10.0.0.6 20.0.0.4" | |
3602 | ||
3603 | ovn-nbctl ls-add ls2 | |
3604 | ovn-nbctl lsp-add ls2 ls2-lp1 \ | |
3605 | -- lsp-set-addresses ls2-lp1 "f0:00:00:00:00:03 30.0.0.6 40.0.0.4" | |
3606 | ovn-nbctl lsp-set-port-security ls2-lp1 "f0:00:00:00:00:03 30.0.0.6 40.0.0.4" | |
3607 | ovn-nbctl lsp-add ls2 ls2-lp2 \ | |
3608 | -- lsp-set-addresses ls2-lp2 "f0:00:00:00:00:04 30.0.0.7" | |
3609 | ovn-nbctl lsp-set-port-security ls2-lp2 "f0:00:00:00:00:04 30.0.0.7" | |
3610 | ||
3611 | ovn-nbctl -- --id=@d1 create DHCP_Options cidr=10.0.0.0/24 \ | |
3612 | options="\"server_id\"=\"10.0.0.1\" \"server_mac\"=\"ff:10:00:00:00:01\" \ | |
3613 | \"lease_time\"=\"3600\" \"router\"=\"10.0.0.1\"" \ | |
3614 | -- add Logical_Switch_Port ls1-lp1 dhcpv4_options @d1 \ | |
3615 | -- add Logical_Switch_Port ls1-lp2 dhcpv4_options @d1 | |
3616 | ||
3617 | ovn-nbctl -- --id=@d2 create DHCP_Options cidr=30.0.0.0/24 \ | |
3618 | options="\"server_id\"=\"30.0.0.1\" \"server_mac\"=\"ff:10:00:00:00:02\" \ | |
3619 | \"lease_time\"=\"3600\"" -- add Logical_Switch_Port ls2-lp2 dhcpv4_options @d2 | |
3620 | ||
3621 | net_add n1 | |
3622 | sim_add hv1 | |
3623 | ||
3624 | as hv1 | |
3625 | ovs-vsctl add-br br-phys | |
3626 | ovn_attach n1 br-phys 192.168.0.1 | |
3627 | ovs-vsctl -- add-port br-int hv1-vif1 -- \ | |
3628 | set interface hv1-vif1 external-ids:iface-id=ls1-lp1 \ | |
3629 | options:tx_pcap=hv1/vif1-tx.pcap \ | |
3630 | options:rxq_pcap=hv1/vif1-rx.pcap \ | |
3631 | ofport-request=1 | |
3632 | ||
3633 | ovs-vsctl -- add-port br-int hv1-vif2 -- \ | |
3634 | set interface hv1-vif2 external-ids:iface-id=ls1-lp2 \ | |
3635 | options:tx_pcap=hv1/vif2-tx.pcap \ | |
3636 | options:rxq_pcap=hv1/vif2-rx.pcap \ | |
3637 | ofport-request=2 | |
3638 | ||
3639 | ovs-vsctl -- add-port br-int hv1-vif3 -- \ | |
3640 | set interface hv1-vif3 external-ids:iface-id=ls2-lp1 \ | |
3641 | options:tx_pcap=hv1/vif3-tx.pcap \ | |
3642 | options:rxq_pcap=hv1/vif3-rx.pcap \ | |
3643 | ofport-request=3 | |
3644 | ||
3645 | ovs-vsctl -- add-port br-int hv1-vif4 -- \ | |
3646 | set interface hv1-vif4 external-ids:iface-id=ls2-lp2 \ | |
3647 | options:tx_pcap=hv1/vif4-tx.pcap \ | |
3648 | options:rxq_pcap=hv1/vif4-rx.pcap \ | |
3649 | ofport-request=4 | |
3650 | ||
3651 | ovn_populate_arp | |
3652 | ||
3653 | sleep 2 | |
3654 | ||
3655 | as hv1 ovs-vsctl show | |
3656 | ||
281977f7 NS |
3657 | # This shell function sends a DHCP request packet |
3658 | # test_dhcp INPORT SRC_MAC DHCP_TYPE OFFER_IP ... | |
3659 | test_dhcp() { | |
3660 | local inport=$1 src_mac=$2 dhcp_type=$3 offer_ip=$4 | |
3661 | local request=ffffffffffff${src_mac}080045100110000000008011000000000000ffffffff | |
3662 | # udp header and dhcp header | |
ab187e7e BP |
3663 | request=${request}0044004300fc0000 |
3664 | request=${request}010106006359aa760000000000000000000000000000000000000000${src_mac} | |
281977f7 | 3665 | # client hardware padding |
ab187e7e | 3666 | request=${request}00000000000000000000 |
281977f7 | 3667 | # server hostname |
ab187e7e BP |
3668 | request=${request}0000000000000000000000000000000000000000000000000000000000000000 |
3669 | request=${request}0000000000000000000000000000000000000000000000000000000000000000 | |
281977f7 | 3670 | # boot file name |
ab187e7e BP |
3671 | request=${request}0000000000000000000000000000000000000000000000000000000000000000 |
3672 | request=${request}0000000000000000000000000000000000000000000000000000000000000000 | |
3673 | request=${request}0000000000000000000000000000000000000000000000000000000000000000 | |
3674 | request=${request}0000000000000000000000000000000000000000000000000000000000000000 | |
281977f7 | 3675 | # dhcp magic cookie |
ab187e7e | 3676 | request=${request}63825363 |
281977f7 | 3677 | # dhcp message type |
ab187e7e | 3678 | request=${request}3501${dhcp_type}ff |
281977f7 NS |
3679 | |
3680 | if test $offer_ip != 0; then | |
3681 | local srv_mac=$5 srv_ip=$6 expected_dhcp_opts=$7 | |
3682 | # total IP length will be the IP length of the request packet | |
3683 | # (which is 272 in our case) + 8 (padding bytes) + (expected_dhcp_opts / 2) | |
3684 | ip_len=`expr 280 + ${#expected_dhcp_opts} / 2` | |
3685 | udp_len=`expr $ip_len - 20` | |
04d60f6e YT |
3686 | ip_len=$(printf "%x" $ip_len) |
3687 | udp_len=$(printf "%x" $udp_len) | |
281977f7 NS |
3688 | # $ip_len var will be in 3 digits i.e 134. So adding a '0' before $ip_len |
3689 | local reply=${src_mac}${srv_mac}080045100${ip_len}000000008011XXXX${srv_ip}${offer_ip} | |
3690 | # udp header and dhcp header. | |
3691 | # $udp_len var will be in 3 digits. So adding a '0' before $udp_len | |
ab187e7e | 3692 | reply=${reply}004300440${udp_len}0000020106006359aa760000000000000000 |
281977f7 | 3693 | # your ip address |
ab187e7e | 3694 | reply=${reply}${offer_ip} |
281977f7 | 3695 | # next server ip address, relay agent ip address, client mac address |
ab187e7e | 3696 | reply=${reply}0000000000000000${src_mac} |
281977f7 | 3697 | # client hardware padding |
ab187e7e | 3698 | reply=${reply}00000000000000000000 |
281977f7 | 3699 | # server hostname |
ab187e7e BP |
3700 | reply=${reply}0000000000000000000000000000000000000000000000000000000000000000 |
3701 | reply=${reply}0000000000000000000000000000000000000000000000000000000000000000 | |
281977f7 | 3702 | # boot file name |
ab187e7e BP |
3703 | reply=${reply}0000000000000000000000000000000000000000000000000000000000000000 |
3704 | reply=${reply}0000000000000000000000000000000000000000000000000000000000000000 | |
3705 | reply=${reply}0000000000000000000000000000000000000000000000000000000000000000 | |
3706 | reply=${reply}0000000000000000000000000000000000000000000000000000000000000000 | |
281977f7 | 3707 | # dhcp magic cookie |
ab187e7e | 3708 | reply=${reply}63825363 |
281977f7 NS |
3709 | # dhcp message type |
3710 | local dhcp_reply_type=02 | |
3711 | if test $dhcp_type = 03; then | |
3712 | dhcp_reply_type=05 | |
3713 | fi | |
ab187e7e | 3714 | reply=${reply}3501${dhcp_reply_type}${expected_dhcp_opts}00000000ff00000000 |
281977f7 NS |
3715 | echo $reply >> $inport.expected |
3716 | else | |
3717 | shift; shift; shift; shift; | |
3718 | for outport; do | |
e4543cfe | 3719 | echo $request >> $outport.expected |
281977f7 NS |
3720 | done |
3721 | fi | |
3722 | as hv1 ovs-appctl netdev-dummy/receive hv1-vif$inport $request | |
3723 | } | |
3724 | ||
3725 | reset_pcap_file() { | |
3726 | local iface=$1 | |
3727 | local pcap_file=$2 | |
3728 | ovs-vsctl -- set Interface $iface options:tx_pcap=dummy-tx.pcap \ | |
3729 | options:rxq_pcap=dummy-rx.pcap | |
3730 | rm -f ${pcap_file}*.pcap | |
3731 | ovs-vsctl -- set Interface $iface options:tx_pcap=${pcap_file}-tx.pcap \ | |
3732 | options:rxq_pcap=${pcap_file}-rx.pcap | |
3733 | } | |
3734 | ||
3735 | ip_to_hex() { | |
3736 | printf "%02x%02x%02x%02x" "$@" | |
3737 | } | |
3738 | ||
3739 | AT_CAPTURE_FILE([ofctl_monitor0.log]) | |
3740 | as hv1 ovs-ofctl monitor br-int resume --detach --no-chdir \ | |
3741 | --pidfile=ovs-ofctl0.pid 2> ofctl_monitor0.log | |
3742 | ||
3743 | echo "---------NB dump-----" | |
3744 | ovn-nbctl show | |
3745 | echo "---------------------" | |
3746 | echo "---------SB dump-----" | |
3747 | ovn-sbctl list datapath_binding | |
3748 | echo "---------------------" | |
3749 | ovn-sbctl list logical_flow | |
3750 | echo "---------------------" | |
3751 | ||
3752 | echo "---------------------" | |
3753 | ovn-sbctl dump-flows | |
3754 | echo "---------------------" | |
3755 | ||
3756 | echo "------ hv1 dump ----------" | |
3757 | as hv1 ovs-ofctl dump-flows br-int | |
3758 | ||
3759 | # Send DHCPDISCOVER. | |
3760 | offer_ip=`ip_to_hex 10 0 0 4` | |
3761 | server_ip=`ip_to_hex 10 0 0 1` | |
7c76bf4e | 3762 | expected_dhcp_opts=330400000e100104ffffff0003040a00000136040a000001 |
281977f7 NS |
3763 | test_dhcp 1 f00000000001 01 $offer_ip ff1000000001 $server_ip $expected_dhcp_opts |
3764 | ||
3765 | # NXT_RESUMEs should be 1. | |
3766 | OVS_WAIT_UNTIL([test 1 = `cat ofctl_monitor*.log | grep -c NXT_RESUME`]) | |
3767 | ||
3768 | $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif1-tx.pcap > 1.packets | |
3769 | cat 1.expected | cut -c -48 > expout | |
3770 | AT_CHECK([cat 1.packets | cut -c -48], [0], [expout]) | |
3771 | # Skipping the IPv4 checksum. | |
3772 | cat 1.expected | cut -c 53- > expout | |
3773 | AT_CHECK([cat 1.packets | cut -c 53-], [0], [expout]) | |
3774 | ||
3775 | # ovs-ofctl also resumes the packets and this causes other ports to receive | |
3776 | # the DHCP request packet. So reset the pcap files so that its easier to test. | |
3777 | reset_pcap_file hv1-vif1 hv1/vif1 | |
3778 | reset_pcap_file hv1-vif2 hv1/vif2 | |
3779 | rm -f 1.expected | |
3780 | rm -f 2.expected | |
3781 | ||
3782 | # Send DHCPREQUEST. | |
3783 | offer_ip=`ip_to_hex 10 0 0 6` | |
3784 | server_ip=`ip_to_hex 10 0 0 1` | |
7c76bf4e | 3785 | expected_dhcp_opts=330400000e100104ffffff0003040a00000136040a000001 |
281977f7 NS |
3786 | test_dhcp 2 f00000000002 03 $offer_ip ff1000000001 $server_ip $expected_dhcp_opts |
3787 | ||
3788 | # NXT_RESUMEs should be 2. | |
3789 | OVS_WAIT_UNTIL([test 2 = `cat ofctl_monitor*.log | grep -c NXT_RESUME`]) | |
3790 | ||
3791 | $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif2-tx.pcap > 2.packets | |
3792 | cat 2.expected | cut -c -48 > expout | |
3793 | AT_CHECK([cat 2.packets | cut -c -48], [0], [expout]) | |
3794 | # Skipping the IPv4 checksum. | |
3795 | cat 2.expected | cut -c 53- > expout | |
3796 | AT_CHECK([cat 2.packets | cut -c 53-], [0], [expout]) | |
3797 | ||
3798 | reset_pcap_file hv1-vif1 hv1/vif1 | |
3799 | reset_pcap_file hv1-vif2 hv1/vif2 | |
3800 | rm -f 1.expected | |
3801 | rm -f 2.expected | |
3802 | ||
3803 | # Send Invalid DHCPv4 packet on ls1-lp2. It should be received by ovn-controller | |
3804 | # but should be resumed without the reply. | |
3805 | # ls1-lp1 (vif1-tx.pcap) should receive the DHCPv4 request packet twice, | |
3806 | # one from ovn-controller and the other from "ovs-ofctl resume." | |
3807 | offer_ip=0 | |
3808 | test_dhcp 2 f00000000002 08 $offer_ip 1 1 | |
3809 | ||
3810 | # NXT_RESUMEs should be 3. | |
3811 | OVS_WAIT_UNTIL([test 3 = `cat ofctl_monitor*.log | grep -c NXT_RESUME`]) | |
3812 | ||
3813 | # vif1-tx.pcap should have received the DHCPv4 (invalid) request packet | |
49d7c759 | 3814 | OVN_CHECK_PACKETS([hv1/vif1-tx.pcap], [1.expected]) |
281977f7 NS |
3815 | |
3816 | reset_pcap_file hv1-vif1 hv1/vif1 | |
3817 | reset_pcap_file hv1-vif2 hv1/vif2 | |
3818 | rm -f 1.expected | |
3819 | rm -f 2.expected | |
3820 | ||
3821 | # Send DHCPv4 packet on ls2-lp1. It doesn't have any DHCPv4 options defined. | |
3822 | # ls2-lp2 (vif4-tx.pcap) should receive the DHCPv4 request packet once. | |
3823 | ||
3824 | test_dhcp 3 f00000000003 01 0 4 | |
3825 | ||
3826 | # Send DHCPv4 packet on ls2-lp2. "router" DHCPv4 option is not defined for | |
3827 | # this lport. | |
3828 | test_dhcp 4 f00000000004 01 0 3 | |
3829 | ||
3830 | # NXT_RESUMEs should be 3. | |
3831 | OVS_WAIT_UNTIL([test 3 = `cat ofctl_monitor*.log | grep -c NXT_RESUME`]) | |
3832 | ||
49d7c759 BP |
3833 | OVN_CHECK_PACKETS([hv1/vif3-tx.pcap], [3.expected]) |
3834 | OVN_CHECK_PACKETS([hv1/vif4-tx.pcap], [4.expected]) | |
281977f7 NS |
3835 | |
3836 | as hv1 | |
33ac3c83 NS |
3837 | OVS_APP_EXIT_AND_WAIT([ovn-controller]) |
3838 | OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) | |
3839 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
3840 | ||
3841 | as ovn-sb | |
3842 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
3843 | ||
3844 | as ovn-nb | |
3845 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
3846 | ||
3847 | as northd | |
3848 | OVS_APP_EXIT_AND_WAIT([ovn-northd]) | |
3849 | ||
3850 | as main | |
3851 | OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) | |
3852 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
3853 | ||
3854 | AT_CLEANUP | |
3855 | ||
40df4566 | 3856 | AT_SETUP([ovn -- dhcpv6 : 1 HV, 2 LS, 5 LSPs]) |
33ac3c83 NS |
3857 | AT_SKIP_IF([test $HAVE_PYTHON = no]) |
3858 | ovn_start | |
3859 | ||
3860 | ovn-nbctl ls-add ls1 | |
3861 | ovn-nbctl lsp-add ls1 ls1-lp1 \ | |
3862 | -- lsp-set-addresses ls1-lp1 "f0:00:00:00:00:01 10.0.0.4 ae70::4" | |
3863 | ||
3864 | ovn-nbctl lsp-set-port-security ls1-lp1 "f0:00:00:00:00:01 10.0.0.4 ae70::4" | |
3865 | ||
3866 | ovn-nbctl lsp-add ls1 ls1-lp2 \ | |
3867 | -- lsp-set-addresses ls1-lp2 "f0:00:00:00:00:02 ae70::5" | |
3868 | ||
3869 | ovn-nbctl lsp-set-port-security ls1-lp2 "f0:00:00:00:00:02 ae70::5" | |
3870 | ||
40df4566 ZKL |
3871 | ovn-nbctl lsp-add ls1 ls1-lp3 \ |
3872 | -- lsp-set-addresses ls1-lp3 "f0:00:00:00:00:22 ae70::22" | |
3873 | ||
3874 | ovn-nbctl lsp-set-port-security ls1-lp3 "f0:00:00:00:00:22 ae70::22" | |
3875 | ||
33ac3c83 NS |
3876 | ovn-nbctl -- --id=@d1 create DHCP_Options cidr="ae70\:\:/64" \ |
3877 | options="\"server_id\"=\"00:00:00:10:00:01\"" \ | |
3878 | -- add Logical_Switch_Port ls1-lp1 dhcpv6_options @d1 \ | |
3879 | -- add Logical_Switch_Port ls1-lp2 dhcpv6_options @d1 | |
3880 | ||
40df4566 ZKL |
3881 | ovn-nbctl -- --id=@d2 create DHCP_Options cidr="ae70\:\:/64" \ |
3882 | options="\"dhcpv6_stateless\"=\"true\" \"server_id\"=\"00:00:00:10:00:01\"" \ | |
3883 | -- add Logical_Switch_Port ls1-lp3 dhcpv6_options @d2 | |
3884 | ||
33ac3c83 NS |
3885 | ovn-nbctl ls-add ls2 |
3886 | ovn-nbctl lsp-add ls2 ls2-lp1 \ | |
3887 | -- lsp-set-addresses ls2-lp1 "f0:00:00:00:00:03 be70::3" | |
3888 | ovn-nbctl lsp-set-port-security ls2-lp1 "f0:00:00:00:00:03 be70::3" | |
3889 | ovn-nbctl lsp-add ls2 ls2-lp2 \ | |
3890 | -- lsp-set-addresses ls2-lp2 "f0:00:00:00:00:04 be70::4" | |
3891 | ovn-nbctl lsp-set-port-security ls2-lp2 "f0:00:00:00:00:04 be70::4" | |
3892 | ||
3893 | net_add n1 | |
3894 | sim_add hv1 | |
3895 | ||
3896 | as hv1 | |
3897 | ovs-vsctl add-br br-phys | |
3898 | ovn_attach n1 br-phys 192.168.0.1 | |
3899 | ovs-vsctl -- add-port br-int hv1-vif1 -- \ | |
3900 | set interface hv1-vif1 external-ids:iface-id=ls1-lp1 \ | |
3901 | options:tx_pcap=hv1/vif1-tx.pcap \ | |
3902 | options:rxq_pcap=hv1/vif1-rx.pcap \ | |
3903 | ofport-request=1 | |
3904 | ||
3905 | ovs-vsctl -- add-port br-int hv1-vif2 -- \ | |
3906 | set interface hv1-vif2 external-ids:iface-id=ls1-lp2 \ | |
3907 | options:tx_pcap=hv1/vif2-tx.pcap \ | |
3908 | options:rxq_pcap=hv1/vif2-rx.pcap \ | |
3909 | ofport-request=2 | |
3910 | ||
3911 | ovs-vsctl -- add-port br-int hv1-vif3 -- \ | |
3912 | set interface hv1-vif3 external-ids:iface-id=ls2-lp1 \ | |
3913 | options:tx_pcap=hv1/vif3-tx.pcap \ | |
3914 | options:rxq_pcap=hv1/vif3-rx.pcap \ | |
3915 | ofport-request=3 | |
3916 | ||
3917 | ovs-vsctl -- add-port br-int hv1-vif4 -- \ | |
3918 | set interface hv1-vif4 external-ids:iface-id=ls2-lp2 \ | |
3919 | options:tx_pcap=hv1/vif4-tx.pcap \ | |
3920 | options:rxq_pcap=hv1/vif4-rx.pcap \ | |
3921 | ofport-request=4 | |
3922 | ||
40df4566 ZKL |
3923 | ovs-vsctl -- add-port br-int hv1-vif5 -- \ |
3924 | set interface hv1-vif5 external-ids:iface-id=ls1-lp3 \ | |
3925 | options:tx_pcap=hv1/vif5-tx.pcap \ | |
3926 | options:rxq_pcap=hv1/vif5-rx.pcap \ | |
3927 | ofport-request=5 | |
3928 | ||
33ac3c83 NS |
3929 | ovn_populate_arp |
3930 | ||
3931 | sleep 2 | |
3932 | ||
3933 | trim_zeros() { | |
3934 | sed 's/\(00\)\{1,\}$//' | |
3935 | } | |
3936 | ||
3937 | # This shell function sends a DHCPv6 request packet | |
40df4566 ZKL |
3938 | # test_dhcpv6 INPORT SRC_MAC SRC_LLA DHCPv6_MSG_TYPE OFFER_IP OUTPORT... |
3939 | # The OUTPORTs (zero or more) list the VIFs on which the original DHCPv6 | |
33ac3c83 NS |
3940 | # packet should be received twice (one from ovn-controller and the other |
3941 | # from the "ovs-ofctl monitor br-int resume" | |
3942 | test_dhcpv6() { | |
3943 | local inport=$1 src_mac=$2 src_lla=$3 msg_code=$4 offer_ip=$5 | |
3944 | local request=ffffffffffff${src_mac}86dd00000000002a1101${src_lla} | |
3945 | # dst ip ff02::1:2 | |
ab187e7e | 3946 | request=${request}ff020000000000000000000000010002 |
33ac3c83 | 3947 | # udp header and dhcpv6 header |
ab187e7e | 3948 | request=${request}02220223002affff${msg_code}010203 |
33ac3c83 | 3949 | # Client identifier |
ab187e7e | 3950 | request=${request}0001000a00030001${src_mac} |
33ac3c83 | 3951 | # IA-NA (Identity Association for Non Temporary Address) |
ab187e7e | 3952 | request=${request}0003000c0102030400000e1000001518 |
33ac3c83 NS |
3953 | shift; shift; shift; shift; shift; |
3954 | if test $offer_ip != 0; then | |
3955 | local server_mac=000000100001 | |
3956 | local server_lla=fe80000000000000020000fffe100001 | |
3957 | local reply_code=07 | |
3958 | if test $msg_code = 01; then | |
3959 | reply_code=02 | |
3960 | fi | |
40df4566 ZKL |
3961 | local msg_len=54 |
3962 | if test $offer_ip = 1; then | |
3963 | msg_len=28 | |
3964 | fi | |
3965 | local reply=${src_mac}${server_mac}86dd0000000000${msg_len}1101${server_lla}${src_lla} | |
33ac3c83 | 3966 | # udp header and dhcpv6 header |
ab187e7e | 3967 | reply=${reply}0223022200${msg_len}ffff${reply_code}010203 |
33ac3c83 | 3968 | # Client identifier |
ab187e7e | 3969 | reply=${reply}0001000a00030001${src_mac} |
33ac3c83 | 3970 | # IA-NA |
40df4566 | 3971 | if test $offer_ip != 1; then |
ab187e7e | 3972 | reply=${reply}0003002801020304ffffffffffffffff00050018${offer_ip}ffffffffffffffff |
40df4566 | 3973 | fi |
33ac3c83 | 3974 | # Server identifier |
ab187e7e | 3975 | reply=${reply}0002000a00030001${server_mac} |
33ac3c83 NS |
3976 | echo $reply | trim_zeros >> $inport.expected |
3977 | else | |
3978 | for outport; do | |
3979 | echo $request | trim_zeros >> $outport.expected | |
3980 | done | |
3981 | fi | |
3982 | ||
3983 | as hv1 ovs-appctl netdev-dummy/receive hv1-vif$inport $request | |
3984 | } | |
3985 | ||
3986 | reset_pcap_file() { | |
3987 | local iface=$1 | |
3988 | local pcap_file=$2 | |
3989 | ovs-vsctl -- set Interface $iface options:tx_pcap=dummy-tx.pcap \ | |
3990 | options:rxq_pcap=dummy-rx.pcap | |
3991 | rm -f ${pcap_file}*.pcap | |
3992 | ovs-vsctl -- set Interface $iface options:tx_pcap=${pcap_file}-tx.pcap \ | |
3993 | options:rxq_pcap=${pcap_file}-rx.pcap | |
3994 | } | |
3995 | ||
3996 | AT_CAPTURE_FILE([ofctl_monitor0.log]) | |
3997 | as hv1 ovs-ofctl monitor br-int resume --detach --no-chdir \ | |
3998 | --pidfile=ovs-ofctl0.pid 2> ofctl_monitor0.log | |
3999 | ||
4000 | echo "---------NB dump-----" | |
4001 | ovn-nbctl show | |
4002 | echo "---------------------" | |
4003 | echo "---------SB dump-----" | |
4004 | ovn-sbctl list datapath_binding | |
4005 | echo "---------------------" | |
4006 | ovn-sbctl list logical_flow | |
4007 | echo "---------------------" | |
4008 | ||
4009 | echo "---------------------" | |
4010 | ovn-sbctl dump-flows | |
4011 | echo "---------------------" | |
4012 | ||
4013 | echo "------ hv1 dump ----------" | |
4014 | as hv1 ovs-ofctl dump-flows br-int | |
4015 | ||
4016 | src_mac=f00000000001 | |
4017 | src_lla=fe80000000000000f20000fffe000001 | |
4018 | offer_ip=ae700000000000000000000000000004 | |
4019 | test_dhcpv6 1 $src_mac $src_lla 01 $offer_ip | |
4020 | ||
4021 | # NXT_RESUMEs should be 1. | |
4022 | OVS_WAIT_UNTIL([test 1 = `cat ofctl_monitor*.log | grep -c NXT_RESUME`]) | |
4023 | ||
4024 | $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif1-tx.pcap | trim_zeros > 1.packets | |
4025 | # cat 1.expected | trim_zeros > expout | |
4026 | cat 1.expected | cut -c -120 > expout | |
4027 | AT_CHECK([cat 1.packets | cut -c -120], [0], [expout]) | |
4028 | # Skipping the UDP checksum | |
4029 | cat 1.expected | cut -c 125- > expout | |
4030 | AT_CHECK([cat 1.packets | cut -c 125-], [0], [expout]) | |
4031 | ||
4032 | rm 1.expected | |
4033 | ||
4034 | # Send invalid packet on ls1-lp2. ovn-controller should resume the packet | |
4035 | # without any modifications and the packet should be received by ls1-lp1. | |
4036 | # ls1-lp1 will receive the packet twice, one from the ovn-controller after the | |
4037 | # resume and the other from ovs-ofctl monitor resume. | |
4038 | ||
4039 | reset_pcap_file hv1-vif1 hv1/vif1 | |
4040 | reset_pcap_file hv1-vif2 hv1/vif2 | |
4041 | ||
4042 | src_mac=f00000000002 | |
4043 | src_lla=fe80000000000000f20000fffe000002 | |
4044 | offer_ip=ae700000000000000000000000000005 | |
4045 | # Set invalid msg_type | |
4046 | ||
4047 | test_dhcpv6 2 $src_mac $src_lla 10 0 1 1 | |
4048 | ||
4049 | # NXT_RESUMEs should be 2. | |
4050 | OVS_WAIT_UNTIL([test 2 = `cat ofctl_monitor*.log | grep -c NXT_RESUME`]) | |
4051 | ||
4052 | # vif2-tx.pcap should not have received the DHCPv6 reply packet | |
4053 | rm 2.packets | |
4054 | $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif2-tx.pcap | trim_zeros > 2.packets | |
4055 | AT_CHECK([cat 2.packets], [0], []) | |
4056 | ||
4057 | # vif1-tx.pcap should have received the DHCPv6 (invalid) request packet | |
4058 | $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif1-tx.pcap | trim_zeros > 1.packets | |
4059 | cat 1.expected > expout | |
4060 | AT_CHECK([cat 1.packets], [0], [expout]) | |
4061 | ||
4062 | # Send DHCPv6 packet on ls2-lp1. native DHCPv6 is disabled on this port. | |
4063 | # There should be no DHCPv6 reply from ovn-controller and the request packet | |
4064 | # should be received by ls2-lp2. | |
4065 | ||
4066 | src_mac=f00000000003 | |
4067 | src_lla=fe80000000000000f20000fffe000003 | |
4068 | test_dhcpv6 3 $src_mac $src_lla 01 0 4 | |
4069 | ||
4070 | # NXT_RESUMEs should be 2 only. | |
4071 | OVS_WAIT_UNTIL([test 2 = `cat ofctl_monitor*.log | grep -c NXT_RESUME`]) | |
4072 | ||
4073 | # vif3-tx.pcap should not have received the DHCPv6 reply packet | |
4074 | $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif3-tx.pcap | trim_zeros > 3.packets | |
4075 | AT_CHECK([cat 3.packets], [0], []) | |
4076 | ||
4077 | # vif4-tx.pcap should have received the DHCPv6 request packet | |
4078 | $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif4-tx.pcap | trim_zeros > 4.packets | |
4079 | cat 4.expected > expout | |
4080 | AT_CHECK([cat 4.packets], [0], [expout]) | |
4081 | ||
40df4566 ZKL |
4082 | # Send DHCPv6 packet on ls1-lp3. native DHCPv6 works as stateless mode for this port. |
4083 | # The DHCPv6 reply should doesn't contian offer_ip. | |
4084 | src_mac=f00000000022 | |
4085 | src_lla=fe80000000000000f20000fffe000022 | |
4086 | reset_pcap_file hv1-vif5 hv1/vif5 | |
4087 | test_dhcpv6 5 $src_mac $src_lla 01 1 5 | |
4088 | ||
4089 | # NXT_RESUMEs should be 3. | |
4090 | OVS_WAIT_UNTIL([test 3 = `cat ofctl_monitor*.log | grep -c NXT_RESUME`]) | |
4091 | ||
4092 | $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif5-tx.pcap | trim_zeros > 5.packets | |
4093 | # Skipping the UDP checksum | |
4094 | cat 5.expected | cut -c 1-120,125- > expout | |
4095 | AT_CHECK([cat 5.packets | cut -c 1-120,125- ], [0], [expout]) | |
4096 | ||
33ac3c83 | 4097 | as hv1 |
281977f7 NS |
4098 | OVS_APP_EXIT_AND_WAIT([ovn-controller]) |
4099 | OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) | |
4100 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
4101 | ||
4102 | as ovn-sb | |
4103 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
4104 | ||
4105 | as ovn-nb | |
4106 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
4107 | ||
4108 | as northd | |
4109 | OVS_APP_EXIT_AND_WAIT([ovn-northd]) | |
4110 | ||
4111 | as main | |
4112 | OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) | |
4113 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
4114 | ||
4115 | AT_CLEANUP | |
4116 | ||
c1645003 | 4117 | AT_SETUP([ovn -- 2 HVs, 2 LRs connected via LS, gateway router]) |
c1645003 GS |
4118 | AT_SKIP_IF([test $HAVE_PYTHON = no]) |
4119 | ovn_start | |
4120 | ||
4121 | # Logical network: | |
4122 | # Two LRs - R1 and R2 that are connected to each other via LS "join" | |
4123 | # in 20.0.0.0/24 network. R1 has switchess foo (192.168.1.0/24) | |
4124 | # connected to it. R2 has alice (172.16.1.0/24) connected to it. | |
4125 | # R2 is a gateway router. | |
4126 | ||
4127 | ||
4128 | ||
4129 | # Create two hypervisor and create OVS ports corresponding to logical ports. | |
4130 | net_add n1 | |
4131 | ||
4132 | sim_add hv1 | |
4133 | as hv1 | |
4134 | ovs-vsctl add-br br-phys | |
4135 | ovn_attach n1 br-phys 192.168.0.1 | |
4136 | ovs-vsctl -- add-port br-int hv1-vif1 -- \ | |
4137 | set interface hv1-vif1 external-ids:iface-id=foo1 \ | |
4138 | options:tx_pcap=hv1/vif1-tx.pcap \ | |
4139 | options:rxq_pcap=hv1/vif1-rx.pcap \ | |
4140 | ofport-request=1 | |
4141 | ||
4142 | ||
4143 | sim_add hv2 | |
4144 | as hv2 | |
4145 | ovs-vsctl add-br br-phys | |
4146 | ovn_attach n1 br-phys 192.168.0.2 | |
4147 | ovs-vsctl -- add-port br-int hv2-vif1 -- \ | |
4148 | set interface hv2-vif1 external-ids:iface-id=alice1 \ | |
4149 | options:tx_pcap=hv2/vif1-tx.pcap \ | |
4150 | options:rxq_pcap=hv2/vif1-rx.pcap \ | |
4151 | ofport-request=1 | |
4152 | ||
4153 | # Pre-populate the hypervisors' ARP tables so that we don't lose any | |
4154 | # packets for ARP resolution (native tunneling doesn't queue packets | |
4155 | # for ARP resolution). | |
4156 | ovn_populate_arp | |
4157 | ||
4158 | ovn-nbctl create Logical_Router name=R1 | |
4159 | ovn-nbctl create Logical_Router name=R2 options:chassis="hv2" | |
4160 | ||
ea46a4e9 JP |
4161 | ovn-nbctl ls-add foo |
4162 | ovn-nbctl ls-add alice | |
4163 | ovn-nbctl ls-add join | |
c1645003 GS |
4164 | |
4165 | # Connect foo to R1 | |
31114af7 | 4166 | ovn-nbctl lrp-add R1 foo 00:00:01:01:02:03 192.168.1.1/24 |
31ed1192 | 4167 | ovn-nbctl lsp-add foo rp-foo -- set Logical_Switch_Port rp-foo \ |
80f408f4 | 4168 | type=router options:router-port=foo addresses=\"00:00:01:01:02:03\" |
c1645003 GS |
4169 | |
4170 | # Connect alice to R2 | |
31114af7 | 4171 | ovn-nbctl lrp-add R2 alice 00:00:02:01:02:03 172.16.1.1/24 |
31ed1192 | 4172 | ovn-nbctl lsp-add alice rp-alice -- set Logical_Switch_Port rp-alice \ |
80f408f4 | 4173 | type=router options:router-port=alice addresses=\"00:00:02:01:02:03\" |
c1645003 GS |
4174 | |
4175 | # Connect R1 to join | |
31114af7 | 4176 | ovn-nbctl lrp-add R1 R1_join 00:00:04:01:02:03 20.0.0.1/24 |
31ed1192 | 4177 | ovn-nbctl lsp-add join r1-join -- set Logical_Switch_Port r1-join \ |
80f408f4 | 4178 | type=router options:router-port=R1_join addresses='"00:00:04:01:02:03"' |
c1645003 GS |
4179 | |
4180 | # Connect R2 to join | |
31114af7 | 4181 | ovn-nbctl lrp-add R2 R2_join 00:00:04:01:02:04 20.0.0.2/24 |
31ed1192 | 4182 | ovn-nbctl lsp-add join r2-join -- set Logical_Switch_Port r2-join \ |
80f408f4 | 4183 | type=router options:router-port=R2_join addresses='"00:00:04:01:02:04"' |
c1645003 GS |
4184 | |
4185 | ||
4186 | #install static routes | |
4187 | ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \ | |
4188 | ip_prefix=172.16.1.0/24 nexthop=20.0.0.2 -- add Logical_Router \ | |
4189 | R1 static_routes @lrt | |
4190 | ||
4191 | ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \ | |
4192 | ip_prefix=192.168.1.0/24 nexthop=20.0.0.1 -- add Logical_Router \ | |
4193 | R2 static_routes @lrt | |
4194 | ||
4195 | # Create logical port foo1 in foo | |
31ed1192 JP |
4196 | ovn-nbctl lsp-add foo foo1 \ |
4197 | -- lsp-set-addresses foo1 "f0:00:00:01:02:03 192.168.1.2" | |
c1645003 GS |
4198 | |
4199 | # Create logical port alice1 in alice | |
31ed1192 JP |
4200 | ovn-nbctl lsp-add alice alice1 \ |
4201 | -- lsp-set-addresses alice1 "f0:00:00:01:02:04 172.16.1.2" | |
c1645003 GS |
4202 | |
4203 | ||
4204 | # Allow some time for ovn-northd and ovn-controller to catch up. | |
4205 | # XXX This should be more systematic. | |
4206 | sleep 2 | |
4207 | ||
4208 | ip_to_hex() { | |
4209 | printf "%02x%02x%02x%02x" "$@" | |
4210 | } | |
c1645003 GS |
4211 | |
4212 | # Send ip packets between foo1 and alice1 | |
4213 | src_mac="f00000010203" | |
4214 | dst_mac="000001010203" | |
4215 | src_ip=`ip_to_hex 192 168 1 2` | |
4216 | dst_ip=`ip_to_hex 172 16 1 2` | |
4217 | packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
4218 | ||
4219 | echo "---------NB dump-----" | |
4220 | ovn-nbctl show | |
4221 | echo "---------------------" | |
4222 | ovn-nbctl list logical_router | |
4223 | echo "---------------------" | |
4224 | ovn-nbctl list logical_router_port | |
4225 | echo "---------------------" | |
4226 | ||
4227 | echo "---------SB dump-----" | |
4228 | ovn-sbctl list datapath_binding | |
4229 | echo "---------------------" | |
4230 | ovn-sbctl list port_binding | |
4231 | echo "---------------------" | |
4232 | ovn-sbctl dump-flows | |
4233 | echo "---------------------" | |
4234 | ovn-sbctl list chassis | |
4235 | ovn-sbctl list encap | |
4236 | echo "---------------------" | |
4237 | ||
c1645003 GS |
4238 | # Packet to Expect at alice1 |
4239 | src_mac="000002010203" | |
4240 | dst_mac="f00000010204" | |
4241 | src_ip=`ip_to_hex 192 168 1 2` | |
4242 | dst_ip=`ip_to_hex 172 16 1 2` | |
4243 | expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000 | |
4244 | ||
4245 | ||
4246 | as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet | |
4247 | as hv1 ovs-appctl ofproto/trace br-int in_port=1 $packet | |
4248 | ||
ab39371d RM |
4249 | echo "------ hv1 dump after packet 1 ----------" |
4250 | as hv1 ovs-ofctl show br-int | |
4251 | as hv1 ovs-ofctl dump-flows br-int | |
4252 | echo "------ hv2 dump after packet 1 ----------" | |
4253 | as hv2 ovs-ofctl show br-int | |
4254 | as hv2 ovs-ofctl dump-flows br-int | |
4255 | echo "----------------------------" | |
4256 | ||
49d7c759 BP |
4257 | echo $expected > expected |
4258 | OVN_CHECK_PACKETS([hv2/vif1-tx.pcap], [expected]) | |
c1645003 | 4259 | |
34114cf8 GS |
4260 | # Delete the router and re-create it. Things should work as before. |
4261 | ovn-nbctl lr-del R2 | |
4262 | ovn-nbctl create Logical_Router name=R2 options:chassis="hv2" | |
4263 | # Connect alice to R2 | |
4264 | ovn-nbctl lrp-add R2 alice 00:00:02:01:02:03 172.16.1.1/24 | |
4265 | # Connect R2 to join | |
4266 | ovn-nbctl lrp-add R2 R2_join 00:00:04:01:02:04 20.0.0.2/24 | |
4267 | ||
4268 | ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \ | |
4269 | ip_prefix=192.168.1.0/24 nexthop=20.0.0.1 -- add Logical_Router \ | |
4270 | R2 static_routes @lrt | |
4271 | ||
4272 | # Wait for ovn-controller to catch up. | |
4273 | sleep 1 | |
4274 | ||
4275 | # Send the packet again. | |
4276 | as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet | |
ab39371d RM |
4277 | |
4278 | echo "------ hv1 dump after packet 2 ----------" | |
4279 | as hv1 ovs-ofctl show br-int | |
4280 | as hv1 ovs-ofctl dump-flows br-int | |
4281 | echo "------ hv2 dump after packet 2 ----------" | |
4282 | as hv2 ovs-ofctl show br-int | |
4283 | as hv2 ovs-ofctl dump-flows br-int | |
4284 | echo "----------------------------" | |
4285 | ||
49d7c759 BP |
4286 | echo $expected >> expected |
4287 | OVN_CHECK_PACKETS([hv2/vif1-tx.pcap], [expected]) | |
34114cf8 | 4288 | |
7a8f15e0 | 4289 | OVN_CLEANUP([hv1],[hv2]) |
c1645003 GS |
4290 | |
4291 | AT_CLEANUP | |
bb3c4568 FF |
4292 | |
4293 | AT_SETUP([ovn -- icmp_reply: 1 HVs, 2 LSs, 1 lport/LS, 1 LR]) | |
4294 | AT_KEYWORDS([router-icmp-reply]) | |
4295 | AT_SKIP_IF([test $HAVE_PYTHON = no]) | |
4296 | ovn_start | |
4297 | ||
4298 | # Logical network: | |
4299 | # One LR - R1 has switch ls1 (191.168.1.0/24) connected to it, | |
4300 | # and has switch ls2 (172.16.1.0/24) connected to it. | |
4301 | ||
fa2a27b2 | 4302 | ovn-nbctl lr-add R1 |
bb3c4568 | 4303 | |
ea46a4e9 JP |
4304 | ovn-nbctl ls-add ls1 |
4305 | ovn-nbctl ls-add ls2 | |
bb3c4568 FF |
4306 | |
4307 | # Connect ls1 to R1 | |
31114af7 | 4308 | ovn-nbctl lrp-add R1 ls1 00:00:00:01:02:f1 192.168.1.1/24 |
31ed1192 | 4309 | ovn-nbctl lsp-add ls1 rp-ls1 -- set Logical_Switch_Port rp-ls1 \ |
80f408f4 | 4310 | type=router options:router-port=ls1 addresses=\"00:00:00:01:02:f1\" |
bb3c4568 FF |
4311 | |
4312 | # Connect ls2 to R1 | |
31114af7 | 4313 | ovn-nbctl lrp-add R1 ls2 00:00:00:01:02:f2 172.16.1.1/24 |
31ed1192 | 4314 | ovn-nbctl lsp-add ls2 rp-ls2 -- set Logical_Switch_Port rp-ls2 \ |
80f408f4 | 4315 | type=router options:router-port=ls2 addresses=\"00:00:00:01:02:f2\" |
bb3c4568 FF |
4316 | |
4317 | # Create logical port ls1-lp1 in ls1 | |
31ed1192 JP |
4318 | ovn-nbctl lsp-add ls1 ls1-lp1 \ |
4319 | -- lsp-set-addresses ls1-lp1 "00:00:00:01:02:03 192.168.1.2" | |
bb3c4568 FF |
4320 | |
4321 | # Create logical port ls2-lp1 in ls2 | |
31ed1192 JP |
4322 | ovn-nbctl lsp-add ls2 ls2-lp1 \ |
4323 | -- lsp-set-addresses ls2-lp1 "00:00:00:01:02:04 172.16.1.2" | |
bb3c4568 FF |
4324 | |
4325 | # Create one hypervisor and create OVS ports corresponding to logical ports. | |
4326 | net_add n1 | |
4327 | ||
4328 | sim_add hv1 | |
4329 | as hv1 | |
4330 | ovs-vsctl add-br br-phys | |
4331 | ovn_attach n1 br-phys 192.168.0.1 | |
4332 | ovs-vsctl -- add-port br-int vif1 -- \ | |
4333 | set interface vif1 external-ids:iface-id=ls1-lp1 \ | |
4334 | options:tx_pcap=hv1/vif1-tx.pcap \ | |
4335 | options:rxq_pcap=hv1/vif1-rx.pcap \ | |
4336 | ofport-request=1 | |
4337 | ||
4338 | ovs-vsctl -- add-port br-int vif2 -- \ | |
4339 | set interface vif2 external-ids:iface-id=ls2-lp1 \ | |
4340 | options:tx_pcap=hv1/vif2-tx.pcap \ | |
4341 | options:rxq_pcap=hv1/vif2-rx.pcap \ | |
4342 | ofport-request=1 | |
4343 | ||
4344 | ||
4345 | # Allow some time for ovn-northd and ovn-controller to catch up. | |
4346 | # XXX This should be more systematic. | |
4347 | sleep 1 | |
4348 | ||
4349 | ||
4350 | ip_to_hex() { | |
4351 | printf "%02x%02x%02x%02x" "$@" | |
4352 | } | |
bb3c4568 FF |
4353 | for i in 1 2; do |
4354 | : > vif$i.expected | |
4355 | done | |
4356 | # test_ipv4_icmp_request INPORT ETH_SRC ETH_DST IPV4_SRC IPV4_DST IP_CHKSUM ICMP_CHKSUM [EXP_IP_CHKSUM EXP_ICMP_CHKSUM] | |
4357 | # | |
4358 | # Causes a packet to be received on INPORT. The packet is an ICMPv4 | |
4359 | # request with ETH_SRC, ETH_DST, IPV4_SRC, IPV4_DST, IP_CHSUM and | |
4360 | # ICMP_CHKSUM as specified. If EXP_IP_CHKSUM and EXP_ICMP_CHKSUM are | |
4361 | # provided, then it should be the ip and icmp checksums of the packet | |
4362 | # responded; otherwise, no reply is expected. | |
4363 | # In the absence of an ip checksum calculation helpers, this relies | |
4364 | # on the caller to provide the checksums for the ip and icmp headers. | |
4365 | # XXX This should be more systematic. | |
4366 | # | |
4367 | # INPORT is an lport number, e.g. 11 for vif11. | |
4368 | # ETH_SRC and ETH_DST are each 12 hex digits. | |
4369 | # IPV4_SRC and IPV4_DST are each 8 hex digits. | |
4370 | # IP_CHSUM and ICMP_CHKSUM are each 4 hex digits. | |
4371 | # EXP_IP_CHSUM and EXP_ICMP_CHKSUM are each 4 hex digits. | |
4372 | test_ipv4_icmp_request() { | |
4373 | local inport=$1 eth_src=$2 eth_dst=$3 ipv4_src=$4 ipv4_dst=$5 ip_chksum=$6 icmp_chksum=$7 | |
4374 | local exp_ip_chksum=$8 exp_icmp_chksum=$9 | |
4375 | shift; shift; shift; shift; shift; shift; shift | |
4376 | shift; shift | |
4377 | ||
4378 | # Use ttl to exercise section 4.2.2.9 of RFC1812 | |
4379 | local ip_ttl=01 | |
4380 | local icmp_id=5fbf | |
4381 | local icmp_seq=0001 | |
4382 | local icmp_data=$(seq 1 56 | xargs printf "%02x") | |
4383 | local icmp_type_code_request=0800 | |
4384 | local icmp_payload=${icmp_type_code_request}${icmp_chksum}${icmp_id}${icmp_seq}${icmp_data} | |
4385 | local packet=${eth_dst}${eth_src}08004500005400004000${ip_ttl}01${ip_chksum}${ipv4_src}${ipv4_dst}${icmp_payload} | |
4386 | ||
4387 | as hv1 ovs-appctl netdev-dummy/receive vif$inport $packet | |
4388 | if test X$exp_icmp_chksum != X; then | |
4389 | # Expect to receive the reply, if any. In same port where packet was sent. | |
4390 | # Note: src and dst fields are expected to be reversed. | |
4391 | local icmp_type_code_response=0000 | |
4392 | local reply_icmp_ttl=fe | |
4393 | local reply_icmp_payload=${icmp_type_code_response}${exp_icmp_chksum}${icmp_id}${icmp_seq}${icmp_data} | |
4394 | local reply=${eth_src}${eth_dst}08004500005400004000${reply_icmp_ttl}01${exp_ip_chksum}${ipv4_dst}${ipv4_src}${reply_icmp_payload} | |
4395 | echo $reply >> vif$inport.expected | |
4396 | fi | |
4397 | } | |
4398 | ||
4399 | # Send ping packet to router's ip addresses, from each of the 2 logical ports. | |
4400 | rtr_l1_ip=$(ip_to_hex 192 168 1 1) | |
4401 | rtr_l2_ip=$(ip_to_hex 172 16 1 1) | |
4402 | l1_ip=$(ip_to_hex 192 168 1 2) | |
4403 | l2_ip=$(ip_to_hex 172 16 1 2) | |
4404 | ||
4405 | # Ping router ip address that is on same subnet as the logical port | |
4406 | test_ipv4_icmp_request 1 000000010203 0000000102f1 $l1_ip $rtr_l1_ip 0000 8510 02ff 8d10 | |
4407 | test_ipv4_icmp_request 2 000000010204 0000000102f2 $l2_ip $rtr_l2_ip 0000 8510 02ff 8d10 | |
4408 | ||
4409 | # Ping router ip address that is on the other side of the logical ports | |
4410 | test_ipv4_icmp_request 1 000000010203 0000000102f1 $l1_ip $rtr_l2_ip 0000 8510 02ff 8d10 | |
4411 | test_ipv4_icmp_request 2 000000010204 0000000102f2 $l2_ip $rtr_l1_ip 0000 8510 02ff 8d10 | |
4412 | ||
4413 | echo "---------NB dump-----" | |
4414 | ovn-nbctl show | |
4415 | echo "---------------------" | |
4416 | ovn-nbctl list logical_router | |
4417 | echo "---------------------" | |
4418 | ovn-nbctl list logical_router_port | |
4419 | echo "---------------------" | |
4420 | ||
4421 | echo "---------SB dump-----" | |
4422 | ovn-sbctl list datapath_binding | |
4423 | echo "---------------------" | |
4424 | ovn-sbctl list logical_flow | |
4425 | echo "---------------------" | |
4426 | ||
4427 | echo "------ hv1 dump ----------" | |
4428 | as hv1 ovs-ofctl dump-flows br-int | |
4429 | ||
4430 | # Now check the packets actually received against the ones expected. | |
4431 | for inport in 1 2; do | |
49d7c759 | 4432 | OVN_CHECK_PACKETS([hv1/vif${inport}-tx.pcap], [vif$inport.expected]) |
bb3c4568 FF |
4433 | done |
4434 | ||
7a8f15e0 | 4435 | OVN_CLEANUP([hv1]) |
bb3c4568 FF |
4436 | |
4437 | AT_CLEANUP | |
94f79fcb RB |
4438 | |
4439 | # 1 hypervisor, 1 port | |
4440 | # make sure that the port state is properly set to up and back down | |
4441 | # when created and deleted. | |
4442 | AT_SETUP([ovn -- port state up and down]) | |
94f79fcb RB |
4443 | ovn_start |
4444 | ||
4445 | ovn-nbctl ls-add ls1 | |
4446 | ovn-nbctl lsp-add ls1 lp1 | |
4447 | ovn-nbctl lsp-set-addresses lp1 unknown | |
4448 | ||
4449 | net_add n1 | |
4450 | sim_add hv1 | |
4451 | as hv1 ovs-vsctl add-br br-phys | |
4452 | as hv1 ovn_attach n1 br-phys 192.168.0.1 | |
4453 | ||
4454 | as hv1 ovs-vsctl add-port br-int vif1 -- set Interface vif1 external-ids:iface-id=lp1 | |
4455 | OVS_WAIT_UNTIL([test x`ovn-nbctl lsp-get-up lp1` = xup]) | |
4456 | ||
4457 | as hv1 ovs-vsctl del-port br-int vif1 | |
4458 | OVS_WAIT_UNTIL([test x`ovn-nbctl lsp-get-up lp1` = xdown]) | |
4459 | ||
7a8f15e0 | 4460 | OVN_CLEANUP([hv1]) |
94f79fcb | 4461 | |
94f79fcb | 4462 | AT_CLEANUP |
e75451fe | 4463 | |
ccc6e1db FF |
4464 | # 1 hypervisor, 1 port |
4465 | # make sure that the OF rules created to support a datapath are added/cleared | |
4466 | # when logical switch is created and removed. | |
4467 | AT_SETUP([ovn -- datapath rules added/removed]) | |
1794d5f2 | 4468 | AT_KEYWORDS([cleanup]) |
ccc6e1db FF |
4469 | ovn_start |
4470 | ||
4471 | net_add n1 | |
4472 | sim_add hv1 | |
4473 | as hv1 ovs-vsctl add-br br-phys | |
4474 | as hv1 ovn_attach n1 br-phys 192.168.0.1 | |
4475 | ||
4476 | # This shell function checks if OF rules in br-int have clauses | |
4477 | # related to OVN datapaths. The caller determines if it should find | |
4478 | # a match in the output, or not. | |
4479 | # | |
4480 | # EXPECT_DATAPATH param determines whether flows that refer to | |
4481 | # datapath to should be present or not. 0 means | |
4482 | # they should not be. | |
4483 | # STAGE_INFO param is a simple string to help identify the stage | |
4484 | # in the test when this function was invoked. | |
4485 | test_datapath_in_of_rules() { | |
4486 | local expect_datapath=$1 stage_info=$2 | |
4487 | echo "------ ovn-nbctl show ${stage_info} ------" | |
4488 | ovn-nbctl show | |
4489 | echo "------ ovn-sbctl show ${stage_info} ------" | |
4490 | ovn-sbctl show | |
4491 | echo "------ OF rules ${stage_info} ------" | |
4492 | AT_CHECK([ovs-ofctl dump-flows br-int], [0], [stdout]) | |
4493 | # if there is a datapath mentioned in the output, check for the | |
4494 | # magic keyword that represents one, based on the exit status of | |
4495 | # a quiet grep | |
4496 | if test $expect_datapath != 0; then | |
4618b102 | 4497 | AT_CHECK([grep -q -i 'metadata=' stdout], [0], [ignore-nolog]) |
ccc6e1db | 4498 | else |
4618b102 | 4499 | AT_CHECK([grep -q -i 'metadata=' stdout], [1], [ignore-nolog]) |
ccc6e1db FF |
4500 | fi |
4501 | } | |
4502 | ||
4503 | test_datapath_in_of_rules 0 "before ls+port create" | |
4504 | ||
4505 | ovn-nbctl ls-add ls1 | |
4506 | ovn-nbctl lsp-add ls1 lp1 | |
4507 | ovn-nbctl lsp-set-addresses lp1 unknown | |
4508 | ||
4509 | as hv1 ovs-vsctl add-port br-int vif1 -- set Interface vif1 external-ids:iface-id=lp1 | |
4510 | OVS_WAIT_UNTIL([test x`ovn-nbctl lsp-get-up lp1` = xup]) | |
4511 | ||
4512 | test_datapath_in_of_rules 1 "after port is bound" | |
4513 | ||
4514 | as hv1 ovs-vsctl del-port br-int vif1 | |
4515 | OVS_WAIT_UNTIL([test x`ovn-nbctl lsp-get-up lp1` = xdown]) | |
4516 | ||
4517 | ovn-nbctl lsp-set-addresses lp1 | |
4518 | ovn-nbctl lsp-del lp1 | |
4519 | ovn-nbctl ls-del ls1 | |
4520 | ||
4521 | # wait for earlier changes to take effect | |
4522 | AT_CHECK([ovn-nbctl --timeout=3 --wait=sb sync], [0], [ignore]) | |
4523 | ||
4524 | # ensure OF rules are no longer present. There used to be a bug here. | |
4525 | test_datapath_in_of_rules 0 "after lport+ls removal" | |
4526 | ||
4527 | OVN_CLEANUP([hv1]) | |
4528 | ||
4529 | AT_CLEANUP | |
4530 | ||
f8a8db39 | 4531 | AT_SETUP([ovn -- nd_na ]) |
e75451fe ZKL |
4532 | AT_SKIP_IF([test $HAVE_PYTHON = no]) |
4533 | ovn_start | |
4534 | ||
4535 | #TODO: since patch port for IPv6 logical router port is not ready not, | |
4536 | # so we are not going to test vifs on different lswitches cases. Try | |
4537 | # to update for that once relevant stuff implemented. | |
4538 | ||
4539 | # In this test cases we create 1 lswitch, it has 2 VIF ports attached | |
4540 | # with. NS packet we test, from one VIF for another VIF, will be replied | |
4541 | # by local ovn-controller, but not by target VIF. | |
4542 | ||
4543 | # Create hypervisors and logical switch lsw0. | |
4544 | ovn-nbctl ls-add lsw0 | |
4545 | net_add n1 | |
4546 | sim_add hv1 | |
4547 | as hv1 | |
4548 | ovs-vsctl add-br br-phys | |
4549 | ovn_attach n1 br-phys 192.168.0.2 | |
4550 | ||
4551 | # Add vif1 to hv1 and lsw0, turn on l2 port security on vif1. | |
4552 | 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 | |
4553 | ovn-nbctl lsp-add lsw0 lp1 | |
4554 | ovn-nbctl lsp-set-addresses lp1 "fa:16:3e:94:05:98 192.168.0.3 fd81:ce49:a948:0:f816:3eff:fe94:598" | |
4555 | 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" | |
4556 | ||
4557 | # Add vif2 to hv1 and lsw0, turn on l2 port security on vif2. | |
4558 | 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 | |
4559 | ovn-nbctl lsp-add lsw0 lp2 | |
4560 | ovn-nbctl lsp-set-addresses lp2 "fa:16:3e:a1:f9:ae 192.168.0.4 fd81:ce49:a948:0:f816:3eff:fea1:f9ae" | |
4561 | 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" | |
4562 | ||
4563 | # Add ACL rule for ICMPv6 on lsw0 | |
4564 | ovn-nbctl acl-add lsw0 from-lport 1002 'ip6 && icmp6' allow-related | |
4565 | ovn-nbctl acl-add lsw0 to-lport 1002 'outport == "lp1" && ip6 && icmp6' allow-related | |
4566 | ovn-nbctl acl-add lsw0 to-lport 1002 'outport == "lp2" && ip6 && icmp6' allow-related | |
4567 | ||
4568 | # Allow some time for ovn-northd and ovn-controller to catch up. | |
4569 | # XXX This should be more systematic. | |
4570 | sleep 1 | |
4571 | ||
4572 | # Given the name of a logical port, prints the name of the hypervisor | |
4573 | # on which it is located. | |
4574 | vif_to_hv() { | |
4575 | echo hv1${1%?} | |
4576 | } | |
e75451fe ZKL |
4577 | for i in 1 2; do |
4578 | : > $i.expected | |
4579 | done | |
4580 | ||
4581 | # Complete Neighbor Solicitation packet and Neighbor Advertisement packet | |
4582 | # vif1 -> NS -> vif2. vif1 <- NA <- ovn-controller. | |
4583 | # vif2 will not receive NS packet, since ovn-controller will reply for it. | |
4584 | ns_packet=3333ffa1f9aefa163e94059886dd6000000000203afffd81ce49a9480000f8163efffe940598fd81ce49a9480000f8163efffea1f9ae8700e01160000000fd81ce49a9480000f8163efffea1f9ae0101fa163e940598 | |
4585 | na_packet=fa163e940598fa163ea1f9ae86dd6000000000203afffd81ce49a9480000f8163efffea1f9aefd81ce49a9480000f8163efffe9405988800e9ed60000000fd81ce49a9480000f8163efffea1f9ae0201fa163ea1f9ae | |
4586 | ||
4587 | as hv1 ovs-appctl netdev-dummy/receive vif1 $ns_packet | |
e4543cfe | 4588 | echo $na_packet >> 1.expected |
e75451fe | 4589 | |
e75451fe ZKL |
4590 | echo "------ hv1 dump ------" |
4591 | as hv1 ovs-vsctl show | |
4592 | as hv1 ovs-ofctl -O OpenFlow13 show br-int | |
4593 | as hv1 ovs-ofctl -O OpenFlow13 dump-flows br-int | |
4594 | ||
4595 | for i in 1 2; do | |
49d7c759 | 4596 | OVN_CHECK_PACKETS([hv1/vif$i-tx.pcap], [$i.expected]) |
e75451fe ZKL |
4597 | done |
4598 | ||
7a8f15e0 | 4599 | OVN_CLEANUP([hv1]) |
e75451fe ZKL |
4600 | |
4601 | AT_CLEANUP | |
7417d147 RM |
4602 | |
4603 | AT_SETUP([ovn -- address sets modification/removal smoke test]) | |
7417d147 RM |
4604 | ovn_start |
4605 | ||
4606 | net_add n1 | |
4607 | ||
4608 | sim_add hv1 | |
4609 | as hv1 | |
4610 | ovs-vsctl add-br br-phys | |
4611 | ovn_attach n1 br-phys 192.168.0.1 | |
4612 | ||
4613 | row=`ovn-nbctl create Address_Set name=set1 addresses=\"1.1.1.1\"` | |
4614 | ovn-nbctl set Address_Set $row name=set1 addresses=\"1.1.1.1,1.1.1.2\" | |
4615 | ovn-nbctl destroy Address_Set $row | |
4616 | ||
4617 | sleep 1 | |
4618 | ||
4619 | # A bug previously existed in the address set support code | |
4620 | # that caused ovn-controller to crash after an address set | |
4621 | # was updated and then removed. This test case ensures | |
4622 | # that ovn-controller is at least still running after | |
4623 | # creating, updating, and deleting an address set. | |
4624 | AT_CHECK([ovs-appctl -t ovn-controller version], [0], [ignore]) | |
4625 | ||
4626 | OVN_CLEANUP([hv1]) | |
4627 | ||
4628 | AT_CLEANUP | |
8639f9be ND |
4629 | |
4630 | AT_SETUP([ovn -- ipam]) | |
8639f9be ND |
4631 | AT_SKIP_IF([test $HAVE_PYTHON = no]) |
4632 | ovn_start | |
4633 | ||
4634 | # Add a port to a switch that does not have a subnet set, then set the | |
4635 | # subnet which should result in an address being allocated for the port. | |
4636 | ovn-nbctl ls-add sw0 | |
4637 | ovn-nbctl lsp-add sw0 p0 -- lsp-set-addresses p0 dynamic | |
fd3b31e9 | 4638 | ovn-nbctl --wait=sb add Logical-Switch sw0 other_config subnet=192.168.1.0/24 |
8639f9be ND |
4639 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p0 dynamic_addresses], [0], |
4640 | ["0a:00:00:00:00:01 192.168.1.2" | |
4641 | ]) | |
4642 | ||
4643 | # Add 9 more ports to sw0, addresses should all be unique. | |
4644 | for n in `seq 1 9`; do | |
11547f85 | 4645 | ovn-nbctl --wait=sb lsp-add sw0 "p$n" -- lsp-set-addresses "p$n" dynamic |
8639f9be ND |
4646 | done |
4647 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p1 dynamic_addresses], [0], | |
4648 | ["0a:00:00:00:00:02 192.168.1.3" | |
4649 | ]) | |
4650 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p2 dynamic_addresses], [0], | |
4651 | ["0a:00:00:00:00:03 192.168.1.4" | |
4652 | ]) | |
4653 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p3 dynamic_addresses], [0], | |
4654 | ["0a:00:00:00:00:04 192.168.1.5" | |
4655 | ]) | |
4656 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p4 dynamic_addresses], [0], | |
4657 | ["0a:00:00:00:00:05 192.168.1.6" | |
4658 | ]) | |
4659 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p5 dynamic_addresses], [0], | |
4660 | ["0a:00:00:00:00:06 192.168.1.7" | |
4661 | ]) | |
4662 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p6 dynamic_addresses], [0], | |
4663 | ["0a:00:00:00:00:07 192.168.1.8" | |
4664 | ]) | |
4665 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p7 dynamic_addresses], [0], | |
4666 | ["0a:00:00:00:00:08 192.168.1.9" | |
4667 | ]) | |
4668 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p8 dynamic_addresses], [0], | |
4669 | ["0a:00:00:00:00:09 192.168.1.10" | |
4670 | ]) | |
4671 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p9 dynamic_addresses], [0], | |
4672 | ["0a:00:00:00:00:0a 192.168.1.11" | |
4673 | ]) | |
4674 | ||
4675 | # Trying similar tests with a second switch. MAC addresses should be unique | |
4676 | # across both switches but IP's only need to be unique within the same switch. | |
4677 | ovn-nbctl ls-add sw1 | |
4678 | ovn-nbctl lsp-add sw1 p10 -- lsp-set-addresses p10 dynamic | |
11547f85 | 4679 | ovn-nbctl --wait=sb add Logical-Switch sw1 other_config subnet=192.168.1.0/24 |
8639f9be ND |
4680 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p10 dynamic_addresses], [0], |
4681 | ["0a:00:00:00:00:0b 192.168.1.2" | |
4682 | ]) | |
4683 | ||
4684 | for n in `seq 11 19`; do | |
11547f85 | 4685 | ovn-nbctl --wait=sb lsp-add sw1 "p$n" -- lsp-set-addresses "p$n" dynamic |
8639f9be ND |
4686 | done |
4687 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p11 dynamic_addresses], [0], | |
4688 | ["0a:00:00:00:00:0c 192.168.1.3" | |
4689 | ]) | |
4690 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p12 dynamic_addresses], [0], | |
4691 | ["0a:00:00:00:00:0d 192.168.1.4" | |
4692 | ]) | |
4693 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p13 dynamic_addresses], [0], | |
4694 | ["0a:00:00:00:00:0e 192.168.1.5" | |
4695 | ]) | |
4696 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p14 dynamic_addresses], [0], | |
4697 | ["0a:00:00:00:00:0f 192.168.1.6" | |
4698 | ]) | |
4699 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p15 dynamic_addresses], [0], | |
4700 | ["0a:00:00:00:00:10 192.168.1.7" | |
4701 | ]) | |
4702 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p16 dynamic_addresses], [0], | |
4703 | ["0a:00:00:00:00:11 192.168.1.8" | |
4704 | ]) | |
4705 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p17 dynamic_addresses], [0], | |
4706 | ["0a:00:00:00:00:12 192.168.1.9" | |
4707 | ]) | |
4708 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p18 dynamic_addresses], [0], | |
4709 | ["0a:00:00:00:00:13 192.168.1.10" | |
4710 | ]) | |
4711 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p19 dynamic_addresses], [0], | |
4712 | ["0a:00:00:00:00:14 192.168.1.11" | |
4713 | ]) | |
4714 | ||
4715 | # Change a port's address to test for multiple ip's for a single address entry | |
4716 | # and addresses set by the user. | |
4717 | ovn-nbctl lsp-set-addresses p0 "0a:00:00:00:00:15 192.168.1.12 192.168.1.14" | |
11547f85 | 4718 | ovn-nbctl --wait=sb lsp-add sw0 p20 -- lsp-set-addresses p20 dynamic |
8639f9be ND |
4719 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p20 dynamic_addresses], [0], |
4720 | ["0a:00:00:00:00:16 192.168.1.13" | |
4721 | ]) | |
4722 | ||
4723 | # Test for logical router port address management. | |
4724 | ovn-nbctl create Logical_Router name=R1 | |
4725 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=sw0 \ | |
4726 | network="192.168.1.1/24" mac=\"0a:00:00:00:00:17\" \ | |
4727 | -- add Logical_Router R1 ports @lrp -- lsp-add sw0 rp-sw0 \ | |
4728 | -- set Logical_Switch_Port rp-sw0 type=router options:router-port=sw0 | |
11547f85 | 4729 | ovn-nbctl --wait=sb lsp-add sw0 p21 -- lsp-set-addresses p21 dynamic |
8639f9be ND |
4730 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p21 dynamic_addresses], [0], |
4731 | ["0a:00:00:00:00:18 192.168.1.15" | |
4732 | ]) | |
4733 | ||
4734 | # Test for address reuse after logical port is deleted. | |
4735 | ovn-nbctl lsp-del p0 | |
11547f85 | 4736 | ovn-nbctl --wait=sb lsp-add sw0 p23 -- lsp-set-addresses p23 dynamic |
8639f9be ND |
4737 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p23 dynamic_addresses], [0], |
4738 | ["0a:00:00:00:00:19 192.168.1.2" | |
4739 | ]) | |
4740 | ||
4741 | # Test for multiple addresses to one logical port. | |
4742 | ovn-nbctl lsp-add sw0 p25 -- lsp-set-addresses p25 \ | |
4743 | "0a:00:00:00:00:1a 192.168.1.12" "0a:00:00:00:00:1b 192.168.1.14" | |
11547f85 | 4744 | ovn-nbctl --wait=sb lsp-add sw0 p26 -- lsp-set-addresses p26 dynamic |
8639f9be ND |
4745 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p26 dynamic_addresses], [0], |
4746 | ["0a:00:00:00:00:1c 192.168.1.16" | |
4747 | ]) | |
4748 | ||
4749 | # Test for exhausting subnet address space. | |
4750 | ovn-nbctl ls-add sw2 -- add Logical-Switch sw2 other_config subnet=172.16.1.0/30 | |
11547f85 | 4751 | ovn-nbctl --wait=sb lsp-add sw2 p27 -- lsp-set-addresses p27 dynamic |
8639f9be ND |
4752 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p27 dynamic_addresses], [0], |
4753 | ["0a:00:00:00:00:1d 172.16.1.2" | |
4754 | ]) | |
4755 | ||
11547f85 | 4756 | ovn-nbctl --wait=sb lsp-add sw2 p28 -- lsp-set-addresses p28 dynamic |
8639f9be ND |
4757 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p28 dynamic_addresses], [0], |
4758 | [[[]] | |
4759 | ]) | |
4760 | ||
4761 | # Test that address management does not add duplicate MAC for lsp/lrp peers. | |
4762 | ovn-nbctl create Logical_Router name=R2 | |
4763 | ovn-nbctl ls-add sw3 | |
4764 | ovn-nbctl lsp-add sw3 p29 -- lsp-set-addresses p29 \ | |
4765 | "0a:00:00:00:00:1e" | |
4766 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=sw3 \ | |
4767 | network="192.168.2.1/24" mac=\"0a:00:00:00:00:1f\" \ | |
4768 | -- add Logical_Router R2 ports @lrp -- lsp-add sw3 rp-sw3 \ | |
4769 | -- set Logical_Switch_Port rp-sw3 type=router options:router-port=sw3 | |
11547f85 | 4770 | ovn-nbctl --wait=sb lsp-add sw0 p30 -- lsp-set-addresses p30 dynamic |
8639f9be ND |
4771 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p30 dynamic_addresses], [0], |
4772 | ["0a:00:00:00:00:20 192.168.1.17" | |
4773 | ]) | |
4774 | ||
6374d518 LR |
4775 | # Test static MAC address with dynamically allocated IP |
4776 | ovn-nbctl --wait=sb lsp-add sw0 p31 -- lsp-set-addresses p31 \ | |
4777 | "fe:dc:ba:98:76:54 dynamic" | |
4778 | AT_CHECK([ovn-nbctl get Logical-Switch-Port p31 dynamic_addresses], [0], | |
4779 | ["fe:dc:ba:98:76:54 192.168.1.18" | |
4780 | ]) | |
4781 | ||
8639f9be ND |
4782 | as ovn-sb |
4783 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
4784 | ||
4785 | as ovn-nb | |
4786 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
4787 | ||
4788 | as northd | |
4789 | OVS_APP_EXIT_AND_WAIT([ovn-northd]) | |
4790 | ||
4791 | AT_CLEANUP | |
4792 | ||
4793 | AT_SETUP([ovn -- ipam connectivity]) | |
8639f9be ND |
4794 | AT_SKIP_IF([test $HAVE_PYTHON = no]) |
4795 | ovn_start | |
4796 | ||
4797 | ovn-nbctl lr-add R1 | |
4798 | ||
4799 | # Test for a ping using dynamically allocated addresses. | |
4800 | ovn-nbctl ls-add foo -- add Logical_Switch foo other_config subnet=192.168.1.0/24 | |
4801 | ovn-nbctl ls-add alice -- add Logical_Switch alice other_config subnet=192.168.2.0/24 | |
4802 | ||
4803 | # Connect foo to R1 | |
4804 | ovn-nbctl lrp-add R1 foo 00:00:00:01:02:03 192.168.1.1/24 | |
4805 | ovn-nbctl lsp-add foo rp-foo -- set Logical_Switch_Port rp-foo type=router \ | |
4806 | options:router-port=foo addresses=\"00:00:00:01:02:03\" | |
4807 | ||
4808 | # Connect alice to R1 | |
4809 | ovn-nbctl lrp-add R1 alice 00:00:00:01:02:04 192.168.2.1/24 | |
4810 | ovn-nbctl lsp-add alice rp-alice -- set Logical_Switch_Port rp-alice type=router \ | |
4811 | options:router-port=alice addresses=\"00:00:00:01:02:04\" | |
4812 | ||
4813 | # Create logical port foo1 in foo | |
fd3b31e9 | 4814 | ovn-nbctl --wait=sb lsp-add foo foo1 \ |
8639f9be | 4815 | -- lsp-set-addresses foo1 "dynamic" |
8bc2c143 | 4816 | AT_CHECK([ovn-nbctl --timeout=10 wait-until Logical-Switch-Port foo1 dynamic_addresses='"0a:00:00:00:00:01 192.168.1.2"'], [0]) |
8639f9be ND |
4817 | |
4818 | # Create logical port alice1 in alice | |
fd3b31e9 | 4819 | ovn-nbctl --wait=sb lsp-add alice alice1 \ |
8639f9be | 4820 | -- lsp-set-addresses alice1 "dynamic" |
8bc2c143 | 4821 | AT_CHECK([ovn-nbctl --timeout=10 wait-until Logical-Switch-Port alice1 dynamic_addresses='"0a:00:00:00:00:02 192.168.2.2"']) |
8639f9be ND |
4822 | |
4823 | # Create logical port foo2 in foo | |
fd3b31e9 | 4824 | ovn-nbctl --wait=sb lsp-add foo foo2 \ |
8639f9be | 4825 | -- lsp-set-addresses foo2 "dynamic" |
8bc2c143 | 4826 | AT_CHECK([ovn-nbctl --timeout=10 wait-until Logical-Switch-Port foo2 dynamic_addresses='"0a:00:00:00:00:03 192.168.1.3"']) |
8639f9be ND |
4827 | |
4828 | # Create a hypervisor and create OVS ports corresponding to logical ports. | |
4829 | net_add n1 | |
4830 | ||
4831 | sim_add hv1 | |
4832 | as hv1 | |
4833 | ovs-vsctl add-br br-phys | |
4834 | ovn_attach n1 br-phys 192.168.0.1 | |
4835 | ovs-vsctl -- add-port br-int hv1-vif1 -- \ | |
4836 | set interface hv1-vif1 external-ids:iface-id=foo1 \ | |
4837 | options:tx_pcap=hv1/vif1-tx.pcap \ | |
4838 | options:rxq_pcap=hv1/vif1-rx.pcap \ | |
4839 | ofport-request=1 | |
4840 | ||
4841 | ovs-vsctl -- add-port br-int hv1-vif2 -- \ | |
4842 | set interface hv1-vif2 external-ids:iface-id=foo2 \ | |
4843 | options:tx_pcap=hv1/vif2-tx.pcap \ | |
4844 | options:rxq_pcap=hv1/vif2-rx.pcap \ | |
4845 | ofport-request=2 | |
4846 | ||
4847 | ovs-vsctl -- add-port br-int hv1-vif3 -- \ | |
4848 | set interface hv1-vif3 external-ids:iface-id=alice1 \ | |
4849 | options:tx_pcap=hv1/vif3-tx.pcap \ | |
4850 | options:rxq_pcap=hv1/vif3-rx.pcap \ | |
4851 | ofport-request=3 | |
4852 | ||
4853 | # Allow some time for ovn-northd and ovn-controller to catch up. | |
4854 | # XXX This should be more systematic. | |
4855 | sleep 1 | |
4856 | ||
4857 | ip_to_hex() { | |
4858 | printf "%02x%02x%02x%02x" "$@" | |
4859 | } | |
8639f9be ND |
4860 | |
4861 | # Send ip packets between foo1 and foo2 | |
4862 | src_mac="0a0000000001" | |
4863 | dst_mac="0a0000000003" | |
4864 | src_ip=`ip_to_hex 192 168 1 2` | |
4865 | dst_ip=`ip_to_hex 192 168 1 3` | |
4866 | packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
4867 | as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet | |
4868 | ||
4869 | # Send ip packets between foo1 and alice1 | |
4870 | src_mac="0a0000000001" | |
4871 | dst_mac="000000010203" | |
4872 | src_ip=`ip_to_hex 192 168 1 2` | |
4873 | dst_ip=`ip_to_hex 192 168 2 2` | |
4874 | packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
4875 | as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet | |
4876 | ||
4877 | echo "---------NB dump-----" | |
4878 | ovn-nbctl show | |
4879 | echo "---------------------" | |
4880 | ovn-nbctl list logical_router | |
4881 | echo "---------------------" | |
4882 | ovn-nbctl list logical_router_port | |
4883 | echo "---------------------" | |
4884 | ||
4885 | echo "---------SB dump-----" | |
4886 | ovn-sbctl list datapath_binding | |
4887 | echo "---------------------" | |
4888 | ovn-sbctl list port_binding | |
4889 | echo "---------------------" | |
4890 | ||
4891 | echo "------ hv1 dump ----------" | |
4892 | as hv1 ovs-ofctl dump-flows br-int | |
4893 | ||
4894 | # Packet to Expect at foo2 | |
4895 | src_mac="0a0000000001" | |
4896 | dst_mac="0a0000000003" | |
4897 | src_ip=`ip_to_hex 192 168 1 2` | |
4898 | dst_ip=`ip_to_hex 192 168 1 3` | |
4899 | expected=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
4900 | ||
e4543cfe DDP |
4901 | $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif2-tx.pcap > received1.packets |
4902 | echo $expected > expout | |
8639f9be ND |
4903 | AT_CHECK([cat received1.packets], [0], [expout]) |
4904 | ||
4905 | # Packet to Expect at alice1 | |
4906 | src_mac="000000010204" | |
4907 | dst_mac="0a0000000002" | |
4908 | src_ip=`ip_to_hex 192 168 1 2` | |
4909 | dst_ip=`ip_to_hex 192 168 2 2` | |
4910 | expected=${dst_mac}${src_mac}08004500001c000000003f110100${src_ip}${dst_ip}0035111100080000 | |
4911 | ||
e4543cfe DDP |
4912 | $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif3-tx.pcap > received2.packets |
4913 | echo $expected > expout | |
8639f9be ND |
4914 | AT_CHECK([cat received2.packets], [0], [expout]) |
4915 | ||
4916 | OVN_CLEANUP([hv1]) | |
4917 | ||
4918 | AT_CLEANUP | |
f5792c3f NS |
4919 | |
4920 | AT_SETUP([ovn -- ovs-vswitchd restart]) | |
1794d5f2 | 4921 | AT_KEYWORDS([vswitchd]) |
f5792c3f NS |
4922 | AT_SKIP_IF([test $HAVE_PYTHON = no]) |
4923 | ovn_start | |
4924 | ||
4925 | ovn-nbctl ls-add ls1 | |
4926 | ||
4927 | ovn-nbctl lsp-add ls1 ls1-lp1 \ | |
4928 | -- lsp-set-addresses ls1-lp1 "f0:00:00:00:00:01 10.0.0.4" | |
4929 | ||
4930 | ovn-nbctl lsp-set-port-security ls1-lp1 "f0:00:00:00:00:01 10.0.0.4" | |
4931 | ||
4932 | net_add n1 | |
4933 | sim_add hv1 | |
4934 | ||
4935 | as hv1 | |
4936 | ovs-vsctl add-br br-phys | |
4937 | ovn_attach n1 br-phys 192.168.0.1 | |
4938 | ovs-vsctl -- add-port br-int hv1-vif1 -- \ | |
4939 | set interface hv1-vif1 external-ids:iface-id=ls1-lp1 \ | |
4940 | options:tx_pcap=hv1/vif1-tx.pcap \ | |
4941 | options:rxq_pcap=hv1/vif1-rx.pcap \ | |
4942 | ofport-request=1 | |
4943 | ||
4944 | ovn_populate_arp | |
4945 | sleep 2 | |
4946 | ||
4947 | as hv1 ovs-vsctl show | |
4948 | ||
4949 | echo "---------------------" | |
4950 | ovn-sbctl dump-flows | |
4951 | echo "---------------------" | |
4952 | ||
4953 | echo "------ hv1 dump ----------" | |
4954 | as hv1 ovs-ofctl dump-flows br-int | |
4955 | total_flows=`as hv1 ovs-ofctl dump-flows br-int | wc -l` | |
4956 | ||
4957 | echo "Total flows before vswitchd restart = " $total_flows | |
4958 | ||
4959 | # Code taken from ovs-save utility | |
4960 | save_flows () { | |
4961 | echo "ovs-ofctl add-flows br-int - << EOF" > restore_flows.sh | |
4962 | as hv1 ovs-ofctl dump-flows "br-int" | sed -e '/NXST_FLOW/d' \ | |
4963 | -e 's/\(idle\|hard\)_age=[^,]*,//g' >> restore_flows.sh | |
4964 | echo "EOF" >> restore_flows.sh | |
4965 | } | |
4966 | ||
4967 | restart_vswitchd () { | |
4968 | restore_flows=$1 | |
4969 | ||
4970 | if test $restore_flows = true; then | |
4971 | save_flows | |
4972 | fi | |
4973 | ||
4974 | as hv1 | |
4975 | OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) | |
4976 | ||
4977 | if test $restore_flows = true; then | |
4978 | as hv1 | |
4979 | ovs-vsctl --no-wait set open_vswitch . other_config:flow-restore-wait="true" | |
4980 | fi | |
4981 | ||
4982 | as hv1 | |
4983 | start_daemon ovs-vswitchd --enable-dummy=system -vvconn -vofproto_dpif -vunixctl | |
4984 | ovs-ofctl dump-flows br-int | |
4985 | ||
4986 | if test $restore_flows = true; then | |
4987 | sh ./restore_flows.sh | |
4988 | echo "Flows after restore" | |
4989 | as hv1 | |
4990 | ovs-ofctl dump-flows br-int | |
4991 | ovs-vsctl --no-wait --if-exists remove open_vswitch . other_config \ | |
4992 | flow-restore-wait="true" | |
4993 | fi | |
4994 | } | |
4995 | ||
4996 | # Save the flows, restart vswitchd and restore the flows | |
4997 | restart_vswitchd true | |
4998 | OVS_WAIT_UNTIL([ | |
4999 | total_flows_after_restart=`as hv1 ovs-ofctl dump-flows br-int | wc -l` | |
5000 | echo "Total flows after vswitchd restart = " $total_flows_after_restart | |
5001 | test "${total_flows}" = "${total_flows_after_restart}" | |
5002 | ]) | |
5003 | ||
5004 | # Restart vswitchd without restoring | |
5005 | restart_vswitchd false | |
5006 | OVS_WAIT_UNTIL([ | |
5007 | total_flows_after_restart=`as hv1 ovs-ofctl dump-flows br-int | wc -l` | |
5008 | echo "Total flows after vswitchd restart = " $total_flows_after_restart | |
5009 | test "${total_flows}" = "${total_flows_after_restart}" | |
5010 | ]) | |
5011 | ||
5012 | OVN_CLEANUP([hv1]) | |
5013 | AT_CLEANUP | |
47021598 CSV |
5014 | |
5015 | AT_SETUP([ovn -- send arp for nexthop]) | |
47021598 CSV |
5016 | AT_SKIP_IF([test $HAVE_PYTHON = no]) |
5017 | ovn_start | |
5018 | ||
5019 | # Topology: Two LSs - ls1 and ls2 are connected via router r0 | |
5020 | ||
5021 | # Create logical switches | |
5022 | ovn-nbctl ls-add ls1 | |
5023 | ovn-nbctl ls-add ls2 | |
5024 | ||
5025 | # Create router | |
5026 | ovn-nbctl create Logical_Router name=lr0 | |
5027 | ||
5028 | # Add router ls1p1 port to gateway router | |
5029 | ovn-nbctl lrp-add lr0 lrp-ls1lp1 f0:00:00:00:00:01 192.168.0.1/24 | |
5030 | ovn-nbctl lsp-add ls1 ls1lp1 -- set Logical_Switch_Port ls1lp1 \ | |
5031 | type=router options:router-port=lrp-ls1lp1 \ | |
5032 | addresses='"f0:00:00:00:00:01 192.168.0.1"' | |
5033 | ||
5034 | # Add router ls2p2 port to gateway router | |
5035 | ovn-nbctl lrp-add lr0 lrp-ls2lp1 f0:00:00:00:00:02 192.168.1.1/24 | |
5036 | ovn-nbctl lsp-add ls2 ls2lp1 -- set Logical_Switch_Port ls2lp1 \ | |
5037 | type=router options:router-port=lrp-ls2lp1 \ | |
5038 | addresses='"f0:00:00:00:00:02 192.168.1.1"' | |
5039 | ||
5040 | # Set default gateway (nexthop) to 192.168.1.254 | |
5041 | ovn-nbctl lr-route-add lr0 "0.0.0.0/0" 192.168.1.254 lrp-ls2lp1 | |
5042 | ||
5043 | # Create logical port ls1lp2 in ls1 | |
5044 | ovn-nbctl lsp-add ls1 ls1lp2 \ | |
5045 | -- lsp-set-addresses ls1lp2 "f0:00:00:00:00:03 192.168.0.2" | |
5046 | ||
5047 | # Create logical port ls2lp2 in ls2 | |
5048 | ovn-nbctl lsp-add ls2 ls2lp2 \ | |
5049 | -- lsp-set-addresses ls2lp2 "f0:00:00:00:00:04 192.168.1.10" | |
5050 | ||
5051 | net_add n1 | |
5052 | sim_add hv1 | |
5053 | as hv1 | |
5054 | ovs-vsctl add-br br-phys | |
5055 | ovn_attach n1 br-phys 192.168.0.1 | |
5056 | ovs-vsctl -- add-port br-int hv1-ls1lp2 -- \ | |
5057 | set interface hv1-ls1lp2 external-ids:iface-id=ls1lp2 \ | |
5058 | options:tx_pcap=hv1/ls1lp2-tx.pcap \ | |
5059 | options:rxq_pcap=hv1/ls1lp2-rx.pcap \ | |
5060 | ofport-request=1 | |
5061 | ovs-vsctl -- add-port br-int hv1-ls2lp2 -- \ | |
5062 | set interface hv1-ls2lp2 external-ids:iface-id=ls2lp2 \ | |
5063 | options:tx_pcap=hv1/ls2lp2-tx.pcap \ | |
5064 | options:rxq_pcap=hv1/ls2lp2-rx.pcap \ | |
5065 | ofport-request=2 | |
5066 | ||
5067 | # Allow some time for ovn-northd and ovn-controller to catch up. | |
5068 | # XXX This should be more systematic. | |
5069 | sleep 1 | |
5070 | ||
5071 | echo "---------NB dump-----" | |
5072 | ovn-nbctl show | |
5073 | echo "---------------------" | |
5074 | ovn-nbctl list logical_router | |
5075 | echo "---------------------" | |
5076 | ovn-nbctl list logical_router_port | |
5077 | echo "---------------------" | |
5078 | ||
5079 | echo "---------SB dump-----" | |
5080 | ovn-sbctl list datapath_binding | |
5081 | echo "---------------------" | |
5082 | ovn-sbctl list port_binding | |
5083 | echo "---------------------" | |
5084 | ovn-sbctl dump-flows | |
5085 | echo "---------------------" | |
5086 | ovn-sbctl list chassis | |
5087 | ovn-sbctl list encap | |
5088 | echo "---------------------" | |
5089 | ||
5090 | echo "------Flows dump-----" | |
5091 | as hv1 | |
5092 | ovs-ofctl dump-flows | |
5093 | echo "---------------------" | |
5094 | ||
5095 | ip_to_hex() { | |
5096 | printf "%02x%02x%02x%02x" "$@" | |
5097 | } | |
5098 | ||
5099 | src_mac="f00000000003" | |
5100 | dst_mac="f00000000001" | |
5101 | src_ip=`ip_to_hex 192 168 0 2` | |
5102 | dst_ip=`ip_to_hex 8 8 8 8` | |
5103 | packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
5104 | ||
5105 | # Send IP packet destined to 8.8.8.8 from lsp1lp2 | |
5106 | as hv1 ovs-appctl netdev-dummy/receive hv1-ls1lp2 $packet | |
5107 | ||
5108 | trim_zeros() { | |
5109 | sed 's/\(00\)\{1,\}$//' | |
5110 | } | |
5111 | ||
5112 | # ARP packet should be received with Target IP Address set to 192.168.1.254 and | |
5113 | # not 8.8.8.8 | |
5114 | ||
5115 | $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/ls2lp2-tx.pcap | trim_zeros > packets | |
5116 | expected="fffffffffffff0000000000208060001080006040001f00000000002c0a80101000000000000c0a801fe" | |
5117 | echo $expected > expout | |
5118 | AT_CHECK([cat packets], [0], [expout]) | |
5119 | cat packets | |
5120 | ||
5121 | OVN_CLEANUP([hv1]) | |
5122 | ||
5123 | AT_CLEANUP | |
8439c2eb CSV |
5124 | |
5125 | AT_SETUP([ovn -- send gratuitous arp for nat ips in localnet]) | |
8439c2eb CSV |
5126 | AT_SKIP_IF([test $HAVE_PYTHON = no]) |
5127 | ovn_start | |
5128 | # Create logical switch | |
5129 | ovn-nbctl ls-add ls0 | |
5130 | # Create gateway router | |
5131 | ovn-nbctl create Logical_Router name=lr0 options:chassis=hv1 | |
5132 | # Add router port to gateway router | |
5133 | ovn-nbctl lrp-add lr0 lrp0 f0:00:00:00:00:01 192.168.0.1/24 | |
5134 | ovn-nbctl lsp-add ls0 lrp0-rp -- set Logical_Switch_Port lrp0-rp \ | |
5135 | type=router options:router-port=lrp0-rp addresses='"f0:00:00:00:00:01"' | |
5136 | # Add nat-address option | |
5137 | ovn-nbctl lsp-set-options lrp0-rp router-port=lrp0 nat-addresses="f0:00:00:00:00:01 192.168.0.2" | |
5138 | ||
5139 | net_add n1 | |
5140 | sim_add hv1 | |
5141 | as hv1 | |
5142 | ovs-vsctl \ | |
5143 | -- add-br br-phys \ | |
5144 | -- add-br br-eth0 | |
5145 | ||
5146 | ovn_attach n1 br-phys 192.168.0.1 | |
5147 | ||
5148 | AT_CHECK([ovs-vsctl set Open_vSwitch . external-ids:ovn-bridge-mappings=physnet1:br-eth0]) | |
5149 | AT_CHECK([ovs-vsctl add-port br-eth0 snoopvif -- set Interface snoopvif options:tx_pcap=hv1/snoopvif-tx.pcap options:rxq_pcap=hv1/snoopvif-rx.pcap]) | |
5150 | ||
5151 | # Create a localnet port. | |
5152 | AT_CHECK([ovn-nbctl lsp-add ls0 ln_port]) | |
5153 | AT_CHECK([ovn-nbctl lsp-set-addresses ln_port unknown]) | |
5154 | AT_CHECK([ovn-nbctl lsp-set-type ln_port localnet]) | |
5155 | AT_CHECK([ovn-nbctl lsp-set-options ln_port network_name=physnet1]) | |
5156 | ||
5157 | ||
5158 | # Wait for packet to be received. | |
5159 | OVS_WAIT_UNTIL([test `wc -c < "hv1/snoopvif-tx.pcap"` -ge 50]) | |
5160 | trim_zeros() { | |
5161 | sed 's/\(00\)\{1,\}$//' | |
5162 | } | |
5163 | $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/snoopvif-tx.pcap | trim_zeros > packets | |
5164 | expected="fffffffffffff0000000000108060001080006040001f00000000001c0a80002000000000000c0a80002" | |
5165 | echo $expected > expout | |
5166 | AT_CHECK([sort packets], [0], [expout]) | |
5167 | cat packets | |
5168 | ||
5169 | OVN_CLEANUP([hv1]) | |
5170 | ||
5171 | AT_CLEANUP | |
6e31816f CSV |
5172 | |
5173 | AT_SETUP([ovn -- delete mac bindings]) | |
6e31816f CSV |
5174 | ovn_start |
5175 | net_add n1 | |
5176 | sim_add hv1 | |
5177 | as hv1 | |
5178 | ovs-vsctl -- add-br br-phys | |
5179 | ovn_attach n1 br-phys 192.168.0.1 | |
5180 | # Create logical switch ls0 | |
5181 | ovn-nbctl ls-add ls0 | |
5182 | # Create ports lp0, lp1 in ls0 | |
5183 | ovn-nbctl lsp-add ls0 lp0 | |
5184 | ovn-nbctl lsp-add ls0 lp1 | |
5185 | ovn-nbctl lsp-set-addresses lp0 "f0:00:00:00:00:01 192.168.0.1" | |
5186 | ovn-nbctl lsp-set-addresses lp1 "f0:00:00:00:00:02 192.168.0.2" | |
5187 | dp_uuid=`ovn-sbctl find datapath | grep uuid | cut -f2 -d ":" | cut -f2 -d " "` | |
5188 | ovn-sbctl create MAC_Binding ip=10.0.0.1 datapath=$dp_uuid logical_port=lp0 mac="mac1" | |
5189 | ovn-sbctl create MAC_Binding ip=10.0.0.1 datapath=$dp_uuid logical_port=lp1 mac="mac2" | |
5190 | ovn-sbctl find MAC_Binding | |
093aa761 | 5191 | # Delete port lp0 and check that its MAC_Binding is deleted. |
6e31816f CSV |
5192 | ovn-nbctl lsp-del lp0 |
5193 | ovn-sbctl find MAC_Binding | |
093aa761 BP |
5194 | OVS_WAIT_UNTIL([test `ovn-sbctl find MAC_Binding logical_port=lp0 | wc -l` = 0]) |
5195 | # Delete logical switch ls0 and check that its MAC_Binding is deleted. | |
6e31816f CSV |
5196 | ovn-nbctl ls-del ls0 |
5197 | ovn-sbctl find MAC_Binding | |
093aa761 | 5198 | OVS_WAIT_UNTIL([test `ovn-sbctl find MAC_Binding | wc -l` = 0]) |
6e31816f CSV |
5199 | |
5200 | OVN_CLEANUP([hv1]) | |
5201 | ||
5202 | AT_CLEANUP | |
926c34fd RM |
5203 | |
5204 | AT_SETUP([ovn -- conntrack zone allocation]) | |
926c34fd RM |
5205 | AT_SKIP_IF([test $HAVE_PYTHON = no]) |
5206 | ovn_start | |
5207 | ||
5208 | # Logical network: | |
5209 | # 2 logical switches "foo" (192.168.1.0/24) and "bar" (172.16.1.0/24) | |
5210 | # connected to a router R1. | |
5211 | # foo has foo1 to act as a client. | |
5212 | # bar has bar1, bar2, bar3 to act as servers. | |
5213 | ||
5214 | net_add n1 | |
5215 | ||
5216 | sim_add hv1 | |
5217 | as hv1 | |
5218 | ovs-vsctl add-br br-phys | |
5219 | ovn_attach n1 br-phys 192.168.0.1 | |
5220 | for i in foo1 bar1 bar2 bar3; do | |
5221 | ovs-vsctl -- add-port br-int $i -- \ | |
5222 | set interface $i external-ids:iface-id=$i \ | |
5223 | options:tx_pcap=hv1/$i-tx.pcap \ | |
5224 | options:rxq_pcap=hv1/$i-rx.pcap | |
5225 | done | |
5226 | ||
5227 | ovn-nbctl create Logical_Router name=R1 | |
5228 | ovn-nbctl ls-add foo | |
5229 | ovn-nbctl ls-add bar | |
5230 | ||
5231 | # Connect foo to R1 | |
5232 | ovn-nbctl lrp-add R1 foo 00:00:01:01:02:03 192.168.1.1/24 | |
5233 | ovn-nbctl lsp-add foo rp-foo -- set Logical_Switch_Port rp-foo \ | |
5234 | type=router options:router-port=foo addresses=\"00:00:01:01:02:03\" | |
5235 | ||
5236 | # Connect bar to R1 | |
5237 | ovn-nbctl lrp-add R1 bar 00:00:01:01:02:04 172.16.1.1/24 | |
5238 | ovn-nbctl lsp-add bar rp-bar -- set Logical_Switch_Port rp-bar \ | |
5239 | type=router options:router-port=bar addresses=\"00:00:01:01:02:04\" | |
5240 | ||
5241 | # Create logical port foo1 in foo | |
5242 | ovn-nbctl lsp-add foo foo1 \ | |
5243 | -- lsp-set-addresses foo1 "f0:00:00:01:02:03 192.168.1.2" | |
5244 | ||
5245 | # Create logical port bar1, bar2 and bar3 in bar | |
5246 | for i in `seq 1 3`; do | |
5247 | ip=`expr $i + 1` | |
5248 | ovn-nbctl lsp-add bar bar$i \ | |
5249 | -- lsp-set-addresses bar$i "f0:00:0a:01:02:$i 172.16.1.$ip" | |
5250 | done | |
5251 | ||
5252 | OVS_WAIT_UNTIL([test `ovs-ofctl dump-flows br-int table=0 | grep REG13 | wc -l` -eq 4]) | |
5253 | ||
5254 | OVN_CLEANUP([hv1]) | |
5255 | ||
5256 | AT_CLEANUP | |
b511690b GS |
5257 | |
5258 | AT_SETUP([ovn -- tag allocation]) | |
b511690b GS |
5259 | ovn_start |
5260 | ||
5261 | AT_CHECK([ovn-nbctl ls-add ls0]) | |
5262 | AT_CHECK([ovn-nbctl lsp-add ls0 parent1]) | |
5263 | AT_CHECK([ovn-nbctl lsp-add ls0 parent2]) | |
5264 | AT_CHECK([ovn-nbctl ls-add ls1]) | |
5265 | ||
5266 | dnl When a tag is provided, no allocation is done | |
5267 | AT_CHECK([ovn-nbctl --wait=sb lsp-add ls1 c0 parent1 3]) | |
5268 | AT_CHECK([ovn-nbctl lsp-get-tag c0], [0], [3 | |
5269 | ]) | |
5270 | dnl The same 'tag' gets created in southbound database. | |
5271 | AT_CHECK([ovn-sbctl --data=bare --no-heading --columns=tag find port_binding \ | |
5272 | logical_port="c0"], [0], [3 | |
5273 | ]) | |
5274 | ||
5275 | dnl Allocate tags and see it getting created in both NB and SB | |
5276 | AT_CHECK([ovn-nbctl --wait=sb lsp-add ls1 c1 parent1 0]) | |
5277 | AT_CHECK([ovn-nbctl lsp-get-tag c1], [0], [1 | |
5278 | ]) | |
5279 | AT_CHECK([ovn-sbctl --data=bare --no-heading --columns=tag find port_binding \ | |
5280 | logical_port="c1"], [0], [1 | |
5281 | ]) | |
5282 | ||
5283 | AT_CHECK([ovn-nbctl --wait=sb lsp-add ls1 c2 parent1 0]) | |
5284 | AT_CHECK([ovn-nbctl lsp-get-tag c2], [0], [2 | |
5285 | ]) | |
5286 | AT_CHECK([ovn-sbctl --data=bare --no-heading --columns=tag find port_binding \ | |
5287 | logical_port="c2"], [0], [2 | |
5288 | ]) | |
5289 | AT_CHECK([ovn-nbctl --wait=sb lsp-add ls1 c3 parent1 0]) | |
5290 | AT_CHECK([ovn-nbctl lsp-get-tag c3], [0], [4 | |
5291 | ]) | |
5292 | AT_CHECK([ovn-sbctl --data=bare --no-heading --columns=tag find port_binding \ | |
5293 | logical_port="c3"], [0], [4 | |
5294 | ]) | |
5295 | ||
5296 | dnl A different parent. | |
5297 | AT_CHECK([ovn-nbctl --wait=sb lsp-add ls1 c4 parent2 0]) | |
5298 | AT_CHECK([ovn-nbctl lsp-get-tag c4], [0], [1 | |
5299 | ]) | |
5300 | AT_CHECK([ovn-sbctl --data=bare --no-heading --columns=tag find port_binding \ | |
5301 | logical_port="c4"], [0], [1 | |
5302 | ]) | |
5303 | ||
5304 | AT_CHECK([ovn-nbctl --wait=sb lsp-add ls1 c5 parent2 0]) | |
5305 | AT_CHECK([ovn-nbctl lsp-get-tag c5], [0], [2 | |
5306 | ]) | |
5307 | AT_CHECK([ovn-sbctl --data=bare --no-heading --columns=tag find port_binding \ | |
5308 | logical_port="c5"], [0], [2 | |
5309 | ]) | |
5310 | ||
5311 | dnl Delete a logical port and create a new one. | |
5312 | AT_CHECK([ovn-nbctl --wait=sb lsp-del c1]) | |
5313 | AT_CHECK([ovn-nbctl --wait=sb lsp-add ls1 c6 parent1 0]) | |
5314 | AT_CHECK([ovn-nbctl lsp-get-tag c6], [0], [1 | |
5315 | ]) | |
5316 | AT_CHECK([ovn-sbctl --data=bare --no-heading --columns=tag find port_binding \ | |
5317 | logical_port="c6"], [0], [1 | |
5318 | ]) | |
5319 | ||
5320 | dnl Restart northd to see that the same allocation remains. | |
5321 | as northd | |
5322 | OVS_APP_EXIT_AND_WAIT([ovn-northd]) | |
5323 | start_daemon ovn-northd \ | |
5324 | --ovnnb-db=unix:"$ovs_base"/ovn-nb/ovn-nb.sock \ | |
5325 | --ovnsb-db=unix:"$ovs_base"/ovn-sb/ovn-sb.sock | |
5326 | ||
5327 | dnl Create a switch to make sure that ovn-northd has run through the main loop. | |
5328 | AT_CHECK([ovn-nbctl --wait=sb ls-add ls-dummy]) | |
5329 | AT_CHECK([ovn-nbctl lsp-get-tag c0], [0], [3 | |
5330 | ]) | |
5331 | AT_CHECK([ovn-nbctl lsp-get-tag c6], [0], [1 | |
5332 | ]) | |
5333 | AT_CHECK([ovn-nbctl lsp-get-tag c2], [0], [2 | |
5334 | ]) | |
5335 | AT_CHECK([ovn-nbctl lsp-get-tag c3], [0], [4 | |
5336 | ]) | |
5337 | AT_CHECK([ovn-nbctl lsp-get-tag c4], [0], [1 | |
5338 | ]) | |
5339 | AT_CHECK([ovn-nbctl lsp-get-tag c5], [0], [2 | |
5340 | ]) | |
5341 | ||
5342 | dnl Create a switch port with a tag that has already been allocated. | |
5343 | dnl It should go through fine with a duplicate tag. | |
5344 | AT_CHECK([ovn-nbctl --wait=sb lsp-add ls1 c7 parent2 2]) | |
5345 | AT_CHECK([ovn-nbctl lsp-get-tag c7], [0], [2 | |
5346 | ]) | |
5347 | AT_CHECK([ovn-sbctl --data=bare --no-heading --columns=tag find port_binding \ | |
5348 | logical_port="c7"], [0], [2 | |
5349 | ]) | |
5350 | AT_CHECK([ovn-nbctl lsp-get-tag c5], [0], [2 | |
5351 | ]) | |
5352 | ||
5353 | AT_CHECK([ovn-nbctl ls-add ls2]) | |
5354 | dnl When there is no parent_name provided (for say, 'localnet'), 'tag_request' | |
5355 | dnl gets copied to 'tag' | |
5356 | AT_CHECK([ovn-nbctl --wait=sb lsp-add ls2 local0 "" 25]) | |
5357 | AT_CHECK([ovn-nbctl lsp-get-tag local0], [0], [25 | |
5358 | ]) | |
5359 | dnl The same 'tag' gets created in southbound database. | |
5360 | AT_CHECK([ovn-sbctl --data=bare --no-heading --columns=tag find port_binding \ | |
5361 | logical_port="local0"], [0], [25 | |
5362 | ]) | |
5363 | dnl If 'tag_request' is 0 for localnet, nothing gets written to 'tag' | |
5364 | AT_CHECK([ovn-nbctl --wait=sb lsp-add ls2 local1 "" 0]) | |
5365 | AT_CHECK([ovn-nbctl lsp-get-tag local1]) | |
5366 | dnl change the tag_request. | |
5367 | AT_CHECK([ovn-nbctl --wait=sb set logical_switch_port local1 tag_request=50]) | |
5368 | AT_CHECK([ovn-nbctl lsp-get-tag local1], [0], [50 | |
5369 | ]) | |
5370 | ||
5371 | AT_CLEANUP | |
57afd0c0 RR |
5372 | |
5373 | AT_SETUP([ovn -- lsp deletion and broadcast-flow deletion on localnet]) | |
57afd0c0 RR |
5374 | ovn_start |
5375 | ovn-nbctl ls-add lsw0 | |
5376 | net_add n1 | |
5377 | for i in 1 2; do | |
5378 | sim_add hv$i | |
5379 | as hv$i | |
5380 | ovs-vsctl add-br br-phys | |
5381 | ovn_attach n1 br-phys 192.168.0.$i | |
5382 | ovs-vsctl add-br br-eth0 | |
5383 | AT_CHECK([ovs-vsctl set Open_vSwitch . external-ids:ovn-bridge-mappings=physnet1:br-eth0]) | |
5384 | done | |
5385 | ||
5386 | # Create a localnet port. | |
5387 | AT_CHECK([ovn-nbctl lsp-add lsw0 ln_port]) | |
5388 | AT_CHECK([ovn-nbctl lsp-set-addresses ln_port unknown]) | |
5389 | AT_CHECK([ovn-nbctl lsp-set-type ln_port localnet]) | |
5390 | AT_CHECK([ovn-nbctl lsp-set-options ln_port network_name=physnet1]) | |
5391 | ||
5392 | ||
5393 | # Create 3 vifs. | |
5394 | AT_CHECK([ovn-nbctl lsp-add lsw0 localvif1]) | |
5395 | AT_CHECK([ovn-nbctl lsp-set-addresses localvif1 "f0:00:00:00:00:01 192.168.1.1"]) | |
5396 | AT_CHECK([ovn-nbctl lsp-set-port-security localvif1 "f0:00:00:00:00:01"]) | |
5397 | AT_CHECK([ovn-nbctl lsp-add lsw0 localvif2]) | |
5398 | AT_CHECK([ovn-nbctl lsp-set-addresses localvif2 "f0:00:00:00:00:01 192.168.1.2"]) | |
5399 | AT_CHECK([ovn-nbctl lsp-set-port-security localvif2 "f0:00:00:00:00:02"]) | |
5400 | AT_CHECK([ovn-nbctl lsp-add lsw0 localvif3]) | |
5401 | AT_CHECK([ovn-nbctl lsp-set-addresses localvif3 "f0:00:00:00:00:03 192.168.1.3"]) | |
5402 | AT_CHECK([ovn-nbctl lsp-set-port-security localvif3 "f0:00:00:00:00:03"]) | |
5403 | ||
5404 | # Bind the localvif1 to hv1. | |
5405 | as hv1 | |
5406 | AT_CHECK([ovs-vsctl add-port br-int localvif1 -- set Interface localvif1 external_ids:iface-id=localvif1]) | |
5407 | ||
5408 | # On hv1, check that there are no flows outputting bcast to tunnel | |
5409 | OVS_WAIT_UNTIL([test `ovs-ofctl dump-flows br-int table=32 | ofctl_strip | grep output | wc -l` -eq 0]) | |
5410 | ||
1ea9b847 | 5411 | # On hv2, check that no flow outputs bcast to tunnel to hv1. |
57afd0c0 | 5412 | as hv2 |
1ea9b847 | 5413 | OVS_WAIT_UNTIL([test `ovs-ofctl dump-flows br-int table=32 | ofctl_strip | grep output | wc -l` -eq 0]) |
57afd0c0 RR |
5414 | |
5415 | # Now bind vif2 on hv2. | |
5416 | AT_CHECK([ovs-vsctl add-port br-int localvif2 -- set Interface localvif2 external_ids:iface-id=localvif2]) | |
5417 | ||
5418 | # At this point, the broadcast flow on vif2 should be deleted. | |
5419 | # because, there is now a localnet vif bound (table=32 programming logic) | |
5420 | OVS_WAIT_UNTIL([test `ovs-ofctl dump-flows br-int table=32 | ofctl_strip | grep output | wc -l` -eq 0]) | |
5421 | ||
5422 | # Verify that the local net patch port exists on hv2. | |
5423 | OVS_WAIT_UNTIL([test `ovs-vsctl show | grep "Port patch-br-int-to-ln_port" | wc -l` -eq 1]) | |
5424 | ||
5425 | # Now bind vif3 on hv2. | |
5426 | AT_CHECK([ovs-vsctl add-port br-int localvif3 -- set Interface localvif3 external_ids:iface-id=localvif3]) | |
5427 | ||
5428 | # Verify that the local net patch port still exists on hv2 | |
5429 | OVS_WAIT_UNTIL([test `ovs-vsctl show | grep "Port patch-br-int-to-ln_port" | wc -l` -eq 1]) | |
5430 | ||
5431 | # Delete localvif2 | |
5432 | AT_CHECK([ovn-nbctl lsp-del localvif2]) | |
5433 | ||
5434 | # Verify that the local net patch port still exists on hv2, | |
5435 | # because, localvif3 is still bound. | |
5436 | OVS_WAIT_UNTIL([test `ovs-vsctl show | grep "Port patch-br-int-to-ln_port" | wc -l` -eq 1]) | |
5437 | ||
57afd0c0 | 5438 | OVN_CLEANUP([hv1],[hv2]) |
1a03fc7d BS |
5439 | |
5440 | AT_CLEANUP | |
5441 | ||
5442 | AT_SETUP([ovn -- DSCP marking check]) | |
5443 | AT_KEYWORDS([ovn]) | |
5444 | ovn_start | |
5445 | ||
5446 | ovn-nbctl ls-add lsw0 | |
5447 | ovn-nbctl --wait=sb lsp-add lsw0 lp1 | |
5448 | ovn-nbctl --wait=sb lsp-add lsw0 lp2 | |
5449 | ovn-nbctl lsp-set-addresses lp1 f0:00:00:00:00:01 | |
5450 | ovn-nbctl lsp-set-addresses lp2 f0:00:00:00:00:02 | |
5451 | ovn-nbctl lsp-set-port-security lp1 f0:00:00:00:00:01 | |
5452 | ovn-nbctl lsp-set-port-security lp2 f0:00:00:00:00:02 | |
5453 | ovn-nbctl --wait=sb sync | |
5454 | net_add n1 | |
5455 | sim_add hv | |
5456 | as hv | |
5457 | ovs-vsctl add-br br-phys | |
5458 | ovn_attach n1 br-phys 192.168.0.1 | |
5459 | ovs-vsctl add-port br-int vif1 -- set Interface vif1 external-ids:iface-id=lp1 options:tx_pcap=vif1-tx.pcap options:rxq_pcap=vif1-rx.pcap ofport-request=1 | |
5460 | ovs-vsctl add-port br-int vif2 -- set Interface vif2 external-ids:iface-id=lp2 options:tx_pcap=vif2-tx.pcap options:rxq_pcap=vif2-rx.pcap ofport-request=2 | |
5461 | ||
5462 | AT_CAPTURE_FILE([trace]) | |
5463 | ovn_trace () { | |
5464 | ovn-trace --all "$@" | tee trace | sed '1,/Minimal trace/d' | |
5465 | } | |
5466 | ||
5467 | # Extracts nw_tos from the final flow from ofproto/trace output and prints | |
5468 | # it on stdout. Prints "none" if no nw_tos was included. | |
5469 | get_final_nw_tos() { | |
5470 | if flow=$(grep '^Final flow:' stdout); then :; else | |
5471 | # The output didn't have a final flow. | |
5472 | return 99 | |
5473 | fi | |
5474 | ||
5475 | tos=$(echo "$flow" | sed -n 's/.*nw_tos=\([[0-9]]\{1,\}\).*/\1/p') | |
5476 | case $tos in | |
5477 | '') echo none ;; | |
5478 | *) echo $tos ;; | |
5479 | esac | |
5480 | } | |
5481 | ||
5482 | # check_tos TOS | |
5483 | # | |
5484 | # Checks that a packet from 1.1.1.1 to 1.1.1.2 gets its DSCP set to TOS. | |
5485 | check_tos() { | |
5486 | # First check with ovn-trace for logical flows. | |
5487 | echo "checking for tos $1" | |
5488 | (if test $1 != 0; then echo "ip.dscp = $1;"; fi; | |
5489 | echo 'output("lp2");') > expout | |
5490 | AT_CHECK_UNQUOTED([ovn_trace lsw0 'inport == "lp1" && eth.src == f0:00:00:00:00:01 && eth.dst == f0:00:00:00:00:02 && ip4.src == 1.1.1.1 && ip4.dst == 1.1.1.2'], [0], [expout]) | |
5491 | ||
5492 | # Then re-check with ofproto/trace for a physical packet. | |
5493 | AT_CHECK([ovs-appctl ofproto/trace br-int 'in_port=1,dl_src=f0:00:00:00:00:01,dl_dst=f0:00:00:00:00:02,dl_type=0x800,nw_src=1.1.1.1,nw_dst=1.1.1.2'], [0], [stdout-nolog]) | |
5494 | AT_CHECK_UNQUOTED([get_final_nw_tos], [0], [`expr $1 \* 4` | |
5495 | ]) | |
5496 | } | |
5497 | ||
5498 | # check at L2 | |
5499 | AT_CHECK([ovn_trace lsw0 'inport == "lp1" && eth.src == f0:00:00:00:00:01 && eth.dst == f0:00:00:00:00:02'], [0], [output("lp2"); | |
5500 | ]) | |
5501 | AT_CHECK([ovs-appctl ofproto/trace br-int 'in_port=1,dl_src=f0:00:00:00:00:01,dl_dst=f0:00:00:00:00:02'], [0], [stdout-nolog]) | |
5502 | AT_CHECK([get_final_nw_tos], [0], [none | |
5503 | ]) | |
5504 | ||
5505 | # check at L3 without dscp marking | |
5506 | check_tos 0 | |
5507 | ||
5508 | # Mark DSCP with a valid value | |
5509 | qos_id=$(ovn-nbctl --wait=hv -- --id=@lp1-qos create QoS priority=100 action=dscp=48 match="inport\=\=\"lp1\"" direction="from-lport" -- set Logical_Switch lsw0 qos_rules=@lp1-qos) | |
5510 | check_tos 48 | |
5511 | ||
5512 | # Update the DSCP marking | |
5513 | ovn-nbctl --wait=hv set QoS $qos_id action=dscp=63 | |
5514 | check_tos 63 | |
5515 | ||
5516 | ovn-nbctl --wait=hv set QoS $qos_id match="outport\=\=\"lp2\"" direction="to-lport" | |
5517 | check_tos 63 | |
5518 | ||
5519 | # Disable DSCP marking | |
5520 | ovn-nbctl --wait=hv clear Logical_Switch lsw0 qos_rules | |
5521 | check_tos 0 | |
5522 | ||
5523 | OVN_CLEANUP([hv]) | |
57afd0c0 | 5524 | AT_CLEANUP |
7fff4eb7 LR |
5525 | |
5526 | AT_SETUP([ovn -- read-only sb db:ptcp access]) | |
5527 | AT_SKIP_IF([test $HAVE_PYTHON = no]) | |
5528 | ||
5529 | : > .$1.db.~lock~ | |
5530 | ovsdb-tool create ovn-sb.db "$abs_top_srcdir"/ovn/ovn-sb.ovsschema | |
5531 | ||
5532 | # Add read-only remote to sb ovsdb-server | |
5533 | AT_CHECK( | |
5534 | [ovsdb-tool transact ovn-sb.db \ | |
5535 | ['["OVN_Southbound", | |
5536 | {"op": "insert", | |
5537 | "table": "SB_Global", | |
5538 | "row": { | |
5539 | "connections": ["set", [["named-uuid", "xyz"]]]}}, | |
5540 | {"op": "insert", | |
5541 | "table": "Connection", | |
5542 | "uuid-name": "xyz", | |
5543 | "row": {"target": "ptcp:0:127.0.0.1", | |
5544 | "read_only": true}}]']], [0], [ignore], [ignore]) | |
5545 | ||
5546 | start_daemon ovsdb-server --remote=punix:ovn-sb.sock --remote=db:OVN_Southbound,SB_Global,connections ovn-sb.db | |
5547 | ||
5548 | PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT]) | |
5549 | ||
5550 | # read-only accesses should succeed | |
5551 | AT_CHECK([ovn-sbctl --db=tcp:127.0.0.1:$TCP_PORT list SB_Global], [0], [stdout], [ignore]) | |
5552 | AT_CHECK([ovn-sbctl --db=tcp:127.0.0.1:$TCP_PORT list Connection], [0], [stdout], [ignore]) | |
5553 | ||
5554 | # write access should fail | |
5555 | AT_CHECK([ovn-sbctl --db=tcp:127.0.0.1:$TCP_PORT chassis-add ch vxlan 1.2.4.8], [1], [ignore], | |
5556 | [ovn-sbctl: transaction error: {"details":"insert operation not allowed when database server is in read only mode","error":"not allowed"} | |
5557 | ]) | |
5558 | ||
5559 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
5560 | AT_CLEANUP | |
5561 | ||
5562 | AT_SETUP([ovn -- read-only sb db:pssl access]) | |
5563 | AT_SKIP_IF([test $HAVE_PYTHON = no]) | |
5564 | AT_SKIP_IF([test "$HAVE_OPENSSL" = no]) | |
5565 | PKIDIR="$(cd $abs_top_builddir/tests && pwd)" | |
5566 | AT_SKIP_IF([expr "$PKIDIR" : ".*[ '\" | |
5567 | \\]"]) | |
5568 | ||
5569 | : > .$1.db.~lock~ | |
5570 | ovsdb-tool create ovn-sb.db "$abs_top_srcdir"/ovn/ovn-sb.ovsschema | |
5571 | ||
5572 | # Add read-only remote to sb ovsdb-server | |
5573 | AT_CHECK( | |
5574 | [ovsdb-tool transact ovn-sb.db \ | |
5575 | ['["OVN_Southbound", | |
5576 | {"op": "insert", | |
5577 | "table": "SB_Global", | |
5578 | "row": { | |
5579 | "connections": ["set", [["named-uuid", "xyz"]]]}}, | |
5580 | {"op": "insert", | |
5581 | "table": "Connection", | |
5582 | "uuid-name": "xyz", | |
5583 | "row": {"target": "pssl:0:127.0.0.1", | |
5584 | "read_only": true}}]']], [0], [ignore], [ignore]) | |
5585 | ||
5586 | start_daemon ovsdb-server --remote=punix:ovn-sb.sock \ | |
5587 | --remote=db:OVN_Southbound,SB_Global,connections \ | |
5588 | --private-key="$PKIDIR/testpki-privkey2.pem" \ | |
5589 | --certificate="$PKIDIR/testpki-cert2.pem" \ | |
5590 | --ca-cert="$PKIDIR/testpki-cacert.pem" \ | |
5591 | ovn-sb.db | |
5592 | ||
5593 | PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT]) | |
5594 | ||
5595 | # read-only accesses should succeed | |
5596 | AT_CHECK([ovn-sbctl --db=ssl:127.0.0.1:$TCP_PORT \ | |
5597 | --private-key=$PKIDIR/testpki-privkey.pem \ | |
5598 | --certificate=$PKIDIR/testpki-cert.pem \ | |
5599 | --ca-cert=$PKIDIR/testpki-cacert.pem \ | |
5600 | list SB_Global], [0], [stdout], [ignore]) | |
5601 | AT_CHECK([ovn-sbctl --db=ssl:127.0.0.1:$TCP_PORT \ | |
5602 | --private-key=$PKIDIR/testpki-privkey.pem \ | |
5603 | --certificate=$PKIDIR/testpki-cert.pem \ | |
5604 | --ca-cert=$PKIDIR/testpki-cacert.pem \ | |
5605 | list Connection], [0], [stdout], [ignore]) | |
5606 | ||
5607 | # write access should fail | |
5608 | AT_CHECK([ovn-sbctl --db=ssl:127.0.0.1:$TCP_PORT \ | |
5609 | --private-key=$PKIDIR/testpki-privkey.pem \ | |
5610 | --certificate=$PKIDIR/testpki-cert.pem \ | |
5611 | --ca-cert=$PKIDIR/testpki-cacert.pem \ | |
5612 | chassis-add ch vxlan 1.2.4.8], [1], [ignore], | |
5613 | [ovn-sbctl: transaction error: {"details":"insert operation not allowed when database server is in read only mode","error":"not allowed"} | |
5614 | ]) | |
5615 | ||
5616 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
5617 | AT_CLEANUP | |
5618 | ||
821302cf LR |
5619 | AT_SETUP([ovn -- nb connection/ssl commands]) |
5620 | AT_SKIP_IF([test $HAVE_PYTHON = no]) | |
5621 | AT_SKIP_IF([test "$HAVE_OPENSSL" = no]) | |
5622 | PKIDIR="$(cd $abs_top_builddir/tests && pwd)" | |
5623 | AT_SKIP_IF([expr "$PKIDIR" : ".*[ '\" | |
5624 | \\]"]) | |
5625 | ||
5626 | : > .$1.db.~lock~ | |
5627 | ovsdb-tool create ovn-nb.db "$abs_top_srcdir"/ovn/ovn-nb.ovsschema | |
5628 | ||
5629 | # Start nb db server using db connection/ssl entries (unpopulated initially) | |
5630 | start_daemon ovsdb-server --remote=punix:ovnnb_db.sock \ | |
5631 | --remote=db:OVN_Northbound,NB_Global,connections \ | |
5632 | --private-key=db:OVN_Northbound,SSL,private_key \ | |
5633 | --certificate=db:OVN_Northbound,SSL,certificate \ | |
5634 | --ca-cert=db:OVN_Northbound,SSL,ca_cert \ | |
5635 | ovn-nb.db | |
5636 | ||
5637 | # Populate SSL configuration entries in nb db | |
5638 | AT_CHECK( | |
5639 | [ovn-nbctl set-ssl $PKIDIR/testpki-privkey.pem \ | |
5640 | $PKIDIR/testpki-cert.pem \ | |
5641 | $PKIDIR/testpki-cacert.pem], [0], [stdout], [ignore]) | |
5642 | ||
5643 | # Populate a passive SSL connection in nb db | |
5644 | AT_CHECK([ovn-nbctl set-connection pssl:0:127.0.0.1], [0], [stdout], [ignore]) | |
5645 | ||
5646 | PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT]) | |
5647 | ||
5648 | # Verify SSL connetivity to nb db server | |
5649 | AT_CHECK([ovn-nbctl --db=ssl:127.0.0.1:$TCP_PORT \ | |
5650 | --private-key=$PKIDIR/testpki-privkey.pem \ | |
5651 | --certificate=$PKIDIR/testpki-cert.pem \ | |
5652 | --ca-cert=$PKIDIR/testpki-cacert.pem \ | |
5653 | list NB_Global], | |
5654 | [0], [stdout], [ignore]) | |
5655 | AT_CHECK([ovn-nbctl --db=ssl:127.0.0.1:$TCP_PORT \ | |
5656 | --private-key=$PKIDIR/testpki-privkey.pem \ | |
5657 | --certificate=$PKIDIR/testpki-cert.pem \ | |
5658 | --ca-cert=$PKIDIR/testpki-cacert.pem \ | |
5659 | list Connection], | |
5660 | [0], [stdout], [ignore]) | |
5661 | AT_CHECK([ovn-nbctl --db=ssl:127.0.0.1:$TCP_PORT \ | |
5662 | --private-key=$PKIDIR/testpki-privkey.pem \ | |
5663 | --certificate=$PKIDIR/testpki-cert.pem \ | |
5664 | --ca-cert=$PKIDIR/testpki-cacert.pem \ | |
5665 | get-connection], | |
5666 | [0], [stdout], [ignore]) | |
5667 | ||
5668 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
5669 | AT_CLEANUP | |
5670 | ||
75fd74f8 GS |
5671 | AT_SETUP([ovn -- nested containers]) |
5672 | ovn_start | |
5673 | ||
5674 | # Physical network: | |
5675 | # 2 HVs. HV1 has 2 VMs - "VM1" and "bar3". HV2 has 1 VM - "VM2" | |
5676 | ||
5677 | # Logical network: | |
5678 | # 3 Logical switches - "mgmt" (172.16.1.0/24), "foo" (192.168.1.0/24) | |
5679 | # and "bar" (192.168.2.0/24). They are all connected to router R1. | |
5680 | ||
5681 | ovn-nbctl lr-add R1 | |
5682 | ovn-nbctl ls-add mgmt | |
5683 | ovn-nbctl ls-add foo | |
5684 | ovn-nbctl ls-add bar | |
5685 | ||
5686 | # Connect mgmt to R1 | |
5687 | ovn-nbctl lrp-add R1 mgmt 00:00:00:01:02:02 172.16.1.1/24 | |
5688 | ovn-nbctl lsp-add mgmt rp-mgmt -- set Logical_Switch_Port rp-mgmt type=router \ | |
5689 | options:router-port=mgmt addresses=\"00:00:00:01:02:02\" | |
5690 | ||
5691 | # Connect foo to R1 | |
5692 | ovn-nbctl lrp-add R1 foo 00:00:00:01:02:03 192.168.1.1/24 | |
5693 | ovn-nbctl lsp-add foo rp-foo -- set Logical_Switch_Port rp-foo type=router \ | |
5694 | options:router-port=foo addresses=\"00:00:00:01:02:03\" | |
5695 | ||
5696 | # Connect bar to R1 | |
5697 | ovn-nbctl lrp-add R1 bar 00:00:00:01:02:04 192.168.2.1/24 | |
5698 | ovn-nbctl lsp-add bar rp-bar -- set Logical_Switch_Port rp-bar type=router \ | |
5699 | options:router-port=bar addresses=\"00:00:00:01:02:04\" | |
5700 | ||
5701 | # "mgmt" has VM1 and VM2 connected | |
5702 | ovn-nbctl lsp-add mgmt vm1 \ | |
5703 | -- lsp-set-addresses vm1 "f0:00:00:01:02:03 172.16.1.2" | |
5704 | ||
5705 | ovn-nbctl lsp-add mgmt vm2 \ | |
5706 | -- lsp-set-addresses vm2 "f0:00:00:01:02:04 172.16.1.3" | |
5707 | ||
5708 | # "foo1" and "foo2" are containers belonging to switch "foo" | |
5709 | # "foo1" has "VM1" as parent_port and "foo2" has "VM2" as parent_port. | |
5710 | ovn-nbctl lsp-add foo foo1 vm1 1 \ | |
5711 | -- lsp-set-addresses foo1 "f0:00:00:01:02:05 192.168.1.2" | |
5712 | ||
5713 | ovn-nbctl lsp-add foo foo2 vm2 2 \ | |
5714 | -- lsp-set-addresses foo2 "f0:00:00:01:02:06 192.168.1.3" | |
5715 | ||
5716 | # "bar1" and "bar2" are containers belonging to switch "bar" | |
5717 | # "bar1" has "VM1" as parent_port and "bar2" has "VM2" as parent_port. | |
5718 | ovn-nbctl lsp-add bar bar1 vm1 2 \ | |
5719 | -- lsp-set-addresses bar1 "f0:00:00:01:02:07 192.168.2.2" | |
5720 | ||
5721 | ovn-nbctl lsp-add bar bar2 vm2 1 \ | |
5722 | -- lsp-set-addresses bar2 "f0:00:00:01:02:08 192.168.2.3" | |
5723 | ||
5724 | # bar3 is a standalone VM belonging to switch "bar" | |
5725 | ovn-nbctl lsp-add bar bar3 \ | |
5726 | -- lsp-set-addresses bar3 "f0:00:00:01:02:09 192.168.2.4" | |
5727 | ||
5728 | # Create two hypervisor and create OVS ports corresponding to logical ports. | |
5729 | net_add n1 | |
5730 | ||
5731 | sim_add hv1 | |
5732 | as hv1 | |
5733 | ovs-vsctl add-br br-phys | |
5734 | ovn_attach n1 br-phys 192.168.0.1 | |
5735 | ovs-vsctl -- add-port br-int vm1 -- \ | |
5736 | set interface vm1 external-ids:iface-id=vm1 \ | |
5737 | options:tx_pcap=hv1/vm1-tx.pcap \ | |
5738 | options:rxq_pcap=hv1/vm1-rx.pcap \ | |
5739 | ofport-request=1 | |
5740 | ||
5741 | ovs-vsctl -- add-port br-int bar3 -- \ | |
5742 | set interface bar3 external-ids:iface-id=bar3 \ | |
5743 | options:tx_pcap=hv1/bar3-tx.pcap \ | |
5744 | options:rxq_pcap=hv1/bar3-rx.pcap \ | |
5745 | ofport-request=2 | |
5746 | ||
5747 | sim_add hv2 | |
5748 | as hv2 | |
5749 | ovs-vsctl add-br br-phys | |
5750 | ovn_attach n1 br-phys 192.168.0.2 | |
5751 | ovs-vsctl -- add-port br-int vm2 -- \ | |
5752 | set interface vm2 external-ids:iface-id=vm2 \ | |
5753 | options:tx_pcap=hv2/vm2-tx.pcap \ | |
5754 | options:rxq_pcap=hv2/vm2-rx.pcap \ | |
5755 | ofport-request=1 | |
5756 | ||
5757 | # Pre-populate the hypervisors' ARP tables so that we don't lose any | |
5758 | # packets for ARP resolution (native tunneling doesn't queue packets | |
5759 | # for ARP resolution). | |
5760 | ovn_populate_arp | |
5761 | ||
5762 | # Allow some time for ovn-northd and ovn-controller to catch up. | |
5763 | # XXX This should be more systematic. | |
5764 | sleep 1 | |
5765 | ||
5766 | ip_to_hex() { | |
5767 | printf "%02x%02x%02x%02x" "$@" | |
5768 | } | |
5769 | ||
5770 | # Send ip packets between foo1 and foo2 (same switch, different HVs and | |
5771 | # different VLAN tags). | |
5772 | src_mac="f00000010205" | |
5773 | dst_mac="f00000010206" | |
5774 | src_ip=`ip_to_hex 192 168 1 2` | |
5775 | dst_ip=`ip_to_hex 192 168 1 3` | |
5776 | packet=${dst_mac}${src_mac}8100000108004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
5777 | as hv1 ovs-appctl netdev-dummy/receive vm1 $packet | |
5778 | ||
5779 | # expected packet at foo2 | |
5780 | packet=${dst_mac}${src_mac}8100000208004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
5781 | echo $packet > expected | |
5782 | OVN_CHECK_PACKETS([hv2/vm2-tx.pcap], [expected]) | |
5783 | ||
5784 | # Send ip packets between foo1 and bar2 (different switch, different HV) | |
5785 | src_mac="f00000010205" | |
5786 | dst_mac="000000010203" | |
5787 | src_ip=`ip_to_hex 192 168 1 2` | |
5788 | dst_ip=`ip_to_hex 192 168 2 3` | |
5789 | packet=${dst_mac}${src_mac}8100000108004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
5790 | as hv1 ovs-appctl netdev-dummy/receive vm1 $packet | |
5791 | ||
5792 | # expected packet at bar2 | |
5793 | src_mac="000000010204" | |
5794 | dst_mac="f00000010208" | |
5795 | packet=${dst_mac}${src_mac}8100000108004500001c000000003f110100${src_ip}${dst_ip}0035111100080000 | |
5796 | echo $packet >> expected | |
5797 | OVN_CHECK_PACKETS([hv2/vm2-tx.pcap], [expected]) | |
5798 | ||
5799 | # Send ip packets between foo1 and bar1 | |
5800 | # (different switch, loopback to same vm but different tag) | |
5801 | src_mac="f00000010205" | |
5802 | dst_mac="000000010203" | |
5803 | src_ip=`ip_to_hex 192 168 1 2` | |
5804 | dst_ip=`ip_to_hex 192 168 2 2` | |
5805 | packet=${dst_mac}${src_mac}8100000108004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
5806 | as hv1 ovs-appctl netdev-dummy/receive vm1 $packet | |
5807 | ||
5808 | # expected packet at bar1 | |
5809 | src_mac="000000010204" | |
5810 | dst_mac="f00000010207" | |
5811 | packet=${dst_mac}${src_mac}8100000208004500001c000000003f110100${src_ip}${dst_ip}0035111100080000 | |
5812 | echo $packet > expected1 | |
5813 | OVN_CHECK_PACKETS([hv1/vm1-tx.pcap], [expected1]) | |
5814 | ||
5815 | # Send ip packets between bar1 and bar3 | |
5816 | # (same switch. But one is container and another is a standalone VM) | |
5817 | src_mac="f00000010207" | |
5818 | dst_mac="f00000010209" | |
5819 | src_ip=`ip_to_hex 192 168 2 2` | |
5820 | dst_ip=`ip_to_hex 192 168 2 3` | |
5821 | packet=${dst_mac}${src_mac}8100000208004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
5822 | as hv1 ovs-appctl netdev-dummy/receive vm1 $packet | |
5823 | ||
5824 | # expected packet at bar3 | |
5825 | packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
5826 | echo $packet > expected | |
5827 | OVN_CHECK_PACKETS([hv1/bar3-tx.pcap], [expected]) | |
5828 | ||
5829 | # Send ip packets between foo1 and vm1. | |
5830 | (different switch, container to the VM hosting it.) | |
5831 | src_mac="f00000010205" | |
5832 | dst_mac="000000010203" | |
5833 | src_ip=`ip_to_hex 192 168 1 2` | |
5834 | dst_ip=`ip_to_hex 172 16 1 2` | |
5835 | packet=${dst_mac}${src_mac}8100000108004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
5836 | as hv1 ovs-appctl netdev-dummy/receive vm1 $packet | |
5837 | ||
5838 | # expected packet at vm1 | |
5839 | src_mac="000000010202" | |
5840 | dst_mac="f00000010203" | |
5841 | packet=${dst_mac}${src_mac}08004500001c000000003f110100${src_ip}${dst_ip}0035111100080000 | |
5842 | echo $packet >> expected1 | |
5843 | OVN_CHECK_PACKETS([hv1/vm1-tx.pcap], [expected1]) | |
5844 | ||
5845 | # Send packets from vm1 to bar1. | |
5846 | (different switch, A hosting VM to a container inside it) | |
5847 | src_mac="f00000010203" | |
5848 | dst_mac="000000010202" | |
5849 | src_ip=`ip_to_hex 172 16 1 2` | |
5850 | dst_ip=`ip_to_hex 192 168 2 2` | |
5851 | packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
5852 | as hv1 ovs-appctl netdev-dummy/receive vm1 $packet | |
5853 | ||
5854 | # expected packet at vm1 | |
5855 | src_mac="000000010204" | |
5856 | dst_mac="f00000010207" | |
5857 | packet=${dst_mac}${src_mac}8100000208004500001c000000003f110100${src_ip}${dst_ip}0035111100080000 | |
5858 | echo $packet >> expected1 | |
5859 | OVN_CHECK_PACKETS([hv1/vm1-tx.pcap], [expected1]) | |
5860 | ||
5861 | OVN_CLEANUP([hv1],[hv2]) | |
5862 | ||
5863 | AT_CLEANUP | |
440a9f4b GS |
5864 | |
5865 | AT_SETUP([ovn -- 3 HVs, 3 LRs connected via LS, source IP based routes]) | |
5866 | AT_SKIP_IF([test $HAVE_PYTHON = no]) | |
5867 | ovn_start | |
5868 | ||
5869 | # Logical network: | |
5870 | # Three LRs - R1, R2 and R3 that are connected to each other via LS "join" | |
5871 | # in 20.0.0.0/24 network. R1 has switchess foo (192.168.1.0/24) and bar | |
5872 | # (192.168.2.0/24) connected to it. | |
5873 | # | |
5874 | # R2 and R3 are gateway routers. | |
5875 | # R2 has alice (172.16.1.0/24) and R3 has bob (172.16.1.0/24) | |
5876 | # connected to it. Note how both alice and bob have the same subnet behind it. | |
5877 | # We are trying to simulate external network via those 2 switches. In real | |
5878 | # world the switch ports of these switches will have addresses set as "unknown" | |
5879 | # to make them learning switches. Or those switches will be "localnet" ones. | |
5880 | ||
5881 | # Create three hypervisors and create OVS ports corresponding to logical ports. | |
5882 | net_add n1 | |
5883 | ||
5884 | sim_add hv1 | |
5885 | as hv1 | |
5886 | ovs-vsctl add-br br-phys | |
5887 | ovn_attach n1 br-phys 192.168.0.1 | |
5888 | ovs-vsctl -- add-port br-int hv1-vif1 -- \ | |
5889 | set interface hv1-vif1 external-ids:iface-id=foo1 \ | |
5890 | options:tx_pcap=hv1/vif1-tx.pcap \ | |
5891 | options:rxq_pcap=hv1/vif1-rx.pcap \ | |
5892 | ofport-request=1 | |
5893 | ||
5894 | ovs-vsctl -- add-port br-int hv1-vif2 -- \ | |
5895 | set interface hv1-vif2 external-ids:iface-id=bar1 \ | |
5896 | options:tx_pcap=hv1/vif2-tx.pcap \ | |
5897 | options:rxq_pcap=hv1/vif2-rx.pcap \ | |
5898 | ofport-request=2 | |
5899 | ||
5900 | sim_add hv2 | |
5901 | as hv2 | |
5902 | ovs-vsctl add-br br-phys | |
5903 | ovn_attach n1 br-phys 192.168.0.2 | |
5904 | ovs-vsctl -- add-port br-int hv2-vif1 -- \ | |
5905 | set interface hv2-vif1 external-ids:iface-id=alice1 \ | |
5906 | options:tx_pcap=hv2/vif1-tx.pcap \ | |
5907 | options:rxq_pcap=hv2/vif1-rx.pcap \ | |
5908 | ofport-request=1 | |
5909 | ||
5910 | sim_add hv3 | |
5911 | as hv3 | |
5912 | ovs-vsctl add-br br-phys | |
5913 | ovn_attach n1 br-phys 192.168.0.3 | |
5914 | ovs-vsctl -- add-port br-int hv3-vif1 -- \ | |
5915 | set interface hv3-vif1 external-ids:iface-id=bob1 \ | |
5916 | options:tx_pcap=hv3/vif1-tx.pcap \ | |
5917 | options:rxq_pcap=hv3/vif1-rx.pcap \ | |
5918 | ofport-request=1 | |
5919 | ||
5920 | ||
5921 | ovn-nbctl create Logical_Router name=R1 | |
5922 | ovn-nbctl create Logical_Router name=R2 options:chassis="hv2" | |
5923 | ovn-nbctl create Logical_Router name=R3 options:chassis="hv3" | |
5924 | ||
5925 | ovn-nbctl ls-add foo | |
5926 | ovn-nbctl ls-add bar | |
5927 | ovn-nbctl ls-add alice | |
5928 | ovn-nbctl ls-add bob | |
5929 | ovn-nbctl ls-add join | |
5930 | ||
5931 | # Connect foo to R1 | |
5932 | ovn-nbctl lrp-add R1 foo 00:00:01:01:02:03 192.168.1.1/24 | |
5933 | ovn-nbctl lsp-add foo rp-foo -- set Logical_Switch_Port rp-foo type=router \ | |
5934 | options:router-port=foo addresses=\"00:00:01:01:02:03\" | |
5935 | ||
5936 | # Connect bar to R1 | |
5937 | ovn-nbctl lrp-add R1 bar 00:00:01:01:02:04 192.168.2.1/24 | |
5938 | ovn-nbctl lsp-add bar rp-bar -- set Logical_Switch_Port rp-bar type=router \ | |
5939 | options:router-port=bar addresses=\"00:00:01:01:02:04\" | |
5940 | ||
5941 | # Connect alice to R2 | |
5942 | ovn-nbctl lrp-add R2 alice 00:00:02:01:02:03 172.16.1.1/24 | |
5943 | ovn-nbctl lsp-add alice rp-alice -- set Logical_Switch_Port rp-alice \ | |
5944 | type=router options:router-port=alice addresses=\"00:00:02:01:02:03\" | |
5945 | ||
5946 | # Connect bob to R3 | |
5947 | ovn-nbctl lrp-add R3 bob 00:00:03:01:02:03 172.16.1.2/24 | |
5948 | ovn-nbctl lsp-add bob rp-bob -- set Logical_Switch_Port rp-bob \ | |
5949 | type=router options:router-port=bob addresses=\"00:00:03:01:02:03\" | |
5950 | ||
5951 | # Connect R1 to join | |
5952 | ovn-nbctl lrp-add R1 R1_join 00:00:04:01:02:03 20.0.0.1/24 | |
5953 | ovn-nbctl lsp-add join r1-join -- set Logical_Switch_Port r1-join \ | |
5954 | type=router options:router-port=R1_join addresses='"00:00:04:01:02:03"' | |
5955 | ||
5956 | # Connect R2 to join | |
5957 | ovn-nbctl lrp-add R2 R2_join 00:00:04:01:02:04 20.0.0.2/24 | |
5958 | ovn-nbctl lsp-add join r2-join -- set Logical_Switch_Port r2-join \ | |
5959 | type=router options:router-port=R2_join addresses='"00:00:04:01:02:04"' | |
5960 | ||
5961 | # Connect R3 to join | |
5962 | ovn-nbctl lrp-add R3 R3_join 00:00:04:01:02:05 20.0.0.3/24 | |
5963 | ovn-nbctl lsp-add join r3-join -- set Logical_Switch_Port r3-join \ | |
5964 | type=router options:router-port=R3_join addresses='"00:00:04:01:02:05"' | |
5965 | ||
5966 | # Install static routes with source ip address as the policy for routing. | |
5967 | # We want traffic from 'foo' to go via R2 and traffic of 'bar' to go via R3. | |
5968 | ovn-nbctl --policy="src-ip" lr-route-add R1 192.168.1.0/24 20.0.0.2 | |
5969 | ovn-nbctl --policy="src-ip" lr-route-add R1 192.168.2.0/24 20.0.0.3 | |
5970 | ||
5971 | # Install static routes with destination ip address as the policy for routing. | |
5972 | ovn-nbctl lr-route-add R2 192.168.0.0/16 20.0.0.1 | |
5973 | ||
5974 | ovn-nbctl lr-route-add R3 192.168.0.0/16 20.0.0.1 | |
5975 | ||
5976 | # Create logical port foo1 in foo | |
5977 | ovn-nbctl lsp-add foo foo1 \ | |
5978 | -- lsp-set-addresses foo1 "f0:00:00:01:02:03 192.168.1.2" | |
5979 | ||
5980 | # Create logical port bar1 in bar | |
5981 | ovn-nbctl lsp-add bar bar1 \ | |
5982 | -- lsp-set-addresses bar1 "f0:00:00:01:02:04 192.168.2.2" | |
5983 | ||
5984 | # Create logical port alice1 in alice | |
5985 | ovn-nbctl lsp-add alice alice1 \ | |
5986 | -- lsp-set-addresses alice1 "f0:00:00:01:02:05 172.16.1.3" | |
5987 | ||
5988 | # Create logical port bob1 in bob | |
5989 | ovn-nbctl lsp-add bob bob1 \ | |
5990 | -- lsp-set-addresses bob1 "f0:00:00:01:02:06 172.16.1.4" | |
5991 | ||
5992 | # Pre-populate the hypervisors' ARP tables so that we don't lose any | |
5993 | # packets for ARP resolution (native tunneling doesn't queue packets | |
5994 | # for ARP resolution). | |
5995 | ovn_populate_arp | |
5996 | ||
5997 | # Allow some time for ovn-northd and ovn-controller to catch up. | |
5998 | # XXX This should be more systematic. | |
5999 | sleep 1 | |
6000 | ||
6001 | ip_to_hex() { | |
6002 | printf "%02x%02x%02x%02x" "$@" | |
6003 | } | |
6004 | trim_zeros() { | |
6005 | sed 's/\(00\)\{1,\}$//' | |
6006 | } | |
6007 | ||
6008 | # Send ip packets between foo1 and bar1 | |
6009 | # (East-west traffic should flow normally) | |
6010 | src_mac="f00000010203" | |
6011 | dst_mac="000001010203" | |
6012 | src_ip=`ip_to_hex 192 168 1 2` | |
6013 | dst_ip=`ip_to_hex 192 168 2 2` | |
6014 | packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
6015 | as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet | |
6016 | ||
6017 | # Send ip packets between foo1 and alice1 | |
6018 | src_mac="f00000010203" | |
6019 | dst_mac="000001010203" | |
6020 | src_ip=`ip_to_hex 192 168 1 2` | |
6021 | dst_ip=`ip_to_hex 172 16 1 3` | |
6022 | packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
6023 | as hv1 ovs-appctl netdev-dummy/receive hv1-vif1 $packet | |
6024 | #as hv1 ovs-appctl ofproto/trace br-int in_port=1 $packet | |
6025 | ||
6026 | # Send ip packets between bar1 and bob1 | |
6027 | src_mac="f00000010204" | |
6028 | dst_mac="000001010204" | |
6029 | src_ip=`ip_to_hex 192 168 2 2` | |
6030 | dst_ip=`ip_to_hex 172 16 1 4` | |
6031 | packet=${dst_mac}${src_mac}08004500001c0000000040110000${src_ip}${dst_ip}0035111100080000 | |
6032 | as hv1 ovs-appctl netdev-dummy/receive hv1-vif2 $packet | |
6033 | #as hv1 ovs-appctl ofproto/trace br-int in_port=2 $packet | |
6034 | ||
6035 | # Packet to expect at bar1 | |
6036 | src_mac="000001010204" | |
6037 | dst_mac="f00000010204" | |
6038 | src_ip=`ip_to_hex 192 168 1 2` | |
6039 | dst_ip=`ip_to_hex 192 168 2 2` | |
6040 | expected=${dst_mac}${src_mac}08004500001c000000003f110100${src_ip}${dst_ip}0035111100080000 | |
6041 | echo $expected > expected | |
6042 | OVN_CHECK_PACKETS([hv1/vif2-tx.pcap], [expected]) | |
6043 | ||
6044 | # Packet to Expect at alice1 | |
6045 | src_mac="000002010203" | |
6046 | dst_mac="f00000010205" | |
6047 | src_ip=`ip_to_hex 192 168 1 2` | |
6048 | dst_ip=`ip_to_hex 172 16 1 3` | |
6049 | expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000 | |
6050 | echo $expected > expected | |
6051 | OVN_CHECK_PACKETS([hv2/vif1-tx.pcap], [expected]) | |
6052 | ||
6053 | # Packet to Expect at bob1 | |
6054 | src_mac="000003010203" | |
6055 | dst_mac="f00000010206" | |
6056 | src_ip=`ip_to_hex 192 168 2 2` | |
6057 | dst_ip=`ip_to_hex 172 16 1 4` | |
6058 | expected=${dst_mac}${src_mac}08004500001c000000003e110200${src_ip}${dst_ip}0035111100080000 | |
6059 | echo $expected > expected | |
6060 | OVN_CHECK_PACKETS([hv3/vif1-tx.pcap], [expected]) | |
6061 | ||
6062 | for sim in hv1 hv2 hv3; do | |
6063 | as $sim | |
6064 | OVS_APP_EXIT_AND_WAIT([ovn-controller]) | |
6065 | OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) | |
6066 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
6067 | done | |
6068 | ||
6069 | as ovn-sb | |
6070 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
6071 | ||
6072 | as ovn-nb | |
6073 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
6074 | ||
6075 | as northd | |
6076 | OVS_APP_EXIT_AND_WAIT([ovn-northd]) | |
6077 | ||
6078 | as main | |
6079 | OVS_APP_EXIT_AND_WAIT([ovs-vswitchd]) | |
6080 | OVS_APP_EXIT_AND_WAIT([ovsdb-server]) | |
6081 | ||
6082 | AT_CLEANUP |