blob: 0e50e4afa694c2582f837367f4b35d6b8f052690 [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 __HOST_METER_TABLE__
18#define __HOST_METER_TABLE__
19
20#include "headers.p4"
21#include "defines.p4"
22
23control host_meter_control(inout headers_t hdr,
24 inout local_metadata_t local_metadata,
25 inout standard_metadata_t standard_metadata) {
Keesjan Karsten23368892018-05-22 10:46:01 +000026 MeterColor meter_tag = MeterColor_GREEN;
27 direct_meter<MeterColor>(MeterType.bytes) host_meter;
Frank Wangd7e3b4b2017-09-24 13:37:54 +090028
29 action read_meter() {
Keesjan Karsten23368892018-05-22 10:46:01 +000030 host_meter.read(meter_tag);
Frank Wangd7e3b4b2017-09-24 13:37:54 +090031 }
32
33 table host_meter_table {
34 key = {
35 hdr.ethernet.src_addr : lpm;
36 }
37 actions = {
38 read_meter();
39 NoAction;
40 }
41 meters = host_meter;
42 default_action = NoAction();
43 }
44
45 apply {
Keesjan Karsten23368892018-05-22 10:46:01 +000046 host_meter_table.apply();
47 if (meter_tag == MeterColor_RED) {
Carmelo Cascone9b607da2019-05-08 14:03:01 -070048 mark_to_drop(standard_metadata);
Frank Wangd7e3b4b2017-09-24 13:37:54 +090049 }
50 }
51}
52
53#endif