blob: 01ecf963109937e623ebe13d71b9475a08200a4c [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
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 */
tom613d8142014-09-11 15:09:37 -070016package org.onlab.onos.net.packet;
17
alshabib1d4cace2014-09-13 19:16:26 -070018import java.nio.ByteBuffer;
19
tom613d8142014-09-11 15:09:37 -070020import org.onlab.onos.net.DeviceId;
tom8bb16062014-09-12 14:47:46 -070021import org.onlab.onos.net.flow.TrafficTreatment;
tom613d8142014-09-11 15:09:37 -070022
alshabib1d4cace2014-09-13 19:16:26 -070023import com.google.common.base.MoreObjects;
tom613d8142014-09-11 15:09:37 -070024
25/**
26 * Default implementation of an immutable outbound packet.
27 */
28public class DefaultOutboundPacket implements OutboundPacket {
29 private final DeviceId sendThrough;
tom8bb16062014-09-12 14:47:46 -070030 private final TrafficTreatment treatment;
tom613d8142014-09-11 15:09:37 -070031 private final ByteBuffer data;
32
33 /**
34 * Creates an immutable outbound packet.
35 *
36 * @param sendThrough identifier through which to send the packet
tom8bb16062014-09-12 14:47:46 -070037 * @param treatment list of packet treatments
tom613d8142014-09-11 15:09:37 -070038 * @param data raw packet data
39 */
40 public DefaultOutboundPacket(DeviceId sendThrough,
alshabib1d4cace2014-09-13 19:16:26 -070041 TrafficTreatment treatment, ByteBuffer data) {
tom613d8142014-09-11 15:09:37 -070042 this.sendThrough = sendThrough;
tom8bb16062014-09-12 14:47:46 -070043 this.treatment = treatment;
tom613d8142014-09-11 15:09:37 -070044 this.data = data;
45 }
46
47 @Override
48 public DeviceId sendThrough() {
49 return sendThrough;
50 }
51
52 @Override
tom8bb16062014-09-12 14:47:46 -070053 public TrafficTreatment treatment() {
54 return treatment;
tom613d8142014-09-11 15:09:37 -070055 }
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)
tom8bb16062014-09-12 14:47:46 -070067 .add("treatment", treatment)
tom613d8142014-09-11 15:09:37 -070068 .toString();
69 }
70}