tests: Add tunnel unit tests.
[sliver-openvswitch.git] / tests / tunnel.at
1 AT_BANNER([tunnel])
2
3 AT_SETUP([tunnel - input])
4 OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=gre \
5                     options:remote_ip=1.1.1.1 ofport_request=1\
6                     -- add-port br0 p2 -- set Interface p2 type=gre \
7                     options:local_ip=2.2.2.2 options:remote_ip=1.1.1.1 \
8                     ofport_request=2 \
9                     -- add-port br0 p3 -- set Interface p3 type=gre \
10                     options:remote_ip=2.2.2.2 ofport_request=3])
11 AT_DATA([flows.txt], [dnl
12 actions=IN_PORT
13 ])
14
15 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
16
17 AT_CHECK([ovs-appctl dpif/show], [0], [dnl
18 br0 (dummy@ovs-dummy):
19         lookups: hit:0 missed:0 lost:0
20         flows: 0
21         br0 65534/100: (dummy)
22         p1 1/1: (gre: remote_ip=1.1.1.1)
23         p2 2/1: (gre: local_ip=2.2.2.2, remote_ip=1.1.1.1)
24         p3 3/1: (gre: remote_ip=2.2.2.2)
25 ])
26
27 dnl remote_ip
28 AT_CHECK([ovs-appctl ofproto/trace br0 'tunnel(tun_id=0x0,src=1.1.1.1,dst=1.2.3.4,tos=0x0,ttl=64,flags()),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
29 AT_CHECK([tail -1 stdout], [0],
30   [Datapath actions: set(tunnel(tun_id=0x0,src=0.0.0.0,dst=1.1.1.1,tos=0x0,ttl=64,flags(df))),1
31 ])
32
33 dnl local_ip, remote_ip
34 AT_CHECK([ovs-appctl ofproto/trace br0 'tunnel(tun_id=0x0,src=1.1.1.1,dst=2.2.2.2,tos=0x0,ttl=64,flags()),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
35 AT_CHECK([tail -1 stdout], [0],
36   [Datapath actions: set(tunnel(tun_id=0x0,src=2.2.2.2,dst=1.1.1.1,tos=0x0,ttl=64,flags(df))),1
37 ])
38
39 dnl reconfigure, local_ip, remote_ip
40 AT_CHECK([ovs-vsctl set Interface p2 type=gre options:local_ip=2.2.2.3 \
41           options:df_default=false options:ttl=1 options:csum=true \
42           -- set Interface p3 type=gre64])
43 AT_CHECK([ovs-appctl dpif/show], [0], [dnl
44 br0 (dummy@ovs-dummy):
45         lookups: hit:0 missed:0 lost:0
46         flows: 0
47         br0 65534/100: (dummy)
48         p1 1/1: (gre: remote_ip=1.1.1.1)
49         p2 2/1: (gre: csum=true, df_default=false, local_ip=2.2.2.3, remote_ip=1.1.1.1, ttl=1)
50         p3 3/64: (gre64: remote_ip=2.2.2.2)
51 ])
52 AT_CHECK([ovs-appctl ofproto/trace br0 'tunnel(tun_id=0x0,src=1.1.1.1,dst=2.2.2.2,tos=0x0,ttl=64,flags()),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
53 AT_CHECK([tail -1 stdout], [0],
54   [Datapath actions: set(tunnel(tun_id=0x0,src=0.0.0.0,dst=1.1.1.1,tos=0x0,ttl=64,flags(df))),1
55 ])
56 AT_CHECK([ovs-appctl ofproto/trace br0 'tunnel(tun_id=0x0,src=1.1.1.1,dst=2.2.2.3,tos=0x0,ttl=64,flags()),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
57 AT_CHECK([tail -1 stdout], [0],
58   [Datapath actions: set(tunnel(tun_id=0x0,src=2.2.2.3,dst=1.1.1.1,tos=0x0,ttl=1,flags(csum))),1
59 ])
60
61 dnl nonexistent tunnel
62 AT_CHECK([ovs-appctl ofproto/trace br0 'tunnel(tun_id=0x0,src=5.5.5.5,dst=6.6.6.6,tos=0x0,ttl=64,flags()),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [2], [ignore], [dnl
63 Invalid flow
64 ovs-appctl: ovs-vswitchd: server returned an error
65 ])
66
67 OVS_VSWITCHD_STOP
68 AT_CLEANUP
69
70 AT_SETUP([tunnel - ECN decapsulation])
71 OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=gre \
72                     options:remote_ip=1.1.1.1 ofport_request=1 \
73                     -- add-port br0 p2 -- set Interface p2 type=dummy \
74                     ofport_request=2])
75 AT_DATA([flows.txt], [dnl
76 actions=2
77 ])
78
79 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
80
81 AT_CHECK([ovs-appctl dpif/show], [0], [dnl
82 br0 (dummy@ovs-dummy):
83         lookups: hit:0 missed:0 lost:0
84         flows: 0
85         br0 65534/100: (dummy)
86         p1 1/1: (gre: remote_ip=1.1.1.1)
87         p2 2/2: (dummy)
88 ])
89
90 AT_CHECK([ovs-appctl ofproto/trace br0 'tunnel(tun_id=0x0,src=1.1.1.1,dst=2.2.2.2,tos=0x3,ttl=64,flags()),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=1,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
91 AT_CHECK([tail -1 stdout], [0],
92   [Datapath actions: 2
93 ])
94 OVS_VSWITCHD_STOP
95 AT_CLEANUP
96
97 AT_SETUP([tunnel - output])
98 OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=gre \
99                     options:remote_ip=1.1.1.1 options:local_ip=2.2.2.2 \
100                     options:key=5 ofport_request=1\
101                     -- add-port br0 p2 -- set Interface p2 type=dummy \
102                     ofport_request=2 ofport_request=2])
103 AT_DATA([flows.txt], [dnl
104 actions=output:1
105 ])
106
107 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
108
109 AT_CHECK([ovs-appctl dpif/show], [0], [dnl
110 br0 (dummy@ovs-dummy):
111         lookups: hit:0 missed:0 lost:0
112         flows: 0
113         br0 65534/100: (dummy)
114         p1 1/1: (gre: key=5, local_ip=2.2.2.2, remote_ip=1.1.1.1)
115         p2 2/2: (dummy)
116 ])
117
118 dnl Basic
119 AT_CHECK([ovs-appctl ofproto/trace br0 'in_port(2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=4,ttl=128,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
120 AT_CHECK([tail -1 stdout], [0],
121   [Datapath actions: set(tunnel(tun_id=0x5,src=2.2.2.2,dst=1.1.1.1,tos=0x0,ttl=64,flags(df,key))),1
122 ])
123
124 dnl ECN
125 AT_CHECK([ovs-appctl ofproto/trace br0 'in_port(2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=1,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
126 AT_CHECK([tail -1 stdout], [0],
127   [Datapath actions: set(tunnel(tun_id=0x5,src=2.2.2.2,dst=1.1.1.1,tos=0x1,ttl=64,flags(df,key))),1
128 ])
129 OVS_VSWITCHD_STOP
130 AT_CLEANUP
131
132 AT_SETUP([tunnel - ToS and TTL inheritance])
133 OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=gre \
134                     options:remote_ip=1.1.1.1 options:tos=inherit \
135                     options:ttl=inherit ofport_request=1 \
136                     -- add-port br0 p2 -- set Interface p2 type=dummy \
137                     ofport_request=2 ofport_request=2])
138 AT_DATA([flows.txt], [dnl
139 actions=output:1
140 ])
141
142 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
143
144 AT_CHECK([ovs-appctl dpif/show], [0], [dnl
145 br0 (dummy@ovs-dummy):
146         lookups: hit:0 missed:0 lost:0
147         flows: 0
148         br0 65534/100: (dummy)
149         p1 1/1: (gre: remote_ip=1.1.1.1, tos=inherit, ttl=inherit)
150         p2 2/2: (dummy)
151 ])
152
153 dnl Basic
154 AT_CHECK([ovs-appctl ofproto/trace br0 'in_port(2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=4,ttl=128,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
155 AT_CHECK([tail -1 stdout], [0],
156   [Datapath actions: set(tunnel(tun_id=0x0,src=0.0.0.0,dst=1.1.1.1,tos=0x4,ttl=128,flags(df))),1
157 ])
158
159 dnl ECN
160 AT_CHECK([ovs-appctl ofproto/trace br0 'in_port(2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=5,ttl=128,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
161 AT_CHECK([tail -1 stdout], [0],
162   [Datapath actions: set(tunnel(tun_id=0x0,src=0.0.0.0,dst=1.1.1.1,tos=0x5,ttl=128,flags(df))),1
163 ])
164
165 dnl non-IP
166 AT_CHECK([ovs-appctl ofproto/trace br0 'in_port(2),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0806),arp(sip=1.2.3.4,tip=5.6.7.8,op=1,sha=00:0f:10:11:12:13,tha=00:14:15:16:17:18)'], [0], [stdout])
167 AT_CHECK([tail -1 stdout], [0],
168   [Datapath actions: set(tunnel(tun_id=0x0,src=0.0.0.0,dst=1.1.1.1,tos=0x0,ttl=64,flags(df))),1
169 ])
170 OVS_VSWITCHD_STOP
171 AT_CLEANUP
172
173 AT_SETUP([tunnel - set_tunnel])
174 OVS_VSWITCHD_START([dnl
175     add-port br0 p1 -- set Interface p1 type=gre options:key=flow \
176         options:remote_ip=1.1.1.1 ofport_request=1 \
177     -- add-port br0 p2 -- set Interface p2 type=gre options:key=flow \
178         options:remote_ip=2.2.2.2 ofport_request=2 \
179     -- add-port br0 p3 -- set Interface p3 type=gre options:key=flow \
180         options:remote_ip=3.3.3.3 ofport_request=3 \
181     -- add-port br0 p4 -- set Interface p4 type=gre options:key=flow \
182         options:remote_ip=4.4.4.4 ofport_request=4])
183 AT_DATA([flows.txt], [dnl
184 actions=set_tunnel:1,output:1,set_tunnel:2,output:2,set_tunnel:3,output:3,set_tunnel:5,output:4
185 ])
186
187 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
188
189 AT_CHECK([ovs-appctl dpif/show], [0], [dnl
190 br0 (dummy@ovs-dummy):
191         lookups: hit:0 missed:0 lost:0
192         flows: 0
193         br0 65534/100: (dummy)
194         p1 1/1: (gre: key=flow, remote_ip=1.1.1.1)
195         p2 2/1: (gre: key=flow, remote_ip=2.2.2.2)
196         p3 3/1: (gre: key=flow, remote_ip=3.3.3.3)
197         p4 4/1: (gre: key=flow, remote_ip=4.4.4.4)
198 ])
199
200 AT_CHECK([ovs-appctl ofproto/trace br0 'in_port(100),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=1,tos=0,ttl=128,frag=no),icmp(type=8,code=0)'], [0], [stdout])
201 AT_CHECK([tail -1 stdout], [0], [Datapath actions: dnl
202 set(tunnel(tun_id=0x1,src=0.0.0.0,dst=1.1.1.1,tos=0x0,ttl=64,flags(df,key))),1,dnl
203 set(tunnel(tun_id=0x2,src=0.0.0.0,dst=2.2.2.2,tos=0x0,ttl=64,flags(df,key))),1,dnl
204 set(tunnel(tun_id=0x3,src=0.0.0.0,dst=3.3.3.3,tos=0x0,ttl=64,flags(df,key))),1,dnl
205 set(tunnel(tun_id=0x5,src=0.0.0.0,dst=4.4.4.4,tos=0x0,ttl=64,flags(df,key))),1
206 ])
207 OVS_VSWITCHD_STOP
208 AT_CLEANUP
209
210 AT_SETUP([tunnel - key])
211 OVS_VSWITCHD_START([dnl
212     add-port br0 p1 -- set Interface p1 type=gre options:key=1 \
213         options:remote_ip=1.1.1.1 ofport_request=1 \
214     -- add-port br0 p2 -- set Interface p2 type=gre options:in_key=2 \
215         options:out_key=3 options:remote_ip=1.1.1.1 ofport_request=2 \
216     -- add-port br0 p3 -- set Interface p3 type=gre options:out_key=5 \
217         options:remote_ip=1.1.1.1 ofport_request=3])
218 AT_DATA([flows.txt], [dnl
219 actions=IN_PORT,output:1,output:2,output:3
220 ])
221
222 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
223
224 AT_CHECK([ovs-appctl dpif/show], [0], [dnl
225 br0 (dummy@ovs-dummy):
226         lookups: hit:0 missed:0 lost:0
227         flows: 0
228         br0 65534/100: (dummy)
229         p1 1/1: (gre: key=1, remote_ip=1.1.1.1)
230         p2 2/1: (gre: in_key=2, out_key=3, remote_ip=1.1.1.1)
231         p3 3/1: (gre: out_key=5, remote_ip=1.1.1.1)
232 ])
233
234 AT_CHECK([ovs-appctl ofproto/trace br0 'tunnel(tun_id=0x1,src=1.1.1.1,dst=2.2.2.2,tos=0x0,ttl=64,flags(key)),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
235 AT_CHECK([tail -1 stdout], [0], [Datapath actions: dnl
236 set(tunnel(tun_id=0x1,src=0.0.0.0,dst=1.1.1.1,tos=0x0,ttl=64,flags(df,key))),1,dnl
237 set(tunnel(tun_id=0x3,src=0.0.0.0,dst=1.1.1.1,tos=0x0,ttl=64,flags(df,key))),1,dnl
238 set(tunnel(tun_id=0x5,src=0.0.0.0,dst=1.1.1.1,tos=0x0,ttl=64,flags(df,key))),1
239 ])
240
241 AT_CHECK([ovs-appctl ofproto/trace br0 'tunnel(tun_id=0x2,src=1.1.1.1,dst=2.2.2.2,tos=0x0,ttl=64,flags(key)),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
242 AT_CHECK([tail -1 stdout], [0], [Datapath actions: dnl
243 set(tunnel(tun_id=0x3,src=0.0.0.0,dst=1.1.1.1,tos=0x0,ttl=64,flags(df,key))),1,dnl
244 set(tunnel(tun_id=0x1,src=0.0.0.0,dst=1.1.1.1,tos=0x0,ttl=64,flags(df,key))),1,dnl
245 set(tunnel(tun_id=0x5,src=0.0.0.0,dst=1.1.1.1,tos=0x0,ttl=64,flags(df,key))),1
246 ])
247
248 AT_CHECK([ovs-appctl ofproto/trace br0 'tunnel(tun_id=0x0,src=1.1.1.1,dst=2.2.2.2,tos=0x0,ttl=64,flags()),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
249 AT_CHECK([tail -1 stdout], [0], [Datapath actions: dnl
250 set(tunnel(tun_id=0x5,src=0.0.0.0,dst=1.1.1.1,tos=0x0,ttl=64,flags(df,key))),1,dnl
251 set(tunnel(tun_id=0x1,src=0.0.0.0,dst=1.1.1.1,tos=0x0,ttl=64,flags(df,key))),1,dnl
252 set(tunnel(tun_id=0x3,src=0.0.0.0,dst=1.1.1.1,tos=0x0,ttl=64,flags(df,key))),1
253 ])
254
255 AT_CHECK([ovs-appctl ofproto/trace br0 'tunnel(tun_id=0xf,src=1.1.1.1,dst=2.2.2.2,tos=0x0,ttl=64,flags(key)),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [2], [ignore], [dnl
256 Invalid flow
257 ovs-appctl: ovs-vswitchd: server returned an error
258 ])
259 OVS_VSWITCHD_STOP
260 AT_CLEANUP
261
262 AT_SETUP([tunnel - key match])
263 OVS_VSWITCHD_START([dnl
264     add-port br0 p1 -- set Interface p1 type=gre options:key=flow \
265         options:remote_ip=1.1.1.1 ofport_request=1 \
266     -- add-port br0 p2 -- set Interface p2 type=gre options:key=3 \
267         options:remote_ip=3.3.3.3 ofport_request=2 \
268     -- add-port br0 p3 -- set Interface p3 type=dummy ofport_request=3 \
269     -- add-port br0 p4 -- set Interface p4 type=dummy ofport_request=4 \
270     -- add-port br0 p5 -- set Interface p5 type=dummy ofport_request=5])
271 AT_DATA([flows.txt], [dnl
272 tun_id=2,actions=output:3
273 tun_id=3,actions=output:4,set_tunnel:2,resubmit:99,set_tunnel:4,output:2,resubmit:99
274 tun_id=4,actions=output:5
275 ])
276
277 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
278
279 AT_CHECK([ovs-appctl dpif/show], [0], [dnl
280 br0 (dummy@ovs-dummy):
281         lookups: hit:0 missed:0 lost:0
282         flows: 0
283         br0 65534/100: (dummy)
284         p1 1/1: (gre: key=flow, remote_ip=1.1.1.1)
285         p2 2/1: (gre: key=3, remote_ip=3.3.3.3)
286         p3 3/3: (dummy)
287         p4 4/4: (dummy)
288         p5 5/5: (dummy)
289 ])
290
291 AT_CHECK([ovs-appctl ofproto/trace br0 'tunnel(tun_id=0x2,src=1.1.1.1,dst=2.2.2.2,tos=0x0,ttl=64,flags(key)),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
292 AT_CHECK([tail -1 stdout], [0], [dnl
293 Datapath actions: 3
294 ])
295
296 AT_CHECK([ovs-appctl ofproto/trace br0 'tunnel(tun_id=0x3,src=1.1.1.1,dst=2.2.2.2,tos=0x0,ttl=64,flags(key)),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
297 AT_CHECK([tail -1 stdout], [0], [dnl
298 Datapath actions: 4,3,set(tunnel(tun_id=0x3,src=0.0.0.0,dst=3.3.3.3,tos=0x0,ttl=64,flags(df,key))),1,5
299 ])
300
301 AT_CHECK([ovs-appctl ofproto/trace br0 'tunnel(tun_id=0x3,src=3.3.3.3,dst=2.2.2.2,tos=0x0,ttl=64,flags(key)),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
302 AT_CHECK([tail -1 stdout], [0], [dnl
303 Datapath actions: 4,3,5
304 ])
305
306 AT_CHECK([ovs-appctl ofproto/trace br0 'tunnel(tun_id=0x0,src=1.1.1.1,dst=2.2.2.2,tos=0x0,ttl=64,flags(key)),in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'], [0], [stdout])
307 AT_CHECK([tail -1 stdout], [0], [dnl
308         - Sends "packet-in" messages to the OpenFlow controller.
309 ])
310
311 OVS_VSWITCHD_STOP
312 AT_CLEANUP