/** * <p>Returns the set of shared risk groups (SRGs) this node belongs to. </p> * @return The set of SRGs as an unmodifiable set */ public SortedSet<SharedRiskGroup> getSRGs() { final SortedSet<SharedRiskGroup> res = new TreeSet<> (cache_nodeNonDynamicSRGs); for (SharedRiskGroup srg : netPlan.cache_dynamicSrgs) if (srg.getNodes().contains(this)) res.add(srg); return res; }
/** * <p>Returns all the links affected by the SRG at all the layers: the links affected, and the input and output links of the affected nodes</p> * @return All the affected links */ public SortedSet<Link> getAffectedLinksAllLayers () { SortedSet<Link> res = new TreeSet<Link> (); res.addAll (getLinksAllLayers()); for (Node n : getNodes ()) { res.addAll (n.cache_nodeIncomingLinks); res.addAll (n.cache_nodeOutgoingLinks); } return res; }
/** * <p>Returns the set of multicast trees affected by the SRG (fail, when the SRG is in failure state). </p> * @return The set of failing multicast trees */ public SortedSet<MulticastTree> getAffectedMulticastTreesAllLayers () { SortedSet<MulticastTree> res = new TreeSet<MulticastTree> (); for (Link e : getLinksAllLayers()) res.addAll (e.cache_traversingTrees); for (Node n : getNodes()) res.addAll (n.cache_nodeAssociatedulticastTrees); return res; }
/** * <p>Returns the set of routes affected by the SRG (fail, when the SRG is in failure state). </p> * @return The set of failing routes */ public SortedSet<Route> getAffectedRoutesAllLayers () { SortedSet<Route> res = new TreeSet<Route> (); for (Link e : getLinksAllLayers()) res.addAll (e.cache_traversingRoutes.keySet()); for (Node n : getNodes()) res.addAll (n.cache_nodeAssociatedRoutes); return res; }
/** * <p>Returns all the links affected by this SRG, but only those at a particular layer. This includes the links involved, and the input and output links of the affected nodes</p> * @param layer Network layer * @return All the affected links at a given layer */ public SortedSet<Link> getAffectedLinks (NetworkLayer layer) { SortedSet<Link> res = new TreeSet<Link> (); for (Link e : getLinksAllLayers()) if (e.layer == layer) res.add (e); for (Node n : getNodes ()) { for (Link e : n.cache_nodeIncomingLinks) if (e.layer == layer) res.add (e); for (Link e : n.cache_nodeOutgoingLinks) if (e.layer == layer) res.add (e); } return res; }
@Override void checkCachesConsistency () { super.checkCachesConsistency (); if (isUp && netPlan.cache_nodesDown.contains(this)) throw new RuntimeException ("Bad"); if (!isUp && !netPlan.cache_nodesDown.contains(this)) throw new RuntimeException ("Bad"); for (Link link : cache_nodeIncomingLinks) if (link.destinationNode != this) throw new RuntimeException ("Bad"); for (Link link : cache_nodeOutgoingLinks) if (link.originNode != this) throw new RuntimeException ("Bad"); for (Demand demand : cache_nodeIncomingDemands) if (demand.egressNode != this) throw new RuntimeException ("Bad"); for (Demand demand : cache_nodeOutgoingDemands) if (demand.ingressNode != this) throw new RuntimeException ("Bad"); for (MulticastDemand demand : cache_nodeIncomingMulticastDemands) if (!demand.egressNodes.contains(this)) throw new RuntimeException ("Bad"); for (MulticastDemand demand : cache_nodeOutgoingMulticastDemands) if (demand.ingressNode != this) throw new RuntimeException ("Bad"); for (SharedRiskGroup srg : cache_nodeNonDynamicSRGs) if (!srg.getNodes().contains(this)) throw new RuntimeException ("Bad"); for (Route route : cache_nodeAssociatedRoutes) if (!route.cache_seqNodesRealPath.contains(this)) throw new RuntimeException ("Bad: " + cache_nodeAssociatedRoutes); for (MulticastTree tree : cache_nodeAssociatedulticastTrees) if (!tree.cache_traversedNodes.contains(this)) throw new RuntimeException ("Bad"); if (!this.mapLayout2NodeXYPositionMap.keySet().equals(netPlan.cache_definedPlotNodeLayouts)) throw new RuntimeException ("Bad"); }
/** * <p>Returns the set of routes in the given layer affected by the SRG (fail, when the SRG is in failure state)</p> * @param layer Network layer * @return The failing routes belonging to that layer */ public SortedSet<Route> getAffectedRoutes (NetworkLayer layer) { SortedSet<Route> res = new TreeSet<Route> (); for (Link e : getLinksAllLayers()) for (Route r : e.cache_traversingRoutes.keySet()) if (r.layer.equals(layer)) res.add (r); for (Node n : getNodes()) for (Route r : n.cache_nodeAssociatedRoutes) if (r.layer.equals(layer)) res.add (r); return res; }
/** * <p>Returns a matrix with as many rows resources, and columns as SRGs. Coordinate (res,srg) is 1 if resource res fails when srg fails</p> * * @return The matrix */ public DoubleMatrix2D getMatrixResource2SRGAssignment() { DoubleMatrix2D delta_es = DoubleFactory2D.sparse.make(resources.size(), srgs.size()); for (SharedRiskGroup srg : srgs) for (Node n : srg.getNodes()) for (Resource res : n.cache_nodeResources) delta_es.set(res.index, srg.index, 1.0); return delta_es; }
public boolean isDynamicCurrentlyEmptySrg () { return isDynamicSrg() && this.getLinksAllLayers().isEmpty() && this.getNodes().isEmpty(); }
/** * <p>Returns the set of multicast trees in the given layer affected by the SRG (fail, when the SRG is in failure state)</p> * @param layer Network layer * @return The failing multicast trees belonging to the given layer */ public SortedSet<MulticastTree> getAffectedMulticastTrees (NetworkLayer layer) { SortedSet<MulticastTree> res = new TreeSet<MulticastTree> (); for (Link e : getLinksAllLayers()) for (MulticastTree t : e.cache_traversingTrees) if (t.layer.equals(layer)) res.add (t); for (Node n : getNodes ()) for (MulticastTree t : n.cache_nodeAssociatedulticastTrees) if (t.layer.equals(layer)) res.add (t); return res; }
final SortedSet<Node> nodesThisSrg = getNodes (); for (NetworkElement e : col)
void checkCachesConsistency () { super.checkCachesConsistency (); assert getNodes ().stream().allMatch(n->n.getNetPlan()== this.netPlan); assert getLinksAllLayers ().stream().allMatch(n->n.getNetPlan()== this.netPlan); if (isDynamicSrg()) { for (Link link : linksIfNonDynamic) if (!link.cache_nonDynamicSrgs.contains(this)) throw new RuntimeException ("Bad"); for (Node node : nodesIfNonDynamic) if (!node.cache_nodeNonDynamicSRGs.contains(this)) throw new RuntimeException ("Bad"); } }
/** * <p>Sets nodes and links associated to the SRG as down (in case they are not yet). The network state is updated with the affected routes, * segments, trees and hop-by-hop routing associated to the new nodes/links down </p> */ public void setAsDown () { checkAttachedToNetPlanObject(); netPlan.setLinksAndNodesFailureState (null , getLinksAllLayers() , null , getNodes ()); }
/** * <p>Sets nodes and links associated to the SRG as up (in case they are not yet). The network state is updated with the affected routes, * segments, trees and hop-by-hop routing associated to the new nodes/links down </p> */ public void setAsUp () { checkAttachedToNetPlanObject(); netPlan.setLinksAndNodesFailureState (getLinksAllLayers() , null , getNodes (), null); }
@Override public void setValueAt(Object aValue, int row, int column) { if (column == 2) { boolean value = (boolean) aValue; Node node = netPlan.getNodeFromId((long) getValueAt(row, 0)); if (value && !srg.getNodes().contains(node)) { netPlan.getSRGFromId(srgId).addNode(node); callback.putTransientColorInElementTopologyCanvas(srg.getNodes(), Color.ORANGE); callback.putTransientColorInElementTopologyCanvas(srg.getLinksAllLayers(), Color.ORANGE); } else if (!value && srg.getNodes().contains(node)) { netPlan.getSRGFromId(srgId).removeNode(node); callback.putTransientColorInElementTopologyCanvas(srg.getNodes(), Color.ORANGE); callback.putTransientColorInElementTopologyCanvas(srg.getLinksAllLayers(), Color.ORANGE); } } super.setValueAt(aValue, row, column); } };
boolean isDeepCopy (SharedRiskGroup e2) { if (!super.isDeepCopy(e2)) return false; if (this.meanTimeToFailInHours != e2.meanTimeToFailInHours) return false; if (this.meanTimeToRepairInHours != e2.meanTimeToRepairInHours) return false; if (this.isDynamicSrg()) { if (!e2.isDynamicSrg()) return false; if (!this.dynamicSrgImplementation.getClass().getName().equals(e2.dynamicSrgImplementation.getClass().getName())) return false; if (!this.dynamicSrgImplementation.getInitializationString().equals(e2.dynamicSrgImplementation.getInitializationString())) return false; if (!NetPlan.isDeepCopy(this.getLinksAllLayers() , e2.getLinksAllLayers())) return false; if (!NetPlan.isDeepCopy(this.getNodes() , e2.getNodes())) return false; } else { if (e2.isDynamicSrg()) return false; if (!NetPlan.isDeepCopy(this.nodesIfNonDynamic , e2.nodesIfNonDynamic)) return false; if (!NetPlan.isDeepCopy(this.linksIfNonDynamic, e2.linksIfNonDynamic)) return false; } return true; }
private List<Triple<String,String,String>> getSRGInfoTables (SharedRiskGroup srg) { final DecimalFormat df = new DecimalFormat("###.##"); final NetPlan np = srg.getNetPlan(); final List<Triple<String,String,String>> res = new ArrayList <> (); res.add(Triple.of("SRG index/id" , "SRG " + srg.getIndex() + " (id " + srg.getId() + ")", "srg" + srg.getId())); res.add(Triple.of("Mean Time To Fail (MTTF)" , df.format(srg.getMeanTimeToFailInHours() / 24) + " days", "")); res.add(Triple.of("Mean Time To Repair (MTTR)" , df.format(srg.getMeanTimeToRepairInHours() / 24) + " days", "")); res.add(Triple.of("Availability" , String.format("%.6f" , srg.getAvailability()) + " days", "")); res.add(Triple.of("#Nodes" , "" + srg.getNodes() , "")); for (Node n : srg.getNodes()) res.add(Triple.of(getNodeName(n) , "" , "node" + n.getId())); res.add(Triple.of("#Links" , "" + srg.getNodes() , "")); for (NetworkLayer layer : np.getNetworkLayers()) { final Set<Link> linksThisLayer = srg.getLinks(layer); if (linksThisLayer.isEmpty()) continue; for (Link link : linksThisLayer) res.add(Triple.of("Link " + getNodeName(link.getOriginNode()) + " -> " + getNodeName(link.getDestinationNode()) , "Link " + link.getIndex() +" (id " + link.getId() + ")" , "link" + link.getId())); } return res; } private List<Triple<String,String,String>> getLinkInfoTables (Link e)
@Override public List<AjtColumnInfo<SharedRiskGroup>> getNonBasicUserDefinedColumnsVisibleOrNot() { final NetPlan np = callback.getDesign(); final NetworkLayer layer = this.getTableNetworkLayer(); final List<AjtColumnInfo<SharedRiskGroup>> res = new LinkedList<> (); res.add(new AjtColumnInfo<SharedRiskGroup>(this , Collection.class, null , "Nodes", "The nodes belonging to this SRG", null , d->d.getNodes() , AGTYPE.SUMCOLLECTIONCOUNT , null)); res.add(new AjtColumnInfo<SharedRiskGroup>(this , Collection.class, null , "Links", "The links in this layer belonging to this SRG", null , d->d.getLinks(layer) , AGTYPE.SUMCOLLECTIONCOUNT , null)); res.add(new AjtColumnInfo<SharedRiskGroup>(this , Collection.class, null , "Links all layers", "The links in this layer or other layers belonging to this SRG", null , d->d.getLinksAllLayers() , AGTYPE.SUMCOLLECTIONCOUNT , null)); res.add(new AjtColumnInfo<SharedRiskGroup>(this , Double.class, null , "MTTF (hours)" , "The average Mean-Time-To-Fail value measued in hours (the time since the element is repaired until it fails again)", (d,val)->d.setMeanTimeToFailInHours((Double) val), d->d.getMeanTimeToFailInHours() , AGTYPE.MAXDOUBLE , null)); res.add(new AjtColumnInfo<SharedRiskGroup>(this , Double.class, null , "MTTR (hours)" , "The average Mean-Time-To-Repair value measued in hours (the time betweem the element fails, and is up again since it is repaired)", (d,val)->d.setMeanTimeToRepairInHours((Double) val), d->d.getMeanTimeToRepairInHours() , AGTYPE.MAXDOUBLE , null)); res.add(new AjtColumnInfo<SharedRiskGroup>(this , Double.class, null , "Availability" , "The probability of findig the element not failed (MTTF / (MTTF + MTTR)) ", (d,val)->d.setMeanTimeToRepairInHours((Double) val), d->d.getMeanTimeToRepairInHours() , AGTYPE.MAXDOUBLE , null)); res.add(new AjtColumnInfo<SharedRiskGroup>(this , Boolean.class, null , "Is dynamic SRG?" , "Indicates if the SRG is dnyamic (and then its belonging nodes and links may change)", null , d->d.isDynamicSrg() , AGTYPE.NOAGGREGATION , null)); return res; }
@Override public void setValueAt(Object aValue, int row, int column) { if (column == 3) { boolean value = (boolean) aValue; Link link = netPlan.getLinkFromId((long) getValueAt(row, 0)); if (value && !srg.getLinksAllLayers().contains(link)) { srg.addLink(link); callback.putTransientColorInElementTopologyCanvas(srg.getNodes(), Color.ORANGE); callback.putTransientColorInElementTopologyCanvas(srg.getLinksAllLayers(), Color.ORANGE); } else if (!value && srg.getLinksAllLayers().contains(link)) { srg.removeLink(link); callback.putTransientColorInElementTopologyCanvas(srg.getNodes(), Color.ORANGE); callback.putTransientColorInElementTopologyCanvas(srg.getLinksAllLayers(), Color.ORANGE); } } super.setValueAt(aValue, row, column); } };
/** * <p>Returns the link-srg assignment matrix (an <i>E</i>x<i>S</i> matrix in which an element <i>δ<sub>es</sub></i> equals 1 if link <i>e</i> * fails when SRG <i>s</i> is affected. If no layer is provided, the default layer is assumed.</p> * * @param optionalLayerParameter Network layer (optional) * @return The link-srg incidence matrix */ public DoubleMatrix2D getMatrixLink2SRGAssignment(NetworkLayer... optionalLayerParameter) { NetworkLayer layer = checkInThisNetPlanOptionalLayerParameter(optionalLayerParameter); DoubleMatrix2D delta_es = DoubleFactory2D.sparse.make(layer.links.size(), srgs.size()); for (SharedRiskGroup s : srgs) { for (Link e : s.getLinksAllLayers()) if (e.layer.equals(layer)) delta_es.set(e.index, s.index, 1); for (Node n : s.getNodes ()) { for (Link e : n.cache_nodeIncomingLinks) if (e.layer.equals(layer)) delta_es.set(e.index, s.index, 1); for (Link e : n.cache_nodeOutgoingLinks) if (e.layer.equals(layer)) delta_es.set(e.index, s.index, 1); } } return delta_es; }