Harshada Chaundkar | dcd1b14 | 2019-03-25 17:27:44 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-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 | package org.onosproject.net.packet; |
| 17 | |
| 18 | /** |
| 19 | * Abstraction of incoming packet filter. |
| 20 | */ |
| 21 | public interface PacketInFilter { |
| 22 | |
| 23 | /** |
| 24 | * Types of filter action applied to incoming packets. |
| 25 | */ |
| 26 | enum FilterAction { |
| 27 | /** |
| 28 | * Signifies that the packet is allowed to be processed. |
| 29 | */ |
| 30 | PACKET_ALLOW, |
| 31 | /** |
| 32 | * Signifies that the packet is denied from being processed |
| 33 | * as it crossed the maxCounter. |
| 34 | */ |
| 35 | PACKET_DENY, |
| 36 | /** |
| 37 | * Signifies that filter applied is a valid filter. |
| 38 | */ |
| 39 | FILTER_VALID, |
| 40 | /** |
| 41 | * Signifies that this filter is disabled. |
| 42 | */ |
| 43 | FILTER_DISABLED, |
| 44 | /** |
| 45 | * Signifies that the current window for packet processing is full |
| 46 | * and the window is blocked for packet processing. |
| 47 | */ |
| 48 | WINDOW_BLOCKED, |
| 49 | /** |
| 50 | * Signifies that the packet processing is blocked as the |
| 51 | * threshold has crossed. |
| 52 | */ |
| 53 | PACKET_BLOCKED, |
| 54 | /** |
| 55 | * Signifies that the filter applied is invalid filter. |
| 56 | */ |
| 57 | FILTER_INVALID |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns FilterAction before processing the packet. |
| 62 | * Decides if the packet is allowed to be processed or not. |
| 63 | * |
| 64 | * @param packet PackerContext holding the packet information |
| 65 | * @return FilterAction |
| 66 | */ |
| 67 | FilterAction preProcess(PacketContext packet); |
| 68 | |
| 69 | /** |
| 70 | * Get the name of the counter. |
| 71 | * |
| 72 | * @return name of the counter |
| 73 | */ |
| 74 | String name(); |
| 75 | |
| 76 | /** |
| 77 | * Get the current value of the count of packets for this particular |
| 78 | * filter type waiting to get processed. |
| 79 | * |
| 80 | * @return count of packets with current filter type waiting to get processed |
| 81 | */ |
| 82 | int pendingPackets(); |
| 83 | |
| 84 | /** |
| 85 | * Get the count of the dropped packets for this filter type. |
| 86 | * |
| 87 | * @return count of dropped packets for this filter type |
| 88 | */ |
| 89 | int droppedPackets(); |
| 90 | |
| 91 | /** |
| 92 | * Set the pps rate for the current filter type to calculate the max counter |
| 93 | * allowed with window size. |
| 94 | * |
| 95 | * @param pps Packet per second rate expected |
| 96 | */ |
| 97 | void setPps(int pps); |
| 98 | |
| 99 | /** |
| 100 | * Set the window size for rate limiting. |
| 101 | * |
| 102 | * @param winSize Window size in milli seconds |
| 103 | */ |
| 104 | void setWinSize(int winSize); |
| 105 | |
| 106 | /** |
| 107 | * Set the Guard time in case WinThres is crossed. |
| 108 | * |
| 109 | * @param guardTime Guard time in seconds |
| 110 | */ |
| 111 | void setGuardTime(int guardTime); |
| 112 | |
| 113 | /** |
| 114 | * Set the Window Threshold for dropping the packet. |
| 115 | * |
| 116 | * @param winThres Threshold count of the consecutive windows with packet drops |
| 117 | */ |
| 118 | void setWinThres(int winThres); |
| 119 | |
| 120 | /** |
| 121 | * Stop the threads running for this filter. |
| 122 | * |
| 123 | */ |
| 124 | void stop(); |
| 125 | |
| 126 | } |