tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.packet; |
| 2 | |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 3 | import java.nio.ByteBuffer; |
| 4 | |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 5 | import org.onlab.onos.net.DeviceId; |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 6 | import org.onlab.onos.net.flow.TrafficTreatment; |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 7 | |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 8 | import com.google.common.base.MoreObjects; |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 9 | |
| 10 | /** |
| 11 | * Default implementation of an immutable outbound packet. |
| 12 | */ |
| 13 | public class DefaultOutboundPacket implements OutboundPacket { |
| 14 | private final DeviceId sendThrough; |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 15 | private final TrafficTreatment treatment; |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 16 | private final ByteBuffer data; |
| 17 | |
| 18 | /** |
| 19 | * Creates an immutable outbound packet. |
| 20 | * |
| 21 | * @param sendThrough identifier through which to send the packet |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 22 | * @param treatment list of packet treatments |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 23 | * @param data raw packet data |
| 24 | */ |
| 25 | public DefaultOutboundPacket(DeviceId sendThrough, |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 26 | TrafficTreatment treatment, ByteBuffer data) { |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 27 | this.sendThrough = sendThrough; |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 28 | this.treatment = treatment; |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 29 | this.data = data; |
| 30 | } |
| 31 | |
| 32 | @Override |
| 33 | public DeviceId sendThrough() { |
| 34 | return sendThrough; |
| 35 | } |
| 36 | |
| 37 | @Override |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 38 | public TrafficTreatment treatment() { |
| 39 | return treatment; |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public ByteBuffer data() { |
| 44 | // FIXME: figure out immutability here |
| 45 | return data; |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public String toString() { |
| 50 | return MoreObjects.toStringHelper(this) |
| 51 | .add("sendThrough", sendThrough) |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 52 | .add("treatment", treatment) |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 53 | .toString(); |
| 54 | } |
| 55 | } |