@Test public void testBuildNetworkLsa() throws Exception { ospfInterfaces = new ArrayList(); ospfInterface1 = new OspfInterfaceImpl(); ospfInterface1.setIpAddress(Ip4Address.valueOf("1.1.1.1")); ospfInterfaces.add(ospfInterface1); ospfInterface2 = new OspfInterfaceImpl(); ospfInterface2.setIpAddress(Ip4Address.valueOf("2.2.2.2")); ospfInterfaces.add(ospfInterface2); ospfInterface3 = new OspfInterfaceImpl(); ospfInterface3.setIpAddress(Ip4Address.valueOf("3.3.3.3")); ospfInterfaces.add(ospfInterface3); ospfArea.setOspfInterfaceList(ospfInterfaces); ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111")); networkLsa = ospfArea.buildNetworkLsa(Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("255.255.255.255")); assertThat(ospfInterfaces.size(), is(3)); assertThat(networkLsa, is(notNullValue())); assertThat(ospfArea, is(notNullValue())); }
public NetworkLsa buildNetworkLsa(Ip4Address interfaceIp, Ip4Address mask) throws Exception { NetworkLsa networkLsa = new NetworkLsa(); networkLsa.setAdvertisingRouter(routerId); networkLsa.setLinkStateId(interfaceIp.toString()); networkLsa.setLsType(OspfLsaType.NETWORK.value()); networkLsa.setAge(1); networkLsa.setOptions(2); networkLsa.setNetworkMask(mask); networkLsa.addAttachedRouter(routerId()); Iterator iter = ospfInterfaceList.iterator(); OspfInterfaceImpl ospfInterface = null; while (iter.hasNext()) { ospfInterface = (OspfInterfaceImpl) iter.next(); if (ospfInterface.ipAddress().equals(interfaceIp)) { break; } } if (ospfInterface != null) { List<OspfNbr> neighborsInFullState = getNeighborsInFullState(ospfInterface); if (neighborsInFullState != null) { for (OspfNbr ospfnbr : neighborsInFullState) { networkLsa.addAttachedRouter(ospfnbr.neighborId()); log.debug("Adding attached neighbor:: {}", ospfnbr.neighborId()); } } } networkLsa.setLsSequenceNo(database.getLsSequenceNumber(OspfLsaType.NETWORK)); ChecksumCalculator checksum = new ChecksumCalculator(); byte[] lsaBytes = networkLsa.asBytes(); networkLsa.setLsPacketLen(lsaBytes.length); lsaBytes = networkLsa.asBytes(); byte[] twoByteChecksum = checksum.calculateLsaChecksum(lsaBytes, OspfUtil.LSAPACKET_CHECKSUM_POS1, OspfUtil.LSAPACKET_CHECKSUM_POS2); int checkSumVal = OspfUtil.byteToInteger(twoByteChecksum); networkLsa.setLsCheckSum(checkSumVal); return networkLsa; }
OspfAreaImpl implements OspfArea { public NetworkLsa buildNetworkLsa(Ip4Address interfaceIp, Ip4Address mask) throws Exception { NetworkLsa networkLsa = new NetworkLsa(); networkLsa.setAdvertisingRouter(routerId); networkLsa.setLinkStateId(interfaceIp.toString()); networkLsa.setLsType(OspfLsaType.NETWORK.value()); networkLsa.setAge(1); networkLsa.setOptions(2); networkLsa.setNetworkMask(mask); networkLsa.addAttachedRouter(routerId()); Iterator iter = ospfInterfaceList.iterator(); OspfInterfaceImpl ospfInterface = null; while (iter.hasNext()) { ospfInterface = (OspfInterfaceImpl) iter.next(); if (ospfInterface.ipAddress().equals(interfaceIp)) { break; } } if (ospfInterface != null) { List<OspfNbr> neighborsInFullState = getNeighborsInFullState(ospfInterface); if (neighborsInFullState != null) { for (OspfNbr ospfnbr : neighborsInFullState) { networkLsa.addAttachedRouter(ospfnbr.neighborId()); log.debug("Adding attached neighbor:: {}", ospfnbr.neighborId()); } } } networkLsa.setLsSequenceNo(database.getLsSequenceNumber(OspfLsaType.NETWORK)); ChecksumCalculator checksum = new ChecksumCalculator(); byte[] lsaBytes = networkLsa.asBytes(); networkLsa.setLsPacketLen(lsaBytes.length); lsaBytes = networkLsa.asBytes(); byte[] twoByteChecksum = checksum.calculateLsaChecksum(lsaBytes, OspfUtil.LSAPACKET_CHECKSUM_POS1, OspfUtil.LSAPACKET_CHECKSUM_POS2); int checkSumVal = OspfUtil.byteToInteger(twoByteChecksum); networkLsa.setLsCheckSum(checkSumVal); return networkLsa; } }
OspfAreaImpl implements OspfArea { public NetworkLsa buildNetworkLsa(Ip4Address interfaceIp, Ip4Address mask) throws Exception { NetworkLsa networkLsa = new NetworkLsa(); networkLsa.setAdvertisingRouter(routerId); networkLsa.setLinkStateId(interfaceIp.toString()); networkLsa.setLsType(OspfLsaType.NETWORK.value()); networkLsa.setAge(1); networkLsa.setOptions(2); networkLsa.setNetworkMask(mask); networkLsa.addAttachedRouter(routerId()); Iterator iter = ospfInterfaceList.iterator(); OspfInterfaceImpl ospfInterface = null; while (iter.hasNext()) { ospfInterface = (OspfInterfaceImpl) iter.next(); if (ospfInterface.ipAddress().equals(interfaceIp)) { break; } } if (ospfInterface != null) { List<OspfNbr> neighborsInFullState = getNeighborsInFullState(ospfInterface); if (neighborsInFullState != null) { for (OspfNbr ospfnbr : neighborsInFullState) { networkLsa.addAttachedRouter(ospfnbr.neighborId()); log.debug("Adding attached neighbor:: {}", ospfnbr.neighborId()); } } } networkLsa.setLsSequenceNo(database.getLsSequenceNumber(OspfLsaType.NETWORK)); ChecksumCalculator checksum = new ChecksumCalculator(); byte[] lsaBytes = networkLsa.asBytes(); networkLsa.setLsPacketLen(lsaBytes.length); lsaBytes = networkLsa.asBytes(); byte[] twoByteChecksum = checksum.calculateLsaChecksum(lsaBytes, OspfUtil.LSAPACKET_CHECKSUM_POS1, OspfUtil.LSAPACKET_CHECKSUM_POS2); int checkSumVal = OspfUtil.byteToInteger(twoByteChecksum); networkLsa.setLsCheckSum(checkSumVal); return networkLsa; } OspfAreaImpl(); }
OspfAreaImpl implements OspfArea { public NetworkLsa buildNetworkLsa(Ip4Address interfaceIp, Ip4Address mask) throws Exception { NetworkLsa networkLsa = new NetworkLsa(); networkLsa.setAdvertisingRouter(routerId); networkLsa.setLinkStateId(interfaceIp.toString()); networkLsa.setLsType(OspfLsaType.NETWORK.value()); networkLsa.setAge(1); networkLsa.setOptions(2); networkLsa.setNetworkMask(mask); networkLsa.addAttachedRouter(routerId()); Iterator iter = ospfInterfaceList.iterator(); OspfInterfaceImpl ospfInterface = null; while (iter.hasNext()) { ospfInterface = (OspfInterfaceImpl) iter.next(); if (ospfInterface.ipAddress().equals(interfaceIp)) { break; } } if (ospfInterface != null) { List<OspfNbr> neighborsInFullState = getNeighborsInFullState(ospfInterface); if (neighborsInFullState != null) { for (OspfNbr ospfnbr : neighborsInFullState) { networkLsa.addAttachedRouter(ospfnbr.neighborId()); log.debug("Adding attached neighbor:: {}", ospfnbr.neighborId()); } } } networkLsa.setLsSequenceNo(database.getLsSequenceNumber(OspfLsaType.NETWORK)); ChecksumCalculator checksum = new ChecksumCalculator(); byte[] lsaBytes = networkLsa.asBytes(); networkLsa.setLsPacketLen(lsaBytes.length); lsaBytes = networkLsa.asBytes(); byte[] twoByteChecksum = checksum.calculateLsaChecksum(lsaBytes, OspfUtil.LSAPACKET_CHECKSUM_POS1, OspfUtil.LSAPACKET_CHECKSUM_POS2); int checkSumVal = OspfUtil.byteToInteger(twoByteChecksum); networkLsa.setLsCheckSum(checkSumVal); return networkLsa; } OspfAreaImpl(); @Override boolean equals(Object o); @Override int hashCode(); Ip4Address routerId(); @JsonProperty("routerId") void setRouterId(Ip4Address routerId); @JsonProperty("isOpaqueEnable") void setIsOpaqueEnabled(boolean isOpaqueEnable); boolean isOpaqueEnabled(); void initializeDb(); @Override void refreshArea(OspfInterface ospfInterface); NetworkLsa buildNetworkLsa(Ip4Address interfaceIp, Ip4Address mask); RouterLsa buildRouterLsa(OspfInterface ospfInterface); Ip4Address areaId(); @JsonProperty("areaId") void setAreaId(Ip4Address areaId); boolean isExternalRoutingCapability(); @JsonProperty("externalRoutingCapability") void setExternalRoutingCapability(boolean externalRoutingCapability); List<OspfInterface> ospfInterfaceList(); @JsonProperty("interface") void setOspfInterfaceList(List<OspfInterface> ospfInterfaceList); boolean noNeighborInLsaExchangeProcess(); List getLsaHeaders(boolean excludeMaxAgeLsa, boolean isOpaquecapable); LsaWrapper getLsa(int lsType, String linkStateID, String advertisingRouter); LsaWrapper lsaLookup(OspfLsa lookupLsa); String isNewerOrSameLsa(OspfLsa lsa1, OspfLsa lsa2); void addLsa(OspfLsa ospfLsa, OspfInterface ospfInterface); void addLsa(OspfLsa ospfLsa, boolean isSelfOriginated, OspfInterface ospfInterface); void addLsaToMaxAgeBin(String key, LsaWrapper wrapper); void setDbRouterSequenceNumber(long newSequenceNumber); void deleteLsa(LsaHeader ospfLsa); void removeLsaFromBin(LsaWrapper lsaWrapper); @Override String toString(); List<OspfNbr> getNeighborsInFullState(OspfInterface ospfInterface); String getLsaKey(LsaHeader lsaHeader); void addToOtherNeighborLsaTxList(LsaHeader recLsa); int options(); void setOptions(int options); int opaqueEnabledOptions(); OspfLsdb database(); }
OspfAreaImpl implements OspfArea { public NetworkLsa buildNetworkLsa(Ip4Address interfaceIp, Ip4Address mask) throws Exception { NetworkLsa networkLsa = new NetworkLsa(); networkLsa.setAdvertisingRouter(routerId); networkLsa.setLinkStateId(interfaceIp.toString()); networkLsa.setLsType(OspfLsaType.NETWORK.value()); networkLsa.setAge(1); networkLsa.setOptions(2); networkLsa.setNetworkMask(mask); networkLsa.addAttachedRouter(routerId()); Iterator iter = ospfInterfaceList.iterator(); OspfInterfaceImpl ospfInterface = null; while (iter.hasNext()) { ospfInterface = (OspfInterfaceImpl) iter.next(); if (ospfInterface.ipAddress().equals(interfaceIp)) { break; } } if (ospfInterface != null) { List<OspfNbr> neighborsInFullState = getNeighborsInFullState(ospfInterface); if (neighborsInFullState != null) { for (OspfNbr ospfnbr : neighborsInFullState) { networkLsa.addAttachedRouter(ospfnbr.neighborId()); log.debug("Adding attached neighbor:: {}", ospfnbr.neighborId()); } } } networkLsa.setLsSequenceNo(database.getLsSequenceNumber(OspfLsaType.NETWORK)); ChecksumCalculator checksum = new ChecksumCalculator(); byte[] lsaBytes = networkLsa.asBytes(); networkLsa.setLsPacketLen(lsaBytes.length); lsaBytes = networkLsa.asBytes(); byte[] twoByteChecksum = checksum.calculateLsaChecksum(lsaBytes, OspfUtil.LSAPACKET_CHECKSUM_POS1, OspfUtil.LSAPACKET_CHECKSUM_POS2); int checkSumVal = OspfUtil.byteToInteger(twoByteChecksum); networkLsa.setLsCheckSum(checkSumVal); return networkLsa; } OspfAreaImpl(); @Override boolean equals(Object o); @Override int hashCode(); Ip4Address routerId(); @JsonProperty("routerId") void setRouterId(Ip4Address routerId); @JsonProperty("isOpaqueEnable") void setIsOpaqueEnabled(boolean isOpaqueEnable); boolean isOpaqueEnabled(); void initializeDb(); @Override void refreshArea(OspfInterface ospfInterface); NetworkLsa buildNetworkLsa(Ip4Address interfaceIp, Ip4Address mask); RouterLsa buildRouterLsa(OspfInterface ospfInterface); Ip4Address areaId(); @JsonProperty("areaId") void setAreaId(Ip4Address areaId); boolean isExternalRoutingCapability(); @JsonProperty("externalRoutingCapability") void setExternalRoutingCapability(boolean externalRoutingCapability); List<OspfInterface> ospfInterfaceList(); @JsonProperty("interface") void setOspfInterfaceList(List<OspfInterface> ospfInterfaceList); boolean noNeighborInLsaExchangeProcess(); List getLsaHeaders(boolean excludeMaxAgeLsa, boolean isOpaquecapable); LsaWrapper getLsa(int lsType, String linkStateID, String advertisingRouter); LsaWrapper lsaLookup(OspfLsa lookupLsa); String isNewerOrSameLsa(OspfLsa lsa1, OspfLsa lsa2); void addLsa(OspfLsa ospfLsa, OspfInterface ospfInterface); void addLsa(OspfLsa ospfLsa, boolean isSelfOriginated, OspfInterface ospfInterface); void addLsaToMaxAgeBin(String key, LsaWrapper wrapper); void setDbRouterSequenceNumber(long newSequenceNumber); void deleteLsa(LsaHeader ospfLsa); void removeLsaFromBin(LsaWrapper lsaWrapper); @Override String toString(); List<OspfNbr> getNeighborsInFullState(OspfInterface ospfInterface); String getLsaKey(LsaHeader lsaHeader); void addToOtherNeighborLsaTxList(LsaHeader recLsa); int options(); void setOptions(int options); int opaqueEnabledOptions(); OspfLsdb database();  }