blob: 605ab4b1847a3adbf818a4f77ca0d62773679633 [file] [log] [blame]
alshabib42947782015-03-31 14:59:06 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
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;
alshabib42947782015-03-31 14:59:06 -070022import org.onosproject.net.flow.TrafficSelector;
23
Thomas Vachuska27bee092015-06-23 19:03:10 -070024import java.util.Objects;
25
alshabib42947782015-03-31 14:59:06 -070026/**
27 * Default implementation of a packet request.
28 */
29public final class DefaultPacketRequest implements PacketRequest {
30 private final TrafficSelector selector;
31 private final PacketPriority priority;
32 private final ApplicationId appId;
Madan Jampani6f8b7022015-12-07 16:59:59 -080033 private final NodeId nodeId;
alshabib42947782015-03-31 14:59:06 -070034
Thomas Vachuska27bee092015-06-23 19:03:10 -070035 /**
36 * Creates a new packet request.
37 *
38 * @param selector traffic selector
39 * @param priority intercept priority
40 * @param appId application id
Madan Jampani6f8b7022015-12-07 16:59:59 -080041 * @param nodeId identifier of node where request originated
Thomas Vachuska27bee092015-06-23 19:03:10 -070042 */
alshabib42947782015-03-31 14:59:06 -070043 public DefaultPacketRequest(TrafficSelector selector, PacketPriority priority,
Madan Jampani6f8b7022015-12-07 16:59:59 -080044 ApplicationId appId,
45 NodeId nodeId) {
alshabib42947782015-03-31 14:59:06 -070046 this.selector = selector;
47 this.priority = priority;
48 this.appId = appId;
Madan Jampani6f8b7022015-12-07 16:59:59 -080049 this.nodeId = nodeId;
alshabib42947782015-03-31 14:59:06 -070050 }
51
Madan Jampani6f8b7022015-12-07 16:59:59 -080052 @Override
alshabib42947782015-03-31 14:59:06 -070053 public TrafficSelector selector() {
54 return selector;
55 }
56
Madan Jampani6f8b7022015-12-07 16:59:59 -080057 @Override
alshabib42947782015-03-31 14:59:06 -070058 public PacketPriority priority() {
59 return priority;
60 }
61
Madan Jampani6f8b7022015-12-07 16:59:59 -080062 @Override
alshabib42947782015-03-31 14:59:06 -070063 public ApplicationId appId() {
64 return appId;
65 }
66
alshabib42947782015-03-31 14:59:06 -070067 @Override
Madan Jampani6f8b7022015-12-07 16:59:59 -080068 public NodeId nodeId() {
69 return nodeId;
70 }
71
72 @Override
alshabib42947782015-03-31 14:59:06 -070073 public int hashCode() {
Madan Jampani6f8b7022015-12-07 16:59:59 -080074 return Objects.hash(selector, priority, appId, nodeId);
Thomas Vachuska27bee092015-06-23 19:03:10 -070075 }
76
77 @Override
78 public boolean equals(Object obj) {
79 if (this == obj) {
80 return true;
81 }
82 if (obj == null || getClass() != obj.getClass()) {
83 return false;
84 }
85 final DefaultPacketRequest other = (DefaultPacketRequest) obj;
86 return Objects.equals(this.selector, other.selector)
87 && Objects.equals(this.priority, other.priority)
Madan Jampani6f8b7022015-12-07 16:59:59 -080088 && Objects.equals(this.appId, other.appId)
89 && Objects.equals(this.nodeId, other.nodeId);
alshabib42947782015-03-31 14:59:06 -070090 }
91
92 @Override
93 public String toString() {
94 return MoreObjects.toStringHelper(this.getClass())
95 .add("selector", selector)
96 .add("priority", priority)
Madan Jampani6f8b7022015-12-07 16:59:59 -080097 .add("appId", appId)
98 .add("nodeId", nodeId).toString();
alshabib42947782015-03-31 14:59:06 -070099 }
100}