Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.packet; |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 17 | |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 18 | import java.nio.ByteBuffer; |
Ray Milkey | afa00d2 | 2014-11-13 19:25:15 -0800 | [diff] [blame] | 19 | import java.util.Objects; |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 20 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.net.flow.TrafficTreatment; |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 23 | |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 24 | import com.google.common.base.MoreObjects; |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Default implementation of an immutable outbound packet. |
| 28 | */ |
Ray Milkey | afa00d2 | 2014-11-13 19:25:15 -0800 | [diff] [blame] | 29 | public final class DefaultOutboundPacket implements OutboundPacket { |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 30 | private final DeviceId sendThrough; |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 31 | private final TrafficTreatment treatment; |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 32 | private final ByteBuffer data; |
| 33 | |
| 34 | /** |
| 35 | * Creates an immutable outbound packet. |
| 36 | * |
| 37 | * @param sendThrough identifier through which to send the packet |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 38 | * @param treatment list of packet treatments |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 39 | * @param data raw packet data |
| 40 | */ |
| 41 | public DefaultOutboundPacket(DeviceId sendThrough, |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 42 | TrafficTreatment treatment, ByteBuffer data) { |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 43 | this.sendThrough = sendThrough; |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 44 | this.treatment = treatment; |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 45 | this.data = data; |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public DeviceId sendThrough() { |
| 50 | return sendThrough; |
| 51 | } |
| 52 | |
| 53 | @Override |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 54 | public TrafficTreatment treatment() { |
| 55 | return treatment; |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public ByteBuffer data() { |
| 60 | // FIXME: figure out immutability here |
| 61 | return data; |
| 62 | } |
| 63 | |
| 64 | @Override |
Ray Milkey | afa00d2 | 2014-11-13 19:25:15 -0800 | [diff] [blame] | 65 | public int hashCode() { |
| 66 | return Objects.hash(sendThrough, treatment, data); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public boolean equals(Object obj) { |
| 71 | if (this == obj) { |
| 72 | return true; |
| 73 | } |
| 74 | if (obj instanceof OutboundPacket) { |
| 75 | final DefaultOutboundPacket other = (DefaultOutboundPacket) obj; |
| 76 | return Objects.equals(this.sendThrough, other.sendThrough) && |
| 77 | Objects.equals(this.treatment, other.treatment) && |
| 78 | Objects.equals(this.data, other.data); |
| 79 | } |
| 80 | return false; |
| 81 | } |
| 82 | @Override |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 83 | public String toString() { |
| 84 | return MoreObjects.toStringHelper(this) |
| 85 | .add("sendThrough", sendThrough) |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 86 | .add("treatment", treatment) |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 87 | .toString(); |
| 88 | } |
| 89 | } |