ONOS-2739 - OSPF Basic Packet Structures , which includes encoding and decoding
Change-Id: I33b48593ec38d28bdff215ce3a608a6d085a9077
diff --git a/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/ospfpacket/types/DdPacketTest.java b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/ospfpacket/types/DdPacketTest.java
new file mode 100644
index 0000000..6b7ead0
--- /dev/null
+++ b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/ospfpacket/types/DdPacketTest.java
@@ -0,0 +1,449 @@
+/*
+ * 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.types;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.Ip4Address;
+import org.onosproject.ospf.protocol.lsa.LsaHeader;
+import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
+import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader;
+import org.onosproject.ospf.protocol.util.OspfPacketType;
+
+import java.util.List;
+import java.util.Vector;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Unit test class for OspfRouterId.
+ */
+public class DdPacketTest {
+
+ private byte[] packet;
+ private byte[] result2;
+ private DdPacket ddPacket;
+ private Vector<LsaHeader> lsaHeaderList = new Vector<LsaHeader>();
+ private int result;
+ private long result1;
+ private OpaqueLsaHeader opqueHeader;
+ private OpaqueLsaHeader opqueHeader1;
+ private List<LsaHeader> header;
+ private OspfPacketHeader ospfPacketHeader;
+ private ChannelBuffer channelBuffer;
+ private LsaHeader lsaHeader;
+ private long result3;
+ private OspfPacketType ospfPacketType;
+
+ @Before
+ public void setUp() throws Exception {
+ ddPacket = new DdPacket();
+ ddPacket.setAuthType(1);
+ ddPacket.setOspftype(2);
+ ddPacket.setRouterId(Ip4Address.valueOf("10.226.165.164"));
+ ddPacket.setAreaId(Ip4Address.valueOf("10.226.165.100"));
+ ddPacket.setChecksum(201);
+ ddPacket.setAuthentication(2);
+ ddPacket.setOspfPacLength(48);
+ ddPacket.setOspfVer(2);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ ddPacket = null;
+ lsaHeaderList.clear();
+ opqueHeader = null;
+ opqueHeader1 = null;
+ header = null;
+ ospfPacketHeader = null;
+ channelBuffer = null;
+ lsaHeader = null;
+ ospfPacketType = null;
+ }
+
+ /**
+ * Tests isOpaqueCapable() getter method.
+ */
+ @Test
+ public void testIsOpaqueCapable() throws Exception {
+ ddPacket.setIsOpaqueCapable(true);
+ assertThat(ddPacket.isOpaqueCapable(), is(true));
+ }
+
+ /**
+ * Tests isOpaqueCapable() setter method.
+ */
+ @Test
+ public void testSetIsOpaqueCapable() throws Exception {
+ ddPacket.setIsOpaqueCapable(true);
+ assertThat(ddPacket.isOpaqueCapable(), is(true));
+ }
+
+ /**
+ * Tests ims() getter method.
+ */
+ @Test
+ public void testGetIms() throws Exception {
+ ddPacket.setIms(1);
+ result = ddPacket.ims();
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(1));
+ }
+
+ /**
+ * Tests ims() setter method.
+ */
+ @Test
+ public void testSetIms() throws Exception {
+ ddPacket.setIms(1);
+ result = ddPacket.ims();
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(1));
+ }
+
+ /**
+ * Tests isMaster() getter method.
+ */
+ @Test
+ public void testGetIsMaster() throws Exception {
+ ddPacket.setIsMaster(2);
+ result = ddPacket.isMaster();
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(2));
+ }
+
+ /**
+ * Tests isMaster() setter method.
+ */
+ @Test
+ public void testSetIsMaster() throws Exception {
+ ddPacket.setIsMaster(2);
+ result = ddPacket.isMaster();
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(2));
+ }
+
+ /**
+ * Tests isInitialize() getter method.
+ */
+ @Test
+ public void testGetIsInitialize() throws Exception {
+ ddPacket.setIsInitialize(3);
+ result = ddPacket.isInitialize();
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(3));
+ }
+
+ /**
+ * Tests isInitialize() setter method.
+ */
+ @Test
+ public void testSetIsInitialize() throws Exception {
+ ddPacket.setIsInitialize(3);
+ int result = ddPacket.isInitialize();
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(3));
+ }
+
+ /**
+ * Tests isMore() getter method.
+ */
+ @Test
+ public void testGetIsMore() throws Exception {
+ ddPacket.setIsMore(4);
+ result = ddPacket.isMore();
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(4));
+ }
+
+ /**
+ * Tests isMore() setter method.
+ */
+ @Test
+ public void testSetIsMore() throws Exception {
+ ddPacket.setIsMore(4);
+ int result = ddPacket.isMore();
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(4));
+ }
+
+ /**
+ * Tests imtu() getter method.
+ */
+ @Test
+ public void testGetImtu() throws Exception {
+ ddPacket.setImtu(5);
+ result = ddPacket.imtu();
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(5));
+ }
+
+ /**
+ * Tests imtu() setter method.
+ */
+ @Test
+ public void testSetImtu() throws Exception {
+ ddPacket.setImtu(5);
+ result = ddPacket.imtu();
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(5));
+ }
+
+ /**
+ * Tests options() getter method.
+ */
+ @Test
+ public void testGetOptions() throws Exception {
+ ddPacket.setOptions(2);
+ result = ddPacket.options();
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(2));
+ }
+
+ /**
+ * Tests options() setter method.
+ */
+ @Test
+ public void testSetOptions() throws Exception {
+ ddPacket.setOptions(2);
+ result = ddPacket.options();
+ Assert.assertNotNull(result);
+ Assert.assertEquals(2, result);
+ }
+
+ /**
+ * Tests sequenceNo() getter method.
+ */
+ @Test
+ public void testGetSequenceno() throws Exception {
+ ddPacket.setSequenceNo(2020);
+ result1 = ddPacket.sequenceNo();
+ assertThat(result1, is(notNullValue()));
+ assertThat(result1, is(2020L));
+ }
+
+ /**
+ * Tests sequenceNo() setter method.
+ */
+ @Test
+ public void testSetSequenceno() throws Exception {
+ ddPacket.setSequenceNo(2020);
+ result3 = ddPacket.sequenceNo();
+ assertThat(result3, is(notNullValue()));
+ assertThat(result3, is(2020L));
+ }
+
+ /**
+ * Tests getLsaHeaderList() getter method.
+ */
+ @Test
+ public void testGetLsaHeaderList() throws Exception {
+ ddPacket.addLsaHeader(createLsaHeader());
+ opqueHeader = new OpaqueLsaHeader();
+ opqueHeader.setLsType(9);
+ opqueHeader.setLsPacketLen(48);
+ opqueHeader.setLsCheckSum(10);
+ opqueHeader.setAge(4);
+ opqueHeader.setOpaqueId(9);
+ opqueHeader.setOpaqueType(9);
+ opqueHeader.setLsSequenceNo(250);
+ opqueHeader.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165"));
+ opqueHeader.setOptions(2);
+ ddPacket.setIsOpaqueCapable(true);
+ ddPacket.addLsaHeader(opqueHeader);
+ opqueHeader1 = new OpaqueLsaHeader();
+ opqueHeader1.setLsType(10);
+ opqueHeader1.setLsPacketLen(48);
+ opqueHeader1.setLsCheckSum(10);
+ opqueHeader1.setAge(4);
+ opqueHeader1.setOpaqueId(9);
+ opqueHeader1.setOpaqueType(9);
+ opqueHeader1.setLsSequenceNo(250);
+ opqueHeader1.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165"));
+ opqueHeader1.setOptions(66);
+ ddPacket.addLsaHeader(opqueHeader1);
+ header = ddPacket.getLsaHeaderList();
+ assertThat(header, is(notNullValue()));
+ }
+
+ /**
+ * Tests getLsaHeaderList() setter method.
+ */
+ @Test
+ public void testSetLsaHeaderList() throws Exception {
+ ddPacket.addLsaHeader(createLsaHeader());
+ opqueHeader = new OpaqueLsaHeader();
+ opqueHeader.setLsType(9);
+ opqueHeader.setLsPacketLen(48);
+ opqueHeader.setLsCheckSum(10);
+ opqueHeader.setAge(4);
+ opqueHeader.setOpaqueId(9);
+ opqueHeader.setOpaqueType(9);
+ opqueHeader.setLsSequenceNo(250);
+ opqueHeader.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165"));
+ opqueHeader.setOptions(66);
+ ddPacket.addLsaHeader(opqueHeader);
+ opqueHeader1 = new OpaqueLsaHeader();
+ opqueHeader1.setLsType(10);
+ opqueHeader1.setLsPacketLen(48);
+ opqueHeader1.setLsCheckSum(10);
+ opqueHeader1.setAge(4);
+ opqueHeader1.setOpaqueId(9);
+ opqueHeader1.setOpaqueType(9);
+ opqueHeader1.setLsSequenceNo(250);
+ opqueHeader1.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165"));
+ opqueHeader1.setOptions(2);
+ ddPacket.addLsaHeader(opqueHeader1);
+ header = ddPacket.getLsaHeaderList();
+ assertThat(header.contains(createLsaHeader()), is(true));
+ }
+
+ /**
+ * Tests addLsaHeader() method.
+ */
+ @Test
+ public void testAddLsaHeader() throws Exception {
+ ddPacket.addLsaHeader(createLsaHeader());
+ assertThat(ddPacket, is(notNullValue()));
+ }
+
+ /**
+ * Tests ospfMessageType() getter method.
+ */
+ @Test
+ public void testGetOspfMessageType() throws Exception {
+ ospfPacketType = ddPacket.ospfMessageType();
+ assertThat(ospfPacketType, is(notNullValue()));
+ assertThat(ospfPacketType, is(OspfPacketType.DD));
+ }
+
+ /**
+ * Tests readFrom() method.
+ */
+ @Test
+ public void testReadFrom() throws Exception {
+ ospfPacketHeader = new OspfPacketHeader();
+ ospfPacketHeader.setAreaId(Ip4Address.valueOf("1.1.1.1"));
+ ospfPacketHeader.setAuthentication(0);
+ ospfPacketHeader.setAuthType(0);
+ ospfPacketHeader.setChecksum(12345);
+ ospfPacketHeader.setDestinationIp(Ip4Address.valueOf("10.10.10.10"));
+ ospfPacketHeader.setOspfPacLength(56);
+ ospfPacketHeader.setOspftype(2);
+ ospfPacketHeader.setOspfVer(2);
+ ospfPacketHeader.setRouterId(Ip4Address.valueOf("2.2.2.2"));
+ ospfPacketHeader.setSourceIp(Ip4Address.valueOf("3.3.3.3"));
+ ddPacket.setIsOpaqueCapable(true);
+ ddPacket.setOptions(66);
+ ddPacket = new DdPacket(ospfPacketHeader);
+ packet = createByteForDdPacket();
+ channelBuffer = ChannelBuffers.copiedBuffer(packet);
+ ddPacket.readFrom(channelBuffer);
+ assertThat(ddPacket, is(notNullValue()));
+ assertThat(ddPacket.ospfMessageType(), is(OspfPacketType.DD));
+ }
+
+ /**
+ * Tests asBytes() method.
+ */
+ @Test
+ public void testAsBytes() throws Exception {
+ result2 = ddPacket.asBytes();
+ assertThat(result2, is(notNullValue()));
+ }
+
+ /**
+ * Tests getDdHeaderAsByteArray() method.
+ */
+ @Test
+ public void testGetDdHeaderAsByteArray() throws Exception {
+ opqueHeader = new OpaqueLsaHeader();
+ opqueHeader.setLsType(9);
+ opqueHeader.setLsPacketLen(48);
+ opqueHeader.setLsCheckSum(10);
+ opqueHeader.setAge(4);
+ opqueHeader.setOpaqueId(9);
+ opqueHeader.setOpaqueType(9);
+ opqueHeader.setLsSequenceNo(250);
+ opqueHeader.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165"));
+ opqueHeader.setOptions(66);
+ ddPacket.addLsaHeader(opqueHeader);
+ opqueHeader1 = new OpaqueLsaHeader();
+ opqueHeader1.setLsType(10);
+ opqueHeader1.setLsPacketLen(48);
+ opqueHeader1.setLsCheckSum(10);
+ opqueHeader1.setAge(4);
+ opqueHeader1.setOpaqueId(9);
+ opqueHeader1.setOpaqueType(9);
+ opqueHeader1.setLsSequenceNo(250);
+ opqueHeader1.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165"));
+ opqueHeader1.setOptions(2);
+ ddPacket.addLsaHeader(opqueHeader1);
+ result2 = ddPacket.getDdHeaderAsByteArray();
+ assertThat(result2, is(notNullValue()));
+ }
+
+ /**
+ * Tests getDdBodyAsByteArray() method.
+ */
+ @Test
+ public void testGetDdBodyAsByteArray() throws Exception {
+ lsaHeader = createLsaHeader();
+ ddPacket.addLsaHeader(lsaHeader);
+ result2 = ddPacket.getDdBodyAsByteArray();
+ assertThat(result2, is(notNullValue()));
+ }
+
+ /**
+ * Tests to string method.
+ */
+ @Test
+ public void testToString() throws Exception {
+ assertThat(ddPacket.toString(), is(notNullValue()));
+ }
+
+ /**
+ * Utility method used by junit methods.
+ */
+ private LsaHeader createLsaHeader() {
+ lsaHeader = new LsaHeader();
+ lsaHeader.setAge(10);
+ lsaHeader.setLinkStateId("10.226.165.164");
+ lsaHeader.setLsCheckSum(222);
+ lsaHeader.setLsPacketLen(48);
+ lsaHeader.setLsSequenceNo(2020);
+ lsaHeader.setLsType(2);
+ lsaHeader.setOptions(2);
+ lsaHeader.setAdvertisingRouter(Ip4Address.valueOf("10.226.165.165"));
+ return lsaHeader;
+ }
+
+ /**
+ * Utility method used by junit methods.
+ */
+ private byte[] createByteForDdPacket() {
+ byte[] ddPacket = {5, -36, 66, 1, 65, 119, -87, 126, 0, 23, 2, 1, 10, 10,
+ 10, 10, 10, 10, 10, 10, -128, 0, 0, 6, -69, 26, 0, 36};
+
+ return ddPacket;
+ }
+}
\ No newline at end of file
diff --git a/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/ospfpacket/types/HelloPacketTest.java b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/ospfpacket/types/HelloPacketTest.java
new file mode 100644
index 0000000..8d8b0f6
--- /dev/null
+++ b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/ospfpacket/types/HelloPacketTest.java
@@ -0,0 +1,325 @@
+/*
+ * 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.types;
+
+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 org.onlab.packet.Ip4Address;
+import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader;
+import org.onosproject.ospf.protocol.util.OspfPacketType;
+
+import java.util.Vector;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Unit test class for HelloPacket.
+ */
+public class HelloPacketTest {
+
+ private boolean result1;
+ private OspfPacketType ospfPacketType;
+ private OspfPacketHeader ospfPacketHeader;
+ private HelloPacket helloPacket;
+ private Vector<String> neighborAddress = new Vector();
+ private Ip4Address result;
+ private int result2;
+ private byte[] packet;
+ private ChannelBuffer channelBuffer;
+ private byte[] result3;
+
+ @Before
+ public void setUp() throws Exception {
+ helloPacket = new HelloPacket();
+ helloPacket.setAuthType(1);
+ helloPacket.setOspftype(2);
+ helloPacket.setRouterId(Ip4Address.valueOf("10.226.165.164"));
+ helloPacket.setAreaId(Ip4Address.valueOf("10.226.165.100"));
+ helloPacket.setChecksum(201);
+ helloPacket.setAuthentication(2);
+ helloPacket.setOspfPacLength(48);
+ helloPacket.setOspfVer(2);
+
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ helloPacket = null;
+ result = null;
+ ospfPacketType = null;
+ ospfPacketHeader = null;
+ packet = null;
+ channelBuffer = null;
+ result3 = null;
+ }
+
+ /**
+ * Tests networkMask() getter method.
+ */
+ @Test
+ public void testGetNetworkMask() throws Exception {
+ helloPacket.setNetworkMask(Ip4Address.valueOf("10.226.165.164"));
+ result = helloPacket.networkMask();
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(Ip4Address.valueOf("10.226.165.164")));
+ }
+
+ /**
+ * Tests networkMask() setter method.
+ */
+ @Test
+ public void testSetNetworkMask() throws Exception {
+ helloPacket.setNetworkMask(Ip4Address.valueOf("10.226.165.164"));
+ result = helloPacket.networkMask();
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(Ip4Address.valueOf("10.226.165.164")));
+ }
+
+ /**
+ * Tests bdr() setter method.
+ */
+ @Test
+ public void testSetBdr() throws Exception {
+ helloPacket.setBdr(Ip4Address.valueOf("10.226.165.166"));
+ result = helloPacket.bdr();
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(Ip4Address.valueOf("10.226.165.166")));
+ }
+
+ /**
+ * Tests dr() getter method.
+ */
+ @Test
+ public void testGetDr() throws Exception {
+ helloPacket.setDr(Ip4Address.valueOf("10.226.165.167"));
+ result = helloPacket.dr();
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(Ip4Address.valueOf("10.226.165.167")));
+ }
+
+ /**
+ * Tests dr() setter method.
+ */
+ @Test
+ public void testSetDr() throws Exception {
+ helloPacket.setDr(Ip4Address.valueOf("10.226.165.167"));
+ result = helloPacket.dr();
+ assertThat(result, is(notNullValue()));
+ assertThat(result, is(Ip4Address.valueOf("10.226.165.167")));
+ }
+
+ /**
+ * Tests addNeighbor() method.
+ */
+ @Test
+ public void testAddNeighbor() throws Exception {
+ helloPacket.addNeighbor(Ip4Address.valueOf("10.226.165.170"));
+ result1 = helloPacket.containsNeighbour(Ip4Address.valueOf("10.226.165.170"));
+ assertThat(result1, is(true));
+ }
+
+ /**
+ * Tests containsNeighbour() method.
+ */
+ @Test
+ public void testContainsNeighbour() throws Exception {
+ helloPacket.addNeighbor(Ip4Address.valueOf("10.226.165.200"));
+ result1 = helloPacket.containsNeighbour(Ip4Address.valueOf("10.226.165.200"));
+ assertThat(result1, is(true));
+ }
+
+
+ /**
+ * Tests options() getter method.
+ */
+ @Test
+ public void testGetOptions() throws Exception {
+ helloPacket.setOptions(10);
+ result2 = helloPacket.options();
+ assertThat(result2, is(notNullValue()));
+ assertThat(result2, is(10));
+ }
+
+ /**
+ * Tests options() setter method.
+ */
+ @Test
+ public void testSetOptions() throws Exception {
+ helloPacket.setOptions(11);
+ result2 = helloPacket.options();
+ assertThat(result2, is(notNullValue()));
+ assertThat(result2, is(11));
+ }
+
+ /**
+ * Tests routerPriority() getter method.
+ */
+ @Test
+ public void testGetRouterPriority() throws Exception {
+ helloPacket.setRouterPriority(1);
+ result2 = helloPacket.routerPriority();
+ assertThat(result2, is(notNullValue()));
+ assertThat(result2, is(1));
+ }
+
+ /**
+ * Tests routerPriority() setter method.
+ */
+ @Test
+ public void testSetRouterPriority() throws Exception {
+ helloPacket.setRouterPriority(2);
+ result2 = helloPacket.routerPriority();
+ assertThat(result2, is(notNullValue()));
+ assertThat(result2, is(2));
+ }
+
+ /**
+ * Tests helloInterval() getter method.
+ */
+ @Test
+ public void testGetHelloInterval() throws Exception {
+ helloPacket.setHelloInterval(10);
+ result2 = helloPacket.helloInterval();
+ assertThat(result2, is(notNullValue()));
+ assertThat(result2, is(10));
+ }
+
+ /**
+ * Tests helloInterval() setter method.
+ */
+ @Test
+ public void testSetHelloInterval() throws Exception {
+ helloPacket.setHelloInterval(10);
+ result2 = helloPacket.helloInterval();
+ assertThat(result2, is(notNullValue()));
+ assertThat(result2, is(10));
+ }
+
+ /**
+ * Tests routerDeadInterval() getter method.
+ */
+ @Test
+ public void testGetRouterDeadInterval() throws Exception {
+ helloPacket.setRouterDeadInterval(50);
+ result2 = helloPacket.routerDeadInterval();
+ assertThat(result2, is(notNullValue()));
+ assertThat(result2, is(50));
+ }
+
+ /**
+ * Tests routerDeadInterval() setter method.
+ */
+ @Test
+ public void testSetRouterDeadInterval() throws Exception {
+ helloPacket.setRouterDeadInterval(50);
+ result2 = helloPacket.routerDeadInterval();
+ assertThat(result2, is(notNullValue()));
+ assertThat(result2, is(50));
+ }
+
+ /**
+ * Tests ospfMessageType() getter method.
+ */
+ @Test
+ public void testGetOspfMessageType() throws Exception {
+ ospfPacketType = helloPacket.ospfMessageType();
+ assertThat(ospfPacketType, is(notNullValue()));
+ assertThat(ospfPacketType, is(OspfPacketType.HELLO));
+ }
+
+ /**
+ * Tests readFrom() method.
+ */
+ @Test
+ public void testReadFrom() throws Exception {
+ ospfPacketHeader = new OspfPacketHeader();
+ ospfPacketHeader.setAreaId(Ip4Address.valueOf("1.1.1.1"));
+ ospfPacketHeader.setAuthentication(0);
+ ospfPacketHeader.setAuthType(0);
+ ospfPacketHeader.setChecksum(12345);
+ ospfPacketHeader.setDestinationIp(Ip4Address.valueOf("10.10.10.10"));
+ ospfPacketHeader.setOspfPacLength(56);
+ ospfPacketHeader.setOspftype(1);
+ ospfPacketHeader.setOspfVer(2);
+ ospfPacketHeader.setRouterId(Ip4Address.valueOf("2.2.2.2"));
+ ospfPacketHeader.setSourceIp(Ip4Address.valueOf("3.3.3.3"));
+ packet = createByteForHelloPacket();
+ channelBuffer = ChannelBuffers.copiedBuffer(packet);
+ helloPacket.readFrom(channelBuffer);
+ assertThat(helloPacket, is(notNullValue()));
+ assertThat(helloPacket.ospfMessageType(), is(OspfPacketType.HELLO));
+ }
+
+ /**
+ * Tests asBytes() method.
+ */
+ @Test
+ public void testAsBytes() throws Exception {
+ result3 = helloPacket.asBytes();
+ assertThat(result3, is(notNullValue()));
+ }
+
+ /**
+ * Tests getHelloHeaderAsByteArray() method.
+ */
+ @Test
+ public void testGetHelloHeaderAsByteArray() throws Exception {
+ result3 = helloPacket.getHelloHeaderAsByteArray();
+ assertThat(result3, is(notNullValue()));
+ }
+
+ /**
+ * Tests getHelloBodyAsByteArray() method.
+ */
+ @Test
+ public void testGetHelloBodyAsByteArray() throws Exception {
+ neighborAddress.add("10.226.165.100");
+ result3 = helloPacket.getHelloBodyAsByteArray();
+ assertThat(result3, is(notNullValue()));
+ }
+
+ /**
+ * Tests getHelloBodyAsByteArray() method.
+ */
+ @Test
+ public void testReadHelloBody() throws Exception {
+ helloPacket.getHelloBodyAsByteArray();
+ assertThat(helloPacket, is(notNullValue()));
+ }
+
+ /**
+ * Tests to string method.
+ */
+ @Test
+ public void testToString() throws Exception {
+ assertThat(helloPacket.toString(), is(notNullValue()));
+ }
+
+ /**
+ * Utility method used by junit methods.
+ */
+ private byte[] createByteForHelloPacket() {
+ byte[] helloPacket = {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};
+
+ return helloPacket;
+ }
+}
\ No newline at end of file
diff --git a/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/ospfpacket/types/LsAcknowledgeTest.java b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/ospfpacket/types/LsAcknowledgeTest.java
new file mode 100644
index 0000000..dd5af91
--- /dev/null
+++ b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/ospfpacket/types/LsAcknowledgeTest.java
@@ -0,0 +1,208 @@
+/*
+ * 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.types;
+
+import org.hamcrest.MatcherAssert;
+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 org.onlab.packet.Ip4Address;
+import org.onosproject.ospf.protocol.lsa.LsaHeader;
+import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
+import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader;
+import org.onosproject.ospf.protocol.util.OspfPacketType;
+
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Unit test class for LsAck.
+ */
+public class LsAcknowledgeTest {
+
+ private LsaHeader lsaHeader;
+ private LsAcknowledge lsAck;
+ private OspfPacketType ospfPacketType;
+ private OspfPacketHeader ospfPacketHeader;
+ private byte[] result;
+ private ChannelBuffer channelBuffer;
+ private OpaqueLsaHeader opaqueLsaHeader;
+
+ @Before
+ public void setUp() throws Exception {
+ lsaHeader = new LsaHeader();
+ lsAck = new LsAcknowledge();
+ lsAck.setAuthType(1);
+ lsAck.setOspftype(5);
+ lsAck.setRouterId(Ip4Address.valueOf("10.226.165.164"));
+ lsAck.setAreaId(Ip4Address.valueOf("10.226.165.100"));
+ lsAck.setChecksum(201);
+ lsAck.setAuthentication(2);
+ lsAck.setOspfPacLength(48);
+ lsAck.setOspfVer(2);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ lsaHeader = null;
+ lsAck = null;
+ ospfPacketType = null;
+ ospfPacketHeader = null;
+ result = null;
+ channelBuffer = null;
+ opaqueLsaHeader = null;
+ }
+
+ /**
+ * Tests getLinkStateHeaders() getter method.
+ */
+ @Test
+ public void testGetLinkStateHeaders() throws Exception {
+ lsaHeader = createLsaHeader();
+ lsAck.addLinkStateHeader(lsaHeader);
+ lsAck.addLinkStateHeader(lsaHeader);
+ List headers = lsAck.getLinkStateHeaders();
+ assertThat(headers.size(), is(1));
+
+ }
+
+ /**
+ * Tests addLinkStateHeader() method.
+ */
+ @Test
+ public void testAddLinkStateHeader() throws Exception {
+ lsaHeader = createLsaHeader();
+ lsAck.addLinkStateHeader(lsaHeader);
+ lsAck.addLinkStateHeader(lsaHeader);
+ assertThat(lsAck, is(notNullValue()));
+ }
+
+
+ /**
+ * Tests ospfMessageType() getter method.
+ */
+ @Test
+ public void testGetOSPFMessageType() throws Exception {
+ ospfPacketType = lsAck.ospfMessageType();
+ assertThat(ospfPacketType, is(notNullValue()));
+ assertThat(ospfPacketType, is(OspfPacketType.LSAACK));
+ }
+
+ /**
+ * Tests ospfMessageType() getter method.
+ */
+ @Test
+ public void testGetOspfMessageType() throws Exception {
+ ospfPacketType = lsAck.ospfMessageType();
+ assertThat(ospfPacketType, is(notNullValue()));
+ assertThat(ospfPacketType, is(OspfPacketType.LSAACK));
+ }
+
+ /**
+ * Tests readFrom() method.
+ */
+ @Test
+ public void testReadFrom() throws Exception {
+ ospfPacketHeader = new OspfPacketHeader();
+ ospfPacketHeader.setAreaId(Ip4Address.valueOf("1.1.1.1"));
+ ospfPacketHeader.setAuthentication(0);
+ ospfPacketHeader.setAuthType(0);
+ ospfPacketHeader.setChecksum(12345);
+ ospfPacketHeader.setDestinationIp(Ip4Address.valueOf("10.10.10.10"));
+ ospfPacketHeader.setOspfPacLength(56);
+ ospfPacketHeader.setOspftype(5);
+ ospfPacketHeader.setOspfVer(2);
+ ospfPacketHeader.setRouterId(Ip4Address.valueOf("2.2.2.2"));
+ ospfPacketHeader.setSourceIp(Ip4Address.valueOf("3.3.3.3"));
+ result = createByteForLSAck();
+ lsAck = new LsAcknowledge(ospfPacketHeader);
+ channelBuffer = ChannelBuffers.copiedBuffer(result);
+ lsAck.readFrom(channelBuffer);
+ assertThat(lsAck, is(notNullValue()));
+ assertThat(lsAck.ospfMessageType(), is(OspfPacketType.LSAACK));
+ }
+
+ /**
+ * Tests asBytes() method.
+ */
+ @Test
+ public void testAsBytes() throws Exception {
+ result = lsAck.asBytes();
+ assertThat(result, is(notNullValue()));
+ }
+
+ /**
+ * Tests getLsAckAsByteArray() method.
+ */
+ @Test
+ public void testGetLsAckAsByteArray() throws Exception {
+ result = lsAck.getLsAckAsByteArray();
+ assertThat(result, is(notNullValue()));
+ }
+
+ /**
+ * Tests getLsAckBodyAsByteArray() method.
+ */
+ @Test
+ public void testGetLsAckBodyAsByteArray() throws Exception {
+ lsaHeader = createLsaHeader();
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ lsAck.addLinkStateHeader(lsaHeader);
+ lsAck.addLinkStateHeader(opaqueLsaHeader);
+ result = lsAck.getLsAckBodyAsByteArray();
+ assertThat(result, is(notNullValue()));
+ }
+
+ /**
+ * Tests to string method.
+ */
+ @Test
+ public void testToString() throws Exception {
+ MatcherAssert.assertThat(lsAck.toString(), is(notNullValue()));
+ }
+
+ /**
+ * Utility method used by junit methods.
+ */
+ private LsaHeader createLsaHeader() {
+ lsaHeader = new LsaHeader();
+ lsaHeader.setAge(10);
+ lsaHeader.setLinkStateId("10.226.165.164");
+ lsaHeader.setLsCheckSum(222);
+ lsaHeader.setLsPacketLen(48);
+ lsaHeader.setLsSequenceNo(2020);
+ lsaHeader.setLsType(5);
+ lsaHeader.setOptions(2);
+ lsaHeader.setAdvertisingRouter(Ip4Address.valueOf("10.226.165.165"));
+ return lsaHeader;
+ }
+
+ /**
+ * Utility method used by junit methods.
+ */
+ private byte[] createByteForLSAck() {
+ byte[] lsAckPacket = {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};
+
+ return lsAckPacket;
+ }
+}
\ No newline at end of file
diff --git a/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/ospfpacket/types/LsRequestTest.java b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/ospfpacket/types/LsRequestTest.java
new file mode 100644
index 0000000..41c9c4f
--- /dev/null
+++ b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/ospfpacket/types/LsRequestTest.java
@@ -0,0 +1,182 @@
+/*
+ * 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.types;
+
+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 org.onlab.packet.Ip4Address;
+import org.onosproject.ospf.protocol.ospfpacket.OspfPacketHeader;
+import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket;
+import org.onosproject.ospf.protocol.util.OspfPacketType;
+
+import java.net.UnknownHostException;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Unit test class for LsRequest.
+ */
+public class LsRequestTest {
+
+ private LsRequest lsRequest;
+ private List<LsRequestPacket> result;
+ private OspfPacketType ospfMessageType;
+ private OspfPacketHeader ospfPacketHeader;
+ private byte[] result1;
+ private String result2;
+ private ChannelBuffer channelBuffer;
+ private LsRequestPacket lsRequestPacket;
+
+ @Before
+ public void setUp() throws Exception {
+ lsRequest = new LsRequest();
+ lsRequest.setAuthType(1);
+ lsRequest.setOspftype(3);
+ lsRequest.setRouterId(Ip4Address.valueOf("10.226.165.164"));
+ lsRequest.setAreaId(Ip4Address.valueOf("10.226.165.163"));
+ lsRequest.setChecksum(201);
+ lsRequest.setAuthentication(2);
+ lsRequest.setOspfPacLength(48);
+ lsRequest.setOspfVer(2);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ lsRequest = null;
+ result = null;
+ ospfMessageType = null;
+ ospfPacketHeader = null;
+ result1 = null;
+ channelBuffer = null;
+ lsRequestPacket = null;
+ }
+
+ /**
+ * Tests addLinkStateRequests() method.
+ */
+ @Test
+ public void testAddLinkStateRequests() throws Exception {
+ lsRequest.addLinkStateRequests(createLsRequestPacket());
+ result = lsRequest.getLinkStateRequests();
+ assertThat(result, is(notNullValue()));
+ assertThat(result.size(), is(1));
+ }
+
+ /**
+ * Tests getLinkStateRequests() method.
+ */
+ @Test
+ public void testGetLinkStateRequests() throws Exception {
+ lsRequest.addLinkStateRequests(createLsRequestPacket());
+ lsRequest.addLinkStateRequests(new LsRequestPacket());
+ result = lsRequest.getLinkStateRequests();
+ assertThat(result, is(notNullValue()));
+ assertThat(result.size(), is(2));
+ }
+
+ /**
+ * Tests ospfMessageType()getter method.
+ */
+ @Test
+ public void testGetOspfMessageType() throws Exception {
+ ospfMessageType = lsRequest.ospfMessageType();
+ assertThat(ospfMessageType, is(notNullValue()));
+ assertThat(ospfMessageType, is(OspfPacketType.LSREQUEST));
+ }
+
+ /**
+ * Tests readFrom() method.
+ */
+ @Test
+ public void testReadFrom() throws Exception {
+ ospfPacketHeader = new OspfPacketHeader();
+ ospfPacketHeader.setAreaId(Ip4Address.valueOf("1.1.1.1"));
+ ospfPacketHeader.setAuthentication(0);
+ ospfPacketHeader.setAuthType(0);
+ ospfPacketHeader.setChecksum(12345);
+ ospfPacketHeader.setDestinationIp(Ip4Address.valueOf("10.10.10.10"));
+ ospfPacketHeader.setOspfPacLength(56);
+ ospfPacketHeader.setOspftype(3);
+ ospfPacketHeader.setOspfVer(2);
+ ospfPacketHeader.setRouterId(Ip4Address.valueOf("2.2.2.2"));
+ ospfPacketHeader.setSourceIp(Ip4Address.valueOf("3.3.3.3"));
+ lsRequest = new LsRequest(ospfPacketHeader);
+ result1 = createByteLsReqestPacket();
+ channelBuffer = ChannelBuffers.copiedBuffer(result1);
+ lsRequest.readFrom(channelBuffer);
+ assertThat(lsRequest, is(notNullValue()));
+ assertThat(lsRequest.ospfMessageType(), is(OspfPacketType.LSREQUEST));
+ }
+
+ /**
+ * Tests asBytes() method.
+ */
+ @Test
+ public void testAsBytes() throws Exception {
+ result1 = lsRequest.asBytes();
+ assertThat(result1, is(notNullValue()));
+ }
+
+ /**
+ * Tests getLsrHeaderAsByteArray() method.
+ */
+ @Test
+ public void testGetLsrHeaderAsByteArray() throws Exception {
+ result1 = lsRequest.getLsrHeaderAsByteArray();
+ assertThat(result1, is(notNullValue()));
+ }
+
+ /**
+ * Tests getLsrBodyAsByteArray() method.
+ */
+ @Test
+ public void testGetLsrBodyAsByteArray() throws Exception {
+ lsRequest.addLinkStateRequests(createLsRequestPacket());
+ lsRequest.addLinkStateRequests(new LsRequestPacket());
+ result1 = lsRequest.getLsrBodyAsByteArray();
+ assertThat(result1, is(notNullValue()));
+ }
+
+ /**
+ * Tests to string method.
+ */
+ @Test
+ public void testToString() throws Exception {
+ result2 = lsRequest.toString();
+ assertThat(result2, is(notNullValue()));
+ }
+
+ private LsRequestPacket createLsRequestPacket() throws UnknownHostException {
+ lsRequestPacket = new LsRequestPacket();
+ lsRequestPacket.setOwnRouterId("165");
+ lsRequestPacket.setLinkStateId("10.226.165.164");
+ lsRequestPacket.setLsType(2);
+ return lsRequestPacket;
+ }
+
+ private byte[] createByteLsReqestPacket() {
+ byte[] lsRequestPacket = {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};
+ return lsRequestPacket;
+ }
+}
\ No newline at end of file