blob: 09d87fc6c395418e49163f0dc6b4b013c6b25680 [file] [log] [blame]
Yi Tseng2a81c9d2016-09-14 10:14:24 -07001/*
2 * Copyright 2016-present 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
17package org.onosproject.net;
18
19import com.google.common.base.MoreObjects;
20import org.onosproject.net.flow.DefaultTrafficSelector;
21import org.onosproject.net.flow.TrafficSelector;
22
23import java.util.Objects;
24
25/**
26 * Connection point with TrafficSelector field.
27 */
28public class FilteredConnectPoint {
29 private final ConnectPoint connectPoint;
30 private final TrafficSelector trafficSelector;
31
32 /**
33 * Creates filtered connect point with default traffic selector.
34 *
35 * @param connectPoint
36 */
37 public FilteredConnectPoint(ConnectPoint connectPoint) {
38 this.connectPoint = connectPoint;
39 this.trafficSelector = DefaultTrafficSelector.emptySelector();
40 }
41
42 /**
43 * Creates new filtered connection point.
44 *
45 * @param connectPoint connect point
46 * @param trafficSelector traffic selector for this connect point
47 */
48 public FilteredConnectPoint(ConnectPoint connectPoint, TrafficSelector trafficSelector) {
49 this.connectPoint = connectPoint;
50 this.trafficSelector = trafficSelector;
51 }
52
53 /**
54 * Returns the traffic selector for this connect point.
55 *
56 * @return Traffic selector for this connect point
57 */
58 public TrafficSelector trafficSelector() {
59 return trafficSelector;
60 }
61
62 /**
63 * Returns the connection point.
64 * @return
65 */
66 public ConnectPoint connectPoint() {
67 return connectPoint;
68 }
69
70 @Override
71 public int hashCode() {
72 return Objects.hash(connectPoint, trafficSelector);
73 }
74
75 @Override
76 public String toString() {
77 return MoreObjects.toStringHelper(getClass())
78 .add("connectPoint", connectPoint)
79 .add("trafficSelector", trafficSelector)
80 .toString();
81 }
82
83 @Override
84 public boolean equals(Object obj) {
85 if (obj == null) {
86 return false;
87 }
88
89 if (this == obj) {
90 return true;
91 }
92
93 if (obj instanceof FilteredConnectPoint) {
94 FilteredConnectPoint other = (FilteredConnectPoint) obj;
95 return other.connectPoint().equals(connectPoint) &&
96 other.trafficSelector().equals(trafficSelector());
97 } else {
98 return false;
99 }
100 }
101}