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 ICMPTest { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 34 | private byte[] pktSerialized = new byte[]{ |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 35 | // (byte) 0xc8, 0x2a, 0x14, 0x2d, 0x35, (byte) 0xf1, |
| 36 | // 0x00, 0x0c, 0x29, 0x3b, (byte) 0x95, (byte) 0xf2, 0x08, 0x0, |
| 37 | 0x45, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x40, 0x00, 0x40, 0x01, |
| 38 | (byte) 0xa3, (byte) 0xcb, |
| 39 | (byte) 0xc0, (byte) 0xa8, (byte) 0x0a, (byte) 0xe7, |
| 40 | (byte) 0xc0, (byte) 0xa8, (byte) 0x0a, (byte) 0xdb, |
| 41 | 0x08, 0x00, 0x7f, 0x0a, 0x76, (byte) 0xf2, 0x00, 0x02, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 42 | 0x01, 0x01, 0x01}; |
| 43 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 44 | @Test |
| 45 | public void testSerialize() { |
| 46 | IPacket packet = new IPv4() |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 47 | .setIdentification((short) 0) |
| 48 | .setFlags((byte) 0x02) |
| 49 | .setTtl((byte) 64) |
| 50 | .setSourceAddress("192.168.10.231") |
| 51 | .setDestinationAddress("192.168.10.219") |
| 52 | .setPayload(new ICMP() |
| 53 | .setIcmpType((byte) 8) |
| 54 | .setIcmpCode((byte) 0) |
| 55 | .setPayload(new Data(new byte[] |
| 56 | {0x76, (byte) 0xf2, 0x0, 0x2, 0x1, 0x1, 0x1})) |
| 57 | ); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 58 | byte[] actual = packet.serialize(); |
| 59 | assertTrue(Arrays.equals(pktSerialized, actual)); |
| 60 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 61 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 62 | @Test |
| 63 | public void testDeserialize() { |
| 64 | IPacket packet = new IPv4(); |
| 65 | packet.deserialize(pktSerialized, 0, pktSerialized.length); |
| 66 | byte[] pktSerialized1 = packet.serialize(); |
| 67 | assertTrue(Arrays.equals(pktSerialized, pktSerialized1)); |
| 68 | } |
| 69 | } |