1 ; SPDX-License-Identifier: BSD-3-Clause
2 ; Copyright(c) 2020 Intel Corporation
4 ; The learner tables are very useful for learning and connection tracking.
6 ; As opposed to regular tables, which are read-only for the data plane, the learner tables can be
7 ; updated by the data plane without any control plane intervention. The "learning" process typically
8 ; takes place by having the default action (i.e. the table action which is executed on lookup miss)
9 ; explicitly add to the table with a specific action the key that just missed the lookup operation.
10 ; Each table key expires automatically after a configurable timeout period if not hit during this
13 ; This example demonstrates a simple connection tracking setup, where the connections are identified
14 ; by the IPv4 destination address. The forwarding action assigned to each new connection gets the
15 ; output port as argument, with the output port of each connection generated by a counter that is
16 ; persistent between packets. On top of the usual table stats, the learner table stats include the
17 ; number of packets with learning related events.
32 bit<16> identification
41 header ethernet instanceof ethernet_h
42 header ipv4 instanceof ipv4_h
54 // Arguments for the "fwd_action" action.
55 bit<32> fwd_action_arg_port_out
58 metadata instanceof metadata_t
63 regarray counter size 1 initval 0
68 struct fwd_action_args_t {
72 action fwd_action args instanceof fwd_action_args_t {
73 mov m.port_out t.port_out
78 action learn_action args none {
79 // Pick the key timeout. Timeout ID #1 (i.e. 120 seconds) is selected.
82 // Read current counter value into m.fwd_action_arg_port_out.
83 regrd m.fwd_action_arg_port_out counter 0
85 // Increment the counter.
88 // Limit the output port values to 0 .. 3.
89 and m.fwd_action_arg_port_out 3
91 // Add the current lookup key to the table with fwd_action as the key action. The action
92 // arguments are read from the packet meta-data (the m.fwd_action_arg_port_out field). These
93 // packet meta-data fields have to be written before the "learn" instruction is invoked.
94 learn fwd_action m.fwd_action_arg_port_out m.timeout_id
96 // Send the current packet to the same output port.
97 mov m.port_out m.fwd_action_arg_port_out
116 default_action learn_action args none