Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [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 | #ifndef __HOST_METER_TABLE__ |
| 18 | #define __HOST_METER_TABLE__ |
| 19 | |
| 20 | #include "headers.p4" |
| 21 | #include "defines.p4" |
| 22 | |
| 23 | control host_meter_control(inout headers_t hdr, |
| 24 | inout local_metadata_t local_metadata, |
| 25 | inout standard_metadata_t standard_metadata) { |
Keesjan Karsten | 2336889 | 2018-05-22 10:46:01 +0000 | [diff] [blame] | 26 | MeterColor meter_tag = MeterColor_GREEN; |
| 27 | direct_meter<MeterColor>(MeterType.bytes) host_meter; |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 28 | |
| 29 | action read_meter() { |
Keesjan Karsten | 2336889 | 2018-05-22 10:46:01 +0000 | [diff] [blame] | 30 | host_meter.read(meter_tag); |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 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 { |
Keesjan Karsten | 2336889 | 2018-05-22 10:46:01 +0000 | [diff] [blame] | 46 | host_meter_table.apply(); |
| 47 | if (meter_tag == MeterColor_RED) { |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 48 | mark_to_drop(); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | #endif |