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