blob: bed42a2e86dea1344e2963b2d56c1cf6585f63f1 [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 */
21package net.floodlightcontroller.packet;
22
23import static org.junit.Assert.assertTrue;
24
25import java.util.Arrays;
26
27import org.junit.Test;
28
29/**
30 * @author David Erickson (daviderickson@cs.stanford.edu)
31 *
32 */
33public class UDPTest {
34
35 @Test
36 public void testSerialize() {
37 byte[] expected = new byte[] { 0x45, 0x00, 0x00, 0x1d, 0x56, 0x23,
38 0x00, 0x00, (byte) 0x80, 0x11, 0x48, 0x7f, (byte) 0xc0,
39 (byte) 0xa8, 0x01, 0x02, 0x0c, (byte) 0x81, (byte) 0xce, 0x02,
40 0x17, (byte) 0xe1, 0x04, 0x5f, 0x00, 0x09, 0x46, 0x6e,
41 0x01 };
42 IPacket packet = new IPv4()
43 .setIdentification((short) 22051)
44 .setTtl((byte) 128)
45 .setSourceAddress("192.168.1.2")
46 .setDestinationAddress("12.129.206.2")
47 .setPayload(new UDP()
48 .setSourcePort((short) 6113)
49 .setDestinationPort((short) 1119)
50 .setPayload(new Data(new byte[] {0x01}))
51 );
52 byte[] actual = packet.serialize();
53 assertTrue(Arrays.equals(expected, actual));
54 }
55}