Search in sources :

Example 1 with VirtualPacketContext

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

the class DefaultVirtualPacketProvider method virtualize.

/**
 * Translate the requested physical PacketContext into a virtual PacketContext.
 * See {@link org.onosproject.net.packet.PacketContext}
 *
 * @param context A physical PacketContext be translated
 * @return A translated virtual PacketContext
 */
private VirtualPacketContext virtualize(PacketContext context) {
    VirtualPort vPort = getMappedVirtualPort(context.inPacket().receivedFrom());
    if (vPort != null) {
        ConnectPoint cp = new ConnectPoint(vPort.element().id(), vPort.number());
        Ethernet eth = context.inPacket().parsed();
        eth.setVlanID(Ethernet.VLAN_UNTAGGED);
        InboundPacket inPacket = new DefaultInboundPacket(cp, eth, ByteBuffer.wrap(eth.serialize()));
        DefaultOutboundPacket outPkt = new DefaultOutboundPacket(cp.deviceId(), DefaultTrafficTreatment.builder().build(), ByteBuffer.wrap(eth.serialize()));
        VirtualPacketContext vContext = new DefaultVirtualPacketContext(context.time(), inPacket, outPkt, false, vPort.networkId(), this);
        return vContext;
    } else {
        return null;
    }
}
Also used : VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Ethernet(org.onlab.packet.Ethernet) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) InboundPacket(org.onosproject.net.packet.InboundPacket) VirtualPacketContext(org.onosproject.incubator.net.virtual.VirtualPacketContext) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 2 with VirtualPacketContext

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

the class DefaultVirtualPacketProvider method devirtualizeContext.

/**
 * Translate the requested virtual packet context into
 * a set of physical outbound packets.
 *
 * @param context A handled virtual packet context
 */
private Set<OutboundPacket> devirtualizeContext(VirtualPacketContext context) {
    Set<OutboundPacket> outboundPackets = new HashSet<>();
    NetworkId networkId = context.networkId();
    TrafficTreatment vTreatment = context.treatmentBuilder().build();
    DeviceId sendThrough = context.outPacket().sendThrough();
    Set<VirtualPort> vPorts = vnaService.getVirtualPorts(networkId, sendThrough);
    PortNumber vOutPortNum = vTreatment.allInstructions().stream().filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).findFirst().get();
    TrafficTreatment.Builder commonTreatmentBuilder = DefaultTrafficTreatment.builder();
    vTreatment.allInstructions().stream().filter(i -> i.type() != Instruction.Type.OUTPUT).forEach(i -> commonTreatmentBuilder.add(i));
    TrafficTreatment commonTreatment = commonTreatmentBuilder.build();
    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, sendThrough);
            return outboundPackets;
        }
        ConnectPoint egressPoint = optionalCpOut.get();
        TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(egressPoint.port()).build();
        OutboundPacket outboundPacket = new DefaultOutboundPacket(egressPoint.deviceId(), treatment, context.outPacket().data());
        outboundPackets.add(outboundPacket);
    } else {
        if (vOutPortNum == PortNumber.FLOOD) {
            Set<VirtualPort> outPorts = vPorts.stream().filter(vp -> !vp.number().isLogical()).filter(vp -> vp.number() != context.inPacket().receivedFrom().port()).collect(Collectors.toSet());
            for (VirtualPort outPort : outPorts) {
                ConnectPoint cpOut = outPort.realizedBy();
                if (cpOut != null) {
                    TrafficTreatment treatment = DefaultTrafficTreatment.builder(commonTreatment).setOutput(cpOut.port()).build();
                    OutboundPacket outboundPacket = new DefaultOutboundPacket(cpOut.deviceId(), treatment, context.outPacket().data());
                    outboundPackets.add(outboundPacket);
                } else {
                    log.warn("Port {} is not realized yet, in Network {}, Device {}", outPort.number(), networkId, 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) DeviceId(org.onosproject.net.DeviceId) Instructions(org.onosproject.net.flow.instructions.Instructions) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) 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)

Aggregations

Ethernet (org.onlab.packet.Ethernet)2 VirtualPacketContext (org.onosproject.incubator.net.virtual.VirtualPacketContext)2 VirtualPort (org.onosproject.incubator.net.virtual.VirtualPort)2 ConnectPoint (org.onosproject.net.ConnectPoint)2 DefaultInboundPacket (org.onosproject.net.packet.DefaultInboundPacket)2 DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)2 InboundPacket (org.onosproject.net.packet.InboundPacket)2 Sets (com.google.common.collect.Sets)1 ByteBuffer (java.nio.ByteBuffer)1 Dictionary (java.util.Dictionary)1 HashSet (java.util.HashSet)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 ApplicationId (org.onosproject.core.ApplicationId)1 CoreService (org.onosproject.core.CoreService)1 NetworkId (org.onosproject.incubator.net.virtual.NetworkId)1 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)1 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)1 VirtualNetworkAdminService (org.onosproject.incubator.net.virtual.VirtualNetworkAdminService)1