blob: bbe097e226ddf1ba714b56f9e4652c536d2650e9 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.packet;
tom613d8142014-09-11 15:09:37 -070017
alshabib1d4cace2014-09-13 19:16:26 -070018import java.nio.ByteBuffer;
Ray Milkeyafa00d22014-11-13 19:25:15 -080019import java.util.Objects;
alshabib1d4cace2014-09-13 19:16:26 -070020
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.net.DeviceId;
22import org.onosproject.net.flow.TrafficTreatment;
tom613d8142014-09-11 15:09:37 -070023
alshabib1d4cace2014-09-13 19:16:26 -070024import com.google.common.base.MoreObjects;
tom613d8142014-09-11 15:09:37 -070025
26/**
27 * Default implementation of an immutable outbound packet.
28 */
Ray Milkeyafa00d22014-11-13 19:25:15 -080029public final class DefaultOutboundPacket implements OutboundPacket {
tom613d8142014-09-11 15:09:37 -070030 private final DeviceId sendThrough;
tom8bb16062014-09-12 14:47:46 -070031 private final TrafficTreatment treatment;
tom613d8142014-09-11 15:09:37 -070032 private final ByteBuffer data;
33
34 /**
35 * Creates an immutable outbound packet.
36 *
37 * @param sendThrough identifier through which to send the packet
tom8bb16062014-09-12 14:47:46 -070038 * @param treatment list of packet treatments
tom613d8142014-09-11 15:09:37 -070039 * @param data raw packet data
40 */
41 public DefaultOutboundPacket(DeviceId sendThrough,
alshabib1d4cace2014-09-13 19:16:26 -070042 TrafficTreatment treatment, ByteBuffer data) {
tom613d8142014-09-11 15:09:37 -070043 this.sendThrough = sendThrough;
tom8bb16062014-09-12 14:47:46 -070044 this.treatment = treatment;
tom613d8142014-09-11 15:09:37 -070045 this.data = data;
46 }
47
48 @Override
49 public DeviceId sendThrough() {
50 return sendThrough;
51 }
52
53 @Override
tom8bb16062014-09-12 14:47:46 -070054 public TrafficTreatment treatment() {
55 return treatment;
tom613d8142014-09-11 15:09:37 -070056 }
57
58 @Override
59 public ByteBuffer data() {
60 // FIXME: figure out immutability here
61 return data;
62 }
63
64 @Override
Ray Milkeyafa00d22014-11-13 19:25:15 -080065 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
tom613d8142014-09-11 15:09:37 -070083 public String toString() {
84 return MoreObjects.toStringHelper(this)
85 .add("sendThrough", sendThrough)
tom8bb16062014-09-12 14:47:46 -070086 .add("treatment", treatment)
tom613d8142014-09-11 15:09:37 -070087 .toString();
88 }
89}