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
51 // Arguments for the "fwd_action" action.
52 bit<32> fwd_action_arg_port_out
55 metadata instanceof metadata_t
60 regarray counter size 1 initval 0
65 struct fwd_action_args_t {
69 action fwd_action args instanceof fwd_action_args_t {
70 mov m.port_out t.port_out
74 action learn_action args none {
75 // Read current counter value into m.fwd_action_arg_port_out.
76 regrd m.fwd_action_arg_port_out counter 0
78 // Increment the counter.
81 // Limit the output port values to 0 .. 3.
82 and m.fwd_action_arg_port_out 3
84 // Add the current lookup key to the table with fwd_action as the key action. The action
85 // arguments are read from the packet meta-data (the m.fwd_action_arg_port_out field). These
86 // packet meta-data fields have to be written before the "learn" instruction is invoked.
89 // Send the current packet to the same output port.
90 mov m.port_out m.fwd_action_arg_port_out
104 fwd_action args m.fwd_action_arg_port_out
106 learn_action args none
109 default_action learn_action args none