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