Search in sources :

Example 11 with DefaultOutboundPacket

use of org.onosproject.net.packet.DefaultOutboundPacket 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 12 with DefaultOutboundPacket

use of org.onosproject.net.packet.DefaultOutboundPacket 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 13 with DefaultOutboundPacket

use of org.onosproject.net.packet.DefaultOutboundPacket in project onos by opennetworkinglab.

the class CastorArpManager method createArp.

@Override
public void createArp(Peer peer) {
    Ethernet packet = null;
    packet = buildArpRequest(peer);
    ByteBuffer buf = ByteBuffer.wrap(packet.serialize());
    ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(peer.getPort());
    TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
    builder.setOutput(connectPoint.port());
    packetService.emit(new DefaultOutboundPacket(connectPoint.deviceId(), builder.build(), buf));
}
Also used : Ethernet(org.onlab.packet.Ethernet) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 14 with DefaultOutboundPacket

use of org.onosproject.net.packet.DefaultOutboundPacket in project onos by opennetworkinglab.

the class CastorArpManager method forward.

/**
 * Forwards the ARP packet to the specified connect point via packet out.
 *
 * @param context The packet context
 */
private void forward(MessageContext context) {
    TrafficTreatment.Builder builder = null;
    Ethernet eth = context.packet();
    ByteBuffer buf = ByteBuffer.wrap(eth.serialize());
    IpAddress target = context.target();
    String value = getMatchingConnectPoint(target);
    if (value != null) {
        ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(value);
        builder = DefaultTrafficTreatment.builder();
        builder.setOutput(connectPoint.port());
        packetService.emit(new DefaultOutboundPacket(connectPoint.deviceId(), builder.build(), buf));
    }
}
Also used : Ethernet(org.onlab.packet.Ethernet) IpAddress(org.onlab.packet.IpAddress) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 15 with DefaultOutboundPacket

use of org.onosproject.net.packet.DefaultOutboundPacket in project onos by opennetworkinglab.

the class DefaultNeighbourMessageActions method sendTo.

/**
 * Outputs a packet out a specific port.
 *
 * @param packet packet to send
 * @param outPort port to send it out
 */
private void sendTo(ByteBuffer packet, ConnectPoint outPort) {
    if (!edgeService.isEdgePoint(outPort)) {
        // misconfiguration).
        return;
    }
    TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
    builder.setOutput(outPort.port());
    packetService.emit(new DefaultOutboundPacket(outPort.deviceId(), builder.build(), packet));
}
Also used : DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment)

Aggregations

DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)53 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)42 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)41 OutboundPacket (org.onosproject.net.packet.OutboundPacket)32 Ethernet (org.onlab.packet.Ethernet)23 ByteBuffer (java.nio.ByteBuffer)12 ConnectPoint (org.onosproject.net.ConnectPoint)12 PortNumber (org.onosproject.net.PortNumber)11 IpAddress (org.onlab.packet.IpAddress)9 Test (org.junit.Test)8 DeviceId (org.onosproject.net.DeviceId)8 InboundPacket (org.onosproject.net.packet.InboundPacket)7 PacketContext (org.onosproject.net.packet.PacketContext)7 Set (java.util.Set)6 MacAddress (org.onlab.packet.MacAddress)6 ApplicationId (org.onosproject.core.ApplicationId)6 PacketProcessor (org.onosproject.net.packet.PacketProcessor)6 DefaultInboundPacket (org.onosproject.net.packet.DefaultInboundPacket)5 PacketService (org.onosproject.net.packet.PacketService)5 PiPacketOperation (org.onosproject.net.pi.runtime.PiPacketOperation)5