ONOS-2739 - OSPF Basic Packet Structures , which includes encoding and decoding

Change-Id: I4bf4b7eb26a0e2b5006b41b24d67c7f21450b11b
diff --git a/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/lsa/LsaHeaderTest.java b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/lsa/LsaHeaderTest.java
new file mode 100644
index 0000000..2876deb
--- /dev/null
+++ b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/lsa/LsaHeaderTest.java
@@ -0,0 +1,308 @@
+/*
+ * 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.lsa;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.Ip4Address;
+import org.onosproject.ospf.controller.OspfLsaType;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.*;
+
+/**
+ * Unit test class for LsaHeader.
+ */
+public class LsaHeaderTest {
+
+    private LsaHeader lsaHeader;
+    private int result;
+    private Ip4Address result1;
+    private long result2;
+    private OspfLsaType ospflsaType;
+    private LsaHeader header;
+    private byte[] result3;
+    private LsaHeader lsaHeader1;
+    private String result4;
+
+    @Before
+    public void setUp() throws Exception {
+        lsaHeader = new LsaHeader();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        lsaHeader = null;
+        result1 = null;
+        ospflsaType = null;
+        header = null;
+        result3 = null;
+        lsaHeader1 = null;
+    }
+
+    /**
+     * Tests equals() method.
+     */
+    @Test
+    public void testEquals() throws Exception {
+        assertThat(lsaHeader.equals(new LsaHeader()), is(true));
+    }
+
+    /**
+     * Tests hashCode() method.
+     */
+    @Test
+    public void testHashCode() throws Exception {
+        result = lsaHeader.hashCode();
+        assertThat(result, is(notNullValue()));
+    }
+
+    /**
+     * Tests age() getter method.
+     */
+    @Test
+    public void testGetAge() throws Exception {
+        lsaHeader.setAge(10);
+        result = lsaHeader.age();
+        assertThat(result, is(10));
+    }
+
+    /**
+     * Tests age() setter method.
+     */
+    @Test
+    public void testSetAge() throws Exception {
+        lsaHeader.setAge(10);
+        result = lsaHeader.age();
+        assertThat(result, is(10));
+    }
+
+    /**
+     * Tests options() getter method.
+     */
+    @Test
+    public void testGetOptions() throws Exception {
+        lsaHeader.setOptions(2);
+        result = lsaHeader.options();
+        assertThat(result, is(2));
+    }
+
+    /**
+     * Tests options() setter method.
+     */
+    @Test
+    public void testSetOptions() throws Exception {
+        lsaHeader.setOptions(2);
+        result = lsaHeader.options();
+        assertThat(result, is(2));
+    }
+
+    /**
+     * Tests lsType() getter method.
+     */
+    @Test
+    public void testGetLsType() throws Exception {
+        lsaHeader.setLsType(1);
+        result = lsaHeader.lsType();
+        assertThat(result, is(1));
+    }
+
+    /**
+     * Tests lsType() setter method.
+     */
+    @Test
+    public void testSetLsType() throws Exception {
+        lsaHeader.setLsType(1);
+        result = lsaHeader.lsType();
+        assertThat(result, is(1));
+    }
+
+    /**
+     * Tests linkStateId() getter method.
+     */
+    @Test
+    public void testGetLinkStateId() throws Exception {
+        lsaHeader.setLinkStateId("10.226.165.164");
+        result4 = lsaHeader.linkStateId();
+        assertThat(result4, is("10.226.165.164"));
+    }
+
+    /**
+     * Tests linkStateId() setter method.
+     */
+    @Test
+    public void testSetLinkStateId() throws Exception {
+        lsaHeader.setLinkStateId("10.226.165.164");
+        result4 = lsaHeader.linkStateId();
+        assertThat(result4, is("10.226.165.164"));
+    }
+
+    /**
+     * Tests advertisingRouter() setter method.
+     */
+    @Test
+    public void testGetAdvertisingRouter() throws Exception {
+        lsaHeader.setAdvertisingRouter(Ip4Address.valueOf("10.226.165.164"));
+        result1 = lsaHeader.advertisingRouter();
+        assertThat(result1, is(Ip4Address.valueOf("10.226.165.164")));
+    }
+
+    /**
+     * Tests advertisingRouter() setter method.
+     */
+    @Test
+    public void testSetAdvertisingRouter() throws Exception {
+        lsaHeader.setAdvertisingRouter(Ip4Address.valueOf("10.226.165.164"));
+        result1 = lsaHeader.advertisingRouter();
+        assertThat(result1, is(Ip4Address.valueOf("10.226.165.164")));
+    }
+
+    /**
+     * Tests lsSequenceNo() getter method.
+     */
+    @Test
+    public void testGetLsSequenceNo() throws Exception {
+        lsaHeader.setLsSequenceNo(222);
+        result2 = lsaHeader.lsSequenceNo();
+        assertThat(result2, is(222L));
+    }
+
+    /**
+     * Tests lsSequenceNo() setter method.
+     */
+    @Test
+    public void testSetLsSequenceNo() throws Exception {
+        lsaHeader.setLsSequenceNo(222);
+        result2 = lsaHeader.lsSequenceNo();
+        assertThat(result2, is(222L));
+    }
+
+    /**
+     * Tests lsCheckSum() getter method.
+     */
+    @Test
+    public void testGetLsChecksum() throws Exception {
+        lsaHeader.setLsCheckSum(2);
+        result = lsaHeader.lsCheckSum();
+        assertThat(result, is(2));
+    }
+
+    /**
+     * Tests lsCheckSum() setter method.
+     */
+    @Test
+    public void testSetLsChecksum() throws Exception {
+        lsaHeader.setLsCheckSum(2);
+        result = lsaHeader.lsCheckSum();
+        assertThat(result, is(2));
+    }
+
+    /**
+     * Tests lsPacketLen() getter method.
+     */
+    @Test
+    public void testGetLsPacketLen() throws Exception {
+        lsaHeader.setLsPacketLen(48);
+        result = lsaHeader.lsPacketLen();
+        assertThat(result, is(48));
+    }
+
+    /**
+     * Tests lsPacketLen() getter method.
+     */
+    @Test
+    public void testSetLsPacketLen() throws Exception {
+        lsaHeader.setLsPacketLen(48);
+        result = lsaHeader.lsPacketLen();
+        assertThat(result, is(48));
+    }
+
+    /**
+     * Tests getOspfLsaType() getter method.
+     */
+    @Test
+    public void testGetOspfLsaType() throws Exception {
+        lsaHeader.setLsType(1);
+        ospflsaType = lsaHeader.getOspfLsaType();
+        assertThat(ospflsaType, is(notNullValue()));
+        assertThat(ospflsaType, is(OspfLsaType.ROUTER));
+        lsaHeader.setLsType(2);
+        ospflsaType = lsaHeader.getOspfLsaType();
+        assertThat(ospflsaType, is(notNullValue()));
+        assertThat(ospflsaType, is(OspfLsaType.NETWORK));
+        lsaHeader.setLsType(3);
+        ospflsaType = lsaHeader.getOspfLsaType();
+        assertThat(ospflsaType, is(notNullValue()));
+        assertThat(ospflsaType, is(OspfLsaType.SUMMARY));
+        lsaHeader.setLsType(4);
+        ospflsaType = lsaHeader.getOspfLsaType();
+        assertThat(ospflsaType, is(notNullValue()));
+        assertThat(ospflsaType, is(OspfLsaType.ASBR_SUMMARY));
+        lsaHeader.setLsType(5);
+        ospflsaType = lsaHeader.getOspfLsaType();
+        assertThat(ospflsaType, is(notNullValue()));
+        assertThat(ospflsaType, is(OspfLsaType.EXTERNAL_LSA));
+        lsaHeader.setLsType(6);
+        ospflsaType = lsaHeader.getOspfLsaType();
+        assertThat(ospflsaType, is(notNullValue()));
+        assertThat(ospflsaType, is(OspfLsaType.UNDEFINED));
+    }
+
+    /**
+     * Tests lsaHeader() getter method.
+     */
+    @Test
+    public void testGetLsaHeader() throws Exception {
+        header = (LsaHeader) lsaHeader.lsaHeader();
+        assertThat(header, instanceOf(LsaHeader.class));
+    }
+
+    /**
+     * Tests getLsaHeaderAsByteArray() method.
+     */
+    @Test
+    public void testGetLsaHeaderAsByteArray() throws Exception {
+        result3 = lsaHeader.getLsaHeaderAsByteArray();
+        assertThat(result3, is(notNullValue()));
+    }
+
+    /**
+     * Tests to string method.
+     */
+    @Test
+    public void testToString() throws Exception {
+        assertThat(lsaHeader.toString(), is(notNullValue()));
+    }
+
+    /**
+     * Tests populateHeader() method.
+     */
+    @Test
+    public void testPopulateHeader() throws Exception {
+        lsaHeader1 = new LsaHeader();
+        lsaHeader1.setLsPacketLen(10);
+        lsaHeader1.setAdvertisingRouter(Ip4Address.valueOf("1.1.1.1"));
+        lsaHeader1.setOptions(2);
+        lsaHeader1.setAge(20);
+        lsaHeader1.setLsType(3);
+        lsaHeader1.setLinkStateId("2.2.2.2");
+        lsaHeader1.setLsCheckSum(1234);
+        lsaHeader1.setLsSequenceNo(456789);
+        lsaHeader.populateHeader(lsaHeader1);
+        assertThat(lsaHeader1, is(notNullValue()));
+    }
+}
\ No newline at end of file
diff --git a/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/lsa/OpaqueLsaHeaderTest.java b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/lsa/OpaqueLsaHeaderTest.java
new file mode 100644
index 0000000..cbf54ec
--- /dev/null
+++ b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/lsa/OpaqueLsaHeaderTest.java
@@ -0,0 +1,137 @@
+/*
+ * 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.lsa;
+
+import org.hamcrest.Matchers;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.Ip4Address;
+
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Unit test class for OpaqueLsaHeader.
+ */
+public class OpaqueLsaHeaderTest {
+
+    private OpaqueLsaHeader opaqueHeader;
+    private OpaqueLsaHeader opaqueLsaHeader1;
+    private int num;
+    private byte[] result;
+    private int result1;
+
+    @Before
+    public void setUp() throws Exception {
+        opaqueHeader = new OpaqueLsaHeader();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        opaqueHeader = null;
+        opaqueLsaHeader1 = null;
+        result = null;
+    }
+
+    /**
+     * Tests populateHeader() method.
+     */
+    @Test
+    public void testPopulateHeader() throws Exception {
+        opaqueLsaHeader1 = new OpaqueLsaHeader();
+        opaqueLsaHeader1.setLsPacketLen(10);
+        opaqueLsaHeader1.setAdvertisingRouter(Ip4Address.valueOf("1.1.1.1"));
+        opaqueLsaHeader1.setOptions(2);
+        opaqueLsaHeader1.setAge(20);
+        opaqueLsaHeader1.setLsType(3);
+        opaqueLsaHeader1.setOpaqueId(1);
+        opaqueLsaHeader1.setOpaqueType(3);
+        opaqueLsaHeader1.setLsCheckSum(1234);
+        opaqueLsaHeader1.setLsSequenceNo(456789);
+        opaqueLsaHeader1.populateHeader(opaqueLsaHeader1);
+        assertThat(opaqueLsaHeader1, is(notNullValue()));
+    }
+
+    /**
+     * Tests opaqueId() getter method.
+     */
+    @Test
+    public void testGetOpaqueId() throws Exception {
+        opaqueHeader.setOpaqueId(1);
+        num = opaqueHeader.opaqueId();
+        assertThat(num, is(1));
+    }
+
+    /**
+     * Tests opaqueId() setter method.
+     */
+    @Test
+    public void testSetOpaqueId() throws Exception {
+        opaqueHeader.setOpaqueId(1);
+        num = opaqueHeader.opaqueId();
+        assertThat(num, is(1));
+    }
+
+    /**
+     * Tests opaqueType() getter method.
+     */
+    @Test
+    public void testGetOpaqueType() throws Exception {
+        opaqueHeader.setOpaqueType(1);
+        num = opaqueHeader.opaqueType();
+        assertThat(num, is(1));
+    }
+
+    /**
+     * Tests opaqueType() setter method.
+     */
+    @Test
+    public void testSetOpaqueType() throws Exception {
+        opaqueHeader.setOpaqueType(1);
+        num = opaqueHeader.opaqueType();
+        assertThat(num, is(1));
+    }
+
+    /**
+     * Tests getOpaqueLsaHeaderAsByteArray() method.
+     */
+    @Test
+    public void testGetOpaqueLsaHeaderAsByteArray() throws Exception {
+        result = opaqueHeader.getOpaqueLsaHeaderAsByteArray();
+        assertThat(result, is(notNullValue()));
+    }
+
+    /**
+     * Tests to string method.
+     */
+    @Test
+    public void testToString() throws Exception {
+        assertThat(opaqueHeader.toString(), is(notNullValue()));
+    }
+
+    /**
+     * Tests hashCode() method.
+     */
+    @Test
+    public void testHashcode() throws Exception {
+
+        result1 = opaqueHeader.hashCode();
+        assertThat(result1, is(Matchers.notNullValue()));
+
+    }
+}
\ No newline at end of file
diff --git a/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/ospfpacket/OspfPacketHeaderTest.java b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/ospfpacket/OspfPacketHeaderTest.java
new file mode 100644
index 0000000..0acb1bf
--- /dev/null
+++ b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/ospfpacket/OspfPacketHeaderTest.java
@@ -0,0 +1,318 @@
+/*
+ * 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.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.Ip4Address;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Unit test class for OspfPacketHeader.
+ */
+public class OspfPacketHeaderTest {
+
+    private final byte[] packet = {0, 0, 0, 0};
+    private OspfPacketHeader ospfPacketHeader;
+    private ChannelBuffer channelBuffer;
+    private byte[] result2;
+    private int result;
+    private Ip4Address result1;
+
+    @Before
+    public void setUp() throws Exception {
+        ospfPacketHeader = new OspfPacketHeader();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        ospfPacketHeader = null;
+        ospfPacketHeader = null;
+        channelBuffer = null;
+        result2 = null;
+        result1 = null;
+    }
+
+    /**
+     * Tests sourceIp() getter method.
+     */
+    @Test
+    public void testGetSourceIP() throws Exception {
+        ospfPacketHeader.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
+        assertThat(ospfPacketHeader.sourceIp(), is(Ip4Address.valueOf("1.1.1.1")));
+    }
+
+    /**
+     * Tests sourceIp() setter method.
+     */
+    @Test
+    public void testSetSourceIP() throws Exception {
+        ospfPacketHeader.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
+        assertThat(result, is(notNullValue()));
+        assertThat(ospfPacketHeader.sourceIp(), is(Ip4Address.valueOf("1.1.1.1")));
+    }
+
+    /**
+     * Tests ospfMessageType() getter method.
+     */
+    @Test
+    public void testGetOspfMessageType() throws Exception {
+        assertThat(ospfPacketHeader.ospfMessageType(), nullValue());
+    }
+
+    /**
+     * Tests readFrom() method.
+     */
+    @Test
+    public void testReadFrom() throws Exception {
+        channelBuffer = ChannelBuffers.copiedBuffer(packet);
+        ospfPacketHeader.readFrom(channelBuffer);
+        assertThat(ospfPacketHeader, is(notNullValue()));
+    }
+
+    /**
+     * Tests asBytes() method.
+     */
+    @Test
+    public void testAsBytes() throws Exception {
+        result2 = ospfPacketHeader.asBytes();
+        assertThat(result2, is(notNullValue()));
+    }
+
+    /**
+     * Tests ospfVersion() getter method.
+     */
+    @Test
+    public void testGetOspfVer() throws Exception {
+        ospfPacketHeader.setOspfVer(2);
+        result = ospfPacketHeader.ospfVersion();
+        assertThat(result, is(notNullValue()));
+        assertThat(result, is(2));
+    }
+
+    /**
+     * Tests ospfVersion() setter method.
+     */
+    @Test
+    public void testSetOspfVer() throws Exception {
+        ospfPacketHeader.setOspfVer(2);
+        result = ospfPacketHeader.ospfVersion();
+        assertThat(result, is(notNullValue()));
+        assertThat(result, is(2));
+    }
+
+    /**
+     * Tests ospfType() getter method.
+     */
+    @Test
+    public void testGetOspfType() throws Exception {
+        ospfPacketHeader.setOspftype(3);
+        result = ospfPacketHeader.ospfType();
+        assertThat(result, is(notNullValue()));
+        assertThat(result, is(3));
+    }
+
+    /**
+     * Tests ospfType() setter method.
+     */
+    @Test
+    public void testSetOspfType() throws Exception {
+        ospfPacketHeader.setOspftype(3);
+        result = ospfPacketHeader.ospfType();
+        assertThat(result, is(notNullValue()));
+        assertThat(result, is(3));
+    }
+
+    /**
+     * Tests ospfPacLength() getter method.
+     */
+    @Test
+    public void testGetOspfPacLength() throws Exception {
+        ospfPacketHeader.setOspfPacLength(3);
+        result = ospfPacketHeader.ospfPacLength();
+        assertThat(result, is(notNullValue()));
+        assertThat(result, is(3));
+    }
+
+    /**
+     * Tests ospfPacLength() setter method.
+     */
+    @Test
+    public void testSetOspfPacLength() throws Exception {
+        ospfPacketHeader.setOspfPacLength(3);
+        int result = ospfPacketHeader.ospfPacLength();
+        assertThat(result, is(notNullValue()));
+        assertThat(result, is(3));
+    }
+
+    /**
+     * Tests routerId()getter method.
+     */
+    @Test
+    public void testGetRouterId() throws Exception {
+
+        ospfPacketHeader.setRouterId(Ip4Address.valueOf("1.1.1.1"));
+        result1 = ospfPacketHeader.routerId();
+        assertThat(result1, is(notNullValue()));
+        assertThat(result1, is(Ip4Address.valueOf("1.1.1.1")));
+
+    }
+
+    /**
+     * Tests routerId() setter method.
+     */
+    @Test
+    public void testSetRouterId() throws Exception {
+        ospfPacketHeader.setRouterId(Ip4Address.valueOf("1.1.1.1"));
+        result1 = ospfPacketHeader.routerId();
+        assertThat(result1, is(notNullValue()));
+        assertThat(result1, is(Ip4Address.valueOf("1.1.1.1")));
+    }
+
+    /**
+     * Tests areaId() getter method.
+     */
+    @Test
+    public void testGetAreaId() throws Exception {
+        ospfPacketHeader.setAreaId(Ip4Address.valueOf("1.1.1.1"));
+        result1 = ospfPacketHeader.areaId();
+        assertThat(result1, is(notNullValue()));
+        assertThat(result1, is(Ip4Address.valueOf("1.1.1.1")));
+    }
+
+    /**
+     * Tests areaId() setter method.
+     */
+    @Test
+    public void testSetAreaId() throws Exception {
+        ospfPacketHeader.setAreaId(Ip4Address.valueOf("1.1.1.1"));
+        result1 = ospfPacketHeader.areaId();
+        assertThat(result1, is(notNullValue()));
+        assertThat(result1, is(Ip4Address.valueOf("1.1.1.1")));
+    }
+
+    /**
+     * Tests checksum() getter method.
+     */
+    @Test
+    public void testGetChecksum() throws Exception {
+        ospfPacketHeader.setChecksum(3);
+        result = ospfPacketHeader.checksum();
+        assertThat(result, is(notNullValue()));
+        assertThat(result, is(3));
+    }
+
+    /**
+     * Tests checksum() setter method.
+     */
+    @Test
+    public void testSetChecksum() throws Exception {
+        ospfPacketHeader.setChecksum(3);
+        result = ospfPacketHeader.checksum();
+        assertThat(result, is(notNullValue()));
+        assertThat(result, is(3));
+    }
+
+    /**
+     * Tests authType() getter method.
+     */
+    @Test
+    public void testGetAutype() throws Exception {
+        ospfPacketHeader.setAuthType(3);
+        result = ospfPacketHeader.authType();
+        Assert.assertNotNull(result);
+        Assert.assertEquals(3, result);
+    }
+
+    /**
+     * Tests authType() setter method.
+     */
+    @Test
+    public void testSetAutype() throws Exception {
+        ospfPacketHeader.setAuthType(3);
+        result = ospfPacketHeader.authType();
+        assertThat(result, is(notNullValue()));
+        assertThat(result, is(3));
+    }
+
+    /**
+     * Tests authentication() getter method.
+     */
+    @Test
+    public void testGetAuthentication() throws Exception {
+        ospfPacketHeader.setAuthentication(3);
+        result = ospfPacketHeader.authentication();
+        assertThat(result, is(notNullValue()));
+        assertThat(result, is(3));
+    }
+
+    /**
+     * Tests authentication() setter method.
+     */
+    @Test
+    public void testSetAuthentication() throws Exception {
+        ospfPacketHeader.setAuthentication(3);
+        result = ospfPacketHeader.authentication();
+        assertThat(result, is(notNullValue()));
+        assertThat(result, is(3));
+    }
+
+    /**
+     * Tests destinationIp() getter method.
+     */
+    @Test
+    public void testGetDestinationIP() throws Exception {
+        ospfPacketHeader.setDestinationIp(Ip4Address.valueOf("1.1.1.1"));
+        result1 = ospfPacketHeader.destinationIp();
+        assertThat(result1, is(notNullValue()));
+        assertThat(result1, is(Ip4Address.valueOf("1.1.1.1")));
+    }
+
+    /**
+     * Tests destinationIp() setter method.
+     */
+    @Test
+    public void testSetDestinationIP() throws Exception {
+        ospfPacketHeader.setDestinationIp(Ip4Address.valueOf("1.1.1.1"));
+        result1 = ospfPacketHeader.destinationIp();
+        assertThat(result1, is(notNullValue()));
+        assertThat(result1, is(Ip4Address.valueOf("1.1.1.1")));
+    }
+
+    /**
+     * Tests to string method.
+     */
+    @Test
+    public void testToString() throws Exception {
+        assertThat(ospfPacketHeader.toString(), is(notNullValue()));
+    }
+
+    /**
+     * Tests populateHeader() method.
+     */
+    @Test
+    public void testPopulateHeader() throws Exception {
+        ospfPacketHeader.populateHeader(new OspfPacketHeader());
+        assertThat(ospfPacketHeader, is(notNullValue()));
+    }
+
+}
\ No newline at end of file
diff --git a/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/util/OspfUtilTest.java b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/util/OspfUtilTest.java
new file mode 100644
index 0000000..750a08d
--- /dev/null
+++ b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/util/OspfUtilTest.java
@@ -0,0 +1,317 @@
+/*
+ * 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.util;
+
+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 static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Unit test class for OspfUtil.
+ */
+public class OspfUtilTest {
+
+    private final int ospfChecksumPos1 = 12;
+    private final int ospfChecksumPos2 = 13;
+    private final int lsaChecksumPos1 = 16;
+    private final int lsaChecksumPos2 = 17;
+    private final int ospfLengthPos1 = 2;
+    private final int ospfLengthPos2 = 3;
+    private final int lsaLengthPos1 = 18;
+    private final int lsaLengthPos2 = 19;
+    private final byte[] input = {0, 2};
+    private final byte[] packet = {2, 1, 0, 52, -64, -88, 56, 1, -64, -88, 56, 1, 0, 100, 0, 100, 0, 0, 0, 0, 0, 0,
+            0, 0, -64, -88, 56, 1, 0, 10, 1, 1, 0, 0, 0, 40, -64, -88, 56, 1, -64, -88, 56, 1, -64, -88, 56, 1, -64,
+            -88, 56, 1};
+    private final byte[] rLsa = {14, 16, 2, 1, -64, -88, -86, 2, -64, -88, -86, 2, -128, 0, 0, 1, 74, -114, 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};
+    private final byte[] opaqueheader = {14, 16, 2, 1, -64, -88, -86, 2, -64, -88, -86, 2, -128, 0, 0, 1, 74, -114,
+            0, 48};
+    private int num;
+    private int result;
+    private int input2;
+    private long input4;
+    private ChannelBuffer channelBuffer;
+    private byte[] result1;
+    private LsaHeader lsaHeader;
+    private boolean result2;
+    private long result3;
+
+
+    @Before
+    public void setUp() throws Exception {
+
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        channelBuffer = null;
+        result1 = null;
+        lsaHeader = null;
+    }
+
+
+    /**
+     * Tests byteToInteger() method.
+     */
+    @Test
+    public void testByteToInteger() throws Exception {
+        result = OspfUtil.byteToInteger(input);
+        assertThat(result, is(notNullValue()));
+        assertThat(result, is(2));
+
+    }
+
+    /**
+     * Tests byteToLong() method.
+     */
+    @Test
+    public void testByteToLong() throws Exception {
+        result3 = OspfUtil.byteToLong(input);
+        assertThat(result3, is(notNullValue()));
+        assertThat(result3, is(2L));
+    }
+
+    /**
+     * Tests byteToInteger() method.
+     */
+    @Test
+    public void testByteToLong1() throws Exception {
+        result3 = OspfUtil.byteToLong(input);
+        assertThat(result3, is(notNullValue()));
+        assertThat(result3, is(2L));
+    }
+
+    /**
+     * Tests byteToInteger() method.
+     */
+    @Test
+    public void testByteToInteger1() throws Exception {
+        result = OspfUtil.byteToInteger(input);
+        assertThat(result, is(notNullValue()));
+        assertThat(result, is(2));
+    }
+
+    /**
+     * Tests to createRandomNumber() method.
+     */
+    @Test
+    public void testCreateRandomNumber() throws Exception {
+        num = OspfUtil.createRandomNumber();
+        assertThat(num, is(notNullValue()));
+    }
+
+    /**
+     * Tests readLsaHeader() method.
+     */
+    @Test
+    public void testReadLsaHeader2() throws Exception {
+        channelBuffer = ChannelBuffers.copiedBuffer(packet);
+        lsaHeader = OspfUtil.readLsaHeader(channelBuffer);
+        assertThat(lsaHeader, is(notNullValue()));
+    }
+
+    /**
+     * Tests to readLsaHeader method.
+     */
+    @Test
+    public void testReadLsaHeader1() throws Exception {
+        channelBuffer = ChannelBuffers.copiedBuffer(opaqueheader);
+        lsaHeader = OspfUtil.readLsaHeader(channelBuffer);
+        assertThat(lsaHeader, is(notNullValue()));
+    }
+
+    /**
+     * Tests convertToTwoBytes() method.
+     */
+    @Test
+    public void testConvertToTwoBytes() throws Exception {
+        input2 = 4;
+        result1 = OspfUtil.convertToTwoBytes(input2);
+        assertThat(result1.length, is(2));
+        input2 = 1000;
+        result1 = OspfUtil.convertToTwoBytes(input2);
+        assertThat(result1.length, is(2));
+    }
+
+    /**
+     * Tests convertToThreeBytes() method.
+     */
+    @Test
+    public void testConvertToThreeBytes() throws Exception {
+        input2 = 1000000;
+        result1 = OspfUtil.convertToThreeBytes(input2);
+        assertThat(result1.length, is(3));
+        input2 = 1000;
+        result1 = OspfUtil.convertToThreeBytes(input2);
+        assertThat(result1.length, is(3));
+        input2 = 1;
+        result1 = OspfUtil.convertToThreeBytes(input2);
+        assertThat(result1.length, is(3));
+    }
+
+    /**
+     * Tests convertToFourBytes() method.
+     */
+    @Test
+    public void testConvertToFourBytes() throws Exception {
+        input4 = 214748364110L;
+        result1 = OspfUtil.convertToFourBytes(input4);
+        assertThat(result1.length, is(4));
+        input4 = 1000000;
+        result1 = OspfUtil.convertToFourBytes(input4);
+        assertThat(result1.length, is(4));
+        input4 = 10000;
+        result1 = OspfUtil.convertToFourBytes(input4);
+        assertThat(result1.length, is(4));
+        input4 = 1;
+        result1 = OspfUtil.convertToFourBytes(input4);
+        assertThat(result1.length, is(4));
+
+    }
+
+    /**
+     * Tests convertToFourBytes() method.
+     */
+    @Test
+    public void testConvertToFourBytes1() throws Exception {
+        input4 = 2147483635;
+        result1 = OspfUtil.convertToFourBytes(this.input4);
+        assertThat(result1.length, is(4));
+        this.input4 = 1000000;
+        result1 = OspfUtil.convertToFourBytes(this.input4);
+        assertThat(result1.length, is(4));
+        this.input4 = 10000;
+        result1 = OspfUtil.convertToFourBytes(this.input4);
+        assertThat(result1.length, is(4));
+        this.input4 = 1;
+        result1 = OspfUtil.convertToFourBytes(this.input4);
+        assertThat(result1.length, is(4));
+
+    }
+
+    /**
+     * Tests addLengthAndCheckSum() method.
+     */
+    @Test
+    public void testAddLengthAndCheckSum() throws Exception {
+        result1 = OspfUtil.addLengthAndCheckSum(packet, ospfLengthPos1, ospfLengthPos2,
+                                                ospfChecksumPos1, ospfChecksumPos2);
+        assertThat(result1[ospfChecksumPos1], is(packet[ospfChecksumPos1]));
+        assertThat(result1[ospfChecksumPos2], is(packet[ospfChecksumPos2]));
+        assertThat(result1[ospfLengthPos1], is(packet[ospfLengthPos1]));
+        assertThat(result1[ospfLengthPos2], is(packet[ospfLengthPos2]));
+    }
+
+    /**
+     * Tests addMetadata() method.
+     */
+    @Test
+    public void testAddMetadata() throws Exception {
+        result1 = OspfUtil.addMetadata(packet, 123, Ip4Address.valueOf("1.1.1.1"));
+        assertThat(result1, is(notNullValue()));
+    }
+
+    /**
+     * Tests addLengthAndCheckSum() method.
+     */
+    @Test
+    public void testAddLsaLengthAndCheckSum() throws Exception {
+        result1 = OspfUtil.addLengthAndCheckSum(rLsa, lsaLengthPos1, lsaLengthPos2,
+                                                lsaChecksumPos1, lsaChecksumPos2);
+        assertThat(result1[lsaLengthPos1], is(rLsa[lsaLengthPos1]));
+        assertThat(result1[lsaLengthPos2], is(rLsa[lsaLengthPos2]));
+        assertThat(result1[lsaChecksumPos1], is(rLsa[lsaChecksumPos1]));
+        assertThat(result1[lsaChecksumPos2], is(rLsa[lsaChecksumPos2]));
+    }
+
+    /**
+     * Tests addMetadata() method.
+     */
+    @Test
+    public void testAddMetaData() throws Exception {
+        result1 = OspfUtil.addMetadata(packet, 1, Ip4Address.valueOf("2.2.2.2"));
+        assertThat(result1, is(notNullValue()));
+    }
+
+    /**
+     * Tests sameNetwork() method.
+     */
+    @Test
+    public void testSameNetwork() throws Exception {
+        result2 = OspfUtil.sameNetwork(Ip4Address.valueOf("10.10.10.10"), Ip4Address.valueOf("10.10.10.11"),
+                                       Ip4Address.valueOf("255.255.255.255"));
+        assertThat(result2, is(false));
+        result2 = OspfUtil.sameNetwork(Ip4Address.valueOf("10.10.10.10"), Ip4Address.valueOf("10.10.10.10"),
+                                       Ip4Address.valueOf("255.255.255.255"));
+        assertThat(result2, is(true));
+    }
+
+    /**
+     * Tests isOpaqueEnabled() method.
+     */
+    @Test
+    public void testIsOpaqueEnabled() throws Exception {
+        result2 = OspfUtil.isOpaqueEnabled(2);
+        assertThat(result2, is(false));
+    }
+
+    /**
+     * Tests sameNetwork() method.
+     */
+    @Test
+    public void testisIsOpaqueEnabled() throws Exception {
+        result2 = OspfUtil.isOpaqueEnabled(2);
+        assertThat(result2, is(false));
+    }
+
+    /**
+     * Tests readLsaHeader() method.
+     */
+    @Test
+    public void testReadLsaHeader() throws Exception {
+        byte[] header = {0, 10, 2, 1, 7, 7, 7, 7, 7, 7, 7, 7, -128, 0, 0, 2, 46, -126, 0,
+                48, 0, 0, 0, 2, 1, 1, 1, 1, 10, 10, 10, 7, 1, 0, 0, 10, 10, 10, 10, 0, -1, -1, -1,
+                0, 3, 0, 0, 10, 0, 10, 66, 10, 1, 0, 0, 1, 7, 7, 7, 7, -128, 0, 0, 1, -64, 79, 0,
+                116, 0, 1, 0, 4, 0, 0, 0, 0, 0, 2, 0, 84, 0, 1, 0, 1, 1, 0, 0, 0, 0, 2, 0, 4, 10,
+                10, 10, 0, 0, 5, 0, 4, 0, 0, 0, 0, 0, 6, 0, 4, 73, -104, -106, -128, 0, 7, 0, 4, 73
+                , -104, -106, -128, 0, 8, 0, 32, 73, -104, -106, -128, 73, -104, -106, -128, 73, -104, -106,
+                -128, 73, -104, -106, -128, 73, -104, -106, -128, 73, -104, -106, -128, 73, -104, -106, -128,
+                73, -104, -106, -128, 0, 9, 0, 4, 0, 0, 0, 0};
+        channelBuffer = ChannelBuffers.copiedBuffer(header);
+        lsaHeader = OspfUtil.readLsaHeader(channelBuffer);
+        assertThat(lsaHeader, is(notNullValue()));
+    }
+
+    /**
+     * Tests readLsaHeader() method.
+     */
+    @Test
+    public void testReadreadLsaHeader() throws Exception {
+        byte[] header = {0, 2, 2, 1, -64, -88, -86, 3, -64, -88, -86, 3, -128, 0, 0, 1, 58, -100, 0, 48};
+        channelBuffer = ChannelBuffers.copiedBuffer(header);
+        lsaHeader = OspfUtil.readLsaHeader(channelBuffer);
+        assertThat(lsaHeader, is(notNullValue()));
+    }
+}
\ No newline at end of file