Search in sources :

Example 16 with DefaultOutboundPacket

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

the class OpenstackRoutingSnatHandler method packetOut.

private void packetOut(Ethernet ethPacketIn, DeviceId srcDevice, int patPort, IpAddress externalIp, ExternalPeerRouter externalPeerRouter) {
    IPv4 iPacket = (IPv4) ethPacketIn.getPayload();
    switch(iPacket.getProtocol()) {
        case IPv4.PROTOCOL_TCP:
            iPacket.setPayload(buildPacketOutTcp(iPacket, patPort));
            break;
        case IPv4.PROTOCOL_UDP:
            iPacket.setPayload(buildPacketOutUdp(iPacket, patPort));
            break;
        default:
            log.trace("Temporally, this method can process UDP and TCP protocol.");
            return;
    }
    iPacket.setSourceAddress(externalIp.toString());
    iPacket.resetChecksum();
    iPacket.setParent(ethPacketIn);
    ethPacketIn.setSourceMACAddress(DEFAULT_GATEWAY_MAC);
    ethPacketIn.setDestinationMACAddress(externalPeerRouter.macAddress());
    ethPacketIn.setPayload(iPacket);
    if (!externalPeerRouter.vlanId().equals(VlanId.NONE)) {
        ethPacketIn.setVlanID(externalPeerRouter.vlanId().toShort());
    }
    ethPacketIn.resetChecksum();
    OpenstackNode srcNode = osNodeService.node(srcDevice);
    if (srcNode == null) {
        final String error = String.format("Cannot find openstack node for %s", srcDevice);
        throw new IllegalStateException(error);
    }
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    packetService.emit(new DefaultOutboundPacket(srcDevice, tBuilder.setOutput(srcNode.uplinkPortNum()).build(), ByteBuffer.wrap(ethPacketIn.serialize())));
}
Also used : IPv4(org.onlab.packet.IPv4) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 17 with DefaultOutboundPacket

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

the class P4RuntimePacketProvider method handleP4RuntimeEvent.

private void handleP4RuntimeEvent(P4RuntimeEvent event) {
    // FIXME we need the device ID into p4RuntimeEvnetSubject to check for mastsership
    if (!(event.subject() instanceof P4RuntimePacketIn) || event.type() != P4RuntimeEvent.Type.PACKET_IN) {
        log.debug("Unrecognized event type {}, discarding", event.type());
        // Not a packet-in event, ignore it.
        return;
    }
    P4RuntimePacketIn eventSubject = (P4RuntimePacketIn) event.subject();
    DeviceId deviceId = eventSubject.deviceId();
    Device device = deviceService.getDevice(eventSubject.deviceId());
    if (device == null) {
        log.warn("Unable to process packet-in from {}, device is null in the core", deviceId);
        return;
    }
    if (!device.is(PiPipelineInterpreter.class)) {
        log.warn("Unable to process packet-in from {}, device has no PiPipelineInterpreter behaviour", deviceId);
        return;
    }
    PiPacketOperation operation = eventSubject.packetOperation();
    InboundPacket inPkt;
    try {
        inPkt = device.as(PiPipelineInterpreter.class).mapInboundPacket(operation, deviceId);
    } catch (PiPipelineInterpreter.PiInterpreterException e) {
        log.warn("Unable to interpret inbound packet from {}: {}", deviceId, e.getMessage());
        return;
    }
    if (log.isTraceEnabled()) {
        final EthType.EtherType etherType = getEtherType(inPkt.unparsed());
        log.trace("Received PACKET-IN <<< device={} ingress_port={} eth_type={}", inPkt.receivedFrom().deviceId(), inPkt.receivedFrom().port(), etherType.ethType().toString());
    }
    if (inPkt == null) {
        log.debug("Received null inbound packet. Ignoring.");
        return;
    }
    OutboundPacket outPkt = new DefaultOutboundPacket(eventSubject.deviceId(), null, operation.data().asReadOnlyBuffer());
    PacketContext pktCtx = new P4RuntimePacketContext(System.currentTimeMillis(), inPkt, outPkt, false);
    // Pushing the packet context up for processing.
    providerService.processPacket(pktCtx);
}
Also used : DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) EthType(org.onlab.packet.EthType) P4RuntimePacketIn(org.onosproject.p4runtime.api.P4RuntimePacketIn) InboundPacket(org.onosproject.net.packet.InboundPacket) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) PiPipelineInterpreter(org.onosproject.net.pi.model.PiPipelineInterpreter) DefaultPacketContext(org.onosproject.net.packet.DefaultPacketContext) PacketContext(org.onosproject.net.packet.PacketContext)

Example 18 with DefaultOutboundPacket

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

the class LinkDiscovery method createOutBoundBddp.

/**
 * Creates packet_out BDDP for specified output port.
 *
 * @param portNumber the port
 * @param portDesc the port description
 * @return Packet_out message with LLDP data
 */
private OutboundPacket createOutBoundBddp(Long portNumber, String portDesc) {
    if (portNumber == null) {
        return null;
    }
    ONOSLLDP lldp = getLinkProbe(portNumber, portDesc);
    if (lldp == null) {
        log.warn("Cannot get link probe with portNumber {} and portDesc {} for {} at BDDP packet creation.", portNumber, portDesc, deviceId);
        return null;
    }
    bddpEth.setSourceMACAddress(context.fingerprint()).setPayload(lldp);
    return new DefaultOutboundPacket(deviceId, builder().setOutput(portNumber(portNumber)).build(), ByteBuffer.wrap(bddpEth.serialize()));
}
Also used : ONOSLLDP(org.onlab.packet.ONOSLLDP) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket)

Example 19 with DefaultOutboundPacket

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

the class HostLocationProvider method sendProbe.

private void sendProbe(Host host, IpAddress targetIp) {
    Ethernet probePacket = null;
    if (targetIp.isIp4()) {
        // IPv4: Use ARP
        probePacket = buildArpRequest(targetIp, host);
    } else {
        // IPv6: Use Neighbor Discovery
        // TODO need to implement ndp probe
        log.info("Triggering probe on device {} ", host);
        return;
    }
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(host.location().port()).build();
    OutboundPacket outboundPacket = new DefaultOutboundPacket(host.location().deviceId(), treatment, ByteBuffer.wrap(probePacket.serialize()));
    packetService.emit(outboundPacket);
}
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) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket)

Example 20 with DefaultOutboundPacket

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

the class DefaultHostProbingProvider method sendLocationProbe.

/**
 * Send the probe packet on given port.
 *
 * @param probe the probe packet
 * @param connectPoint the port we want to probe
 */
private void sendLocationProbe(Ethernet probe, ConnectPoint connectPoint) {
    log.debug("Sending probe for host {} on location {} with probeMac {}", probe.getDestinationMAC(), connectPoint, probe.getSourceMAC());
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build();
    OutboundPacket outboundPacket = new DefaultOutboundPacket(connectPoint.deviceId(), treatment, ByteBuffer.wrap(probe.serialize()));
    packetService.emit(outboundPacket);
}
Also used : DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket)

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