blob: 83f4a41777f61bf4a521e97ffa1cfddb1c246499 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
Ray Milkey269ffb92014-04-03 14:43:30 -07002 * 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 Krishnaswamy345ee992012-12-13 20:29:48 -080017
18/**
19 *
20 */
Jonathan Hartdeda0ba2014-04-03 11:14:12 -070021package net.onrc.onos.core.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
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080028import org.junit.Test;
29
30/**
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080031 * @author David Erickson (daviderickson@cs.stanford.edu)
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080032 */
Ray Milkey269ffb92014-04-03 14:43:30 -070033public class BSNTest {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080034 protected byte[] probePkt = {
Ray Milkey269ffb92014-04-03 14:43:30 -070035 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, // src mac
36 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, // dst mac
37 (byte) 0x89, 0x42, // BSN type
38 0x20, 0x00, 0x06, 0x04, 0x00, 0x01, 0x00, 0x00, // BSN header
39 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // controller id
40 0x00, 0x00, 0x00, 0x03, // sequence id
41 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, // src mac
42 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, // dst mac
43 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, // switch dpid
44 0x00, 0x00, 0x00, 0x01 // port number
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080045 };
Ray Milkey269ffb92014-04-03 14:43:30 -070046
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080047 protected Ethernet getProbePacket() {
48 return (Ethernet) new Ethernet()
Ray Milkey269ffb92014-04-03 14:43:30 -070049 .setSourceMACAddress("00:00:00:00:00:04")
50 .setDestinationMACAddress("00:00:00:00:00:01")
51 .setEtherType(Ethernet.TYPE_BSN)
52 .setPayload(new BSN(BSN.BSN_TYPE_PROBE)
53 .setPayload(new BSNPROBE()
54 .setSequenceId(3)
55 .setSrcMac(new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x01})
56 .setDstMac(new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x04})
57 .setSrcSwDpid(0x06)
58 .setSrcPortNo(0x01)
59 )
60 );
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080061 }
62
63 @Test
64 public void testSerialize() throws Exception {
65 Ethernet pkt = getProbePacket();
66 byte[] serialized = pkt.serialize();
67 assertTrue(Arrays.equals(probePkt, serialized));
68 }
69
70 @Test
71 public void testDeserialize() throws Exception {
72 Ethernet pkt = (Ethernet) new Ethernet().deserialize(probePkt, 0, probePkt.length);
73 assertTrue(Arrays.equals(probePkt, pkt.serialize()));
74
75 Ethernet expected = getProbePacket();
76 assertEquals(expected, pkt);
77 }
78}