blob: bed47336925547e2b8128bc0fde43d717d01f589 [file] [log] [blame]
Rusty Eddy80f12522015-09-03 22:42:02 +00001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onlab.packet;
17
18import org.junit.Before;
19import org.junit.Test;
20import org.onlab.packet.pim.PIMAddrUnicast;
21import org.onlab.packet.pim.PIMHello;
22import org.onlab.packet.pim.PIMJoinPrune;
23
24import static junit.framework.Assert.assertTrue;
25
26public final class PIMTest {
27
28 public static final String SADDR = "10.2.1.2";
29 public static final String PIMADDR = "224.0.0.13";
30 public static final String PIMUADDR = "10.23.3.5";
31
32 public static final String SADDR1 = "10.1.1.1/32";
33 public static final String SADDR2 = "10.1.2.1/32";
34 public static final String GADDR1 = "232.1.1.1/32";
35 public static final String GADDR2 = "232.1.2.1/32";
36
37 public static final String CPSTR1 = "of:deadbeefball/8";
38 public static final String CPSTR2 = "of:deadbeefcafe/3";
39 public static final String CPSTR3 = "of:2badcafef00d/3";
40
41 private Deserializer<PIM> deserializer;
42
43 private PIM pimHello;
44 private PIMHello hello;
45
46 private PIM pimJoinPrune;
47 private PIMJoinPrune joinPrune;
48
49 @Before
50 public void setUp() throws Exception {
51
52 // Create a PIM Hello
53 pimHello = new PIM();
54 pimHello.setVersion((byte) 2);
55 pimHello.setPIMType((byte) PIM.TYPE_HELLO);
56 pimHello.setChecksum((short) 0);
57
58 hello = new PIMHello();
59 hello.addHoldtime(0xd2);
60 hello.addPriority(44);
61 hello.addGenId(0xf00d);
62 pimHello.setPayload(hello);
63 hello.setParent(pimHello);
64
65 // Create PIM Join Prune
66 pimJoinPrune = new PIM();
67 pimJoinPrune.setVersion((byte) 2);
68 pimJoinPrune.setPIMType((byte) PIM.TYPE_JOIN_PRUNE_REQUEST);
69 pimJoinPrune.setChecksum((short) 0);
70
71 joinPrune = new PIMJoinPrune();
72 joinPrune.setUpstreamAddr(new PIMAddrUnicast(SADDR));
73 joinPrune.addJoin(GADDR1, SADDR1);
74 joinPrune.addJoin(GADDR2, SADDR2);
75 joinPrune.addPrune(GADDR1, SADDR2);
76 joinPrune.addPrune(GADDR2, SADDR1);
77
78 pimJoinPrune.setPayload(joinPrune);
79 joinPrune.setParent(pimJoinPrune);
80
81 deserializer = PIM.deserializer();
82 }
83
84 @Test
85 public void testDerserializeBadInput() throws Exception {
86 PacketTestUtils.testDeserializeBadInput(deserializer);
87 }
88
89 @Test
90 public void testDeserializeTruncated() throws Exception {
91 //byte [] bits = pimHello.serialize();
92 //PacketTestUtils.testDeserializeTruncated(deserializer, bits);
93
94 byte [] bits = pimJoinPrune.serialize();
95 PacketTestUtils.testDeserializeTruncated(deserializer, bits);
96 }
97
98 @Test
99 public void testDeserializeHello() throws Exception {
100 byte [] data = pimHello.serialize();
101 PIM pim = deserializer.deserialize(data, 0, data.length);
102 assertTrue(pim.equals(pimHello));
103 }
104
105 @Test
106 public void testDeserializeJoinPrune() throws Exception {
107 byte [] data = pimJoinPrune.serialize();
108 PIM pim = deserializer.deserialize(data, 0, data.length);
109 assertTrue(pim.equals(pimJoinPrune));
110 }
111
112}