blob: c07681a0c85ddfc9ed831995367eda466d8b0bd6 [file] [log] [blame]
Yi Tseng2a81c9d2016-09-14 10:14:24 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Yi Tseng2a81c9d2016-09-14 10:14:24 -07003 *
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 *
Ray Milkeyef794342016-11-09 16:20:29 -080035 * @param connectPoint connect point
Yi Tseng2a81c9d2016-09-14 10:14:24 -070036 */
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.
Ray Milkeyef794342016-11-09 16:20:29 -080064 *
65 * @return connect point
Yi Tseng2a81c9d2016-09-14 10:14:24 -070066 */
67 public ConnectPoint connectPoint() {
68 return connectPoint;
69 }
70
71 @Override
72 public int hashCode() {
73 return Objects.hash(connectPoint, trafficSelector);
74 }
75
76 @Override
77 public String toString() {
78 return MoreObjects.toStringHelper(getClass())
79 .add("connectPoint", connectPoint)
80 .add("trafficSelector", trafficSelector)
81 .toString();
82 }
83
84 @Override
85 public boolean equals(Object obj) {
86 if (obj == null) {
87 return false;
88 }
89
90 if (this == obj) {
91 return true;
92 }
93
94 if (obj instanceof FilteredConnectPoint) {
95 FilteredConnectPoint other = (FilteredConnectPoint) obj;
96 return other.connectPoint().equals(connectPoint) &&
97 other.trafficSelector().equals(trafficSelector());
98 } else {
99 return false;
100 }
101 }
102}