blob: ce2eb118ee4b76c4cc72ea6ba1679e2e730d5f8b [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;
19import org.onosproject.core.ApplicationId;
alshabib42947782015-03-31 14:59:06 -070020import org.onosproject.net.flow.TrafficSelector;
21
Thomas Vachuska27bee092015-06-23 19:03:10 -070022import java.util.Objects;
23
alshabib42947782015-03-31 14:59:06 -070024/**
25 * Default implementation of a packet request.
26 */
27public final class DefaultPacketRequest implements PacketRequest {
28 private final TrafficSelector selector;
29 private final PacketPriority priority;
30 private final ApplicationId appId;
alshabib42947782015-03-31 14:59:06 -070031
Thomas Vachuska27bee092015-06-23 19:03:10 -070032 /**
33 * Creates a new packet request.
34 *
35 * @param selector traffic selector
36 * @param priority intercept priority
37 * @param appId application id
38 */
alshabib42947782015-03-31 14:59:06 -070039 public DefaultPacketRequest(TrafficSelector selector, PacketPriority priority,
Thomas Vachuska27bee092015-06-23 19:03:10 -070040 ApplicationId appId) {
alshabib42947782015-03-31 14:59:06 -070041 this.selector = selector;
42 this.priority = priority;
43 this.appId = appId;
alshabib42947782015-03-31 14:59:06 -070044 }
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
alshabib42947782015-03-31 14:59:06 -070058 @Override
59 public int hashCode() {
Thomas Vachuska27bee092015-06-23 19:03:10 -070060 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);
alshabib42947782015-03-31 14:59:06 -070075 }
76
77 @Override
78 public String toString() {
79 return MoreObjects.toStringHelper(this.getClass())
80 .add("selector", selector)
81 .add("priority", priority)
Thomas Vachuska27bee092015-06-23 19:03:10 -070082 .add("appId", appId).toString();
alshabib42947782015-03-31 14:59:06 -070083 }
84}