blob: 710d19a813880ca596d2613f858decbe173e4a76 [file] [log] [blame]
Frank Wangd7e3b4b2017-09-24 13:37:54 +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#ifndef METERS
18#define METERS
19#include "defines.p4"
20
21control port_meters_ingress(inout headers_t hdr,
22 inout standard_metadata_t standard_metadata) {
23 meter(MAX_PORTS, MeterType.bytes) ingress_port_meter;
24 MeterColor_t ingress_color = MeterColor_t.GREEN;
25
26 apply {
27 ingress_port_meter.execute_meter<MeterColor_t>((bit<32>)standard_metadata.ingress_port, ingress_color);
28 if (ingress_color == MeterColor_t.RED) {
29 mark_to_drop();
30 }
31 }
32}
33
34control port_meters_egress(inout headers_t hdr,
35 inout standard_metadata_t standard_metadata) {
36
37 meter(MAX_PORTS, MeterType.bytes) egress_port_meter;
38 MeterColor_t egress_color = MeterColor_t.GREEN;
39
40 apply {
41 egress_port_meter.execute_meter<MeterColor_t>((bit<32>)standard_metadata.egress_port, egress_color);
42 if (egress_color == MeterColor_t.RED) {
43 mark_to_drop();
44 }
45 }
46}
47#endif