Link extends NetworkElement implements IMonitorizableElement { public Triple<SortedMap<Demand,SortedSet<Link>>,SortedMap<Demand,SortedSet<Link>>,SortedMap<Pair<MulticastDemand,Node>,SortedSet<Link>>> getLinksThisLayerPotentiallyCarryingTrafficTraversingThisLink () { final SortedMap<Demand,SortedSet<Link>> resPrimary = new TreeMap<> (); final SortedMap<Demand,SortedSet<Link>> resBackup = new TreeMap<> (); for (Demand travDemands : this.cacheHbH_normCarriedOccupiedPerTraversingDemandCurrentState.keySet()) resPrimary.put(travDemands , new TreeSet<> (travDemands.cacheHbH_normCarriedOccupiedPerLinkCurrentState.keySet())); for (Route r : cache_traversingRoutes.keySet()) { if (r.isDown()) continue; for (Link e : r.getSeqLinks()) { if (r.isBackupRoute()) { SortedSet<Link> linksSoFar = resBackup.get(r.getDemand()); if (linksSoFar == null) { linksSoFar = new TreeSet<> (); resBackup.put(r.getDemand(), linksSoFar); } linksSoFar.add(e); } else { SortedSet<Link> linksSoFar = resPrimary.get(r.getDemand()); if (linksSoFar == null) { linksSoFar = new TreeSet<> (); resPrimary.put(r.getDemand(), linksSoFar); } linksSoFar.add(e); } } } SortedMap<Pair<MulticastDemand,Node>,SortedSet<Link>> resMCast = new TreeMap<> (); for (MulticastTree t : cache_traversingTrees) { for (Node egressNode : t.getEgressNodesReached()) { final List<Link> pathToEgressNode = t.getSeqLinksToEgressNode(egressNode); if (!pathToEgressNode.contains(this)) continue; if (!netPlan.isUp (pathToEgressNode)) continue; SortedSet<Link> linksSoFar = resMCast.get(Pair.of(t.getMulticastDemand() , egressNode)); if (linksSoFar == null) { linksSoFar = new TreeSet<> (); resMCast.put(Pair.of(t.getMulticastDemand() , egressNode), linksSoFar); } linksSoFar.addAll(pathToEgressNode); } } return Triple.of(resPrimary,resBackup,resMCast); } 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 testGetLinksThisLayerPotentiallyCarryingTrafficTraversingThisLink () { Triple<SortedMap<Demand,SortedSet<Link>>,SortedMap<Demand,SortedSet<Link>>,SortedMap<Pair<MulticastDemand,Node>,SortedSet<Link>>> triple; triple = link12.getLinksThisLayerPotentiallyCarryingTrafficTraversingThisLink (); assertEquals (triple.getFirst() , ImmutableMap.of(d12 , Sets.newHashSet(link12) , d13 , Sets.newHashSet(link12 , link23) , scd123 , Sets.newHashSet(link12 , link23))); assertEquals (triple.getSecond() , ImmutableMap.of()); assertEquals (triple.getThird() , ImmutableMap.of(Pair.of(d123,n3) , Sets.newHashSet(link12 , link23) , Pair.of(d123,n2) , Sets.newHashSet(link12) )); link23.setFailureState(false); triple = link12.getLinksThisLayerPotentiallyCarryingTrafficTraversingThisLink (); assertEquals (triple.getFirst() , ImmutableMap.of(d12 , Sets.newHashSet(link12))); assertEquals (triple.getSecond() , ImmutableMap.of()); assertEquals (triple.getThird() , ImmutableMap.of(Pair.of(d123,n2) , Sets.newHashSet(link12) )); link23.setFailureState(true); triple = link13.getLinksThisLayerPotentiallyCarryingTrafficTraversingThisLink (); assertEquals (triple.getFirst() , ImmutableMap.of()); assertEquals (triple.getSecond() , ImmutableMap.of(d13 , Sets.newHashSet(link13))); assertEquals (triple.getThird() , ImmutableMap.of(Pair.of(d123,n3) , Sets.newHashSet(link13))); link23.setFailureState(false); triple = link13.getLinksThisLayerPotentiallyCarryingTrafficTraversingThisLink (); assertEquals (triple.getFirst() , ImmutableMap.of()); assertEquals (triple.getSecond() , ImmutableMap.of(d13 , Sets.newHashSet(link13))); assertEquals (triple.getThird() , ImmutableMap.of(Pair.of(d123,n3) , Sets.newHashSet(link13))); }