blob: a73e726541b8a1642d6928701d2a3a19e0020939 [file] [log] [blame]
/*
* Copyright 2017-present Open Networking Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* -*- P4_16 -*- */
#ifndef __INT_PARSER__
#define __INT_PARSER__
parser int_parser (
packet_in packet,
out headers_t hdr,
inout local_metadata_t local_metadata,
inout standard_metadata_t standard_metadata) {
state start {
transition select(standard_metadata.ingress_port) {
CPU_PORT: parse_packet_out;
default: parse_ethernet;
}
}
state parse_packet_out {
packet.extract(hdr.packet_out);
transition parse_ethernet;
}
state parse_ethernet {
packet.extract(hdr.ethernet);
transition select(hdr.ethernet.ether_type) {
ETH_TYPE_IPV4 : parse_ipv4;
default : accept;
}
}
state parse_ipv4 {
packet.extract(hdr.ipv4);
transition select(hdr.ipv4.protocol) {
IP_PROTO_TCP : parse_tcp;
IP_PROTO_UDP : parse_udp;
default: accept;
}
}
state parse_tcp {
packet.extract(hdr.tcp);
local_metadata.l4_src_port = hdr.tcp.src_port;
local_metadata.l4_dst_port = hdr.tcp.dst_port;
transition select(hdr.ipv4.dscp) {
DSCP_INT &&& DSCP_MASK: parse_intl4_shim;
default: accept;
}
}
state parse_udp {
packet.extract(hdr.udp);
local_metadata.l4_src_port = hdr.udp.src_port;
local_metadata.l4_dst_port = hdr.udp.dst_port;
transition select(hdr.ipv4.dscp) {
DSCP_INT &&& DSCP_MASK: parse_intl4_shim;
default: accept;
}
}
state parse_intl4_shim {
packet.extract(hdr.intl4_shim);
local_metadata.int_meta.intl4_shim_len = hdr.intl4_shim.len;
transition parse_int_header;
}
state parse_int_header {
packet.extract(hdr.int_header);
transition parse_int_data;
}
state parse_int_data {
// Parse INT metadata stack
packet.extract(hdr.int_data, ((bit<32>) (local_metadata.int_meta.intl4_shim_len - INT_HEADER_LEN_WORD)) << 5);
transition accept;
}
}
control int_deparser(
packet_out packet,
in headers_t hdr) {
apply {
packet.emit(hdr.packet_in);
packet.emit(hdr.report_ethernet);
packet.emit(hdr.report_ipv4);
packet.emit(hdr.report_udp);
packet.emit(hdr.report_fixed_header);
packet.emit(hdr.ethernet);
packet.emit(hdr.ipv4);
packet.emit(hdr.tcp);
packet.emit(hdr.udp);
packet.emit(hdr.intl4_shim);
packet.emit(hdr.int_header);
packet.emit(hdr.int_switch_id);
packet.emit(hdr.int_level1_port_ids);
packet.emit(hdr.int_hop_latency);
packet.emit(hdr.int_q_occupancy);
packet.emit(hdr.int_ingress_tstamp);
packet.emit(hdr.int_egress_tstamp);
packet.emit(hdr.int_level2_port_ids);
packet.emit(hdr.int_egress_tx_util);
packet.emit(hdr.int_data);
}
}
#endif