blob: 1e857055aa96a8dfc4a6cd571e1a1299e3565719 [file] [log] [blame]
Jonghwan Hyuned478dc2018-08-06 15:35:18 +09001/*
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
21control process_int_report (
22 inout parsed_headers_t hdr,
23 inout fabric_metadata_t fabric_metadata,
24 inout standard_metadata_t standard_metadata) {
25
Carmelo Casconeb5324e72018-11-25 02:26:32 -080026 @hidden
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090027 action add_report_fixed_header() {
28 /* Device should include its own INT metadata as embedded,
29 * we'll not use fabric_report_header for this purpose.
30 */
31 hdr.report_fixed_header.setValid();
32 hdr.report_fixed_header.ver = 0;
33 /* only support for flow_watchlist */
34 hdr.report_fixed_header.nproto = NPROTO_ETHERNET;
35 hdr.report_fixed_header.d = 0;
36 hdr.report_fixed_header.q = 0;
37 hdr.report_fixed_header.f = 1;
38 hdr.report_fixed_header.rsvd = 0;
39 //TODO how to get information specific to the switch
40 hdr.report_fixed_header.hw_id = HW_ID;
41 // TODO how save a variable and increment
42 hdr.report_fixed_header.seq_no = 0;
43 //TODO how to get timestamp from ingress ns
Carmelo Cascone79a3a312018-08-16 17:14:43 -070044 hdr.report_fixed_header.ingress_tstamp = (bit<32>) standard_metadata.enq_timestamp;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090045 }
46
Carmelo Cascone9b0171b2018-08-14 01:43:57 -070047 action do_report_encapsulation(mac_addr_t src_mac, mac_addr_t mon_mac, ipv4_addr_t src_ip,
48 ipv4_addr_t mon_ip, l4_port_t mon_port) {
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090049 //Report Ethernet Header
50 hdr.report_ethernet.setValid();
51 hdr.report_ethernet.dst_addr = mon_mac;
52 hdr.report_ethernet.src_addr = src_mac;
Sundararajan Renganathanb27024f2020-07-10 02:43:40 +000053 hdr.report_eth_type.setValid();
Daniele Moro693d76f2019-09-24 14:34:07 -070054 hdr.report_eth_type.value = ETHERTYPE_IPV4;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090055
56 //Report IPV4 Header
57 hdr.report_ipv4.setValid();
58 hdr.report_ipv4.version = 4w4;
59 hdr.report_ipv4.ihl = 4w5;
60 hdr.report_ipv4.dscp = 6w0;
61 hdr.report_ipv4.ecn = 2w0;
62 /* Total Len is report_ipv4_len + report_udp_len + report_fixed_hdr_len + ethernet_len + ipv4_totalLen */
63 hdr.report_ipv4.total_len = (bit<16>) IPV4_MIN_HEAD_LEN + (bit<16>) UDP_HEADER_LEN +
64 (bit<16>) REPORT_FIXED_HEADER_LEN + (bit<16>) ETH_HEADER_LEN + hdr.ipv4.total_len;
65 /* Dont Fragment bit should be set */
66 hdr.report_ipv4.identification = 0;
67 hdr.report_ipv4.flags = 0;
68 hdr.report_ipv4.frag_offset = 0;
69 hdr.report_ipv4.ttl = 0xFF;
70 hdr.report_ipv4.protocol = PROTO_UDP;
71 hdr.report_ipv4.src_addr = src_ip;
72 hdr.report_ipv4.dst_addr = mon_ip;
73
74 //Report UDP Header
75 hdr.report_udp.setValid();
Carmelo Casconeb5324e72018-11-25 02:26:32 -080076 hdr.report_udp.sport = 0;
77 hdr.report_udp.dport = mon_port;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090078 hdr.report_udp.len = (bit<16>) UDP_HEADER_LEN + (bit<16>) REPORT_FIXED_HEADER_LEN +
79 (bit<16>) ETH_HEADER_LEN + hdr.ipv4.total_len;
80
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090081 add_report_fixed_header();
82 }
83
84 /* Cloned packet instance_type is PKT_INSTANCE_TYPE_INGRESS_CLONE=1
85 * Packet is forwarded according to the mirroring_add command
86 */
87 table tb_generate_report {
88 key = {
89 }
90 actions = {
91 do_report_encapsulation;
Carmelo Casconeb5324e72018-11-25 02:26:32 -080092 @defaultonly nop();
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090093 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -080094 default_action = nop;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090095 }
96
97 apply {
98 tb_generate_report.apply();
99 }
100}
101#endif