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; |
| 19 | import org.onosproject.core.ApplicationId; |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 20 | import org.onosproject.net.flow.TrafficSelector; |
| 21 | |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame^] | 22 | import java.util.Objects; |
| 23 | |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 24 | /** |
| 25 | * Default implementation of a packet request. |
| 26 | */ |
| 27 | public final class DefaultPacketRequest implements PacketRequest { |
| 28 | private final TrafficSelector selector; |
| 29 | private final PacketPriority priority; |
| 30 | private final ApplicationId appId; |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 31 | |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame^] | 32 | /** |
| 33 | * Creates a new packet request. |
| 34 | * |
| 35 | * @param selector traffic selector |
| 36 | * @param priority intercept priority |
| 37 | * @param appId application id |
| 38 | */ |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 39 | public DefaultPacketRequest(TrafficSelector selector, PacketPriority priority, |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame^] | 40 | ApplicationId appId) { |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 41 | this.selector = selector; |
| 42 | this.priority = priority; |
| 43 | this.appId = appId; |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | public TrafficSelector selector() { |
| 47 | return selector; |
| 48 | } |
| 49 | |
| 50 | public PacketPriority priority() { |
| 51 | return priority; |
| 52 | } |
| 53 | |
| 54 | public ApplicationId appId() { |
| 55 | return appId; |
| 56 | } |
| 57 | |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 58 | @Override |
| 59 | public int hashCode() { |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame^] | 60 | return Objects.hash(selector, priority, appId); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public boolean equals(Object obj) { |
| 65 | if (this == obj) { |
| 66 | return true; |
| 67 | } |
| 68 | if (obj == null || getClass() != obj.getClass()) { |
| 69 | return false; |
| 70 | } |
| 71 | final DefaultPacketRequest other = (DefaultPacketRequest) obj; |
| 72 | return Objects.equals(this.selector, other.selector) |
| 73 | && Objects.equals(this.priority, other.priority) |
| 74 | && Objects.equals(this.appId, other.appId); |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public String toString() { |
| 79 | return MoreObjects.toStringHelper(this.getClass()) |
| 80 | .add("selector", selector) |
| 81 | .add("priority", priority) |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame^] | 82 | .add("appId", appId).toString(); |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 83 | } |
| 84 | } |