alshabib | 1d2bc40 | 2015-07-31 17:04:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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.incubator.net.meter; |
| 17 | |
| 18 | import org.onosproject.core.ApplicationId; |
| 19 | import org.onosproject.net.DeviceId; |
| 20 | |
| 21 | import java.util.Collection; |
| 22 | import java.util.Optional; |
| 23 | |
| 24 | /** |
| 25 | * Represents a generalized meter to be deployed on a device. |
| 26 | */ |
| 27 | public interface Meter { |
| 28 | |
| 29 | enum Unit { |
| 30 | /** |
| 31 | * Packets per second. |
| 32 | */ |
| 33 | PKTS_PER_SEC, |
| 34 | |
| 35 | /** |
| 36 | * Kilo bits per second. |
| 37 | */ |
| 38 | KB_PER_SEC |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * The target device for this meter. |
| 43 | * |
| 44 | * @return a device id |
| 45 | */ |
| 46 | DeviceId deviceId(); |
| 47 | |
| 48 | /** |
| 49 | * This meters id. |
| 50 | * |
| 51 | * @return a meter id |
| 52 | */ |
| 53 | MeterId id(); |
| 54 | |
| 55 | /** |
| 56 | * The id of the application which created this meter. |
| 57 | * |
| 58 | * @return an application id |
| 59 | */ |
| 60 | ApplicationId appId(); |
| 61 | |
| 62 | /** |
| 63 | * The unit used within this meter. |
| 64 | * |
| 65 | * @return |
| 66 | */ |
| 67 | Unit unit(); |
| 68 | |
| 69 | /** |
| 70 | * Signals whether this meter applies to bursts only. |
| 71 | * |
| 72 | * @return a boolean |
| 73 | */ |
| 74 | boolean isBurst(); |
| 75 | |
| 76 | /** |
| 77 | * The collection of bands to apply on the dataplane. |
| 78 | * |
| 79 | * @return a collection of bands. |
| 80 | */ |
| 81 | Collection<Band> bands(); |
| 82 | |
| 83 | /** |
| 84 | * Obtains an optional context. |
| 85 | * |
| 86 | * @return optional; which will be empty if there is no context. |
| 87 | * Otherwise it will return the context. |
| 88 | */ |
| 89 | Optional<MeterContext> context(); |
| 90 | |
| 91 | /** |
| 92 | * A meter builder. |
| 93 | */ |
| 94 | interface Builder { |
| 95 | |
| 96 | /** |
| 97 | * Assigns the target device for this meter. |
| 98 | * |
| 99 | * @param deviceId a device id |
| 100 | * @return this |
| 101 | */ |
| 102 | Builder forDevice(DeviceId deviceId); |
| 103 | |
| 104 | /** |
| 105 | * Assigns the id to this meter. |
| 106 | * |
| 107 | * @param id an integer |
| 108 | * @return this |
| 109 | */ |
| 110 | Builder withId(int id); |
| 111 | |
| 112 | /** |
| 113 | * Assigns the application that built this meter. |
| 114 | * |
| 115 | * @param appId an application id |
| 116 | * @return this |
| 117 | */ |
| 118 | Builder fromApp(ApplicationId appId); |
| 119 | |
| 120 | /** |
| 121 | * Assigns the @See Unit to use for this meter. |
| 122 | * Defaults to kb/s |
| 123 | * |
| 124 | * @param unit a unit |
| 125 | * @return this |
| 126 | */ |
| 127 | Builder withUnit(Unit unit); |
| 128 | |
| 129 | /** |
| 130 | * Sets this meter as applicable to burst traffic only. |
| 131 | * Defaults to false. |
| 132 | * |
| 133 | * @return this |
| 134 | */ |
| 135 | Builder burst(); |
| 136 | |
| 137 | /** |
| 138 | * Assigns bands to this meter. There must be at least one band. |
| 139 | * |
| 140 | * @param bands a collection of bands |
| 141 | * @return this |
| 142 | */ |
| 143 | Builder withBands(Collection<Band> bands); |
| 144 | |
| 145 | Builder withContext(MeterContext context); |
| 146 | |
| 147 | /** |
| 148 | * Builds the meter based on the specified parameters. |
| 149 | * |
| 150 | * @return a meter |
| 151 | */ |
| 152 | Meter build(); |
| 153 | } |
| 154 | |
| 155 | } |