Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | /** |
| 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 | */ |
| 21 | package net.floodlightcontroller.packet; |
| 22 | |
| 23 | import static org.junit.Assert.assertEquals; |
| 24 | import static org.junit.Assert.assertTrue; |
| 25 | |
| 26 | import java.util.Arrays; |
| 27 | |
| 28 | import org.junit.Test; |
| 29 | |
| 30 | /** |
| 31 | * |
| 32 | * @author David Erickson (daviderickson@cs.stanford.edu) |
| 33 | * |
| 34 | */ |
| 35 | public class BSNTest { |
| 36 | protected byte[] probePkt = { |
| 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, // src mac |
| 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, // dst mac |
| 39 | (byte) 0x89, 0x42, // BSN type |
| 40 | 0x20, 0x00, 0x06, 0x04, 0x00, 0x01, 0x00, 0x00, // BSN header |
| 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // controller id |
| 42 | 0x00, 0x00, 0x00, 0x03, // sequence id |
| 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, // src mac |
| 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, // dst mac |
| 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, // switch dpid |
| 46 | 0x00, 0x00, 0x00, 0x01 // port number |
| 47 | }; |
| 48 | |
| 49 | protected Ethernet getProbePacket() { |
| 50 | return (Ethernet) new Ethernet() |
| 51 | .setSourceMACAddress("00:00:00:00:00:04") |
| 52 | .setDestinationMACAddress("00:00:00:00:00:01") |
| 53 | .setEtherType(Ethernet.TYPE_BSN) |
| 54 | .setPayload(new BSN(BSN.BSN_TYPE_PROBE) |
| 55 | .setPayload(new BSNPROBE() |
| 56 | .setSequenceId(3) |
| 57 | .setSrcMac(new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x01}) |
| 58 | .setDstMac(new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x04}) |
| 59 | .setSrcSwDpid(0x06) |
| 60 | .setSrcPortNo(0x01) |
| 61 | ) |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | @Test |
| 66 | public void testSerialize() throws Exception { |
| 67 | Ethernet pkt = getProbePacket(); |
| 68 | byte[] serialized = pkt.serialize(); |
| 69 | assertTrue(Arrays.equals(probePkt, serialized)); |
| 70 | } |
| 71 | |
| 72 | @Test |
| 73 | public void testDeserialize() throws Exception { |
| 74 | Ethernet pkt = (Ethernet) new Ethernet().deserialize(probePkt, 0, probePkt.length); |
| 75 | assertTrue(Arrays.equals(probePkt, pkt.serialize())); |
| 76 | |
| 77 | Ethernet expected = getProbePacket(); |
| 78 | assertEquals(expected, pkt); |
| 79 | } |
| 80 | } |