sunish vk
Committed by Thomas Vachuska

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

Change-Id: I18972a0712fbd63798f92da7b4c48381b4a38519
/*
* 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.buffer.HeapChannelBufferFactory;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelConfig;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ip4Address;
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.area.OspfAreaAddressRangeImpl;
import org.onosproject.ospf.controller.area.OspfAreaImpl;
import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
import org.onosproject.ospf.controller.util.OspfEligibleRouter;
import org.onosproject.ospf.exceptions.OspfParseException;
import org.onosproject.ospf.protocol.lsa.LsaHeader;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import org.onosproject.ospf.protocol.lsa.tlvtypes.RouterTlv;
import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
import org.onosproject.ospf.protocol.ospfpacket.OspfMessage;
import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket;
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.ChecksumCalculator;
import org.onosproject.ospf.protocol.util.OspfInterfaceState;
import java.net.SocketAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
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 OspfInterfaceChannelHandler.
*/
public class OspfInterfaceChannelHandlerTest {
private List<OspfAreaAddressRange> addressRanges;
private List<OspfInterface> ospfInterfaces;
private Controller controller;
private OspfAreaImpl ospfArea;
private OspfInterfaceImpl ospfInterface;
private OspfInterfaceChannelHandler ospfInterfaceChannelHandler;
private HashMap<String, OspfNbr> ospfNbrHashMap;
private OspfNbrImpl ospfNbr;
private Channel channel;
private ChannelHandlerContext channelHandlerContext;
private ChannelStateEvent channelStateEvent;
private HelloPacket helloPacket;
private DdPacket ddPacket;
private ChecksumCalculator checksumCalculator;
private byte[] byteArray;
private byte[] checkArray;
private ChannelBuffer buf;
private OspfEligibleRouter ospfEligibleRouter;
private LsUpdate lsUpdate;
private LsAcknowledge lsAck;
private LsRequest lsRequest;
private TopologyForDeviceAndLink topologyForDeviceAndLink;
@Before
public void setUp() throws Exception {
addressRanges = new ArrayList();
ospfInterfaces = new ArrayList<>();
ospfArea = createOspfArea();
ospfInterface = createOspfInterface();
ospfNbrHashMap = new HashMap();
topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl();
ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"),
Ip4Address.valueOf("2.2.2.2"), 2,
new OspfInterfaceChannelHandler(new Controller(), ospfArea,
ospfInterface)
, topologyForDeviceAndLink);
ospfNbr.setNeighborId(Ip4Address.valueOf("10.10.10.10"));
ospfNbr.setRouterPriority(0);
ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
ospfInterface.addNeighbouringRouter(ospfNbr);
controller = new Controller();
ospfInterfaceChannelHandler = new OspfInterfaceChannelHandler();
ospfInterfaceChannelHandler = new OspfInterfaceChannelHandler(controller, ospfArea,
ospfInterface);
}
@After
public void tearDown() throws Exception {
ospfInterfaceChannelHandler = null;
addressRanges = null;
ospfInterfaces = null;
controller = null;
ospfArea = null;
ospfInterfaceChannelHandler = null;
ospfInterface = null;
ospfNbrHashMap = null;
channel = null;
channelHandlerContext = null;
channelStateEvent = null;
helloPacket = null;
ddPacket = null;
checksumCalculator = null;
byteArray = null;
checkArray = null;
ospfEligibleRouter = null;
lsUpdate = null;
lsAck = null;
lsRequest = null;
}
/**
* Tests interfaceUp() method.
*/
@Test
public void testInterfaceUp() throws Exception {
ospfInterface.setInterfaceType(2);
ospfInterface.setRouterPriority(0);
ospfInterfaceChannelHandler.interfaceUp();
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
/**
* Tests interfaceUp() method.
*/
@Test
public void testInterfaceUp1() throws Exception {
ospfInterface.setInterfaceType(2);
ospfInterface.setRouterPriority(0);
ospfInterfaceChannelHandler.interfaceUp();
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
/**
* Tests interfaceUp() method.
*/
@Test
public void testInterfaceUp2() throws Exception {
ospfInterface.setInterfaceType(1);
ospfInterface.setRouterPriority(1);
ospfInterfaceChannelHandler.interfaceUp();
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
/**
* Tests interfaceUp() method.
*/
@Test
public void testInterfaceUp3() throws Exception {
ospfInterface.setInterfaceType(2);
ospfInterface.setRouterPriority(1);
ospfInterfaceChannelHandler.interfaceUp();
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
/**
* Tests backupSeen() method.
*/
@Test
public void testBackupSeen() throws Exception {
channel = EasyMock.createMock(Channel.class);
ospfInterface.setState(OspfInterfaceState.WAITING);
ospfInterfaceChannelHandler.backupSeen(channel);
assertThat(ospfInterface.dr(), is(notNullValue()));
}
/**
* Tests waitTimer() method.
*/
@Test
public void testWaitTimer() throws Exception {
channel = EasyMock.createMock(Channel.class);
ospfInterface.setState(OspfInterfaceState.WAITING);
ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.10"));
ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
ospfInterfaceChannelHandler.waitTimer(channel);
assertThat(ospfInterface.dr(), is(notNullValue()));
}
/**
* Tests neighborChange() method.
*/
@Test
public void testNeighborChange() throws Exception {
ospfNbrHashMap = 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.setNeighborId(Ip4Address.valueOf("111.111.111.111"));
ospfNbrHashMap.put("111.111.111.111", ospfNbr);
ospfNbr.setState(OspfNeighborState.EXCHANGE);
ospfInterface.setListOfNeighbors(ospfNbrHashMap);
ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.10"));
ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.10"));
ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
channel = EasyMock.createMock(Channel.class);
ospfInterface.setState(OspfInterfaceState.DR);
ospfInterfaceChannelHandler.waitTimer(channel);
assertThat(ospfInterface.dr(), is(Ip4Address.valueOf("0.0.0.0")));
}
/**
* Tests interfaceDown() method.
*/
@Test(expected = Exception.class)
public void testInterfaceDown() throws Exception {
ospfInterfaceChannelHandler.interfaceDown();
assertThat(ospfInterface.state(), is(OspfInterfaceState.DOWN));
}
/**
* Tests channelConnected() method.
*/
@Test(expected = Exception.class)
public void testChannelConnected() throws Exception {
channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
channelStateEvent = EasyMock.createMock(ChannelStateEvent.class);
ospfInterfaceChannelHandler.channelConnected(channelHandlerContext, channelStateEvent);
assertThat(ospfInterface.state(), is(notNullValue()));
}
/**
* Tests exceptionCaught() method.
*/
@Test(expected = Exception.class)
public void testExceptionCaught() throws Exception {
channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
ExceptionEvent exception = EasyMock.createMock(ExceptionEvent.class);
ospfInterfaceChannelHandler.exceptionCaught(channelHandlerContext, exception);
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
/**
* Tests channelDisconnected() method.
*/
@Test(expected = Exception.class)
public void testChannelDisconnected() throws Exception {
channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
channelStateEvent = EasyMock.createMock(ChannelStateEvent.class);
ospfInterfaceChannelHandler.channelDisconnected(channelHandlerContext, channelStateEvent);
assertThat(ospfInterface.state(), is(notNullValue()));
}
/**
* Tests messageReceived() method.
*/
@Test
public void testMessageReceived() throws Exception {
ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
ospfInterface.setInterfaceType(2);
ospfArea.setAreaId(Ip4Address.valueOf("13.13.13.13"));
channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
MessageEvent messageEvent = new MessageEvent() {
@Override
public Object getMessage() {
helloPacket = new HelloPacket();
helloPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
helloPacket.setRouterId(Ip4Address.valueOf("10.10.10.10"));
helloPacket.setOspfVer(2);
helloPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
helloPacket.setOptions(2);
helloPacket.setAreaId(Ip4Address.valueOf("5.5.5.5"));
helloPacket.setNetworkMask(Ip4Address.valueOf("3.3.3.3"));
helloPacket.setOspftype(1);
helloPacket.setAuthType(0);
helloPacket.setAuthentication(0);
checksumCalculator = new ChecksumCalculator();
byteArray = helloPacket.asBytes();
helloPacket.setOspfPacLength(byteArray.length);
checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13);
buf = ChannelBuffers.copiedBuffer(checkArray);
helloPacket.setChecksum(buf.readUnsignedShort());
List<HelloPacket> messPackets = new ArrayList<>();
messPackets.add(helloPacket);
return messPackets;
}
@Override
public SocketAddress getRemoteAddress() {
return null;
}
@Override
public Channel getChannel() {
return null;
}
@Override
public ChannelFuture getFuture() {
return null;
}
};
ospfInterfaceChannelHandler.messageReceived(channelHandlerContext, messageEvent);
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
/**
* Tests processOSPFMessage() method.
*/
@Test
public void testProcessOSPFMessage() throws Exception {
ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
ospfInterface.setIpNetworkMask(Ip4Address.valueOf("225.225.225.225"));
ospfInterface.setInterfaceType(2);
ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
OspfMessage message;
helloPacket = new HelloPacket();
helloPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
helloPacket.setRouterId(Ip4Address.valueOf("10.10.10.10"));
helloPacket.setOspfVer(2);
helloPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
helloPacket.setOptions(2);
helloPacket.setNetworkMask(Ip4Address.valueOf("3.3.3.3"));
helloPacket.setOspftype(1);
helloPacket.setAuthType(0);
helloPacket.setHelloInterval(60);
helloPacket.setRouterDeadInterval(60);
helloPacket.setAuthentication(0);
checksumCalculator = new ChecksumCalculator();
byteArray = helloPacket.asBytes();
helloPacket.setOspfPacLength(byteArray.length);
checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13);
checkArray[0] = -53;
checkArray[1] = 37;
buf = ChannelBuffers.copiedBuffer(checkArray);
helloPacket.setChecksum(buf.readUnsignedShort());
message = helloPacket;
ospfInterfaceChannelHandler.processOSPFMessage(message, channelHandlerContext);
ddPacket = new DdPacket();
ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
ddPacket.setRouterId(Ip4Address.valueOf("10.10.10.10"));
ddPacket.setOspfVer(2);
ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
ddPacket.setOptions(2);
ddPacket.setOspftype(2);
ddPacket.setAuthType(0);
ddPacket.setAuthentication(0);
checksumCalculator = new ChecksumCalculator();
byteArray = ddPacket.asBytes();
ddPacket.setOspfPacLength(byteArray.length);
checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13);
checkArray[0] = -49;
checkArray[1] = -79;
buf = ChannelBuffers.copiedBuffer(checkArray);
ddPacket.setChecksum(buf.readUnsignedShort());
message = ddPacket;
ospfInterfaceChannelHandler.processOSPFMessage(message, channelHandlerContext);
lsRequest = new LsRequest();
lsRequest.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
lsRequest.setRouterId(Ip4Address.valueOf("10.10.10.10"));
lsRequest.setOspfVer(2);
lsRequest.setAreaId(Ip4Address.valueOf("12.12.12.12"));
lsRequest.setOspftype(3);
lsRequest.setAuthType(0);
lsRequest.setAuthentication(0);
checksumCalculator = new ChecksumCalculator();
byteArray = lsRequest.asBytes();
lsRequest.setOspfPacLength(byteArray.length);
checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13);
checkArray[0] = -33;
checkArray[1] = -58;
buf = ChannelBuffers.copiedBuffer(checkArray);
lsRequest.setChecksum(buf.readUnsignedShort());
message = lsRequest;
ospfInterfaceChannelHandler.processOSPFMessage(message, channelHandlerContext);
lsUpdate = new LsUpdate();
lsUpdate.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
lsUpdate.setRouterId(Ip4Address.valueOf("10.10.10.10"));
lsUpdate.setOspfVer(2);
lsUpdate.setAreaId(Ip4Address.valueOf("12.12.12.12"));
lsUpdate.setOspftype(4);
lsUpdate.setAuthType(0);
lsUpdate.setAuthentication(0);
checksumCalculator = new ChecksumCalculator();
byteArray = lsUpdate.asBytes();
lsUpdate.setOspfPacLength(byteArray.length);
checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13);
checkArray[0] = -47;
checkArray[1] = -77;
buf = ChannelBuffers.copiedBuffer(checkArray);
lsUpdate.setChecksum(buf.readUnsignedShort());
message = lsUpdate;
ospfInterfaceChannelHandler.processOSPFMessage(message, channelHandlerContext);
lsAck = new LsAcknowledge();
lsAck.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
lsAck.setRouterId(Ip4Address.valueOf("10.10.10.10"));
lsAck.setOspfVer(2);
lsAck.setAreaId(Ip4Address.valueOf("12.12.12.12"));
lsAck.setOspftype(5);
lsAck.setAuthType(0);
lsAck.setAuthentication(0);
checksumCalculator = new ChecksumCalculator();
byteArray = lsAck.asBytes();
lsAck.setOspfPacLength(byteArray.length);
checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13);
checkArray[0] = -47;
checkArray[1] = -74;
buf = ChannelBuffers.copiedBuffer(checkArray);
lsAck.setChecksum(buf.readUnsignedShort());
message = lsAck;
ospfInterfaceChannelHandler.processOSPFMessage(message, channelHandlerContext);
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
/**
* Tests processHelloMessage() method.
*/
@Test
public void testProcessHelloMessage() throws Exception {
ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
ospfInterface.setInterfaceType(1);
ospfInterface.setIpNetworkMask(Ip4Address.valueOf("244.244.244.244"));
ospfInterface.setHelloIntervalTime(10);
ospfInterface.setRouterDeadIntervalTime(10);
ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
OspfMessage message;
helloPacket = new HelloPacket();
helloPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
helloPacket.setOspfVer(2);
helloPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
helloPacket.setNetworkMask(Ip4Address.valueOf("244.244.244.244"));
helloPacket.setHelloInterval(10);
helloPacket.setRouterDeadInterval(10);
helloPacket.setDr(Ip4Address.valueOf("10.10.10.10"));
helloPacket.setBdr(Ip4Address.valueOf("11.11.11.11"));
helloPacket.setRouterId(Ip4Address.valueOf("111.111.111.111"));
message = helloPacket;
ospfInterfaceChannelHandler.processHelloMessage(message, channelHandlerContext);
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
/**
* Tests processHelloMessage() method.
*/
@Test
public void testProcessHelloMessage1() throws Exception {
ospfInterface.setInterfaceType(2);
ospfInterface.setRouterPriority(1);
ospfInterfaceChannelHandler.interfaceUp();
ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
ospfInterface.setState(OspfInterfaceState.WAITING);
ospfInterface.setInterfaceType(2);
ospfInterface.setIpNetworkMask(Ip4Address.valueOf("244.244.244.244"));
ospfInterface.setHelloIntervalTime(10);
ospfInterface.setRouterDeadIntervalTime(10);
ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
OspfMessage message;
helloPacket = new HelloPacket();
helloPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
helloPacket.setOspfVer(2);
helloPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
helloPacket.setNetworkMask(Ip4Address.valueOf("244.244.244.244"));
helloPacket.setHelloInterval(10);
helloPacket.setRouterDeadInterval(10);
helloPacket.setDr(Ip4Address.valueOf("10.10.10.10"));
helloPacket.setBdr(Ip4Address.valueOf("11.11.11.11"));
helloPacket.setRouterId(Ip4Address.valueOf("2.2.2.2"));
message = helloPacket;
ospfInterfaceChannelHandler.processHelloMessage(message, channelHandlerContext);
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
ospfNbrHashMap = new HashMap();
ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"),
Ip4Address.valueOf("2.2.2.2"), 2,
new OspfInterfaceChannelHandler(new Controller(), ospfArea,
ospfInterface)
, topologyForDeviceAndLink);
ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
ospfNbr.setRouterPriority(0);
ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
ospfInterface.addNeighbouringRouter(ospfNbr);
ospfInterfaceChannelHandler.processHelloMessage(message, channelHandlerContext);
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
/**
* Tests processDdMessage() method.
*/
@Test
public void testProcessDdMessage() throws Exception {
ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
ospfInterface.setInterfaceType(2);
ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
ospfInterface.setHelloIntervalTime(10);
ospfInterface.setRouterDeadIntervalTime(10);
ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
OspfMessage message;
ddPacket = new DdPacket();
ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
ddPacket.setOspfVer(2);
ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
ddPacket.setRouterId(Ip4Address.valueOf("2.2.2.2"));
ddPacket.setIsOpaqueCapable(true);
ddPacket.setIsMore(1);
ddPacket.setIsInitialize(1);
ddPacket.setIsMaster(1);
ddPacket.setSequenceNo(123);
message = ddPacket;
ospfNbrHashMap = new HashMap();
ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"),
Ip4Address.valueOf("2.2.2.2"), 2,
new OspfInterfaceChannelHandler(new Controller(), ospfArea,
ospfInterface)
, topologyForDeviceAndLink);
ospfNbr.setLastDdPacket(createDdPacket());
ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
ospfNbr.setState(OspfNeighborState.EXSTART);
ospfNbr.setRouterPriority(0);
ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
ospfNbr.setDdSeqNum(123);
ospfInterface.addNeighbouringRouter(ospfNbr);
ospfInterfaceChannelHandler.processDdMessage(message, channelHandlerContext);
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
/**
* Tests processDdMessage() method.
*/
@Test(expected = Exception.class)
public void testProcessDdMessage3() throws Exception {
ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
ospfInterface.setInterfaceType(2);
ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
ospfInterface.setHelloIntervalTime(10);
ospfInterface.setRouterDeadIntervalTime(10);
ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
OspfMessage message;
ddPacket = new DdPacket();
ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
ddPacket.setOspfVer(2);
ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
ddPacket.setRouterId(Ip4Address.valueOf("2.2.2.2"));
ddPacket.setIsOpaqueCapable(true);
ddPacket.setIsMore(1);
ddPacket.setIsInitialize(1);
ddPacket.setIsMaster(1);
ddPacket.setSequenceNo(123);
message = ddPacket;
ospfNbrHashMap = new HashMap();
ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"),
Ip4Address.valueOf("2.2.2.2"), 2,
new OspfInterfaceChannelHandler(new Controller(), ospfArea,
ospfInterface)
, topologyForDeviceAndLink);
ospfNbr.setLastDdPacket(createDdPacket());
ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
ospfNbr.setState(OspfNeighborState.EXSTART);
ospfNbr.setRouterPriority(0);
ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
ospfNbr.setDdSeqNum(123);
ospfInterface.addNeighbouringRouter(ospfNbr);
ddPacket.setIsMore(1);
ddPacket.setIsInitialize(0);
ddPacket.setIsMaster(0);
ddPacket.setSequenceNo(123);
ospfInterface.addNeighbouringRouter(ospfNbr);
ospfInterfaceChannelHandler.processDdMessage(message, channelHandlerContext);
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
/**
* Tests processDdMessage() method.
*/
@Test(expected = Exception.class)
public void testProcessDdMessage1() throws Exception {
ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
ospfInterface.setInterfaceType(2);
ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
ospfInterface.setHelloIntervalTime(10);
ospfInterface.setRouterDeadIntervalTime(10);
ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
OspfMessage message;
ddPacket = new DdPacket();
ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
ddPacket.setOspfVer(2);
ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
ddPacket.setRouterId(Ip4Address.valueOf("2.2.2.2"));
ddPacket.setIsOpaqueCapable(true);
ddPacket.setIsMore(1);
ddPacket.setIsInitialize(1);
ddPacket.setIsMaster(1);
ddPacket.setSequenceNo(123);
message = ddPacket;
ospfNbrHashMap = new HashMap();
ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"),
Ip4Address.valueOf("2.2.2.2"), 2,
new OspfInterfaceChannelHandler(new Controller(), ospfArea,
ospfInterface)
, topologyForDeviceAndLink);
ospfNbr.setLastDdPacket(createDdPacket());
ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
ospfNbr.setState(OspfNeighborState.EXCHANGE);
ospfNbr.setRouterPriority(0);
ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
ospfNbr.setDdSeqNum(123);
ospfInterface.addNeighbouringRouter(ospfNbr);
ddPacket.setIsMore(1);
ddPacket.setIsInitialize(0);
ddPacket.setIsMaster(0);
ddPacket.setSequenceNo(123);
ospfInterface.addNeighbouringRouter(ospfNbr);
ospfInterfaceChannelHandler.processDdMessage(message, channelHandlerContext);
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
/**
* Tests processDdMessage() method.
*/
@Test(expected = Exception.class)
public void testProcessDdMessage2() throws Exception {
ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
ospfInterface.setInterfaceType(2);
ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
ospfInterface.setHelloIntervalTime(10);
ospfInterface.setRouterDeadIntervalTime(10);
ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
OspfMessage message;
ddPacket = new DdPacket();
ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
ddPacket.setOspfVer(2);
ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
ddPacket.setRouterId(Ip4Address.valueOf("2.2.2.2"));
ddPacket.setIsOpaqueCapable(true);
ddPacket.setIsMore(1);
ddPacket.setIsInitialize(1);
ddPacket.setIsMaster(1);
ddPacket.setSequenceNo(123);
message = ddPacket;
ospfNbrHashMap = new HashMap();
ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"),
Ip4Address.valueOf("2.2.2.2"), 2,
new OspfInterfaceChannelHandler(new Controller(), ospfArea,
ospfInterface)
, topologyForDeviceAndLink);
ospfNbr.setLastDdPacket(createDdPacket());
ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
ospfNbr.setState(OspfNeighborState.LOADING);
ospfNbr.setRouterPriority(0);
ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
ospfNbr.setDdSeqNum(123);
ospfInterface.addNeighbouringRouter(ospfNbr);
ospfInterfaceChannelHandler.processDdMessage(message, channelHandlerContext);
ddPacket.setIsMore(1);
ddPacket.setIsInitialize(0);
ddPacket.setIsMaster(0);
ddPacket.setSequenceNo(123);
ospfInterface.addNeighbouringRouter(ospfNbr);
ospfNbr.setState(OspfNeighborState.LOADING);
ospfInterface.addNeighbouringRouter(ospfNbr);
ospfInterfaceChannelHandler.processDdMessage(message, channelHandlerContext);
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
/**
* Tests processLsRequestMessage() method.
*/
@Test
public void testProcessLSRequestMessage() throws Exception {
ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
ospfInterface.setInterfaceType(2);
ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
ospfInterface.setHelloIntervalTime(10);
ospfInterface.setRouterDeadIntervalTime(10);
ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
OspfMessage message;
lsRequest = new LsRequest();
lsRequest.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
lsRequest.setOspfVer(2);
lsRequest.setAreaId(Ip4Address.valueOf("12.12.12.12"));
lsRequest.setRouterId(Ip4Address.valueOf("10.226.165.100"));
List<LsRequestPacket> lsRequests = new ArrayList();
LsRequestPacket lsRequestPacket = new LsRequestPacket();
lsRequestPacket.setLsType(3);
lsRequestPacket.setLinkStateId("2.2.2.2");
lsRequestPacket.setOwnRouterId("2.2.2.2");
lsRequests.add(lsRequestPacket);
lsRequests.add(lsRequestPacket);
lsRequest.addLinkStateRequests(new LsRequestPacket());
lsRequest.addLinkStateRequests(new LsRequestPacket());
message = lsRequest;
ospfNbrHashMap = new HashMap();
ospfNbr.setState(OspfNeighborState.EXCHANGE);
ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
Ip4Address.valueOf("10.226.165.100"), 2,
new OspfInterfaceChannelHandler(new Controller(), ospfArea,
createOspfInterface1())
, topologyForDeviceAndLink);
ospfNbr.setLastDdPacket(createDdPacket());
ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
ospfNbr.setState(OspfNeighborState.FULL);
ospfNbr.setRouterPriority(0);
ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
ospfNbr.setDdSeqNum(123);
ospfInterface.addNeighbouringRouter(ospfNbr);
ospfInterface.setListOfNeighbors(ospfNbrHashMap);
ospfInterfaceChannelHandler.processLsRequestMessage(message, channelHandlerContext);
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
/**
* Tests processLsUpdateMessage() method.
*/
@Test
public void testProcessLSUpdateMessage() throws Exception {
ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
ospfInterface.setInterfaceType(2);
ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
ospfInterface.setHelloIntervalTime(10);
ospfInterface.setRouterDeadIntervalTime(10);
ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
OspfMessage message;
lsUpdate = new LsUpdate();
lsUpdate.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
lsUpdate.setOspfVer(2);
lsUpdate.setAreaId(Ip4Address.valueOf("12.12.12.12"));
lsUpdate.setRouterId(Ip4Address.valueOf("10.226.165.100"));
RouterLsa routerLsa = new RouterLsa();
lsUpdate.addLsa(routerLsa);
lsUpdate.setNumberOfLsa(1);
message = lsUpdate;
ospfNbrHashMap = new HashMap();
ospfNbr.setState(OspfNeighborState.FULL);
ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
Ip4Address.valueOf("10.226.165.100"), 2,
new OspfInterfaceChannelHandler(new Controller(), ospfArea,
createOspfInterface1())
, topologyForDeviceAndLink);
ospfNbr.setLastDdPacket(createDdPacket());
ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
ospfNbr.setState(OspfNeighborState.FULL);
ospfNbr.setRouterPriority(0);
ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
ospfNbr.setDdSeqNum(123);
ospfInterface.addNeighbouringRouter(ospfNbr);
ospfInterfaceChannelHandler.processLsUpdateMessage(message, channelHandlerContext);
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
@Test(expected = Exception.class)
public void testProcessLSAckMessage() throws Exception {
ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
ospfInterface.setInterfaceType(2);
ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
ospfInterface.setHelloIntervalTime(10);
ospfInterface.setRouterDeadIntervalTime(10);
ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
OspfMessage message;
lsAck = new LsAcknowledge();
lsAck.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
lsAck.setOspfVer(2);
lsAck.setAreaId(Ip4Address.valueOf("12.12.12.12"));
LsaHeader lsaHeader = new LsaHeader();
lsAck.addLinkStateHeader(lsaHeader);
message = lsAck;
ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
Ip4Address.valueOf("10.226.165.100"), 2,
new OspfInterfaceChannelHandler(new Controller(), ospfArea,
createOspfInterface())
, topologyForDeviceAndLink);
ospfNbr.setLastDdPacket(createDdPacket());
ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2"));
ospfNbr.setState(OspfNeighborState.FULL);
ospfNbr.setRouterPriority(0);
ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13"));
ospfNbr.setDdSeqNum(123);
ospfInterfaceChannelHandler.processLsAckMessage(message, channelHandlerContext);
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
/**
* Tests compareDdPackets() method.
*/
@Test
public void testCompareDDPackets() throws Exception {
ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
ospfInterface.setInterfaceType(2);
ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
ospfInterface.setHelloIntervalTime(10);
ospfInterface.setRouterDeadIntervalTime(10);
ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12"));
channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
OspfMessage message;
ddPacket = new DdPacket();
ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1"));
ddPacket.setOspfVer(2);
ddPacket.setIsInitialize(1);
ddPacket.setIsMaster(1);
ddPacket.setIsMore(1);
ddPacket.setOptions(2);
ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12"));
assertThat(ospfInterfaceChannelHandler.compareDdPackets(ddPacket, ddPacket), is(true));
}
@Test(expected = Exception.class)
public void testCloseChannel() throws Exception {
channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
ospfInterfaceChannelHandler.closeChannel(channelHandlerContext);
assertThat(ospfInterface.dr(), is(notNullValue()));
}
/**
* Tests electRouter() method.
*/
@Test
public void testElectRouter() throws Exception {
ospfInterface.setDr(Ip4Address.valueOf("3.3.3.3"));
ospfInterface.setBdr(Ip4Address.valueOf("3.3.3.3"));
ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
ChannelConfig channelConfig = EasyMock.createMock(ChannelConfig.class);
EasyMock.expect(channelConfig.getBufferFactory()).andReturn(new HeapChannelBufferFactory());
Channel channel = EasyMock.createMock(Channel.class);
ospfInterfaceChannelHandler.electRouter(channel);
assertThat(ospfInterface.dr(), is(notNullValue()));
}
/**
* Tests electBdr() method.
*/
@Test
public void testElectBdr() throws Exception {
ospfEligibleRouter = new OspfEligibleRouter();
ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
ospfEligibleRouter.setIsDr(true);
ospfEligibleRouter.setRouterPriority(10);
ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
ospfEligibleRouter.setIsBdr(false);
OspfEligibleRouter ospfEligibleRouter1 = new OspfEligibleRouter();
ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
ospfEligibleRouter.setIsDr(true);
ospfEligibleRouter.setRouterPriority(10);
ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
ospfEligibleRouter.setIsBdr(false);
OspfEligibleRouter ospfEligibleRouter2 = new OspfEligibleRouter();
ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
ospfEligibleRouter.setIsDr(true);
ospfEligibleRouter.setRouterPriority(10);
ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
ospfEligibleRouter.setIsBdr(false);
List<OspfEligibleRouter> ospfEligibleRouters = new ArrayList<>();
ospfEligibleRouters.add(ospfEligibleRouter);
ospfEligibleRouters.add(ospfEligibleRouter1);
ospfEligibleRouters.add(ospfEligibleRouter2);
OspfEligibleRouter eligibleRouter = ospfInterfaceChannelHandler.electBdr(ospfEligibleRouters);
assertThat(ospfEligibleRouters.size(), is(3));
assertThat(eligibleRouter, is(notNullValue()));
}
/**
* Tests electDr() method.
*/
@Test
public void testElectDR() throws Exception {
ospfEligibleRouter = new OspfEligibleRouter();
ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
ospfEligibleRouter.setIsDr(true);
ospfEligibleRouter.setRouterPriority(10);
ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
ospfEligibleRouter.setIsBdr(false);
OspfEligibleRouter ospfEligibleRouter1 = new OspfEligibleRouter();
ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
ospfEligibleRouter.setIsDr(true);
ospfEligibleRouter.setRouterPriority(10);
ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
ospfEligibleRouter.setIsBdr(false);
OspfEligibleRouter ospfEligibleRouter2 = new OspfEligibleRouter();
ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
ospfEligibleRouter.setIsDr(true);
ospfEligibleRouter.setRouterPriority(10);
ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
ospfEligibleRouter.setIsBdr(false);
List<OspfEligibleRouter> ospfEligibleRouters = new ArrayList<>();
ospfEligibleRouters.add(ospfEligibleRouter);
ospfEligibleRouters.add(ospfEligibleRouter1);
ospfEligibleRouters.add(ospfEligibleRouter2);
OspfEligibleRouter eligibleRouter = ospfInterfaceChannelHandler.electDr(ospfEligibleRouters,
ospfEligibleRouter);
assertThat(ospfEligibleRouters.size(), is(3));
assertThat(eligibleRouter, is(notNullValue()));
}
/**
* Tests selectRouterBasedOnPriority() method.
*/
@Test
public void testSelectRouterBasedOnPriority() throws Exception {
ospfEligibleRouter = new OspfEligibleRouter();
ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
ospfEligibleRouter.setIsDr(true);
ospfEligibleRouter.setRouterPriority(10);
ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
ospfEligibleRouter.setIsBdr(false);
OspfEligibleRouter ospfEligibleRouter1 = new OspfEligibleRouter();
ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
ospfEligibleRouter.setIsDr(true);
ospfEligibleRouter.setRouterPriority(11);
ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
ospfEligibleRouter.setIsBdr(false);
OspfEligibleRouter ospfEligibleRouter2 = new OspfEligibleRouter();
ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
ospfEligibleRouter.setIsDr(true);
ospfEligibleRouter.setRouterPriority(12);
ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1"));
ospfEligibleRouter.setIsBdr(false);
List<OspfEligibleRouter> ospfEligibleRouters = new ArrayList<>();
ospfEligibleRouters.add(ospfEligibleRouter);
ospfEligibleRouters.add(ospfEligibleRouter1);
ospfEligibleRouters.add(ospfEligibleRouter2);
OspfEligibleRouter eligibleRouter = ospfInterfaceChannelHandler.selectRouterBasedOnPriority(
ospfEligibleRouters);
assertThat(eligibleRouter, is(notNullValue()));
}
/**
* Tests addDeviceInformation() method.
*/
@Test(expected = Exception.class)
public void testAddDeviceInformation() throws Exception {
ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
Ip4Address.valueOf("10.226.165.100"), 2,
new OspfInterfaceChannelHandler(new Controller(), ospfArea,
createOspfInterface())
, topologyForDeviceAndLink);
ospfInterfaceChannelHandler.addDeviceInformation(new OspfRouterImpl());
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
/**
* Tests removeDeviceInformation() method.
*/
@Test(expected = Exception.class)
public void testRemoveDeviceInformation() throws Exception {
ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
Ip4Address.valueOf("10.226.165.100"), 2,
new OspfInterfaceChannelHandler(new Controller(), ospfArea,
createOspfInterface())
, topologyForDeviceAndLink);
ospfInterfaceChannelHandler.removeDeviceInformation(new OspfRouterImpl());
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
/**
* Tests addLinkInformation() method.
*/
@Test(expected = Exception.class)
public void testaddLinkInformation() throws Exception {
ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
Ip4Address.valueOf("10.226.165.100"), 2,
new OspfInterfaceChannelHandler(new Controller(), ospfArea,
createOspfInterface())
, topologyForDeviceAndLink);
List topTlv = new ArrayList();
topTlv.add(new RouterTlv(new TlvHeader()));
ospfInterfaceChannelHandler.addLinkInformation(new OspfRouterImpl(), new OspfLinkTedImpl());
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
/**
* Tests removeLinkInformation() method.
*/
@Test(expected = Exception.class)
public void testRemoveLinkInformation() throws Exception {
ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"),
Ip4Address.valueOf("10.226.165.100"), 2,
new OspfInterfaceChannelHandler(new Controller(), ospfArea,
createOspfInterface())
, topologyForDeviceAndLink);
ospfInterfaceChannelHandler.removeLinkInformation(ospfNbr);
assertThat(ospfInterfaceChannelHandler, is(notNullValue()));
}
/**
* Utility for test method.
*/
private DdPacket createDdPacket() throws OspfParseException {
byte[] ddPacket = {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};
DdPacket ddPacket1 = new DdPacket();
ChannelBuffer buf = ChannelBuffers.buffer(ddPacket.length);
buf.writeBytes(ddPacket);
ddPacket1.readFrom(buf);
return ddPacket1;
}
/**
* Utility for test method.
*/
private OspfInterfaceImpl createOspfInterface() throws UnknownHostException {
ospfInterface = new OspfInterfaceImpl();
OspfAreaImpl ospfArea = new OspfAreaImpl();
OspfInterfaceChannelHandler ospfInterfaceChannelHandler = EasyMock.createMock(
OspfInterfaceChannelHandler.class);
ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.226.165.164"),
Ip4Address.valueOf("1.1.1.1"), 2, ospfInterfaceChannelHandler
, topologyForDeviceAndLink);
ospfNbr.setState(OspfNeighborState.EXSTART);
ospfNbr.setNeighborId(Ip4Address.valueOf("10.226.165.100"));
this.ospfInterface = new OspfInterfaceImpl();
this.ospfInterface.setIpAddress(Ip4Address.valueOf("10.226.165.164"));
this.ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
this.ospfInterface.setAreaId(2);
this.ospfInterface.setAuthKey("authKey");
this.ospfInterface.setAuthType("AuthReq");
this.ospfInterface.setBdr(Ip4Address.valueOf("111.111.111.111"));
this.ospfInterface.setDr(Ip4Address.valueOf("111.111.111.111"));
this.ospfInterface.setHelloIntervalTime(20);
this.ospfInterface.setInterfaceCost(10);
this.ospfInterface.setInterfaceType(2);
this.ospfInterface.setReTransmitInterval(2000);
this.ospfInterface.setMtu(6500);
this.ospfInterface.setPollInterval(1000);
this.ospfInterface.setRouterDeadIntervalTime(1000);
this.ospfInterface.setRouterPriority(1);
this.ospfInterface.setTransmitDelay(500);
this.ospfInterface.setInterfaceType(1);
this.ospfInterface.addNeighbouringRouter(ospfNbr);
return this.ospfInterface;
}
/**
* Utility for test method.
*/
private OspfInterfaceImpl createOspfInterface1() throws UnknownHostException {
ospfInterface = new OspfInterfaceImpl();
OspfAreaImpl ospfArea = new OspfAreaImpl();
OspfInterfaceChannelHandler ospfInterfaceChannelHandler = EasyMock.createMock(
OspfInterfaceChannelHandler.class);
ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.226.165.164"),
Ip4Address.valueOf("1.1.1.1"), 2, ospfInterfaceChannelHandler
, topologyForDeviceAndLink);
ospfNbr.setState(OspfNeighborState.FULL);
ospfNbr.setNeighborId(Ip4Address.valueOf("10.226.165.100"));
ospfInterface = new OspfInterfaceImpl();
ospfInterface.setIpAddress(Ip4Address.valueOf("10.226.165.164"));
ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255"));
ospfInterface.setAreaId(2);
ospfInterface.setAuthKey("authKey");
ospfInterface.setAuthType("AuthReq");
ospfInterface.setBdr(Ip4Address.valueOf("111.111.111.111"));
ospfInterface.setDr(Ip4Address.valueOf("111.111.111.111"));
ospfInterface.setHelloIntervalTime(20);
ospfInterface.setInterfaceCost(10);
ospfInterface.setInterfaceType(2);
ospfInterface.setReTransmitInterval(2000);
ospfInterface.setMtu(6500);
ospfInterface.setPollInterval(1000);
ospfInterface.setRouterDeadIntervalTime(1000);
ospfInterface.setRouterPriority(1);
ospfInterface.setTransmitDelay(500);
ospfInterface.setInterfaceType(1);
ospfInterface.addNeighbouringRouter(ospfNbr);
return ospfInterface;
}
/**
* Utility for test method.
*/
private OspfAreaImpl createOspfArea() throws UnknownHostException {
OspfAreaAddressRangeImpl ospfAreaAddressRange;
ospfAreaAddressRange = createOspfAreaAddressRange();
addressRanges.add(ospfAreaAddressRange);
OspfAreaImpl ospfArea = new OspfAreaImpl();
ospfArea.setStubCost(10);
ospfArea.setAreaId(Ip4Address.valueOf("10.226.165.164"));
ospfArea.setExternalRoutingCapability(true);
ospfArea.setTransitCapability(true);
ospfArea.setAddressRanges(addressRanges);
OspfInterfaceImpl ospfInterface = createOspfInterface();
ospfInterfaces.add(ospfInterface);
ospfArea.setInterfacesLst(ospfInterfaces);
RouterLsa routerLsa = new RouterLsa();
routerLsa.setLsType(1);
routerLsa.setLinkStateId("2.2.2.2");
routerLsa.setAdvertisingRouter(Ip4Address.valueOf("2.2.2.2"));
try {
ospfArea.addLsa(routerLsa, false, ospfInterface);
} catch (Exception e) {
System.out.println("ospfAreaImpl createOspfArea");
}
ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
return ospfArea;
}
/**
* Utility for test method.
*/
private OspfAreaAddressRangeImpl createOspfAreaAddressRange() {
OspfAreaAddressRangeImpl ospfAreaAddressRange = new OspfAreaAddressRangeImpl();
ospfAreaAddressRange.setIpAddress(Ip4Address.valueOf("10.226.165.164"));
ospfAreaAddressRange.setAdvertise(true);
ospfAreaAddressRange.setMask("mask");
return ospfAreaAddressRange;
}
}
\ 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.channel.Channel;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ip4Address;
import org.onosproject.ospf.controller.OspfInterface;
import org.onosproject.ospf.controller.OspfLsa;
import org.onosproject.ospf.controller.OspfLsaType;
import org.onosproject.ospf.controller.OspfNeighborState;
import org.onosproject.ospf.controller.TopologyForDeviceAndLink;
import org.onosproject.ospf.controller.area.OspfAreaImpl;
import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
import org.onosproject.ospf.controller.lsdb.LsaWrapperImpl;
import org.onosproject.ospf.controller.lsdb.LsdbAgeImpl;
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.ospfpacket.OspfMessage;
import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket;
import org.onosproject.ospf.protocol.ospfpacket.types.HelloPacket;
import org.onosproject.ospf.protocol.ospfpacket.types.LsRequest;
import org.onosproject.ospf.protocol.ospfpacket.types.LsUpdate;
import org.onosproject.ospf.protocol.util.ChecksumCalculator;
import org.onosproject.ospf.protocol.util.OspfUtil;
import java.net.SocketAddress;
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 OspfNbrImpl.
*/
public class OspfNbrImplTest {
private OspfNbrImpl ospfNbr;
private OspfInterfaceImpl ospfInterface;
private OspfAreaImpl ospfArea;
private OspfInterfaceImpl ospfInterface1;
private OspfInterfaceImpl ospfInterface2;
private List<OspfInterface> ospfInterfaces;
private List<OspfLsa> ospfLsaList;
private Channel channel;
private Channel channel1;
private Channel channel2;
private OspfMessage ospfMessage;
private TopologyForDeviceAndLink topologyForDeviceAndLink;
@Before
public void setUp() throws Exception {
ospfInterface = new OspfInterfaceImpl();
ospfInterface.setInterfaceType(2);
ospfInterface.setRouterDeadIntervalTime(30);
ospfInterface.setReTransmitInterval(30);
ospfInterface.setDr(Ip4Address.valueOf("1.1.1.1"));
ospfInterface.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
ospfArea = new OspfAreaImpl();
ospfInterface1 = new OspfInterfaceImpl();
ospfInterface1.setInterfaceType(2);
ospfInterface1.setRouterDeadIntervalTime(30);
ospfInterface1.setReTransmitInterval(30);
ospfInterface1.setDr(Ip4Address.valueOf("7.7.7.7"));
ospfInterface1.setIpAddress(Ip4Address.valueOf("7.7.7.7"));
ospfInterface2 = new OspfInterfaceImpl();
ospfInterface2.setInterfaceType(2);
ospfInterface2.setRouterDeadIntervalTime(30);
ospfInterface2.setReTransmitInterval(30);
ospfInterface2.setDr(Ip4Address.valueOf("6.6.6.6"));
ospfInterface2.setIpAddress(Ip4Address.valueOf("6.6.6.6"));
ospfInterfaces = new ArrayList();
ospfInterfaces.add(ospfInterface);
ospfInterfaces.add(ospfInterface1);
ospfInterfaces.add(ospfInterface2);
ospfArea.setInterfacesLst(ospfInterfaces);
ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111"));
topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl();
ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("1.1.1.1"),
Ip4Address.valueOf("2.2.2.2"), 2,
new OspfInterfaceChannelHandler(new Controller(),
ospfArea, ospfInterface)
, topologyForDeviceAndLink);
}
@After
public void tearDown() throws Exception {
ospfNbr = null;
ospfArea = null;
ospfInterface = null;
ospfLsaList = null;
channel = null;
channel1 = null;
channel2 = null;
ospfMessage = null;
}
/**
* Tests neighborIpAddr() method.
*/
@Test
public void testNeighborIpAddr() throws Exception {
assertThat(ospfNbr.neighborIpAddr(), is(notNullValue()));
}
/**
* Tests isOpaqueCapable() getter method.
*/
@Test
public void testIsOpaqueCapable() throws Exception {
assertThat(ospfNbr.isOpaqueCapable(), is(false));
}
/**
* Tests isOpaqueCapable() setter method.
*/
@Test
public void testSetIsOpaqueCapable() throws Exception {
ospfNbr.setIsOpaqueCapable(true);
assertThat(ospfNbr.isOpaqueCapable(), is(true));
}
/**
* Tests oneWayReceived() method.
*/
@Test
public void testOneWayReceived() throws Exception {
ospfMessage = new HelloPacket();
ospfNbr.setState(OspfNeighborState.ATTEMPT);
channel = EasyMock.createMock(Channel.class);
ospfNbr.oneWayReceived(ospfMessage, channel);
channel1 = EasyMock.createMock(Channel.class);
ospfNbr.setState(OspfNeighborState.DOWN);
ospfNbr.oneWayReceived(ospfMessage, channel1);
channel2 = EasyMock.createMock(Channel.class);
ospfNbr.setState(OspfNeighborState.TWOWAY);
ospfNbr.oneWayReceived(ospfMessage, channel2);
assertThat(ospfNbr, is(notNullValue()));
}
/**
* Tests twoWayReceived() method.
*/
@Test(expected = Exception.class)
public void testTwoWayReceived() throws Exception {
ospfNbr.setNeighborDr(Ip4Address.valueOf("1.1.1.1"));
ospfMessage = new HelloPacket();
ospfNbr.setState(OspfNeighborState.ATTEMPT);
ospfNbr.setNeighborDr(Ip4Address.valueOf("2.2.2.2"));
ospfInterface.setIpAddress(Ip4Address.valueOf("2.2.2.2"));
channel = EasyMock.createMock(Channel.class);
SocketAddress socketAddress = EasyMock.createMock(SocketAddress.class);
channel.bind(socketAddress);
ospfNbr.twoWayReceived(ospfMessage, channel);
ospfInterface.setIpAddress(Ip4Address.valueOf("3.3.3.3"));
channel1 = EasyMock.createMock(Channel.class);
ospfNbr.twoWayReceived(ospfMessage, channel1);
assertThat(ospfNbr, is(notNullValue()));
}
/**
* Tests negotiationDone() method.
*/
@Test(expected = Exception.class)
public void testNegotiationDone() throws Exception {
ospfLsaList = new ArrayList();
ospfLsaList.add(new RouterLsa());
ospfMessage = new HelloPacket();
ospfNbr.setState(OspfNeighborState.EXSTART);
channel = EasyMock.createMock(Channel.class);
ospfNbr.negotiationDone(ospfMessage, true, ospfLsaList, channel);
channel1 = EasyMock.createMock(Channel.class);
ospfNbr.negotiationDone(ospfMessage, false, ospfLsaList, channel1);
assertThat(ospfNbr, is(notNullValue()));
}
/**
* Tests processLsas() method.
*/
@Test
public void testProcessLsas() throws Exception {
ospfLsaList = new ArrayList();
RouterLsa routerLsa = new RouterLsa();
routerLsa.setLsType(1);
ospfLsaList.add(routerLsa);
NetworkLsa networkLsa = new NetworkLsa();
routerLsa.setLsType(2);
ospfLsaList.add(networkLsa);
routerLsa.setLsType(3);
ospfLsaList.add(routerLsa);
ospfNbr.processLsas(ospfLsaList);
assertThat(ospfNbr, is(notNullValue()));
}
/**
* Tests seqNumMismatch() method.
*/
@Test
public void testSeqNumMismatch() throws Exception {
ospfNbr.setState(OspfNeighborState.FULL);
assertThat(ospfNbr.seqNumMismatch("samelsa"), is(notNullValue()));
}
/**
* Tests badLSReq() method.
*/
@Test
public void testBadLSReq() throws Exception {
channel = EasyMock.createMock(Channel.class);
ospfNbr.setState(OspfNeighborState.FULL);
ospfNbr.badLSReq(channel);
assertThat(ospfNbr, is(notNullValue()));
}
/**
* Tests processDdPacket() method.
*/
@Test
public void testProcessDdPacket() throws Exception {
ospfArea.addLsa(new RouterLsa(), false, ospfInterface);
ospfArea.addLsa(new RouterLsa(), ospfInterface);
ospfArea.addLsaToMaxAgeBin("lsa", new LsaWrapperImpl());
channel = EasyMock.createMock(Channel.class);
DdPacket ddPacket = new DdPacket();
ddPacket.addLsaHeader(new LsaHeader());
ospfNbr.processDdPacket(true, ddPacket, channel);
channel1 = EasyMock.createMock(Channel.class);
ddPacket.setIsMore(1);
ospfNbr.processDdPacket(false, ddPacket, channel1);
assertThat(ospfNbr, is(notNullValue()));
}
/**
* Tests exchangeDone() method.
*/
@Test
public void testExchangeDone() throws Exception {
ospfMessage = new HelloPacket();
channel = EasyMock.createMock(Channel.class);
ospfNbr.setState(OspfNeighborState.EXCHANGE);
ospfNbr.exchangeDone(ospfMessage, channel);
assertThat(ospfNbr, is(notNullValue()));
}
/**
* Tests exchangeDone() method.
*/
@Test
public void testExchangeDone1() throws Exception {
ospfMessage = new HelloPacket();
channel = EasyMock.createMock(Channel.class);
ospfNbr.setState(OspfNeighborState.EXCHANGE);
ospfLsaList = new ArrayList();
RouterLsa routerLsa = new RouterLsa();
routerLsa.setLsType(1);
ospfLsaList.add(routerLsa);
NetworkLsa networkLsa = new NetworkLsa();
routerLsa.setLsType(2);
ospfLsaList.add(networkLsa);
routerLsa.setLsType(3);
ospfLsaList.add(routerLsa);
ospfNbr.processLsas(ospfLsaList);
ospfNbr.setState(OspfNeighborState.EXCHANGE);
ospfNbr.exchangeDone(ospfMessage, channel);
assertThat(ospfNbr, is(notNullValue()));
}
/**
* Tests adjOk() method.
*/
@Test
public void testAdjOk() throws Exception {
channel = EasyMock.createMock(Channel.class);
ospfInterface.setIpAddress(Ip4Address.valueOf("2.2.2.2"));
ospfNbr.setState(OspfNeighborState.TWOWAY);
ospfNbr.setNeighborDr(Ip4Address.valueOf("2.2.2.2"));
ospfNbr.adjOk(channel);
Assert.assertNotNull(ospfNbr);
}
/**
* Tests processLsUpdate() method.
*/
@Test
public void testProcessLsUpdate() throws Exception {
LsUpdate ospfMessage = new LsUpdate();
ospfMessage.setSourceIp(Ip4Address.valueOf("10.10.10.10"));
ospfMessage.addLsa(new RouterLsa());
ospfMessage.addLsa(new NetworkLsa());
channel = EasyMock.createMock(Channel.class);
ospfNbr.setState(OspfNeighborState.EXCHANGE);
ospfNbr.processLsUpdate(ospfMessage, channel);
assertThat(ospfNbr, is(notNullValue()));
}
/**
* Tests loadingDone() method.
*/
@Test
public void testLoadingDone() throws Exception {
ospfArea.addLsa(new RouterLsa(), false, ospfInterface);
ospfArea.addLsa(new RouterLsa(), ospfInterface);
ospfArea.addLsaToMaxAgeBin("lsa", new LsaWrapperImpl());
ospfNbr.loadingDone();
assertThat(ospfNbr, is(notNullValue()));
}
/**
* Tests processReceivedLsa() method.
*/
@Test
public void testProcessReceivedLsa() throws Exception {
LsaWrapperImpl lsaWrapper = new LsaWrapperImpl();
LsdbAgeImpl lsdbAge = new LsdbAgeImpl(new OspfAreaImpl());
lsdbAge.ageLsaAndFlood();
lsaWrapper.setLsdbAge(lsdbAge);
lsaWrapper.setLsaHeader(new NetworkLsa());
RouterLsa routerlsa = new RouterLsa();
routerlsa.setLsType(1);
routerlsa.setOptions(2);
routerlsa.setAdvertisingRouter(Ip4Address.valueOf("1.1.1.1"));
routerlsa.setAge(100);
routerlsa.setLinkStateId("2.2.2.2");
routerlsa.setLsSequenceNo(1010101);
lsaWrapper.setLsaHeader(new RouterLsa());
ospfArea.addLsa(routerlsa, false, ospfInterface);
lsaWrapper.addLsa(OspfLsaType.ROUTER, routerlsa);
ospfArea.addLsa(routerlsa, ospfInterface);
ospfArea.addLsaToMaxAgeBin("lsa", new LsaWrapperImpl());
byte[] res = routerlsa.asBytes();
routerlsa.setLsPacketLen(res.length);
res = new ChecksumCalculator().calculateLsaChecksum(routerlsa.asBytes(), 16, 17);
routerlsa.setLsCheckSum(OspfUtil.byteToInteger(res));
channel = EasyMock.createMock(Channel.class);
lsdbAge.ageLsaAndFlood();
assertThat(ospfNbr.processReceivedLsa(lsaWrapper.lsaHeader(), true, channel,
Ip4Address.valueOf("10.10.10.10")), is(true));
channel1 = EasyMock.createMock(Channel.class);
assertThat(ospfNbr.processReceivedLsa(routerlsa, true, channel1,
Ip4Address.valueOf("10.10.10.10")), is(true));
}
/**
* Tests isNullorLatest() method.
*/
@Test
public void testIsNullorLatest() throws Exception {
LsaWrapperImpl lsaWrapper = new LsaWrapperImpl();
LsdbAgeImpl lsdbAge = new LsdbAgeImpl(new OspfAreaImpl());
lsdbAge.ageLsaAndFlood();
lsaWrapper.setLsdbAge(lsdbAge);
lsaWrapper.setLsaHeader(new LsaHeader());
lsaWrapper.addLsa(OspfLsaType.ROUTER, new RouterLsa());
assertThat(ospfNbr.isNullorLatest(lsaWrapper, new LsaHeader()), is(notNullValue()));
}
/**
* Tests processSelfOriginatedLsa() method.
*/
@Test
public void testProcessSelfOriginatedLsa() throws Exception {
ospfNbr.processSelfOriginatedLsa();
assertThat(ospfNbr, is(notNullValue()));
}
/**
* Tests sendLsa() method.
*/
@Test
public void testSendLsa() throws Exception {
channel = EasyMock.createMock(Channel.class);
ospfNbr.sendLsa(new LsaHeader(), Ip4Address.valueOf("1.1.1.1"), channel);
assertThat(ospfNbr, is(notNullValue()));
}
/**
* Tests directAcknowledge() method.
*/
@Test
public void testDirectAcknowledge() throws Exception {
channel = EasyMock.createMock(Channel.class);
ospfNbr.directAcknowledge(new LsaHeader(), channel, Ip4Address.valueOf("1.1.1.1"));
assertThat(ospfNbr, is(notNullValue()));
}
/**
* Tests neighborDown() method.
*/
@Test(expected = Exception.class)
public void testNeighborDown() throws Exception {
ospfNbr.neighborDown();
assertThat(ospfNbr, is(notNullValue()));
}
/**
* Tests startFloodingTimer() method.
*/
@Test
public void testStartFloodingTimer() throws Exception {
channel = EasyMock.createMock(Channel.class);
ospfNbr.startFloodingTimer(channel);
assertThat(ospfNbr, is(notNullValue()));
}
/**
* Tests lastDdPacket() getter method.
*/
@Test
public void testGetLastDdPacket() throws Exception {
ospfNbr.setLastDdPacket(new DdPacket());
assertThat(ospfNbr.lastDdPacket(), is(notNullValue()));
}
/**
* Tests lastDdPacket() setter method.
*/
@Test
public void testSetLastDdPacket() throws Exception {
ospfNbr.setLastDdPacket(new DdPacket());
assertThat(ospfNbr.lastDdPacket(), is(notNullValue()));
}
/**
* Tests neighborId() getter method.
*/
@Test
public void testNeighborId() throws Exception {
ospfNbr.setNeighborId(Ip4Address.valueOf("1.1.1.1"));
assertThat(ospfNbr.neighborId(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests neighborId() setter method.
*/
@Test
public void testSetNeighborId() throws Exception {
ospfNbr.setNeighborId(Ip4Address.valueOf("1.1.1.1"));
assertThat(ospfNbr.neighborId(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests neighborDr() getter method.
*/
@Test
public void testNeighborDr() throws Exception {
ospfNbr.setNeighborDr(Ip4Address.valueOf("1.1.1.1"));
assertThat(ospfNbr.neighborDr(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests neighborDr() setter method.
*/
@Test
public void testSetNeighborDr() throws Exception {
ospfNbr.setNeighborDr(Ip4Address.valueOf("1.1.1.1"));
assertThat(ospfNbr.neighborDr(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests neighborBdr() getter method.
*/
@Test
public void testNeighborBdr() throws Exception {
ospfNbr.setNeighborBdr(Ip4Address.valueOf("1.1.1.1"));
assertThat(ospfNbr.neighborBdr(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests neighborBdr() setter method.
*/
@Test
public void testSetNeighborBdr() throws Exception {
ospfNbr.setNeighborBdr(Ip4Address.valueOf("1.1.1.1"));
assertThat(ospfNbr.neighborBdr(), is(Ip4Address.valueOf("1.1.1.1")));
}
/**
* Tests routerPriority() getter method.
*/
@Test
public void testRouterPriority() throws Exception {
ospfNbr.setRouterPriority(1);
assertThat(ospfNbr.routerPriority(), is(1));
}
/**
* Tests routerPriority() setter method.
*/
@Test
public void testSetRouterPriority() throws Exception {
ospfNbr.setRouterPriority(1);
assertThat(ospfNbr.routerPriority(), is(1));
}
/**
* Tests options() getter method.
*/
@Test
public void testGetOptions() throws Exception {
ospfNbr.setOptions(1);
assertThat(ospfNbr.options(), is(1));
}
/**
* Tests options() setter method.
*/
@Test
public void testSetOptions() throws Exception {
ospfNbr.setOptions(1);
assertThat(ospfNbr.options(), is(1));
}
/**
* Tests ddSeqNum() getter method.
*/
@Test
public void testGetDdSeqNum() throws Exception {
ospfNbr.setDdSeqNum(1);
assertThat(ospfNbr.ddSeqNum(), is(1L));
}
/**
* Tests ddSeqNum() setter method.
*/
@Test
public void testSetDdSeqNum() throws Exception {
ospfNbr.setDdSeqNum(1);
assertThat(ospfNbr.ddSeqNum(), is(1L));
}
/**
* Tests isMaster() getter method.
*/
@Test
public void testIsMaster() throws Exception {
ospfNbr.setIsMaster(1);
assertThat(ospfNbr.isMaster(), is(1));
}
/**
* Tests lastDdPacket() getter method.
*/
@Test
public void testGetLastSentDdPacket() throws Exception {
ospfNbr.setLastDdPacket(new DdPacket());
assertThat(ospfNbr.lastDdPacket(), is(notNullValue()));
}
/**
* Tests lastDdPacket() setter method.
*/
@Test
public void testSetLastSentDdPacket() throws Exception {
ospfNbr.setLastDdPacket(new DdPacket());
assertThat(ospfNbr.lastDdPacket(), is(notNullValue()));
}
/**
* Tests getLastSentLsrPacket() getter method.
*/
@Test
public void testGetLastSentLsrPacket() throws Exception {
ospfNbr.setLastSentLsrPacket(new LsRequest());
assertThat(ospfNbr.getLastSentLsrPacket(), is(notNullValue()));
}
/**
* Tests getLastSentLsrPacket() setter method.
*/
@Test
public void testSetLastSentLsrPacket() throws Exception {
ospfNbr.setLastSentLsrPacket(new LsRequest());
assertThat(ospfNbr.getLastSentLsrPacket(), is(notNullValue()));
}
/**
* Tests getState() getter method.
*/
@Test
public void testGetState() throws Exception {
ospfNbr.setState(OspfNeighborState.EXCHANGE);
assertThat(ospfNbr.getState(), is(OspfNeighborState.EXCHANGE));
}
/**
* Tests getState() setter method.
*/
@Test
public void testSetState() throws Exception {
ospfNbr.setState(OspfNeighborState.EXCHANGE);
assertThat(ospfNbr.getState(), is(OspfNeighborState.EXCHANGE));
}
/**
* Tests isMaster() setter method.
*/
@Test
public void testSetIsMaster() throws Exception {
ospfNbr.setIsMaster(1);
assertThat(ospfNbr.isMaster(), is(1));
}
/**
* Tests getLsReqList() method.
*/
@Test
public void testGetLsReqList() throws Exception {
assertThat(ospfNbr.getLsReqList(), is(notNullValue()));
}
/**
* Tests getReTxList() method.
*/
@Test
public void testGetReTxList() throws Exception {
assertThat(ospfNbr.getReTxList(), is(notNullValue()));
}
/**
* Tests getPendingReTxList() method.
*/
@Test
public void testGetPendingReTxList() throws Exception {
assertThat(ospfNbr.getPendingReTxList(), 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.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ip4Address;
import org.onosproject.ospf.controller.DeviceInformation;
import org.onosproject.ospf.controller.OspfLinkTed;
import org.onosproject.ospf.controller.OspfLsa;
import org.onosproject.ospf.controller.area.OspfAreaImpl;
import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
import org.onosproject.ospf.protocol.lsa.TlvHeader;
import org.onosproject.ospf.protocol.lsa.subtypes.OspfLsaLink;
import org.onosproject.ospf.protocol.lsa.tlvtypes.LinkTlv;
import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa10;
import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
import java.util.List;
import java.util.Map;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
* Unit test class for TopologyForDeviceAndLinkImpl.
*/
public class TopologyForDeviceAndLinkImplTest {
private final byte[] packet = {0, 9, 0, 4, 0, 0, 0, 1,
0, 9, 0, 4, 0, 0, 0, 1,
0, 1, 0, 4, 0, 0, 0, 1,
0, 2, 0, 4, 0, 0, 0, 1,
0, 3, 0, 4, 0, 0, 0, 1,
0, 4, 0, 4, 0, 0, 0, 1,
0, 6, 0, 4, 0, 0, 0, 1,
0, 7, 0, 4, 0, 0, 0, 1,
0, 8, 0, 4, 0, 0, 0, 1,
};
private TopologyForDeviceAndLinkImpl topologyForDeviceAndLink;
private Map result;
private LinkTlv linkTlv;
private TlvHeader header;
private ChannelBuffer channelBuffer;
@Before
public void setUp() throws Exception {
topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl();
}
@After
public void tearDown() throws Exception {
topologyForDeviceAndLink = null;
}
/**
* Tests deviceInformationMap() method.
*/
@Test
public void testDeviceInformationMap() throws Exception {
result = topologyForDeviceAndLink.deviceInformationMap();
assertThat(result.size(), is(0));
}
/**
* Tests setDeviceInformationMap() method.
*/
@Test
public void testSetDeviceInformationMap() throws Exception {
topologyForDeviceAndLink.setDeviceInformationMap("1.1.1.1", new DeviceInformationImpl());
result = topologyForDeviceAndLink.deviceInformationMap();
assertThat(result.size(), is(1));
}
/**
* Tests deviceInformation() method.
*/
@Test
public void testDeviceInformation() throws Exception {
topologyForDeviceAndLink.setDeviceInformationMap("1.1.1.1", new DeviceInformationImpl());
DeviceInformation deviceInformation = topologyForDeviceAndLink.deviceInformation("1.1.1.1");
assertThat(deviceInformation, is(notNullValue()));
}
/**
* Tests removeDeviceInformationMap() method.
*/
@Test
public void testRemoveDeviceInformationMap() throws Exception {
topologyForDeviceAndLink.setDeviceInformationMap("1.1.1.1", new DeviceInformationImpl());
topologyForDeviceAndLink.deviceInformation("1.1.1.1");
result = topologyForDeviceAndLink.deviceInformationMap();
topologyForDeviceAndLink.removeDeviceInformationMap("1.1.1.1");
assertThat(result.size(), is(0));
}
/**
* Tests linkInformationMap() method.
*/
@Test
public void testLinkInformationMap() throws Exception {
result = topologyForDeviceAndLink.linkInformationMap();
assertThat(result.size(), is(0));
}
/**
* Tests setLinkInformationMap() method.
*/
@Test
public void testSetLinkInformationMap() throws Exception {
topologyForDeviceAndLink.setLinkInformationMap("1.1.1.1", new LinkInformationImpl());
result = topologyForDeviceAndLink.linkInformationMap();
assertThat(result.size(), is(1));
}
/**
* Tests removeLinkInformationMap() method.
*/
@Test
public void testRemoveLinkInformationMap() throws Exception {
topologyForDeviceAndLink.setLinkInformationMap("1.1.1.1", new LinkInformationImpl());
topologyForDeviceAndLink.removeLinkInformationMap("1.1.1.1");
result = topologyForDeviceAndLink.linkInformationMap();
assertThat(result.size(), is(0));
}
/**
* Tests getOspfLinkTedHashMap() method.
*/
@Test
public void testGetOspfLinkTedHashMap() throws Exception {
OspfLinkTed ospfLinkTed = topologyForDeviceAndLink.getOspfLinkTedHashMap("1.1.1.1");
assertThat(ospfLinkTed, is(nullValue()));
}
/**
* Tests addLocalDevice() method.
*/
@Test
public void testAddLocalDevice() throws Exception {
OspfAreaImpl ospfArea = new OspfAreaImpl();
ospfArea.setRouterId(Ip4Address.valueOf("5.5.5.5"));
topologyForDeviceAndLink.addLocalDevice(createOspfLsa(), new OspfInterfaceImpl(), ospfArea);
topologyForDeviceAndLink.addLocalDevice(createOspfLsa1(), new OspfInterfaceImpl(), ospfArea);
assertThat(topologyForDeviceAndLink, is(notNullValue()));
}
/**
* Tests addLocalLink() method.
*/
@Test
public void testAddLocalLink() throws Exception {
Ip4Address linkData = Ip4Address.valueOf("1.1.1.1");
Ip4Address linkSrc = Ip4Address.valueOf("2.2.2.2");
Ip4Address linkDest = Ip4Address.valueOf("3.3.3.3");
boolean opaqueEnabled = true;
boolean linkSrcIdNotRouterId = true;
topologyForDeviceAndLink.addLocalLink("10.10.10.10", linkData, linkSrc,
linkDest, opaqueEnabled, linkSrcIdNotRouterId);
assertThat(topologyForDeviceAndLink, is(notNullValue()));
}
/**
* Tests removeLinks() method.
*/
@Test
public void testRemoveLinks() throws Exception {
Ip4Address linkData = Ip4Address.valueOf("1.1.1.1");
Ip4Address linkSrc = Ip4Address.valueOf("2.2.2.2");
Ip4Address linkDest = Ip4Address.valueOf("3.3.3.3");
boolean opaqueEnabled = true;
boolean linkSrcIdNotRouterId = true;
topologyForDeviceAndLink.addLocalLink("10.10.10.10", linkData, linkSrc,
linkDest, opaqueEnabled, linkSrcIdNotRouterId);
topologyForDeviceAndLink.removeLinks(Ip4Address.valueOf("10.10.10.10"));
assertThat(topologyForDeviceAndLink, is(notNullValue()));
}
/**
* Tests updateLinkInformation() method.
*/
@Test
public void testUpdateLinkInformation() throws Exception {
OspfAreaImpl ospfArea = new OspfAreaImpl();
ospfArea.setRouterId(Ip4Address.valueOf("5.5.5.5"));
topologyForDeviceAndLink.updateLinkInformation(createOspfLsa(), ospfArea);
assertThat(topologyForDeviceAndLink, is(notNullValue()));
}
/**
* Tests getDeleteRouterInformation() method.
*/
@Test
public void testGetDeleteRouterInformation() throws Exception {
OspfAreaImpl ospfArea = new OspfAreaImpl();
ospfArea.setRouterId(Ip4Address.valueOf("5.5.5.5"));
topologyForDeviceAndLink.updateLinkInformation(createOspfLsa(), ospfArea);
List list = topologyForDeviceAndLink.getDeleteRouterInformation(createOspfLsa(), ospfArea);
assertThat(list, is(notNullValue()));
}
/**
* Utility for test methods.
*/
private OspfLsa createOspfLsa() {
RouterLsa routerLsa = new RouterLsa();
routerLsa.setLsType(1);
routerLsa.setAdvertisingRouter(Ip4Address.valueOf("6.6.6.6"));
OspfLsaLink ospfLsaLink = new OspfLsaLink();
ospfLsaLink.setLinkData("192.168.7.77");
ospfLsaLink.setLinkId("9.9.9.9");
ospfLsaLink.setLinkType(1);
OspfLsaLink ospfLsaLink0 = new OspfLsaLink();
ospfLsaLink0.setLinkData("7.7.7.7");
ospfLsaLink0.setLinkId("7.7.7.7");
ospfLsaLink0.setLinkType(2);
OspfLsaLink ospfLsaLink120 = new OspfLsaLink();
ospfLsaLink120.setLinkData("192.168.7.77");
ospfLsaLink120.setLinkId("1.1.1.1");
ospfLsaLink120.setLinkType(1);
OspfLsaLink lsaLink = new OspfLsaLink();
lsaLink.setLinkData("192.168.7.77");
lsaLink.setLinkId("14.14.14.14");
lsaLink.setLinkType(2);
routerLsa.addRouterLink(lsaLink);
routerLsa.addRouterLink(ospfLsaLink);
routerLsa.addRouterLink(ospfLsaLink0);
routerLsa.addRouterLink(ospfLsaLink120);
return routerLsa;
}
/**
* Utility for test methods.
*/
private OspfLsa createOspfLsa1() throws Exception {
OpaqueLsa10 opaqueLsa10 = new OpaqueLsa10(new OpaqueLsaHeader());
opaqueLsa10.setLsType(10);
header = new TlvHeader();
header.setTlvLength(8);
header.setTlvType(9);
linkTlv = new LinkTlv(header);
channelBuffer = ChannelBuffers.copiedBuffer(packet);
linkTlv.readFrom(channelBuffer);
opaqueLsa10.addValue(linkTlv);
return opaqueLsa10;
}
}