blob: 27be84e8991a10513b59502ad8e8ca2d59efd729 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
Ray Milkey269ffb92014-04-03 14:43:30 -07002 * Copyright 2011, Big Switch Networks, Inc.
3 * Originally created by David Erickson, Stanford University
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License. You may obtain
7 * a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations
15 * under the License.
16 **/
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080017
Jonathan Hartdeda0ba2014-04-03 11:14:12 -070018package net.onrc.onos.core.packet;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080019
20/**
Ray Milkeyb41100a2014-04-10 10:42:15 -070021 * @author David Erickson (daviderickson@cs.stanford.edu).
Ray Milkey269ffb92014-04-03 14:43:30 -070022 */
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080023public interface IPacket {
24 /**
Jonathan Hart99ff20a2014-06-15 16:53:00 -070025 * Gets the payload of the packet.
26 *
27 * @return the payload of the packet
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080028 */
29 public IPacket getPayload();
30
31 /**
Jonathan Hart99ff20a2014-06-15 16:53:00 -070032 * Sets the payload of the packet.
33 *
34 * @param packet the inner packet to set as the payload
35 * @return this IPacket
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080036 */
37 public IPacket setPayload(IPacket packet);
38
39 /**
Jonathan Hart99ff20a2014-06-15 16:53:00 -070040 * Gets the parent (outer) packet.
41 *
42 * @return the parent packet
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080043 */
44 public IPacket getParent();
45
46 /**
Jonathan Hart99ff20a2014-06-15 16:53:00 -070047 * Sets the parent (outer) packet.
48 *
49 * @param packet the parent packet
50 * @return this IPacket
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080051 */
52 public IPacket setParent(IPacket packet);
53
54 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -070055 * Reset any checksums as needed, and call resetChecksum on all parents.
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080056 */
57 public void resetChecksum();
Ray Milkey269ffb92014-04-03 14:43:30 -070058
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080059 /**
Ray Milkey269ffb92014-04-03 14:43:30 -070060 * Sets all payloads parent packet if applicable, then serializes this
Ray Milkeyb41100a2014-04-10 10:42:15 -070061 * packet and all payloads.
Ray Milkey269ffb92014-04-03 14:43:30 -070062 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080063 * @return a byte[] containing this packet and payloads
64 */
65 public byte[] serialize();
66
67 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -070068 * Deserializes this packet layer and all possible payloads.
Ray Milkey269ffb92014-04-03 14:43:30 -070069 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080070 * @param data
71 * @param offset offset to start deserializing from
72 * @param length length of the data to deserialize
73 * @return the deserialized data
74 */
75 public IPacket deserialize(byte[] data, int offset, int length);
Ray Milkey269ffb92014-04-03 14:43:30 -070076
77 /**
78 * Clone this packet and its payload packet but not its parent.
79 *
Jonathan Hart99ff20a2014-06-15 16:53:00 -070080 * @return a cloned copy of this packet
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080081 */
82 public Object clone();
83}