DrawNode (Node n , NetworkLayer layer , int maxHeightOrSizeIcon) { Pair<ImageIcon,Shape> getIconAndShape = getNodeIcon(n , layer , maxHeightOrSizeIcon); this.associatedElement = n; this.icon = getIconAndShape.getFirst().getImage(); this.shapeIconToSetByPainter = getIconAndShape.getSecond(); this.labels = Arrays.asList(n.getName().equals("")? "Node " + n.getIndex() : n.getName()); this.urlsLabels = Arrays.asList("node" + n.getId()); } DrawNode (Resource r , int maxHeightOrSizeIcon , double occupiedCapacity)
for (Node node : nodes) out.append(String.format("Routing table for n%d%n", node.getId ())); out_thisEgressNode.append(String.format("dst: n%d, gw:", egressNode.getId ())); for (Link link : outgoingLinks_thisNode) if (trafficValue < 0) continue; out_thisEgressNode.append(String.format(" [e%d (n%d): %f]", link.getId (), links.get(link.getIndex()).getDestinationNode().getId (), trafficValue)); thereAreRoutes = true;
private static Pair<Route, Integer> addLightpath(NetPlan netPlan, Node ingressNode, Node egressNode, DoubleMatrix1D w_f, NetPlan cpl, DoubleMatrix2D wavelengthFiberOccupancy) { /* Try to find a feasible physical path, with a free wavelength along it, among the set of candidate paths */ final Demand cplDemand = cpl.getNodePairDemands(cpl.getNodeFromId(ingressNode.getId()), cpl.getNodeFromId(egressNode.getId()), false).iterator().next(); for (Route cplRoute : cplDemand.getRoutes()) { List<Link> seqLinks = new LinkedList<Link>(); for (Link cplLink : cplRoute.getSeqLinks()) seqLinks.add(netPlan.getLinkFromId(cplLink.getId())); final int wavelength = WDMUtils.spectrumAssignment_firstFit(seqLinks, wavelengthFiberOccupancy,1); if (wavelength != -1) return Pair.of(cplRoute, wavelength); } /* Otherwise, return null*/ return null; }
void copyFrom (NetworkLayer origin) { if ((this.id != origin.id) || (this.index != origin.index)) throw new RuntimeException ("Bad"); if ((this.netPlan == null) || (origin.netPlan == null) || (this.netPlan == origin.netPlan)) throw new RuntimeException ("Bad"); this.demandTrafficUnitsName = origin.demandTrafficUnitsName; this.description = origin.description; this.defaultNodeIconURL = origin.defaultNodeIconURL; this.name = origin.name; this.linkCapacityUnitsName = origin.linkCapacityUnitsName; this.cache_linksDown.clear (); for (Link e : origin.cache_linksDown) this.cache_linksDown.add(this.netPlan.getLinkFromId (e.id)); this.cache_linksZeroCap.clear (); for (Link e : origin.cache_linksZeroCap) this.cache_linksZeroCap.add(this.netPlan.getLinkFromId (e.id)); this.cache_coupledLinks.clear (); for (Link e : origin.cache_coupledLinks) this.cache_coupledLinks.add(this.netPlan.getLinkFromId (e.id)); this.cache_coupledDemands.clear (); for (Demand d : origin.cache_coupledDemands) this.cache_coupledDemands.add(this.netPlan.getDemandFromId (d.id)); this.cache_coupledMulticastDemands.clear (); for (MulticastDemand d : origin.cache_coupledMulticastDemands) this.cache_coupledMulticastDemands.add(this.netPlan.getMulticastDemandFromId(d.id)); this.cache_routesDown.clear (); for (Route r : origin.cache_routesDown) this.cache_routesDown.add(this.netPlan.getRouteFromId (r.id)); this.cache_routesTravLinkZeroCap.clear(); for (Route r : origin.cache_routesTravLinkZeroCap) this.cache_routesTravLinkZeroCap.add(this.netPlan.getRouteFromId (r.id)); this.cache_multicastTreesDown.clear (); for (MulticastTree t : origin.cache_multicastTreesDown) this.cache_multicastTreesDown.add(this.netPlan.getMulticastTreeFromId (t.id)); this.cache_multicastTreesTravLinkZeroCap.clear(); for (MulticastTree t : origin.cache_multicastTreesTravLinkZeroCap) this.cache_multicastTreesTravLinkZeroCap.add(this.netPlan.getMulticastTreeFromId (t.id)); this.cache_nodePairLinksThisLayer.clear(); for (Entry<Pair<Node,Node>,SortedSet<Link>> entry : origin.cache_nodePairLinksThisLayer.entrySet()) this.cache_nodePairLinksThisLayer.put(Pair.of(this.netPlan.getNodeFromId(entry.getKey().getFirst().getId()) , this.netPlan.getNodeFromId(entry.getKey().getSecond().getId())) , (SortedSet<Link>) (SortedSet<?>) this.netPlan.translateCollectionToThisNetPlan(entry.getValue())); this.cache_nodePairDemandsThisLayer.clear(); for (Entry<Pair<Node,Node>,SortedSet<Demand>> entry : origin.cache_nodePairDemandsThisLayer.entrySet()) this.cache_nodePairDemandsThisLayer.put(Pair.of(this.netPlan.getNodeFromId(entry.getKey().getFirst().getId()) , this.netPlan.getNodeFromId(entry.getKey().getSecond().getId())) , (SortedSet<Demand>) (SortedSet<?>) this.netPlan.translateCollectionToThisNetPlan(entry.getValue())); this.cache_qosTypes2DemandMap.clear(); for (Entry<String,Pair<SortedSet<Demand>,SortedSet<MulticastDemand>>> entry : origin.cache_qosTypes2DemandMap.entrySet()) this.cache_qosTypes2DemandMap.put(entry.getKey() , Pair.of((SortedSet<Demand>) (SortedSet<?>) this.netPlan.translateCollectionToThisNetPlan(entry.getValue().getFirst()) , (SortedSet<MulticastDemand>) (SortedSet<?>) this.netPlan.translateCollectionToThisNetPlan(entry.getValue().getSecond()))); for (Link e : origin.links) this.links.get(e.index).copyFrom(e); for (Demand d : origin.demands) this.demands.get(d.index).copyFrom(d); for (MulticastDemand d : origin.multicastDemands) this.multicastDemands.get(d.index).copyFrom(d); for (Route r : origin.routes) this.routes.get(r.index).copyFrom(r); for (MulticastTree t : origin.multicastTrees) this.multicastTrees.get(t.index).copyFrom(t); }
nodeName2Id.put(name, node.getId ());
@Override public int compare(Pair<Long, Long> o1, Pair<Long, Long> o2) { NetworkLayer layer = netPlan.getNetworkLayerFromId(layerId); Node node1 = netPlan.getLinkFromId (o1.getSecond()).getOriginNode(); Node node2 = netPlan.getLinkFromId (o2.getSecond()).getOriginNode(); int compareNodes = Long.compare(node1.getId (), node2.getId ()); if (compareNodes != 0) return compareNodes; int compareDemands = o1.getFirst().compareTo(o2.getFirst()); if (compareDemands != 0) return compareDemands; int compareLinks = o1.getSecond().compareTo(o2.getSecond()); return compareLinks; } }
JSelectionTablePanel selectionPanel = new JSelectionTablePanel(StringUtils.arrayOf("Node","Index","Id"), "Nodes"); LinkedList<Object[]> selectionPanelElements = new LinkedList<>(); netPlan.getNodes().stream().forEach(n -> originNodeComboBox.addItem(StringLabeller.of(n.getId(),n.toString()))); netPlan.getNodes().stream().filter(n -> n != netPlan.getNode(0)).forEach(n -> selectionPanelElements.add(new Object[]{n,n.getIndex(),n.getId()})); selectionPanel.setCandidateElements(selectionPanelElements); Node newSelectedNode = netPlan.getNodeFromId(newSelectedNodeId); selectionPanelElements.clear(); netPlan.getNodes().stream().filter(n -> n != newSelectedNode).forEach(n -> selectionPanelElements.add(new Object[]{n,n.getIndex(),n.getId()})); selectionPanel.setCandidateElements(selectionPanelElements); });
temp.append("<html>"); temp.append("<table border=\"0\">"); temp.append("<tr><td colspan=\"2\"><strong>Node index " + npNode.getIndex() + " (id: " + npNode.getId() + ") - Layer " + getLayerName(layer) + "</strong></td></tr>"); temp.append("<tr><td>Name:</td><td>" + npNode.getName() + "</td></tr>"); temp.append("<tr><td>Total offered unicast traffic (in / out):</td>");
double yCoord = Double.parseDouble(data[2]); String name = data[0]; long nodeId = netPlan.addNode(xCoord, yCoord, name, null).getId (); nodeName2Id.put(name, nodeId);
@Override public void itemStateChanged(ItemEvent e) { linkSelector.removeAllItems(); Object selectedItem_Node = nodeSelector.getSelectedItem(); if(selectedItem_Node == null) return; final long nodeId = (long) ((StringLabeller) selectedItem_Node).getObject(); final Node node = netPlan.getNodeFromId(nodeId); for (Link link : node.getOutgoingLinks(layer)) { String originNodeLabel = "Node " + link.getOriginNode().getId(); if (!link.getOriginNode().getName().isEmpty()) originNodeLabel += " (" + link.getOriginNode().getName() + ")"; String destinationNodeLabel = "Node " + link.getDestinationNode().getId(); if (!link.getDestinationNode().getName().isEmpty()) destinationNodeLabel += " (" + link.getDestinationNode().getName() + ")"; String linkLabel = "e" + link.getId() + ": " + originNodeLabel + " -> " + destinationNodeLabel; linkSelector.addItem(StringLabeller.of(link.getId(), linkLabel)); } if(linkSelector.getItemCount() == 0) linkSelector.setSelectedIndex(-1); else linkSelector.setSelectedIndex(0); } };
private List<Triple<String,String,String>> getNodeInfoTables (Node n , NetworkLayer layer) { final DecimalFormat df = new DecimalFormat("###.##"); final NetPlan np = n.getNetPlan(); final List<Triple<String,String,String>> res = new ArrayList <> (); final String trafUnits = np.getDemandTrafficUnitsName(layer); res.add(Triple.of("Node index/id" , "Node " + n.getIndex() + " (id " + n.getId() + ")", "node" + n.getId())); res.add(Triple.of("Name" , n.getName().equals("")? "No name" : n.getName(), "")); res.add(Triple.of("Site", (n.getSiteName() != null) ? n.getSiteName() : "undefined","")); res.add(Triple.of("Coordinates (x,y)" , "(" + n.getXYPositionMap().getX() + "," + n.getXYPositionMap().getY() + ")" , "")); res.add(Triple.of("Is up?", "" + n.isUp() , "")); res.add(Triple.of("# Resources" , n.getResources().isEmpty() ? "none" : ""+n.getResources().size() , "")); for (Resource r : n.getResources()) res.add(Triple.of("- " + getResourceName(r) , "" , "resource" + r.getId())); res.add(Triple.of("Information at layer" , getLayerName(layer) , "")); res.add(Triple.of("# output links", "" + n.getOutgoingLinks(layer).size() , "")); res.add(Triple.of("# input links" , "" + n.getIncomingLinks(layer).size() , "")); res.add(Triple.of("Output traffic" , "" + df.format(n.getOutgoingLinks(layer).stream().mapToDouble(e->e.getCarriedTraffic()).sum()) + " " + trafUnits , "")); res.add(Triple.of("Input traffic" , df.format(n.getIncomingLinks(layer).stream().mapToDouble(e->e.getCarriedTraffic()).sum()) + " " + trafUnits , "")); res.add(Triple.of("# SRGs" , n.getSRGs().isEmpty() ? "none" : ""+n.getSRGs().size() , "")); for (SharedRiskGroup srg : n.getSRGs()) res.add(Triple.of("- Sh. risk group index/id" , "" + srg.getIndex() + " (id " + srg.getId() + ")" , "srg" + srg.getId())); return res; } private List<Triple<String,String,String>> getResourceInfoTables (Resource r)
String nodeLabel = "Node " + node.getId(); if (!nodeName.isEmpty()) nodeLabel += " (" + nodeName + ")"; nodeSelector.addItem(StringLabeller.of(node.getId(), nodeLabel)); String ingressNodeLabel = "Node " + demand.getIngressNode().getId(); if (!demand.getIngressNode().getName().isEmpty()) ingressNodeLabel += " (" + demand.getIngressNode().getName() + ")"; String egressNodeLabel = "Node " + demand.getEgressNode().getId(); if (!demand.getEgressNode().getName().isEmpty()) egressNodeLabel += " (" + demand.getEgressNode().getName() + ")";
private void setNodeTableInfoFromNetPlan(NetPlan netPlan) { int N = netPlan.getNumberOfNodes(); if (N == 0) throw new Net2PlanException("Network structure doesn't contain a physical topology"); maxLevel = 1; Object[][] data = new Object[N][6]; for (Node node : netPlan.getNodes()) { final int n = node.getIndex(); final long nodeId = node.getId(); double population; int level; population = (int) node.getPopulation (); try { level = Integer.parseInt(node.getAttribute("level")); } catch (Exception ex) { level = 1; } data[n][0] = nodeId; data[n][1] = node.getName(); data[n][2] = node.getXYPositionMap().getX(); data[n][3] = node.getXYPositionMap().getY(); data[n][4] = population < 0 ? 0 : population; data[n][5] = level < 1 ? 1 : level; if (level > maxLevel) maxLevel = level; } nodeInfoTableModel.setDataVector(data, nodeInfoTableHeader); ((DefaultTableModel) levelMatrixTableModel).setRowCount(maxLevel); numNodes.setText(Integer.toString(N)); }
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)
double currentDistanceFromRouteInit_km = 0; res.add(Triple.of(currentDistanceFromRouteInit_km, "OADM-ADD", (double) seqLinks.get(0).getOriginNode().getId())); for (Link e : seqLinks) final long endNodeLink = e.getDestinationNode().getId(); final long lastLink = seqLinks.get(seqLinks.size() - 1).getId(); if (e.getId() == lastLink)
nodeData[n][0] = node.getId(); nodeData[n][1] = node.getName(); nodeData[n][2] = srg.getNodes().contains(node); linkData[e][1] = link.getOriginNode().getId() + (link.getOriginNode().getName().isEmpty() ? "" : " (" + link.getOriginNode().getName() + ")"); linkData[e][2] = link.getDestinationNode().getId() + (link.getDestinationNode().getName().isEmpty() ? "" : " (" + link.getDestinationNode().getName() + ")"); linkData[e][3] = srg.getLinksAllLayers().contains(link);
res.add(Quadruple.of(currentDistanceFromRouteInit_km, "OADM-ADD", (double) e.getOriginNode().getId(), oadmNoiseFigures_dB[oadmCounter++] + "")); else res.add(Quadruple.of(currentDistanceFromRouteInit_km, "OADM-ADD", (double) e.getOriginNode().getId(), oadm_addChannelNoiseFactor_dB.getDouble() + "")); final long endNodeLink = e.getDestinationNode().getId(); final long lastLink = seqLinks.get(seqLinks.size() - 1).getId(); if (e.getId() == lastLink)