blob: b5eca4606451e36b188e352d2936495ce1ce2279 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2* 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**/
17
18/**
19 *
20 */
Jonathan Hartdeda0ba2014-04-03 11:14:12 -070021package net.onrc.onos.core.packet;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080022
23import static org.junit.Assert.assertTrue;
24
25import java.util.Arrays;
26
Jonathan Hartdeda0ba2014-04-03 11:14:12 -070027import net.onrc.onos.core.packet.Data;
28import net.onrc.onos.core.packet.IPacket;
29import net.onrc.onos.core.packet.IPv4;
30import net.onrc.onos.core.packet.UDP;
Jonathan Hart96892d12014-03-26 20:21:29 -070031
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080032import org.junit.Test;
33
34/**
35 * @author David Erickson (daviderickson@cs.stanford.edu)
36 *
37 */
38public class UDPTest {
39
40 @Test
41 public void testSerialize() {
42 byte[] expected = new byte[] { 0x45, 0x00, 0x00, 0x1d, 0x56, 0x23,
43 0x00, 0x00, (byte) 0x80, 0x11, 0x48, 0x7f, (byte) 0xc0,
44 (byte) 0xa8, 0x01, 0x02, 0x0c, (byte) 0x81, (byte) 0xce, 0x02,
45 0x17, (byte) 0xe1, 0x04, 0x5f, 0x00, 0x09, 0x46, 0x6e,
46 0x01 };
47 IPacket packet = new IPv4()
48 .setIdentification((short) 22051)
49 .setTtl((byte) 128)
50 .setSourceAddress("192.168.1.2")
51 .setDestinationAddress("12.129.206.2")
52 .setPayload(new UDP()
53 .setSourcePort((short) 6113)
54 .setDestinationPort((short) 1119)
55 .setPayload(new Data(new byte[] {0x01}))
56 );
57 byte[] actual = packet.serialize();
58 assertTrue(Arrays.equals(expected, actual));
59 }
60}