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