コード例 #1
0
  private boolean isVirtualNodeAlreadyAdded(int sourceId) {

    List<NetworkElement> virtualDevices =
        NetworkModelHelper.getNetworkElementsByClassName(
            VirtualDevice.class, mappingNetworkResult.getNetworkElements());

    for (NetworkElement device : virtualDevices)
      if (device.getName().equals(String.valueOf(sourceId))) return true;

    return false;
  }
コード例 #2
0
  /**
   * This method looks if there's a virtual device implemented by the physical device with the param
   * name in model. If so, the name of this virtual device is returned. If not, the "size" index is
   * returned in order to add a new virtual device with this name to the virtual devices list.
   *
   * @param phyNodeId
   * @return
   */
  private int getVirtualDeviceIdByPhysicalId(int phyNodeId) {

    List<NetworkElement> vDevices =
        NetworkModelHelper.getNetworkElementsByClassName(
            VirtualDevice.class, mappingNetworkResult.getNetworkElements());

    String phyNodeName = this.inpNetwork.getNodes().get(phyNodeId).getPnodeID();

    for (NetworkElement vDevice : vDevices) {
      if (((VirtualDevice) vDevice).getImplementedBy().equals(phyNodeName))
        return Integer.valueOf(vDevice.getName());
    }

    return Integer.valueOf(vDevices.size());
  }
コード例 #3
0
  private void addVirtualDeviceToModel(int phyNodeId) throws ResourceNotFoundException {

    List<NetworkElement> vDevices =
        NetworkModelHelper.getNetworkElementsByClassName(
            VirtualDevice.class, mappingNetworkResult.getNetworkElements());

    int virtualId = vDevices.size();

    String phyDeviceId = inpNetwork.getNodes().get(phyNodeId).getPnodeID();

    Device device = NetworkModelHelper.getDeviceByName(physicalNetworkModel, phyDeviceId);

    if (device == null)
      throw new ResourceNotFoundException(
          "Device " + phyDeviceId + " not found in network topology.");

    VirtualDevice vDevice = new VirtualDevice();
    vDevice.setName(String.valueOf(virtualId));
    vDevice.setImplementedBy(phyDeviceId);

    mappingNetworkResult.getNetworkElements().add(vDevice);
  }