blob: b7c5046b0af210a9a99c8e9b48e52e4049af46eb [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 -*- */
18#ifndef __INT_SOURCE__
19#define __INT_SOURCE__
20
21// Insert INT header to the packet
22control process_int_source (
23 inout headers_t hdr,
24 inout local_metadata_t local_metadata,
25 inout standard_metadata_t standard_metadata) {
26
27 direct_counter(CounterType.packets_and_bytes) counter_int_source;
28
Jonghwan Hyunc235d462019-01-30 23:31:48 +090029 action int_source(bit<5> hop_metadata_len, bit<8> remaining_hop_cnt, bit<4> ins_mask0003, bit<4> ins_mask0407) {
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -080030 // insert INT shim header
31 hdr.intl4_shim.setValid();
32 // int_type: Hop-by-hop type (1) , destination type (2)
33 hdr.intl4_shim.int_type = 1;
34 hdr.intl4_shim.len = INT_HEADER_LEN_WORD;
Jonghwan Hyunc235d462019-01-30 23:31:48 +090035 hdr.intl4_shim.dscp = hdr.ipv4.dscp;
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -080036
37 // insert INT header
38 hdr.int_header.setValid();
39 hdr.int_header.ver = 0;
40 hdr.int_header.rep = 0;
41 hdr.int_header.c = 0;
42 hdr.int_header.e = 0;
Jonghwan Hyunc235d462019-01-30 23:31:48 +090043 hdr.int_header.m = 0;
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -080044 hdr.int_header.rsvd1 = 0;
Jonghwan Hyunc235d462019-01-30 23:31:48 +090045 hdr.int_header.rsvd2 = 0;
46 hdr.int_header.hop_metadata_len = hop_metadata_len;
47 hdr.int_header.remaining_hop_cnt = remaining_hop_cnt;
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -080048 hdr.int_header.instruction_mask_0003 = ins_mask0003;
49 hdr.int_header.instruction_mask_0407 = ins_mask0407;
50 hdr.int_header.instruction_mask_0811 = 0; // not supported
51 hdr.int_header.instruction_mask_1215 = 0; // not supported
52
Jonghwan Hyunc235d462019-01-30 23:31:48 +090053 // add the header len (3 words) to total len
54 hdr.ipv4.len = hdr.ipv4.len + INT_HEADER_SIZE + INT_SHIM_HEADER_SIZE;
55 hdr.udp.length_ = hdr.udp.length_ + INT_HEADER_SIZE + INT_SHIM_HEADER_SIZE;
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -080056 }
Jonghwan Hyunc235d462019-01-30 23:31:48 +090057 action int_source_dscp(bit<5> hop_metadata_len, bit<8> remaining_hop_cnt, bit<4> ins_mask0003, bit<4> ins_mask0407) {
58 int_source(hop_metadata_len, remaining_hop_cnt, ins_mask0003, ins_mask0407);
59 hdr.ipv4.dscp = DSCP_INT;
60 counter_int_source.count();
Jonghwan Hyun8be03392017-12-04 15:48:44 -080061 }
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -080062
63 table tb_int_source {
64 key = {
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -080065 hdr.ipv4.src_addr: ternary;
66 hdr.ipv4.dst_addr: ternary;
67 local_metadata.l4_src_port: ternary;
68 local_metadata.l4_dst_port: ternary;
69 }
70 actions = {
Jonghwan Hyun8be03392017-12-04 15:48:44 -080071 int_source_dscp;
Jonghwan Hyunc235d462019-01-30 23:31:48 +090072 @defaultonly nop();
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -080073 }
74 counters = counter_int_source;
Jonghwan Hyunc235d462019-01-30 23:31:48 +090075 const default_action = nop();
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -080076 }
77
78 apply {
79 tb_int_source.apply();
80 }
81}
82
Jonghwan Hyunc235d462019-01-30 23:31:48 +090083control process_int_source_sink (
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -080084 inout headers_t hdr,
85 inout local_metadata_t local_metadata,
86 inout standard_metadata_t standard_metadata) {
87
Jonghwan Hyunf5d57822018-05-09 10:19:50 -070088 direct_counter(CounterType.packets_and_bytes) counter_set_source;
89 direct_counter(CounterType.packets_and_bytes) counter_set_sink;
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -080090
91 action int_set_source () {
Jonghwan Hyunc235d462019-01-30 23:31:48 +090092 local_metadata.int_meta.source = _TRUE;
93 counter_set_source.count();
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -080094 }
95
96 action int_set_sink () {
Jonghwan Hyunc235d462019-01-30 23:31:48 +090097 local_metadata.int_meta.sink = _TRUE;
98 counter_set_sink.count();
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -080099 }
100
Jonghwan Hyunf5d57822018-05-09 10:19:50 -0700101 table tb_set_source {
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -0800102 key = {
Jonghwan Hyunf5d57822018-05-09 10:19:50 -0700103 standard_metadata.ingress_port: exact;
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -0800104 }
105 actions = {
106 int_set_source;
Jonghwan Hyunc235d462019-01-30 23:31:48 +0900107 @defaultonly nop();
Jonghwan Hyunf5d57822018-05-09 10:19:50 -0700108 }
109 counters = counter_set_source;
Jonghwan Hyunc235d462019-01-30 23:31:48 +0900110 const default_action = nop();
111 size = MAX_PORTS;
Jonghwan Hyunf5d57822018-05-09 10:19:50 -0700112 }
113 table tb_set_sink {
114 key = {
Jonghwan Hyun6777d532018-11-18 20:50:16 +0900115 standard_metadata.egress_spec: exact;
Jonghwan Hyunf5d57822018-05-09 10:19:50 -0700116 }
117 actions = {
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -0800118 int_set_sink;
Jonghwan Hyunc235d462019-01-30 23:31:48 +0900119 @defaultonly nop();
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -0800120 }
Jonghwan Hyunf5d57822018-05-09 10:19:50 -0700121 counters = counter_set_sink;
Jonghwan Hyunc235d462019-01-30 23:31:48 +0900122 const default_action = nop();
123 size = MAX_PORTS;
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -0800124 }
125
126 apply {
Jonghwan Hyunf5d57822018-05-09 10:19:50 -0700127 tb_set_source.apply();
128 tb_set_sink.apply();
Jonghwan Hyun4a9a6712017-11-13 14:43:55 -0800129 }
130}
131#endif