Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [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 parsed_headers_t hdr, |
| 24 | inout fabric_metadata_t fabric_metadata, |
| 25 | inout standard_metadata_t standard_metadata) { |
| 26 | |
| 27 | direct_counter(CounterType.packets_and_bytes) counter_int_source; |
| 28 | |
Carmelo Cascone | b0c6665 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 29 | @hidden |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 30 | action int_source(bit<8> max_hop, bit<5> ins_cnt, bit<4> ins_mask0003, bit<4> ins_mask0407) { |
Carmelo Cascone | 3053ed1 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 31 | // Insert INT shim header. |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 32 | hdr.intl4_shim.setValid(); |
| 33 | // int_type: Hop-by-hop type (1) , destination type (2) |
| 34 | hdr.intl4_shim.int_type = 1; |
Carmelo Cascone | 3053ed1 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 35 | hdr.intl4_shim.len_words = INT_HEADER_LEN_WORDS; |
| 36 | // Insert INT header. |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 37 | hdr.int_header.setValid(); |
| 38 | hdr.int_header.ver = 0; |
| 39 | hdr.int_header.rep = 0; |
| 40 | hdr.int_header.c = 0; |
| 41 | hdr.int_header.e = 0; |
| 42 | hdr.int_header.rsvd1 = 0; |
| 43 | hdr.int_header.ins_cnt = ins_cnt; |
| 44 | hdr.int_header.max_hop_cnt = max_hop; |
| 45 | hdr.int_header.total_hop_cnt = 0; |
| 46 | hdr.int_header.instruction_mask_0003 = ins_mask0003; |
| 47 | hdr.int_header.instruction_mask_0407 = ins_mask0407; |
| 48 | hdr.int_header.instruction_mask_0811 = 0; // not supported |
| 49 | hdr.int_header.instruction_mask_1215 = 0; // not supported |
Carmelo Cascone | 3053ed1 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 50 | // Insert INT tail header. |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 51 | hdr.intl4_tail.setValid(); |
| 52 | hdr.intl4_tail.next_proto = hdr.ipv4.protocol; |
Carmelo Cascone | b0c6665 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 53 | hdr.intl4_tail.dest_port = fabric_metadata.l4_dport; |
Carmelo Cascone | 3053ed1 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 54 | hdr.intl4_tail.dscp = hdr.ipv4.dscp; |
| 55 | // Update IP and UDP (if not valid we don't care) lens (in bytes). |
| 56 | hdr.ipv4.total_len = hdr.ipv4.total_len + INT_HEADER_LEN_BYTES; |
| 57 | hdr.udp.len = hdr.udp.len + INT_HEADER_LEN_BYTES; |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 58 | } |
Carmelo Cascone | 3053ed1 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 59 | |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 60 | action int_source_dscp(bit<8> max_hop, bit<5> ins_cnt, bit<4> ins_mask0003, bit<4> ins_mask0407) { |
| 61 | int_source(max_hop, ins_cnt, ins_mask0003, ins_mask0407); |
| 62 | hdr.ipv4.dscp = INT_DSCP; |
Carmelo Cascone | 3053ed1 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 63 | counter_int_source.count(); |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | table tb_int_source { |
| 67 | key = { |
Carmelo Cascone | b0c6665 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 68 | hdr.ipv4.src_addr: ternary @name("ipv4_src"); |
| 69 | hdr.ipv4.dst_addr: ternary @name("ipv4_dst"); |
| 70 | fabric_metadata.l4_sport: ternary @name("l4_sport"); |
| 71 | fabric_metadata.l4_dport: ternary @name("l4_dport"); |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 72 | } |
| 73 | actions = { |
| 74 | int_source_dscp; |
Carmelo Cascone | b0c6665 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 75 | @defaultonly nop(); |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 76 | } |
| 77 | counters = counter_int_source; |
Carmelo Cascone | b0c6665 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 78 | const default_action = nop(); |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | apply { |
| 82 | tb_int_source.apply(); |
| 83 | } |
| 84 | } |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 85 | #endif |