Link extends NetworkElement implements IMonitorizableElement { @Override void checkCachesConsistency () { super.checkCachesConsistency (); if (layer.netPlan != this.netPlan) throw new RuntimeException ("Bad"); if (!layer.links.contains(this)) throw new RuntimeException ("Bad"); if (this.bidirectionalPair != null) { if (this.bidirectionalPair.bidirectionalPair != this) throw new RuntimeException ("Bad"); if (this.bidirectionalPair.netPlan != this.netPlan) throw new RuntimeException ("Bad"); if (this.bidirectionalPair.originNode != this.destinationNode) throw new RuntimeException ("Bad"); if (this.bidirectionalPair.destinationNode != this.originNode) throw new RuntimeException ("Bad"); if (this.bidirectionalPair.layer != this.layer) throw new RuntimeException ("Bad"); } if (isUp && layer.cache_linksDown.contains(this)) throw new RuntimeException ("Bad"); if (!isUp && !layer.cache_linksDown.contains(this)) throw new RuntimeException ("Bad"); if (isCoupled ()) if (capacity > 0 && (!originNode.isUp || !destinationNode.isUp)) throw new RuntimeException ("Bad. Link: " + this + ", capacity: " + this.capacity + ", isUp: " + this.isUp + ", origin up: " + originNode.isUp + ", dest up: " + destinationNode.isUp); if (capacity < Configuration.precisionFactor && !layer.cache_linksZeroCap.contains(this)) throw new RuntimeException ("Bad"); if (capacity >= Configuration.precisionFactor && layer.cache_linksZeroCap.contains(this)) throw new RuntimeException ("Bad"); if (!isUp) { if (Math.abs(cache_totalCarriedTraffic) > 1e-3) throw new RuntimeException ("Bad"); if (Math.abs(cache_totalOccupiedCapacity) > 1e-3) throw new RuntimeException ("Bad"); for (Route r : cache_traversingRoutes.keySet()) if ((r.getCarriedTraffic() != 0) || (r.getOccupiedCapacity(this) != 0)) throw new RuntimeException ("Bad"); for (MulticastTree r : cache_traversingTrees) if ((r.getCarriedTraffic() != 0) || (r.getOccupiedLinkCapacity() != 0)) throw new RuntimeException ("Bad"); } if (this.isCoupledInSameLayer()) { final SortedSet<Link> upIntraLayerPropLinks = getIntraLayerUpPropagationIncludingMe(); final SortedSet<Link> downIntraLayerPropLinks = coupledLowerOrThisLayerDemand.getLinksThisLayerNonZeroFrOrTravRoutes(true); if (!Sets.intersection(upIntraLayerPropLinks, downIntraLayerPropLinks).isEmpty()) throw new RuntimeException (); } for (SharedRiskGroup srg : netPlan.srgs) { if (!srg.isDynamicSrg()) if (this.cache_nonDynamicSrgs.contains(srg) != srg.getLinksAllLayers().contains(this)) throw new RuntimeException ("Bad"); } for (Demand d : cacheHbH_frs.keySet()) if (d.isSourceRouting()) throw new RuntimeException (); for (Demand d : cacheHbH_normCarriedOccupiedPerTraversingDemandCurrentState.keySet()) if (d.isSourceRouting()) throw new RuntimeException (); for (Route r : cache_traversingRoutes.keySet()) if (!r.getDemand().isSourceRouting()) throw new RuntimeException (); double check_totalCarriedTraffic = 0; double check_totalOccupiedCapacity = 0; SortedMap<String,Double> check_occupAndViolationPerQos = new TreeMap<> (); for (Route route : layer.routes) { if (!route.getDemand().isSourceRouting()) throw new RuntimeException (); if (this.cache_traversingRoutes.containsKey(route) != route.cache_seqLinksRealPath.contains(this)) throw new RuntimeException ("Bad. link: " + this + ", route: " + route + ", this.cache_traversingRoutes: " + this.cache_traversingRoutes + ", route.seqLinksRealPath: "+ route.cache_seqLinksRealPath); if (this.cache_traversingRoutes.containsKey(route)) { int numPasses = 0; for (Link linkRoute : route.cache_seqLinksRealPath) if (linkRoute == this) numPasses ++; if (numPasses != this.cache_traversingRoutes.get(route)) throw new RuntimeException ("Bad"); check_totalCarriedTraffic += route.getCarriedTraffic(); check_totalOccupiedCapacity += route.getOccupiedCapacity(this); final String qos = route.demand.getQosType(); if (check_occupAndViolationPerQos.containsKey(qos)) check_occupAndViolationPerQos.put(qos , check_occupAndViolationPerQos.get(qos) + route.getOccupiedCapacity(this)); else check_occupAndViolationPerQos.put(qos , route.getOccupiedCapacity(this)); } } if (!cacheHbH_frs.keySet().containsAll(cacheHbH_normCarriedOccupiedPerTraversingDemandCurrentState.keySet())) throw new RuntimeException(); for (Demand d : this.cacheHbH_frs.keySet()) { final double splitFactor = cacheHbH_frs.get(d); if (splitFactor <= 0) throw new RuntimeException(); if (splitFactor > 1 + Configuration.precisionFactor)throw new RuntimeException("split: " + splitFactor); if (d.cacheHbH_frs.get(this) != splitFactor) throw new RuntimeException (); } for (Demand d : this.cacheHbH_normCarriedOccupiedPerTraversingDemandCurrentState.keySet()) { final double normTraffic = this.cacheHbH_normCarriedOccupiedPerTraversingDemandCurrentState.get(d).getFirst(); final double cap = this.cacheHbH_normCarriedOccupiedPerTraversingDemandCurrentState.get(d).getSecond(); if (!d.cacheHbH_normCarriedOccupiedPerLinkCurrentState.get(this).equals(Pair.of(normTraffic, cap))) throw new RuntimeException (); if (Math.abs(normTraffic * d.offeredTraffic - cap) > 1e-3) throw new RuntimeException(); check_totalCarriedTraffic += cap; check_totalOccupiedCapacity += cap; final String qos = d.getQosType(); if (check_occupAndViolationPerQos.containsKey(qos)) check_occupAndViolationPerQos.put(qos , check_occupAndViolationPerQos.get(qos) + cap); else check_occupAndViolationPerQos.put(qos , cap); } for (MulticastTree tree : layer.multicastTrees) { if (this.cache_traversingTrees.contains(tree) != tree.linkSet.contains(this)) throw new RuntimeException ("Bad"); if (this.cache_traversingTrees.contains(tree)) { check_totalCarriedTraffic += tree.getCarriedTraffic(); check_totalOccupiedCapacity += tree.getOccupiedLinkCapacity(); final String qos = tree.getMulticastDemand().getQosType(); if (check_occupAndViolationPerQos.containsKey(qos)) check_occupAndViolationPerQos.put(qos , check_occupAndViolationPerQos.get(qos) + tree.getOccupiedLinkCapacity()); else check_occupAndViolationPerQos.put(qos , tree.getOccupiedLinkCapacity()); } } if (Math.abs(cache_totalCarriedTraffic - check_totalCarriedTraffic) > 1E-3) throw new RuntimeException ("Bad: Link: " + this + ". carriedTrafficSummingRoutesAndCarriedTrafficByProtectionSegments: " + cache_totalCarriedTraffic + ", check_carriedTrafficSummingRoutesAndCarriedTrafficByProtectionSegments: " + check_totalCarriedTraffic); if (cache_totalOccupiedCapacity != check_totalOccupiedCapacity) { if (check_totalOccupiedCapacity != 0) { if ((cache_totalOccupiedCapacity / check_totalOccupiedCapacity) > (1 + 1E-3)) throw new RuntimeException(); } else { if (cache_totalOccupiedCapacity > 1E-3 || cache_totalOccupiedCapacity < -1E-3) throw new RuntimeException(); } } if (coupledLowerOrThisLayerDemand != null) if (!coupledLowerOrThisLayerDemand.coupledUpperOrSameLayerLink.equals (this)) throw new RuntimeException ("Bad"); if (coupledLowerLayerMulticastDemand != null) if (!coupledLowerLayerMulticastDemand.coupledUpperLayerLinks.containsValue(this)) throw new RuntimeException ("Bad"); double check_totalOccupied = 0; double check_totalViolated = 0; final SortedMap<String,Pair<Double,Double>> qos2OccupAndViol = getPerQoSOccupationAndQosViolationMap (); final SortedSet<String> qosUnion = new TreeSet<> (Sets.union(qos2OccupAndViol.keySet(), check_occupAndViolationPerQos.keySet())); for (String qos : qosUnion) { final double occupiedQosMap = qos2OccupAndViol.containsKey(qos)? qos2OccupAndViol.get(qos).getFirst() : 0; final double violatedQosMap = qos2OccupAndViol.containsKey(qos)? qos2OccupAndViol.get(qos).getSecond() : 0; assert violatedQosMap <= occupiedQosMap + Configuration.precisionFactor; final double occupiedCheck = check_occupAndViolationPerQos.containsKey(qos)? check_occupAndViolationPerQos.get(qos) : 0; assert Math.abs(occupiedCheck - occupiedQosMap) < 1e-3; check_totalOccupied += occupiedQosMap; check_totalViolated += violatedQosMap; } assert Math.abs(check_totalOccupied - this.getOccupiedCapacity()) < 1e-3; assert check_totalViolated <= check_totalOccupied + Configuration.precisionFactor; assert getCapacity() + Configuration.precisionFactor >= (check_totalOccupied - check_totalViolated); } protected  Link(NetPlan netPlan , long id , int index , NetworkLayer layer , Node originNode , Node destinationNode , double lengthInKm , double propagationSpeedInKmPerSecond , double capacity , AttributeMap attributes); Color getNominalColor(); void setNominalColor(Color nominalColor); double getOccupiedCapacityFromDemand(Demand d); Pair<Double,Double> getQosOccupationAndQosViolation(String qosType); Pair<Integer,Double> getQosTypePriorityAndMaxLinkUtilization(String qosType); SortedMap<String,Pair<Integer,Double>> getQosTypePriorityAndMaxLinkUtilizationMap(); void setQosTypePriorityAndMaxLinkUtilization(String qosType , int priority , double maxLinkUtilization); void removeQosTypePriorityAndMaxLinkUtilization(String qosType); SortedMap<String,Pair<Double,Double>> getPerQoSOccupationAndQosViolationMap(); SortedSet<Demand> getDemandsWithNonZeroForwardingRules(); Node getOriginNode(); Node getDestinationNode(); NetworkLayer getLayer(); Demand getCoupledDemand(); MulticastDemand getCoupledMulticastDemand(); boolean isCoupled(); SortedMap<Pair<Demand,Link>,Double> getForwardingRules(); double getCapacity(); void setCapacity(double newLinkCapacity); double getCarriedTraffic(); SortedSet<Route> getTraversingBackupRoutes(); int getNumberOfTraversingBackupRoutes(); double getUtilization(); double getOccupiedCapacity(); double getOccupiedCapacityOnlyBackupRoutes(); double getLengthInKm(); void setLengthInKm(double lengthInKm); double getPropagationSpeedInKmPerSecond(); double getMulticastCarriedTraffic(); double getMulticastOccupiedLinkCapacity(); void setPropagationSpeedInKmPerSecond(double speed); double getPropagationDelayInMs(); boolean isUp(); boolean isDown(); boolean isOversubscribed(); double getOversubscribedTraffic(); SortedSet<SharedRiskGroup> getSRGs(); SortedSet<Route> getTraversingRoutes(); SortedMap<Route,Integer> getTraversingRoutesAndMultiplicity(); int getNumberOfTraversingRoutes(); SortedSet<MulticastTree> getTraversingTrees(); int getNumberOfTraversingTrees(); int getNumberOfForwardingRules(); void coupleToLowerLayerDemand(Demand demand); Demand coupleToNewDemandCreated(NetworkLayer newDemandLayer , RoutingType routingTypeDemand); void removeAllForwardingRules(); Link getBidirectionalPair(); void setBidirectionalPair(Link e); boolean isBidirectional(); Link createBidirectionalPair(); void remove(); boolean setFailureState(boolean setAsUp); @Override String toString(); SortedSet<String> getQosViolated(); boolean isQoSViolated(String qosType); Triple<SortedSet<Demand>,SortedSet<Demand>,SortedSet<MulticastDemand>> getDemandsPotentiallyTraversingThisLink(); Triple<SortedMap<Demand,SortedSet<Link>>,SortedMap<Demand,SortedSet<Link>>,SortedMap<Pair<MulticastDemand,Node>,SortedSet<Link>>> getLinksThisLayerPotentiallyCarryingTrafficTraversingThisLink(); Triple<SortedMap<Demand,SortedSet<Link>>,SortedMap<Demand,SortedSet<Link>>,SortedMap<Pair<MulticastDemand,Node>,SortedSet<Link>>> getLinksDownPropagationPotentiallyCarryingTrafficTraversingThisLink(); boolean isCoupledInSameLayer(); boolean isCoupledInDifferentLayer(); void decouple(); @Override TrafficSeries getMonitoredOrForecastedCarriedTraffic(); @Override void setMonitoredOrForecastedCarriedTraffic(TrafficSeries newTimeSeries); @Override double getCurrentTrafficToAddMonitSample(); @Override boolean isPossibleToSetCurrentTrafficAsGivenMonitSample(); @Override void setCurrentTrafficToGivenMonitSample(double traffic); @Override Optional<TrafficPredictor> getTrafficPredictor(); @Override void setTrafficPredictor(TrafficPredictor tp); @Override void removeTrafficPredictor();  }
@Test public void testCheckCaches() { np.checkCachesConsistency(); }