blob: 68427f8411577d8fa5045e93e6939fe7e534bd98 [file] [log] [blame]
alshabib42947782015-03-31 14:59:06 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
alshabib42947782015-03-31 14:59:06 -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 */
16package org.onosproject.net.packet;
17
18import com.google.common.base.MoreObjects;
Madan Jampani6f8b7022015-12-07 16:59:59 -080019
20import org.onosproject.cluster.NodeId;
alshabib42947782015-03-31 14:59:06 -070021import org.onosproject.core.ApplicationId;
alshabib19e2cea2015-12-07 11:31:49 -080022import org.onosproject.net.DeviceId;
alshabib42947782015-03-31 14:59:06 -070023import org.onosproject.net.flow.TrafficSelector;
24
Thomas Vachuska27bee092015-06-23 19:03:10 -070025import java.util.Objects;
alshabib19e2cea2015-12-07 11:31:49 -080026import java.util.Optional;
Thomas Vachuska27bee092015-06-23 19:03:10 -070027
alshabib42947782015-03-31 14:59:06 -070028/**
29 * Default implementation of a packet request.
30 */
31public final class DefaultPacketRequest implements PacketRequest {
32 private final TrafficSelector selector;
33 private final PacketPriority priority;
34 private final ApplicationId appId;
Madan Jampani6f8b7022015-12-07 16:59:59 -080035 private final NodeId nodeId;
alshabib19e2cea2015-12-07 11:31:49 -080036 private final Optional<DeviceId> deviceId;
37
alshabib42947782015-03-31 14:59:06 -070038
Thomas Vachuska27bee092015-06-23 19:03:10 -070039 /**
40 * Creates a new packet request.
alshabib19e2cea2015-12-07 11:31:49 -080041 * @param selector traffic selector
Thomas Vachuska27bee092015-06-23 19:03:10 -070042 * @param priority intercept priority
43 * @param appId application id
Madan Jampani6f8b7022015-12-07 16:59:59 -080044 * @param nodeId identifier of node where request originated
alshabib19e2cea2015-12-07 11:31:49 -080045 * @param deviceId device id
Thomas Vachuska27bee092015-06-23 19:03:10 -070046 */
alshabib42947782015-03-31 14:59:06 -070047 public DefaultPacketRequest(TrafficSelector selector, PacketPriority priority,
alshabib19e2cea2015-12-07 11:31:49 -080048 ApplicationId appId, NodeId nodeId, Optional<DeviceId> deviceId) {
alshabib42947782015-03-31 14:59:06 -070049 this.selector = selector;
50 this.priority = priority;
51 this.appId = appId;
Madan Jampani6f8b7022015-12-07 16:59:59 -080052 this.nodeId = nodeId;
alshabib19e2cea2015-12-07 11:31:49 -080053 this.deviceId = deviceId;
alshabib42947782015-03-31 14:59:06 -070054 }
55
Madan Jampani6f8b7022015-12-07 16:59:59 -080056 @Override
alshabib42947782015-03-31 14:59:06 -070057 public TrafficSelector selector() {
58 return selector;
59 }
60
Madan Jampani6f8b7022015-12-07 16:59:59 -080061 @Override
alshabib42947782015-03-31 14:59:06 -070062 public PacketPriority priority() {
63 return priority;
64 }
65
Madan Jampani6f8b7022015-12-07 16:59:59 -080066 @Override
alshabib42947782015-03-31 14:59:06 -070067 public ApplicationId appId() {
68 return appId;
69 }
70
alshabib19e2cea2015-12-07 11:31:49 -080071 public Optional<DeviceId> deviceId() {
72 return deviceId;
73 }
74
alshabib42947782015-03-31 14:59:06 -070075 @Override
Madan Jampani6f8b7022015-12-07 16:59:59 -080076 public NodeId nodeId() {
77 return nodeId;
78 }
79
80 @Override
alshabib42947782015-03-31 14:59:06 -070081 public int hashCode() {
alshabib19e2cea2015-12-07 11:31:49 -080082 return Objects.hash(selector, priority, appId, nodeId, deviceId);
Thomas Vachuska27bee092015-06-23 19:03:10 -070083 }
84
85 @Override
86 public boolean equals(Object obj) {
87 if (this == obj) {
88 return true;
89 }
90 if (obj == null || getClass() != obj.getClass()) {
91 return false;
92 }
93 final DefaultPacketRequest other = (DefaultPacketRequest) obj;
94 return Objects.equals(this.selector, other.selector)
95 && Objects.equals(this.priority, other.priority)
Madan Jampani6f8b7022015-12-07 16:59:59 -080096 && Objects.equals(this.appId, other.appId)
alshabib19e2cea2015-12-07 11:31:49 -080097 && Objects.equals(this.nodeId, other.nodeId)
98 && Objects.equals(this.deviceId, other.deviceId);
alshabib42947782015-03-31 14:59:06 -070099 }
100
101 @Override
102 public String toString() {
103 return MoreObjects.toStringHelper(this.getClass())
104 .add("selector", selector)
105 .add("priority", priority)
Madan Jampani6f8b7022015-12-07 16:59:59 -0800106 .add("appId", appId)
alshabib19e2cea2015-12-07 11:31:49 -0800107 .add("nodeId", nodeId)
Sho SHIMIZUef7e2902016-02-12 18:38:29 -0800108 .add("applies to", deviceId.map(DeviceId::toString).orElse("all"))
alshabib19e2cea2015-12-07 11:31:49 -0800109 .toString();
alshabib42947782015-03-31 14:59:06 -0700110 }
Sho SHIMIZUef7e2902016-02-12 18:38:29 -0800111}