blob: a72caef7da9ac922f98a28a00bae1d1217f400af [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 */
Jonathan Hart96892d12014-03-26 20:21:29 -070021package net.onrc.onos.packet;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080022
23import static org.junit.Assert.assertEquals;
24import static org.junit.Assert.assertTrue;
25
26import java.util.Arrays;
27
Jonathan Hart96892d12014-03-26 20:21:29 -070028import net.onrc.onos.packet.BSN;
29import net.onrc.onos.packet.BSNPROBE;
30import net.onrc.onos.packet.Ethernet;
31
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080032import org.junit.Test;
33
34/**
35 *
36 * @author David Erickson (daviderickson@cs.stanford.edu)
37 *
38 */
39public 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}