Ejemplo n.º 1
0
 @SuppressWarnings("unchecked")
 public static Map<VirtualNetwork, Boolean> calculateMappedVnr(NetworkStack stack) {
   VirtualNetwork tempVnr;
   Network tmpN;
   boolean isMapped;
   Map<VirtualNetwork, Boolean> isMappedVnr = new LinkedHashMap<VirtualNetwork, Boolean>();
   for (Iterator<Network<?, ?, ?>> net = stack.iterator(); net.hasNext(); ) {
     tmpN = net.next();
     if (tmpN.getLayer() != 0) {
       tempVnr = (VirtualNetwork) tmpN;
       isMapped = true;
       for (VirtualNode tmpVNode : tempVnr.getVertices()) {
         for (AbstractDemand dem : tmpVNode) {
           if (dem instanceof CpuDemand) {
             if (dem.getMappings().isEmpty()) {
               isMapped = false;
             }
             break;
           }
         }
       }
       isMappedVnr.put(tempVnr, isMapped);
     }
   }
   return isMappedVnr;
 }
Ejemplo n.º 2
0
  @Override
  public double calculate() {
    HashMap<VirtualLink, Integer> lengths = new HashMap<VirtualLink, Integer>();

    SubstrateNetwork sNetwork = stack.getSubstrate();
    for (SubstrateLink sl : sNetwork.getEdges()) {
      LinkedList<VirtualLink> visited = new LinkedList<VirtualLink>();

      for (AbstractResource r : sl.get()) {
        for (Mapping m : r.getMappings()) {
          AbstractDemand d = m.getDemand();
          NetworkEntity<? extends AbstractConstraint> e = d.getOwner();
          if (e instanceof VirtualLink) {
            VirtualLink vl = (VirtualLink) e;

            if (!visited.contains(vl)) {
              visited.add(vl);

              Integer i = lengths.get(vl);
              if (i == null) {
                i = 1;
              } else {
                i++;
              }
              lengths.put(vl, i);
            }
          }
        }
      }
    }

    int sum = 0;
    for (Integer i : lengths.values()) {
      sum += i;
    }

    int counter = 0;
    for (@SuppressWarnings("rawtypes") Network net : stack) {
      if (net instanceof VirtualNetwork) {
        VirtualNetwork vNet = (VirtualNetwork) net;
        counter += vNet.getEdgeCount();
      }
    }

    return (counter == 0 ? 0.0 : (sum / (double) counter));
  }
  /** Node mapping method implementation */
  @Override
  protected boolean nodeMapping(VirtualNetwork vNet) {
    List<SubstrateNode> unmappedSnodes = super.getUnmappedsNodes();
    List<SubstrateNode> allNodes = new LinkedList<SubstrateNode>(sNet.getVertices());
    SubstrateNode mappedSnode = null;

    VirtualNode currVnode;
    List<SubstrateNode> candidates = new LinkedList<SubstrateNode>();

    // Move through the virtual nodes
    for (Iterator<VirtualNode> itt = vNet.getVertices().iterator(); itt.hasNext(); ) {
      currVnode = itt.next();
      // Find the candidate substrate nodes accomplishing the virtual node
      // demands
      for (AbstractDemand dem : currVnode) {
        if (dem instanceof CpuDemand) {
          if (!nodeOverload) {
            if (!withDist) {
              candidates = findFulfillingNodes(dem, unmappedSnodes);
            } else {
              candidates = findFulfillingNodes(currVnode, dem, unmappedSnodes, distance);
            }
          } else {
            if (!withDist) {
              candidates = findFulfillingNodes(dem, allNodes);
            } else {
              candidates = findFulfillingNodes(currVnode, dem, allNodes, distance);
            }
          }
        }
        // Find the feasible node with greatest available resources
        // The available resources are the H value defined in the
        // "Rethinking virtual network embedding" paper

        mappedSnode = bestAvailableResources(candidates);
        if (mappedSnode != null) {
          // Realize the node mapping
          if (NodeLinkAssignation.vnm(currVnode, mappedSnode)) {
            nodeMapping.put(currVnode, mappedSnode);
          } else {
            // If this exception is thrown, it means that something
            // in the code is wrong. The feasibility of nodes is
            // checked in findFulfillingNodes

            throw new AssertionError("But we checked before!");
          }
        } else {
          // Mapping is not possible, not feasible nodes
          return false;
        }
      }
    }
    return true;
  }
  private static List<VirtualNetwork> createVNDemands() {
    List<VirtualNetwork> vns = new LinkedList<VirtualNetwork>();
    IdDemand idDem;
    CpuDemand cpuDem;
    BandwidthDemand bwDem;

    // Network with Layer (x) MUST be instance before Network Layer (x+1)

    // Virtual network: Layer 1
    VirtualNetwork vn1 = new VirtualNetwork(1);
    vns.add(vn1);

    VirtualNode vC = new VirtualNode(1);
    idDem = new IdDemand(vC);
    idDem.setDemandedId("5");
    assertTrue(vC.add(idDem));
    cpuDem = new CpuDemand(vC);
    cpuDem.setDemandedCycles(25.0);
    assertTrue(vC.add(cpuDem));
    assertTrue(vn1.addVertex(vC));

    VirtualNode vD = new VirtualNode(1);
    idDem = new IdDemand(vD);
    idDem.setDemandedId("2");
    assertTrue(vD.add(idDem));
    cpuDem = new CpuDemand(vD);
    cpuDem.setDemandedCycles(25.0);
    assertTrue(vD.add(cpuDem));
    assertTrue(vn1.addVertex(vD));

    VirtualLink eCD = new VirtualLink(1);
    bwDem = new BandwidthDemand(eCD);
    bwDem.setDemandedBandwidth(10.0);
    assertTrue(eCD.add(bwDem));
    assertTrue(vn1.addEdge(eCD, vC, vD));

    // Virtual network layer 2
    VirtualNetwork vn0 = new VirtualNetwork(2);
    vns.add(vn0);

    VirtualNode vA = new VirtualNode(2);
    idDem = new IdDemand(vA);
    idDem.setDemandedId("1");
    assertTrue(vA.add(idDem));
    cpuDem = new CpuDemand(vA);
    cpuDem.setDemandedCycles(25.0);
    assertTrue(vA.add(cpuDem));
    assertTrue(vn0.addVertex(vA));

    VirtualNode vB = new VirtualNode(2);
    idDem = new IdDemand(vB);
    idDem.setDemandedId("3");
    assertTrue(vB.add(idDem));
    cpuDem = new CpuDemand(vB);
    cpuDem.setDemandedCycles(50.0);
    assertTrue(vB.add(cpuDem));
    assertTrue(vn0.addVertex(vB));

    VirtualNode vE = new VirtualNode(2);
    idDem = new IdDemand(vE);
    idDem.setDemandedId("4");
    assertTrue(vE.add(idDem));
    cpuDem = new CpuDemand(vE);
    cpuDem.setDemandedCycles(10.0);
    assertTrue(vE.add(cpuDem));
    assertTrue(vn0.addVertex(vE));

    VirtualLink eAB = new VirtualLink(2);
    bwDem = new BandwidthDemand(eAB);
    bwDem.setDemandedBandwidth(10.0);
    assertTrue(eAB.add(bwDem));
    assertTrue(vn0.addEdge(eAB, vA, vB));

    VirtualLink eBE = new VirtualLink(2);
    bwDem = new BandwidthDemand(eBE);
    bwDem.setDemandedBandwidth(10.0);
    assertTrue(eBE.add(bwDem));
    assertTrue(vn0.addEdge(eBE, vB, vE));

    return vns;
  }