blob: bf2a4e5df4b3f221ca432e1e98cfc60557ca3495 [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();
Jonghwan Hyunc235d462019-01-30 23:31:48 +090033 hdr.report_fixed_header.ver = 1;
34 hdr.report_fixed_header.len = 4;
Jonghwan Hyun6777d532018-11-18 20:50:16 +090035 /* only support for flow_watchlist */
36 hdr.report_fixed_header.nproto = NPROTO_ETHERNET;
Jonghwan Hyunc235d462019-01-30 23:31:48 +090037 hdr.report_fixed_header.rep_md_bits = 0;
Jonghwan Hyun6777d532018-11-18 20:50:16 +090038 hdr.report_fixed_header.d = 0;
39 hdr.report_fixed_header.q = 0;
40 hdr.report_fixed_header.f = 1;
41 hdr.report_fixed_header.rsvd = 0;
42 //TODO how to get information specific to the switch
43 hdr.report_fixed_header.hw_id = HW_ID;
Jonghwan Hyunc235d462019-01-30 23:31:48 +090044 hdr.report_fixed_header.sw_id = local_metadata.int_meta.switch_id;
Jonghwan Hyun6777d532018-11-18 20:50:16 +090045 // TODO how save a variable and increment
46 hdr.report_fixed_header.seq_no = 0;
47 //TODO how to get timestamp from ingress ns
48 hdr.report_fixed_header.ingress_tstamp = (bit<32>) standard_metadata.enq_timestamp;
49
50 }
51
52 action do_report_encapsulation(mac_t src_mac, mac_t mon_mac, ip_address_t src_ip,
53 ip_address_t mon_ip, l4_port_t mon_port) {
54 //Report Ethernet Header
55 hdr.report_ethernet.setValid();
56 hdr.report_ethernet.dst_addr = mon_mac;
57 hdr.report_ethernet.src_addr = src_mac;
58 hdr.report_ethernet.ether_type = ETH_TYPE_IPV4;
59
60 //Report IPV4 Header
61 hdr.report_ipv4.setValid();
62 hdr.report_ipv4.version = IP_VERSION_4;
63 hdr.report_ipv4.ihl = IPV4_IHL_MIN;
64 hdr.report_ipv4.dscp = 6w0;
65 hdr.report_ipv4.ecn = 2w0;
66 /* Total Len is report_ipv4_len + report_udp_len + report_fixed_hdr_len + ethernet_len + ipv4_totalLen */
Jonghwan Hyunc235d462019-01-30 23:31:48 +090067 hdr.report_ipv4.len = (bit<16>) IPV4_MIN_HEAD_LEN + (bit<16>) UDP_HEADER_LEN + (bit<16>) REPORT_FIXED_HEADER_LEN +
68 (bit<16>) ETH_HEADER_LEN + (bit<16>) IPV4_MIN_HEAD_LEN + (bit<16>) UDP_HEADER_LEN + (((bit<16>) hdr.intl4_shim.len)<< 2);
Jonghwan Hyun6777d532018-11-18 20:50:16 +090069 /* Dont Fragment bit should be set */
70 hdr.report_ipv4.identification = 0;
71 hdr.report_ipv4.flags = 0;
72 hdr.report_ipv4.frag_offset = 0;
73 hdr.report_ipv4.ttl = REPORT_HDR_TTL;
74 hdr.report_ipv4.protocol = IP_PROTO_UDP;
75 hdr.report_ipv4.src_addr = src_ip;
76 hdr.report_ipv4.dst_addr = mon_ip;
77
78 //Report UDP Header
79 hdr.report_udp.setValid();
80 hdr.report_udp.src_port = 0;
81 hdr.report_udp.dst_port = mon_port;
Jonghwan Hyunc235d462019-01-30 23:31:48 +090082 hdr.report_udp.length_ = (bit<16>) UDP_HEADER_LEN + (bit<16>) REPORT_FIXED_HEADER_LEN +
83 (bit<16>) ETH_HEADER_LEN + (bit<16>) IPV4_MIN_HEAD_LEN + (bit<16>) UDP_HEADER_LEN +
84 (((bit<16>) hdr.intl4_shim.len)<< 2);
Jonghwan Hyun6777d532018-11-18 20:50:16 +090085
86 local_metadata.compute_checksum = true;
87 add_report_fixed_header();
Jonghwan Hyunc235d462019-01-30 23:31:48 +090088
89 truncate((bit<32>)hdr.report_ipv4.len + (bit<32>) ETH_HEADER_LEN);
Jonghwan Hyun6777d532018-11-18 20:50:16 +090090 }
91
Jonghwan Hyunc235d462019-01-30 23:31:48 +090092 // Cloned packet is forwarded according to the mirroring_add command
Jonghwan Hyun6777d532018-11-18 20:50:16 +090093 table tb_generate_report {
Jonghwan Hyunc235d462019-01-30 23:31:48 +090094 // We don't really need a key here, however we add a dummy one as a
95 // workaround to ONOS inability to properly support default actions.
Jonghwan Hyun6777d532018-11-18 20:50:16 +090096 key = {
Jonghwan Hyunc235d462019-01-30 23:31:48 +090097 hdr.int_header.isValid(): exact @name("int_is_valid");
Jonghwan Hyun6777d532018-11-18 20:50:16 +090098 }
99 actions = {
100 do_report_encapsulation;
Jonghwan Hyunc235d462019-01-30 23:31:48 +0900101 @defaultonly nop();
Jonghwan Hyun6777d532018-11-18 20:50:16 +0900102 }
Jonghwan Hyunc235d462019-01-30 23:31:48 +0900103 default_action = nop;
Jonghwan Hyun6777d532018-11-18 20:50:16 +0900104 }
105
106 apply {
107 tb_generate_report.apply();
108 }
109}
110#endif