1 AT_BANNER([learning action])
3 AT_SETUP([learning action - parsing and formatting])
4 AT_DATA([flows.txt], [[
6 actions=learn(send_flow_rem)
7 actions=learn(delete_learned)
8 actions=learn(send_flow_rem,delete_learned)
9 actions=learn(NXM_OF_VLAN_TCI[0..11], NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[], output:NXM_OF_IN_PORT[], load:10->NXM_NX_REG0[5..10])
10 actions=learn(table=1,idle_timeout=10, hard_timeout=20, fin_idle_timeout=5, fin_hard_timeout=10, priority=10, cookie=0xfedcba9876543210, in_port=99,NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG1[16..31])
12 AT_CHECK([ovs-ofctl parse-flows flows.txt], [0],
13 [[usable protocols: any
14 chosen protocol: OpenFlow10-table_id
15 OFPT_FLOW_MOD (xid=0x1): ADD actions=learn(table=1)
16 OFPT_FLOW_MOD (xid=0x2): ADD actions=learn(table=1,send_flow_rem)
17 OFPT_FLOW_MOD (xid=0x3): ADD actions=learn(table=1,delete_learned)
18 OFPT_FLOW_MOD (xid=0x4): ADD actions=learn(table=1,send_flow_rem,delete_learned)
19 OFPT_FLOW_MOD (xid=0x5): ADD actions=learn(table=1,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],output:NXM_OF_IN_PORT[],load:0xa->NXM_NX_REG0[5..10])
20 OFPT_FLOW_MOD (xid=0x6): ADD actions=learn(table=1,idle_timeout=10,hard_timeout=20,fin_idle_timeout=5,fin_hard_timeout=10,priority=10,cookie=0xfedcba9876543210,in_port=99,NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG1[16..31])
24 AT_SETUP([learning action - parsing and formatting - illegal in_port_oxm])
25 AT_CHECK([[ovs-ofctl parse-flow 'actions=learn(table=1, in_port_oxm=123456)']],
27 AT_CHECK([sed -e 's/.*|ofp_util|WARN|//' < stderr], [0],
28 [[port 123456 is outside the supported range 0 through ffff or 0xffffff00 through 0xffffffff
29 ovs-ofctl: 123456: port value out of range for in_port_oxm
33 AT_SETUP([learning action - parsing and formatting - OXM])
34 AT_DATA([flows.txt], [[
35 actions=learn(output:OXM_OF_IN_PORT[])
36 actions=learn(table=1, in_port=1, load:OXM_OF_IN_PORT[]->NXM_NX_REG1[], load:0xfffffffe->OXM_OF_IN_PORT[])
38 AT_CHECK([ovs-ofctl -O OpenFlow12 parse-flows flows.txt], [0],
39 [[usable protocols: any
40 chosen protocol: OXM-OpenFlow12
41 OFPT_FLOW_MOD (OF1.2) (xid=0x1): ADD actions=learn(table=1,output:OXM_OF_IN_PORT[])
42 OFPT_FLOW_MOD (OF1.2) (xid=0x2): ADD actions=learn(table=1,in_port=1,load:OXM_OF_IN_PORT[]->NXM_NX_REG1[],load:0xfffffffe->OXM_OF_IN_PORT[])
46 AT_SETUP([learning action - examples])
47 AT_DATA([flows.txt], [[
48 # These are the examples from nicira-ext.h.
49 actions=learn(in_port=99,NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[], load:NXM_OF_IN_PORT[]->NXM_NX_REG1[16..31])
50 actions=learn(NXM_OF_VLAN_TCI[0..11], NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],output:NXM_OF_IN_PORT[])
51 table=0 actions=learn(table=1,hard_timeout=10, NXM_OF_VLAN_TCI[0..11],output:NXM_OF_IN_PORT[]), resubmit(,1)
52 table=1 priority=0 actions=flood
54 AT_CHECK([ovs-ofctl parse-flows flows.txt], [0],
55 [[usable protocols: OXM,OpenFlow10+table_id,NXM+table_id,OpenFlow11
56 chosen protocol: OpenFlow10+table_id
57 OFPT_FLOW_MOD (xid=0x1): ADD table:255 actions=learn(table=1,in_port=99,NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:NXM_OF_IN_PORT[]->NXM_NX_REG1[16..31])
58 OFPT_FLOW_MOD (xid=0x2): ADD table:255 actions=learn(table=1,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],output:NXM_OF_IN_PORT[])
59 OFPT_FLOW_MOD (xid=0x3): ADD actions=learn(table=1,hard_timeout=10,NXM_OF_VLAN_TCI[0..11],output:NXM_OF_IN_PORT[]),resubmit(,1)
60 OFPT_FLOW_MOD (xid=0x4): ADD table:1 priority=0 actions=FLOOD
64 AT_SETUP([learning action - satisfied prerequisites])
66 [[actions=learn(eth_type=0x800,load:5->NXM_OF_IP_DST[])
67 ip,actions=learn(load:NXM_OF_IP_DST[]->NXM_NX_REG1[])
68 ip,actions=learn(eth_type=0x800,OXM_OF_IPV4_DST[])
70 AT_CHECK([ovs-ofctl parse-flows flows.txt], [0],
71 [[usable protocols: any
72 chosen protocol: OpenFlow10-table_id
73 OFPT_FLOW_MOD (xid=0x1): ADD actions=learn(table=1,eth_type=0x800,load:0x5->NXM_OF_IP_DST[])
74 OFPT_FLOW_MOD (xid=0x2): ADD ip actions=learn(table=1,load:NXM_OF_IP_DST[]->NXM_NX_REG1[])
75 OFPT_FLOW_MOD (xid=0x3): ADD ip actions=learn(table=1,eth_type=0x800,NXM_OF_IP_DST[])
79 AT_SETUP([learning action - invalid prerequisites])
80 AT_CHECK([[ovs-ofctl parse-flow 'actions=learn(load:5->NXM_OF_IP_DST[])']],
82 AT_CHECK([sed -e 's/.*|meta_flow|WARN|//' < stderr], [0],
83 [[destination field ip_dst lacks correct prerequisites
84 ovs-ofctl: actions are invalid with specified match (OFPBAC_MATCH_INCONSISTENT)
86 AT_CHECK([[ovs-ofctl parse-flow 'actions=learn(load:NXM_OF_IP_DST[]->NXM_NX_REG1[])']],
88 AT_CHECK([sed -e 's/.*|meta_flow|WARN|//' < stderr], [0],
89 [[source field ip_dst lacks correct prerequisites
90 ovs-ofctl: actions are invalid with specified match (OFPBAC_MATCH_INCONSISTENT)
94 AT_SETUP([learning action - too-long immediate value])
95 dnl 129 bits is too long.
96 AT_CHECK([[ovs-ofctl parse-flow 'actions=learn(load:0x1fedbca9876543210fedbca9876543210->NXM_NX_IPV6_DST[])']],
97 [1], [], [[ovs-ofctl: 0x1fedbca9876543210fedbca9876543210->NXM_NX_IPV6_DST[]: value does not fit into 128 bits
100 dnl 128 bits is merely a bad prerequisite.
101 AT_CHECK([[ovs-ofctl parse-flow 'actions=learn(load:0xfedbca9876543210fedbca9876543210->NXM_NX_IPV6_DST[])']], [1], [], [stderr])
102 AT_CHECK([sed -e 's/.*|meta_flow|WARN|//' < stderr], [0],
103 [[destination field ipv6_dst lacks correct prerequisites
104 ovs-ofctl: actions are invalid with specified match (OFPBAC_MATCH_INCONSISTENT)
108 AT_SETUP([learning action - standard VLAN+MAC learning])
110 [add-port br0 p1 -- set Interface p1 type=dummy ofport_request=1 -- \
111 add-port br0 p2 -- set Interface p2 type=dummy ofport_request=2 -- \
112 add-port br0 p3 -- set Interface p3 type=dummy ofport_request=3])
113 # Set up flow table for VLAN+MAC learning.
114 AT_DATA([flows.txt], [[
115 table=0 actions=learn(table=1, hard_timeout=60, NXM_OF_VLAN_TCI[0..11], NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[], output:NXM_OF_IN_PORT[]), resubmit(,1)
116 table=1 priority=0 actions=flood
118 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
120 # Trace an ARP packet arriving on port 3, to create a MAC learning entry.
121 flow="in_port(3),eth(src=50:54:00:00:00:05,dst=ff:ff:ff:ff:ff:ff),eth_type(0x0806),arp(sip=192.168.0.1,tip=192.168.0.2,op=1,sha=50:54:00:00:00:05,tha=00:00:00:00:00:00)"
122 AT_CHECK([ovs-appctl ofproto/trace ovs-dummy "$flow" -generate], [0], [stdout])
123 actual=`tail -1 stdout | sed 's/Datapath actions: //'`
126 AT_CHECK([ovs-dpctl normalize-actions "$flow" "$expected"], [0], [stdout])
128 AT_CHECK([ovs-dpctl normalize-actions "$flow" "$actual"], [0], [expout])
130 # Check for the MAC learning entry.
131 AT_CHECK([ovs-ofctl dump-flows br0 table=1 | ofctl_strip | sort], [0], [dnl
132 table=1, hard_timeout=60, vlan_tci=0x0000/0x0fff,dl_dst=50:54:00:00:00:05 actions=output:3
133 table=1, priority=0 actions=FLOOD
137 # Trace a packet arrival destined for the learned MAC.
138 # (This will also learn a MAC.)
139 AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(1),eth(src=50:54:00:00:00:06,dst=50:54:00:00:00:05),eth_type(0x0806),arp(sip=192.168.0.2,tip=192.168.0.1,op=2,sha=50:54:00:00:00:06,tha=50:54:00:00:00:05)' -generate], [0], [stdout])
140 AT_CHECK([tail -1 stdout], [0], [Datapath actions: 3
143 # Check for both MAC learning entries.
144 AT_CHECK([ovs-ofctl dump-flows br0 table=1 | ofctl_strip |sort], [0], [dnl
145 table=1, hard_timeout=60, vlan_tci=0x0000/0x0fff,dl_dst=50:54:00:00:00:05 actions=output:3
146 table=1, hard_timeout=60, vlan_tci=0x0000/0x0fff,dl_dst=50:54:00:00:00:06 actions=output:1
147 table=1, priority=0 actions=FLOOD
151 # Trace a packet arrival that updates the first learned MAC entry.
152 flow="in_port(2),eth(src=50:54:00:00:00:05,dst=ff:ff:ff:ff:ff:ff),eth_type(0x0806),arp(sip=192.168.0.1,tip=192.168.0.2,op=1,sha=50:54:00:00:00:05,tha=00:00:00:00:00:00)"
153 AT_CHECK([ovs-appctl ofproto/trace ovs-dummy "$flow" -generate], [0], [stdout])
154 actual=`tail -1 stdout | sed 's/Datapath actions: //'`
157 AT_CHECK([ovs-dpctl normalize-actions "$flow" "$expected"], [0], [stdout])
159 AT_CHECK([ovs-dpctl normalize-actions "$flow" "$actual"], [0], [expout])
161 # Check that the MAC learning entry was updated.
162 AT_CHECK([ovs-ofctl dump-flows br0 table=1 | ofctl_strip | sort], [0], [dnl
163 table=1, hard_timeout=60, vlan_tci=0x0000/0x0fff,dl_dst=50:54:00:00:00:05 actions=output:2
164 table=1, hard_timeout=60, vlan_tci=0x0000/0x0fff,dl_dst=50:54:00:00:00:06 actions=output:1
165 table=1, priority=0 actions=FLOOD
171 dnl This test checks that repeated uses of a "learn" action cause the
172 dnl modified time of the learned flow to advance. Otherwise, the
173 dnl learned flow will expire after its hard timeout even though it's
174 dnl supposed to be refreshed. (The expiration can be hard to see since
175 dnl it gets re-learned again the next time a packet appears, but
176 dnl sometimes the expiration can cause temporary flooding etc.)
177 AT_SETUP([learning action - learn refreshes hard_age])
179 [add-port br0 p1 -- set Interface p1 type=dummy ofport_request=1 -- \
180 add-port br0 p2 -- set Interface p2 type=dummy ofport_request=2 -- \
181 add-port br0 p3 -- set Interface p3 type=dummy ofport_request=3])
185 # Set up flow table for MAC learning.
186 AT_DATA([flows.txt], [[
187 table=0 actions=learn(table=1, hard_timeout=10, NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[], output:NXM_OF_IN_PORT[]), resubmit(,1)
188 table=1 priority=0 actions=flood
190 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
192 # Trace an ICMP packet arriving on port 3, to create a MAC learning entry.
193 flow="in_port(3),eth(src=50:54:00:00:00:07,dst=50:54:00:00:00:05),eth_type(0x0800),ipv4(src=192.168.0.2,dst=192.168.0.1,proto=1,tos=0,ttl=64,frag=no),icmp(type=0,code=0)"
194 AT_CHECK([ovs-appctl ofproto/trace ovs-dummy "$flow" -generate], [0], [stdout])
195 actual=`tail -1 stdout | sed 's/Datapath actions: //'`
198 AT_CHECK([ovs-dpctl normalize-actions "$flow" "$expected"], [0], [stdout])
200 AT_CHECK([ovs-dpctl normalize-actions "$flow" "$actual"], [0], [expout])
202 # Check that the MAC learning entry appeared.
203 AT_CHECK([ovs-ofctl dump-flows br0 table=1 | ofctl_strip | sort], [0], [dnl
204 table=1, hard_timeout=10, dl_dst=50:54:00:00:00:07 actions=output:3
205 table=1, priority=0 actions=FLOOD
209 # For 25 seconds, make sure that the MAC learning entry doesn't
210 # disappear as long as we refresh it every second.
211 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25; do
212 ovs-appctl time/warp 1000
213 AT_CHECK([ovs-appctl ofproto/trace ovs-dummy "$flow" -generate], [0], [stdout])
215 # Check that the entry is there.
216 AT_CHECK([ovs-ofctl dump-flows br0 table=1], [0], [stdout])
217 AT_CHECK([ofctl_strip < stdout | sort], [0], [dnl
218 table=1, hard_timeout=10, dl_dst=50:54:00:00:00:07 actions=output:3
219 table=1, priority=0 actions=FLOOD
223 if test $i != 1; then
224 # Check that hard_age has appeared. We need to do this separately
225 # from the above check because ofctl_strip removes it. dump-flows
226 # only prints hard_age when it is different from the flow's duration
227 # (that is, the number of seconds from the time it was created),
228 # so we only check for it after we've refreshed the flow once.
229 AT_CHECK([grep dl_dst=50:54:00:00:00:07 stdout | grep -c hard_age],
235 # Make sure that 15 seconds without refreshing makes the flow time out.
236 ovs-appctl time/warp 15000 5000
238 AT_CHECK([ovs-ofctl dump-flows br0 table=1 | ofctl_strip | sort], [0], [dnl
239 table=1, priority=0 actions=FLOOD
245 AT_SETUP([learning action - TCPv4 port learning])
247 [add-port br0 p1 -- set Interface p1 type=dummy -- \
248 add-port br0 p2 -- set Interface p2 type=dummy -- \
249 add-port br0 p3 -- set Interface p3 type=dummy])
250 # Set up flow table for TCPv4 port learning.
251 AT_CHECK([[ovs-ofctl add-flow br0 'table=0 tcp actions=learn(table=1, hard_timeout=60, eth_type=0x800, nw_proto=6, NXM_OF_IP_SRC[]=NXM_OF_IP_DST[], NXM_OF_IP_DST[]=NXM_OF_IP_SRC[], NXM_OF_TCP_SRC[]=NXM_OF_TCP_DST[], NXM_OF_TCP_DST[]=NXM_OF_TCP_SRC[]), flood']])
253 # Trace a TCPv4 packet arriving on port 3.
254 flow="in_port(3),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:06),eth_type(0x0800),ipv4(src=192.168.0.2,dst=192.168.0.1,proto=6,tos=0,ttl=64,frag=no),tcp(src=40000,dst=80)"
255 AT_CHECK([ovs-appctl ofproto/trace ovs-dummy "$flow" -generate], [0], [stdout])
256 actual=`tail -1 stdout | sed 's/Datapath actions: //'`
259 AT_CHECK([ovs-dpctl normalize-actions "$flow" "$expected"], [0], [stdout])
261 AT_CHECK([ovs-dpctl normalize-actions "$flow" "$actual"], [0], [expout])
263 # Check for the learning entry.
264 AT_CHECK([ovs-ofctl dump-flows br0 table=1 | ofctl_strip | sort], [0], [dnl
265 table=1, hard_timeout=60, tcp,nw_src=192.168.0.1,nw_dst=192.168.0.2,tp_src=80,tp_dst=40000 actions=drop
271 AT_SETUP([learning action - TCPv6 port learning])
273 [add-port br0 p1 -- set Interface p1 type=dummy -- \
274 add-port br0 p2 -- set Interface p2 type=dummy -- \
275 add-port br0 p3 -- set Interface p3 type=dummy])
276 # Set up flow table for TCPv6 port learning.
277 # Also add a 128-bit-wide "load" action and a 128-bit literal match to check
279 AT_CHECK([[ovs-ofctl add-flow br0 'table=0 tcp6 actions=learn(table=1, hard_timeout=60, eth_type=0x86dd, nw_proto=6, NXM_NX_IPV6_SRC[]=NXM_NX_IPV6_DST[], ipv6_dst=2001:0db8:85a3:0000:0000:8a2e:0370:7334, NXM_OF_TCP_SRC[]=NXM_OF_TCP_DST[], NXM_OF_TCP_DST[]=NXM_OF_TCP_SRC[], load(0x20010db885a308d313198a2e03707348->NXM_NX_IPV6_DST[])), flood']])
281 # Trace a TCPv6 packet arriving on port 3.
282 flow="in_port(3),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:06),eth_type(0x86dd),ipv6(src=fec0::2,dst=fec0::1,label=0,proto=6,tclass=0,hlimit=255,frag=no),tcp(src=40000,dst=80)"
283 AT_CHECK([ovs-appctl ofproto/trace ovs-dummy "$flow" -generate], [0], [stdout])
284 actual=`tail -1 stdout | sed 's/Datapath actions: //'`
287 AT_CHECK([ovs-dpctl normalize-actions "$flow" "$expected"], [0], [stdout])
289 AT_CHECK([ovs-dpctl normalize-actions "$flow" "$actual"], [0], [expout])
291 # Check for the learning entry.
292 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
293 table=1, hard_timeout=60, tcp6,ipv6_src=fec0::1,ipv6_dst=2001:db8:85a3::8a2e:370:7334,tp_src=80,tp_dst=40000 actions=load:0x13198a2e03707348->NXM_NX_IPV6_DST[[0..63]],load:0x20010db885a308d3->NXM_NX_IPV6_DST[[64..127]]
294 tcp6 actions=learn(table=1,hard_timeout=60,eth_type=0x86dd,nw_proto=6,NXM_NX_IPV6_SRC[[]]=NXM_NX_IPV6_DST[[]],ipv6_dst=2001:db8:85a3::8a2e:370:7334,NXM_OF_TCP_SRC[[]]=NXM_OF_TCP_DST[[]],NXM_OF_TCP_DST[[]]=NXM_OF_TCP_SRC[[]],load:0x20010db885a308d313198a2e03707348->NXM_NX_IPV6_DST[[]]),FLOOD
300 # In this use of a learn action, the first packet in the flow creates
301 # a new flow that changes the behavior of subsequent packets in the
303 AT_SETUP([learning action - self-modifying flow])
305 add_of_ports br0 1 2 3
308 # Set up flow table for TCPv4 port learning.
309 AT_CHECK([[ovs-ofctl add-flow br0 'actions=load:3->NXM_NX_REG0[0..15],learn(table=0,priority=65535,NXM_OF_ETH_SRC[],NXM_OF_VLAN_TCI[0..11],output:NXM_NX_REG0[0..15]),output:2']])
311 # Trace some packets arriving. The particular packets don't matter.
312 for i in 1 2 3 4 5 6 7 8 9 10; do
313 ovs-appctl netdev-dummy/receive p1 '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)'
314 ovs-appctl time/warp 10
315 if [[ $i -eq 1 ]]; then
320 # Check for the learning entry.
321 ovs-appctl time/warp 1000
322 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0],
323 [[ n_packets=1, n_bytes=60, actions=load:0x3->NXM_NX_REG0[0..15],learn(table=0,priority=65535,NXM_OF_ETH_SRC[],NXM_OF_VLAN_TCI[0..11],output:NXM_NX_REG0[0..15]),output:2
324 n_packets=9, n_bytes=540, priority=65535,vlan_tci=0x0000/0x0fff,dl_src=50:54:00:00:00:05 actions=output:3
328 # Check that the first packet went out port 2 and the rest out port 3.
330 [(ovs-ofctl dump-ports br0 2; ovs-ofctl dump-ports br0 3) | strip_xids], [0],
331 [OFPST_PORT reply: 1 ports
332 port 2: rx pkts=0, bytes=0, drop=0, errs=0, frame=0, over=0, crc=0
333 tx pkts=1, bytes=60, drop=0, errs=0, coll=0
334 OFPST_PORT reply: 1 ports
335 port 3: rx pkts=0, bytes=0, drop=0, errs=0, frame=0, over=0, crc=0
336 tx pkts=9, bytes=540, drop=0, errs=0, coll=0
342 # This test is much like the previous, but adds idle timeouts and sends
343 # two different flows to the bridge. This tests that the statistics are
344 # attributed correctly.
345 AT_SETUP([learning action - self-modifying flow with idle_timeout])
347 add_of_ports br0 1 2 3
350 # Set up flow table for TCPv4 port learning.
351 AT_CHECK([[ovs-ofctl add-flow br0 'actions=load:3->NXM_NX_REG0[0..15],learn(table=0,idle_timeout=5,priority=65535,NXM_OF_ETH_SRC[],NXM_OF_VLAN_TCI[0..11],output:NXM_NX_REG0[0..15]),output:2']])
353 # Trace some packets arriving. The particular packets don't matter.
354 for i in `seq 1 10`; do
355 ovs-appctl netdev-dummy/receive p1 '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)'
356 ovs-appctl time/warp 10
357 if [[ $i -eq 1 ]]; then
362 # Trace some packets arriving. This is is a different flow from the previous.
363 # Note that we advance time by 1 second between each packet here.
364 for i in `seq 1 10`; do
365 ovs-appctl netdev-dummy/receive p1 'in_port(1),eth(src=50:54:00:00:00:06,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)'
366 ovs-appctl time/warp 1000
367 # Note: netdev-dummy/receive merely queues the packet.
368 # We need to wait for other thread to process the packet
369 # and update the flow's 'used' for the packet.
370 # (i % 3 == 0) below is somehow arbitrary but chosen to ensure
371 # that we update the flow's 'used' frequently enough to prevent
373 if [[ $i -eq 1 -o $((i % 3)) -eq 0 ]]; then
378 # Check that the first packet of each flow went out port 2 and the rest out
381 [(ovs-ofctl dump-ports br0 2; ovs-ofctl dump-ports br0 3) | strip_xids], [0],
382 [OFPST_PORT reply: 1 ports
383 port 2: rx pkts=0, bytes=0, drop=0, errs=0, frame=0, over=0, crc=0
384 tx pkts=2, bytes=120, drop=0, errs=0, coll=0
385 OFPST_PORT reply: 1 ports
386 port 3: rx pkts=0, bytes=0, drop=0, errs=0, frame=0, over=0, crc=0
387 tx pkts=18, bytes=1080, drop=0, errs=0, coll=0
390 # Check for the learning entry.
391 ovs-appctl time/warp 1000
392 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0],
393 [[ n_packets=2, n_bytes=120, actions=load:0x3->NXM_NX_REG0[0..15],learn(table=0,idle_timeout=5,priority=65535,NXM_OF_ETH_SRC[],NXM_OF_VLAN_TCI[0..11],output:NXM_NX_REG0[0..15]),output:2
394 n_packets=9, n_bytes=540, idle_timeout=5, priority=65535,vlan_tci=0x0000/0x0fff,dl_src=50:54:00:00:00:06 actions=output:3
400 # This test is much like the previous, but adds hard timeouts and sends
401 # two different flows to the bridge. This tests that the statistics are
402 # attributed correctly.
403 AT_SETUP([learning action - self-modifying flow with hard_timeout])
405 add_of_ports br0 1 2 3
408 # Set up flow table for TCPv4 port learning.
409 AT_CHECK([[ovs-ofctl add-flow br0 'actions=load:3->NXM_NX_REG0[0..15],learn(table=0,hard_timeout=10,priority=65535,NXM_OF_ETH_SRC[],NXM_OF_VLAN_TCI[0..11],output:NXM_NX_REG0[0..15]),output:2']])
411 # Trace some packets arriving. The particular packets don't matter.
412 for i in `seq 1 10`; do
413 ovs-appctl netdev-dummy/receive p1 '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)'
414 if [[ $i -eq 1 ]]; then
417 ovs-appctl time/warp 10
420 # Trace some packets arriving. This is is a different flow from the previous.
421 # Note that we advance time by 2 second between each packet here.
422 for i in `seq 1 10`; do
423 ovs-appctl netdev-dummy/receive p1 'in_port(1),eth(src=50:54:00:00:00:06,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)'
424 # Note: hard_timeout should fire immediately after #6 packet.
425 # #7 packet re-install the flow and the following 3 packets
426 # (#8, #9, #10) use the flow.
427 # it's difficult to predict the exact timing of rule expiry
428 # because it's affected by flow dumper thread via udpif_dump_seq.
429 # hard_timeout value for this test was chosen to overcome the uncertainty.
431 # receive #1 learn, install flow with hard_timeout=10
432 # sleep to ensure the flow installation
433 # (warp, timeout left 8s)
434 # receive #2 the learned flow
435 # (warp, timeout left 6s)
437 # (warp, timeout left 4s)
439 # (warp, timeout left 2s)
441 # (warp, timeout left 0s)
442 # NOTE: OVS does not consider this expired yet. cf. rule_expire()
444 # (warp, timeout left -2s)
445 # sleep to ensure flow expiration
446 # receive #7 learn, install flow with hard_timeout=10
447 # sleep to ensure the flow installation
448 # (warp, timeout left 8s)
450 # (warp, timeout left 6s)
452 # (warp, timeout left 4s)
454 # (warp, timeout left 2s)
455 if [[ $i -eq 1 -o $i -eq 7 ]]; then
458 ovs-appctl time/warp 2000
459 if [[ $i -eq 6 ]]; then
464 # Check that the first packet of each flow went out port 2 and the rest out
467 [(ovs-ofctl dump-ports br0 2; ovs-ofctl dump-ports br0 3) | strip_xids], [0],
468 [OFPST_PORT reply: 1 ports
469 port 2: rx pkts=0, bytes=0, drop=0, errs=0, frame=0, over=0, crc=0
470 tx pkts=3, bytes=180, drop=0, errs=0, coll=0
471 OFPST_PORT reply: 1 ports
472 port 3: rx pkts=0, bytes=0, drop=0, errs=0, frame=0, over=0, crc=0
473 tx pkts=17, bytes=1020, drop=0, errs=0, coll=0
476 # Check for the learning entry.
477 ovs-appctl time/warp 1000
479 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0],
480 [[ n_packets=3, n_bytes=180, actions=load:0x3->NXM_NX_REG0[0..15],learn(table=0,hard_timeout=10,priority=65535,NXM_OF_ETH_SRC[],NXM_OF_VLAN_TCI[0..11],output:NXM_NX_REG0[0..15]),output:2
481 n_packets=3, n_bytes=180, hard_timeout=10, priority=65535,vlan_tci=0x0000/0x0fff,dl_src=50:54:00:00:00:06 actions=output:3
487 AT_SETUP([learning action - fin_timeout feature])
488 # This is a totally artificial use of the "learn" action. The only purpose
489 # is to check that specifying fin_idle_timeout or fin_hard_timeout causes
490 # a corresponding fin_timeout action to end up in the learned flows.
492 [add-port br0 p1 -- set Interface p1 type=dummy ofport_request=1])
493 AT_CHECK([[ovs-ofctl add-flow br0 'actions=learn(fin_hard_timeout=10, fin_idle_timeout=5, NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[], output:NXM_OF_IN_PORT[])']])
494 AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(1),eth(src=50:54:00:00:00:05,dst=ff:ff:ff:ff:ff:ff),eth_type(0x0806),arp(sip=192.168.0.1,tip=192.168.0.2,op=1,sha=50:54:00:00:00:05,tha=00:00:00:00:00:00)' -generate], [0], [ignore])
495 AT_CHECK([ovs-ofctl dump-flows br0 table=1 | ofctl_strip], [0],
497 table=1, dl_dst=50:54:00:00:00:05 actions=fin_timeout(idle_timeout=5,hard_timeout=10),output:1
502 AT_SETUP([learning action - delete_learned feature])
505 # Add some initial flows and check that it was successful.
506 AT_DATA([flows.txt], [dnl
507 reg0=0x1 actions=learn(delete_learned,cookie=0x123)
508 reg0=0x2 actions=learn(delete_learned,cookie=0x123)
509 cookie=0x123, table=1, reg0=0x3 actions=drop
510 cookie=0x123, table=1, reg0=0x4 actions=drop
511 cookie=0x123, table=2, reg0=0x5 actions=drop
512 cookie=0x234, table=1, reg0=0x6 actions=drop
514 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
515 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
516 cookie=0x123, table=1, reg0=0x3 actions=drop
517 cookie=0x123, table=1, reg0=0x4 actions=drop
518 cookie=0x123, table=2, reg0=0x5 actions=drop
519 cookie=0x234, table=1, reg0=0x6 actions=drop
520 reg0=0x1 actions=learn(table=1,delete_learned,cookie=0x123)
521 reg0=0x2 actions=learn(table=1,delete_learned,cookie=0x123)
525 # Delete one of the learn actions. The learned flows should stay, since there
526 # is another learn action with the identical target.
527 AT_CHECK([ovs-ofctl del-flows br0 'table=0 reg0=1'])
528 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
529 cookie=0x123, table=1, reg0=0x3 actions=drop
530 cookie=0x123, table=1, reg0=0x4 actions=drop
531 cookie=0x123, table=2, reg0=0x5 actions=drop
532 cookie=0x234, table=1, reg0=0x6 actions=drop
533 reg0=0x2 actions=learn(table=1,delete_learned,cookie=0x123)
537 # Change the flow with the learn action by adding a second action. The learned
538 # flows should stay because the learn action is still there.
539 AT_CHECK([ovs-ofctl mod-flows br0 'table=0 reg0=2 actions=output:1,learn(delete_learned,cookie=0x123)'])
540 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
541 cookie=0x123, table=1, reg0=0x3 actions=drop
542 cookie=0x123, table=1, reg0=0x4 actions=drop
543 cookie=0x123, table=2, reg0=0x5 actions=drop
544 cookie=0x234, table=1, reg0=0x6 actions=drop
545 reg0=0x2 actions=output:1,learn(table=1,delete_learned,cookie=0x123)
549 # Change the flow with the learn action by replacing its learn action by one
550 # with a different target. The (previous) learned flows disappear.
551 AT_CHECK([ovs-ofctl mod-flows br0 'table=0 reg0=2 actions=learn(delete_learned,cookie=0x234)'])
552 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
553 cookie=0x123, table=2, reg0=0x5 actions=drop
554 cookie=0x234, table=1, reg0=0x6 actions=drop
555 reg0=0x2 actions=learn(table=1,delete_learned,cookie=0x234)
559 # Use add-flow to replace the flow with the learn action by one with the
560 # same learn action and an extra action. The (new) learned flow remains.
561 AT_CHECK([ovs-ofctl add-flow br0 'table=0 reg0=2 actions=learn(delete_learned,cookie=0x234),output:2'])
562 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
563 cookie=0x123, table=2, reg0=0x5 actions=drop
564 cookie=0x234, table=1, reg0=0x6 actions=drop
565 reg0=0x2 actions=learn(table=1,delete_learned,cookie=0x234),output:2
569 # Delete the flow with the learn action. The learned flow disappears too.
570 AT_CHECK([ovs-ofctl del-flows br0 table=0])
571 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
572 cookie=0x123, table=2, reg0=0x5 actions=drop
576 # Add a new set of flows to check on a corner case: the learned flows
577 # contain their own learn actions which cascade to further deletions.
578 # This can't happen if the learned flows were actually created by a
579 # learn action, since the learn action has very restricted action
580 # support, but there's no restriction that the deleted flows were
581 # created by a learn action.
582 AT_DATA([flows.txt], [dnl
583 reg0=0x1 actions=learn(table=1,delete_learned,cookie=0x123)
584 reg0=0x2 actions=learn(table=2,delete_learned,cookie=0x234)
585 cookie=0x123, table=1, reg0=0x3 actions=learn(table=3,delete_learned,cookie=0x345)
586 cookie=0x234, table=2, reg0=0x3 actions=learn(table=4,delete_learned,cookie=0x456)
587 cookie=0x345, table=3, reg0=0x4 actions=learn(table=5,delete_learned,cookie=0x567)
588 cookie=0x456, table=4, reg0=0x5 actions=learn(table=5,delete_learned,cookie=0x567)
589 cookie=0x567, table=5, reg0=0x6 actions=drop
590 cookie=0x567, table=5, reg0=0x7 actions=drop
591 cookie=0x567, table=5, reg0=0x8 actions=drop
593 AT_CHECK([ovs-ofctl del-flows br0])
594 AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
595 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
596 cookie=0x123, table=1, reg0=0x3 actions=learn(table=3,delete_learned,cookie=0x345)
597 cookie=0x234, table=2, reg0=0x3 actions=learn(table=4,delete_learned,cookie=0x456)
598 cookie=0x345, table=3, reg0=0x4 actions=learn(table=5,delete_learned,cookie=0x567)
599 cookie=0x456, table=4, reg0=0x5 actions=learn(table=5,delete_learned,cookie=0x567)
600 cookie=0x567, table=5, reg0=0x6 actions=drop
601 cookie=0x567, table=5, reg0=0x7 actions=drop
602 cookie=0x567, table=5, reg0=0x8 actions=drop
603 reg0=0x1 actions=learn(table=1,delete_learned,cookie=0x123)
604 reg0=0x2 actions=learn(table=2,delete_learned,cookie=0x234)
608 # Deleting the flow with reg0=1 should cascade to delete a few levels
609 # of learned flows, but the ones with cookie=0x567 stick around
610 # because of the flow with cookie=0x456.
611 AT_CHECK([ovs-ofctl del-flows br0 'table=0 reg0=1'])
612 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
613 cookie=0x234, table=2, reg0=0x3 actions=learn(table=4,delete_learned,cookie=0x456)
614 cookie=0x456, table=4, reg0=0x5 actions=learn(table=5,delete_learned,cookie=0x567)
615 cookie=0x567, table=5, reg0=0x6 actions=drop
616 cookie=0x567, table=5, reg0=0x7 actions=drop
617 cookie=0x567, table=5, reg0=0x8 actions=drop
618 reg0=0x2 actions=learn(table=2,delete_learned,cookie=0x234)
622 # Deleting the flow with reg0=2 should cascade to delete all the rest:
623 AT_CHECK([ovs-ofctl del-flows br0 'table=0 reg0=2'])
624 AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl