Dhruv Dhody
Committed by Thomas Vachuska

ONOS-2740,ONOS-2741,from ONOS-3032 - to ONOS 3071 , OSPF Protocol Implementation Unit Tests

Change-Id: Ie7f02bd9bff16902647c7af406f7ece9cdf0ae6c
/*
* 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.OspfArea;
import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for OspfProcessImpl.
*/
public class OspfProcessImplTest {
private OspfProcessImpl ospfProcess;
private List<OspfArea> list;
private List result;
@Before
public void setUp() throws Exception {
ospfProcess = new OspfProcessImpl();
}
@After
public void tearDown() throws Exception {
ospfProcess = null;
list = null;
}
/**
* Tests areas() getter method.
*/
@Test
public void testGetAreas() throws Exception {
list = new ArrayList();
list.add(new OspfAreaImpl());
list.add(new OspfAreaImpl());
ospfProcess.setAreas(list);
result = ospfProcess.areas();
assertThat(result.size(), is(2));
}
/**
* Tests areas() setter method.
*/
@Test
public void testSetAreas() throws Exception {
list = new ArrayList();
list.add(new OspfAreaImpl());
list.add(new OspfAreaImpl());
ospfProcess.setAreas(list);
result = ospfProcess.areas();
assertThat(result.size(), is(2));
}
/**
* Tests processId() getter method.
*/
@Test
public void testGetProcessId() throws Exception {
ospfProcess.setProcessId("1.1.1.1");
assertThat(ospfProcess.processId(), is("1.1.1.1"));
}
/**
* Tests processId() setter method.
*/
@Test
public void testSetProcessId() throws Exception {
ospfProcess.setProcessId("1.1.1.1");
assertThat(ospfProcess.processId(), is("1.1.1.1"));
}
/**
* Tests to string method.
*/
@Test
public void testToString() throws Exception {
assertThat(ospfProcess.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* 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.impl;
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.junit.Assert.assertThat;
/**
* Unit test class for DeviceInformationImpl.
*/
public class DeviceInformationImplTest {
private DeviceInformationImpl deviceInformation;
@Before
public void setUp() throws Exception {
deviceInformation = new DeviceInformationImpl();
}
@After
public void tearDown() throws Exception {
deviceInformation = null;
}
/**
* Tests routerId() getter method.
*/
@Test
public void testRouterId() throws Exception {
deviceInformation.setRouterId(Ip4Address.valueOf("1.1.1.1"));
assertThat(deviceInformation.routerId(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests routerId() setter method.
*/
@Test
public void testSetRouterId() throws Exception {
deviceInformation.setRouterId(Ip4Address.valueOf("1.1.1.1"));
assertThat(deviceInformation.routerId(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests deviceId() getter method.
*/
@Test
public void testDeviceId() throws Exception {
deviceInformation.setDeviceId(Ip4Address.valueOf("1.1.1.1"));
assertThat(deviceInformation.deviceId(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests deviceId() getter method.
*/
@Test
public void testSetDeviceId() throws Exception {
deviceInformation.setDeviceId(Ip4Address.valueOf("1.1.1.1"));
assertThat(deviceInformation.deviceId(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests interfaceId() method.
*/
@Test
public void testInterfaceId() throws Exception {
deviceInformation.addInterfaceId(Ip4Address.valueOf("1.1.1.1"));
assertThat(deviceInformation.interfaceId().size(), is(1));
}
/**
* Tests addInterfaceId() method.
*/
@Test
public void testAddInterfaceId() throws Exception {
deviceInformation.addInterfaceId(Ip4Address.valueOf("1.1.1.1"));
assertThat(deviceInformation.interfaceId().size(), is(1));
}
/**
* Tests areaId() getter method.
*/
@Test
public void testAreaId() throws Exception {
deviceInformation.setAreaId(Ip4Address.valueOf("1.1.1.1"));
assertThat(deviceInformation.areaId(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests areaId() setter method.
*/
@Test
public void testSetAreaId() throws Exception {
deviceInformation.setAreaId(Ip4Address.valueOf("1.1.1.1"));
assertThat(deviceInformation.areaId(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests isAlreadyCreated() getter method.
*/
@Test
public void testIsAlreadyCreated() throws Exception {
deviceInformation.setAlreadyCreated(true);
assertThat(deviceInformation.isAlreadyCreated(), is(true));
}
/**
* Tests isAlreadyCreated() setter method.
*/
@Test
public void testSetAlreadyCreated() throws Exception {
deviceInformation.setAlreadyCreated(true);
assertThat(deviceInformation.isAlreadyCreated(), is(true));
}
/**
* Tests isDr() getter method.
*/
@Test
public void testIsDr() throws Exception {
deviceInformation.setDr(true);
assertThat(deviceInformation.isDr(), is(true));
}
/**
* Tests isDr() setter method.
*/
@Test
public void testSetDr() throws Exception {
deviceInformation.setDr(true);
assertThat(deviceInformation.isDr(), is(true));
}
/**
* Tests neighborId() getter method.
*/
@Test
public void testNeighborId() throws Exception {
deviceInformation.setNeighborId(Ip4Address.valueOf("1.1.1.1"));
assertThat(deviceInformation.neighborId(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests neighborId() setter method.
*/
@Test
public void testSetNeighborId() throws Exception {
deviceInformation.setNeighborId(Ip4Address.valueOf("1.1.1.1"));
assertThat(deviceInformation.neighborId(), is(Ip4Address.valueOf("1.1.1.1")));
}
}
\ No newline at end of file
/*
* 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.impl;
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.junit.Assert.assertThat;
/**
* Unit test class for LinkInformationImpl.
*/
public class LinkInformationImplTest {
private LinkInformationImpl linkInformation;
@Before
public void setUp() throws Exception {
linkInformation = new LinkInformationImpl();
}
@After
public void tearDown() throws Exception {
linkInformation = null;
}
/**
* Tests linkId() getter method.
*/
@Test
public void testLinkId() throws Exception {
linkInformation.setLinkId("1.1.1.1");
assertThat(linkInformation.linkId(), is("1.1.1.1"));
}
/**
* Tests linkId() setter method.
*/
@Test
public void testSetLinkId() throws Exception {
linkInformation.setLinkId("1.1.1.1");
assertThat(linkInformation.linkId(), is("1.1.1.1"));
}
/**
* Tests isAlreadyCreated() getter method.
*/
@Test
public void testIsAlreadyCreated() throws Exception {
linkInformation.setAlreadyCreated(true);
assertThat(linkInformation.isAlreadyCreated(), is(true));
}
/**
* Tests isAlreadyCreated() setter method.
*/
@Test
public void testSetAlreadyCreated() throws Exception {
linkInformation.setAlreadyCreated(true);
assertThat(linkInformation.isAlreadyCreated(), is(true));
}
/**
* Tests isLinkSrcIdNotRouterId() getter method.
*/
@Test
public void testIsLinkSrcIdNotRouterId() throws Exception {
linkInformation.setLinkSrcIdNotRouterId(true);
assertThat(linkInformation.isLinkSrcIdNotRouterId(), is(true));
}
/**
* Tests isLinkSrcIdNotRouterId() setter method.
*/
@Test
public void testSetLinkSrcIdNotRouterId() throws Exception {
linkInformation.setLinkSrcIdNotRouterId(true);
assertThat(linkInformation.isLinkSrcIdNotRouterId(), is(true));
}
/**
* Tests linkDestinationId() getter method.
*/
@Test
public void testLinkDestinationId() throws Exception {
linkInformation.setLinkDestinationId(Ip4Address.valueOf("1.1.1.1"));
assertThat(linkInformation.linkDestinationId(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests linkDestinationId() setter method.
*/
@Test
public void testSetLinkDestinationId() throws Exception {
linkInformation.setLinkDestinationId(Ip4Address.valueOf("1.1.1.1"));
assertThat(linkInformation.linkDestinationId(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests linkSourceId() getter method.
*/
@Test
public void testLinkSourceId() throws Exception {
linkInformation.setLinkSourceId(Ip4Address.valueOf("1.1.1.1"));
assertThat(linkInformation.linkSourceId(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests linkSourceId() setter method.
*/
@Test
public void testSetLinkSourceId() throws Exception {
linkInformation.setLinkSourceId(Ip4Address.valueOf("1.1.1.1"));
assertThat(linkInformation.linkSourceId(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests interfaceIp() getter method.
*/
@Test
public void testInterfaceIp() throws Exception {
linkInformation.setInterfaceIp(Ip4Address.valueOf("1.1.1.1"));
assertThat(linkInformation.interfaceIp(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests interfaceIp() setter method.
*/
@Test
public void testSetInterfaceIp() throws Exception {
linkInformation.setInterfaceIp(Ip4Address.valueOf("1.1.1.1"));
assertThat(linkInformation.interfaceIp(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests linkSourceIpAddress() getter method.
*/
@Test
public void testLinkSourceIpAddress() throws Exception {
linkInformation.setLinkSourceIpAddress(Ip4Address.valueOf("1.1.1.1"));
assertThat(linkInformation.linkSourceIpAddress(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests linkSourceIpAddress() setter method.
*/
@Test
public void testSetLinkSourceIpAddress() throws Exception {
linkInformation.setLinkSourceIpAddress(Ip4Address.valueOf("1.1.1.1"));
assertThat(linkInformation.linkSourceIpAddress(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests linkDestinationId() getter method.
*/
@Test
public void testLinkDestinationIpAddress() throws Exception {
linkInformation.setLinkDestinationIpAddress(Ip4Address.valueOf("1.1.1.1"));
assertThat(linkInformation.linkDestinationIpAddress(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests linkDestinationId() setter method.
*/
@Test
public void testSetLinkDestinationIpAddress() throws Exception {
linkInformation.setLinkDestinationIpAddress(Ip4Address.valueOf("1.1.1.1"));
assertThat(linkInformation.linkDestinationIpAddress(), is(Ip4Address.valueOf("1.1.1.1")));
}
}
\ No newline at end of file
/*
* 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.impl;
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.OspfInterface;
import org.onosproject.ospf.controller.OspfLinkListener;
import org.onosproject.ospf.controller.OspfProcess;
import org.onosproject.ospf.controller.OspfRouter;
import org.onosproject.ospf.controller.OspfRouterListener;
import org.onosproject.ospf.controller.area.OspfAreaImpl;
import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
import org.onosproject.ospf.controller.area.OspfProcessImpl;
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 OspfRouterId.
*/
public class OspfControllerImplTest {
private OspfControllerImpl ospfController;
private OspfRouterListener ospfRouterListener;
private OspfLinkListener ospfLinkListener;
private Controller controller;
private List<OspfProcess> ospfProcesses;
private OspfProcess process1;
private OspfProcess process2;
private List<OspfArea> areas;
private OspfAreaImpl ospfArea;
private List<OspfInterface> ospfInterfaces;
private OspfInterfaceImpl ospfInterface;
private OspfProcess ospfProcess;
private OspfArea ospfArea1;
private OspfRouter ospfRouter;
@Before
public void setUp() throws Exception {
ospfController = new OspfControllerImpl();
controller = new Controller();
}
@After
public void tearDown() throws Exception {
ospfController = null;
ospfRouterListener = null;
ospfLinkListener = null;
controller = null;
ospfProcesses = null;
areas = null;
ospfArea = null;
ospfInterfaces = null;
ospfInterface = null;
ospfProcess = null;
ospfProcess = null;
ospfArea1 = null;
ospfRouter = null;
}
/**
* Tests activate() method.
*/
@Test
public void testActivate() throws Exception {
ospfController.activate();
assertThat(ospfController, is(notNullValue()));
}
@Test(expected = Exception.class)
public void testDeactivate() throws Exception {
ospfController.activate();
ospfController.deactivate();
assertThat(ospfController, is(notNullValue()));
}
/**
* Tests addRouterListener() method.
*/
@Test
public void testAddRouterListener() throws Exception {
ospfRouterListener = EasyMock.createMock(OspfRouterListener.class);
ospfController.addRouterListener(ospfRouterListener);
assertThat(ospfController, is(notNullValue()));
}
/**
* Tests removeRouterListener() method.
*/
@Test
public void testRemoveRouterListener() throws Exception {
ospfRouterListener = EasyMock.createMock(OspfRouterListener.class);
ospfController.addRouterListener(ospfRouterListener);
ospfController.removeRouterListener(ospfRouterListener);
assertThat(ospfController, is(notNullValue()));
}
/**
* Tests addLinkListener() method.
*/
@Test
public void testAddLinkListener() throws Exception {
ospfLinkListener = EasyMock.createMock(OspfLinkListener.class);
ospfController.addLinkListener(ospfLinkListener);
assertThat(ospfController, is(notNullValue()));
}
/**
* Tests removeLinkListener() method.
*/
@Test
public void testRemoveLinkListener() throws Exception {
ospfLinkListener = EasyMock.createMock(OspfLinkListener.class);
ospfController.addLinkListener(ospfLinkListener);
ospfController.removeLinkListener(ospfLinkListener);
assertThat(ospfController, is(notNullValue()));
}
/**
* Tests updateConfig() method.
*/
@Test
public void testUpdateConfig() throws Exception {
ospfProcess = new OspfProcessImpl();
ospfArea = new OspfAreaImpl();
ospfInterface = new OspfInterfaceImpl();
ospfInterfaces = new ArrayList();
ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
ospfInterfaces.add(ospfInterface);
ospfArea.setAreaId(Ip4Address.valueOf("2.2.2.2"));
ospfArea.setInterfacesLst(ospfInterfaces);
ospfProcess.setProcessId("10.10.10.10");
areas = new ArrayList();
areas.add(ospfArea);
ospfProcess.setAreas(areas);
ospfProcesses = new ArrayList();
ospfProcesses.add(ospfProcess);
process1 = new OspfProcessImpl();
process1.setProcessId("11.11.11.11");
ospfArea1 = new OspfAreaImpl();
ospfArea1.setAreaId(Ip4Address.valueOf("2.2.2.2"));
ospfArea1.setInterfacesLst(ospfInterfaces);
areas.add(ospfArea1);
process1.setAreas(areas);
ospfProcesses.add(process1);
ospfController.updateConfig(ospfProcesses);
assertThat(ospfController, is(notNullValue()));
}
/**
* Tests deleteConfig() method.
*/
@Test
public void testDeleteConfig() throws Exception {
ospfProcess = new OspfProcessImpl();
ospfArea = new OspfAreaImpl();
ospfInterface = new OspfInterfaceImpl();
ospfInterfaces = new ArrayList();
ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.5"));
ospfInterfaces.add(ospfInterface);
ospfArea.setAreaId(Ip4Address.valueOf("2.2.2.2"));
ospfArea.setInterfacesLst(ospfInterfaces);
ospfProcess.setProcessId("10.10.10.10");
areas = new ArrayList();
areas.add(ospfArea);
ospfProcess.setAreas(areas);
ospfProcesses = new ArrayList();
ospfProcesses.add(ospfProcess);
process1 = new OspfProcessImpl();
process1.setProcessId("11.11.11.11");
ospfArea1 = new OspfAreaImpl();
ospfArea1.setAreaId(Ip4Address.valueOf("2.2.2.2"));
ospfArea1.setInterfacesLst(ospfInterfaces);
areas.add(ospfArea1);
process1.setAreas(areas);
ospfProcesses.add(process1);
ospfController.deleteConfig(ospfProcesses, "INTERFACE");
assertThat(ospfController, is(notNullValue()));
}
/**
* Tests addLink() method.
*/
@Test
public void testAddLink() throws Exception {
ospfRouter = new OspfRouterImpl();
ospfController.agent.addLink(ospfRouter, new OspfLinkTedImpl());
assertThat(ospfController, is(notNullValue()));
}
/**
* Tests deleteLink() method.
*/
@Test
public void testDeleteLink() throws Exception {
ospfRouter = new OspfRouterImpl();
ospfController.agent.addLink(ospfRouter, new OspfLinkTedImpl());
ospfController.agent.deleteLink(ospfRouter);
assertThat(ospfController, is(notNullValue()));
}
/**
* Tests listener() method.
*/
@Test
public void testListener() throws Exception {
assertThat(ospfController.listener().size(), is(0));
}
/**
* Tests linkListener() method.
*/
@Test
public void testLinkListener() throws Exception {
assertThat(ospfController.linkListener().size(), is(0));
}
/**
* Tests addConnectedRouter() method.
*/
@Test
public void testaddConnectedRouter() throws Exception {
ospfRouter = new OspfRouterImpl();
ospfController.agent.addConnectedRouter(ospfRouter);
assertThat(ospfController, is(notNullValue()));
}
/**
* Tests removeConnectedRouter() method.
*/
@Test
public void testRemoveConnectedRouter() throws Exception {
ospfRouter = new OspfRouterImpl();
ospfController.agent.addConnectedRouter(ospfRouter);
ospfController.agent.removeConnectedRouter(ospfRouter);
assertThat(ospfController, is(notNullValue()));
}
/**
* Tests getAllConfiguredProcesses() method.
*/
@Test(expected = Exception.class)
public void testGetAllConfiguredProcesses() throws Exception {
assertThat(ospfController.getAllConfiguredProcesses().size(), is(0));
}
}
\ No newline at end of file
/*
* 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.impl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip6Address;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
/**
* Unit test class for OspfDeviceTedImpl.
*/
public class OspfDeviceTedImplTest {
private OspfDeviceTedImpl ospfDeviceTed;
@Before
public void setUp() throws Exception {
ospfDeviceTed = new OspfDeviceTedImpl();
}
@After
public void tearDown() throws Exception {
ospfDeviceTed = null;
}
/**
* Tests ipv4RouterIds() getter method.
*/
@Test
public void testIpv4RouterIds() throws Exception {
List list = new ArrayList();
list.add(Ip4Address.valueOf("1.1.1.1"));
ospfDeviceTed.setIpv4RouterIds(list);
assertThat(ospfDeviceTed.ipv4RouterIds().size(), is(1));
}
/**
* Tests ipv4RouterIds() setter method.
*/
@Test
public void testSetIpv4RouterIds() throws Exception {
List list = new ArrayList();
list.add(Ip4Address.valueOf("1.1.1.1"));
ospfDeviceTed.setIpv4RouterIds(list);
assertThat(ospfDeviceTed.ipv4RouterIds().size(), is(1));
}
/**
* Tests abr() getter method.
*/
@Test
public void testAbr() throws Exception {
ospfDeviceTed.setAbr(true);
assertThat(ospfDeviceTed.abr(), is(true));
}
/**
* Tests abr() setter method.
*/
@Test
public void testSetAbr() throws Exception {
ospfDeviceTed.setAbr(true);
assertThat(ospfDeviceTed.abr(), is(true));
}
/**
* Tests asbr() getter method.
*/
@Test
public void testAsbr() throws Exception {
ospfDeviceTed.setAsbr(true);
assertThat(ospfDeviceTed.asbr(), is(true));
}
/**
* Tests asbr() setter method.
*/
@Test
public void testSetAsbr() throws Exception {
ospfDeviceTed.setAsbr(true);
assertThat(ospfDeviceTed.asbr(), is(true));
}
/**
* Tests topologyIds() getter method.
*/
@Test
public void testTopologyIds() throws Exception {
List list = new ArrayList();
list.add(Ip4Address.valueOf("1.1.1.1"));
ospfDeviceTed.setTopologyIds(list);
assertThat(ospfDeviceTed.topologyIds().size(), is(1));
}
/**
* Tests topologyIds() setter method.
*/
@Test
public void testSetTopologyIds() throws Exception {
List list = new ArrayList();
list.add(Ip4Address.valueOf("1.1.1.1"));
ospfDeviceTed.setTopologyIds(list);
assertThat(ospfDeviceTed.topologyIds().size(), is(1));
}
/**
* Tests ipv6RouterIds() getter method.
*/
@Test(expected = Exception.class)
public void testIpv6RouterIds() throws Exception {
List list = new ArrayList();
list.add(Ip6Address.valueOf(InetAddress.getLocalHost()));
ospfDeviceTed.setIpv6RouterIds(list);
assertThat(ospfDeviceTed.ipv6RouterIds().size(), is(1));
}
/**
* Tests ipv6RouterIds() setter method.
*/
@Test(expected = Exception.class)
public void testSetIpv6RouterIds() throws Exception {
List list = new ArrayList();
list.add(Ip6Address.valueOf(InetAddress.getLocalHost()));
ospfDeviceTed.setIpv6RouterIds(list);
assertThat(ospfDeviceTed.ipv6RouterIds().size(), is(1));
}
}
\ No newline at end of file
/*
* 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.impl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ip4Address;
import org.onlab.util.Bandwidth;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
/**
* Unit test class for OspfDeviceTedImpl.
*/
public class OspfLinkTedImplTest {
private OspfLinkTedImpl ospfLinkTed;
@Before
public void setUp() throws Exception {
ospfLinkTed = new OspfLinkTedImpl();
}
@After
public void tearDown() throws Exception {
ospfLinkTed = null;
}
/**
* Tests maximumLink() getter method.
*/
@Test
public void testMaximumLink() throws Exception {
ospfLinkTed.setMaximumLink(Bandwidth.bps(1234));
assertThat(ospfLinkTed.maximumLink(), is(Bandwidth.bps(1234)));
}
/**
* Tests maximumLink() setter method.
*/
@Test
public void testSetMaximumLink() throws Exception {
ospfLinkTed.setMaximumLink(Bandwidth.bps(1234));
assertThat(ospfLinkTed.maximumLink(), is(Bandwidth.bps(1234)));
}
/**
* Tests ipv6RemRouterId() getter method.
*/
@Test
public void testIpv6RemRouterId() throws Exception {
List list = new ArrayList();
ospfLinkTed.setIpv6RemRouterId(list);
assertThat(ospfLinkTed.ipv6RemRouterId().size(), is(0));
}
/**
* Tests ipv6RemRouterId() setter method.
*/
@Test
public void testSetIpv6RemRouterId() throws Exception {
List list = new ArrayList();
ospfLinkTed.setIpv6RemRouterId(list);
assertThat(ospfLinkTed.ipv6RemRouterId().size(), is(0));
}
/**
* Tests ipv4RemRouterId() getter method.
*/
@Test
public void testIpv4RemRouterId() throws Exception {
List list = new ArrayList();
list.add(Ip4Address.valueOf(InetAddress.getLocalHost()));
ospfLinkTed.setIpv4RemRouterId(list);
assertThat(ospfLinkTed.ipv4RemRouterId().size(), is(1));
}
/**
* Tests ipv4RemRouterId() setter method.
*/
@Test
public void testSetIpv4RemRouterId() throws Exception {
List list = new ArrayList();
list.add(Ip4Address.valueOf(InetAddress.getLocalHost()));
ospfLinkTed.setIpv4RemRouterId(list);
assertThat(ospfLinkTed.ipv4RemRouterId().size(), is(1));
}
/**
* Tests ipv6LocRouterId() getter method.
*/
@Test
public void testIpv6LocRouterId() throws Exception {
List list = new ArrayList();
ospfLinkTed.setIpv4LocRouterId(list);
assertThat(ospfLinkTed.ipv6LocRouterId().size(), is(0));
}
/**
* Tests ipv6LocRouterId() setter method.
*/
@Test
public void testSetIpv6LocRouterId() throws Exception {
List list = new ArrayList();
ospfLinkTed.setIpv4LocRouterId(list);
assertThat(ospfLinkTed.ipv6LocRouterId().size(), is(0));
}
/**
* Tests ipv4LocRouterId() getter method.
*/
@Test
public void testIpv4LocRouterId() throws Exception {
List list = new ArrayList();
list.add(Ip4Address.valueOf(InetAddress.getLocalHost()));
ospfLinkTed.setIpv4LocRouterId(list);
assertThat(ospfLinkTed.ipv4LocRouterId().size(), is(1));
}
/**
* Tests ipv4LocRouterId() setter method.
*/
@Test
public void testSetIpv4LocRouterId() throws Exception {
List list = new ArrayList();
list.add(Ip4Address.valueOf(InetAddress.getLocalHost()));
ospfLinkTed.setIpv4LocRouterId(list);
assertThat(ospfLinkTed.ipv4LocRouterId().size(), is(1));
}
/**
* Tests teMetric() getter method.
*/
@Test
public void testTeMetric() throws Exception {
ospfLinkTed.setTeMetric(1234);
assertThat(ospfLinkTed.teMetric(), is(1234));
}
/**
* Tests teMetric() setter method.
*/
@Test
public void testSetTeMetric() throws Exception {
ospfLinkTed.setTeMetric(1234);
assertThat(ospfLinkTed.teMetric(), is(1234));
}
/**
* Tests maxReserved() getter method.
*/
@Test
public void testMaxReserved() throws Exception {
ospfLinkTed.setMaxReserved(Bandwidth.bps(1234));
assertThat(ospfLinkTed.maxReserved(), is(Bandwidth.bps(1234)));
}
/**
* Tests maxReserved() setter method.
*/
@Test
public void testSetMaxReserved() throws Exception {
ospfLinkTed.setMaxReserved(Bandwidth.bps(1234));
assertThat(ospfLinkTed.maxReserved(), is(Bandwidth.bps(1234)));
}
/**
* Tests maxUnResBandwidth() getter method.
*/
@Test
public void testMaxUnResBandwidth() throws Exception {
ospfLinkTed.setMaxUnResBandwidth(Bandwidth.bps(1234));
assertThat(ospfLinkTed.maxUnResBandwidth(), is(notNullValue()));
}
/**
* Tests maxUnResBandwidth() setter method.
*/
@Test
public void testSetMaxUnResBandwidth() throws Exception {
ospfLinkTed.setMaxUnResBandwidth(Bandwidth.bps(1234.0));
assertThat(ospfLinkTed.maxUnResBandwidth(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* 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.impl;
import org.easymock.EasyMock;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* Unit test class for OspfMessageDecoder.
*/
public class OspfMessageDecoderTest {
private final byte[] hellopacket = {0, 0, 0, 0, 2, 1, 0, 44, -64, -88, -86, 8, 0, 0, 0, 1, 39, 59,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 10, 2, 1, 0, 0, 0,
40, -64, -88, -86, 8, 0, 0, 0, 0};
private final byte[] ddpacket = {0, 0, 0, 0, 2, 2, 0, 32, -64, -88, -86, 8, 0, 0, 0, 1, -96, 82,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -36, 2, 7, 65, 119, -87, 126};
private final byte[] ddpacket44 = {0, 0, 0, 0, 2, 2, 0, 10, -64, -88};
private final byte[] lsAckpacket = {0, 0, 0, 0, 2, 5, 0, 44, -64, -88, -86, 8, 0, 0, 0, 1, -30, -12,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 16, 2, 1, -64, -88, -86, 2, -64,
-88, -86, 2, -128, 0, 0, 1, 74, -114, 0, 48};
private final byte[] lsUpdatePacket = {0, 0, 0, 0, 2, 4, 0, 76, -64, -88, -86, 3, 0, 0, 0, 1, 7, 111,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 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[] lsRequestPacket = {0, 0, 0, 0, 2, 3, 0, 36, -64, -88, -86, 3, 0, 0, 0, 1, -67, -57,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -64, -88, -86, 8, -64, -88, -86, 8};
private OspfMessageDecoder ospfMessageDecoder;
private ChannelHandlerContext ctx;
private Channel channel;
private SocketAddress socketAddress;
private ChannelBuffer channelBuffer;
@Before
public void setUp() throws Exception {
ospfMessageDecoder = new OspfMessageDecoder();
}
@After
public void tearDown() throws Exception {
ospfMessageDecoder = null;
channel = null;
socketAddress = null;
channelBuffer = null;
}
/**
* Tests decode() method.
*/
@Test
public void testDecode() throws Exception {
channel = EasyMock.createMock(Channel.class);
socketAddress = InetSocketAddress.createUnresolved("127.0.0.1", 7000);
channelBuffer = ChannelBuffers.copiedBuffer(hellopacket);
assertThat(ospfMessageDecoder.decode(ctx, channel, channelBuffer), is(nullValue()));
}
}
\ No newline at end of file
/*
* 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.impl;
import org.easymock.EasyMock;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ip4Address;
import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket;
import org.onosproject.ospf.protocol.ospfpacket.types.HelloPacket;
import org.onosproject.ospf.protocol.ospfpacket.types.LsAcknowledge;
import org.onosproject.ospf.protocol.ospfpacket.types.LsRequest;
import org.onosproject.ospf.protocol.ospfpacket.types.LsUpdate;
import org.onosproject.ospf.protocol.util.OspfInterfaceState;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* Created by sdn on 13/1/16.
*/
public class OspfMessageEncoderTest {
private final byte[] hpacket = {2, 1, 0, 44, -64, -88, -86, 8, 0, 0, 0, 1, 39, 59,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 10, 2, 1, 0, 0, 0,
40, -64, -88, -86, 8, 0, 0, 0, 0};
private final byte[] dpacket = {2, 2, 0, 32, -64, -88, -86, 8, 0, 0, 0, 1, -96, 82,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -36, 2, 7, 65, 119, -87, 126};
private final byte[] lrpacket = {2, 3, 0, 36, -64, -88, -86, 3, 0, 0, 0, 1, -67, -57,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -64, -88, -86, 8, -64, -88, -86, 8};
private byte[] lAckpacket = {2, 5, 0, 44, -64, -88, -86, 8, 0, 0, 0, 1, -30, -12,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 16, 2, 1, -64, -88, -86, 2, -64,
-88, -86, 2, -128, 0, 0, 1, 74, -114, 0, 48};
private HelloPacket helloPacket;
private DdPacket ddPacket;
private LsAcknowledge lsAcknowledge;
private LsRequest lsRequest;
private LsUpdate lsUpdate;
private ChannelHandlerContext ctx;
private OspfMessageEncoder ospfMessageEncoder;
private ChannelBuffer buf;
private SocketAddress socketAddress;
private Channel channel;
@Before
public void setUp() throws Exception {
ospfMessageEncoder = new OspfMessageEncoder();
helloPacket = new HelloPacket();
ddPacket = new DdPacket();
lsAcknowledge = new LsAcknowledge();
lsRequest = new LsRequest();
lsUpdate = new LsUpdate();
helloPacket.setOspftype(1);
ddPacket.setOspftype(2);
lsAcknowledge.setOspftype(5);
lsRequest.setOspftype(3);
lsUpdate.setOspftype(4);
OspfInterfaceImpl ospfInterface = new OspfInterfaceImpl();
ospfInterface.setState(OspfInterfaceState.DROTHER);
ospfMessageEncoder = new OspfMessageEncoder(ospfInterface);
}
@After
public void tearDown() throws Exception {
helloPacket = null;
ddPacket = null;
lsAcknowledge = null;
lsRequest = null;
lsUpdate = null;
ospfMessageEncoder = null;
buf = null;
}
/**
* Tests encode() method.
*/
@Test
public void testEncode() throws Exception {
socketAddress = InetSocketAddress.createUnresolved("127.0.0.1", 8600);
channel = EasyMock.createMock(Channel.class);
helloPacket = new HelloPacket();
helloPacket.setDestinationIp(Ip4Address.valueOf("15.15.15.15"));
buf = ChannelBuffers.buffer(hpacket.length);
buf.writeBytes(hpacket);
helloPacket.readFrom(buf);
ospfMessageEncoder.encode(ctx, channel, helloPacket);
ddPacket = new DdPacket();
ddPacket.setDestinationIp(Ip4Address.valueOf("15.15.15.15"));
buf = ChannelBuffers.buffer(dpacket.length);
buf.writeBytes(dpacket);
ddPacket.readFrom(buf);
ospfMessageEncoder.encode(ctx, channel, ddPacket);
lsRequest = new LsRequest();
lsRequest.setDestinationIp(Ip4Address.valueOf("15.15.15.15"));
buf = ChannelBuffers.buffer(lrpacket.length);
buf.writeBytes(lrpacket);
lsRequest.readFrom(buf);
ospfMessageEncoder.encode(ctx, channel, lsRequest);
lsAcknowledge = new LsAcknowledge();
lsAcknowledge.setDestinationIp(Ip4Address.valueOf("15.15.15.15"));
buf = ChannelBuffers.buffer(lAckpacket.length);
buf.writeBytes(lAckpacket);
lsAcknowledge.readFrom(buf);
ospfMessageEncoder.encode(ctx, channel, lsAcknowledge);
assertThat(ospfMessageEncoder, is(notNullValue()));
}
}
\ No newline at end of file
/*
* 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.impl;
import org.jboss.netty.channel.ChannelPipeline;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.ospf.controller.area.OspfAreaImpl;
import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* Unit test class for OspfPipelineFactory.
*/
public class OspfPipelineFactoryTest {
private OspfPipelineFactory ospfPipelineFactory;
private ChannelPipeline channelPipeline;
@Before
public void setUp() throws Exception {
ospfPipelineFactory = new OspfPipelineFactory(new Controller(), new OspfAreaImpl(), new OspfInterfaceImpl());
}
@After
public void tearDown() throws Exception {
ospfPipelineFactory = null;
channelPipeline = null;
}
/**
* Tests getPipeline() method.
*/
@Test
public void testGetPipeline() throws Exception {
channelPipeline = ospfPipelineFactory.getPipeline();
assertThat(channelPipeline, is(notNullValue()));
}
/**
* Tests releaseExternalResources() method.
*/
@Test
public void testReleaseExternalResources() throws Exception {
ospfPipelineFactory.releaseExternalResources();
assertThat(channelPipeline, is(nullValue()));
}
}
\ No newline at end of file
/*
* 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.impl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
import org.onosproject.ospf.controller.OspfDeviceTed;
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 OspfRouterImpl.
*/
public class OspfRouterImplTest {
private OspfRouterImpl ospfRouter;
private OspfDeviceTed ospfDeviceTed;
private List<OspfDeviceTed> list;
@Before
public void setUp() throws Exception {
ospfRouter = new OspfRouterImpl();
}
@After
public void tearDown() throws Exception {
ospfRouter = null;
}
/**
* Tests routerIp() getter method.
*/
@Test
public void testRouterIp() throws Exception {
ospfRouter.setRouterIp(Ip4Address.valueOf("1.1.1.1"));
assertThat(ospfRouter.routerIp(), is(IpAddress.valueOf("1.1.1.1")));
}
/**
* Tests routerIp() setter method.
*/
@Test
public void testSetRouterIp() throws Exception {
ospfRouter.setRouterIp(Ip4Address.valueOf("1.1.1.1"));
assertThat(ospfRouter.routerIp(), is(IpAddress.valueOf("1.1.1.1")));
}
/**
* Tests areaIdOfInterface() getter method.
*/
@Test
public void testAreaIdOfInterface() throws Exception {
ospfRouter.setAreaIdOfInterface(Ip4Address.valueOf("1.1.1.1"));
assertThat(ospfRouter.areaIdOfInterface(), is(IpAddress.valueOf("1.1.1.1")));
}
/**
* Tests areaIdOfInterface() setter method.
*/
@Test
public void testSetAreaIdOfInterface() throws Exception {
ospfRouter.setAreaIdOfInterface(Ip4Address.valueOf("1.1.1.1"));
assertThat(ospfRouter.areaIdOfInterface(), is(IpAddress.valueOf("1.1.1.1")));
}
/**
* Tests interfaceId() getter method.
*/
@Test
public void testInterfaceId() throws Exception {
ospfRouter.setInterfaceId(Ip4Address.valueOf("1.1.1.1"));
assertThat(ospfRouter.interfaceId(), is(IpAddress.valueOf("1.1.1.1")));
}
/**
* Tests interfaceId() setter method.
*/
@Test
public void testSetInterfaceId() throws Exception {
ospfRouter.setInterfaceId(Ip4Address.valueOf("1.1.1.1"));
assertThat(ospfRouter.interfaceId(), is(IpAddress.valueOf("1.1.1.1")));
}
/**
* Tests isDr() setter method.
*/
@Test
public void testSetDr() throws Exception {
ospfRouter.setDr(true);
assertThat(ospfRouter.isDr(), is(true));
}
/**
* Tests isDr() getter method.
*/
@Test
public void testIsDr() throws Exception {
ospfRouter.setDr(true);
assertThat(ospfRouter.isDr(), is(true));
}
/**
* Tests isOpaque() setter method.
*/
@Test
public void testSetOpaque() throws Exception {
ospfRouter.setOpaque(true);
assertThat(ospfRouter.isOpaque(), is(true));
}
/**
* Tests isOpaque() getter method.
*/
@Test
public void testisOpaque() throws Exception {
ospfRouter.setOpaque(true);
assertThat(ospfRouter.isOpaque(), is(true));
}
/**
* Tests deviceTed() getter method.
*/
@Test
public void testDeviceTed() throws Exception {
ospfRouter.setDeviceTed(new OspfDeviceTedImpl());
assertThat(ospfRouter.deviceTed(), is(notNullValue()));
}
/**
* Tests deviceTed() Setter method.
*/
@Test
public void testSetDeviceTed() throws Exception {
ospfRouter.setDeviceTed(new OspfDeviceTedImpl());
assertThat(ospfRouter.deviceTed(), is(notNullValue()));
}
/**
* Tests neighborRouterId() getter method.
*/
@Test
public void testNeighborRouterId() throws Exception {
ospfRouter.setNeighborRouterId(Ip4Address.valueOf("1.1.1.1"));
assertThat(ospfRouter.neighborRouterId(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests neighborRouterId() Setter method.
*/
@Test
public void testSetNeighborRouterId() throws Exception {
ospfRouter.setNeighborRouterId(Ip4Address.valueOf("1.1.1.1"));
assertThat(ospfRouter.neighborRouterId(), is(Ip4Address.valueOf("1.1.1.1")));
}
}
\ No newline at end of file