Pier Luigi | 09220c2 | 2017-09-14 22:00:30 +0200 | [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 | package org.onosproject.net.behaviour.trafficcontrol; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import com.google.common.base.Objects; |
| 21 | import org.onosproject.net.ConnectPoint; |
| 22 | import org.onosproject.net.NetworkResource; |
| 23 | |
| 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 25 | import static com.google.common.base.Preconditions.checkNotNull; |
| 26 | |
| 27 | /** |
| 28 | * Abstraction which encapsulates policer |
| 29 | * data to be used as network resource. |
| 30 | */ |
| 31 | @Beta |
| 32 | public final class PolicingResource implements NetworkResource { |
| 33 | |
| 34 | // The policer id identifying this resource |
| 35 | private final PolicerId policerId; |
| 36 | // The connect point where the policer applies |
| 37 | private final ConnectPoint connectPoint; |
| 38 | |
| 39 | public PolicingResource(PolicerId pId, ConnectPoint cP) { |
| 40 | checkNotNull(pId, "Must specify a policer id"); |
| 41 | checkNotNull(cP, "Must specify a connect point"); |
| 42 | policerId = pId; |
| 43 | connectPoint = cP; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Return the policer id of this resource. |
| 48 | * |
| 49 | * @return the policer id |
| 50 | */ |
| 51 | public PolicerId policerId() { |
| 52 | return policerId; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Returns the connect point of this resource. |
| 57 | * |
| 58 | * @return the connect point |
| 59 | */ |
| 60 | public ConnectPoint connectPoint() { |
| 61 | return connectPoint; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public String toString() { |
| 66 | return toStringHelper(this) |
| 67 | .add("id", policerId()) |
| 68 | .add("connectPoint", connectPoint()).toString(); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public boolean equals(Object o) { |
| 73 | if (this == o) { |
| 74 | return true; |
| 75 | } |
| 76 | if (o == null || getClass() != o.getClass()) { |
| 77 | return false; |
| 78 | } |
| 79 | PolicingResource that = (PolicingResource) o; |
| 80 | return Objects.equal(policerId, that.policerId) && |
| 81 | Objects.equal(connectPoint, that.connectPoint); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public int hashCode() { |
| 86 | return Objects.hashCode(policerId, connectPoint); |
| 87 | } |
| 88 | |
| 89 | } |