alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
alshabib | 4294778 | 2015-03-31 14:59:06 -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 | */ |
| 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 | 19e2cea | 2015-12-07 11:31:49 -0800 | [diff] [blame] | 22 | import org.onosproject.net.DeviceId; |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 23 | import org.onosproject.net.flow.TrafficSelector; |
| 24 | |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 25 | import java.util.Objects; |
alshabib | 19e2cea | 2015-12-07 11:31:49 -0800 | [diff] [blame] | 26 | import java.util.Optional; |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 27 | |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Default implementation of a packet request. |
| 30 | */ |
| 31 | public final class DefaultPacketRequest implements PacketRequest { |
| 32 | private final TrafficSelector selector; |
| 33 | private final PacketPriority priority; |
| 34 | private final ApplicationId appId; |
Madan Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 35 | private final NodeId nodeId; |
alshabib | 19e2cea | 2015-12-07 11:31:49 -0800 | [diff] [blame] | 36 | private final Optional<DeviceId> deviceId; |
Pier Luigi Ventre | 6fd1ca9 | 2017-01-13 03:15:50 +0000 | [diff] [blame] | 37 | |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 38 | |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 39 | /** |
| 40 | * Creates a new packet request. |
Charles Chan | 874900e | 2016-12-09 16:55:39 -0800 | [diff] [blame] | 41 | * @param selector traffic selector |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 42 | * @param priority intercept priority |
| 43 | * @param appId application id |
Madan Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 44 | * @param nodeId identifier of node where request originated |
alshabib | 19e2cea | 2015-12-07 11:31:49 -0800 | [diff] [blame] | 45 | * @param deviceId device id |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 46 | */ |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 47 | public DefaultPacketRequest(TrafficSelector selector, PacketPriority priority, |
alshabib | 19e2cea | 2015-12-07 11:31:49 -0800 | [diff] [blame] | 48 | ApplicationId appId, NodeId nodeId, Optional<DeviceId> deviceId) { |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 49 | this.selector = selector; |
| 50 | this.priority = priority; |
| 51 | this.appId = appId; |
Madan Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 52 | this.nodeId = nodeId; |
alshabib | 19e2cea | 2015-12-07 11:31:49 -0800 | [diff] [blame] | 53 | this.deviceId = deviceId; |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Madan Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 56 | @Override |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 57 | public TrafficSelector selector() { |
| 58 | return selector; |
| 59 | } |
| 60 | |
Madan Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 61 | @Override |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 62 | public PacketPriority priority() { |
| 63 | return priority; |
| 64 | } |
| 65 | |
Madan Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 66 | @Override |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 67 | public ApplicationId appId() { |
| 68 | return appId; |
| 69 | } |
| 70 | |
alshabib | 19e2cea | 2015-12-07 11:31:49 -0800 | [diff] [blame] | 71 | public Optional<DeviceId> deviceId() { |
| 72 | return deviceId; |
| 73 | } |
| 74 | |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 75 | @Override |
Madan Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 76 | public NodeId nodeId() { |
| 77 | return nodeId; |
| 78 | } |
| 79 | |
| 80 | @Override |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 81 | public int hashCode() { |
Pier Luigi Ventre | 6fd1ca9 | 2017-01-13 03:15:50 +0000 | [diff] [blame] | 82 | return Objects.hash(selector, priority, appId, nodeId, deviceId); |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 83 | } |
| 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 Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 96 | && Objects.equals(this.appId, other.appId) |
alshabib | 19e2cea | 2015-12-07 11:31:49 -0800 | [diff] [blame] | 97 | && Objects.equals(this.nodeId, other.nodeId) |
Pier Luigi Ventre | 6fd1ca9 | 2017-01-13 03:15:50 +0000 | [diff] [blame] | 98 | && Objects.equals(this.deviceId, other.deviceId); |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public String toString() { |
| 103 | return MoreObjects.toStringHelper(this.getClass()) |
| 104 | .add("selector", selector) |
| 105 | .add("priority", priority) |
Madan Jampani | 6f8b702 | 2015-12-07 16:59:59 -0800 | [diff] [blame] | 106 | .add("appId", appId) |
alshabib | 19e2cea | 2015-12-07 11:31:49 -0800 | [diff] [blame] | 107 | .add("nodeId", nodeId) |
Sho SHIMIZU | ef7e290 | 2016-02-12 18:38:29 -0800 | [diff] [blame] | 108 | .add("applies to", deviceId.map(DeviceId::toString).orElse("all")) |
alshabib | 19e2cea | 2015-12-07 11:31:49 -0800 | [diff] [blame] | 109 | .toString(); |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 110 | } |
Sho SHIMIZU | ef7e290 | 2016-02-12 18:38:29 -0800 | [diff] [blame] | 111 | } |