alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.net.packet; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
Madan Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 19 | |
| 20 | import org.onosproject.cluster.NodeId; |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 21 | import org.onosproject.core.ApplicationId; |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 22 | import org.onosproject.net.flow.TrafficSelector; |
| 23 | |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 24 | import java.util.Objects; |
| 25 | |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Default implementation of a packet request. |
| 28 | */ |
| 29 | public final class DefaultPacketRequest implements PacketRequest { |
| 30 | private final TrafficSelector selector; |
| 31 | private final PacketPriority priority; |
| 32 | private final ApplicationId appId; |
Madan Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 33 | private final NodeId nodeId; |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 34 | |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 35 | /** |
| 36 | * Creates a new packet request. |
| 37 | * |
| 38 | * @param selector traffic selector |
| 39 | * @param priority intercept priority |
| 40 | * @param appId application id |
Madan Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 41 | * @param nodeId identifier of node where request originated |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 42 | */ |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 43 | public DefaultPacketRequest(TrafficSelector selector, PacketPriority priority, |
Madan Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 44 | ApplicationId appId, |
| 45 | NodeId nodeId) { |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 46 | this.selector = selector; |
| 47 | this.priority = priority; |
| 48 | this.appId = appId; |
Madan Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 49 | this.nodeId = nodeId; |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Madan Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 52 | @Override |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 53 | public TrafficSelector selector() { |
| 54 | return selector; |
| 55 | } |
| 56 | |
Madan Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 57 | @Override |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 58 | public PacketPriority priority() { |
| 59 | return priority; |
| 60 | } |
| 61 | |
Madan Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 62 | @Override |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 63 | public ApplicationId appId() { |
| 64 | return appId; |
| 65 | } |
| 66 | |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 67 | @Override |
Madan Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 68 | public NodeId nodeId() { |
| 69 | return nodeId; |
| 70 | } |
| 71 | |
| 72 | @Override |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 73 | public int hashCode() { |
Madan Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 74 | return Objects.hash(selector, priority, appId, nodeId); |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 75 | } |
| 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 Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 88 | && Objects.equals(this.appId, other.appId) |
| 89 | && Objects.equals(this.nodeId, other.nodeId); |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public String toString() { |
| 94 | return MoreObjects.toStringHelper(this.getClass()) |
| 95 | .add("selector", selector) |
| 96 | .add("priority", priority) |
Madan Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 97 | .add("appId", appId) |
| 98 | .add("nodeId", nodeId).toString(); |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 99 | } |
| 100 | } |