/**
  * @param vNode virtual node
  * @param sNode substrate node
  * @param distance
  * @return true if vNode is separated from sNode by a value lower than "distance"
  */
 private boolean nodeDistance(VirtualNode vNode, SubstrateNode sNode, int distance) {
   double dis;
   dis =
       Math.pow(sNode.getCoordinateX() - vNode.getCoordinateX(), 2)
           + Math.pow(sNode.getCoordinateY() - vNode.getCoordinateY(), 2);
   if (Math.sqrt(dis) <= distance) {
     return true;
   } else {
     return false;
   }
 }
示例#2
0
 public static int getStressLevel(SubstrateNode n) {
   int max = 0;
   int stress;
   for (AbstractResource r : n.get()) {
     stress = 0;
     if (r instanceof CpuResource) {
       for (Mapping f : r.getMappings()) {
         if (f.getDemand().getOwner() instanceof VirtualNode) stress++;
       }
     } else {
       stress = r.getMappings().size();
     }
     if (stress > max) {
       max = stress;
     }
   }
   return max;
 }
  /**
   * @param sn Substrate node
   * @return The available resources of the node sn
   */
  private double calcLinksRes(SubstrateNode sn) {
    SubstrateNode srcSnode = null;
    double resBW = 0;
    double total_resBW = 0;

    for (SubstrateLink sl : sNet.getEdges()) {
      srcSnode = sNet.getSource(sl);
      // If the processing SubstrateNode is equals to the source of a
      // SubstrateLink then add the link
      if (sn.equals(srcSnode)) {
        for (AbstractResource res : sl) {
          if (res instanceof BandwidthResource) {
            resBW = ((BandwidthResource) res).getAvailableBandwidth();
            total_resBW += resBW;
          }
        }
      }
    }
    return total_resBW;
  }
  private static SubstrateNetwork createSubstrate() {
    SubstrateNetwork subsNetwork = new SubstrateNetwork(false);
    IdResource idRes;
    CpuResource cpuRes;

    SubstrateNode subsNode1 = new SubstrateNode();
    idRes = new IdResource(subsNode1, subsNetwork);
    idRes.setId("1");
    assertTrue(subsNode1.add(idRes));
    cpuRes = new CpuResource(subsNode1);
    cpuRes.setCycles(100.0);
    assertTrue(subsNode1.add(cpuRes));
    assertTrue(subsNetwork.addVertex(subsNode1));

    subsNode2 = new SubstrateNode();
    idRes = new IdResource(subsNode2, subsNetwork);
    idRes.setId("2");
    assertTrue(subsNode2.add(idRes));
    cpuRes = new CpuResource(subsNode2);
    cpuRes.setCycles(100.0);
    assertTrue(subsNode2.add(cpuRes));
    assertTrue(subsNetwork.addVertex(subsNode2));

    SubstrateNode subsNode3 = new SubstrateNode();
    idRes = new IdResource(subsNode3, subsNetwork);
    idRes.setId("3");
    assertTrue(subsNode3.add(idRes));
    cpuRes = new CpuResource(subsNode3);
    cpuRes.setCycles(0.0);
    assertTrue(subsNode3.add(cpuRes));
    assertTrue(subsNetwork.addVertex(subsNode3));

    SubstrateNode subsNode4 = new SubstrateNode();
    idRes = new IdResource(subsNode4, subsNetwork);
    idRes.setId("4");
    assertTrue(subsNode4.add(idRes));
    cpuRes = new CpuResource(subsNode4);
    cpuRes.setCycles(100.0);
    assertTrue(subsNode4.add(cpuRes));
    assertTrue(subsNetwork.addVertex(subsNode4));

    subsNode5 = new SubstrateNode();
    idRes = new IdResource(subsNode5, subsNetwork);
    idRes.setId("5");
    assertTrue(subsNode5.add(idRes));
    cpuRes = new CpuResource(subsNode5);
    cpuRes.setCycles(100.0);
    assertTrue(subsNode5.add(cpuRes));
    assertTrue(subsNetwork.addVertex(subsNode5));

    // Create links
    BandwidthResource bwRes;
    SubstrateLink subsLink12 = new SubstrateLink();
    bwRes = new BandwidthResource(subsLink12);
    bwRes.setBandwidth(10.0);
    assertTrue(subsLink12.add(bwRes));
    assertTrue(subsNetwork.addEdge(subsLink12, subsNode1, subsNode2));

    SubstrateLink subsLink21 = new SubstrateLink();
    bwRes = new BandwidthResource(subsLink21);
    bwRes.setBandwidth(9.0);
    assertTrue(subsLink21.add(bwRes));
    assertTrue(subsNetwork.addEdge(subsLink21, subsNode2, subsNode1));

    SubstrateLink subsLink23 = new SubstrateLink();
    bwRes = new BandwidthResource(subsLink23);
    bwRes.setBandwidth(10.0);
    assertTrue(subsLink23.add(bwRes));
    assertTrue(subsNetwork.addEdge(subsLink23, subsNode2, subsNode3));

    SubstrateLink subsLink32 = new SubstrateLink();
    bwRes = new BandwidthResource(subsLink32);
    bwRes.setBandwidth(10.0);
    assertTrue(subsLink32.add(bwRes));
    assertTrue(subsNetwork.addEdge(subsLink32, subsNode3, subsNode2));

    SubstrateLink subsLink34 = new SubstrateLink();
    bwRes = new BandwidthResource(subsLink34);
    bwRes.setBandwidth(10.0);
    assertTrue(subsLink34.add(bwRes));
    assertTrue(subsNetwork.addEdge(subsLink34, subsNode3, subsNode4));

    SubstrateLink subsLink43 = new SubstrateLink();
    bwRes = new BandwidthResource(subsLink43);
    bwRes.setBandwidth(10.0);
    assertTrue(subsLink43.add(bwRes));
    assertTrue(subsNetwork.addEdge(subsLink43, subsNode4, subsNode3));

    SubstrateLink subsLink45 = new SubstrateLink();
    bwRes = new BandwidthResource(subsLink45);
    bwRes.setBandwidth(10.0);
    assertTrue(subsLink45.add(bwRes));
    assertTrue(subsNetwork.addEdge(subsLink45, subsNode4, subsNode5));

    SubstrateLink subsLink54 = new SubstrateLink();
    bwRes = new BandwidthResource(subsLink54);
    bwRes.setBandwidth(10.0);
    assertTrue(subsLink54.add(bwRes));
    assertTrue(subsNetwork.addEdge(subsLink54, subsNode5, subsNode4));

    SubstrateLink subsLink15 = new SubstrateLink();
    bwRes = new BandwidthResource(subsLink15);
    bwRes.setBandwidth(10.0);
    assertTrue(subsLink15.add(bwRes));
    assertTrue(subsNetwork.addEdge(subsLink15, subsNode1, subsNode5));

    SubstrateLink subsLink51 = new SubstrateLink();
    bwRes = new BandwidthResource(subsLink51);
    bwRes.setBandwidth(10.0);
    assertTrue(subsLink51.add(bwRes));
    assertTrue(subsNetwork.addEdge(subsLink51, subsNode5, subsNode1));

    SubstrateLink subsLink24 = new SubstrateLink();
    bwRes = new BandwidthResource(subsLink24);
    bwRes.setBandwidth(10.0);
    assertTrue(subsLink24.add(bwRes));
    assertTrue(subsNetwork.addEdge(subsLink24, subsNode2, subsNode4));

    SubstrateLink subsLink42 = new SubstrateLink();
    bwRes = new BandwidthResource(subsLink42);
    bwRes.setBandwidth(10.0); // TODO:!!!!!!!!!!!!! -> 9
    assertTrue(subsLink42.add(bwRes));
    assertTrue(subsNetwork.addEdge(subsLink42, subsNode4, subsNode2));

    return subsNetwork;
  }