blob: a73e726541b8a1642d6928701d2a3a19e0020939 [file] [log] [blame]
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -08001/*
2 * Copyright 2017-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/* -*- P4_16 -*- */
Jonghwan Hyun8be03392017-12-04 15:48:44 -080018#ifndef __INT_PARSER__
19#define __INT_PARSER__
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -080020
21parser int_parser (
22 packet_in packet,
23 out headers_t hdr,
24 inout local_metadata_t local_metadata,
25 inout standard_metadata_t standard_metadata) {
26 state start {
27 transition select(standard_metadata.ingress_port) {
28 CPU_PORT: parse_packet_out;
29 default: parse_ethernet;
30 }
31 }
32
33 state parse_packet_out {
34 packet.extract(hdr.packet_out);
35 transition parse_ethernet;
36 }
37
38 state parse_ethernet {
39 packet.extract(hdr.ethernet);
40 transition select(hdr.ethernet.ether_type) {
41 ETH_TYPE_IPV4 : parse_ipv4;
42 default : accept;
43 }
44 }
45
46 state parse_ipv4 {
47 packet.extract(hdr.ipv4);
48 transition select(hdr.ipv4.protocol) {
49 IP_PROTO_TCP : parse_tcp;
50 IP_PROTO_UDP : parse_udp;
51 default: accept;
52 }
53 }
54
55 state parse_tcp {
56 packet.extract(hdr.tcp);
Jonghwan Hyun8be03392017-12-04 15:48:44 -080057 local_metadata.l4_src_port = hdr.tcp.src_port;
58 local_metadata.l4_dst_port = hdr.tcp.dst_port;
Jonghwan Hyunc235d462019-01-30 23:31:48 +090059 transition select(hdr.ipv4.dscp) {
60 DSCP_INT &&& DSCP_MASK: parse_intl4_shim;
Jonghwan Hyun8be03392017-12-04 15:48:44 -080061 default: accept;
62 }
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -080063 }
64
65 state parse_udp {
66 packet.extract(hdr.udp);
67 local_metadata.l4_src_port = hdr.udp.src_port;
68 local_metadata.l4_dst_port = hdr.udp.dst_port;
Jonghwan Hyunc235d462019-01-30 23:31:48 +090069 transition select(hdr.ipv4.dscp) {
70 DSCP_INT &&& DSCP_MASK: parse_intl4_shim;
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -080071 default: accept;
72 }
73 }
74
75 state parse_intl4_shim {
76 packet.extract(hdr.intl4_shim);
Jonghwan Hyunc235d462019-01-30 23:31:48 +090077 local_metadata.int_meta.intl4_shim_len = hdr.intl4_shim.len;
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -080078 transition parse_int_header;
79 }
80
81 state parse_int_header {
82 packet.extract(hdr.int_header);
Jonghwan Hyunc235d462019-01-30 23:31:48 +090083 transition parse_int_data;
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -080084 }
85
86 state parse_int_data {
Jonghwan Hyunc235d462019-01-30 23:31:48 +090087 // Parse INT metadata stack
88 packet.extract(hdr.int_data, ((bit<32>) (local_metadata.int_meta.intl4_shim_len - INT_HEADER_LEN_WORD)) << 5);
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -080089 transition accept;
90 }
91}
92
93control int_deparser(
94 packet_out packet,
95 in headers_t hdr) {
96 apply {
97 packet.emit(hdr.packet_in);
Jonghwan Hyun6777d532018-11-18 20:50:16 +090098 packet.emit(hdr.report_ethernet);
99 packet.emit(hdr.report_ipv4);
100 packet.emit(hdr.report_udp);
101 packet.emit(hdr.report_fixed_header);
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -0800102 packet.emit(hdr.ethernet);
103 packet.emit(hdr.ipv4);
104 packet.emit(hdr.tcp);
105 packet.emit(hdr.udp);
106 packet.emit(hdr.intl4_shim);
107 packet.emit(hdr.int_header);
108 packet.emit(hdr.int_switch_id);
Jonghwan Hyunc235d462019-01-30 23:31:48 +0900109 packet.emit(hdr.int_level1_port_ids);
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -0800110 packet.emit(hdr.int_hop_latency);
111 packet.emit(hdr.int_q_occupancy);
112 packet.emit(hdr.int_ingress_tstamp);
113 packet.emit(hdr.int_egress_tstamp);
Jonghwan Hyunc235d462019-01-30 23:31:48 +0900114 packet.emit(hdr.int_level2_port_ids);
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -0800115 packet.emit(hdr.int_egress_tx_util);
116 packet.emit(hdr.int_data);
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -0800117 }
118}
119
Jonghwan Hyun6777d532018-11-18 20:50:16 +0900120#endif