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_REPORT__ |
| 19 | #define __INT_REPORT__ |
| 20 | |
| 21 | control process_int_report ( |
| 22 | inout parsed_headers_t hdr, |
| 23 | inout fabric_metadata_t fabric_metadata, |
| 24 | inout standard_metadata_t standard_metadata) { |
| 25 | |
| 26 | action add_report_fixed_header() { |
| 27 | /* Device should include its own INT metadata as embedded, |
| 28 | * we'll not use fabric_report_header for this purpose. |
| 29 | */ |
| 30 | hdr.report_fixed_header.setValid(); |
| 31 | hdr.report_fixed_header.ver = 0; |
| 32 | /* only support for flow_watchlist */ |
| 33 | hdr.report_fixed_header.nproto = NPROTO_ETHERNET; |
| 34 | hdr.report_fixed_header.d = 0; |
| 35 | hdr.report_fixed_header.q = 0; |
| 36 | hdr.report_fixed_header.f = 1; |
| 37 | hdr.report_fixed_header.rsvd = 0; |
| 38 | //TODO how to get information specific to the switch |
| 39 | hdr.report_fixed_header.hw_id = HW_ID; |
| 40 | // TODO how save a variable and increment |
| 41 | hdr.report_fixed_header.seq_no = 0; |
| 42 | //TODO how to get timestamp from ingress ns |
Carmelo Cascone | 3053ed1 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 43 | hdr.report_fixed_header.ingress_tstamp = (bit<32>) standard_metadata.enq_timestamp; |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 44 | } |
| 45 | |
Carmelo Cascone | 9b0171b | 2018-08-14 01:43:57 -0700 | [diff] [blame] | 46 | action do_report_encapsulation(mac_addr_t src_mac, mac_addr_t mon_mac, ipv4_addr_t src_ip, |
| 47 | ipv4_addr_t mon_ip, l4_port_t mon_port) { |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 48 | //Report Ethernet Header |
| 49 | hdr.report_ethernet.setValid(); |
| 50 | hdr.report_ethernet.dst_addr = mon_mac; |
| 51 | hdr.report_ethernet.src_addr = src_mac; |
| 52 | hdr.report_ethernet.ether_type = ETHERTYPE_IPV4; |
| 53 | |
| 54 | //Report IPV4 Header |
| 55 | hdr.report_ipv4.setValid(); |
| 56 | hdr.report_ipv4.version = 4w4; |
| 57 | hdr.report_ipv4.ihl = 4w5; |
| 58 | hdr.report_ipv4.dscp = 6w0; |
| 59 | hdr.report_ipv4.ecn = 2w0; |
| 60 | /* Total Len is report_ipv4_len + report_udp_len + report_fixed_hdr_len + ethernet_len + ipv4_totalLen */ |
| 61 | hdr.report_ipv4.total_len = (bit<16>) IPV4_MIN_HEAD_LEN + (bit<16>) UDP_HEADER_LEN + |
| 62 | (bit<16>) REPORT_FIXED_HEADER_LEN + (bit<16>) ETH_HEADER_LEN + hdr.ipv4.total_len; |
| 63 | /* Dont Fragment bit should be set */ |
| 64 | hdr.report_ipv4.identification = 0; |
| 65 | hdr.report_ipv4.flags = 0; |
| 66 | hdr.report_ipv4.frag_offset = 0; |
| 67 | hdr.report_ipv4.ttl = 0xFF; |
| 68 | hdr.report_ipv4.protocol = PROTO_UDP; |
| 69 | hdr.report_ipv4.src_addr = src_ip; |
| 70 | hdr.report_ipv4.dst_addr = mon_ip; |
| 71 | |
| 72 | //Report UDP Header |
| 73 | hdr.report_udp.setValid(); |
| 74 | hdr.report_udp.src_port = 0; |
| 75 | hdr.report_udp.dst_port = mon_port; |
| 76 | hdr.report_udp.len = (bit<16>) UDP_HEADER_LEN + (bit<16>) REPORT_FIXED_HEADER_LEN + |
| 77 | (bit<16>) ETH_HEADER_LEN + hdr.ipv4.total_len; |
| 78 | |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 79 | add_report_fixed_header(); |
| 80 | } |
| 81 | |
| 82 | /* Cloned packet instance_type is PKT_INSTANCE_TYPE_INGRESS_CLONE=1 |
| 83 | * Packet is forwarded according to the mirroring_add command |
| 84 | */ |
| 85 | table tb_generate_report { |
| 86 | key = { |
| 87 | } |
| 88 | actions = { |
| 89 | do_report_encapsulation; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | apply { |
| 94 | tb_generate_report.apply(); |
| 95 | } |
| 96 | } |
| 97 | #endif |