Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | /** |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 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 | **/ |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 17 | |
| 18 | /** |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 19 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 20 | */ |
Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 21 | package net.onrc.onos.core.packet; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 22 | |
| 23 | import static org.junit.Assert.assertTrue; |
| 24 | |
| 25 | import java.util.Arrays; |
| 26 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 27 | import org.junit.Test; |
| 28 | |
Yuta HIGUCHI | aa132f5 | 2014-06-26 10:18:39 -0700 | [diff] [blame] | 29 | // CHECKSTYLE IGNORE WriteTag FOR NEXT 2 LINES |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 30 | /** |
| 31 | * @author shudong.zhou@bigswitch.com |
| 32 | */ |
| 33 | public class TCPTest { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 34 | private byte[] pktSerialized = new byte[]{0x45, 0x20, |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 35 | 0x00, 0x34, 0x1d, (byte) 0x85, 0x00, 0x00, 0x32, 0x06, |
| 36 | 0x31, 0x1e, 0x4a, 0x7d, 0x2d, 0x6d, (byte) 0xc0, (byte) 0xa8, |
| 37 | 0x01, 0x6f, 0x03, (byte) 0xe1, (byte) 0xc0, 0x32, (byte) 0xe3, (byte) 0xad, |
| 38 | (byte) 0xee, (byte) 0x88, (byte) 0xb7, (byte) 0xda, (byte) 0xd8, 0x24, (byte) 0x80, 0x10, |
| 39 | 0x01, 0x0b, 0x59, 0x33, 0x00, 0x00, 0x01, 0x01, |
| 40 | 0x08, 0x0a, 0x20, (byte) 0x9a, 0x41, 0x04, 0x07, 0x76, |
| 41 | 0x53, 0x1f}; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 42 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 43 | @Test |
| 44 | public void testSerialize() { |
| 45 | IPacket packet = new IPv4() |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 46 | .setDiffServ((byte) 0x20) |
| 47 | .setIdentification((short) 0x1d85) |
| 48 | .setFlags((byte) 0x00) |
| 49 | .setTtl((byte) 50) |
| 50 | .setSourceAddress("74.125.45.109") |
| 51 | .setDestinationAddress("192.168.1.111") |
| 52 | .setPayload(new TCP() |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 53 | .setSourcePort((short) 993) |
| 54 | .setDestinationPort((short) 49202) |
| 55 | .setSequence(0xe3adee88) |
| 56 | .setAcknowledge(0xb7dad824) |
| 57 | .setDataOffset((byte) 8) |
| 58 | .setFlags((short) 0x10) |
| 59 | .setWindowSize((short) 267) |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 60 | .setOptions(new byte[]{0x01, 0x01, 0x08, 0x0a, 0x20, (byte) 0x9a, |
| 61 | 0x41, 0x04, 0x07, 0x76, 0x53, 0x1f}) |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 62 | .setPayload(null) |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 63 | ); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 64 | byte[] actual = packet.serialize(); |
| 65 | assertTrue(Arrays.equals(pktSerialized, actual)); |
| 66 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 67 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 68 | @Test |
| 69 | public void testDeserialize() { |
| 70 | IPacket packet = new IPv4(); |
| 71 | packet.deserialize(pktSerialized, 0, pktSerialized.length); |
| 72 | byte[] pktSerialized1 = packet.serialize(); |
| 73 | assertTrue(Arrays.equals(pktSerialized, pktSerialized1)); |
| 74 | } |
| 75 | } |