Search in sources :

Example 36 with OutboundPacket

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

the class TunnellingConnectivityManager method forward.

/**
 * Forwards a BGP packet to another connect point.
 *
 * @param context the packet context of the incoming packet
 */
private void forward(PacketContext context) {
    ConnectPoint outputPort = null;
    IPv4 ipv4 = (IPv4) context.inPacket().parsed().getPayload();
    IpAddress dstAddress = IpAddress.valueOf(ipv4.getDestinationAddress());
    if (context.inPacket().receivedFrom().equals(bgpSpeaker.connectPoint())) {
        if (bgpSpeaker.peers().contains(dstAddress)) {
            Interface intf = interfaceService.getMatchingInterface(dstAddress);
            if (intf != null) {
                outputPort = intf.connectPoint();
            }
        }
    } else {
        Set<Interface> interfaces = interfaceService.getInterfacesByPort(context.inPacket().receivedFrom());
        if (interfaces.stream().flatMap(intf -> intf.ipAddressesList().stream()).anyMatch(ia -> ia.ipAddress().equals(dstAddress))) {
            outputPort = bgpSpeaker.connectPoint();
        }
    }
    if (outputPort != null) {
        TrafficTreatment t = DefaultTrafficTreatment.builder().setOutput(outputPort.port()).build();
        OutboundPacket o = new DefaultOutboundPacket(outputPort.deviceId(), t, context.inPacket().unparsed());
        packetService.emit(o);
    }
}
Also used : Interface(org.onosproject.net.intf.Interface) InterfaceService(org.onosproject.net.intf.InterfaceService) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) TCP(org.onlab.packet.TCP) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) OutboundPacket(org.onosproject.net.packet.OutboundPacket) ApplicationId(org.onosproject.core.ApplicationId) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IpAddress(org.onlab.packet.IpAddress) TpPort(org.onlab.packet.TpPort) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) PacketProcessor(org.onosproject.net.packet.PacketProcessor) Set(java.util.Set) PacketService(org.onosproject.net.packet.PacketService) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) BgpConfig(org.onosproject.routing.config.BgpConfig) IPv4(org.onlab.packet.IPv4) PacketContext(org.onosproject.net.packet.PacketContext) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) IPv4(org.onlab.packet.IPv4) IpAddress(org.onlab.packet.IpAddress) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) Interface(org.onosproject.net.intf.Interface) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket)

Example 37 with OutboundPacket

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

the class Dhcp4HandlerImpl method sendResponseToClient.

/**
 * Send the response DHCP to the requester host.
 *
 * @param thePacket the packet
 * @param dhcpPayload the DHCP data
 */
private void sendResponseToClient(InternalPacket thePacket, DHCP dhcpPayload) {
    checkNotNull(thePacket, "Nothing to send");
    checkNotNull(thePacket.getPacket(), "Packet to send must not be empty");
    checkNotNull(thePacket.getDestLocation(), "Packet destination not be empty");
    Ethernet ethPacket = thePacket.getPacket();
    if (directlyConnected(dhcpPayload)) {
        ethPacket = removeRelayAgentOption(ethPacket);
    }
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(thePacket.getDestLocation().port()).build();
    OutboundPacket o = new DefaultOutboundPacket(thePacket.getDestLocation().deviceId(), treatment, ByteBuffer.wrap(ethPacket.serialize()));
    if (log.isTraceEnabled()) {
        log.trace("Relaying packet to DHCP client {} via {}", ethPacket, thePacket.getDestLocation());
    }
    packetService.emit(o);
}
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) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) OutboundPacket(org.onosproject.net.packet.OutboundPacket)

Example 38 with OutboundPacket

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

the class Dhcp4HandlerImpl method forwardPacket.

// forward the packet to ConnectPoint where the DHCP server is attached.
private void forwardPacket(InternalPacket packet) {
    // send Packetout to dhcp server connectpoint.
    if (packet.getDestLocation() != null) {
        TrafficTreatment t = DefaultTrafficTreatment.builder().setOutput(packet.getDestLocation().port()).build();
        OutboundPacket o = new DefaultOutboundPacket(packet.getDestLocation().deviceId(), t, ByteBuffer.wrap(packet.getPacket().serialize()));
        if (log.isTraceEnabled()) {
            log.trace("Relaying packet to destination {}", packet.getDestLocation());
        }
        log.debug("packetService.emit(o) to port {}", packet.getDestLocation());
        packetService.emit(o);
    }
}
Also used : DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) OutboundPacket(org.onosproject.net.packet.OutboundPacket)

Example 39 with OutboundPacket

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

the class Dhcp6HandlerImpl method forwardPacket.

// forward the packet to ConnectPoint where the DHCP server is attached.
private void forwardPacket(InternalPacket packet) {
    // send Packetout to dhcp server connectpoint.
    if (packet.getDestLocation() != null) {
        TrafficTreatment t = DefaultTrafficTreatment.builder().setOutput(packet.getDestLocation().port()).build();
        OutboundPacket o = new DefaultOutboundPacket(packet.getDestLocation().deviceId(), t, ByteBuffer.wrap(packet.getPacket().serialize()));
        packetService.emit(o);
        if (log.isTraceEnabled()) {
            IPv6 ip6 = (IPv6) packet.getPacket().getPayload();
            UDP udp = (UDP) ip6.getPayload();
            DHCP6 dhcp6 = (DHCP6) udp.getPayload();
            log.trace("Relaying packet to destination {} eth: {} dhcp: {}", packet.getDestLocation(), packet.getPacket(), dhcp6);
        }
    }
}
Also used : UDP(org.onlab.packet.UDP) IPv6(org.onlab.packet.IPv6) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DHCP6(org.onlab.packet.DHCP6) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) OutboundPacket(org.onosproject.net.packet.OutboundPacket)

Example 40 with OutboundPacket

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

the class DhcpRelayManager method sendHostRelearnProbeToConnectPoint.

// Send Host Relearn Probe packets to ConnectPoint
private void sendHostRelearnProbeToConnectPoint(Ethernet nsPacket, ConnectPoint connectPoint) {
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build();
    OutboundPacket outboundPacket = new DefaultOutboundPacket(connectPoint.deviceId(), treatment, ByteBuffer.wrap(nsPacket.serialize()));
    int counter = 0;
    try {
        while (counter < dhcpHostRelearnProbeCount) {
            packetService.emit(outboundPacket);
            counter++;
            Thread.sleep(dhcpHostRelearnProbeInterval);
        }
    } catch (Exception e) {
        log.error("Exception while emmiting packet {}", e.getMessage(), e);
    }
}
Also used : DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) OutboundPacket(org.onosproject.net.packet.OutboundPacket) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

OutboundPacket (org.onosproject.net.packet.OutboundPacket)46 DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)35 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)29 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)25 Ethernet (org.onlab.packet.Ethernet)20 Test (org.junit.Test)17 ConnectPoint (org.onosproject.net.ConnectPoint)16 PortNumber (org.onosproject.net.PortNumber)15 DeviceId (org.onosproject.net.DeviceId)12 ByteBuffer (java.nio.ByteBuffer)11 Port (org.onosproject.net.Port)9 InboundPacket (org.onosproject.net.packet.InboundPacket)9 PiPacketOperation (org.onosproject.net.pi.runtime.PiPacketOperation)9 ImmutableList (com.google.common.collect.ImmutableList)8 Instruction (org.onosproject.net.flow.instructions.Instruction)8 DefaultInboundPacket (org.onosproject.net.packet.DefaultInboundPacket)8 PiPacketMetadata (org.onosproject.net.pi.runtime.PiPacketMetadata)8 Optional (java.util.Optional)7 Device (org.onosproject.net.Device)7 Interface (org.onosproject.net.intf.Interface)6