Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [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 | #include <core.p4> |
| 19 | #include <v1model.p4> |
| 20 | |
| 21 | #include "include/defines.p4" |
| 22 | #include "include/headers.p4" |
| 23 | #include "include/actions.p4" |
Jonghwan Hyun | 8be0339 | 2017-12-04 15:48:44 -0800 | [diff] [blame] | 24 | #include "include/int_definitions.p4" |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 25 | #include "include/int_headers.p4" |
| 26 | #include "include/packet_io.p4" |
| 27 | #include "include/port_counters.p4" |
| 28 | #include "include/table0.p4" |
| 29 | #include "include/checksums.p4" |
| 30 | #include "include/int_parser.p4" |
| 31 | #include "include/int_source.p4" |
| 32 | #include "include/int_transit.p4" |
| 33 | #include "include/int_sink.p4" |
Jonghwan Hyun | 6777d53 | 2018-11-18 20:50:16 +0900 | [diff] [blame] | 34 | #include "include/int_report.p4" |
| 35 | |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 36 | |
Jonghwan Hyun | f5d5782 | 2018-05-09 10:19:50 -0700 | [diff] [blame] | 37 | control ingress ( |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 38 | inout headers_t hdr, |
| 39 | inout local_metadata_t local_metadata, |
| 40 | inout standard_metadata_t standard_metadata) { |
| 41 | |
| 42 | apply { |
| 43 | port_counters_ingress.apply(hdr, standard_metadata); |
| 44 | packetio_ingress.apply(hdr, standard_metadata); |
| 45 | table0_control.apply(hdr, local_metadata, standard_metadata); |
Jonghwan Hyun | 6777d53 | 2018-11-18 20:50:16 +0900 | [diff] [blame] | 46 | process_set_source_sink.apply(hdr, local_metadata, standard_metadata); |
| 47 | if(local_metadata.int_meta.sink == 1) { |
| 48 | // clone packet for Telemetry Report |
| 49 | // FIXME: this works only on BMv2 |
| 50 | #ifdef __TARGET_BMV2__ |
| 51 | clone(CloneType.I2E, REPORT_MIRROR_SESSION_ID); |
| 52 | #endif |
| 53 | } |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
Jonghwan Hyun | f5d5782 | 2018-05-09 10:19:50 -0700 | [diff] [blame] | 57 | control egress ( |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 58 | inout headers_t hdr, |
| 59 | inout local_metadata_t local_metadata, |
| 60 | inout standard_metadata_t standard_metadata) { |
| 61 | |
| 62 | apply { |
| 63 | if (standard_metadata.ingress_port != CPU_PORT && |
| 64 | standard_metadata.egress_port != CPU_PORT && |
Jonghwan Hyun | 8be0339 | 2017-12-04 15:48:44 -0800 | [diff] [blame] | 65 | (hdr.udp.isValid() || hdr.tcp.isValid())) { |
Jonghwan Hyun | f5d5782 | 2018-05-09 10:19:50 -0700 | [diff] [blame] | 66 | process_set_source_sink.apply(hdr, local_metadata, standard_metadata); |
| 67 | if (local_metadata.int_meta.source == 1) { |
Jonghwan Hyun | 8be0339 | 2017-12-04 15:48:44 -0800 | [diff] [blame] | 68 | process_int_source.apply(hdr, local_metadata, standard_metadata); |
| 69 | } |
| 70 | if(hdr.int_header.isValid()) { |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 71 | process_int_transit.apply(hdr, local_metadata, standard_metadata); |
Jonghwan Hyun | 6777d53 | 2018-11-18 20:50:16 +0900 | [diff] [blame] | 72 | /* update underlay header based on INT information inserted */ |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 73 | process_int_outer_encap.apply(hdr, local_metadata, standard_metadata); |
Jonghwan Hyun | f5d5782 | 2018-05-09 10:19:50 -0700 | [diff] [blame] | 74 | if (local_metadata.int_meta.sink == 1) { |
Jonghwan Hyun | 6777d53 | 2018-11-18 20:50:16 +0900 | [diff] [blame] | 75 | /* send int report */ |
| 76 | process_int_report.apply(hdr, local_metadata, standard_metadata); |
| 77 | /* int sink */ |
Jonghwan Hyun | f5d5782 | 2018-05-09 10:19:50 -0700 | [diff] [blame] | 78 | process_int_sink.apply(hdr, local_metadata, standard_metadata); |
| 79 | } |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | port_counters_egress.apply(hdr, standard_metadata); |
| 83 | packetio_egress.apply(hdr, standard_metadata); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | V1Switch( |
| 88 | int_parser(), |
| 89 | verify_checksum_control(), |
Jonghwan Hyun | f5d5782 | 2018-05-09 10:19:50 -0700 | [diff] [blame] | 90 | ingress(), |
| 91 | egress(), |
Jonghwan Hyun | 4a9a671 | 2017-11-13 14:43:55 -0800 | [diff] [blame] | 92 | compute_checksum_control(), |
| 93 | int_deparser() |
Jonghwan Hyun | 6777d53 | 2018-11-18 20:50:16 +0900 | [diff] [blame] | 94 | ) main; |