Add example for FIB with VRF and ECMP support.
Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Signed-off-by: Churchill Khangar <churchill.khangar@intel.com>
--- /dev/null
+; SPDX-License-Identifier: BSD-3-Clause
+; Copyright(c) 2020 Intel Corporation
+
+;
+; Customize the LINK parameters to match your setup.
+;
+mempool MEMPOOL0 buffer 2304 pool 32K cache 256 cpu 0
+
+link LINK0 dev 0000:18:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK1 dev 0000:18:00.1 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK2 dev 0000:3b:00.0 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+link LINK3 dev 0000:3b:00.1 rxq 1 128 MEMPOOL0 txq 1 512 promiscuous on
+
+;
+; PIPELINE0 setup.
+;
+pipeline PIPELINE0 create 0
+
+pipeline PIPELINE0 port in 0 link LINK0 rxq 0 bsz 32
+pipeline PIPELINE0 port in 1 link LINK1 rxq 0 bsz 32
+pipeline PIPELINE0 port in 2 link LINK2 rxq 0 bsz 32
+pipeline PIPELINE0 port in 3 link LINK3 rxq 0 bsz 32
+
+pipeline PIPELINE0 port out 0 link LINK0 txq 0 bsz 32
+pipeline PIPELINE0 port out 1 link LINK1 txq 0 bsz 32
+pipeline PIPELINE0 port out 2 link LINK2 txq 0 bsz 32
+pipeline PIPELINE0 port out 3 link LINK3 txq 0 bsz 32
+pipeline PIPELINE0 port out 4 sink none
+
+pipeline PIPELINE0 build ./examples/pipeline/examples/fib.spec
+
+;
+; Initial set of table entries.
+;
+; The table entries can later be updated at run-time through the CLI commands. Once the application
+; has been successfully started, the command to get the CLI prompt is: telnet 0.0.0.0 8086.
+;
+pipeline PIPELINE0 table routing_table add ./examples/pipeline/examples/fib_routing_table.txt
+pipeline PIPELINE0 selector nexthop_group_table group add
+pipeline PIPELINE0 selector nexthop_group_table group add
+pipeline PIPELINE0 selector nexthop_group_table group add
+pipeline PIPELINE0 selector nexthop_group_table group add
+pipeline PIPELINE0 selector nexthop_group_table group add
+pipeline PIPELINE0 selector nexthop_group_table group add
+pipeline PIPELINE0 selector nexthop_group_table group add
+pipeline PIPELINE0 selector nexthop_group_table group add
+pipeline PIPELINE0 selector nexthop_group_table group add
+pipeline PIPELINE0 selector nexthop_group_table group add
+pipeline PIPELINE0 selector nexthop_group_table group add
+pipeline PIPELINE0 selector nexthop_group_table group add
+pipeline PIPELINE0 selector nexthop_group_table group member add ./examples/pipeline/examples/fib_nexthop_group_table.txt
+pipeline PIPELINE0 table nexthop_table add ./examples/pipeline/examples/fib_nexthop_table.txt
+pipeline PIPELINE0 commit
+
+;
+; Pipelines-to-threads mapping.
+;
+thread 1 pipeline PIPELINE0 enable
--- /dev/null
+; SPDX-License-Identifier: BSD-3-Clause
+; Copyright(c) 2021 Intel Corporation
+
+; This example illustrates a FIB [1] with VRF [2] and ECMP [3] support. A FIB essentially is the
+; data plane copy of the routing table. The VRF support allows for multiple logical routing tables
+; to co-exist as part of the same "physical" routing table; the VRF ID typically identifies the
+; logical table to provide the matching route for the IP destination address of the input packet.
+; The ECMP provides a load balancing mechanism for the packet forwarding by allowing for multiple
+; next hops (of equal or different weights, in case of WCMP [4]) to be provided for each route.
+;
+; In this example, the VRF ID is read from the IP source address of the input packet as opposed to a
+; more complex classification scheme being used. The routing table produces the ID of the group of
+; next hops associated with the current route, out of which a single next hop is selected based on a
+; hashing scheme that preserves the packet order within each flow (with the flow defined here by a
+; typical 3-tuple) by always selecting the same next hop for packets that are part of the same flow.
+; The next hop provides the Ethernet header and the output port for the outgoing packet.
+;
+; [1] Forwarding Information Base (FIB):
+; https://en.wikipedia.org/wiki/Forwarding_information_base
+; [2] Virtual Routing and Forwarding (VRF):
+; https://en.wikipedia.org/wiki/Virtual_routing_and_forwarding
+; [3] Equal-Cost Multi-Path (ECMP) routing:
+; https://en.wikipedia.org/wiki/Equal-cost_multi-path_routing
+; [4] Weighted-Cost Multi-Path (WCMP) routing.
+
+//
+// Headers
+//
+struct ethernet_h {
+ bit<48> dst_addr
+ bit<48> src_addr
+ bit<16> ethertype
+}
+
+struct ipv4_h {
+ bit<8> ver_ihl
+ bit<8> diffserv
+ bit<16> total_len
+ bit<16> identification
+ bit<16> flags_offset
+ bit<8> ttl
+ bit<8> protocol
+ bit<16> hdr_checksum
+ bit<32> src_addr
+ bit<32> dst_addr
+}
+
+header ethernet instanceof ethernet_h
+header ipv4 instanceof ipv4_h
+
+//
+// Meta-data
+//
+struct metadata_t {
+ bit<32> port_in
+ bit<32> port_out
+ bit<32> vrf_id
+ bit<32> dst_addr
+ bit<32> nexthop_group_id
+ bit<32> nexthop_id
+}
+
+metadata instanceof metadata_t
+
+//
+// Actions
+//
+struct nexthop_group_action_args_t {
+ bit<32> nexthop_group_id
+}
+
+action nexthop_group_action args instanceof nexthop_group_action_args_t {
+ mov m.nexthop_group_id t.nexthop_group_id
+ return
+}
+
+struct nexthop_action_args_t {
+ bit<48> ethernet_dst_addr
+ bit<48> ethernet_src_addr
+ bit<16> ethernet_ethertype
+ bit<32> port_out
+}
+
+action nexthop_action args instanceof nexthop_action_args_t {
+ //Set Ethernet header.
+ mov h.ethernet.dst_addr t.ethernet_dst_addr
+ mov h.ethernet.src_addr t.ethernet_src_addr
+ mov h.ethernet.ethertype t.ethernet_ethertype
+ validate h.ethernet
+
+ //Decrement the TTL and update the checksum within the IPv4 header.
+ cksub h.ipv4.hdr_checksum h.ipv4.ttl
+ sub h.ipv4.ttl 0x1
+ ckadd h.ipv4.hdr_checksum h.ipv4.ttl
+
+ //Set the output port.
+ mov m.port_out t.port_out
+
+ return
+}
+
+action drop args none {
+ drop
+}
+
+//
+// Tables
+//
+table routing_table {
+ key {
+ m.vrf_id exact
+ m.dst_addr lpm
+ }
+
+ actions {
+ nexthop_group_action
+ drop
+ }
+
+ default_action drop args none
+
+ size 1048576
+}
+
+selector nexthop_group_table {
+ group_id m.nexthop_group_id
+
+ selector {
+ h.ipv4.protocol
+ h.ipv4.src_addr
+ h.ipv4.dst_addr
+ }
+
+ member_id m.nexthop_id
+
+ n_groups_max 65536
+
+ n_members_per_group_max 64
+}
+
+table nexthop_table {
+ key {
+ m.nexthop_id exact
+ }
+
+ actions {
+ nexthop_action
+ drop
+ }
+
+ default_action drop args none
+
+ size 1048576
+}
+
+//
+// Pipeline
+//
+apply {
+ rx m.port_in
+ extract h.ethernet
+ extract h.ipv4
+ mov m.vrf_id h.ipv4.src_addr
+ mov m.dst_addr h.ipv4.dst_addr
+ table routing_table
+ table nexthop_group_table
+ table nexthop_table
+ emit h.ethernet
+ emit h.ipv4
+ tx m.port_out
+}
--- /dev/null
+; SPDX-License-Identifier: BSD-3-Clause
+; Copyright(c) 2021 Intel Corporation
+
+// Nexthop group #0 (Single member)
+group 0 member 0 weight 1
+
+// Nexthop group #1 (Single member)
+group 1 member 1 weight 1
+
+// Nexthop group #2 (Single member)
+group 2 member 2 weight 1
+
+// Nexthop group #3 (Single member)
+group 3 member 3 weight 1
+
+// Nexthop group #4 (ECMP)
+group 4 member 4 weight 1
+group 4 member 5 weight 1
+
+// Nexthop group #5 (ECMP)
+group 5 member 5 weight 1
+group 5 member 6 weight 1
+
+// Nexthop group #6 (ECMP)
+group 6 member 6 weight 1
+group 6 member 7 weight 1
+
+// Nexthop group #7 (ECMP)
+group 7 member 7 weight 1
+group 7 member 4 weight 1
+
+// Nexthop group #8 (WCMP)
+group 8 member 8 weight 4
+group 8 member 9 weight 2
+group 8 member 10 weight 1
+group 8 member 11 weight 1
+
+// Nexthop group #9 (WCMP)
+group 9 member 9 weight 4
+group 9 member 10 weight 2
+group 9 member 11 weight 1
+group 9 member 8 weight 1
+
+// Nexthop group #10 (WCMP)
+group 10 member 10 weight 4
+group 10 member 11 weight 2
+group 10 member 8 weight 1
+group 10 member 9 weight 1
+
+// Nexthop group #11 (WCMP)
+group 11 member 11 weight 4
+group 11 member 8 weight 2
+group 11 member 9 weight 1
+group 11 member 10 weight 1
--- /dev/null
+; SPDX-License-Identifier: BSD-3-Clause
+; Copyright(c) 2021 Intel Corporation
+
+match 0 action nexthop_action ethernet_dst_addr 0xaabbcc000000 ethernet_src_addr 0xddeeff000000 ethernet_ethertype 0x0800 port_out 0
+match 1 action nexthop_action ethernet_dst_addr 0xaabbcc000001 ethernet_src_addr 0xddeeff000001 ethernet_ethertype 0x0800 port_out 1
+match 2 action nexthop_action ethernet_dst_addr 0xaabbcc000002 ethernet_src_addr 0xddeeff000002 ethernet_ethertype 0x0800 port_out 2
+match 3 action nexthop_action ethernet_dst_addr 0xaabbcc000003 ethernet_src_addr 0xddeeff000003 ethernet_ethertype 0x0800 port_out 3
+
+match 4 action nexthop_action ethernet_dst_addr 0xaabbcc000004 ethernet_src_addr 0xddeeff000004 ethernet_ethertype 0x0800 port_out 0
+match 5 action nexthop_action ethernet_dst_addr 0xaabbcc000005 ethernet_src_addr 0xddeeff000005 ethernet_ethertype 0x0800 port_out 1
+match 6 action nexthop_action ethernet_dst_addr 0xaabbcc000006 ethernet_src_addr 0xddeeff000006 ethernet_ethertype 0x0800 port_out 2
+match 7 action nexthop_action ethernet_dst_addr 0xaabbcc000007 ethernet_src_addr 0xddeeff000007 ethernet_ethertype 0x0800 port_out 3
+
+match 8 action nexthop_action ethernet_dst_addr 0xaabbcc000008 ethernet_src_addr 0xddeeff000008 ethernet_ethertype 0x0800 port_out 0
+match 9 action nexthop_action ethernet_dst_addr 0xaabbcc000009 ethernet_src_addr 0xddeeff000009 ethernet_ethertype 0x0800 port_out 1
+match 10 action nexthop_action ethernet_dst_addr 0xaabbcc00000a ethernet_src_addr 0xddeeff00000a ethernet_ethertype 0x0800 port_out 2
+match 11 action nexthop_action ethernet_dst_addr 0xaabbcc00000b ethernet_src_addr 0xddeeff00000b ethernet_ethertype 0x0800 port_out 3
+
+match 12 action nexthop_action ethernet_dst_addr 0xaabbcc00000c ethernet_src_addr 0xddeeff00000c ethernet_ethertype 0x0800 port_out 0
+match 13 action nexthop_action ethernet_dst_addr 0xaabbcc00000d ethernet_src_addr 0xddeeff00000d ethernet_ethertype 0x0800 port_out 1
+match 14 action nexthop_action ethernet_dst_addr 0xaabbcc00000e ethernet_src_addr 0xddeeff00000e ethernet_ethertype 0x0800 port_out 2
+match 15 action nexthop_action ethernet_dst_addr 0xaabbcc00000f ethernet_src_addr 0xddeeff00000f ethernet_ethertype 0x0800 port_out 3
--- /dev/null
+; SPDX-License-Identifier: BSD-3-Clause
+; Copyright(c) 2021 Intel Corporation
+
+// VRF #0
+match 0 0x00000000/0xC0000000 action nexthop_group_action nexthop_group_id 0
+match 0 0x40000000/0xC0000000 action nexthop_group_action nexthop_group_id 1
+match 0 0x80000000/0xC0000000 action nexthop_group_action nexthop_group_id 2
+match 0 0xC0000000/0xC0000000 action nexthop_group_action nexthop_group_id 3
+
+// VRF #1
+match 1 0x00000000/0xC0000000 action nexthop_group_action nexthop_group_id 4
+match 1 0x40000000/0xC0000000 action nexthop_group_action nexthop_group_id 5
+match 1 0x80000000/0xC0000000 action nexthop_group_action nexthop_group_id 6
+match 1 0xC0000000/0xC0000000 action nexthop_group_action nexthop_group_id 7
+
+// VRF #2
+match 2 0x00000000/0xC0000000 action nexthop_group_action nexthop_group_id 8
+match 2 0x40000000/0xC0000000 action nexthop_group_action nexthop_group_id 9
+match 2 0x80000000/0xC0000000 action nexthop_group_action nexthop_group_id 10
+match 2 0xC0000000/0xC0000000 action nexthop_group_action nexthop_group_id 11
+
+// VRF #3
+match 3 0x00000000/0x00000000 action nexthop_group_action nexthop_group_id 4
+match 3 0x80000000/0x80000000 action nexthop_group_action nexthop_group_id 5
+match 3 0xC0000000/0xC0000000 action nexthop_group_action nexthop_group_id 6
+
+// VRF #4
+match 4 0x00000000/0x00000000 action nexthop_group_action nexthop_group_id 8
+match 4 0x80000000/0x80000000 action nexthop_group_action nexthop_group_id 9
+match 4 0xC0000000/0xC0000000 action nexthop_group_action nexthop_group_id 10