blob: 1269bce7626517ad3d9ba973d8b125805c0dfc71 [file] [log] [blame]
Brian O'Connor7cbbbb72016-04-09 02:13:23 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Brian O'Connor7cbbbb72016-04-09 02:13:23 -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 */
Charles Chand2990362016-04-18 13:44:03 -070016package org.onosproject.segmentrouting.storekey;
Saurav Das4ce45962015-11-24 23:21:05 -080017
18import org.onosproject.net.DeviceId;
19import org.onosproject.net.PortNumber;
Saurav Das76ae6812017-03-15 15:15:14 -070020import org.onosproject.net.flow.TrafficSelector;
Saurav Das4ce45962015-11-24 23:21:05 -080021import org.onosproject.net.flow.TrafficTreatment;
22
23import java.util.Objects;
24
Ruchi Sahotaef0761c2019-01-28 01:08:18 +000025import static com.google.common.base.MoreObjects.toStringHelper;
26
Saurav Das4ce45962015-11-24 23:21:05 -080027/**
Charles Chane849c192016-01-11 18:28:54 -080028 * Key of Device/Port to NextObjective store.
29 *
30 * Since there can be multiple next objectives to the same physical port,
31 * we differentiate between them by including the treatment in the key.
Saurav Das4ce45962015-11-24 23:21:05 -080032 */
33public class PortNextObjectiveStoreKey {
34 private final DeviceId deviceId;
35 private final PortNumber portNum;
36 private final TrafficTreatment treatment;
Saurav Das76ae6812017-03-15 15:15:14 -070037 private final TrafficSelector meta;
Saurav Das4ce45962015-11-24 23:21:05 -080038
Charles Chane849c192016-01-11 18:28:54 -080039 /**
40 * Constructs the key of port next objective store.
41 *
42 * @param deviceId device ID
43 * @param portNum port number
44 * @param treatment treatment that will be applied to the interface
Saurav Das76ae6812017-03-15 15:15:14 -070045 * @param meta optional data to pass to the driver
Charles Chane849c192016-01-11 18:28:54 -080046 */
Saurav Das4ce45962015-11-24 23:21:05 -080047 public PortNextObjectiveStoreKey(DeviceId deviceId, PortNumber portNum,
Saurav Das76ae6812017-03-15 15:15:14 -070048 TrafficTreatment treatment,
49 TrafficSelector meta) {
Saurav Das4ce45962015-11-24 23:21:05 -080050 this.deviceId = deviceId;
51 this.portNum = portNum;
52 this.treatment = treatment;
Saurav Das76ae6812017-03-15 15:15:14 -070053 this.meta = meta;
Saurav Das4ce45962015-11-24 23:21:05 -080054 }
55
56 /**
57 * Gets device id in this PortNextObjectiveStoreKey.
58 *
59 * @return device id
60 */
61 public DeviceId deviceId() {
62 return deviceId;
63 }
64
65 /**
66 * Gets port information in this PortNextObjectiveStoreKey.
67 *
68 * @return port information
69 */
70 public PortNumber portNumber() {
71 return portNum;
72 }
73
74 /**
75 * Gets treatment information in this PortNextObjectiveStoreKey.
76 *
77 * @return treatment information
78 */
79 public TrafficTreatment treatment() {
80 return treatment;
81 }
82
Saurav Das76ae6812017-03-15 15:15:14 -070083 /**
84 * Gets metadata information in this PortNextObjectiveStoreKey.
85 *
86 * @return meta information
87 */
88 public TrafficSelector meta() {
89 return meta;
90 }
91
92
Saurav Das4ce45962015-11-24 23:21:05 -080093 @Override
94 public boolean equals(Object o) {
95 if (this == o) {
96 return true;
97 }
98 if (!(o instanceof PortNextObjectiveStoreKey)) {
99 return false;
100 }
101 PortNextObjectiveStoreKey that =
102 (PortNextObjectiveStoreKey) o;
103 return (Objects.equals(this.deviceId, that.deviceId) &&
104 Objects.equals(this.portNum, that.portNum) &&
Saurav Das76ae6812017-03-15 15:15:14 -0700105 Objects.equals(this.treatment, that.treatment) &&
106 Objects.equals(this.meta, that.meta));
Saurav Das4ce45962015-11-24 23:21:05 -0800107 }
108
109 @Override
110 public int hashCode() {
Saurav Das76ae6812017-03-15 15:15:14 -0700111 return Objects.hash(deviceId, portNum, treatment, meta);
Saurav Das4ce45962015-11-24 23:21:05 -0800112 }
113
114 @Override
115 public String toString() {
Ruchi Sahotaef0761c2019-01-28 01:08:18 +0000116 return toStringHelper(getClass())
117 .add("deviceId", deviceId)
118 .add("portNum", portNum)
119 .add("treatment", treatment)
120 .add("meta", meta)
121 .toString();
Saurav Das4ce45962015-11-24 23:21:05 -0800122 }
123}