@Test public void testProcessOspfMessage() throws Exception { ospfInterface.setOspfArea(ospfArea); ospfInterface.setInterfaceType(OspfInterfaceType.POINT_TO_POINT.value()); ospfInterface.setIpNetworkMask(Ip4Address.valueOf("0.0.0.0")); ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11")); 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.0.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); helloPacket.setNetworkMask(Ip4Address.valueOf("1.1.1.1")); checksumCalculator = new ChecksumCalculator(); byteArray = helloPacket.asBytes(); helloPacket.setOspfPacLength(byteArray.length); checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13); checkArray[0] = -51; checkArray[1] = 52; buf = ChannelBuffers.copiedBuffer(checkArray); helloPacket.setChecksum(buf.readUnsignedShort()); message = helloPacket; ospfInterface.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()); channelHandlerContext = null; channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); message = ddPacket; ospfInterface.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] = -47; checkArray[1] = -72; buf = ChannelBuffers.copiedBuffer(checkArray); lsRequest.setChecksum(buf.readUnsignedShort()); message = lsRequest; channelHandlerContext = null; channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); ospfInterface.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; ospfInterface.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; channelHandlerContext = null; channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); ospfInterface.processOspfMessage(message, channelHandlerContext); assertThat(ospfInterface, is(notNullValue())); }
public void processOspfMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception { log.debug("OspfChannelHandler::processOspfMessage...!!!"); if (!validateMessage(ospfMessage)) { return; } switch (ospfMessage.ospfMessageType().value()) { case OspfParameters.HELLO: processHelloMessage(ospfMessage, ctx); break; case OspfParameters.DD: processDdMessage(ospfMessage, ctx); break; case OspfParameters.LSREQUEST: processLsRequestMessage(ospfMessage, ctx); break; case OspfParameters.LSUPDATE: processLsUpdateMessage(ospfMessage, ctx); break; case OspfParameters.LSACK: processLsAckMessage(ospfMessage, ctx); break; default: log.debug("Unknown packet to process...!!!"); break; } }
OspfInterfaceImpl implements OspfInterface { public void processOspfMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception { log.debug("OspfChannelHandler::processOspfMessage...!!!"); if (!validateMessage(ospfMessage)) { return; } switch (ospfMessage.ospfMessageType().value()) { case OspfParameters.HELLO: processHelloMessage(ospfMessage, ctx); break; case OspfParameters.DD: processDdMessage(ospfMessage, ctx); break; case OspfParameters.LSREQUEST: processLsRequestMessage(ospfMessage, ctx); break; case OspfParameters.LSUPDATE: processLsUpdateMessage(ospfMessage, ctx); break; case OspfParameters.LSACK: processLsAckMessage(ospfMessage, ctx); break; default: log.debug("Unknown packet to process...!!!"); break; } } }
OspfInterfaceImpl implements OspfInterface { public void processOspfMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception { log.debug("OspfChannelHandler::processOspfMessage...!!!"); if (!validateMessage(ospfMessage)) { return; } switch (ospfMessage.ospfMessageType().value()) { case OspfParameters.HELLO: processHelloMessage(ospfMessage, ctx); break; case OspfParameters.DD: processDdMessage(ospfMessage, ctx); break; case OspfParameters.LSREQUEST: processLsRequestMessage(ospfMessage, ctx); break; case OspfParameters.LSUPDATE: processLsUpdateMessage(ospfMessage, ctx); break; case OspfParameters.LSACK: processLsAckMessage(ospfMessage, ctx); break; default: log.debug("Unknown packet to process...!!!"); break; } }  }
OspfInterfaceImpl implements OspfInterface { public void processOspfMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception { log.debug("OspfChannelHandler::processOspfMessage...!!!"); if (!validateMessage(ospfMessage)) { return; } switch (ospfMessage.ospfMessageType().value()) { case OspfParameters.HELLO: processHelloMessage(ospfMessage, ctx); break; case OspfParameters.DD: processDdMessage(ospfMessage, ctx); break; case OspfParameters.LSREQUEST: processLsRequestMessage(ospfMessage, ctx); break; case OspfParameters.LSUPDATE: processLsUpdateMessage(ospfMessage, ctx); break; case OspfParameters.LSACK: processLsAckMessage(ospfMessage, ctx); break; default: log.debug("Unknown packet to process...!!!"); break; } }  OspfInterfaceState state(); void setState(OspfInterfaceState ospfInterfaceState); void setChannel(Channel channel); OspfArea ospfArea(); void setController(Controller controller); void setOspfArea(OspfArea ospfArea); String interfaceState(); List<LsaHeader> linkStateHeaders(); Ip4Address ipNetworkMask(); @Override void setIpNetworkMask(Ip4Address ipNetworkMask); void addNeighbouringRouter(OspfNbr ospfNbr); OspfNbr neighbouringRouter(String neighborId); void removeNeighbors(); void removeNeighbor(OspfNbr ospfNeighbor); void addLsaHeaderForDelayAck(LsaHeader lsaHeader); void removeLsaFromNeighborMap(String lsaKey); boolean isNeighborInList(String neighborId); Map<String, OspfNbr> listOfNeighbors(); void setListOfNeighbors(HashMap<String, OspfNbr> listOfNeighbors); int interfaceIndex(); void setInterfaceIndex(int interfaceIndex); Ip4Address ipAddress(); void setIpAddress(Ip4Address ipAddress); int routerPriority(); void setRouterPriority(int routerPriority); int helloIntervalTime(); void setHelloIntervalTime(int helloIntervalTime); int routerDeadIntervalTime(); void setRouterDeadIntervalTime(int routerDeadIntervalTime); int interfaceType(); void setInterfaceType(int interfaceType); int mtu(); void setMtu(int mtu); int reTransmitInterval(); void setReTransmitInterval(int reTransmitInterval); Ip4Address dr(); void setDr(Ip4Address dr); Ip4Address bdr(); void setBdr(Ip4Address bdr); void interfaceUp(); void backupSeen(Channel ch); void waitTimer(Channel ch); void callDrElection(Channel ch); void neighborChange(); void interfaceDown(); void processOspfMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx); boolean compareDdPackets(DdPacket receivedDPacket, DdPacket lastDdPacket); void startHelloTimer(); void stopHelloTimer(); void startWaitTimer(); void stopWaitTimer(); void startDelayedAckTimer(); void stopDelayedAckTimer(); void electRouter(Channel ch); List<OspfEligibleRouter> calculateListOfEligibleRouters(OspfEligibleRouter electedDr); OspfEligibleRouter electBdr(List<OspfEligibleRouter> eligibleRouters); OspfEligibleRouter electDr(List<OspfEligibleRouter> eligibleRouters,
                                      OspfEligibleRouter electedBdr); OspfEligibleRouter selectRouterBasedOnPriority(List<OspfEligibleRouter> routersList); void addDeviceInformation(OspfRouter ospfRouter); void removeDeviceInformation(OspfRouter ospfRouter); void addLinkInformation(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed); void removeLinkInformation(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
OspfInterfaceImpl implements OspfInterface { public void processOspfMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception { log.debug("OspfChannelHandler::processOspfMessage...!!!"); if (!validateMessage(ospfMessage)) { return; } switch (ospfMessage.ospfMessageType().value()) { case OspfParameters.HELLO: processHelloMessage(ospfMessage, ctx); break; case OspfParameters.DD: processDdMessage(ospfMessage, ctx); break; case OspfParameters.LSREQUEST: processLsRequestMessage(ospfMessage, ctx); break; case OspfParameters.LSUPDATE: processLsUpdateMessage(ospfMessage, ctx); break; case OspfParameters.LSACK: processLsAckMessage(ospfMessage, ctx); break; default: log.debug("Unknown packet to process...!!!"); break; } }  OspfInterfaceState state(); void setState(OspfInterfaceState ospfInterfaceState); void setChannel(Channel channel); OspfArea ospfArea(); void setController(Controller controller); void setOspfArea(OspfArea ospfArea); String interfaceState(); List<LsaHeader> linkStateHeaders(); Ip4Address ipNetworkMask(); @Override void setIpNetworkMask(Ip4Address ipNetworkMask); void addNeighbouringRouter(OspfNbr ospfNbr); OspfNbr neighbouringRouter(String neighborId); void removeNeighbors(); void removeNeighbor(OspfNbr ospfNeighbor); void addLsaHeaderForDelayAck(LsaHeader lsaHeader); void removeLsaFromNeighborMap(String lsaKey); boolean isNeighborInList(String neighborId); Map<String, OspfNbr> listOfNeighbors(); void setListOfNeighbors(HashMap<String, OspfNbr> listOfNeighbors); int interfaceIndex(); void setInterfaceIndex(int interfaceIndex); Ip4Address ipAddress(); void setIpAddress(Ip4Address ipAddress); int routerPriority(); void setRouterPriority(int routerPriority); int helloIntervalTime(); void setHelloIntervalTime(int helloIntervalTime); int routerDeadIntervalTime(); void setRouterDeadIntervalTime(int routerDeadIntervalTime); int interfaceType(); void setInterfaceType(int interfaceType); int mtu(); void setMtu(int mtu); int reTransmitInterval(); void setReTransmitInterval(int reTransmitInterval); Ip4Address dr(); void setDr(Ip4Address dr); Ip4Address bdr(); void setBdr(Ip4Address bdr); void interfaceUp(); void backupSeen(Channel ch); void waitTimer(Channel ch); void callDrElection(Channel ch); void neighborChange(); void interfaceDown(); void processOspfMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx); boolean compareDdPackets(DdPacket receivedDPacket, DdPacket lastDdPacket); void startHelloTimer(); void stopHelloTimer(); void startWaitTimer(); void stopWaitTimer(); void startDelayedAckTimer(); void stopDelayedAckTimer(); void electRouter(Channel ch); List<OspfEligibleRouter> calculateListOfEligibleRouters(OspfEligibleRouter electedDr); OspfEligibleRouter electBdr(List<OspfEligibleRouter> eligibleRouters); OspfEligibleRouter electDr(List<OspfEligibleRouter> eligibleRouters,
                                      OspfEligibleRouter electedBdr); OspfEligibleRouter selectRouterBasedOnPriority(List<OspfEligibleRouter> routersList); void addDeviceInformation(OspfRouter ospfRouter); void removeDeviceInformation(OspfRouter ospfRouter); void addLinkInformation(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed); void removeLinkInformation(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }