Brian O'Connor | 14796d2 | 2016-04-09 02:13:23 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0947d7e | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Brian O'Connor | 14796d2 | 2016-04-09 02:13:23 -0700 | [diff] [blame] | 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 | */ |
Charles Chan | 1eaf480 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 16 | package org.onosproject.segmentrouting.storekey; |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 17 | |
| 18 | import org.onosproject.net.DeviceId; |
| 19 | import org.onosproject.net.PortNumber; |
Saurav Das | 368cf21 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 20 | import org.onosproject.net.flow.TrafficSelector; |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 21 | import org.onosproject.net.flow.TrafficTreatment; |
| 22 | |
| 23 | import java.util.Objects; |
| 24 | |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 25 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 26 | |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 27 | /** |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 28 | * 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 Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 32 | */ |
| 33 | public class PortNextObjectiveStoreKey { |
| 34 | private final DeviceId deviceId; |
| 35 | private final PortNumber portNum; |
| 36 | private final TrafficTreatment treatment; |
Saurav Das | 368cf21 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 37 | private final TrafficSelector meta; |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 38 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 39 | /** |
| 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 Das | 368cf21 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 45 | * @param meta optional data to pass to the driver |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 46 | */ |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 47 | public PortNextObjectiveStoreKey(DeviceId deviceId, PortNumber portNum, |
Saurav Das | 368cf21 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 48 | TrafficTreatment treatment, |
| 49 | TrafficSelector meta) { |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 50 | this.deviceId = deviceId; |
| 51 | this.portNum = portNum; |
| 52 | this.treatment = treatment; |
Saurav Das | 368cf21 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 53 | this.meta = meta; |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 54 | } |
| 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 Das | 368cf21 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 83 | /** |
| 84 | * Gets metadata information in this PortNextObjectiveStoreKey. |
| 85 | * |
| 86 | * @return meta information |
| 87 | */ |
| 88 | public TrafficSelector meta() { |
| 89 | return meta; |
| 90 | } |
| 91 | |
| 92 | |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 93 | @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 Das | 368cf21 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 105 | Objects.equals(this.treatment, that.treatment) && |
| 106 | Objects.equals(this.meta, that.meta)); |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public int hashCode() { |
Saurav Das | 368cf21 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 111 | return Objects.hash(deviceId, portNum, treatment, meta); |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public String toString() { |
Ruchi Sahota | 71bcb4e | 2019-01-28 01:08:18 +0000 | [diff] [blame] | 116 | return toStringHelper(getClass()) |
| 117 | .add("deviceId", deviceId) |
| 118 | .add("portNum", portNum) |
| 119 | .add("treatment", treatment) |
| 120 | .add("meta", meta) |
| 121 | .toString(); |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 122 | } |
| 123 | } |