blob: 0429bd179455732cf6411701358f0557ca025a67 [file] [log] [blame]
Brian O'Connor14796d22016-04-09 02:13:23 -07001/*
Brian O'Connor0947d7e2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Brian O'Connor14796d22016-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 Chan1eaf4802016-04-18 13:44:03 -070016package org.onosproject.segmentrouting.storekey;
Saurav Das2d94d312015-11-24 23:21:05 -080017
18import org.onosproject.net.DeviceId;
19import org.onosproject.net.PortNumber;
Saurav Das368cf212017-03-15 15:15:14 -070020import org.onosproject.net.flow.TrafficSelector;
Saurav Das2d94d312015-11-24 23:21:05 -080021import org.onosproject.net.flow.TrafficTreatment;
22
23import java.util.Objects;
24
25/**
Charles Chanb7f75ac2016-01-11 18:28:54 -080026 * 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 Das2d94d312015-11-24 23:21:05 -080030 */
31public class PortNextObjectiveStoreKey {
32 private final DeviceId deviceId;
33 private final PortNumber portNum;
34 private final TrafficTreatment treatment;
Saurav Das368cf212017-03-15 15:15:14 -070035 private final TrafficSelector meta;
Saurav Das2d94d312015-11-24 23:21:05 -080036
Charles Chanb7f75ac2016-01-11 18:28:54 -080037 /**
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 Das368cf212017-03-15 15:15:14 -070043 * @param meta optional data to pass to the driver
Charles Chanb7f75ac2016-01-11 18:28:54 -080044 */
Saurav Das2d94d312015-11-24 23:21:05 -080045 public PortNextObjectiveStoreKey(DeviceId deviceId, PortNumber portNum,
Saurav Das368cf212017-03-15 15:15:14 -070046 TrafficTreatment treatment,
47 TrafficSelector meta) {
Saurav Das2d94d312015-11-24 23:21:05 -080048 this.deviceId = deviceId;
49 this.portNum = portNum;
50 this.treatment = treatment;
Saurav Das368cf212017-03-15 15:15:14 -070051 this.meta = meta;
Saurav Das2d94d312015-11-24 23:21:05 -080052 }
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 Das368cf212017-03-15 15:15:14 -070081 /**
82 * Gets metadata information in this PortNextObjectiveStoreKey.
83 *
84 * @return meta information
85 */
86 public TrafficSelector meta() {
87 return meta;
88 }
89
90
Saurav Das2d94d312015-11-24 23:21:05 -080091 @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 Das368cf212017-03-15 15:15:14 -0700103 Objects.equals(this.treatment, that.treatment) &&
104 Objects.equals(this.meta, that.meta));
Saurav Das2d94d312015-11-24 23:21:05 -0800105 }
106
107 @Override
108 public int hashCode() {
Saurav Das368cf212017-03-15 15:15:14 -0700109 return Objects.hash(deviceId, portNum, treatment, meta);
Saurav Das2d94d312015-11-24 23:21:05 -0800110 }
111
112 @Override
113 public String toString() {
Saurav Das368cf212017-03-15 15:15:14 -0700114 return "Device: " + deviceId + " Port: " + portNum +
115 " Treatment: " + treatment +
116 " Meta: " + meta;
Saurav Das2d94d312015-11-24 23:21:05 -0800117 }
118}