1 ; SPDX-License-Identifier: BSD-3-Clause
2 ; Copyright(c) 2020 Intel Corporation
17 bit<16> identification
40 header ethernet instanceof ethernet_h
41 header ipv4 instanceof ipv4_h
42 header outer_ethernet instanceof ethernet_h
43 header outer_ipv4 instanceof ipv4_h
44 header outer_udp instanceof udp_h
45 header outer_vxlan instanceof vxlan_h
55 metadata instanceof metadata_t
60 struct vxlan_encap_args_t {
61 bit<48> ethernet_dst_addr
62 bit<48> ethernet_src_addr
63 bit<16> ethernet_ethertype
66 bit<16> ipv4_total_len
67 bit<16> ipv4_identification
68 bit<16> ipv4_flags_offset
71 bit<16> ipv4_hdr_checksum
79 bit<24> vxlan_reserved
81 bit<8> vxlan_reserved2
86 // Ethernet (14) | IPv4 (total_len)
89 // Ethernet (14) | IPv4 (20) | UDP (8) | VXLAN (8) | Input frame | Ethernet FCS (4)
91 // Note: The input frame has its FCS removed before encapsulation in the output
94 // Assumption: When read from the table, the outer IPv4 and UDP headers contain
95 // the following fields:
96 // - t.ipv4_total_len: Set to 50, which covers the length of:
97 // - The outer IPv4 header (20 bytes);
98 // - The outer UDP header (8 bytes);
99 // - The outer VXLAN header (8 bytes);
100 // - The inner Ethernet header (14 bytes);
101 // - t.ipv4_hdr_checksum: Includes the above total length.
102 // - t.udp_length: Set to 30, which covers the length of:
103 // - The outer UDP header (8 bytes);
104 // - The outer VXLAN header (8 bytes);
105 // - The inner Ethernet header (14 bytes);
106 // - t.udp_checksum: Set to 0.
108 // Once the total length of the inner IPv4 packet (h.ipv4.total_len) is known,
109 // the outer IPv4 and UDP headers are updated as follows:
110 // - h.outer_ipv4.total_len = t.ipv4_total_len + h.ipv4.total_len
111 // - h.outer_ipv4.hdr_checksum = t.ipv4_hdr_checksum + h.ipv4.total_len
112 // - h.outer_udp.length = t.udp_length + h.ipv4.total_len
113 // - h.outer_udp.checksum: No change.
116 action vxlan_encap args instanceof vxlan_encap_args_t {
117 //Set the outer Ethernet header.
118 mov h.outer_ethernet.dst_addr t.ethernet_dst_addr
119 mov h.outer_ethernet.src_addr t.ethernet_src_addr
120 mov h.outer_ethernet.ethertype t.ethernet_ethertype
121 validate h.outer_ethernet
123 //Set the outer IPv4 header.
124 mov h.outer_ipv4.ver_ihl t.ipv4_ver_ihl
125 mov h.outer_ipv4.diffserv t.ipv4_diffserv
126 mov h.outer_ipv4.total_len t.ipv4_total_len
127 mov h.outer_ipv4.identification t.ipv4_identification
128 mov h.outer_ipv4.flags_offset t.ipv4_flags_offset
129 mov h.outer_ipv4.ttl t.ipv4_ttl
130 mov h.outer_ipv4.protocol t.ipv4_protocol
131 mov h.outer_ipv4.hdr_checksum t.ipv4_hdr_checksum
132 mov h.outer_ipv4.src_addr t.ipv4_src_addr
133 mov h.outer_ipv4.dst_addr t.ipv4_dst_addr
134 validate h.outer_ipv4
136 //Set the outer UDP header.
137 mov h.outer_udp.src_port t.udp_src_port
138 mov h.outer_udp.dst_port t.udp_dst_port
139 mov h.outer_udp.length t.udp_length
140 mov h.outer_udp.checksum t.udp_checksum
143 //Set the outer VXLAN header.
144 mov h.outer_vxlan.flags t.vxlan_flags
145 mov h.outer_vxlan.reserved t.vxlan_reserved
146 mov h.outer_vxlan.vni t.vxlan_vni
147 mov h.outer_vxlan.reserved2 t.vxlan_reserved2
148 validate h.outer_vxlan
150 //Set the output port.
151 mov m.port_out t.port_out
153 //Update h.outer_ipv4.total_len field.
154 add h.outer_ipv4.total_len h.ipv4.total_len
156 //Update h.outer_ipv4.hdr_checksum field.
157 ckadd h.outer_ipv4.hdr_checksum h.ipv4.total_len
159 //Update h.outer_udp.length field.
160 add h.outer_udp.length h.ipv4.total_len
165 action drop args none {
174 h.ethernet.dst_addr exact
182 default_action drop args none
194 emit h.outer_ethernet