Java Code Examples for org.onosproject.net.packet.InboundPacket#parsed()

The following examples show how to use org.onosproject.net.packet.InboundPacket#parsed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NeighbourResolutionManager.java    From onos with Apache License 2.0 6 votes vote down vote up
private void handlePacket(PacketContext context) {
    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();

    NeighbourMessageContext msgContext =
            DefaultNeighbourMessageContext.createContext(ethPkt, pkt.receivedFrom(), actions);

    if (msgContext == null) {
        return;
    }

    if (handleMessage(msgContext)) {
        context.block();
    }

}
 
Example 2
Source File: IcmpHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void processPacketIn(InboundPacket pkt) {

        boolean ipMatches = false;
        Ethernet ethernet = pkt.parsed();
        IPv4 ipv4 = (IPv4) ethernet.getPayload();
        ConnectPoint connectPoint = pkt.receivedFrom();
        IpAddress destIpAddress = IpAddress.valueOf(ipv4.getDestinationAddress());
        Interface targetInterface = interfaceService.getMatchingInterface(destIpAddress);

        if (targetInterface == null) {
            log.trace("No matching interface for {}", destIpAddress);
            return;
        }

        for (InterfaceIpAddress interfaceIpAddress: targetInterface.ipAddressesList()) {
            if (interfaceIpAddress.ipAddress().equals(destIpAddress)) {
                ipMatches = true;
                break;
            }
        }

        if (((ICMP) ipv4.getPayload()).getIcmpType() == ICMP.TYPE_ECHO_REQUEST &&
                ipMatches) {
            sendIcmpResponse(ethernet, connectPoint);
        }
    }
 
Example 3
Source File: OpenstackRoutingArpHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void process(PacketContext context) {
    if (context.isHandled()) {
        return;
    }

    InboundPacket pkt = context.inPacket();
    Ethernet ethernet = pkt.parsed();
    if (ethernet != null && ethernet.getEtherType() == Ethernet.TYPE_ARP) {
        eventExecutor.execute(() -> {

            if (!isRelevantHelper(context)) {
                return;
            }

            processArpPacket(context, ethernet);
        });
    }
}
 
Example 4
Source File: CastorArpManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void process(PacketContext context) {

    if (context.isHandled()) {
        return;
    }
    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();
    if (ethPkt == null) {
        return;
    }
    if (ethPkt.getEtherType() == TYPE_ARP) {
        //handle the arp packet.
        handlePacket(context);
    } else {
        return;
    }
}
 
Example 5
Source File: RouterAdvertisementManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void process(PacketContext context) {
    if (context.isHandled()) {
        return;
    }

    // Ensure packet is IPv6 Solicited RA
    InboundPacket pkt = context.inPacket();
    Ethernet ethernet = pkt.parsed();
    if ((ethernet == null) || (ethernet.getEtherType() != Ethernet.TYPE_IPV6)) {
        return;
    }
    IPv6 ipv6Packet = (IPv6) ethernet.getPayload();
    if (ipv6Packet.getNextHeader() != IPv6.PROTOCOL_ICMP6) {
        return;
    }
    ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
    if (icmp6Packet.getIcmpType() != ICMP6.ROUTER_SOLICITATION) {
        return;
    }

    // Start solicited-RA handling thread
    SolicitedRAWorkerThread sraWorkerThread = new SolicitedRAWorkerThread(pkt);
    executors.schedule(sraWorkerThread, 0, TimeUnit.SECONDS);
}
 
Example 6
Source File: OpenstackTroubleshootManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void process(PacketContext context) {
    if (context.isHandled()) {
        return;
    }

    InboundPacket pkt = context.inPacket();
    Ethernet ethernet = pkt.parsed();
    if (ethernet == null || ethernet.getEtherType() == Ethernet.TYPE_ARP) {
        return;
    }

    IPv4 iPacket = (IPv4) ethernet.getPayload();
    if (iPacket.getProtocol() == IPv4.PROTOCOL_ICMP) {
        eventExecutor.execute(() -> processIcmpPacket(context, ethernet));
    }
}
 
Example 7
Source File: NeighbourResolutionManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void process(PacketContext context) {
    // Stop processing if the packet has been handled, since we
    // can't do any more to it.
    if (context.isHandled()) {
        return;
    }

    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();
    if (ethPkt == null) {
        return;
    }

    if (ethPkt.getEtherType() == TYPE_ARP) {
        // handle ARP packets
        handlePacket(context);
    } else if (ethPkt.getEtherType() == TYPE_IPV6) {
        IPv6 ipv6 = (IPv6) ethPkt.getPayload();
        if (ipv6.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
            ICMP6 icmp6 = (ICMP6) ipv6.getPayload();
            if (icmp6.getIcmpType() == NEIGHBOR_SOLICITATION ||
                    icmp6.getIcmpType() == NEIGHBOR_ADVERTISEMENT) {
                // handle ICMPv6 solicitations and advertisements (NDP)
                handlePacket(context);
            }
        }
    }
}
 
Example 8
Source File: VtnManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void process(PacketContext context) {
    InboundPacket pkt = context.inPacket();
    ConnectPoint connectPoint = pkt.receivedFrom();
    DeviceId deviceId = connectPoint.deviceId();
    Ethernet ethPkt = pkt.parsed();
    if (ethPkt == null) {
        return;
    }
    if (ethPkt.getEtherType() == Ethernet.TYPE_ARP) {
        ARP arpPacket = (ARP) ethPkt.getPayload();
        if ((arpPacket.getOpCode() == ARP.OP_REQUEST)) {
            arprequestProcess(arpPacket, deviceId);
        } else if (arpPacket.getOpCode() == ARP.OP_REPLY) {
            arpresponceProcess(arpPacket, deviceId);
        }
    } else if (ethPkt.getEtherType() == Ethernet.TYPE_IPV4) {
        if (ethPkt.getDestinationMAC().isMulticast()) {
            return;
        }
        IPv4 ip = (IPv4) ethPkt.getPayload();
        upStreamPacketProcessor(ip, deviceId);

    } else {
        return;
    }
}
 
Example 9
Source File: OpenstackRoutingSnatHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void process(PacketContext context) {

    if (context.isHandled()) {
        return;
    }

    InboundPacket pkt = context.inPacket();
    Ethernet eth = pkt.parsed();
    if (eth == null || eth.getEtherType() == Ethernet.TYPE_ARP) {
        return;
    }

    IPv4 iPacket = (IPv4) eth.getPayload();
    switch (iPacket.getProtocol()) {
        case IPv4.PROTOCOL_ICMP:
            break;
        case IPv4.PROTOCOL_UDP:
            UDP udpPacket = (UDP) iPacket.getPayload();
            if (udpPacket.getDestinationPort() == UDP.DHCP_SERVER_PORT &&
                    udpPacket.getSourcePort() == UDP.DHCP_CLIENT_PORT) {
                break; // don't process DHCP
            }
        default:
            eventExecutor.execute(() -> {
                if (!isRelevantHelper(context)) {
                    return;
                }
                processSnatPacket(context, eth);
            });
            break;
    }
}
 
Example 10
Source File: CastorArpManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean handlePacket(PacketContext context) {

    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();

    if (ethPkt == null) {
        return false;
    }

    MessageContext msgContext = createContext(ethPkt, pkt.receivedFrom());

    if (msgContext == null) {
        return false;
    }
    switch (msgContext.type()) {
        case REPLY:
            forward(msgContext);
            updateMac(msgContext);
            handleArpForL2(msgContext);
            break;
        case REQUEST:
            forward(msgContext);
            updateMac(msgContext);
            handleArpForL2(msgContext);
            break;
        default:
            return false;
    }
    context.block();
    return true;
}
 
Example 11
Source File: K8sRoutingArpHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void process(PacketContext context) {
    if (context.isHandled()) {
        return;
    }

    InboundPacket pkt = context.inPacket();
    Ethernet ethernet = pkt.parsed();
    if (ethernet != null && ethernet.getEtherType() == Ethernet.TYPE_ARP) {
        eventExecutor.execute(() -> processArpPacket(context, ethernet));
    }
}
 
Example 12
Source File: SimpleFabricRouting.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void process(PacketContext context) {
    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();
    if (ethPkt == null) {
        return;
    }
    ConnectPoint srcCp = pkt.receivedFrom();
    IpAddress srcIp;
    IpAddress dstIp;
    byte ipProto = 0;  /* 0 or tcp, udp */

    switch (EthType.EtherType.lookup(ethPkt.getEtherType())) {
    case IPV4:
        IPv4 ipv4Packet = (IPv4) ethPkt.getPayload();
        srcIp = IpAddress.valueOf(ipv4Packet.getSourceAddress());
        dstIp = IpAddress.valueOf(ipv4Packet.getDestinationAddress());
        ipProto = ipv4Packet.getProtocol();
        break;
    case IPV6:
        IPv6 ipv6Packet = (IPv6) ethPkt.getPayload();
        srcIp = IpAddress.valueOf(IpAddress.Version.INET6, ipv6Packet.getSourceAddress());
        dstIp = IpAddress.valueOf(IpAddress.Version.INET6, ipv6Packet.getDestinationAddress());
        ipProto = ipv6Packet.getNextHeader();
        break;
    default:
        return;  // ignore unknow ether type packets
    }
    if (ipProto != 6 && ipProto != 17) {
        ipProto = 0;  /* handle special for TCP and UDP only */
    }

    if (!checkVirtualGatewayIpPacket(pkt, srcIp, dstIp)) {
        ipPacketReactiveProcessor(context, ethPkt, srcCp, srcIp, dstIp, ipProto);
        // TODO: add ReactiveRouting for dstIp to srcIp with discovered egressCp as srcCp
    }
}
 
Example 13
Source File: PimApplication.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void process(PacketContext context) {

    // return if this packet has already been handled
    if (context.isHandled()) {
        return;
    }

    // get the inbound packet
    InboundPacket pkt = context.inPacket();
    if (pkt == null) {
        // problem getting the inbound pkt.  Log it debug to avoid spamming log file
        log.debug("Could not retrieve packet from context");
        return;
    }

    // Get the ethernet header
    Ethernet eth = pkt.parsed();
    if (eth == null) {
        // problem getting the ethernet pkt.  Log it debug to avoid spamming log file
        log.debug("Could not retrieve ethernet packet from the parsed packet");
        return;
    }

    // Get the PIM Interface the packet was received on.
    PimInterface pimi = pimInterfaceManager.getPimInterface(pkt.receivedFrom());
    if (pimi == null) {
        return;
    }

    /*
     * Pass the packet processing off to the PIMInterface for processing.
     *
     * TODO: Is it possible that PIM interface processing should move to the
     * PIMInterfaceManager directly?
     */
    pimPacketHandler.processPacket(eth, pimi);
}
 
Example 14
Source File: SdnIpReactiveRouting.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void process(PacketContext context) {

    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();
    if (ethPkt == null) {
        return;
    }
    ConnectPoint srcConnectPoint = pkt.receivedFrom();

    switch (EthType.EtherType.lookup(ethPkt.getEtherType())) {
    case ARP:
        ARP arpPacket = (ARP) ethPkt.getPayload();
        Ip4Address targetIpAddress = Ip4Address
                .valueOf(arpPacket.getTargetProtocolAddress());
        // Only when it is an ARP request packet and the target IP
        // address is a virtual gateway IP address, then it will be
        // processed.
        if (arpPacket.getOpCode() == ARP.OP_REQUEST
                && config.isVirtualGatewayIpAddress(targetIpAddress)) {
            MacAddress gatewayMacAddress =
                    config.getVirtualGatewayMacAddress();
            if (gatewayMacAddress == null) {
                break;
            }
            Ethernet eth = ARP.buildArpReply(targetIpAddress,
                                             gatewayMacAddress,
                                             ethPkt);

            TrafficTreatment.Builder builder =
                    DefaultTrafficTreatment.builder();
            builder.setOutput(srcConnectPoint.port());
            packetService.emit(new DefaultOutboundPacket(
                    srcConnectPoint.deviceId(),
                    builder.build(),
                    ByteBuffer.wrap(eth.serialize())));
        }
        break;
    case IPV4:
        // Parse packet
        IPv4 ipv4Packet = (IPv4) ethPkt.getPayload();
        IpAddress dstIp =
                IpAddress.valueOf(ipv4Packet.getDestinationAddress());
        IpAddress srcIp =
                IpAddress.valueOf(ipv4Packet.getSourceAddress());
        MacAddress srcMac = ethPkt.getSourceMAC();
        packetReactiveProcessor(dstIp, srcIp, srcConnectPoint, srcMac);

        // TODO emit packet first or packetReactiveProcessor first
        ConnectPoint egressConnectPoint = null;
        egressConnectPoint = getEgressConnectPoint(dstIp);
        if (egressConnectPoint != null) {
            forwardPacketToDst(context, egressConnectPoint);
        }
        break;
    default:
        break;
    }
}
 
Example 15
Source File: VirtualPublicHosts.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void process(PacketContext context) {

    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();

    // Only handle the ARP packets
    if (ethPkt == null || ethPkt.getEtherType() != Ethernet.TYPE_ARP) {
        return;
    }
    ARP arpPacket = (ARP) ethPkt.getPayload();
    // Only handle ARP request packets
    if (arpPacket.getOpCode() != ARP.OP_REQUEST) {
        return;
    }

    Ip4Address targetIpAddress = Ip4Address
            .valueOf(arpPacket.getTargetProtocolAddress());

    // Only handle an ARP request when the target IP address inside is
    // an assigned public IP address
    if (!vbngConfigService.isAssignedPublicIpAddress(targetIpAddress)) {
        return;
    }

    MacAddress virtualHostMac =
            vbngConfigService.getPublicFacingMac();
    if (virtualHostMac == null) {
        return;
    }

    ConnectPoint srcConnectPoint = pkt.receivedFrom();
    Ethernet eth = ARP.buildArpReply(targetIpAddress,
                                     virtualHostMac,
                                     ethPkt);

    TrafficTreatment.Builder builder =
            DefaultTrafficTreatment.builder();
    builder.setOutput(srcConnectPoint.port());
    packetService.emit(new DefaultOutboundPacket(
            srcConnectPoint.deviceId(),
            builder.build(),
            ByteBuffer.wrap(eth.serialize())));
}
 
Example 16
Source File: ReactiveForwarding.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void process(PacketContext context) {
    // Stop processing if the packet has been handled, since we
    // can't do any more to it.

    if (context.isHandled()) {
        return;
    }

    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();

    if (ethPkt == null) {
        return;
    }

    MacAddress macAddress = ethPkt.getSourceMAC();
    ReactiveForwardMetrics macMetrics = null;
    macMetrics = createCounter(macAddress);
    inPacket(macMetrics);

    // Bail if this is deemed to be a control packet.
    if (isControlPacket(ethPkt)) {
        droppedPacket(macMetrics);
        return;
    }

    // Skip IPv6 multicast packet when IPv6 forward is disabled.
    if (!ipv6Forwarding && isIpv6Multicast(ethPkt)) {
        droppedPacket(macMetrics);
        return;
    }

    HostId id = HostId.hostId(ethPkt.getDestinationMAC(), VlanId.vlanId(ethPkt.getVlanID()));

    // Do not process LLDP MAC address in any way.
    if (id.mac().isLldp()) {
        droppedPacket(macMetrics);
        return;
    }

    // Do not process IPv4 multicast packets, let mfwd handle them
    if (ignoreIPv4Multicast && ethPkt.getEtherType() == Ethernet.TYPE_IPV4) {
        if (id.mac().isMulticast()) {
            return;
        }
    }

    // Do we know who this is for? If not, flood and bail.
    Host dst = hostService.getHost(id);
    if (dst == null) {
        flood(context, macMetrics);
        return;
    }

    // Are we on an edge switch that our destination is on? If so,
    // simply forward out to the destination and bail.
    if (pkt.receivedFrom().deviceId().equals(dst.location().deviceId())) {
        if (!context.inPacket().receivedFrom().port().equals(dst.location().port())) {
            installRule(context, dst.location().port(), macMetrics);
        }
        return;
    }

    // Otherwise, get a set of paths that lead from here to the
    // destination edge switch.
    Set<Path> paths =
            topologyService.getPaths(topologyService.currentTopology(),
                                     pkt.receivedFrom().deviceId(),
                                     dst.location().deviceId());
    if (paths.isEmpty()) {
        // If there are no paths, flood and bail.
        flood(context, macMetrics);
        return;
    }

    // Otherwise, pick a path that does not lead back to where we
    // came from; if no such path, flood and bail.
    Path path = pickForwardPathIfPossible(paths, pkt.receivedFrom().port());
    if (path == null) {
        log.warn("Don't know where to go from here {} for {} -> {}",
                 pkt.receivedFrom(), ethPkt.getSourceMAC(), ethPkt.getDestinationMAC());
        flood(context, macMetrics);
        return;
    }

    // Otherwise forward and be done with it.
    installRule(context, path.src().port(), macMetrics);
}
 
Example 17
Source File: SegmentRoutingManager.java    From onos with Apache License 2.0 4 votes vote down vote up
private void processPacketInternal(PacketContext context) {
    if (context.isHandled()) {
        return;
    }

    InboundPacket pkt = context.inPacket();
    Ethernet ethernet = pkt.parsed();

    if (ethernet == null) {
        return;
    }

    log.trace("Rcvd pktin from {}: {}", context.inPacket().receivedFrom(),
              ethernet);
    if (ethernet.getEtherType() == TYPE_ARP) {
        log.warn("Received unexpected ARP packet on {}",
                 context.inPacket().receivedFrom());
        log.trace("{}", ethernet);
        return;
    } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV4) {
        IPv4 ipv4Packet = (IPv4) ethernet.getPayload();
        //ipHandler.addToPacketBuffer(ipv4Packet);
        if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) {
            icmpHandler.processIcmp(ethernet, pkt.receivedFrom());
        } else {
            // NOTE: We don't support IP learning at this moment so this
            //       is not necessary. Also it causes duplication of DHCP packets.
            // ipHandler.processPacketIn(ipv4Packet, pkt.receivedFrom());
        }
    } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV6) {
        IPv6 ipv6Packet = (IPv6) ethernet.getPayload();
        //ipHandler.addToPacketBuffer(ipv6Packet);
        // We deal with the packet only if the packet is a ICMP6 ECHO/REPLY
        if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
            ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
            if (icmp6Packet.getIcmpType() == ICMP6.ECHO_REQUEST ||
                    icmp6Packet.getIcmpType() == ICMP6.ECHO_REPLY) {
                icmpHandler.processIcmpv6(ethernet, pkt.receivedFrom());
            } else {
                log.trace("Received ICMPv6 0x{} - not handled",
                        Integer.toHexString(icmp6Packet.getIcmpType() & 0xff));
            }
        } else {
           // NOTE: We don't support IP learning at this moment so this
           //       is not necessary. Also it causes duplication of DHCPv6 packets.
           // ipHandler.processPacketIn(ipv6Packet, pkt.receivedFrom());
        }
    }
}
 
Example 18
Source File: McastForwarding.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Process incoming packets.
 *
 * @param context packet processing context
 */
@Override
public void process(PacketContext context) {
    // Stop processing if the packet has been handled, since we
    // can't do any more to it.
    if (context.isHandled()) {
        return;
    }

    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();

    if (ethPkt == null) {
        return;
    }

    if (ethPkt.getEtherType() != Ethernet.TYPE_IPV4 &&
            ethPkt.getEtherType() != Ethernet.TYPE_IPV6) {
        return;
    }

    if (ethPkt.getEtherType() == Ethernet.TYPE_IPV6) {
        // Ignore ipv6 at the moment.
        return;
    }

    IPv4 ip = (IPv4) ethPkt.getPayload();
    IpAddress saddr = Ip4Address.valueOf(ip.getSourceAddress());
    IpAddress gaddr = IpAddress.valueOf(ip.getDestinationAddress());

    log.debug("Packet ({}, {}) has been punted\n" +
                    "\tingress port: {}\n",
            saddr.toString(),
            gaddr.toString(),
            context.inPacket().receivedFrom().toString());

    // Don't allow PIM/IGMP packets to be handled here.
    byte proto = ip.getProtocol();
    if (proto == IPv4.PROTOCOL_PIM || proto == IPv4.PROTOCOL_IGMP) {
        return;
    }

    IpPrefix spfx = IpPrefix.valueOf(saddr, 32);
    IpPrefix gpfx = IpPrefix.valueOf(gaddr, 32);

    // TODO do we want to add a type for Mcast?
    McastRoute mRoute = new McastRoute(saddr, gaddr, McastRoute.Type.STATIC);

    ConnectPoint ingress = mcastRouteManager.fetchSource(mRoute);

    // An ingress port already exists. Log error.
    if (ingress != null) {
        log.error(McastForwarding.class.getSimpleName() + " received packet which already has a route.");
        return;
    } else {
        //add ingress port
        mcastRouteManager.addSource(mRoute, pkt.receivedFrom());
    }

    ArrayList<ConnectPoint> egressList = (ArrayList<ConnectPoint>) mcastRouteManager.fetchSinks(mRoute);
    //If there are no egress ports set return, otherwise forward the packets to their expected port.
    if (egressList.isEmpty()) {
        return;
    }

    // Send the pack out each of the egress devices & port
    forwardPacketToDst(context, egressList);
}
 
Example 19
Source File: PacketStatistics.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void process(PacketContext context) {
    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();

    //Indicates whether this is an ARP Packet
    if (ethPkt.getEtherType() == Ethernet.TYPE_ARP) {
        arpCounter.inc();

    } else if (ethPkt.getEtherType() == Ethernet.TYPE_LLDP) {
        lldpCounter.inc();

    } else if (ethPkt.getEtherType() == Ethernet.TYPE_VLAN) {
        vlanCounter.inc();

    } else if (ethPkt.getEtherType() == Ethernet.TYPE_BSN) {
        bsnCounter.inc();

    } else if (ethPkt.getEtherType() == Ethernet.TYPE_RARP) {
        rarpCounter.inc();

    } else if (ethPkt.getEtherType() == Ethernet.MPLS_UNICAST
            || ethPkt.getEtherType() == Ethernet.MPLS_MULTICAST) {
        mplsCounter.inc();

    } else if (ethPkt.getEtherType() == Ethernet.TYPE_IPV4) {
        IPv4 ipv4Packet = (IPv4) ethPkt.getPayload();
        //Indicates whether this is a TCP Packet
        if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_TCP) {
            tcpCounter.inc();

        } else if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) {
            icmpCounter.inc();

        } else if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_IGMP) {
            igmpCounter.inc();

        } else if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_PIM) {
            pimCounter.inc();

        } else if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_UDP) {
            UDP udpPacket = (UDP) ipv4Packet.getPayload();
                //Indicates whether this packet is a DHCP Packet
                if (udpPacket.getSourcePort() == UDP.DHCP_CLIENT_PORT
                        || udpPacket.getSourcePort() == UDP.DHCP_SERVER_PORT) {
                    dhcpCounter.inc();
                }
            }
    } else if (ethPkt.getEtherType() == Ethernet.TYPE_IPV6) {
           IPv6 ipv6Pkt = (IPv6) ethPkt.getPayload();
           if (ipv6Pkt.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
               icmp6Counter.inc();
               ICMP6 icmpv6 = (ICMP6) ipv6Pkt.getPayload();
               if (icmpv6.getIcmpType() == ICMP6.NEIGHBOR_SOLICITATION) {
                  nbrSolicitCounter.inc();
               } else if (icmpv6.getIcmpType() == ICMP6.NEIGHBOR_ADVERTISEMENT) {
                  nbrAdvertCounter.inc();
               }
           }
    } else {
            log.debug("Packet is unknown.");
            unknownCounter.inc();
    }
}