blob: 29ab25834ca40fc35a3ca74b31687e3e391f76c0 [file] [log] [blame]
Pier Luigi09220c22017-09-14 22:00:30 +02001/*
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
17package org.onosproject.net.behaviour.trafficcontrol;
18
19import com.google.common.annotations.Beta;
20import com.google.common.base.Objects;
21import org.onosproject.net.ConnectPoint;
22import org.onosproject.net.NetworkResource;
23
24import static com.google.common.base.MoreObjects.toStringHelper;
25import 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
32public 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}