Brian O'Connor | 7cbbbb7 | 2016-04-09 02:13:23 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Brian O'Connor | 7cbbbb7 | 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 | d299036 | 2016-04-18 13:44:03 -0700 | [diff] [blame] | 16 | package org.onosproject.segmentrouting.storekey; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 17 | |
| 18 | import org.onosproject.net.DeviceId; |
| 19 | import org.onosproject.net.PortNumber; |
Saurav Das | 76ae681 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 20 | import org.onosproject.net.flow.TrafficSelector; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 21 | import org.onosproject.net.flow.TrafficTreatment; |
| 22 | |
| 23 | import java.util.Objects; |
| 24 | |
| 25 | /** |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 26 | * Key of Device/Port to NextObjective store. |
| 27 | * |
| 28 | * Since there can be multiple next objectives to the same physical port, |
| 29 | * we differentiate between them by including the treatment in the key. |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 30 | */ |
| 31 | public class PortNextObjectiveStoreKey { |
| 32 | private final DeviceId deviceId; |
| 33 | private final PortNumber portNum; |
| 34 | private final TrafficTreatment treatment; |
Saurav Das | 76ae681 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 35 | private final TrafficSelector meta; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 36 | |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 37 | /** |
| 38 | * Constructs the key of port next objective store. |
| 39 | * |
| 40 | * @param deviceId device ID |
| 41 | * @param portNum port number |
| 42 | * @param treatment treatment that will be applied to the interface |
Saurav Das | 76ae681 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 43 | * @param meta optional data to pass to the driver |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 44 | */ |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 45 | public PortNextObjectiveStoreKey(DeviceId deviceId, PortNumber portNum, |
Saurav Das | 76ae681 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 46 | TrafficTreatment treatment, |
| 47 | TrafficSelector meta) { |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 48 | this.deviceId = deviceId; |
| 49 | this.portNum = portNum; |
| 50 | this.treatment = treatment; |
Saurav Das | 76ae681 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 51 | this.meta = meta; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Gets device id in this PortNextObjectiveStoreKey. |
| 56 | * |
| 57 | * @return device id |
| 58 | */ |
| 59 | public DeviceId deviceId() { |
| 60 | return deviceId; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Gets port information in this PortNextObjectiveStoreKey. |
| 65 | * |
| 66 | * @return port information |
| 67 | */ |
| 68 | public PortNumber portNumber() { |
| 69 | return portNum; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Gets treatment information in this PortNextObjectiveStoreKey. |
| 74 | * |
| 75 | * @return treatment information |
| 76 | */ |
| 77 | public TrafficTreatment treatment() { |
| 78 | return treatment; |
| 79 | } |
| 80 | |
Saurav Das | 76ae681 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 81 | /** |
| 82 | * Gets metadata information in this PortNextObjectiveStoreKey. |
| 83 | * |
| 84 | * @return meta information |
| 85 | */ |
| 86 | public TrafficSelector meta() { |
| 87 | return meta; |
| 88 | } |
| 89 | |
| 90 | |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 91 | @Override |
| 92 | public boolean equals(Object o) { |
| 93 | if (this == o) { |
| 94 | return true; |
| 95 | } |
| 96 | if (!(o instanceof PortNextObjectiveStoreKey)) { |
| 97 | return false; |
| 98 | } |
| 99 | PortNextObjectiveStoreKey that = |
| 100 | (PortNextObjectiveStoreKey) o; |
| 101 | return (Objects.equals(this.deviceId, that.deviceId) && |
| 102 | Objects.equals(this.portNum, that.portNum) && |
Saurav Das | 76ae681 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 103 | Objects.equals(this.treatment, that.treatment) && |
| 104 | Objects.equals(this.meta, that.meta)); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public int hashCode() { |
Saurav Das | 76ae681 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 109 | return Objects.hash(deviceId, portNum, treatment, meta); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public String toString() { |
Saurav Das | 76ae681 | 2017-03-15 15:15:14 -0700 | [diff] [blame] | 114 | return "Device: " + deviceId + " Port: " + portNum + |
| 115 | " Treatment: " + treatment + |
| 116 | " Meta: " + meta; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 117 | } |
| 118 | } |