@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)); }
public boolean processReceivedLsa(LsaHeader recLsa, boolean receivedViaFlooding, Channel ch, Ip4Address sourceIp) throws Exception { log.debug("OSPFNbr::processReceivedLsa(recLsa, recievedViaFlooding, ch)...!!!"); ChecksumCalculator checkSum = new ChecksumCalculator(); if (!checkSum.isValidLsaCheckSum(recLsa, recLsa.getOspfLsaType().value(), OspfUtil.LSAPACKET_CHECKSUM_POS1, OspfUtil.LSAPACKET_CHECKSUM_POS2)) { log.debug("Checksum mismatch. Received LSA packet type {} ", recLsa.lsType()); return true; } if (((recLsa.getOspfLsaType().value() > OspfLsaType.EXTERNAL_LSA.value()) && (recLsa.getOspfLsaType().value() < OspfLsaType.LINK_LOCAL_OPAQUE_LSA.value())) || (recLsa.getOspfLsaType().value() > OspfLsaType.AS_OPAQUE_LSA.value())) { return true; } if ((recLsa.getOspfLsaType() == OspfLsaType.EXTERNAL_LSA) && (!ospfArea.isExternalRoutingCapability())) { return true; } if ((recLsa.age() == OspfParameters.MAXAGE) && (ospfArea.lsaLookup(recLsa) == null) && ospfArea.noNeighborInLsaExchangeProcess()) { directAcknowledge(recLsa, ch, sourceIp); return true; } String key = ((OspfAreaImpl) ospfArea).getLsaKey(recLsa); LsaWrapper lsWrapper = ospfArea.lsaLookup(recLsa); String status = isNullorLatest(lsWrapper, recLsa); if (status.equals("isNullorLatest")) { if (recLsa.lsType() == OspfLsaType.ROUTER.value() && recLsa.advertisingRouter().equals( ospfArea.routerId())) { if (recLsa.lsSequenceNo() > ((LsaWrapperImpl) lsWrapper).lsaHeader().lsSequenceNo()) { ospfArea.setDbRouterSequenceNumber(recLsa.lsSequenceNo() + 1); processSelfOriginatedLsa(); } if (recLsa.age() == OspfParameters.MAXAGE) { ((LsaWrapperImpl) lsWrapper).lsaHeader().setAge(OspfParameters.MAXAGE); ospfArea.addLsaToMaxAgeBin(((OspfAreaImpl) ospfArea).getLsaKey(((LsaWrapperImpl) lsWrapper).lsaHeader()), lsWrapper); ospfArea.removeLsaFromBin(lsWrapper); } return true; } else if (recLsa.lsType() == OspfLsaType.NETWORK.value() && isLinkStateMatchesOwnRouterId( recLsa.linkStateId())) { if (((OspfInterfaceImpl) ospfInterface).state() != OspfInterfaceState.DR || !recLsa.advertisingRouter().equals( ospfArea.routerId())) { if (lsWrapper != null) { ((LsaWrapperImpl) lsWrapper).lsaHeader().setAge(OspfParameters.MAXAGE); ospfArea.addLsaToMaxAgeBin(((OspfAreaImpl) ospfArea).getLsaKey(((LsaWrapperImpl) lsWrapper).lsaHeader()), lsWrapper); ospfArea.removeLsaFromBin(lsWrapper); } else { recLsa.setAge(OspfParameters.MAXAGE); ((OspfAreaImpl) ospfArea).addToOtherNeighborLsaTxList(recLsa); } } return true; } else { if (recLsa.age() == OspfParameters.MAXAGE) { ((OspfInterfaceImpl) ospfInterface).addLsaHeaderForDelayAck(recLsa); if (lsWrapper != null) { lsWrapper.setLsaAgeReceived(OspfParameters.MAXAGE); ospfArea.addLsaToMaxAgeBin(((OspfAreaImpl) ospfArea).getLsaKey(((LsaWrapperImpl) lsWrapper).lsaHeader()), lsWrapper); ospfArea.removeLsaFromBin(lsWrapper); } else { ((OspfAreaImpl) ospfArea).addToOtherNeighborLsaTxList(recLsa); } return true; } else { ospfArea.addLsa(recLsa, ospfInterface); log.debug("Inside addLsaMethod"); topologyForDeviceAndLink.addLocalDevice(recLsa, ospfInterface, ospfArea); callDeviceAndLinkAdding(topologyForDeviceAndLink); log.debug("Adding to lsdb interface State {}", ((OspfInterfaceImpl) ospfInterface).state().value()); if (((OspfInterfaceImpl) ospfInterface).state().value() == OspfInterfaceState.BDR.value()) { if (neighborDr.equals(sourceIp)) { log.debug("Adding for delayed ack {}", recLsa); ((OspfInterfaceImpl) ospfInterface).addLsaHeaderForDelayAck(recLsa); } } else { log.debug("Adding for delayed ack {}", recLsa); ((OspfInterfaceImpl) ospfInterface).addLsaHeaderForDelayAck(recLsa); } if (((OspfInterfaceImpl) ospfInterface).state().value() == OspfInterfaceState.DR.value() || ((OspfInterfaceImpl) ospfInterface).state().value() == OspfInterfaceState.POINT2POINT.value()) { ((OspfAreaImpl) ospfArea).addToOtherNeighborLsaTxList(recLsa); } } } } if (lsReqList.contains(key)) { badLSReq(ch); } if (status.equals("same")) { if (pendingReTxList.containsKey(key)) { pendingReTxList.remove(key); if (((OspfInterfaceImpl) ospfInterface).state().value() == OspfInterfaceState.BDR.value()) { if (neighborDr.equals(recLsa.advertisingRouter())) { ((OspfInterfaceImpl) ospfInterface).addLsaHeaderForDelayAck(recLsa); } } } else { directAcknowledge(recLsa, ch, sourceIp); return true; } } else if (status.equals("old")) { if ((recLsa.lsSequenceNo() == OspfParameters.MAXSEQUENCENUMBER) && (recLsa.age() == OspfParameters.MAXAGE)) { return true; } else { int diff = Math.abs(lsWrapper.lsaAgeReceived() - recLsa.age()); if (diff > OspfParameters.MINLSARRIVAL) { sendLsa(((LsaWrapperImpl) lsWrapper).lsaHeader(), sourceIp, ch); } } } constructDeviceInformationFromDb(); callDeviceAndLinkAdding(topologyForDeviceAndLink); return true; }
OspfNbrImpl implements OspfNbr { public boolean processReceivedLsa(LsaHeader recLsa, boolean receivedViaFlooding, Channel ch, Ip4Address sourceIp) throws Exception { log.debug("OSPFNbr::processReceivedLsa(recLsa, recievedViaFlooding, ch)...!!!"); ChecksumCalculator checkSum = new ChecksumCalculator(); if (!checkSum.isValidLsaCheckSum(recLsa, recLsa.getOspfLsaType().value(), OspfUtil.LSAPACKET_CHECKSUM_POS1, OspfUtil.LSAPACKET_CHECKSUM_POS2)) { log.debug("Checksum mismatch. Received LSA packet type {} ", recLsa.lsType()); return true; } if (((recLsa.getOspfLsaType().value() > OspfLsaType.EXTERNAL_LSA.value()) && (recLsa.getOspfLsaType().value() < OspfLsaType.LINK_LOCAL_OPAQUE_LSA.value())) || (recLsa.getOspfLsaType().value() > OspfLsaType.AS_OPAQUE_LSA.value())) { return true; } if ((recLsa.getOspfLsaType() == OspfLsaType.EXTERNAL_LSA) && (!ospfArea.isExternalRoutingCapability())) { return true; } if ((recLsa.age() == OspfParameters.MAXAGE) && (ospfArea.lsaLookup(recLsa) == null) && ospfArea.noNeighborInLsaExchangeProcess()) { directAcknowledge(recLsa, ch, sourceIp); return true; } String key = ((OspfAreaImpl) ospfArea).getLsaKey(recLsa); LsaWrapper lsWrapper = ospfArea.lsaLookup(recLsa); String status = isNullorLatest(lsWrapper, recLsa); if (status.equals("isNullorLatest")) { if (recLsa.lsType() == OspfLsaType.ROUTER.value() && recLsa.advertisingRouter().equals( ospfArea.routerId())) { if (recLsa.lsSequenceNo() > ((LsaWrapperImpl) lsWrapper).lsaHeader().lsSequenceNo()) { ospfArea.setDbRouterSequenceNumber(recLsa.lsSequenceNo() + 1); processSelfOriginatedLsa(); } if (recLsa.age() == OspfParameters.MAXAGE) { ((LsaWrapperImpl) lsWrapper).lsaHeader().setAge(OspfParameters.MAXAGE); ospfArea.addLsaToMaxAgeBin(((OspfAreaImpl) ospfArea).getLsaKey(((LsaWrapperImpl) lsWrapper).lsaHeader()), lsWrapper); ospfArea.removeLsaFromBin(lsWrapper); } return true; } else if (recLsa.lsType() == OspfLsaType.NETWORK.value() && isLinkStateMatchesOwnRouterId( recLsa.linkStateId())) { if (((OspfInterfaceImpl) ospfInterface).state() != OspfInterfaceState.DR || !recLsa.advertisingRouter().equals( ospfArea.routerId())) { if (lsWrapper != null) { ((LsaWrapperImpl) lsWrapper).lsaHeader().setAge(OspfParameters.MAXAGE); ospfArea.addLsaToMaxAgeBin(((OspfAreaImpl) ospfArea).getLsaKey(((LsaWrapperImpl) lsWrapper).lsaHeader()), lsWrapper); ospfArea.removeLsaFromBin(lsWrapper); } else { recLsa.setAge(OspfParameters.MAXAGE); ((OspfAreaImpl) ospfArea).addToOtherNeighborLsaTxList(recLsa); } } return true; } else { if (recLsa.age() == OspfParameters.MAXAGE) { ((OspfInterfaceImpl) ospfInterface).addLsaHeaderForDelayAck(recLsa); if (lsWrapper != null) { lsWrapper.setLsaAgeReceived(OspfParameters.MAXAGE); ospfArea.addLsaToMaxAgeBin(((OspfAreaImpl) ospfArea).getLsaKey(((LsaWrapperImpl) lsWrapper).lsaHeader()), lsWrapper); ospfArea.removeLsaFromBin(lsWrapper); } else { ((OspfAreaImpl) ospfArea).addToOtherNeighborLsaTxList(recLsa); } return true; } else { ospfArea.addLsa(recLsa, ospfInterface); log.debug("Inside addLsaMethod"); topologyForDeviceAndLink.addLocalDevice(recLsa, ospfInterface, ospfArea); callDeviceAndLinkAdding(topologyForDeviceAndLink); log.debug("Adding to lsdb interface State {}", ((OspfInterfaceImpl) ospfInterface).state().value()); if (((OspfInterfaceImpl) ospfInterface).state().value() == OspfInterfaceState.BDR.value()) { if (neighborDr.equals(sourceIp)) { log.debug("Adding for delayed ack {}", recLsa); ((OspfInterfaceImpl) ospfInterface).addLsaHeaderForDelayAck(recLsa); } } else { log.debug("Adding for delayed ack {}", recLsa); ((OspfInterfaceImpl) ospfInterface).addLsaHeaderForDelayAck(recLsa); } if (((OspfInterfaceImpl) ospfInterface).state().value() == OspfInterfaceState.DR.value() || ((OspfInterfaceImpl) ospfInterface).state().value() == OspfInterfaceState.POINT2POINT.value()) { ((OspfAreaImpl) ospfArea).addToOtherNeighborLsaTxList(recLsa); } } } } if (lsReqList.contains(key)) { badLSReq(ch); } if (status.equals("same")) { if (pendingReTxList.containsKey(key)) { pendingReTxList.remove(key); if (((OspfInterfaceImpl) ospfInterface).state().value() == OspfInterfaceState.BDR.value()) { if (neighborDr.equals(recLsa.advertisingRouter())) { ((OspfInterfaceImpl) ospfInterface).addLsaHeaderForDelayAck(recLsa); } } } else { directAcknowledge(recLsa, ch, sourceIp); return true; } } else if (status.equals("old")) { if ((recLsa.lsSequenceNo() == OspfParameters.MAXSEQUENCENUMBER) && (recLsa.age() == OspfParameters.MAXAGE)) { return true; } else { int diff = Math.abs(lsWrapper.lsaAgeReceived() - recLsa.age()); if (diff > OspfParameters.MINLSARRIVAL) { sendLsa(((LsaWrapperImpl) lsWrapper).lsaHeader(), sourceIp, ch); } } } constructDeviceInformationFromDb(); callDeviceAndLinkAdding(topologyForDeviceAndLink); return true; } }
OspfNbrImpl implements OspfNbr { public boolean processReceivedLsa(LsaHeader recLsa, boolean receivedViaFlooding, Channel ch, Ip4Address sourceIp) throws Exception { log.debug("OSPFNbr::processReceivedLsa(recLsa, recievedViaFlooding, ch)...!!!"); ChecksumCalculator checkSum = new ChecksumCalculator(); if (!checkSum.isValidLsaCheckSum(recLsa, recLsa.getOspfLsaType().value(), OspfUtil.LSAPACKET_CHECKSUM_POS1, OspfUtil.LSAPACKET_CHECKSUM_POS2)) { log.debug("Checksum mismatch. Received LSA packet type {} ", recLsa.lsType()); return true; } if (((recLsa.getOspfLsaType().value() > OspfLsaType.EXTERNAL_LSA.value()) && (recLsa.getOspfLsaType().value() < OspfLsaType.LINK_LOCAL_OPAQUE_LSA.value())) || (recLsa.getOspfLsaType().value() > OspfLsaType.AS_OPAQUE_LSA.value())) { return true; } if ((recLsa.getOspfLsaType() == OspfLsaType.EXTERNAL_LSA) && (!ospfArea.isExternalRoutingCapability())) { return true; } if ((recLsa.age() == OspfParameters.MAXAGE) && (ospfArea.lsaLookup(recLsa) == null) && ospfArea.noNeighborInLsaExchangeProcess()) { directAcknowledge(recLsa, ch, sourceIp); return true; } String key = ((OspfAreaImpl) ospfArea).getLsaKey(recLsa); LsaWrapper lsWrapper = ospfArea.lsaLookup(recLsa); String status = isNullorLatest(lsWrapper, recLsa); if (status.equals("isNullorLatest")) { if (recLsa.lsType() == OspfLsaType.ROUTER.value() && recLsa.advertisingRouter().equals( ospfArea.routerId())) { if (recLsa.lsSequenceNo() > ((LsaWrapperImpl) lsWrapper).lsaHeader().lsSequenceNo()) { ospfArea.setDbRouterSequenceNumber(recLsa.lsSequenceNo() + 1); processSelfOriginatedLsa(); } if (recLsa.age() == OspfParameters.MAXAGE) { ((LsaWrapperImpl) lsWrapper).lsaHeader().setAge(OspfParameters.MAXAGE); ospfArea.addLsaToMaxAgeBin(((OspfAreaImpl) ospfArea).getLsaKey(((LsaWrapperImpl) lsWrapper).lsaHeader()), lsWrapper); ospfArea.removeLsaFromBin(lsWrapper); } return true; } else if (recLsa.lsType() == OspfLsaType.NETWORK.value() && isLinkStateMatchesOwnRouterId( recLsa.linkStateId())) { if (((OspfInterfaceImpl) ospfInterface).state() != OspfInterfaceState.DR || !recLsa.advertisingRouter().equals( ospfArea.routerId())) { if (lsWrapper != null) { ((LsaWrapperImpl) lsWrapper).lsaHeader().setAge(OspfParameters.MAXAGE); ospfArea.addLsaToMaxAgeBin(((OspfAreaImpl) ospfArea).getLsaKey(((LsaWrapperImpl) lsWrapper).lsaHeader()), lsWrapper); ospfArea.removeLsaFromBin(lsWrapper); } else { recLsa.setAge(OspfParameters.MAXAGE); ((OspfAreaImpl) ospfArea).addToOtherNeighborLsaTxList(recLsa); } } return true; } else { if (recLsa.age() == OspfParameters.MAXAGE) { ((OspfInterfaceImpl) ospfInterface).addLsaHeaderForDelayAck(recLsa); if (lsWrapper != null) { lsWrapper.setLsaAgeReceived(OspfParameters.MAXAGE); ospfArea.addLsaToMaxAgeBin(((OspfAreaImpl) ospfArea).getLsaKey(((LsaWrapperImpl) lsWrapper).lsaHeader()), lsWrapper); ospfArea.removeLsaFromBin(lsWrapper); } else { ((OspfAreaImpl) ospfArea).addToOtherNeighborLsaTxList(recLsa); } return true; } else { ospfArea.addLsa(recLsa, ospfInterface); log.debug("Inside addLsaMethod"); topologyForDeviceAndLink.addLocalDevice(recLsa, ospfInterface, ospfArea); callDeviceAndLinkAdding(topologyForDeviceAndLink); log.debug("Adding to lsdb interface State {}", ((OspfInterfaceImpl) ospfInterface).state().value()); if (((OspfInterfaceImpl) ospfInterface).state().value() == OspfInterfaceState.BDR.value()) { if (neighborDr.equals(sourceIp)) { log.debug("Adding for delayed ack {}", recLsa); ((OspfInterfaceImpl) ospfInterface).addLsaHeaderForDelayAck(recLsa); } } else { log.debug("Adding for delayed ack {}", recLsa); ((OspfInterfaceImpl) ospfInterface).addLsaHeaderForDelayAck(recLsa); } if (((OspfInterfaceImpl) ospfInterface).state().value() == OspfInterfaceState.DR.value() || ((OspfInterfaceImpl) ospfInterface).state().value() == OspfInterfaceState.POINT2POINT.value()) { ((OspfAreaImpl) ospfArea).addToOtherNeighborLsaTxList(recLsa); } } } } if (lsReqList.contains(key)) { badLSReq(ch); } if (status.equals("same")) { if (pendingReTxList.containsKey(key)) { pendingReTxList.remove(key); if (((OspfInterfaceImpl) ospfInterface).state().value() == OspfInterfaceState.BDR.value()) { if (neighborDr.equals(recLsa.advertisingRouter())) { ((OspfInterfaceImpl) ospfInterface).addLsaHeaderForDelayAck(recLsa); } } } else { directAcknowledge(recLsa, ch, sourceIp); return true; } } else if (status.equals("old")) { if ((recLsa.lsSequenceNo() == OspfParameters.MAXSEQUENCENUMBER) && (recLsa.age() == OspfParameters.MAXAGE)) { return true; } else { int diff = Math.abs(lsWrapper.lsaAgeReceived() - recLsa.age()); if (diff > OspfParameters.MINLSARRIVAL) { sendLsa(((LsaWrapperImpl) lsWrapper).lsaHeader(), sourceIp, ch); } } } constructDeviceInformationFromDb(); callDeviceAndLinkAdding(topologyForDeviceAndLink); return true; } OspfNbrImpl(OspfArea paramOspfArea, OspfInterface paramOspfInterface,
                       Ip4Address ipAddr, Ip4Address routerId, int options,
                       TopologyForDeviceAndLink topologyForDeviceAndLinkCommon); }
OspfNbrImpl implements OspfNbr { public boolean processReceivedLsa(LsaHeader recLsa, boolean receivedViaFlooding, Channel ch, Ip4Address sourceIp) throws Exception { log.debug("OSPFNbr::processReceivedLsa(recLsa, recievedViaFlooding, ch)...!!!"); ChecksumCalculator checkSum = new ChecksumCalculator(); if (!checkSum.isValidLsaCheckSum(recLsa, recLsa.getOspfLsaType().value(), OspfUtil.LSAPACKET_CHECKSUM_POS1, OspfUtil.LSAPACKET_CHECKSUM_POS2)) { log.debug("Checksum mismatch. Received LSA packet type {} ", recLsa.lsType()); return true; } if (((recLsa.getOspfLsaType().value() > OspfLsaType.EXTERNAL_LSA.value()) && (recLsa.getOspfLsaType().value() < OspfLsaType.LINK_LOCAL_OPAQUE_LSA.value())) || (recLsa.getOspfLsaType().value() > OspfLsaType.AS_OPAQUE_LSA.value())) { return true; } if ((recLsa.getOspfLsaType() == OspfLsaType.EXTERNAL_LSA) && (!ospfArea.isExternalRoutingCapability())) { return true; } if ((recLsa.age() == OspfParameters.MAXAGE) && (ospfArea.lsaLookup(recLsa) == null) && ospfArea.noNeighborInLsaExchangeProcess()) { directAcknowledge(recLsa, ch, sourceIp); return true; } String key = ((OspfAreaImpl) ospfArea).getLsaKey(recLsa); LsaWrapper lsWrapper = ospfArea.lsaLookup(recLsa); String status = isNullorLatest(lsWrapper, recLsa); if (status.equals("isNullorLatest")) { if (recLsa.lsType() == OspfLsaType.ROUTER.value() && recLsa.advertisingRouter().equals( ospfArea.routerId())) { if (recLsa.lsSequenceNo() > ((LsaWrapperImpl) lsWrapper).lsaHeader().lsSequenceNo()) { ospfArea.setDbRouterSequenceNumber(recLsa.lsSequenceNo() + 1); processSelfOriginatedLsa(); } if (recLsa.age() == OspfParameters.MAXAGE) { ((LsaWrapperImpl) lsWrapper).lsaHeader().setAge(OspfParameters.MAXAGE); ospfArea.addLsaToMaxAgeBin(((OspfAreaImpl) ospfArea).getLsaKey(((LsaWrapperImpl) lsWrapper).lsaHeader()), lsWrapper); ospfArea.removeLsaFromBin(lsWrapper); } return true; } else if (recLsa.lsType() == OspfLsaType.NETWORK.value() && isLinkStateMatchesOwnRouterId( recLsa.linkStateId())) { if (((OspfInterfaceImpl) ospfInterface).state() != OspfInterfaceState.DR || !recLsa.advertisingRouter().equals( ospfArea.routerId())) { if (lsWrapper != null) { ((LsaWrapperImpl) lsWrapper).lsaHeader().setAge(OspfParameters.MAXAGE); ospfArea.addLsaToMaxAgeBin(((OspfAreaImpl) ospfArea).getLsaKey(((LsaWrapperImpl) lsWrapper).lsaHeader()), lsWrapper); ospfArea.removeLsaFromBin(lsWrapper); } else { recLsa.setAge(OspfParameters.MAXAGE); ((OspfAreaImpl) ospfArea).addToOtherNeighborLsaTxList(recLsa); } } return true; } else { if (recLsa.age() == OspfParameters.MAXAGE) { ((OspfInterfaceImpl) ospfInterface).addLsaHeaderForDelayAck(recLsa); if (lsWrapper != null) { lsWrapper.setLsaAgeReceived(OspfParameters.MAXAGE); ospfArea.addLsaToMaxAgeBin(((OspfAreaImpl) ospfArea).getLsaKey(((LsaWrapperImpl) lsWrapper).lsaHeader()), lsWrapper); ospfArea.removeLsaFromBin(lsWrapper); } else { ((OspfAreaImpl) ospfArea).addToOtherNeighborLsaTxList(recLsa); } return true; } else { ospfArea.addLsa(recLsa, ospfInterface); log.debug("Inside addLsaMethod"); topologyForDeviceAndLink.addLocalDevice(recLsa, ospfInterface, ospfArea); callDeviceAndLinkAdding(topologyForDeviceAndLink); log.debug("Adding to lsdb interface State {}", ((OspfInterfaceImpl) ospfInterface).state().value()); if (((OspfInterfaceImpl) ospfInterface).state().value() == OspfInterfaceState.BDR.value()) { if (neighborDr.equals(sourceIp)) { log.debug("Adding for delayed ack {}", recLsa); ((OspfInterfaceImpl) ospfInterface).addLsaHeaderForDelayAck(recLsa); } } else { log.debug("Adding for delayed ack {}", recLsa); ((OspfInterfaceImpl) ospfInterface).addLsaHeaderForDelayAck(recLsa); } if (((OspfInterfaceImpl) ospfInterface).state().value() == OspfInterfaceState.DR.value() || ((OspfInterfaceImpl) ospfInterface).state().value() == OspfInterfaceState.POINT2POINT.value()) { ((OspfAreaImpl) ospfArea).addToOtherNeighborLsaTxList(recLsa); } } } } if (lsReqList.contains(key)) { badLSReq(ch); } if (status.equals("same")) { if (pendingReTxList.containsKey(key)) { pendingReTxList.remove(key); if (((OspfInterfaceImpl) ospfInterface).state().value() == OspfInterfaceState.BDR.value()) { if (neighborDr.equals(recLsa.advertisingRouter())) { ((OspfInterfaceImpl) ospfInterface).addLsaHeaderForDelayAck(recLsa); } } } else { directAcknowledge(recLsa, ch, sourceIp); return true; } } else if (status.equals("old")) { if ((recLsa.lsSequenceNo() == OspfParameters.MAXSEQUENCENUMBER) && (recLsa.age() == OspfParameters.MAXAGE)) { return true; } else { int diff = Math.abs(lsWrapper.lsaAgeReceived() - recLsa.age()); if (diff > OspfParameters.MINLSARRIVAL) { sendLsa(((LsaWrapperImpl) lsWrapper).lsaHeader(), sourceIp, ch); } } } constructDeviceInformationFromDb(); callDeviceAndLinkAdding(topologyForDeviceAndLink); return true; } OspfNbrImpl(OspfArea paramOspfArea, OspfInterface paramOspfInterface,
                       Ip4Address ipAddr, Ip4Address routerId, int options,
                       TopologyForDeviceAndLink topologyForDeviceAndLinkCommon); Ip4Address neighborIpAddr(); boolean isOpaqueCapable(); void setIsOpaqueCapable(boolean isOpaqueCapable); void setRouterDeadInterval(int routerDeadInterval); void oneWayReceived(OspfMessage ospfHello, Channel channel); void twoWayReceived(OspfMessage ospfMessage, Channel channel); void negotiationDone(OspfMessage ospfMessage,
                                boolean neighborIsMaster, List payload, Channel ch); void processLsas(List ddPayload); OspfMessage seqNumMismatch(String reason); void badLSReq(Channel ch); void processDdPacket(boolean neighborIsMaster, DdPacket dataDescPkt,
                                Channel ch); void exchangeDone(OspfMessage message, Channel ch); void adjOk(Channel ch); void processLsUpdate(LsUpdate lsUpdPkt, Channel ch); void loadingDone(); boolean processReceivedLsa(LsaHeader recLsa,
                                      boolean receivedViaFlooding, Channel ch, Ip4Address sourceIp); String isNullorLatest(LsaWrapper lsWrapper, LsaHeader recLsa); void processSelfOriginatedLsa(); void sendLsa(LsaHeader lsa, Ip4Address destination, Channel ch); void directAcknowledge(LsaHeader ackLsa, Channel ch, Ip4Address sourceIp); void neighborDown(); void startInactivityTimeCheck(); void stopInactivityTimeCheck(); void startFloodingTimer(Channel channel); void stopFloodingTimer(); void stopRxMtDdTimer(); void stopRxMtLsrTimer(); DdPacket lastDdPacket(); void setLastDdPacket(DdPacket lastDdPacket); Ip4Address neighborId(); void setNeighborId(Ip4Address neighborId); Ip4Address neighborDr(); void setNeighborDr(Ip4Address neighborDr); Ip4Address neighborBdr(); void setNeighborBdr(Ip4Address neighborBdr); int routerPriority(); void setRouterPriority(int routerPriority); int options(); void setOptions(int options); long ddSeqNum(); void setDdSeqNum(long ddSeqNum); int isMaster(); DdPacket lastSentDdPacket(); void setLastSentDdPacket(DdPacket lastSentDdPacket); LsRequest getLastSentLsrPacket(); void setLastSentLsrPacket(LsRequest lastSentLsrPacket); OspfNeighborState getState(); void setState(OspfNeighborState state); void setIsMaster(int isMaster); Hashtable getLsReqList(); Map getReTxList(); Map<String, OspfLsa> getPendingReTxList(); }
OspfNbrImpl implements OspfNbr { public boolean processReceivedLsa(LsaHeader recLsa, boolean receivedViaFlooding, Channel ch, Ip4Address sourceIp) throws Exception { log.debug("OSPFNbr::processReceivedLsa(recLsa, recievedViaFlooding, ch)...!!!"); ChecksumCalculator checkSum = new ChecksumCalculator(); if (!checkSum.isValidLsaCheckSum(recLsa, recLsa.getOspfLsaType().value(), OspfUtil.LSAPACKET_CHECKSUM_POS1, OspfUtil.LSAPACKET_CHECKSUM_POS2)) { log.debug("Checksum mismatch. Received LSA packet type {} ", recLsa.lsType()); return true; } if (((recLsa.getOspfLsaType().value() > OspfLsaType.EXTERNAL_LSA.value()) && (recLsa.getOspfLsaType().value() < OspfLsaType.LINK_LOCAL_OPAQUE_LSA.value())) || (recLsa.getOspfLsaType().value() > OspfLsaType.AS_OPAQUE_LSA.value())) { return true; } if ((recLsa.getOspfLsaType() == OspfLsaType.EXTERNAL_LSA) && (!ospfArea.isExternalRoutingCapability())) { return true; } if ((recLsa.age() == OspfParameters.MAXAGE) && (ospfArea.lsaLookup(recLsa) == null) && ospfArea.noNeighborInLsaExchangeProcess()) { directAcknowledge(recLsa, ch, sourceIp); return true; } String key = ((OspfAreaImpl) ospfArea).getLsaKey(recLsa); LsaWrapper lsWrapper = ospfArea.lsaLookup(recLsa); String status = isNullorLatest(lsWrapper, recLsa); if (status.equals("isNullorLatest")) { if (recLsa.lsType() == OspfLsaType.ROUTER.value() && recLsa.advertisingRouter().equals( ospfArea.routerId())) { if (recLsa.lsSequenceNo() > ((LsaWrapperImpl) lsWrapper).lsaHeader().lsSequenceNo()) { ospfArea.setDbRouterSequenceNumber(recLsa.lsSequenceNo() + 1); processSelfOriginatedLsa(); } if (recLsa.age() == OspfParameters.MAXAGE) { ((LsaWrapperImpl) lsWrapper).lsaHeader().setAge(OspfParameters.MAXAGE); ospfArea.addLsaToMaxAgeBin(((OspfAreaImpl) ospfArea).getLsaKey(((LsaWrapperImpl) lsWrapper).lsaHeader()), lsWrapper); ospfArea.removeLsaFromBin(lsWrapper); } return true; } else if (recLsa.lsType() == OspfLsaType.NETWORK.value() && isLinkStateMatchesOwnRouterId( recLsa.linkStateId())) { if (((OspfInterfaceImpl) ospfInterface).state() != OspfInterfaceState.DR || !recLsa.advertisingRouter().equals( ospfArea.routerId())) { if (lsWrapper != null) { ((LsaWrapperImpl) lsWrapper).lsaHeader().setAge(OspfParameters.MAXAGE); ospfArea.addLsaToMaxAgeBin(((OspfAreaImpl) ospfArea).getLsaKey(((LsaWrapperImpl) lsWrapper).lsaHeader()), lsWrapper); ospfArea.removeLsaFromBin(lsWrapper); } else { recLsa.setAge(OspfParameters.MAXAGE); ((OspfAreaImpl) ospfArea).addToOtherNeighborLsaTxList(recLsa); } } return true; } else { if (recLsa.age() == OspfParameters.MAXAGE) { ((OspfInterfaceImpl) ospfInterface).addLsaHeaderForDelayAck(recLsa); if (lsWrapper != null) { lsWrapper.setLsaAgeReceived(OspfParameters.MAXAGE); ospfArea.addLsaToMaxAgeBin(((OspfAreaImpl) ospfArea).getLsaKey(((LsaWrapperImpl) lsWrapper).lsaHeader()), lsWrapper); ospfArea.removeLsaFromBin(lsWrapper); } else { ((OspfAreaImpl) ospfArea).addToOtherNeighborLsaTxList(recLsa); } return true; } else { ospfArea.addLsa(recLsa, ospfInterface); log.debug("Inside addLsaMethod"); topologyForDeviceAndLink.addLocalDevice(recLsa, ospfInterface, ospfArea); callDeviceAndLinkAdding(topologyForDeviceAndLink); log.debug("Adding to lsdb interface State {}", ((OspfInterfaceImpl) ospfInterface).state().value()); if (((OspfInterfaceImpl) ospfInterface).state().value() == OspfInterfaceState.BDR.value()) { if (neighborDr.equals(sourceIp)) { log.debug("Adding for delayed ack {}", recLsa); ((OspfInterfaceImpl) ospfInterface).addLsaHeaderForDelayAck(recLsa); } } else { log.debug("Adding for delayed ack {}", recLsa); ((OspfInterfaceImpl) ospfInterface).addLsaHeaderForDelayAck(recLsa); } if (((OspfInterfaceImpl) ospfInterface).state().value() == OspfInterfaceState.DR.value() || ((OspfInterfaceImpl) ospfInterface).state().value() == OspfInterfaceState.POINT2POINT.value()) { ((OspfAreaImpl) ospfArea).addToOtherNeighborLsaTxList(recLsa); } } } } if (lsReqList.contains(key)) { badLSReq(ch); } if (status.equals("same")) { if (pendingReTxList.containsKey(key)) { pendingReTxList.remove(key); if (((OspfInterfaceImpl) ospfInterface).state().value() == OspfInterfaceState.BDR.value()) { if (neighborDr.equals(recLsa.advertisingRouter())) { ((OspfInterfaceImpl) ospfInterface).addLsaHeaderForDelayAck(recLsa); } } } else { directAcknowledge(recLsa, ch, sourceIp); return true; } } else if (status.equals("old")) { if ((recLsa.lsSequenceNo() == OspfParameters.MAXSEQUENCENUMBER) && (recLsa.age() == OspfParameters.MAXAGE)) { return true; } else { int diff = Math.abs(lsWrapper.lsaAgeReceived() - recLsa.age()); if (diff > OspfParameters.MINLSARRIVAL) { sendLsa(((LsaWrapperImpl) lsWrapper).lsaHeader(), sourceIp, ch); } } } constructDeviceInformationFromDb(); callDeviceAndLinkAdding(topologyForDeviceAndLink); return true; } OspfNbrImpl(OspfArea paramOspfArea, OspfInterface paramOspfInterface,
                       Ip4Address ipAddr, Ip4Address routerId, int options,
                       TopologyForDeviceAndLink topologyForDeviceAndLinkCommon); Ip4Address neighborIpAddr(); boolean isOpaqueCapable(); void setIsOpaqueCapable(boolean isOpaqueCapable); void setRouterDeadInterval(int routerDeadInterval); void oneWayReceived(OspfMessage ospfHello, Channel channel); void twoWayReceived(OspfMessage ospfMessage, Channel channel); void negotiationDone(OspfMessage ospfMessage,
                                boolean neighborIsMaster, List payload, Channel ch); void processLsas(List ddPayload); OspfMessage seqNumMismatch(String reason); void badLSReq(Channel ch); void processDdPacket(boolean neighborIsMaster, DdPacket dataDescPkt,
                                Channel ch); void exchangeDone(OspfMessage message, Channel ch); void adjOk(Channel ch); void processLsUpdate(LsUpdate lsUpdPkt, Channel ch); void loadingDone(); boolean processReceivedLsa(LsaHeader recLsa,
                                      boolean receivedViaFlooding, Channel ch, Ip4Address sourceIp); String isNullorLatest(LsaWrapper lsWrapper, LsaHeader recLsa); void processSelfOriginatedLsa(); void sendLsa(LsaHeader lsa, Ip4Address destination, Channel ch); void directAcknowledge(LsaHeader ackLsa, Channel ch, Ip4Address sourceIp); void neighborDown(); void startInactivityTimeCheck(); void stopInactivityTimeCheck(); void startFloodingTimer(Channel channel); void stopFloodingTimer(); void stopRxMtDdTimer(); void stopRxMtLsrTimer(); DdPacket lastDdPacket(); void setLastDdPacket(DdPacket lastDdPacket); Ip4Address neighborId(); void setNeighborId(Ip4Address neighborId); Ip4Address neighborDr(); void setNeighborDr(Ip4Address neighborDr); Ip4Address neighborBdr(); void setNeighborBdr(Ip4Address neighborBdr); int routerPriority(); void setRouterPriority(int routerPriority); int options(); void setOptions(int options); long ddSeqNum(); void setDdSeqNum(long ddSeqNum); int isMaster(); DdPacket lastSentDdPacket(); void setLastSentDdPacket(DdPacket lastSentDdPacket); LsRequest getLastSentLsrPacket(); void setLastSentLsrPacket(LsRequest lastSentLsrPacket); OspfNeighborState getState(); void setState(OspfNeighborState state); void setIsMaster(int isMaster); Hashtable getLsReqList(); Map getReTxList(); Map<String, OspfLsa> getPendingReTxList();  }