예제 #1
0
  /**
   * TODO
   *
   * @param physicalNode TODO
   * @param physicalResourceRequirements TODO
   * @return TODO
   */
  private boolean checkPhysicalNodeSatisfied(
      PhysicalNode physicalNode,
      List<
              org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual
                  .network.rev151010.virtual.node.instance.PhysicalResourceRequirement>
          physicalResourceRequirements)
      throws VNMappingException {
    List<
            org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical
                .network.rev151010.physical.node.instance.Attribute>
        attributes = physicalNode.getAttribute();
    org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network
            .rev151010.physical.node.instance.Attribute
        attribute;

    for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network
            .rev151010.virtual.node.instance.PhysicalResourceRequirement
        physicalResourceRequirement : physicalResourceRequirements) {
      attribute =
          getPhysicalNodeAttribute(attributes, physicalResourceRequirement.getAttributeName());

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

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

    return true;
  }
예제 #2
0
  /**
   * 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;
  }
예제 #3
0
  /**
   * 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;
  }
예제 #4
0
  /**
   * TODO
   *
   * @param virtualNetworkId TODO
   * @param virtualNode TODO
   * @param physicalNodes TODO
   * @return TODO
   */
  private PhysicalNode virtualNodeMapping(
      VirtualNetworkId virtualNetworkId, VirtualNode virtualNode, List<PhysicalNode> physicalNodes)
      throws VNMappingException {
    List<
            org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network
                .rev151010.virtual.node.instance.PhysicalResourceRequirement>
        physicalResourceRequirements = virtualNode.getPhysicalResourceRequirement();
    List<PhysicalNode> candidates = new LinkedList<PhysicalNode>();

    switch (virtualNode.getNodeType()) {
      case Vswitch:
        for (PhysicalNode physicalNode : physicalNodes) {
          if (PhysicalNode.NodeType.Switch == physicalNode.getNodeType()) {
            if (checkPhysicalNodeSatisfied(physicalNode, physicalResourceRequirements)) {
              candidates.add(physicalNode);
            }
          }
        }
        break;

      case Vrouter:
        for (PhysicalNode physicalNode : physicalNodes) {
          if (PhysicalNode.NodeType.Router == physicalNode.getNodeType()) {
            if (checkPhysicalNodeSatisfied(physicalNode, physicalResourceRequirements)) {
              candidates.add(physicalNode);
            }
          }
        }
        break;

      case Vfirewall:
        for (PhysicalNode physicalNode : physicalNodes) {
          if (PhysicalNode.NodeType.Firewall == physicalNode.getNodeType()) {
            if (checkPhysicalNodeSatisfied(physicalNode, physicalResourceRequirements)) {
              candidates.add(physicalNode);
            }
          }
        }
        break;

      case Vloadbalancer:
        for (PhysicalNode physicalNode : physicalNodes) {
          if (PhysicalNode.NodeType.Loadbalancer == physicalNode.getNodeType()) {
            if (checkPhysicalNodeSatisfied(physicalNode, physicalResourceRequirements)) {
              candidates.add(physicalNode);
            }
          }
        }
        break;

      default:
        throw new VNMappingException(
            "Unsupported virtual node type " + virtualNode.getNodeType() + ".");
        //                break;
    }

    if (candidates.isEmpty()) {
      return null;
    }

    return candidates.get(0);
  }