Search in sources :

Example 31 with OutboundPacket

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

the class McastForwarding method forwardPacketToDst.

/**
 * Forward the packet to it's multicast destinations.
 *
 * @param context The packet context
 * @param egressList The list of egress ports which the multicast packet is intended for.
 */
private void forwardPacketToDst(PacketContext context, ArrayList<ConnectPoint> egressList) {
    // Send the pack out each of the respective egress ports
    for (ConnectPoint egress : egressList) {
        TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(egress.port()).build();
        OutboundPacket packet = new DefaultOutboundPacket(egress.deviceId(), treatment, context.inPacket().unparsed());
        packetService.emit(packet);
    }
}
Also used : DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket)

Example 32 with OutboundPacket

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

the class SimpleFabricManager method requestMac.

@Override
public boolean requestMac(IpAddress ip) {
    FabricSubnet fabricSubnet = fabricSubnet(ip);
    if (fabricSubnet == null) {
        log.warn("simple fabric request mac failed for unknown fabricSubnet: {}", ip);
        return false;
    }
    FabricNetwork fabricNetwork = fabricNetwork(fabricSubnet.networkName());
    if (fabricNetwork == null) {
        log.warn("simple fabric request mac failed for unknown fabricNetwork name {}: {}", fabricSubnet.networkName(), ip);
        return false;
    }
    log.debug("simple fabric send request mac fabricNetwork {}: {}", fabricNetwork.name(), ip);
    for (Interface iface : fabricNetwork.interfaces()) {
        Ethernet neighbourReq;
        if (ip.isIp4()) {
            neighbourReq = ARP.buildArpRequest(fabricSubnet.gatewayMac().toBytes(), fabricSubnet.gatewayIp().toOctets(), ip.toOctets(), iface.vlan().toShort());
        } else {
            byte[] soliciteIp = IPv6.getSolicitNodeAddress(ip.toOctets());
            neighbourReq = NeighborSolicitation.buildNdpSolicit(ip.getIp6Address(), fabricSubnet.gatewayIp().getIp6Address(), Ip6Address.valueOf(soliciteIp), MacAddress.valueOf(fabricSubnet.gatewayMac().toBytes()), MacAddress.valueOf(IPv6.getMCastMacAddress(soliciteIp)), iface.vlan());
        }
        TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(iface.connectPoint().port()).build();
        OutboundPacket packet = new DefaultOutboundPacket(iface.connectPoint().deviceId(), treatment, ByteBuffer.wrap(neighbourReq.serialize()));
        packetService.emit(packet);
    }
    return true;
}
Also used : FabricSubnet(org.onosproject.simplefabric.api.FabricSubnet) Ethernet(org.onlab.packet.Ethernet) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FabricNetwork(org.onosproject.simplefabric.api.FabricNetwork) Interface(org.onosproject.net.intf.Interface) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket)

Example 33 with OutboundPacket

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

the class SimpleFabricRouting method forwardPacketToDstIp.

/**
 * Emits the specified packet onto the network.
 */
private void forwardPacketToDstIp(PacketContext context, IpAddress nextHopIp, MacAddress srcMac, boolean updateMac) {
    Set<Host> hosts = hostService.getHostsByIp(nextHopIp);
    Host dstHost;
    if (!hosts.isEmpty()) {
        dstHost = hosts.iterator().next();
    } else {
        // NOTE: hostService.requestMac(nextHopIp); NOT IMPLEMENTED in ONOS HostManager.java; do it myself
        log.warn("forward packet nextHopIp host_mac unknown: nextHopIp={}", nextHopIp);
        hostService.startMonitoringIp(nextHopIp);
        simpleFabric.requestMac(nextHopIp);
        // CONSIDER: make flood on all port of the dstHost's DefaultFabricNetwork
        return;
    }
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(dstHost.location().port()).build();
    OutboundPacket outPacket;
    if (updateMac) {
        // NOTE: eth address update by treatment is NOT applied, so update mac myself
        outPacket = new DefaultOutboundPacket(dstHost.location().deviceId(), treatment, ByteBuffer.wrap(context.inPacket().parsed().setSourceMACAddress(srcMac).setDestinationMACAddress(dstHost.mac()).serialize()));
    } else {
        outPacket = new DefaultOutboundPacket(dstHost.location().deviceId(), treatment, context.inPacket().unparsed());
    }
    // be quiet on normal situation
    log.info("forward packet: nextHopIP={} srcCP={} dstCP={}", nextHopIp, context.inPacket().receivedFrom(), dstHost.location());
    packetService.emit(outPacket);
}
Also used : Host(org.onosproject.net.Host) 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 34 with OutboundPacket

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

the class SimpleFabricRouting method checkVirtualGatewayIpPacket.

/**
 * handle Packet with dstIp=virtualGatewayIpAddresses.
 * returns true(handled) or false(not for virtual gateway)
 */
private boolean checkVirtualGatewayIpPacket(InboundPacket pkt, IpAddress srcIp, IpAddress dstIp) {
    // assume valid
    Ethernet ethPkt = pkt.parsed();
    MacAddress mac = simpleFabric.vMacForIp(dstIp);
    if (mac == null || !simpleFabric.isVirtualGatewayMac(ethPkt.getDestinationMAC())) {
        /* Destination MAC should be any of virtual gateway macs */
        return false;
    } else if (dstIp.isIp4()) {
        IPv4 ipv4Packet = (IPv4) ethPkt.getPayload();
        if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) {
            ICMP icmpPacket = (ICMP) ipv4Packet.getPayload();
            if (icmpPacket.getIcmpType() == ICMP.TYPE_ECHO_REQUEST) {
                log.info("IPV4 ICMP ECHO request to virtual gateway: " + "srcIp={} dstIp={} proto={}", srcIp, dstIp, ipv4Packet.getProtocol());
                TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(pkt.receivedFrom().port()).build();
                OutboundPacket packet = new DefaultOutboundPacket(pkt.receivedFrom().deviceId(), treatment, ByteBuffer.wrap(icmpPacket.buildIcmpReply(pkt.parsed()).serialize()));
                packetService.emit(packet);
                return true;
            }
        }
        log.warn("IPV4 packet to virtual gateway dropped: " + "srcIp={} dstIp={} proto={}", srcIp, dstIp, ipv4Packet.getProtocol());
        return true;
    } else if (dstIp.isIp6()) {
        // TODO: not tested yet (2017-07-20)
        IPv6 ipv6Packet = (IPv6) ethPkt.getPayload();
        if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
            ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
            if (icmp6Packet.getIcmpType() == ICMP6.ECHO_REQUEST) {
                log.info("IPV6 ICMP6 ECHO request to virtual gateway: srcIp={} dstIp={} nextHeader={}", srcIp, dstIp, ipv6Packet.getNextHeader());
                TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(pkt.receivedFrom().port()).build();
                OutboundPacket packet = new DefaultOutboundPacket(pkt.receivedFrom().deviceId(), treatment, ByteBuffer.wrap(icmp6Packet.buildIcmp6Reply(pkt.parsed()).serialize()));
                packetService.emit(packet);
                return true;
            }
        }
        log.warn("IPV6 packet to virtual gateway dropped: srcIp={} dstIp={} nextHeader={}", srcIp, dstIp, ipv6Packet.getNextHeader());
        return true;
    }
    // unknown traffic
    return false;
}
Also used : IPv6(org.onlab.packet.IPv6) Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ICMP6(org.onlab.packet.ICMP6) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) ICMP(org.onlab.packet.ICMP)

Example 35 with OutboundPacket

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

the class IcmpHandler method sendPacketOut.

private void sendPacketOut(ConnectPoint outport, Ethernet payload) {
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(outport.port()).build();
    OutboundPacket packet = new DefaultOutboundPacket(outport.deviceId(), treatment, ByteBuffer.wrap(payload.serialize()));
    packetService.emit(packet);
}
Also used : DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket)

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