Search in sources :

Example 11 with VirtualPort

use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.

the class DefaultVirtualPacketProvider method devirtualize.

/**
 * Translate the requested virtual outbound packet into
 * a set of physical OutboundPacket.
 * See {@link org.onosproject.net.packet.OutboundPacket}
 *
 * @param packet an OutboundPacket to be translated
 * @return a set of de-virtualized (physical) OutboundPacket
 */
private Set<OutboundPacket> devirtualize(NetworkId networkId, OutboundPacket packet) {
    Set<OutboundPacket> outboundPackets = new HashSet<>();
    Set<VirtualPort> vPorts = vnaService.getVirtualPorts(networkId, packet.sendThrough());
    TrafficTreatment.Builder commonTreatmentBuilder = DefaultTrafficTreatment.builder();
    packet.treatment().allInstructions().stream().filter(i -> i.type() != Instruction.Type.OUTPUT).forEach(i -> commonTreatmentBuilder.add(i));
    TrafficTreatment commonTreatment = commonTreatmentBuilder.build();
    PortNumber vOutPortNum = packet.treatment().allInstructions().stream().filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).findFirst().get();
    if (!vOutPortNum.isLogical()) {
        Optional<ConnectPoint> optionalCpOut = vPorts.stream().filter(v -> v.number().equals(vOutPortNum)).map(v -> v.realizedBy()).findFirst();
        if (!optionalCpOut.isPresent()) {
            log.warn("Port {} is not realized yet, in Network {}, Device {}", vOutPortNum, networkId, packet.sendThrough());
            return outboundPackets;
        }
        ConnectPoint egressPoint = optionalCpOut.get();
        TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(egressPoint.port()).build();
        OutboundPacket outboundPacket = new DefaultOutboundPacket(egressPoint.deviceId(), treatment, packet.data());
        outboundPackets.add(outboundPacket);
    } else {
        if (vOutPortNum == PortNumber.FLOOD) {
            for (VirtualPort outPort : vPorts) {
                ConnectPoint cpOut = outPort.realizedBy();
                if (cpOut != null) {
                    TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(cpOut.port()).build();
                    OutboundPacket outboundPacket = new DefaultOutboundPacket(cpOut.deviceId(), treatment, packet.data());
                    outboundPackets.add(outboundPacket);
                } else {
                    log.warn("Port {} is not realized yet, in Network {}, Device {}", outPort.number(), networkId, packet.sendThrough());
                }
            }
        }
    }
    return outboundPackets;
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) VirtualNetworkEvent(org.onosproject.incubator.net.virtual.VirtualNetworkEvent) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) ComponentContext(org.osgi.service.component.ComponentContext) VirtualPacketProviderService(org.onosproject.incubator.net.virtual.provider.VirtualPacketProviderService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet) Ethernet(org.onlab.packet.Ethernet) Component(org.osgi.service.component.annotations.Component) VirtualPacketContext(org.onosproject.incubator.net.virtual.VirtualPacketContext) OutboundPacket(org.onosproject.net.packet.OutboundPacket) ApplicationId(org.onosproject.core.ApplicationId) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) Activate(org.osgi.service.component.annotations.Activate) VirtualProviderRegistryService(org.onosproject.incubator.net.virtual.provider.VirtualProviderRegistryService) TenantId(org.onosproject.net.TenantId) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Deactivate(org.osgi.service.component.annotations.Deactivate) Instruction(org.onosproject.net.flow.instructions.Instruction) PacketProcessor(org.onosproject.net.packet.PacketProcessor) Set(java.util.Set) PacketService(org.onosproject.net.packet.PacketService) ProviderId(org.onosproject.net.provider.ProviderId) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) VirtualPacketProvider(org.onosproject.incubator.net.virtual.provider.VirtualPacketProvider) VirtualNetworkListener(org.onosproject.incubator.net.virtual.VirtualNetworkListener) AbstractVirtualProvider(org.onosproject.incubator.net.virtual.provider.AbstractVirtualProvider) InboundPacket(org.onosproject.net.packet.InboundPacket) PacketContext(org.onosproject.net.packet.PacketContext) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) VirtualNetworkAdminService(org.onosproject.incubator.net.virtual.VirtualNetworkAdminService) Optional(java.util.Optional) PacketPriority(org.onosproject.net.packet.PacketPriority) Reference(org.osgi.service.component.annotations.Reference) DeviceId(org.onosproject.net.DeviceId) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Dictionary(java.util.Dictionary) Instructions(org.onosproject.net.flow.instructions.Instructions) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) PortNumber(org.onosproject.net.PortNumber) HashSet(java.util.HashSet)

Example 12 with VirtualPort

use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.

the class DefaultVirtualPacketProvider method getMappedVirtualPort.

/**
 * Find the corresponding virtual port with the physical port.
 *
 * @param cp the connect point for the physical network
 * @return a virtual port
 */
private VirtualPort getMappedVirtualPort(ConnectPoint cp) {
    Set<TenantId> tIds = vnaService.getTenantIds();
    Set<VirtualNetwork> vNetworks = new HashSet<>();
    tIds.forEach(tid -> vNetworks.addAll(vnaService.getVirtualNetworks(tid)));
    for (VirtualNetwork vNet : vNetworks) {
        Set<VirtualDevice> vDevices = vnaService.getVirtualDevices(vNet.id());
        Set<VirtualPort> vPorts = new HashSet<>();
        vDevices.forEach(dev -> vPorts.addAll(vnaService.getVirtualPorts(dev.networkId(), dev.id())));
        VirtualPort vPort = vPorts.stream().filter(vp -> vp.realizedBy().equals(cp)).findFirst().orElse(null);
        if (vPort != null) {
            return vPort;
        }
    }
    return null;
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) TenantId(org.onosproject.net.TenantId) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) HashSet(java.util.HashSet)

Example 13 with VirtualPort

use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.

the class VirtualNetworkWebResource method createVirtualPort.

/**
 * Creates a virtual network port in a virtual device in a virtual network.
 *
 * @param networkId    network identifier
 * @param virtDeviceId virtual device identifier
 * @param stream       virtual port JSON stream
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel VirtualPort
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{networkId}/devices/{deviceId}/ports")
public Response createVirtualPort(@PathParam("networkId") long networkId, @PathParam("deviceId") String virtDeviceId, InputStream stream) {
    try {
        ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
        // final VirtualPort vportReq = codec(VirtualPort.class).decode(jsonTree, this);
        JsonNode specifiedNetworkId = jsonTree.get("networkId");
        JsonNode specifiedDeviceId = jsonTree.get("deviceId");
        if (specifiedNetworkId == null || specifiedNetworkId.asLong() != (networkId)) {
            throw new IllegalArgumentException(INVALID_FIELD + "networkId");
        }
        if (specifiedDeviceId == null || !specifiedDeviceId.asText().equals(virtDeviceId)) {
            throw new IllegalArgumentException(INVALID_FIELD + "deviceId");
        }
        JsonNode specifiedPortNum = jsonTree.get("portNum");
        JsonNode specifiedPhysDeviceId = jsonTree.get("physDeviceId");
        JsonNode specifiedPhysPortNum = jsonTree.get("physPortNum");
        final NetworkId nid = NetworkId.networkId(networkId);
        DeviceId vdevId = DeviceId.deviceId(virtDeviceId);
        ConnectPoint realizedBy = new ConnectPoint(DeviceId.deviceId(specifiedPhysDeviceId.asText()), PortNumber.portNumber(specifiedPhysPortNum.asText()));
        VirtualPort vport = vnetAdminService.createVirtualPort(nid, vdevId, PortNumber.portNumber(specifiedPortNum.asText()), realizedBy);
        UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path("vnets").path(specifiedNetworkId.asText()).path("devices").path(specifiedDeviceId.asText()).path("ports").path(vport.number().toString());
        return Response.created(locationBuilder.build()).build();
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) UriBuilder(javax.ws.rs.core.UriBuilder) ConnectPoint(org.onosproject.net.ConnectPoint) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 14 with VirtualPort

use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.

the class VirtualPortBindCommand method doExecute.

@Override
protected void doExecute() {
    VirtualNetworkAdminService service = get(VirtualNetworkAdminService.class);
    DeviceService deviceService = get(DeviceService.class);
    VirtualPort vPort = getVirtualPort(PortNumber.portNumber(portNum));
    checkNotNull(vPort, "The virtual Port does not exist");
    ConnectPoint realizedBy = new ConnectPoint(DeviceId.deviceId(physDeviceId), PortNumber.portNumber(physPortNum));
    service.bindVirtualPort(NetworkId.networkId(networkId), DeviceId.deviceId(deviceId), PortNumber.portNumber(portNum), realizedBy);
    print("Virtual port is successfully bound.");
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DeviceService(org.onosproject.net.device.DeviceService) VirtualNetworkAdminService(org.onosproject.incubator.net.virtual.VirtualNetworkAdminService) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 15 with VirtualPort

use of org.onosproject.incubator.net.virtual.VirtualPort in project onos by opennetworkinglab.

the class VirtualPortBindCommand method getVirtualPort.

/**
 * Returns the virtual port matching the device and port identifier.
 *
 * @param aPortNumber port identifier
 * @return matching virtual port, or null.
 */
private VirtualPort getVirtualPort(PortNumber aPortNumber) {
    VirtualNetworkService service = get(VirtualNetworkService.class);
    Set<VirtualPort> ports = service.getVirtualPorts(NetworkId.networkId(networkId), DeviceId.deviceId(deviceId));
    return ports.stream().filter(p -> p.number().equals(aPortNumber)).findFirst().get();
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService)

Aggregations

VirtualPort (org.onosproject.incubator.net.virtual.VirtualPort)23 ConnectPoint (org.onosproject.net.ConnectPoint)15 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)11 HashSet (java.util.HashSet)9 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)9 NetworkId (org.onosproject.incubator.net.virtual.NetworkId)8 VirtualNetworkService (org.onosproject.incubator.net.virtual.VirtualNetworkService)8 DeviceId (org.onosproject.net.DeviceId)7 PortNumber (org.onosproject.net.PortNumber)7 Sets (com.google.common.collect.Sets)6 Optional (java.util.Optional)6 Set (java.util.Set)6 CoreService (org.onosproject.core.CoreService)6 VirtualNetworkEvent (org.onosproject.incubator.net.virtual.VirtualNetworkEvent)6 Activate (org.osgi.service.component.annotations.Activate)6 Component (org.osgi.service.component.annotations.Component)6 Deactivate (org.osgi.service.component.annotations.Deactivate)6 Reference (org.osgi.service.component.annotations.Reference)6 ReferenceCardinality (org.osgi.service.component.annotations.ReferenceCardinality)6 Logger (org.slf4j.Logger)6