blob: b7ca3572f215f494036b1e25d8c7464fbe0b785e [file] [log] [blame]
Jonghwan Hyun6777d532018-11-18 20:50:16 +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
21#include "telemetry_report_headers.p4"
22
23control process_int_report (
24 inout headers_t hdr,
25 inout local_metadata_t local_metadata,
26 inout standard_metadata_t standard_metadata) {
27
28 action add_report_fixed_header() {
29 /* Device should include its own INT metadata as embedded,
30 * we'll not use local_report_header for this purpose.
31 */
32 hdr.report_fixed_header.setValid();
33 hdr.report_fixed_header.ver = 0;
34 /* only support for flow_watchlist */
35 hdr.report_fixed_header.nproto = NPROTO_ETHERNET;
36 hdr.report_fixed_header.d = 0;
37 hdr.report_fixed_header.q = 0;
38 hdr.report_fixed_header.f = 1;
39 hdr.report_fixed_header.rsvd = 0;
40 //TODO how to get information specific to the switch
41 hdr.report_fixed_header.hw_id = HW_ID;
42 // TODO how save a variable and increment
43 hdr.report_fixed_header.seq_no = 0;
44 //TODO how to get timestamp from ingress ns
45 hdr.report_fixed_header.ingress_tstamp = (bit<32>) standard_metadata.enq_timestamp;
46
47 }
48
49 action do_report_encapsulation(mac_t src_mac, mac_t mon_mac, ip_address_t src_ip,
50 ip_address_t mon_ip, l4_port_t mon_port) {
51 //Report Ethernet Header
52 hdr.report_ethernet.setValid();
53 hdr.report_ethernet.dst_addr = mon_mac;
54 hdr.report_ethernet.src_addr = src_mac;
55 hdr.report_ethernet.ether_type = ETH_TYPE_IPV4;
56
57 //Report IPV4 Header
58 hdr.report_ipv4.setValid();
59 hdr.report_ipv4.version = IP_VERSION_4;
60 hdr.report_ipv4.ihl = IPV4_IHL_MIN;
61 hdr.report_ipv4.dscp = 6w0;
62 hdr.report_ipv4.ecn = 2w0;
63 /* Total Len is report_ipv4_len + report_udp_len + report_fixed_hdr_len + ethernet_len + ipv4_totalLen */
64 hdr.report_ipv4.len = (bit<16>) IPV4_MIN_HEAD_LEN + (bit<16>) UDP_HEADER_LEN +
65 (bit<16>) REPORT_FIXED_HEADER_LEN + (bit<16>) ETH_HEADER_LEN + hdr.ipv4.len;
66 /* Dont Fragment bit should be set */
67 hdr.report_ipv4.identification = 0;
68 hdr.report_ipv4.flags = 0;
69 hdr.report_ipv4.frag_offset = 0;
70 hdr.report_ipv4.ttl = REPORT_HDR_TTL;
71 hdr.report_ipv4.protocol = IP_PROTO_UDP;
72 hdr.report_ipv4.src_addr = src_ip;
73 hdr.report_ipv4.dst_addr = mon_ip;
74
75 //Report UDP Header
76 hdr.report_udp.setValid();
77 hdr.report_udp.src_port = 0;
78 hdr.report_udp.dst_port = mon_port;
79 hdr.report_udp.length_ = (bit<16>) UDP_HEADER_LEN + (bit<16>) REPORT_FIXED_HEADER_LEN +
80 (bit<16>) ETH_HEADER_LEN + hdr.ipv4.len;
81
82 local_metadata.compute_checksum = true;
83 add_report_fixed_header();
84 }
85
86 /* Cloned packet instance_type is PKT_INSTANCE_TYPE_INGRESS_CLONE=1
87 * Packet is forwarded according to the mirroring_add command
88 */
89 table tb_generate_report {
90 key = {
91 standard_metadata.instance_type: exact;
92 }
93 actions = {
94 do_report_encapsulation;
95 }
96 }
97
98 apply {
99 tb_generate_report.apply();
100 }
101}
102#endif