Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 1 | /* |
| 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 |
| 22 | control 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 Hyun | c235d46 | 2019-01-30 23:31:48 +0900 | [diff] [blame] | 29 | action int_source(bit<5> hop_metadata_len, bit<8> remaining_hop_cnt, bit<4> ins_mask0003, bit<4> ins_mask0407) { |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 30 | // 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 Hyun | c235d46 | 2019-01-30 23:31:48 +0900 | [diff] [blame] | 35 | hdr.intl4_shim.dscp = hdr.ipv4.dscp; |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 36 | |
| 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 Hyun | c235d46 | 2019-01-30 23:31:48 +0900 | [diff] [blame] | 43 | hdr.int_header.m = 0; |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 44 | hdr.int_header.rsvd1 = 0; |
Jonghwan Hyun | c235d46 | 2019-01-30 23:31:48 +0900 | [diff] [blame] | 45 | 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 Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 48 | 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 Hyun | c235d46 | 2019-01-30 23:31:48 +0900 | [diff] [blame] | 53 | // 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 Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 56 | } |
Jonghwan Hyun | c235d46 | 2019-01-30 23:31:48 +0900 | [diff] [blame] | 57 | 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 Hyun | 8be0339 | 2017-12-04 15:48:44 -0800 | [diff] [blame] | 61 | } |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 62 | |
| 63 | table tb_int_source { |
| 64 | key = { |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 65 | 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 Hyun | 8be0339 | 2017-12-04 15:48:44 -0800 | [diff] [blame] | 71 | int_source_dscp; |
Jonghwan Hyun | c235d46 | 2019-01-30 23:31:48 +0900 | [diff] [blame] | 72 | @defaultonly nop(); |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 73 | } |
| 74 | counters = counter_int_source; |
Jonghwan Hyun | c235d46 | 2019-01-30 23:31:48 +0900 | [diff] [blame] | 75 | const default_action = nop(); |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | apply { |
| 79 | tb_int_source.apply(); |
| 80 | } |
| 81 | } |
| 82 | |
Jonghwan Hyun | c235d46 | 2019-01-30 23:31:48 +0900 | [diff] [blame] | 83 | control process_int_source_sink ( |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 84 | inout headers_t hdr, |
| 85 | inout local_metadata_t local_metadata, |
| 86 | inout standard_metadata_t standard_metadata) { |
| 87 | |
Jonghwan Hyun | f5d5782 | 2018-05-09 10:19:50 -0700 | [diff] [blame] | 88 | direct_counter(CounterType.packets_and_bytes) counter_set_source; |
| 89 | direct_counter(CounterType.packets_and_bytes) counter_set_sink; |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 90 | |
| 91 | action int_set_source () { |
Jonghwan Hyun | c235d46 | 2019-01-30 23:31:48 +0900 | [diff] [blame] | 92 | local_metadata.int_meta.source = _TRUE; |
| 93 | counter_set_source.count(); |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | action int_set_sink () { |
Jonghwan Hyun | c235d46 | 2019-01-30 23:31:48 +0900 | [diff] [blame] | 97 | local_metadata.int_meta.sink = _TRUE; |
| 98 | counter_set_sink.count(); |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 99 | } |
| 100 | |
Jonghwan Hyun | f5d5782 | 2018-05-09 10:19:50 -0700 | [diff] [blame] | 101 | table tb_set_source { |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 102 | key = { |
Jonghwan Hyun | f5d5782 | 2018-05-09 10:19:50 -0700 | [diff] [blame] | 103 | standard_metadata.ingress_port: exact; |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 104 | } |
| 105 | actions = { |
| 106 | int_set_source; |
Jonghwan Hyun | c235d46 | 2019-01-30 23:31:48 +0900 | [diff] [blame] | 107 | @defaultonly nop(); |
Jonghwan Hyun | f5d5782 | 2018-05-09 10:19:50 -0700 | [diff] [blame] | 108 | } |
| 109 | counters = counter_set_source; |
Jonghwan Hyun | c235d46 | 2019-01-30 23:31:48 +0900 | [diff] [blame] | 110 | const default_action = nop(); |
| 111 | size = MAX_PORTS; |
Jonghwan Hyun | f5d5782 | 2018-05-09 10:19:50 -0700 | [diff] [blame] | 112 | } |
| 113 | table tb_set_sink { |
| 114 | key = { |
Jonghwan Hyun | 6777d53 | 2018-11-18 20:50:16 +0900 | [diff] [blame] | 115 | standard_metadata.egress_spec: exact; |
Jonghwan Hyun | f5d5782 | 2018-05-09 10:19:50 -0700 | [diff] [blame] | 116 | } |
| 117 | actions = { |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 118 | int_set_sink; |
Jonghwan Hyun | c235d46 | 2019-01-30 23:31:48 +0900 | [diff] [blame] | 119 | @defaultonly nop(); |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 120 | } |
Jonghwan Hyun | f5d5782 | 2018-05-09 10:19:50 -0700 | [diff] [blame] | 121 | counters = counter_set_sink; |
Jonghwan Hyun | c235d46 | 2019-01-30 23:31:48 +0900 | [diff] [blame] | 122 | const default_action = nop(); |
| 123 | size = MAX_PORTS; |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | apply { |
Jonghwan Hyun | f5d5782 | 2018-05-09 10:19:50 -0700 | [diff] [blame] | 127 | tb_set_source.apply(); |
| 128 | tb_set_sink.apply(); |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | #endif |