ONOS-2739 - OSPF Basic Packet Structures , which includes encoding and decoding
Change-Id: Ifaaa4d3640c6a4fec4931db54a1f03100cc9d9e6
diff --git a/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/ospfpacket/OspfMessageReaderTest.java b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/ospfpacket/OspfMessageReaderTest.java
new file mode 100644
index 0000000..8b1d089
--- /dev/null
+++ b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/ospfpacket/OspfMessageReaderTest.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.ospf.protocol.ospfpacket;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Unit test class for OspfMessageReader.
+ */
+
+public class OspfMessageReaderTest {
+
+ private final byte[] packet1 = {1, 1, 1, 1, 2, 1, 0, 44, -64, -88, -86, 8,
+ 0, 0, 0, 1, 39, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0,
+ 10, 2, 1, 0, 0, 0, 40, -64, -88, -86, 8, 0, 0, 0, 0};
+ private final byte[] packet2 = {1, 1, 1, 1, 2, 2, 0, 52, -64, -88, -86, 8, 0,
+ 0, 0, 1, -96, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -36, 2, 7, 65, 119,
+ -87, 126, 0, 23, 2, 1, 10, 10, 10, 10, 10, 10, 10, 10, -128, 0, 0, 6,
+ -69, 26, 0, 36};
+ private final byte[] packet3 = {1, 1, 1, 1, 2, 3, 0, 36, -64, -88, -86, 3, 0,
+ 0, 0, 1, -67, -57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -64, -88,
+ -86, 8, -64, -88, -86, 8};
+ private final byte[] packet4 = {1, 1, 1, 1, 2, 4, 1, 36, -64, -88, -86, 3, 0,
+ 0, 0, 1, 54, 107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0,
+ 2, 2, 1, -64, -88, -86, 3, -64, -88, -86, 3, -128, 0
+ , 0, 1, 58, -100, 0, 48, 2, 0, 0, 2, -64, -88, -86
+ , 0, -1, -1, -1, 0, 3, 0, 0, 10, -64, -88, -86, 0,
+ -1, -1, -1, 0, 3, 0, 0, 10, 0, 3, 2, 5, 80, -44,
+ 16, 0, -64, -88, -86, 2, -128, 0, 0, 1, 42, 73, 0,
+ 36, -1, -1, -1, -1, -128, 0, 0, 20, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 3, 2, 5, -108, 121, -85, 0, -64, -88,
+ -86, 2, -128, 0, 0, 1, 52, -91, 0, 36, -1, -1, -1,
+ 0, -128, 0, 0, 20, -64, -88, -86, 1, 0, 0, 0, 0, 0,
+ 3, 2, 5, -64, -126, 120, 0, -64, -88, -86, 2, -128, 0,
+ 0, 1, -45, 25, 0, 36, -1, -1, -1, 0, -128, 0, 0, 20,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 5, -64, -88, 0, 0,
+ -64, -88, -86, 2, -128, 0, 0, 1, 55, 8, 0, 36, -1, -1
+ , -1, 0, -128, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 3, 2, 5, -64, -88, 1, 0, -64, -88, -86, 2, -128, 0, 0,
+ 1, 44, 18, 0, 36, -1, -1, -1, 0, -128, 0, 0, 20, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 3, 2, 5, -64, -88, -84, 0, -64,
+ -88, -86, 2, -128, 0, 0, 1, 51, 65, 0, 36, -1, -1, -1, 0,
+ -128, 0, 0, 20, -64, -88, -86, 10, 0, 0, 0, 0};
+ private final byte[] packet5 = {1, 1, 1, 1, 2, 5, 0, 44, -64, -88, -86, 8, 0, 0,
+ 0, 1, -30, -12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 16, 2, 1, -64, -88, -86,
+ 2, -64, -88, -86, 2, -128, 0, 0, 1, 74, -114, 0, 48};
+ private OspfMessageReader ospfMessageReader;
+ private ChannelBuffer channelBuffer;
+
+ @Before
+ public void setUp() throws Exception {
+ ospfMessageReader = new OspfMessageReader();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ ospfMessageReader = null;
+ channelBuffer = null;
+ }
+
+ /**
+ * Tests readFromBuffer() method.
+ */
+ @Test
+ public void testReadFromBuffer() throws Exception {
+ channelBuffer = ChannelBuffers.copiedBuffer(packet1);
+ ospfMessageReader.readFromBuffer(channelBuffer);
+
+ channelBuffer = ChannelBuffers.copiedBuffer(packet2);
+ ospfMessageReader.readFromBuffer(channelBuffer);
+
+ channelBuffer = ChannelBuffers.copiedBuffer(packet3);
+ ospfMessageReader.readFromBuffer(channelBuffer);
+
+ channelBuffer = ChannelBuffers.copiedBuffer(packet4);
+ ospfMessageReader.readFromBuffer(channelBuffer);
+
+ channelBuffer = ChannelBuffers.copiedBuffer(packet5);
+ ospfMessageReader.readFromBuffer(channelBuffer);
+ assertThat(ospfMessageReader, is(notNullValue()));
+
+ }
+}