コード例 #1
0
ファイル: VNMappingUnit.java プロジェクト: inocybe/odl-nemo
  /**
   * TODO
   *
   * @param virtualNetworkId TODO
   * @param virtualNodeId TODO
   * @param virtualPort TODO
   * @param physicalNode TODO
   * @return TODO
   */
  private PhysicalPort virtualPortMapping(
      VirtualNetworkId virtualNetworkId,
      VirtualNodeId virtualNodeId,
      VirtualPort virtualPort,
      PhysicalNode physicalNode)
      throws VNMappingException {
    if (VirtualPort.PortType.Internal == virtualPort.getPortType()) {
      return null;
    }

    List<PhysicalPort> physicalPorts = physicalNode.getPhysicalPort();
    List<PhysicalResourceRequirement> physicalResourceRequirements =
        virtualPort.getPhysicalResourceRequirement();

    for (PhysicalPort physicalPort : physicalPorts) {
      if (PhysicalPort.PortType.External == physicalPort.getPortType()
          && checkPhysicalPortSatisfied(physicalPort, physicalResourceRequirements)) {
        return physicalPort;
      }
    }

    return null;
  }
コード例 #2
0
ファイル: VNMappingUnit.java プロジェクト: inocybe/odl-nemo
  /**
   * TODO
   *
   * @param physicalPort TODO
   * @param physicalResourceRequirements TODO
   * @return TODO
   */
  private boolean checkPhysicalPortSatisfied(
      PhysicalPort physicalPort, List<PhysicalResourceRequirement> physicalResourceRequirements)
      throws VNMappingException {
    List<Attribute> attributes = physicalPort.getAttribute();
    Attribute attribute;

    for (PhysicalResourceRequirement physicalResourceRequirement : physicalResourceRequirements) {
      attribute =
          getPhysicalPortAttribute(attributes, physicalResourceRequirement.getAttributeName());

      if (null == attribute) {
        return false;
      }

      if (!checkPhysicalPortAttributeSatisfied(attribute, physicalResourceRequirement)) {
        return false;
      }
    }

    return true;
  }
コード例 #3
0
ファイル: VNMappingUnit.java プロジェクト: inocybe/odl-nemo
  /**
   * TODO
   *
   * @param virtualNetwork TODO
   * @param userVnPnMapping TODO
   * @param physicalPaths TODO
   */
  public void virtualNetworkMapping(
      VirtualNetwork virtualNetwork,
      UserVnPnMapping userVnPnMapping,
      List<PhysicalPath> physicalPaths)
      throws VNMappingException {
    ReadOnlyTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction();

    InstanceIdentifier<PhysicalNodes> physicalNodesIid =
        InstanceIdentifier.builder(PhysicalNetwork.class).child(PhysicalNodes.class).build();
    Optional<PhysicalNodes> result;

    try {
      result = readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, physicalNodesIid).get();
    } catch (InterruptedException exception) {
      throw new VNMappingException("Can not read the physical nodes.");
    } catch (ExecutionException exception) {
      throw new VNMappingException("Can not read the physical nodes.");
    }

    if (!result.isPresent()) {
      throw new VNMappingException(
          "Failed virtual network mapping caused by " + "absent underlying network topology.");
    }

    PhysicalNodes physicalNodes = result.get();
    List<PhysicalNode> physicalNodeList = physicalNodes.getPhysicalNode();

    UserId userId = virtualNetwork.getUserId();
    List<VnPnMappingResult> vnPnMappingResults = userVnPnMapping.getVnPnMappingResult();
    List<VirtualNode> virtualNodes = virtualNetwork.getVirtualNodes().getVirtualNode();
    List<VirtualPort> virtualPorts;
    PhysicalNode physicalNode;
    PhysicalPort physicalPort;
    VnPnMappingResult vnPnMappingResult;

    for (VirtualNode virtualNode : virtualNodes) {
      physicalNode =
          virtualNodeMapping(virtualNetwork.getNetworkId(), virtualNode, physicalNodeList);

      if (null == physicalNode) {
        // If mapping failed, reset the user physical resources.
        pnResourcesTracker.resetResource(userId);

        throw new VNMappingException(
            "Failed mapping for the virtual node "
                + virtualNode.getNodeId().getValue()
                + " in the virtual network "
                + virtualNetwork.getNetworkId().getValue());
      }

      // Keep physical resource.
      pnResourcesTracker.addPhysicalNode(userId, physicalNode);

      virtualPorts = virtualNode.getVirtualPort();

      for (VirtualPort virtualPort : virtualPorts) {
        if (VirtualPort.PortType.External == virtualPort.getPortType()) {
          physicalPort =
              virtualPortMapping(
                  virtualNetwork.getNetworkId(),
                  virtualNode.getNodeId(),
                  virtualPort,
                  physicalNode);

          if (null == physicalPort) {
            // If mapping failed, reset the user physical resources.
            pnResourcesTracker.resetResource(userId);

            throw new VNMappingException(
                "Failed mapping for the virtual port "
                    + virtualPort.getPortId().getValue()
                    + " of the virtual node "
                    + virtualNode.getNodeId().getValue()
                    + " in the virtual network "
                    + virtualNetwork.getNetworkId().getValue());
          }

          // Keep physical resource.
          pnResourcesTracker.addPhysicalPort(userId, physicalPort);

          vnPnMappingResult =
              new VnPnMappingResultBuilder()
                  .setVirtualResourceId(new VirtualResourceId(UUID.randomUUID().toString()))
                  .setVirtualResourceType(VirtualResourceInstance.VirtualResourceType.Vport)
                  .setVirtualResourceEntityId(
                      new VirtualResourceEntityId(virtualPort.getPortId().getValue()))
                  .setParentVirtualResourceEntityId(
                      new VirtualResourceEntityId(virtualNode.getNodeId().getValue()))
                  .setPhysicalResourceId(new PhysicalResourceId(UUID.randomUUID().toString()))
                  .setPhysicalResourceType(PhysicalResourceInstance.PhysicalResourceType.Port)
                  .setPhysicalResourceEntityId(
                      new PhysicalResourceEntityId(physicalPort.getPortId().getValue()))
                  .setParentPhysicalResourceEntityId(
                      new PhysicalResourceEntityId(physicalNode.getNodeId().getValue()))
                  .build();

          vnPnMappingResults.add(vnPnMappingResult);
        }
      }

      vnPnMappingResult =
          new VnPnMappingResultBuilder()
              .setVirtualResourceId(new VirtualResourceId(UUID.randomUUID().toString()))
              .setVirtualResourceType(VirtualResourceInstance.VirtualResourceType.Vnode)
              .setVirtualResourceEntityId(
                  new VirtualResourceEntityId(virtualNode.getNodeId().getValue()))
              .setPhysicalResourceId(new PhysicalResourceId(UUID.randomUUID().toString()))
              .setPhysicalResourceType(PhysicalResourceInstance.PhysicalResourceType.Node)
              .setPhysicalResourceEntityId(
                  new PhysicalResourceEntityId(physicalNode.getNodeId().getValue()))
              .build();

      vnPnMappingResults.add(vnPnMappingResult);
    }

    List<VirtualLink> virtualLinks = virtualNetwork.getVirtualLinks().getVirtualLink();
    List<VirtualLink> newVirtualLinks = new ArrayList<VirtualLink>(virtualLinks.size());
    PhysicalPath physicalPath;
    VirtualLink newVirtualLink;

    for (VirtualLink virtualLink : virtualLinks) {
      physicalPath =
          virtualLinkMapping(virtualNetwork.getNetworkId(), virtualLink, userVnPnMapping);

      if (null == physicalPath) {
        // If mapping failed, reset the user physical resources.
        pnResourcesTracker.resetResource(userId);

        throw new VNMappingException(
            "Failed mapping for the virtual link "
                + virtualLink.getLinkId().getValue()
                + " in the virtual network "
                + virtualNetwork.getNetworkId().getValue());
      }

      // Keep physical resource.
      pnResourcesTracker.addPhysicalPath(userId, physicalPath);

      physicalPaths.add(physicalPath);

      newVirtualLink =
          new VirtualLinkBuilder(virtualLink)
              .setMetric(physicalPath.getMetric())
              .setDelay(physicalPath.getDelay())
              .build();

      newVirtualLinks.add(newVirtualLink);

      vnPnMappingResult =
          new VnPnMappingResultBuilder()
              .setVirtualResourceId(new VirtualResourceId(UUID.randomUUID().toString()))
              .setVirtualResourceType(VirtualResourceInstance.VirtualResourceType.Vlink)
              .setVirtualResourceEntityId(
                  new VirtualResourceEntityId(virtualLink.getLinkId().getValue()))
              .setPhysicalResourceId(new PhysicalResourceId(UUID.randomUUID().toString()))
              .setPhysicalResourceType(PhysicalResourceInstance.PhysicalResourceType.Path)
              .setPhysicalResourceEntityId(
                  new PhysicalResourceEntityId(physicalPath.getPathId().getValue()))
              .build();

      vnPnMappingResults.add(vnPnMappingResult);
    }

    virtualLinks.clear();
    virtualLinks.addAll(newVirtualLinks);

    return;
  }