Search in sources :

Example 6 with PROTOCOL_ICMP6

use of org.onlab.packet.IPv6.PROTOCOL_ICMP6 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)

Aggregations

ICMP6 (org.onlab.packet.ICMP6)5 IPv6 (org.onlab.packet.IPv6)5 Ethernet (org.onlab.packet.Ethernet)4 ICMP (org.onlab.packet.ICMP)2 IPv4 (org.onlab.packet.IPv4)2 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)2 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)2 ByteBuffer (java.nio.ByteBuffer)1 Test (org.junit.Test)1 Ip4Prefix (org.onlab.packet.Ip4Prefix)1 Ip6Prefix (org.onlab.packet.Ip6Prefix)1 IpAddress (org.onlab.packet.IpAddress)1 MacAddress (org.onlab.packet.MacAddress)1 TCP (org.onlab.packet.TCP)1 UDP (org.onlab.packet.UDP)1 IExtensionHeader (org.onlab.packet.ipv6.IExtensionHeader)1 NeighborSolicitation (org.onlab.packet.ndp.NeighborSolicitation)1 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)1 TrafficSelector (org.onosproject.net.flow.TrafficSelector)1 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)1