/** 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 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())); }
@Before public void setUp() throws Exception { ospfProcess = new OspfProcessImpl(); ospfArea = createOspfArea(); ospfAreas.add(ospfArea); ospfProcess.setAreas(ospfAreas); ospfProcesses.add(ospfProcess); controller = new Controller(); topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl(); ospfNbr = new OspfNbrImpl( ospfArea, ospfInterface, ip4Address1, ip4Address2, 2, topologyForDeviceAndLink); ospfNbr.setNeighborId(ip4Address1); ospfNbr.setRouterPriority(0); ospfNbr.setNeighborDr(ip4Address3); ospfInterface.addNeighbouringRouter(ospfNbr); ospfInterfaceChannelHandler = new OspfInterfaceChannelHandler(controller, ospfProcesses); }
/** 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, ip4Address5, ip4Address6, 2, topologyForDeviceAndLink); ospfNbr.setState(OspfNeighborState.FULL); ospfNbr.setNeighborId(ip4Address7); ospfInterface = new OspfInterfaceImpl(); ospfInterface.setIpAddress(ip4Address5); ospfInterface.setIpNetworkMask(subnetAddress); ospfInterface.setBdr(ip4Address4); ospfInterface.setDr(ip4Address4); ospfInterface.setHelloIntervalTime(20); ospfInterface.setInterfaceType(2); ospfInterface.setReTransmitInterval(2000); ospfInterface.setMtu(6500); ospfInterface.setRouterDeadIntervalTime(1000); ospfInterface.setRouterPriority(1); ospfInterface.setInterfaceType(1); ospfInterface.addNeighbouringRouter(ospfNbr); return ospfInterface; }