blob: 6f581e15a4ea7d84b9d62732ad7b72ed64f58441 [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) {
26
27 direct_meter<bit<32>>(MeterType.bytes) host_meter;
28
29 action read_meter() {
30 host_meter.read(local_metadata.meter_tag);
31 }
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 {
46 if (host_meter_table.apply().hit && local_metadata.meter_tag == 2) {
47 mark_to_drop();
48 }
49 }
50}
51
52#endif