ONOS-2740,ONOS-2741,from ONOS-3032 - to ONOS 3071 , OSPF Protocol Implementation Unit Tests
Change-Id: I7cb129186a99bbf3d20fd6731485e3d84905e939
diff --git a/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/area/ConfigurationTest.java b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/area/ConfigurationTest.java
new file mode 100755
index 0000000..6f078f1
--- /dev/null
+++ b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/area/ConfigurationTest.java
@@ -0,0 +1,103 @@
+/*
+ * 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.controller.area;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.ospf.controller.OspfProcess;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Unit test class for Configuration.
+ */
+public class ConfigurationTest {
+ private Configuration configuration;
+ private List<OspfProcess> ospfProcesses;
+ private List result;
+ private OspfProcessImpl ospfProcessImpl;
+
+ @Before
+ public void setUp() throws Exception {
+ configuration = new Configuration();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ configuration = null;
+ ospfProcessImpl = new OspfProcessImpl();
+ result = null;
+ ospfProcesses = null;
+ }
+
+ /**
+ * Tests getProcesses() getter method.
+ */
+ @Test
+ public void testGetOspfProcess() throws Exception {
+ ospfProcesses = new ArrayList();
+ ospfProcesses.add(ospfProcessImpl);
+ ospfProcesses.add(ospfProcessImpl);
+ configuration.setProcesses(ospfProcesses);
+ result = configuration.getProcesses();
+ assertThat(result.size(), is(2));
+ }
+
+ /**
+ * Tests setProcesses() setter method.
+ */
+ @Test
+ public void testSetOspfProcess() throws Exception {
+ ospfProcesses = new ArrayList();
+ ospfProcesses.add(ospfProcessImpl);
+ ospfProcesses.add(ospfProcessImpl);
+ configuration.setProcesses(ospfProcesses);
+ result = configuration.getProcesses();
+ assertThat(result.size(), is(2));
+ }
+
+ /**
+ * Tests getMethod() getter method.
+ */
+ @Test
+ public void testGetMethod() throws Exception {
+ configuration.setMethod("method");
+ assertThat(configuration.getMethod(), is("method"));
+ }
+
+ /**
+ * Tests setMethod() setter method.
+ */
+ @Test
+ public void testSetMethod() throws Exception {
+ configuration.setMethod("method");
+ assertThat(configuration.getMethod(), is("method"));
+ }
+
+ /**
+ * Tests to string method.
+ */
+ @Test
+ public void testToString() throws Exception {
+ assertThat(configuration.toString(), is(notNullValue()));
+ }
+}
\ No newline at end of file
diff --git a/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/area/OspfAreaAddressRangeImplTest.java b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/area/OspfAreaAddressRangeImplTest.java
new file mode 100755
index 0000000..6c58238
--- /dev/null
+++ b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/area/OspfAreaAddressRangeImplTest.java
@@ -0,0 +1,133 @@
+/*
+ * 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.controller.area;
+
+
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.Ip4Address;
+import org.onosproject.ospf.controller.OspfAreaAddressRange;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Unit test class for OspfAreaAddressRangeImpl.
+ */
+public class OspfAreaAddressRangeImplTest {
+
+ private OspfAreaAddressRange ospfAreaAddressRange;
+ private int result;
+ private String result1;
+
+ @Before
+ public void setUp() throws Exception {
+ ospfAreaAddressRange = new OspfAreaAddressRangeImpl();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ ospfAreaAddressRange = null;
+ }
+
+ /**
+ * Tests ipAddress() getter method.
+ */
+ @Test
+ public void testGetIpAddress() throws Exception {
+ ospfAreaAddressRange.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
+ assertThat(ospfAreaAddressRange.ipAddress(), is(Ip4Address.valueOf("1.1.1.1")));
+ }
+
+ /**
+ * Tests ipAddress() setter method.
+ */
+ @Test
+ public void testSetIpAddress() throws Exception {
+ ospfAreaAddressRange.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
+ assertThat(ospfAreaAddressRange.ipAddress(), is(Ip4Address.valueOf("1.1.1.1")));
+ }
+
+ /**
+ * Tests mask() getter method.
+ */
+ @Test
+ public void testGetMask() throws Exception {
+ ospfAreaAddressRange.setMask("1.1.1.1");
+ assertThat(ospfAreaAddressRange.mask(), is("1.1.1.1"));
+ }
+
+ /**
+ * Tests mask() setter method.
+ */
+ @Test
+ public void testSetMask() throws Exception {
+ ospfAreaAddressRange.setMask("1.1.1.1");
+ assertThat(ospfAreaAddressRange.mask(), is("1.1.1.1"));
+ }
+
+ /**
+ * Tests isAdvertise() getter method.
+ */
+ @Test
+ public void testIsAdvertise() throws Exception {
+ ospfAreaAddressRange.setAdvertise(true);
+ assertThat(ospfAreaAddressRange.isAdvertise(), is(true));
+ }
+
+ /**
+ * Tests isAdvertise() setter method.
+ */
+ @Test
+ public void testSetAdvertise() throws Exception {
+ ospfAreaAddressRange.setAdvertise(true);
+ assertThat(ospfAreaAddressRange.isAdvertise(), is(true));
+ }
+
+ /**
+ * Tests equals() method.
+ */
+ @Test
+ public void testEquals() throws Exception {
+ assertThat(ospfAreaAddressRange.equals(new OspfAreaAddressRangeImpl()), is(false));
+ }
+
+ /**
+ * Tests equals() method.
+ */
+ @Test
+ public void testEquals1() throws Exception {
+ assertThat(ospfAreaAddressRange.equals(EasyMock.createMock(OspfAreaAddressRange.class)), is(false));
+ }
+
+ @Test
+ public void testHashCode() throws Exception {
+ result = ospfAreaAddressRange.hashCode();
+ assertThat(result, is(notNullValue()));
+ }
+
+ /**
+ * Tests to string method.
+ */
+ @Test
+ public void testToString() throws Exception {
+ result1 = ospfAreaAddressRange.toString();
+ assertThat(result1, is(notNullValue()));
+ }
+}
\ No newline at end of file
diff --git a/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/area/OspfAreaImplTest.java b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/area/OspfAreaImplTest.java
new file mode 100755
index 0000000..f7b40fa
--- /dev/null
+++ b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/area/OspfAreaImplTest.java
@@ -0,0 +1,722 @@
+/*
+ * 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.controller.area;
+
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.Ip4Address;
+import org.onosproject.ospf.controller.OspfArea;
+import org.onosproject.ospf.controller.OspfAreaAddressRange;
+import org.onosproject.ospf.controller.OspfInterface;
+import org.onosproject.ospf.controller.OspfNbr;
+import org.onosproject.ospf.controller.OspfNeighborState;
+import org.onosproject.ospf.controller.TopologyForDeviceAndLink;
+import org.onosproject.ospf.controller.impl.Controller;
+import org.onosproject.ospf.controller.impl.OspfInterfaceChannelHandler;
+import org.onosproject.ospf.controller.impl.OspfNbrImpl;
+import org.onosproject.ospf.controller.impl.TopologyForDeviceAndLinkImpl;
+import org.onosproject.ospf.controller.lsdb.LsaWrapperImpl;
+import org.onosproject.ospf.protocol.lsa.LsaHeader;
+import org.onosproject.ospf.protocol.lsa.types.NetworkLsa;
+import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
+import org.onosproject.ospf.protocol.util.OspfInterfaceState;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.*;
+
+/**
+ * Unit test class for OspfAreaImpl.
+ */
+public class OspfAreaImplTest {
+
+ private OspfAreaImpl ospfArea;
+ private int result;
+ private OspfInterfaceImpl ospfInterface;
+ private HashMap<String, OspfNbr> ospfNbrList;
+ private List<OspfInterface> ospfInterfaces;
+ private OspfInterfaceImpl ospfInterface1;
+ private OspfInterfaceImpl ospfInterface2;
+ private OspfInterfaceImpl ospfInterface3;
+ private OspfInterfaceImpl ospfInterface4;
+ private OspfInterfaceImpl ospfInterface5;
+ private OspfInterfaceImpl ospfInterface6;
+ private NetworkLsa networkLsa;
+ private OspfNbrImpl ospfNbr;
+ private RouterLsa routerLsa;
+ private List<OspfAreaAddressRange> ospfAreaAddressRanges;
+ private LsaHeader lsaHeader;
+ private TopologyForDeviceAndLink topologyForDeviceAndLink;
+
+ @Before
+ public void setUp() throws Exception {
+ ospfArea = new OspfAreaImpl();
+ topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ ospfArea = null;
+ ospfInterface = null;
+ ospfNbrList = null;
+ ospfInterfaces = null;
+ ospfAreaAddressRanges = null;
+ lsaHeader = null;
+ routerLsa = null;
+ ospfNbr = null;
+ networkLsa = null;
+ ospfInterface1 = null;
+ ospfInterface2 = null;
+ ospfInterface3 = null;
+ ospfInterface4 = null;
+ ospfInterface5 = null;
+ ospfInterface6 = null;
+
+ }
+
+ /**
+ * Tests equals() method.
+ */
+ @Test
+ public void testEquals() throws Exception {
+ ospfArea = new OspfAreaImpl();
+ ospfInterface = new OspfInterfaceImpl();
+ ospfArea.setTransitCapability(true);
+ ospfArea.setExternalRoutingCapability(true);
+ ospfArea.setStubCost(100);
+ ospfArea.initializeDb();
+ ospfArea.setAddressRanges(ospfAreaAddressRanges);
+ assertThat(ospfArea.equals(ospfArea), is(true));
+ ospfArea = EasyMock.createMock(OspfAreaImpl.class);
+ assertThat(ospfArea.equals(ospfArea), is(true));
+ OspfArea ospfArea = new OspfAreaImpl();
+ assertThat(ospfArea.equals(ospfArea), is(true));
+ }
+
+ /**
+ * Tests hashCode() method.
+ */
+ @Test
+ public void testHashCode() throws Exception {
+ result = ospfArea.hashCode();
+ assertThat(result, is(notNullValue()));
+ }
+
+ /**
+ * Tests routerId() getter method.
+ */
+ @Test
+ public void testGetRouterId() throws Exception {
+ ospfArea.setRouterId(Ip4Address.valueOf("1.1.1.1"));
+ assertThat(ospfArea.routerId(), is(Ip4Address.valueOf("1.1.1.1")));
+ }
+
+ /**
+ * Tests routerId() setter method.
+ */
+ @Test
+ public void testSetRouterId() throws Exception {
+ ospfArea.setRouterId(Ip4Address.valueOf("1.1.1.1"));
+ assertThat(ospfArea.routerId(), is(Ip4Address.valueOf("1.1.1.1")));
+ }
+
+ /**
+ * Tests isOpaqueEnabled() getter method.
+ */
+ @Test
+ public void testSetisOpaqueEnabled() throws Exception {
+ ospfArea.setIsOpaqueEnabled(true);
+ assertThat(ospfArea.isOpaqueEnabled(), is(true));
+ }
+
+ /**
+ * Tests isOpaqueEnabled() setter method.
+ */
+ @Test
+ public void testIsOpaqueEnabled() throws Exception {
+ ospfArea.setIsOpaqueEnabled(true);
+ assertThat(ospfArea.isOpaqueEnabled(), is(true));
+ }
+
+ /**
+ * Tests initializeDb() method.
+ */
+ @Test
+ public void testInitializeDb() throws Exception {
+ ospfArea.initializeDb();
+ assertThat(ospfArea, is(notNullValue()));
+ }
+
+ /**
+ * Tests refreshArea() method.
+ */
+ @Test
+ public void testRefreshArea() throws Exception {
+
+ ospfInterface = new OspfInterfaceImpl();
+ ospfInterface.setState(OspfInterfaceState.DR);
+ ospfNbrList = new HashMap();
+ ospfNbrList.put("1.1.1.1", new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
+ Ip4Address.valueOf("1.1.1.1"),
+ Ip4Address.valueOf("2.2.2.2"), 2,
+ new OspfInterfaceChannelHandler(new Controller(),
+ new OspfAreaImpl(),
+ new OspfInterfaceImpl()),
+ topologyForDeviceAndLink));
+ ospfNbrList.put("2.2.2.2", new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
+ Ip4Address.valueOf("1.1.1.1"),
+ Ip4Address.valueOf("2.2.2.2"), 2,
+ new OspfInterfaceChannelHandler(new Controller(),
+ new OspfAreaImpl(),
+ new OspfInterfaceImpl())
+ , topologyForDeviceAndLink));
+ ospfNbrList.put("3.3.3.3", new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
+ Ip4Address.valueOf("1.1.1.1"),
+ Ip4Address.valueOf("2.2.2.2"), 2,
+ new OspfInterfaceChannelHandler(new Controller(),
+ new OspfAreaImpl(),
+ new OspfInterfaceImpl())
+ , topologyForDeviceAndLink));
+ ospfNbrList.put("4.4.4.4", new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
+ Ip4Address.valueOf("1.1.1.1"),
+ Ip4Address.valueOf("2.2.2.2"), 2,
+ new OspfInterfaceChannelHandler(new Controller(),
+ new OspfAreaImpl(),
+ new OspfInterfaceImpl())
+ , topologyForDeviceAndLink));
+
+ ospfInterface.setListOfNeighbors(ospfNbrList);
+ ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.10"));
+ ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
+ ospfInterfaces = new ArrayList();
+ ospfInterface1 = new OspfInterfaceImpl();
+ ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
+ ospfInterfaces.add(ospfInterface1);
+ ospfInterface2 = new OspfInterfaceImpl();
+ ospfInterface2.setIpAddress(Ip4Address.valueOf("2.2.2.2"));
+ ospfInterfaces.add(ospfInterface2);
+ ospfInterface3 = new OspfInterfaceImpl();
+ ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
+ ospfInterfaces.add(ospfInterface3);
+ ospfArea.setInterfacesLst(ospfInterfaces);
+ ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
+ networkLsa = ospfArea.buildNetworkLsa(Ip4Address.valueOf("1.1.1.1"),
+ Ip4Address.valueOf("255.255.255.255"));
+ ospfArea.refreshArea(ospfInterface);
+ assertThat(ospfNbrList.size(), is(4));
+ assertThat(networkLsa, is(notNullValue()));
+ assertThat(ospfArea, is(notNullValue()));
+ }
+
+ /**
+ * Tests buildNetworkLsa() method.
+ */
+ @Test
+ public void testBuildNetworkLsa() throws Exception {
+ ospfInterfaces = new ArrayList();
+ ospfInterface1 = new OspfInterfaceImpl();
+ ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
+ ospfInterfaces.add(ospfInterface1);
+ ospfInterface2 = new OspfInterfaceImpl();
+ ospfInterface2.setIpAddress(Ip4Address.valueOf("2.2.2.2"));
+ ospfInterfaces.add(ospfInterface2);
+ ospfInterface3 = new OspfInterfaceImpl();
+ ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
+ ospfInterfaces.add(ospfInterface3);
+ ospfArea.setInterfacesLst(ospfInterfaces);
+ ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
+ networkLsa = ospfArea.buildNetworkLsa(Ip4Address.valueOf("1.1.1.1"),
+ Ip4Address.valueOf("255.255.255.255"));
+ assertThat(ospfInterfaces.size(), is(3));
+ assertThat(networkLsa, is(notNullValue()));
+ assertThat(ospfArea, is(notNullValue()));
+ }
+
+ /**
+ * Tests buildNetworkLsa() method.
+ */
+ @Test
+ public void testBuildNetworkLsa1() throws Exception {
+ ospfInterfaces = new ArrayList();
+ ospfInterface1 = new OspfInterfaceImpl();
+ ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
+ ospfInterface1.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
+ ospfInterface1.setState(OspfInterfaceState.POINT2POINT);
+ ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
+ Ip4Address.valueOf("1.1.1.1"),
+ Ip4Address.valueOf("2.2.2.2"), 2,
+ new OspfInterfaceChannelHandler(new Controller(),
+ new OspfAreaImpl(),
+ new OspfInterfaceImpl())
+ , topologyForDeviceAndLink);
+ ospfNbr.setState(OspfNeighborState.FULL);
+ ospfInterface1.addNeighbouringRouter(ospfNbr);
+ ospfInterfaces.add(ospfInterface1);
+ ospfArea.setInterfacesLst(ospfInterfaces);
+ ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
+ networkLsa = ospfArea.buildNetworkLsa(Ip4Address.valueOf("1.1.1.1"),
+ Ip4Address.valueOf("255.255.255.255"));
+ assertThat(ospfInterfaces.size(), is(1));
+ assertThat(networkLsa, is(notNullValue()));
+ assertThat(ospfArea, is(notNullValue()));
+ }
+
+ /**
+ * Tests buildRouterLsa() method.
+ */
+ @Test
+ public void testBuildRouterLsa() throws Exception {
+ ospfNbrList = new HashMap();
+ ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
+ Ip4Address.valueOf("1.1.1.1"),
+ Ip4Address.valueOf("2.2.2.2"), 2,
+ new OspfInterfaceChannelHandler(new Controller(),
+ new OspfAreaImpl(),
+ new OspfInterfaceImpl())
+ , topologyForDeviceAndLink);
+ ospfNbr.setState(OspfNeighborState.FULL);
+ ospfInterfaces = new ArrayList();
+ ospfInterface1 = new OspfInterfaceImpl();
+ ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
+ ospfInterface1.setState(OspfInterfaceState.DOWN);
+ ospfInterface1.addNeighbouringRouter(ospfNbr);
+ ospfInterfaces.add(ospfInterface1);
+ ospfInterface2 = new OspfInterfaceImpl();
+ ospfInterface2.setState(OspfInterfaceState.LOOPBACK);
+ ospfInterface2.setIpAddress(Ip4Address.valueOf("2.2.2.2"));
+ ospfInterface2.addNeighbouringRouter(ospfNbr);
+ ospfInterfaces.add(ospfInterface2);
+ ospfInterface3 = new OspfInterfaceImpl();
+ ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
+ ospfInterface3.setState(OspfInterfaceState.POINT2POINT);
+ ospfInterface3.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
+ ospfInterface3.addNeighbouringRouter(ospfNbr);
+ ospfInterface3.setListOfNeighbors(ospfNbrList);
+ ospfInterfaces.add(ospfInterface3);
+ ospfInterface4 = new OspfInterfaceImpl();
+ ospfInterface4.setState(OspfInterfaceState.WAITING);
+ ospfInterface4.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
+ ospfInterface4.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
+ ospfInterfaces.add(ospfInterface4);
+ ospfInterface5 = new OspfInterfaceImpl();
+ ospfInterface5.setState(OspfInterfaceState.DR);
+ ospfInterface5.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
+ ospfInterfaces.add(ospfInterface5);
+ ospfInterface6 = new OspfInterfaceImpl();
+ ospfInterface6.setState(OspfInterfaceState.BDR);
+ ospfInterface6.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
+ ospfInterface6.setDr(Ip4Address.valueOf("3.3.3.3"));
+ ospfInterfaces.add(ospfInterface6);
+ ospfArea.setInterfacesLst(ospfInterfaces);
+ ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
+ assertThat(ospfInterfaces.size(), is(6));
+ routerLsa = ospfArea.buildRouterLsa(ospfInterface1);
+ assertThat(routerLsa, is(notNullValue()));
+ routerLsa = ospfArea.buildRouterLsa(ospfInterface2);
+ assertThat(routerLsa, is(notNullValue()));
+ routerLsa = ospfArea.buildRouterLsa(ospfInterface3);
+ assertThat(routerLsa, is(notNullValue()));
+ assertThat(ospfArea, is(notNullValue()));
+ }
+
+ /**
+ * Tests buildRouterLsa() method.
+ */
+ @Test
+ public void testBuildRouterLsa1() throws Exception {
+ ospfInterfaces = new ArrayList();
+ ospfInterface1 = new OspfInterfaceImpl();
+ ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
+ ospfInterface1.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
+ ospfInterface1.setState(OspfInterfaceState.POINT2POINT);
+ ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
+ Ip4Address.valueOf("1.1.1.1"),
+ Ip4Address.valueOf("2.2.2.2"), 2,
+ new OspfInterfaceChannelHandler(new Controller(),
+ new OspfAreaImpl(),
+ new OspfInterfaceImpl())
+ , topologyForDeviceAndLink);
+ ospfNbr.setState(OspfNeighborState.FULL);
+ ospfInterface1.addNeighbouringRouter(ospfNbr);
+ ospfInterfaces.add(ospfInterface1);
+ ospfArea.setInterfacesLst(ospfInterfaces);
+ ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
+ routerLsa = ospfArea.buildRouterLsa(ospfInterface1);
+ assertThat(routerLsa, is(notNullValue()));
+ }
+
+ /**
+ * Tests areaId() getter method.
+ */
+ @Test
+ public void testGetAreaId() throws Exception {
+ ospfArea.setAreaId(Ip4Address.valueOf("1.1.1.1"));
+ assertThat(ospfArea.areaId(), is(Ip4Address.valueOf("1.1.1.1")));
+ }
+
+ /**
+ * Tests areaId() setter method.
+ */
+ @Test
+ public void testSetAreaId() throws Exception {
+ ospfArea.setAreaId(Ip4Address.valueOf("1.1.1.1"));
+ assertThat(ospfArea.areaId(), is(Ip4Address.valueOf("1.1.1.1")));
+ }
+
+ /**
+ * Tests addressRanges() getter method.
+ */
+ @Test
+ public void testGetAddressRanges() throws Exception {
+ ospfAreaAddressRanges = new ArrayList();
+ ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
+ ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
+ ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
+ ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
+ ospfArea.setAddressRanges(ospfAreaAddressRanges);
+ assertThat(ospfArea.addressRanges().size(), is(4));
+ }
+
+ /**
+ * Tests addressRanges() setter method.
+ */
+ @Test
+ public void testSetAddressRanges() throws Exception {
+ ospfAreaAddressRanges = new ArrayList();
+ ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
+ ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
+ ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
+ ospfAreaAddressRanges.add(new OspfAreaAddressRangeImpl());
+ ospfArea.setAddressRanges(ospfAreaAddressRanges);
+ assertThat(ospfArea.addressRanges().size(), is(4));
+ }
+
+ /**
+ * Tests isTransitCapability() getter method.
+ */
+ @Test
+ public void testIsTransitCapability() throws Exception {
+ ospfArea.setTransitCapability(true);
+ assertThat(ospfArea.isTransitCapability(), is(true));
+ }
+
+ /**
+ * Tests isTransitCapability() setter method.
+ */
+ @Test
+ public void testSetTransitCapability() throws Exception {
+ ospfArea.setTransitCapability(true);
+ assertThat(ospfArea.isTransitCapability(), is(true));
+ }
+
+ /**
+ * Tests isExternalRoutingCapability() getter method.
+ */
+ @Test
+ public void testIsExternalRoutingCapability() throws Exception {
+ ospfArea.setExternalRoutingCapability(true);
+ assertThat(ospfArea.isExternalRoutingCapability(), is(true));
+ }
+
+ /**
+ * Tests isExternalRoutingCapability() setter method.
+ */
+ @Test
+ public void testSetExternalRoutingCapability() throws Exception {
+ ospfArea.setExternalRoutingCapability(true);
+ assertThat(ospfArea.isExternalRoutingCapability(), is(true));
+ }
+
+ /**
+ * Tests stubCost() getter method.
+ */
+ @Test
+ public void testGetStubCost() throws Exception {
+ ospfArea.setStubCost(100);
+ assertThat(ospfArea.stubCost(), is(100));
+ }
+
+ /**
+ * Tests stubCost() setter method.
+ */
+ @Test
+ public void testSetStubCost() throws Exception {
+ ospfArea.setStubCost(100);
+ assertThat(ospfArea.stubCost(), is(100));
+ }
+
+ /**
+ * Tests getInterfacesLst() getter method.
+ */
+ @Test
+ public void testGetInterfacesLst() throws Exception {
+ ospfInterfaces = new ArrayList();
+ ospfInterface1 = new OspfInterfaceImpl();
+ ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
+ ospfInterfaces.add(ospfInterface1);
+ ospfInterface2 = new OspfInterfaceImpl();
+ ospfInterface2.setIpAddress(Ip4Address.valueOf("2.2.2.2"));
+ ospfInterfaces.add(ospfInterface2);
+ ospfInterface3 = new OspfInterfaceImpl();
+ ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
+ ospfInterfaces.add(ospfInterface3);
+ ospfArea.setInterfacesLst(ospfInterfaces);
+ assertThat(ospfInterfaces.size(), is(3));
+ assertThat(ospfArea.getInterfacesLst(), is(notNullValue()));
+ }
+
+ /**
+ * Tests setInterfacesLst() setter method.
+ */
+ @Test
+ public void testSetInterfacesLst() throws Exception {
+ ospfInterfaces = new ArrayList();
+ ospfInterface1 = new OspfInterfaceImpl();
+ ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
+ ospfInterfaces.add(ospfInterface1);
+ ospfInterface2 = new OspfInterfaceImpl();
+ ospfInterface2.setIpAddress(Ip4Address.valueOf("2.2.2.2"));
+ ospfInterfaces.add(ospfInterface2);
+ ospfInterface3 = new OspfInterfaceImpl();
+ ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
+ ospfInterfaces.add(ospfInterface3);
+ ospfArea.setInterfacesLst(ospfInterfaces);
+ assertThat(ospfInterfaces.size(), is(3));
+ assertThat(ospfArea.getInterfacesLst(), is(notNullValue()));
+ }
+
+ /**
+ * Tests noNeighborInLsaExchangeProcess() method.
+ */
+ @Test
+ public void testNoNeighborInLsaExchangeProcess() throws Exception {
+ ospfInterfaces = new ArrayList();
+ ospfInterface1 = new OspfInterfaceImpl();
+ ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
+ ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
+ Ip4Address.valueOf("1.1.1.1"),
+ Ip4Address.valueOf("2.2.2.2"), 2,
+ new OspfInterfaceChannelHandler(new Controller(),
+ new OspfAreaImpl(),
+ new OspfInterfaceImpl())
+ , topologyForDeviceAndLink);
+ ospfNbr.setState(OspfNeighborState.EXCHANGE.EXCHANGE);
+ ospfInterface1.addNeighbouringRouter(ospfNbr);
+ ospfInterfaces.add(ospfInterface1);
+ ospfArea.setInterfacesLst(ospfInterfaces);
+ assertThat(ospfArea.noNeighborInLsaExchangeProcess(), is(false));
+ }
+
+ /**
+ * Tests getLsaHeaders() method.
+ */
+ @Test
+ public void testGetLsaHeaders() throws Exception {
+ assertThat(ospfArea.getLsaHeaders(true, true).size(), is(0));
+ }
+
+ /**
+ * Tests getLsa() method.
+ */
+ @Test
+ public void testGetLsa() throws Exception {
+ assertThat(ospfArea.getLsa(1, "1.1.1.1", "1.1.1.1"), is(nullValue()));
+ assertThat(ospfArea.getLsa(10, "1.1.1.1", "1.1.1.1"), is(nullValue()));
+ }
+
+ /**
+ * Tests lsaLookup() method.
+ */
+ @Test
+ public void testLsaLookup() throws Exception {
+ assertThat(ospfArea.lsaLookup(new RouterLsa()), is(nullValue()));
+ }
+
+ /**
+ * Tests isNewerOrSameLsa() method.
+ */
+ @Test
+ public void testIsNewerOrSameLsa() throws Exception {
+ assertThat(ospfArea.isNewerOrSameLsa(new RouterLsa(), new RouterLsa()), is("same"));
+ }
+
+ /**
+ * Tests addLsa() method.
+ */
+ @Test
+ public void testAddLsa() throws Exception {
+ ospfArea.addLsa(new RouterLsa(), new OspfInterfaceImpl());
+ assertThat(ospfArea, is(notNullValue()));
+ }
+
+ /**
+ * Tests addLsa() method.
+ */
+ @Test
+ public void testAddLsa1() throws Exception {
+ ospfArea.addLsa(new RouterLsa(), false, new OspfInterfaceImpl());
+ assertThat(ospfArea, is(notNullValue()));
+ }
+
+ /**
+ * Tests addLsaToMaxAgeBin() method.
+ */
+ @Test
+ public void testAddLsaToMaxAgeBin() throws Exception {
+ ospfArea.addLsaToMaxAgeBin("111", new LsaWrapperImpl());
+ assertThat(ospfArea, is(notNullValue()));
+ }
+
+ /**
+ * Tests setDbRouterSequenceNumber() method.
+ */
+ @Test
+ public void testSetDbRouterSequenceNumber() throws Exception {
+ ospfArea.setDbRouterSequenceNumber(123456);
+ assertThat(ospfArea, is(notNullValue()));
+ }
+
+ /**
+ * Tests deleteLsa() method.
+ */
+ @Test
+ public void testDeleteLsa() throws Exception {
+ ospfArea.deleteLsa(new LsaHeader());
+ assertThat(ospfArea, is(notNullValue()));
+ }
+
+ /**
+ * Tests removeLsaFromBin() method.
+ */
+ @Test
+ public void testRemoveLsaFromBin() throws Exception {
+ ospfArea.removeLsaFromBin(new LsaWrapperImpl());
+ assertThat(ospfArea, is(notNullValue()));
+ }
+
+ /**
+ * Tests to string method.
+ */
+ @Test
+ public void testToString() throws Exception {
+ assertThat(ospfArea.toString(), is(notNullValue()));
+ }
+
+ /**
+ * Tests getNeighborsInFullState() method.
+ */
+ @Test
+ public void testGetNeighborsinFullState() throws Exception {
+ ospfInterfaces = new ArrayList();
+ ospfInterface1 = new OspfInterfaceImpl();
+ ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
+ ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
+ Ip4Address.valueOf("1.1.1.1"),
+ Ip4Address.valueOf("2.2.2.2"), 2,
+ new OspfInterfaceChannelHandler(new Controller(),
+ new OspfAreaImpl(),
+ new OspfInterfaceImpl())
+ , topologyForDeviceAndLink);
+ ospfNbr.setState(OspfNeighborState.FULL);
+ ospfInterface1.addNeighbouringRouter(ospfNbr);
+ ospfInterfaces.add(ospfInterface1);
+ ospfArea.setInterfacesLst(ospfInterfaces);
+ assertThat(ospfArea.getNeighborsInFullState(ospfInterface1).size(), is(1));
+ }
+
+ /**
+ * Tests getLsaKey() method.
+ */
+ @Test
+ public void testGetLsaKey() throws Exception {
+ lsaHeader = new LsaHeader();
+ lsaHeader.setAdvertisingRouter(Ip4Address.valueOf("1.1.1.1"));
+ assertThat(ospfArea.getLsaKey(lsaHeader), is(notNullValue()));
+ }
+
+ /**
+ * Tests addToOtherNeighborLsaTxList() method.
+ */
+ @Test
+ public void testAddToOtherNeighborLsaTxList() throws Exception {
+ ospfInterfaces = new ArrayList();
+ ospfInterface1 = new OspfInterfaceImpl();
+ ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
+ ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(),
+ Ip4Address.valueOf("1.1.1.1"),
+ Ip4Address.valueOf("2.2.2.2"), 2,
+ new OspfInterfaceChannelHandler(new Controller(),
+ new OspfAreaImpl(),
+ new OspfInterfaceImpl())
+ , topologyForDeviceAndLink);
+ ospfNbr.setState(OspfNeighborState.FULL);
+ ospfInterface1.addNeighbouringRouter(ospfNbr);
+ ospfInterfaces.add(ospfInterface1);
+ ospfArea.setInterfacesLst(ospfInterfaces);
+ lsaHeader = new LsaHeader();
+ lsaHeader.setAdvertisingRouter(Ip4Address.valueOf("1.1.1.1"));
+ ospfArea.addToOtherNeighborLsaTxList(lsaHeader);
+ assertThat(ospfArea, is(notNullValue()));
+ }
+
+ /**
+ * Tests options() getter method.
+ */
+ @Test
+ public void testGetOptions() throws Exception {
+ ospfArea.setOptions(2);
+ assertThat(ospfArea.options(), is(2));
+ }
+
+ /**
+ * Tests options() setter method.
+ */
+ @Test
+ public void testSetOptions() throws Exception {
+ ospfArea.setOptions(2);
+ assertThat(ospfArea.options(), is(2));
+ }
+
+ /**
+ * Tests isOpaqueEnabled() method.
+ */
+ @Test
+ public void testGetOpaqueEnabledOptions() throws Exception {
+ ospfArea.setIsOpaqueEnabled(true);
+ assertThat(ospfArea.isOpaqueEnabled(), is(true));
+ }
+
+ /**
+ * Tests database() method.
+ */
+ @Test
+ public void testGetDatabase() throws Exception {
+ assertThat(ospfArea.database(), is(notNullValue()));
+ }
+
+ /**
+ * Tests opaqueEnabledOptions() method.
+ */
+ @Test
+ public void testOpaqueEnabledOptionsa() throws Exception {
+ assertThat(ospfArea.opaqueEnabledOptions(), is(66));
+ }
+}
\ No newline at end of file
diff --git a/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/lsdb/LsaBinImplTest.java b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/lsdb/LsaBinImplTest.java
new file mode 100755
index 0000000..90f572b
--- /dev/null
+++ b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/lsdb/LsaBinImplTest.java
@@ -0,0 +1,109 @@
+/*
+ * 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.controller.lsdb;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.ospf.controller.LsaWrapper;
+import org.onosproject.ospf.protocol.lsa.LsaHeader;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Unit test class for LsaBinImpl.
+ */
+public class LsaBinImplTest {
+ private LsaBinImpl lsaBin;
+ private LsaHeader ospflsa1;
+ private LsaWrapper lsaWrapper;
+
+
+ @Before
+ public void setUp() throws Exception {
+ ospflsa1 = new LsaHeader();
+ ospflsa1.setAge(20);
+ lsaBin = new LsaBinImpl(1);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ ospflsa1 = null;
+ lsaBin = null;
+ }
+
+ /**
+ * Tests binNumber() getter method.
+ */
+ @Test
+ public void testGetBinNumber() throws Exception {
+ lsaWrapper = new LsaWrapperImpl();
+ lsaBin.addOspfLsa("lsa1", lsaWrapper);
+ assertThat(lsaBin.binNumber(), is(1));
+ }
+
+ /**
+ * Tests addOspfLsa() method.
+ */
+ @Test
+ public void testAddOspfLsa() throws Exception {
+ LsaWrapper lsaWrapper = new LsaWrapperImpl();
+ lsaBin.addOspfLsa("lsa1", lsaWrapper);
+ assertThat(lsaBin, is(notNullValue()));
+ }
+
+ /**
+ * Tests ospfLsa() getter method.
+ */
+ @Test
+ public void testGetOspfLsa() throws Exception {
+ lsaWrapper = new LsaWrapperImpl();
+ lsaBin.addOspfLsa("lsa1", lsaWrapper);
+ assertThat(lsaBin, is(notNullValue()));
+ assertThat(lsaBin.ospfLsa("lsa1"), is(lsaWrapper));
+ }
+
+ /**
+ * Tests removeOspfLsa() method.
+ */
+ @Test
+ public void testRemoveOspfLsa() throws Exception {
+ lsaWrapper = new LsaWrapperImpl();
+ lsaBin.addOspfLsa("lsa1", lsaWrapper);
+ lsaBin.removeOspfLsa("lsa1", lsaWrapper);
+ assertThat(lsaBin, is(notNullValue()));
+ }
+
+ /**
+ * Tests listOfLsa() method.
+ */
+ @Test
+ public void testGetListOfLsa() throws Exception {
+ lsaWrapper = new LsaWrapperImpl();
+ lsaBin.addOspfLsa("lsa1", lsaWrapper);
+ assertThat(lsaBin.listOfLsa().size(), is(1));
+ }
+
+ /**
+ * Tests to string method.
+ */
+ @Test
+ public void testToString() throws Exception {
+ assertThat(lsaBin.toString(), is(notNullValue()));
+ }
+}
\ No newline at end of file
diff --git a/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/lsdb/LsaQueueConsumerTest.java b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/lsdb/LsaQueueConsumerTest.java
new file mode 100755
index 0000000..49fda9e
--- /dev/null
+++ b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/lsdb/LsaQueueConsumerTest.java
@@ -0,0 +1,177 @@
+/*
+ * 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.controller.lsdb;
+
+import org.easymock.EasyMock;
+import org.jboss.netty.channel.Channel;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.ospf.controller.LsaWrapper;
+import org.onosproject.ospf.controller.OspfArea;
+import org.onosproject.ospf.controller.OspfLsaType;
+import org.onosproject.ospf.controller.area.OspfAreaImpl;
+import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
+import org.onosproject.ospf.protocol.lsa.LsaHeader;
+import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
+import org.onosproject.ospf.protocol.util.OspfInterfaceState;
+
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Unit test class for LsaQueueConsumer.
+ */
+public class LsaQueueConsumerTest {
+ private LsaQueueConsumer lsaQueueConsumer;
+ private BlockingQueue<LsaWrapper> blockingQueue;
+ private Channel channel;
+ private LsaWrapperImpl lsaWrapper;
+ private OspfArea ospfArea;
+ private RouterLsa routerLsa;
+ private OspfInterfaceImpl ospfInterface;
+ private LsaHeader lsaHeader;
+ private LsdbAgeImpl lsdbAge;
+
+ @Before
+ public void setUp() throws Exception {
+ lsaQueueConsumer = EasyMock.createMock(LsaQueueConsumer.class);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ lsaQueueConsumer = null;
+ blockingQueue = null;
+ channel = null;
+ lsaWrapper = null;
+ lsdbAge = null;
+ lsaHeader = null;
+ ospfInterface = null;
+ ospfArea = null;
+ routerLsa = null;
+ }
+
+ /**
+ * Tests run() method.
+ */
+ @Test
+ public void testRun() throws Exception {
+ blockingQueue = new ArrayBlockingQueue(5);
+ channel = EasyMock.createMock(Channel.class);
+ ospfArea = new OspfAreaImpl();
+ lsaWrapper = new LsaWrapperImpl();
+ lsaWrapper.setLsaProcessing("verifyChecksum");
+ blockingQueue.add(lsaWrapper);
+ lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea);
+ lsaQueueConsumer.run();
+ assertThat(lsaQueueConsumer, is(notNullValue()));
+ }
+
+ /**
+ * Tests run() method.
+ */
+ @Test
+ public void testRun1() throws Exception {
+ blockingQueue = new ArrayBlockingQueue(5);
+ channel = EasyMock.createMock(Channel.class);
+ ospfArea = new OspfAreaImpl();
+ lsaWrapper = new LsaWrapperImpl();
+ routerLsa = new RouterLsa();
+ routerLsa.setLsType(1);
+ lsaWrapper.addLsa(OspfLsaType.ROUTER, routerLsa);
+ ospfInterface = new OspfInterfaceImpl();
+ ospfInterface.setState(OspfInterfaceState.DR);
+ lsaWrapper.setOspfInterface(ospfInterface);
+ lsaWrapper.setIsSelfOriginated(true);
+ lsaHeader = new LsaHeader();
+ lsaHeader.setLsType(1);
+ lsaWrapper.setLsaHeader(lsaHeader);
+ lsaWrapper.setLsaProcessing("refreshLsa");
+ lsaWrapper.setLsdbAge(new LsdbAgeImpl(new OspfAreaImpl()));
+ blockingQueue.add(lsaWrapper);
+ lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea);
+ lsaQueueConsumer.run();
+ assertThat(lsaQueueConsumer, is(notNullValue()));
+ }
+
+ @Test
+ public void testRun3() throws Exception {
+ blockingQueue = new ArrayBlockingQueue(5);
+ channel = EasyMock.createMock(Channel.class);
+ ospfArea = new OspfAreaImpl();
+ lsaWrapper = new LsaWrapperImpl();
+ routerLsa = new RouterLsa();
+ routerLsa.setLsType(2);
+ lsaWrapper.addLsa(OspfLsaType.NETWORK, routerLsa);
+ ospfInterface = new OspfInterfaceImpl();
+ ospfInterface.setState(OspfInterfaceState.BDR);
+ lsaWrapper.setOspfInterface(ospfInterface);
+ lsaWrapper.setIsSelfOriginated(true);
+ lsaHeader = new LsaHeader();
+ lsaHeader.setLsType(2);
+ lsaWrapper.setLsaHeader(lsaHeader);
+ lsaWrapper.setLsaProcessing("refreshLsa");
+ lsaWrapper.setLsdbAge(new LsdbAgeImpl(new OspfAreaImpl()));
+ blockingQueue.add(lsaWrapper);
+ lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea);
+ lsaQueueConsumer.run();
+ assertThat(lsaQueueConsumer, is(notNullValue()));
+ }
+
+ /**
+ * Tests run() method.
+ */
+ @Test
+ public void testRun5() throws Exception {
+ blockingQueue = new ArrayBlockingQueue(5);
+ channel = EasyMock.createMock(Channel.class);
+ ospfArea = new OspfAreaImpl();
+ lsaWrapper = new LsaWrapperImpl();
+ routerLsa = new RouterLsa();
+ routerLsa.setLsType(2);
+ lsaWrapper.addLsa(OspfLsaType.NETWORK, routerLsa);
+ ospfInterface = new OspfInterfaceImpl();
+ ospfInterface.setState(OspfInterfaceState.DR);
+ lsaWrapper.setOspfInterface(ospfInterface);
+ lsaWrapper.setIsSelfOriginated(true);
+ lsaHeader = new LsaHeader();
+ lsaHeader.setLsType(2);
+ lsaWrapper.setLsaHeader(lsaHeader);
+ lsaWrapper.setLsaProcessing("maxAgeLsa");
+ lsaWrapper.setLsdbAge(new LsdbAgeImpl(new OspfAreaImpl()));
+ blockingQueue.add(lsaWrapper);
+ lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea);
+ lsaQueueConsumer.run();
+ assertThat(lsaQueueConsumer, is(notNullValue()));
+ }
+
+ /**
+ * Tests setChannel() method.
+ */
+ @Test
+ public void testSetChannel() throws Exception {
+ channel = EasyMock.createMock(Channel.class);
+ lsdbAge = new LsdbAgeImpl(new OspfAreaImpl());
+ lsdbAge.startDbAging();
+ lsdbAge.setChannel(channel);
+ assertThat(lsaQueueConsumer, is(notNullValue()));
+ }
+
+}
\ No newline at end of file
diff --git a/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/lsdb/LsaWrapperImplTest.java b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/lsdb/LsaWrapperImplTest.java
new file mode 100755
index 0000000..b8d95c7
--- /dev/null
+++ b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/lsdb/LsaWrapperImplTest.java
@@ -0,0 +1,395 @@
+/*
+ * 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.controller.lsdb;
+
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.ospf.controller.OspfLsaType;
+import org.onosproject.ospf.controller.area.OspfAreaImpl;
+import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
+import org.onosproject.ospf.protocol.lsa.LsaHeader;
+import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Unit test class for LsaWrapperImpl.
+ */
+public class LsaWrapperImplTest {
+
+ private LsaWrapperImpl lsaWrapper;
+ private LsdbAgeImpl lsdbAge;
+ private LsaHeader header;
+ private OspfInterfaceImpl ospfInterfaceImpl;
+
+ @Before
+ public void setUp() throws Exception {
+ lsaWrapper = new LsaWrapperImpl();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ lsaWrapper = null;
+ header = null;
+ lsdbAge = null;
+ ospfInterfaceImpl = null;
+ }
+
+ /**
+ * Tests lsaType() getter method.
+ */
+ @Test
+ public void testGetLsaType() throws Exception {
+ lsaWrapper.setLsaType(OspfLsaType.ROUTER);
+ assertThat(lsaWrapper.lsaType(), is(OspfLsaType.ROUTER));
+ }
+
+ /**
+ * Tests lsaType() setter method.
+ */
+ @Test
+ public void testSetLsaType() throws Exception {
+ lsaWrapper.setLsaType(OspfLsaType.ROUTER);
+ assertThat(lsaWrapper.lsaType(), is(OspfLsaType.ROUTER));
+ }
+
+ /**
+ * Tests isSelfOriginated() getter method.
+ */
+ @Test
+ public void testIsSelfOriginated() throws Exception {
+ lsaWrapper.setIsSelfOriginated(true);
+ assertThat(lsaWrapper.isSelfOriginated(), is(true));
+ }
+
+ /**
+ * Tests isSelfOriginated() setter method.
+ */
+ @Test
+ public void testSetIsSelfOriginated() throws Exception {
+ lsaWrapper.setIsSelfOriginated(true);
+ assertThat(lsaWrapper.isSelfOriginated(), is(true));
+ }
+
+ /**
+ * Tests addLsa() method.
+ */
+ @Test
+ public void testAddLSA() throws Exception {
+ lsaWrapper.addLsa(OspfLsaType.ROUTER, new RouterLsa());
+ assertThat(lsaWrapper, is(notNullValue()));
+ }
+
+ /**
+ * Tests lsaAgeReceived() getter method.
+ */
+ @Test
+ public void testGetLsaAgeReceived() throws Exception {
+ lsaWrapper.setLsaAgeReceived(10);
+ assertThat(lsaWrapper.lsaAgeReceived(), is(10));
+ }
+
+ /**
+ * Tests lsaAgeReceived() setter method.
+ */
+ @Test
+ public void testSetLsaAgeReceived() throws Exception {
+ lsaWrapper.setLsaAgeReceived(10);
+ assertThat(lsaWrapper.lsaAgeReceived(), is(10));
+ }
+
+ /**
+ * Tests lsaHeader() getter method.
+ */
+ @Test
+ public void testGetLsaHeader() throws Exception {
+ lsdbAge = new LsdbAgeImpl(new OspfAreaImpl());
+ lsdbAge.ageLsaAndFlood();
+ lsaWrapper.setLsdbAge(lsdbAge);
+ header = new LsaHeader();
+ lsaWrapper.setLsaHeader(header);
+ assertThat(lsaWrapper.lsaHeader(), instanceOf(LsaHeader.class));
+ }
+
+ /**
+ * Tests lsaHeader() setter method.
+ */
+ @Test
+ public void testSetLsaHeader() throws Exception {
+ lsdbAge = new LsdbAgeImpl(new OspfAreaImpl());
+ lsdbAge.ageLsaAndFlood();
+ lsaWrapper.setLsdbAge(lsdbAge);
+ header = new LsaHeader();
+ lsaWrapper.setLsaHeader(header);
+ assertThat(lsaWrapper.lsaHeader(), instanceOf(LsaHeader.class));
+ }
+
+ /**
+ * Tests setOspfLsa() setter method.
+ */
+ @Test
+ public void testSetOspfLsa() throws Exception {
+ lsaWrapper.setOspfLsa(new RouterLsa());
+ assertThat(lsaWrapper, is(notNullValue()));
+ }
+
+ /**
+ * Tests noReTransmissionLists() getter method.
+ */
+ @Test
+ public void testGetNoReTransmissionLists() throws Exception {
+ lsaWrapper.setNoReTransmissionLists(10);
+ assertThat(lsaWrapper.noReTransmissionLists(), is(10));
+ }
+
+ /**
+ * Tests noReTransmissionLists() setter method.
+ */
+ @Test
+ public void testSetNoReTransmissionLists() throws Exception {
+ lsaWrapper.setNoReTransmissionLists(10);
+ assertThat(lsaWrapper.noReTransmissionLists(), is(10));
+ }
+
+ /**
+ * Tests isInAnAgeBin() getter method.
+ */
+ @Test
+ public void testIsInAnAgeBin() throws Exception {
+ lsaWrapper.setInAnAgeBin(true);
+ assertThat(lsaWrapper.isInAnAgeBin(), is(true));
+ }
+
+ /**
+ * Tests isInAnAgeBin() setter method.
+ */
+ @Test
+ public void testSetInAnAgeBin() throws Exception {
+ lsaWrapper.setInAnAgeBin(true);
+ assertThat(lsaWrapper.isInAnAgeBin(), is(true));
+ }
+
+ /**
+ * Tests isChangedSinceLastFlood() getter method.
+ */
+ @Test
+ public void testIsChangedSinceLastFlood() throws Exception {
+ lsaWrapper.setChangedSinceLastFlood(true);
+ assertThat(lsaWrapper.isChangedSinceLastFlood(), is(true));
+ }
+
+ /**
+ * Tests isChangedSinceLastFlood() setter method.
+ */
+ @Test
+ public void testSetChangedSinceLastFlood() throws Exception {
+ lsaWrapper.setChangedSinceLastFlood(true);
+ assertThat(lsaWrapper.isChangedSinceLastFlood(), is(true));
+ }
+
+ /**
+ * Tests isSequenceRollOver() method.
+ */
+ @Test
+ public void testIsSequenceRollOver() throws Exception {
+ lsaWrapper.setIsSequenceRollOver(true);
+ assertThat(lsaWrapper.isSequenceRollOver(), is(true));
+ }
+
+ /**
+ * Tests isSentReplyForOlderLsa() method.
+ */
+ @Test
+ public void testIsSentReplyForOlderLSA() throws Exception {
+ lsaWrapper.setSentReplyForOlderLsa(true);
+ assertThat(lsaWrapper.isSentReplyForOlderLsa(), is(true));
+ }
+
+ /**
+ * Tests isCheckAge() getter method.
+ */
+ @Test
+ public void testIsCheckAge() throws Exception {
+ lsaWrapper.setCheckAge(true);
+ assertThat(lsaWrapper.isCheckAge(), is(true));
+ }
+
+ /**
+ * Tests isCheckAge() setter method.
+ */
+ @Test
+ public void testIsSentReplyForOlderLsa() throws Exception {
+ lsaWrapper.setIsSequenceRollOver(true);
+ assertThat(lsaWrapper.isSequenceRollOver(), is(true));
+ }
+
+ /**
+ * Tests isSentReplyForOlderLsa() getter method.
+ */
+ @Test
+ public void testSetSentReplyForOlderLsa() throws Exception {
+ lsaWrapper.setSentReplyForOlderLsa(true);
+ assertThat(lsaWrapper.isSentReplyForOlderLsa(), is(true));
+ }
+
+ /**
+ * Tests isSentReplyForOlderLsa() setter method.
+ */
+ @Test
+ public void testSetCheckAge() throws Exception {
+ lsaWrapper.setCheckAge(true);
+ assertThat(lsaWrapper.isCheckAge(), is(true));
+ }
+
+ /**
+ * Tests isAging() getter method.
+ */
+ @Test
+ public void testIsAging() throws Exception {
+ lsaWrapper.setIsAging(true);
+ assertThat(lsaWrapper.isAging(), is(true));
+ }
+
+ /**
+ * Tests isAging() setter method.
+ */
+ @Test
+ public void testSetIsAging() throws Exception {
+ lsaWrapper.setIsAging(true);
+ assertThat(lsaWrapper.isAging(), is(true));
+ }
+
+ /**
+ * Tests currentAge() method.
+ */
+ @Test
+ public void testGetCurrentAge() throws Exception {
+ lsdbAge = new LsdbAgeImpl(new OspfAreaImpl());
+ lsdbAge.ageLsaAndFlood();
+ lsaWrapper.setLsdbAge(lsdbAge);
+ assertThat(lsaWrapper.currentAge(), is(notNullValue()));
+ }
+
+ /**
+ * Tests ageCounterWhenReceived() getter method.
+ */
+ @Test
+ public void testGetAgeCounterWhenReceived() throws Exception {
+ lsaWrapper.setAgeCounterWhenReceived(10);
+ assertThat(lsaWrapper.ageCounterWhenReceived(), is(10));
+ }
+
+ /**
+ * Tests ageCounterWhenReceived() setter method.
+ */
+ @Test
+ public void testSetAgeCounterWhenReceived() throws Exception {
+ lsaWrapper.setAgeCounterWhenReceived(10);
+ assertThat(lsaWrapper.ageCounterWhenReceived(), is(10));
+ }
+
+ /**
+ * Tests lsaProcessing() getter method.
+ */
+ @Test
+ public void testGetLsaProcessing() throws Exception {
+ lsaWrapper.setLsaProcessing("router");
+ assertThat(lsaWrapper.lsaProcessing(), is("router"));
+ }
+
+ /**
+ * Tests lsaProcessing() setter method.
+ */
+ @Test
+ public void testSetLsaProcessing() throws Exception {
+ lsaWrapper.setLsaProcessing("router");
+ assertThat(lsaWrapper.lsaProcessing(), is("router"));
+ }
+
+ /**
+ * Tests binNumber() getter method.
+ */
+ @Test
+ public void testGetBinNumber() throws Exception {
+ lsaWrapper.setBinNumber(10);
+ assertThat(lsaWrapper.binNumber(), is(10));
+ }
+
+ /**
+ * Tests binNumber() setter method.
+ */
+ @Test
+ public void testSetBinNumber() throws Exception {
+ lsaWrapper.setBinNumber(10);
+ assertThat(lsaWrapper.binNumber(), is(10));
+ }
+
+ /**
+ * Tests ospfInterface() getter method.
+ */
+ @Test
+ public void testGetOspfInterface() throws Exception {
+ ospfInterfaceImpl = EasyMock.createMock(OspfInterfaceImpl.class);
+ lsaWrapper.setOspfInterface(ospfInterfaceImpl);
+ assertThat(lsaWrapper.ospfInterface(), is(notNullValue()));
+ }
+
+ /**
+ * Tests ospfInterface() setter method.
+ */
+ @Test
+ public void testSetOspfInterface() throws Exception {
+ ospfInterfaceImpl = EasyMock.createMock(OspfInterfaceImpl.class);
+ lsaWrapper.setOspfInterface(ospfInterfaceImpl);
+ assertThat(lsaWrapper.ospfInterface(), is(notNullValue()));
+ }
+
+ /**
+ * Tests getLsdbAge() method.
+ */
+ @Test
+ public void testGetLsdbAge() throws Exception {
+ assertThat(lsaWrapper.getLsdbAge(), is(nullValue()));
+ }
+
+ /**
+ * Tests to string method.
+ */
+ @Test
+ public void testToString() throws Exception {
+ assertThat(lsaWrapper.toString(), is(notNullValue()));
+ }
+
+ /**
+ * Tests equals() method.
+ */
+ @Test
+ public void testEquals() throws Exception {
+ assertThat(lsaWrapper.equals(new LsaWrapperImpl()), is(true));
+ }
+
+ /**
+ * Tests hashCode() method.
+ */
+ @Test
+ public void testHashCode() throws Exception {
+ int hashCode = lsaWrapper.hashCode();
+ assertThat(hashCode, is(notNullValue()));
+ }
+}
\ No newline at end of file
diff --git a/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/lsdb/LsdbAgeImplTest.java b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/lsdb/LsdbAgeImplTest.java
new file mode 100755
index 0000000..c34e2b8
--- /dev/null
+++ b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/lsdb/LsdbAgeImplTest.java
@@ -0,0 +1,272 @@
+/*
+ * 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.controller.lsdb;
+
+import org.easymock.EasyMock;
+import org.jboss.netty.channel.Channel;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.ospf.controller.LsaBin;
+import org.onosproject.ospf.controller.OspfArea;
+import org.onosproject.ospf.controller.area.OspfAreaImpl;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Unit test class for LsdbAgeImpl.
+ */
+public class LsdbAgeImplTest {
+ private LsdbAgeImpl lsdbAge;
+ private OspfAreaImpl ospfAreaImpl;
+ private LsaBinImpl lsaBin;
+ private LsaBin lsaBin1;
+ private LsaWrapperImpl lsaWrapper;
+ private OspfArea ospfArea;
+ private Channel channel;
+
+ @Before
+ public void setUp() throws Exception {
+ ospfAreaImpl = EasyMock.createMock(OspfAreaImpl.class);
+ lsdbAge = new LsdbAgeImpl(ospfAreaImpl);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ lsdbAge = null;
+ lsaBin = null;
+ lsaBin1 = null;
+ ospfAreaImpl = null;
+ lsaWrapper = null;
+ channel = null;
+ ospfArea = null;
+ }
+
+ /**
+ * Tests getLsaBin() method.
+ */
+ @Test
+ public void testGetLsaBin() throws Exception {
+ lsaBin = new LsaBinImpl(1);
+ lsdbAge.addLsaBin(1, lsaBin);
+ assertThat(lsdbAge, is(notNullValue()));
+ lsaBin1 = lsdbAge.getLsaBin(1);
+ assertThat(lsaBin, instanceOf(LsaBin.class));
+ assertThat(lsaBin1, instanceOf(LsaBin.class));
+ }
+
+ /**
+ * Tests addLsaBin() method.
+ */
+ @Test
+ public void testAddLsaBin() throws Exception {
+ lsaBin = new LsaBinImpl(1);
+ lsdbAge.addLsaBin(1, lsaBin);
+ assertThat(lsdbAge, is(notNullValue()));
+ assertThat(lsaBin, instanceOf(LsaBin.class));
+ }
+
+ /**
+ * Tests equals() method.
+ */
+ @Test
+ public void testEquals() throws Exception {
+ assertThat(lsdbAge.equals(lsdbAge), is(true));
+ }
+
+ /**
+ * Tests hashCode() method.
+ */
+ @Test
+ public void testHashCode() throws Exception {
+ int hashCode = lsdbAge.hashCode();
+ assertThat(hashCode, is(notNullValue()));
+ }
+
+ /**
+ * Tests addLsaToMaxAgeBin() method.
+ */
+ @Test
+ public void testAddLsaToMaxAgeBin() throws Exception {
+ lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
+ lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper);
+ assertThat(lsdbAge, is(notNullValue()));
+ }
+
+ /**
+ * Tests removeLsaFromBin() method.
+ */
+ @Test
+ public void testRemoveLsaFromBin() throws Exception {
+ lsaBin = EasyMock.createMock(LsaBinImpl.class);
+ lsaWrapper = new LsaWrapperImpl();
+ lsaWrapper.setBinNumber(-1);
+ lsaBin.addOspfLsa("1", lsaWrapper);
+ lsdbAge.startDbAging();
+ lsdbAge.addLsaToMaxAgeBin("3600", lsaWrapper);
+ lsdbAge.addLsaBin(-1, lsaBin);
+ lsdbAge.removeLsaFromBin(lsaWrapper);
+ assertThat(lsdbAge, is(notNullValue()));
+ }
+
+ /**
+ * Tests startDbAging() method.
+ */
+ @Test
+ public void testStartDbAging() throws Exception {
+ lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
+ lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper);
+ lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
+ lsdbAge.addLsaToMaxAgeBin("lsa2", lsaWrapper);
+ lsdbAge.startDbAging();
+ assertThat(lsdbAge, is(notNullValue()));
+ }
+
+ /**
+ * Tests ageLsaAndFlood() method.
+ */
+ @Test
+ public void testAgeLsaAndFlood() throws Exception {
+ lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
+ lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper);
+ lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
+ lsdbAge.addLsaToMaxAgeBin("lsa2", lsaWrapper);
+ lsdbAge.startDbAging();
+ lsdbAge.ageLsaAndFlood();
+ Assert.assertNotNull(lsdbAge);
+ }
+
+ /**
+ * Tests maxAgeLsa() method.
+ */
+ @Test
+ public void testMaxageLsa() throws Exception {
+ lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
+ ospfArea = new OspfAreaImpl();
+ lsdbAge = new LsdbAgeImpl(ospfArea);
+ lsaWrapper.setLsdbAge(lsdbAge);
+ lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper);
+ lsaBin = new LsaBinImpl(1);
+ lsaBin.addOspfLsa("1", lsaWrapper);
+ lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
+ lsdbAge.addLsaToMaxAgeBin("lsa2", lsaWrapper);
+ lsaBin.addOspfLsa("2", lsaWrapper);
+ lsdbAge.startDbAging();
+ lsdbAge = new LsdbAgeImpl(new OspfAreaImpl());
+ lsdbAge.ageLsaAndFlood();
+ lsdbAge.maxAgeLsa();
+ assertThat(lsdbAge, is(notNullValue()));
+
+ }
+
+ /**
+ * Tests refreshLsa() method.
+ */
+ @Test
+ public void testRefereshLsa() throws Exception {
+ lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
+ lsaWrapper.setBinNumber(0);
+ lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper);
+ lsdbAge.ageLsaAndFlood();
+ lsaWrapper.setBinNumber(0);
+ lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
+ lsdbAge.addLsaToMaxAgeBin("lsa2", lsaWrapper);
+ lsdbAge.ageLsaAndFlood();
+ lsdbAge.startDbAging();
+ lsaBin = new LsaBinImpl(1809);
+ lsdbAge.refreshLsa();
+ assertThat(lsdbAge, is(notNullValue()));
+ }
+
+ /**
+ * Tests checkAges() method.
+ */
+ @Test
+ public void testCheckAges() throws Exception {
+ lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
+ lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper);
+ lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
+ lsdbAge.addLsaToMaxAgeBin("lsa2", lsaWrapper);
+ lsdbAge.startDbAging();
+ lsdbAge.checkAges();
+ assertThat(lsdbAge, is(notNullValue()));
+
+ }
+
+ /**
+ * Tests getChannel() getter method.
+ */
+ @Test
+ public void testGetChannel() throws Exception {
+ channel = EasyMock.createMock(Channel.class);
+ lsdbAge.setChannel(channel);
+ assertThat(lsdbAge.getChannel(), is(notNullValue()));
+ }
+
+ /**
+ * Tests setChannel() setter method.
+ */
+ @Test
+ public void testSetChannel() throws Exception {
+ channel = EasyMock.createMock(Channel.class);
+ lsdbAge.setChannel(channel);
+ assertThat(lsdbAge.getChannel(), is(notNullValue()));
+ }
+
+ /**
+ * Tests getAgeCounter() method.
+ */
+ @Test
+ public void testGetAgeCounter() throws Exception {
+ lsaBin = new LsaBinImpl(1);
+ lsdbAge.addLsaBin(1, lsaBin);
+ int age = lsdbAge.getAgeCounter();
+ assertThat(age, is(notNullValue()));
+ }
+
+ /**
+ * Tests getAgeCounterRollOver() method.
+ */
+ @Test
+ public void testGetAgeCounterRollOver() throws Exception {
+ lsaBin = new LsaBinImpl(1);
+ lsdbAge.addLsaBin(1, lsaBin);
+ lsdbAge.startDbAging();
+ assertThat(lsdbAge.getAgeCounterRollOver(), is(notNullValue()));
+ }
+
+ /**
+ * Tests getMaxAgeBin() method.
+ */
+ @Test
+ public void testGetMaxAgeBin() throws Exception {
+ lsaBin = new LsaBinImpl(1);
+ lsdbAge.addLsaBin(1, lsaBin);
+ lsdbAge.startDbAging();
+ assertThat(lsdbAge.getMaxAgeBin(), is(notNullValue()));
+ }
+
+ /**
+ * Tests age2Bin() method.
+ */
+ @Test
+ public void testAge2Bin() throws Exception {
+ int age = lsdbAge.age2Bin(0);
+ assertThat(age, is(notNullValue()));
+ }
+}
\ No newline at end of file
diff --git a/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/lsdb/OspfLsdbImplTest.java b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/lsdb/OspfLsdbImplTest.java
new file mode 100755
index 0000000..272344d
--- /dev/null
+++ b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/lsdb/OspfLsdbImplTest.java
@@ -0,0 +1,459 @@
+/*
+ * 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.controller.lsdb;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.ospf.controller.OspfLsaType;
+import org.onosproject.ospf.controller.area.OspfAreaImpl;
+import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
+import org.onosproject.ospf.protocol.lsa.LsaHeader;
+import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
+import org.onosproject.ospf.protocol.lsa.types.AsbrSummaryLsa;
+import org.onosproject.ospf.protocol.lsa.types.ExternalLsa;
+import org.onosproject.ospf.protocol.lsa.types.NetworkLsa;
+import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa10;
+import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa11;
+import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa9;
+import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
+import org.onosproject.ospf.protocol.lsa.types.SummaryLsa;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Unit test class for OspfLsdbImpl.
+ */
+public class OspfLsdbImplTest {
+ private OspfLsdbImpl ospfLsdb;
+ private RouterLsa routerLsa;
+ private NetworkLsa networkLsa;
+ private SummaryLsa summaryLsa;
+ private AsbrSummaryLsa asbrSummaryLsa;
+ private OpaqueLsa9 opaqueLsa9;
+ private OpaqueLsa10 opaqueLsa10;
+ private OpaqueLsa11 opaqueLsa11;
+ private ExternalLsa externalLsa;
+ private OpaqueLsaHeader opaqueLsaHeader;
+ private LsaWrapperImpl lsaWrapper;
+ private OpaqueLsaHeader opaqueLsaHeader1;
+ private String key;
+
+ @Before
+ public void setUp() throws Exception {
+ OspfAreaImpl ospfArea = new OspfAreaImpl();
+ ospfLsdb = new OspfLsdbImpl(ospfArea);
+ routerLsa = new RouterLsa();
+ networkLsa = new NetworkLsa();
+ summaryLsa = new SummaryLsa(new LsaHeader());
+ asbrSummaryLsa = new AsbrSummaryLsa(new LsaHeader());
+ opaqueLsa9 = new OpaqueLsa9(new OpaqueLsaHeader());
+ opaqueLsa10 = new OpaqueLsa10(new OpaqueLsaHeader());
+ opaqueLsa11 = new OpaqueLsa11(new OpaqueLsaHeader());
+ externalLsa = new ExternalLsa(new LsaHeader());
+
+
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ ospfLsdb = null;
+ routerLsa = null;
+ externalLsa = null;
+ summaryLsa = null;
+ asbrSummaryLsa = null;
+ opaqueLsa10 = null;
+ opaqueLsa11 = null;
+ opaqueLsa9 = null;
+ networkLsa = null;
+ lsaWrapper = null;
+ opaqueLsaHeader = null;
+ opaqueLsaHeader1 = null;
+ key = null;
+ }
+
+ /**
+ * Tests equals() method.
+ */
+ @Test
+ public void testEquals() throws Exception {
+ assertThat(ospfLsdb.equals(new OspfLsdbImpl(new OspfAreaImpl())), is(false));
+ }
+
+ /**
+ * Tests hashCode() method.
+ */
+ @Test
+ public void testHashCode() throws Exception {
+ int hashCode = ospfLsdb.hashCode();
+ assertThat(hashCode, is(notNullValue()));
+ }
+
+ /**
+ * Tests initializeDb() method.
+ */
+ @Test
+ public void testInitializeDb() throws Exception {
+ ospfLsdb.initializeDb();
+ assertThat(ospfLsdb, is(notNullValue()));
+ }
+
+ /**
+ * Tests getAllLsaHeaders() method.
+ */
+ @Test
+ public void testGetAllLsaHeaders() throws Exception {
+ ospfLsdb.initializeDb();
+ routerLsa.setLsType(1);
+ assertThat(ospfLsdb.addLsa(routerLsa, false, new OspfInterfaceImpl()), is(true));
+ networkLsa.setLsType(2);
+ assertThat(ospfLsdb.addLsa(networkLsa, false, new OspfInterfaceImpl()), is(true));
+ summaryLsa.setLsType(3);
+ assertThat(ospfLsdb.addLsa(summaryLsa, false, new OspfInterfaceImpl()), is(true));
+ asbrSummaryLsa.setLsType(4);
+ assertThat(ospfLsdb.addLsa(asbrSummaryLsa, false, new OspfInterfaceImpl()), is(true));
+ externalLsa.setLsType(5);
+ assertThat(ospfLsdb.addLsa(externalLsa, false, new OspfInterfaceImpl()), is(true));
+ ospfLsdb.initializeDb();
+ assertThat(ospfLsdb.getAllLsaHeaders(true, true).size(), is(5));
+
+ }
+
+ /**
+ * Tests getLsaKey() method.
+ */
+ @Test
+ public void testGetLsaKey() throws Exception {
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(1);
+ assertThat(ospfLsdb.getLsaKey(opaqueLsaHeader), is(notNullValue()));
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(2);
+ assertThat(ospfLsdb.getLsaKey(opaqueLsaHeader), is(notNullValue()));
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(3);
+ assertThat(ospfLsdb.getLsaKey(opaqueLsaHeader), is(notNullValue()));
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(4);
+ assertThat(ospfLsdb.getLsaKey(opaqueLsaHeader), is(notNullValue()));
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(5);
+ assertThat(ospfLsdb.getLsaKey(opaqueLsaHeader), is(notNullValue()));
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(9);
+ assertThat(ospfLsdb.getLsaKey(opaqueLsaHeader), is(notNullValue()));
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(10);
+ assertThat(ospfLsdb.getLsaKey(opaqueLsaHeader), is(notNullValue()));
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(11);
+ assertThat(ospfLsdb.getLsaKey(opaqueLsaHeader), is(notNullValue()));
+ }
+
+ /**
+ * Tests lsaLookup() method.
+ */
+ @Test
+ public void testLsaLookup() throws Exception {
+ ospfLsdb.initializeDb();
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ ospfLsdb.addLsa(opaqueLsaHeader, true, new OspfInterfaceImpl());
+ opaqueLsaHeader.setLsType(1);
+ String key = ospfLsdb.getLsaKey(opaqueLsaHeader);
+ assertThat(ospfLsdb.lsaLookup(opaqueLsaHeader), is(nullValue()));
+ }
+
+ /**
+ * Tests findLsa() method.
+ */
+ @Test
+ public void testFindlsa() throws Exception {
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(1);
+ key = ospfLsdb.getLsaKey(opaqueLsaHeader);
+ ospfLsdb.addLsa(new RouterLsa(), false, new OspfInterfaceImpl());
+ lsaWrapper = (LsaWrapperImpl) ospfLsdb.findLsa(opaqueLsaHeader.lsType(), key);
+ assertThat(lsaWrapper, is(nullValue()));
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(2);
+ key = ospfLsdb.getLsaKey(opaqueLsaHeader);
+ ospfLsdb.addLsa(new RouterLsa(), false, new OspfInterfaceImpl());
+ lsaWrapper = (LsaWrapperImpl) ospfLsdb.findLsa(opaqueLsaHeader.lsType(), key);
+ assertThat(lsaWrapper, is(nullValue()));
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(3);
+ key = ospfLsdb.getLsaKey(opaqueLsaHeader);
+ ospfLsdb.addLsa(new RouterLsa(), false, new OspfInterfaceImpl());
+ lsaWrapper = (LsaWrapperImpl) ospfLsdb.findLsa(opaqueLsaHeader.lsType(), key);
+ assertThat(lsaWrapper, is(nullValue()));
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(4);
+ key = ospfLsdb.getLsaKey(opaqueLsaHeader);
+ ospfLsdb.addLsa(new RouterLsa(), false, new OspfInterfaceImpl());
+ lsaWrapper = (LsaWrapperImpl) ospfLsdb.findLsa(opaqueLsaHeader.lsType(), key);
+ assertThat(lsaWrapper, is(nullValue()));
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(5);
+ key = ospfLsdb.getLsaKey(opaqueLsaHeader);
+ ospfLsdb.addLsa(new RouterLsa(), false, new OspfInterfaceImpl());
+ lsaWrapper = (LsaWrapperImpl) ospfLsdb.findLsa(opaqueLsaHeader.lsType(), key);
+ assertThat(lsaWrapper, is(nullValue()));
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(9);
+ key = ospfLsdb.getLsaKey(opaqueLsaHeader);
+ ospfLsdb.addLsa(new RouterLsa(), false, new OspfInterfaceImpl());
+ lsaWrapper = (LsaWrapperImpl) ospfLsdb.findLsa(opaqueLsaHeader.lsType(), key);
+ assertThat(lsaWrapper, is(nullValue()));
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(10);
+ key = ospfLsdb.getLsaKey(opaqueLsaHeader);
+ ospfLsdb.addLsa(new RouterLsa(), false, new OspfInterfaceImpl());
+ lsaWrapper = (LsaWrapperImpl) ospfLsdb.findLsa(opaqueLsaHeader.lsType(), key);
+ assertThat(lsaWrapper, is(nullValue()));
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(11);
+ key = ospfLsdb.getLsaKey(opaqueLsaHeader);
+ ospfLsdb.addLsa(new RouterLsa(), false, new OspfInterfaceImpl());
+ lsaWrapper = (LsaWrapperImpl) ospfLsdb.findLsa(opaqueLsaHeader.lsType(), key);
+ assertThat(lsaWrapper, is(nullValue()));
+ }
+
+ /**
+ * Tests addLSA() method.
+ */
+ @Test
+ public void testAddLSA() throws Exception {
+ routerLsa.setLsType(1);
+ assertThat(ospfLsdb.addLsa(routerLsa, false, new OspfInterfaceImpl()), is(true));
+ networkLsa.setLsType(2);
+ assertThat(ospfLsdb.addLsa(networkLsa, false, new OspfInterfaceImpl()), is(true));
+ summaryLsa.setLsType(3);
+ assertThat(ospfLsdb.addLsa(summaryLsa, false, new OspfInterfaceImpl()), is(true));
+ asbrSummaryLsa.setLsType(4);
+ assertThat(ospfLsdb.addLsa(asbrSummaryLsa, false, new OspfInterfaceImpl()), is(true));
+ externalLsa.setLsType(5);
+ assertThat(ospfLsdb.addLsa(externalLsa, false, new OspfInterfaceImpl()), is(true));
+ opaqueLsa9.setLsType(9);
+ assertThat(ospfLsdb.addLsa(opaqueLsa9, false, new OspfInterfaceImpl()), is(true));
+ opaqueLsa10.setLsType(10);
+ assertThat(ospfLsdb.addLsa(opaqueLsa10, false, new OspfInterfaceImpl()), is(true));
+ opaqueLsa11.setLsType(11);
+ assertThat(ospfLsdb.addLsa(opaqueLsa11, false, new OspfInterfaceImpl()), is(true));
+
+ }
+
+ /**
+ * Tests addLsaToMaxAgeBin() method.
+ */
+ @Test
+ public void testAddLsaToMaxAgeBin() throws Exception {
+ lsaWrapper = new LsaWrapperImpl();
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(1);
+ key = ospfLsdb.getLsaKey(opaqueLsaHeader);
+ lsaWrapper.setLsaHeader((OpaqueLsaHeader) opaqueLsaHeader);
+ ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
+ lsaWrapper = new LsaWrapperImpl();
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(2);
+ ospfLsdb.getLsaKey(opaqueLsaHeader);
+ lsaWrapper.setLsaHeader(opaqueLsaHeader);
+ ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
+ lsaWrapper = new LsaWrapperImpl();
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(3);
+ ospfLsdb.getLsaKey(opaqueLsaHeader);
+ lsaWrapper.setLsaHeader(opaqueLsaHeader);
+ ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
+ lsaWrapper = new LsaWrapperImpl();
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(4);
+ ospfLsdb.getLsaKey(opaqueLsaHeader);
+ lsaWrapper.setLsaHeader(opaqueLsaHeader);
+ ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
+ lsaWrapper = new LsaWrapperImpl();
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(5);
+ ospfLsdb.getLsaKey(opaqueLsaHeader);
+ lsaWrapper.setLsaHeader(opaqueLsaHeader);
+ ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
+ lsaWrapper = new LsaWrapperImpl();
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(9);
+ ospfLsdb.getLsaKey(opaqueLsaHeader);
+ lsaWrapper.setLsaHeader(opaqueLsaHeader);
+ ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
+ lsaWrapper = new LsaWrapperImpl();
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(10);
+ ospfLsdb.getLsaKey(opaqueLsaHeader);
+ lsaWrapper.setLsaHeader(opaqueLsaHeader);
+ ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
+ lsaWrapper = new LsaWrapperImpl();
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(11);
+ ospfLsdb.getLsaKey(opaqueLsaHeader);
+ lsaWrapper.setLsaHeader(opaqueLsaHeader);
+ ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
+ assertThat(ospfLsdb, is(notNullValue()));
+ }
+
+ /**
+ * Tests removeLsaFromBin() method.
+ */
+ @Test
+ public void testRemoveLsaFromBin() throws Exception {
+ lsaWrapper = new LsaWrapperImpl();
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(1);
+ key = ospfLsdb.getLsaKey(opaqueLsaHeader);
+ lsaWrapper.setLsaHeader(opaqueLsaHeader);
+ ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
+ ospfLsdb.removeLsaFromBin(lsaWrapper);
+ lsaWrapper = new LsaWrapperImpl();
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(2);
+ ospfLsdb.getLsaKey(opaqueLsaHeader);
+ lsaWrapper.setLsaHeader(opaqueLsaHeader);
+ ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
+ ospfLsdb.removeLsaFromBin(lsaWrapper);
+ lsaWrapper = new LsaWrapperImpl();
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(3);
+ ospfLsdb.getLsaKey(opaqueLsaHeader);
+ lsaWrapper.setLsaHeader(opaqueLsaHeader);
+ ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
+ ospfLsdb.removeLsaFromBin(lsaWrapper);
+ lsaWrapper = new LsaWrapperImpl();
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(4);
+ ospfLsdb.getLsaKey(opaqueLsaHeader);
+ lsaWrapper.setLsaHeader(opaqueLsaHeader);
+ ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
+ ospfLsdb.removeLsaFromBin(lsaWrapper);
+ lsaWrapper = new LsaWrapperImpl();
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(5);
+ ospfLsdb.getLsaKey(opaqueLsaHeader);
+ lsaWrapper.setLsaHeader(opaqueLsaHeader);
+ ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
+ ospfLsdb.removeLsaFromBin(lsaWrapper);
+ lsaWrapper = new LsaWrapperImpl();
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(9);
+ ospfLsdb.getLsaKey(opaqueLsaHeader);
+ lsaWrapper.setLsaHeader(opaqueLsaHeader);
+ ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
+ ospfLsdb.removeLsaFromBin(lsaWrapper);
+ lsaWrapper = new LsaWrapperImpl();
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(10);
+ ospfLsdb.getLsaKey(opaqueLsaHeader);
+ lsaWrapper.setLsaHeader(opaqueLsaHeader);
+ ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
+ ospfLsdb.removeLsaFromBin(lsaWrapper);
+ lsaWrapper = new LsaWrapperImpl();
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(11);
+ ospfLsdb.getLsaKey(opaqueLsaHeader);
+ lsaWrapper.setLsaHeader(opaqueLsaHeader);
+ ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
+ ospfLsdb.removeLsaFromBin(lsaWrapper);
+ assertThat(ospfLsdb, is(notNullValue()));
+ }
+
+ /**
+ * Tests isNewerOrSameLsa() method.
+ */
+ @Test
+ public void testIsNewerorSameLSA() throws Exception {
+ lsaWrapper = new LsaWrapperImpl();
+ opaqueLsaHeader1 = new OpaqueLsaHeader();
+ opaqueLsaHeader1.setLsType(1);
+ key = ospfLsdb.getLsaKey(opaqueLsaHeader1);
+ lsaWrapper.setLsaHeader(opaqueLsaHeader1);
+ ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
+ lsaWrapper = new LsaWrapperImpl();
+ opaqueLsaHeader = new OpaqueLsaHeader();
+ opaqueLsaHeader.setLsType(2);
+ ospfLsdb.getLsaKey(opaqueLsaHeader);
+ lsaWrapper.setLsaHeader(opaqueLsaHeader);
+ ospfLsdb.addLsaToMaxAgeBin(key, lsaWrapper);
+ assertThat(ospfLsdb.isNewerOrSameLsa(opaqueLsaHeader1, opaqueLsaHeader), is(notNullValue()));
+ assertThat(ospfLsdb, is(notNullValue()));
+ }
+
+ /**
+ * Tests getLsSequenceNumber() method.
+ */
+ @Test
+ public void testGetLsSequenceNumber() throws Exception {
+ assertThat(ospfLsdb.getLsSequenceNumber(OspfLsaType.NETWORK), is(notNullValue()));
+ assertThat(ospfLsdb.getLsSequenceNumber(OspfLsaType.ROUTER), is(notNullValue()));
+ }
+
+ /**
+ * Tests deleteLsa() method.
+ */
+ @Test
+ public void testDeleteLsa() throws Exception {
+ opaqueLsaHeader1 = new OpaqueLsaHeader();
+ opaqueLsaHeader1.setLsType(1);
+ ospfLsdb.deleteLsa(opaqueLsaHeader1);
+ opaqueLsaHeader1 = new OpaqueLsaHeader();
+ opaqueLsaHeader1.setLsType(2);
+ ospfLsdb.deleteLsa(opaqueLsaHeader1);
+ opaqueLsaHeader1 = new OpaqueLsaHeader();
+ opaqueLsaHeader1.setLsType(3);
+ ospfLsdb.deleteLsa(opaqueLsaHeader1);
+ opaqueLsaHeader1 = new OpaqueLsaHeader();
+ opaqueLsaHeader1.setLsType(4);
+ ospfLsdb.deleteLsa(opaqueLsaHeader1);
+ opaqueLsaHeader1 = new OpaqueLsaHeader();
+ opaqueLsaHeader1.setLsType(5);
+ ospfLsdb.deleteLsa(opaqueLsaHeader1);
+ opaqueLsaHeader1 = new OpaqueLsaHeader();
+ opaqueLsaHeader1.setLsType(9);
+ ospfLsdb.deleteLsa(opaqueLsaHeader1);
+ opaqueLsaHeader1 = new OpaqueLsaHeader();
+ opaqueLsaHeader1.setLsType(10);
+ ospfLsdb.deleteLsa(opaqueLsaHeader1);
+ opaqueLsaHeader1 = new OpaqueLsaHeader();
+ opaqueLsaHeader1.setLsType(11);
+ ospfLsdb.deleteLsa(opaqueLsaHeader1);
+ assertThat(ospfLsdb, is(notNullValue()));
+
+ }
+
+ /**
+ * Tests getLsSequenceNumber() method.
+ */
+ @Test
+ public void testSetRouterLsaSeqNo() throws Exception {
+ ospfLsdb.setRouterLsaSeqNo(-2147483647);
+ assertThat(ospfLsdb.getLsSequenceNumber(OspfLsaType.ROUTER), is(-2147483647L));
+ }
+
+ /**
+ * Tests getLsSequenceNumber() method.
+ */
+ @Test
+ public void testSetNetworkLsaSeqNo() throws Exception {
+ ospfLsdb.setNetworkLsaSeqNo(111111);
+ assertThat(ospfLsdb.getLsSequenceNumber(OspfLsaType.NETWORK), is(111111L));
+ }
+}
\ No newline at end of file
diff --git a/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/util/OspfEligibleRouterTest.java b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/util/OspfEligibleRouterTest.java
new file mode 100755
index 0000000..84b55cf
--- /dev/null
+++ b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/util/OspfEligibleRouterTest.java
@@ -0,0 +1,132 @@
+/*
+ * 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.controller.util;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.Ip4Address;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Unit test class for OspfEligibleRouter.
+ */
+public class OspfEligibleRouterTest {
+
+ private OspfEligibleRouter ospfEligibleRouter;
+
+ @Before
+ public void setUp() throws Exception {
+ ospfEligibleRouter = new OspfEligibleRouter();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ ospfEligibleRouter = null;
+ }
+
+ /**
+ * Tests getIpAddress() getter method.
+ */
+ @Test
+ public void testGetIpAddress() throws Exception {
+ ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
+ assertThat(ospfEligibleRouter.getIpAddress(), is(Ip4Address.valueOf("1.1.1.1")));
+ }
+
+ /**
+ * Tests setIpAddress() setter method.
+ */
+ @Test
+ public void testSetIpAddress() throws Exception {
+ ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
+ assertThat(ospfEligibleRouter.getIpAddress(), is(Ip4Address.valueOf("1.1.1.1")));
+ }
+
+ /**
+ * Tests getRouterId() getter method.
+ */
+ @Test
+ public void testGetRouterId() throws Exception {
+ ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
+ assertThat(ospfEligibleRouter.getRouterId(), is(Ip4Address.valueOf("1.1.1.1")));
+ }
+
+ /**
+ * Tests setRouterId() setter method.
+ */
+ @Test
+ public void testSetRouterId() throws Exception {
+ ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
+ assertThat(ospfEligibleRouter.getRouterId(), is(Ip4Address.valueOf("1.1.1.1")));
+ }
+
+ /**
+ * Tests getRouterPriority() getter method.
+ */
+ @Test
+ public void testGetRouterPriority() throws Exception {
+ ospfEligibleRouter.setRouterPriority(1);
+ assertThat(ospfEligibleRouter.getRouterPriority(), is(1));
+ }
+
+ /**
+ * Tests getRouterPriority() setter method.
+ */
+ @Test
+ public void testSetRouterPriority() throws Exception {
+ ospfEligibleRouter.setRouterPriority(1);
+ assertThat(ospfEligibleRouter.getRouterPriority(), is(1));
+ }
+
+ /**
+ * Tests isDr() getter method.
+ */
+ @Test
+ public void testIsDr() throws Exception {
+ ospfEligibleRouter.setIsDr(true);
+ assertThat(ospfEligibleRouter.isDr(), is(true));
+ }
+
+ /**
+ * Tests isDr() setter method.
+ */
+ @Test
+ public void testSetIsDr() throws Exception {
+ ospfEligibleRouter.setIsDr(true);
+ assertThat(ospfEligibleRouter.isDr(), is(true));
+ }
+
+ /**
+ * Tests isBdr() getter method.
+ */
+ @Test
+ public void testIsBdr() throws Exception {
+ ospfEligibleRouter.setIsBdr(true);
+ assertThat(ospfEligibleRouter.isBdr(), is(true));
+ }
+
+ /**
+ * Tests isBdr() setter method.
+ */
+ @Test
+ public void testSetIsBdr() throws Exception {
+ ospfEligibleRouter.setIsBdr(true);
+ assertThat(ospfEligibleRouter.isBdr(), is(true));
+ }
+}