/** 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; }
/** 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())); }