1 ; SPDX-License-Identifier: BSD-3-Clause
2 ; Copyright(c) 2021 Intel Corporation
4 ; This example illustrates a FIB [1] with VRF [2] and ECMP [3] support. A FIB essentially is the
5 ; data plane copy of the routing table. The VRF support allows for multiple logical routing tables
6 ; to co-exist as part of the same "physical" routing table; the VRF ID typically identifies the
7 ; logical table to provide the matching route for the IP destination address of the input packet.
8 ; The ECMP provides a load balancing mechanism for the packet forwarding by allowing for multiple
9 ; next hops (of equal or different weights, in case of WCMP [4]) to be provided for each route.
11 ; In this example, the VRF ID is read from the IP source address of the input packet as opposed to a
12 ; more complex classification scheme being used. The routing table produces the ID of the group of
13 ; next hops associated with the current route, out of which a single next hop is selected based on a
14 ; hashing scheme that preserves the packet order within each flow (with the flow defined here by a
15 ; typical 3-tuple) by always selecting the same next hop for packets that are part of the same flow.
16 ; The next hop provides the Ethernet header and the output port for the outgoing packet.
18 ; [1] Forwarding Information Base (FIB):
19 ; https://en.wikipedia.org/wiki/Forwarding_information_base
20 ; [2] Virtual Routing and Forwarding (VRF):
21 ; https://en.wikipedia.org/wiki/Virtual_routing_and_forwarding
22 ; [3] Equal-Cost Multi-Path (ECMP) routing:
23 ; https://en.wikipedia.org/wiki/Equal-cost_multi-path_routing
24 ; [4] Weighted-Cost Multi-Path (WCMP) routing.
39 bit<16> identification
48 header ethernet instanceof ethernet_h
49 header ipv4 instanceof ipv4_h
59 bit<32> nexthop_group_id
63 metadata instanceof metadata_t
68 struct nexthop_group_action_args_t {
69 bit<32> nexthop_group_id
72 action nexthop_group_action args instanceof nexthop_group_action_args_t {
73 mov m.nexthop_group_id t.nexthop_group_id
77 struct nexthop_action_args_t {
78 bit<48> ethernet_dst_addr
79 bit<48> ethernet_src_addr
80 bit<16> ethernet_ethertype
84 action nexthop_action args instanceof nexthop_action_args_t {
85 //Set Ethernet header.
86 mov h.ethernet.dst_addr t.ethernet_dst_addr
87 mov h.ethernet.src_addr t.ethernet_src_addr
88 mov h.ethernet.ethertype t.ethernet_ethertype
91 //Decrement the TTL and update the checksum within the IPv4 header.
92 cksub h.ipv4.hdr_checksum h.ipv4.ttl
94 ckadd h.ipv4.hdr_checksum h.ipv4.ttl
96 //Set the output port.
97 mov m.port_out t.port_out
102 action drop args none {
109 table routing_table {
120 default_action drop args none
125 selector nexthop_group_table {
126 group_id m.nexthop_group_id
134 member_id m.nexthop_id
138 n_members_per_group_max 64
141 table nexthop_table {
151 default_action drop args none
163 mov m.vrf_id h.ipv4.src_addr
164 mov m.dst_addr h.ipv4.dst_addr
166 table nexthop_group_table