API for LLDP, NS, NA, ARP counter added in Packet stats app
Change-Id: If49f35d2fb302496f59e095a2ae6062ca48108ad
diff --git a/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/PacketStatistics.java b/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/PacketStatistics.java
new file mode 100644
index 0000000..ad3074e
--- /dev/null
+++ b/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/PacketStatistics.java
@@ -0,0 +1,252 @@
+/*
+ * Copyright 2014-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.packetstats;
+import com.codahale.metrics.Counter;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.onlab.packet.Ethernet;
+import org.onlab.packet.IPv4;
+import org.onlab.packet.IPv6;
+import org.onlab.packet.ICMP6;
+import org.onlab.packet.UDP;
+import org.onosproject.cfg.ComponentConfigService;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.flow.FlowRuleService;
+import org.onosproject.net.packet.InboundPacket;
+import org.onosproject.net.packet.PacketContext;
+import org.onosproject.net.packet.PacketProcessor;
+import org.onosproject.net.packet.PacketService;
+
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import static org.slf4j.LoggerFactory.getLogger;
+import org.onlab.metrics.MetricsComponent;
+import org.onlab.metrics.MetricsFeature;
+import org.onlab.metrics.MetricsService;
+
+/**
+ * Application for Packet Statistics.
+ */
+@Component(immediate = true)
+public class PacketStatistics {
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY)
+ protected PacketService packetService;
+
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY)
+ protected FlowRuleService flowRuleService;
+
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY)
+ protected ComponentConfigService cfgService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY)
+ protected MetricsService metricService;
+
+ private PacketCounter processor = new PacketCounter();
+ private final Logger log = getLogger(getClass());
+
+ private ApplicationId appId;
+
+
+ private MetricsComponent packetStatisticsComponent;
+ private MetricsFeature arpFeature;
+ private Counter arpCounter;
+ private MetricsFeature dhcpFeature;
+ private Counter dhcpCounter;
+ private MetricsFeature lldpFeature;
+ private Counter lldpCounter;
+ private MetricsFeature vlanFeature;
+ private Counter vlanCounter;
+ private MetricsFeature tcpFeature;
+ private Counter tcpCounter;
+ private MetricsFeature icmpFeature;
+ private Counter icmpCounter;
+ private MetricsFeature icmp6Feature;
+ private Counter icmp6Counter;
+ private MetricsFeature nbrSolicitFeature;
+ private Counter nbrSolicitCounter;
+ private MetricsFeature nbrAdvertFeature;
+ private Counter nbrAdvertCounter;
+ private MetricsFeature igmpFeature;
+ private Counter igmpCounter;
+ private MetricsFeature pimFeature;
+ private Counter pimCounter;
+ private MetricsFeature bsnFeature;
+ private Counter bsnCounter;
+ private MetricsFeature rarpFeature;
+ private Counter rarpCounter;
+ private MetricsFeature mplsFeature;
+ private Counter mplsCounter;
+ private MetricsFeature unknownFeature;
+ private Counter unknownCounter;
+
+ @Activate
+ public void activate(ComponentContext context) {
+ this.packetStatisticsComponent =
+ metricService.registerComponent("packetStatisticsComponent");
+ this.arpFeature =
+ packetStatisticsComponent.registerFeature("arpFeature");
+ this.dhcpFeature =
+ packetStatisticsComponent.registerFeature("dhcpFeature");
+ this.lldpFeature =
+ packetStatisticsComponent.registerFeature("lldpFeature");
+ this.vlanFeature =
+ packetStatisticsComponent.registerFeature("vlanFeature");
+ this.tcpFeature =
+ packetStatisticsComponent.registerFeature("tcpFeature");
+ this.icmpFeature =
+ packetStatisticsComponent.registerFeature("icmpFeature");
+ this.icmp6Feature =
+ packetStatisticsComponent.registerFeature("icmp6Feature");
+ this.nbrSolicitFeature =
+ packetStatisticsComponent.registerFeature("nbrSolicitFeature");
+ this.nbrAdvertFeature =
+ packetStatisticsComponent.registerFeature("nbrAdvertFeature");
+ this.igmpFeature =
+ packetStatisticsComponent.registerFeature("igmpFeature");
+ this.pimFeature =
+ packetStatisticsComponent.registerFeature("pimFeature");
+ this.bsnFeature =
+ packetStatisticsComponent.registerFeature("bsnFeature");
+ this.rarpFeature =
+ packetStatisticsComponent.registerFeature("rarpFeature");
+ this.mplsFeature =
+ packetStatisticsComponent.registerFeature("mplsFeature");
+ this.unknownFeature =
+ packetStatisticsComponent.registerFeature("unknownFeature");
+ this.arpCounter =
+ metricService.createCounter(packetStatisticsComponent, arpFeature, "arpPC");
+ this.dhcpCounter =
+ metricService.createCounter(packetStatisticsComponent, dhcpFeature, "dhcpPC");
+ this.lldpCounter =
+ metricService.createCounter(packetStatisticsComponent, lldpFeature, "lldpPC");
+ this.vlanCounter =
+ metricService.createCounter(packetStatisticsComponent, vlanFeature, "vlanPC");
+ this.icmpCounter =
+ metricService.createCounter(packetStatisticsComponent, icmpFeature, "icmpPC");
+ this.icmp6Counter =
+ metricService.createCounter(packetStatisticsComponent, icmp6Feature, "icmp6PC");
+ this.nbrSolicitCounter =
+ metricService.createCounter(packetStatisticsComponent, nbrSolicitFeature, "nbrSolicitPC");
+ this.nbrAdvertCounter =
+ metricService.createCounter(packetStatisticsComponent, nbrAdvertFeature, "nbrAdvertPC");
+ this.igmpCounter =
+ metricService.createCounter(packetStatisticsComponent, igmpFeature, "igmpPC");
+ this.pimCounter =
+ metricService.createCounter(packetStatisticsComponent, pimFeature, "pimPC");
+ this.bsnCounter =
+ metricService.createCounter(packetStatisticsComponent, bsnFeature, "bsnPC");
+ this.mplsCounter =
+ metricService.createCounter(packetStatisticsComponent, mplsFeature, "mplsPC");
+ this.unknownCounter =
+ metricService.createCounter(packetStatisticsComponent, unknownFeature, "unknownPC");
+
+ appId = coreService.registerApplication("org.onosproject.packet-stats");
+
+ packetService.addProcessor(processor, PacketProcessor.director(0));
+ log.info("Started", appId.id());
+ }
+
+ @Deactivate
+ public void deactivate() {
+ cfgService.unregisterProperties(getClass(), false);
+ flowRuleService.removeFlowRulesById(appId);
+ packetService.removeProcessor(processor);
+ processor = null;
+ log.info("Stopped");
+ }
+
+
+ /**
+ * Packet processor responsible for counting various types of packets.
+ */
+ private class PacketCounter implements PacketProcessor {
+ @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();
+ }
+ }
+ }
+}
diff --git a/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/PacketStatsUiComponent.java b/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/PacketStatsUiComponent.java
new file mode 100644
index 0000000..e9982a2
--- /dev/null
+++ b/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/PacketStatsUiComponent.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2016-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.packetstats;
+
+
+import com.google.common.collect.ImmutableList;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.onosproject.ui.UiExtension;
+import org.onosproject.ui.UiExtensionService;
+import org.onosproject.ui.UiMessageHandlerFactory;
+import org.onosproject.ui.UiView;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+/**
+ * ONOS UI Custom-View application component for the Packet Statistics Application.
+ */
+@Component(immediate = true)
+public class PacketStatsUiComponent {
+ private static final String VIEW_ID = "sampleCustom";
+ private static final String VIEW_TEXT = "Packet Statistics Application";
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY)
+ protected UiExtensionService uiExtensionService;
+
+ // List of application views
+ private final List<UiView> uiViews = ImmutableList.of(
+ new UiView(UiView.Category.OTHER, VIEW_ID, VIEW_TEXT)
+ );
+
+
+ // Factory for UI message handlers
+ private final UiMessageHandlerFactory messageHandlerFactory =
+ () -> ImmutableList.of(new PacketStatsUiMessageHandler());
+
+
+ // Application UI extension
+ protected UiExtension extension =
+ new UiExtension.Builder(getClass().getClassLoader(), uiViews)
+ .resourcePath(VIEW_ID)
+ .messageHandlerFactory(messageHandlerFactory)
+ .build();
+
+ @Activate
+ protected void activate() {
+ uiExtensionService.register(extension);
+ log.info("Started");
+ }
+
+ @Deactivate
+ protected void deactivate() {
+ uiExtensionService.unregister(extension);
+ log.info("Stopped");
+ }
+
+}
diff --git a/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/PacketStatsUiMessageHandler.java b/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/PacketStatsUiMessageHandler.java
new file mode 100644
index 0000000..a13c543
--- /dev/null
+++ b/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/PacketStatsUiMessageHandler.java
@@ -0,0 +1,274 @@
+/*
+ * Copyright 2016-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.packetstats;
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.MetricFilter;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.ImmutableSet;
+import org.onosproject.net.ConnectPoint;
+import org.onlab.metrics.MetricsService;
+import org.onosproject.ui.RequestHandler;
+import org.onosproject.ui.UiMessageHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * ONOS UI Custom-View message handler.
+ * <p>
+ * This class contains the request handlers that handle the response
+ * to each event. In this particular implementation the second message
+ * handler creates the patch and the first message handler loads the data.
+ */
+
+public class PacketStatsUiMessageHandler extends UiMessageHandler {
+
+ private static final String ARP_REQ = "arpRequest";
+ private static final String ARP_RESP = "arpResponse";
+ private static final String DHCP_REQ = "dhcpRequest";
+ private static final String DHCP_RESP = "dhcpResponse";
+ private static final String ICMP_REQ = "icmpRequest";
+ private static final String ICMP_RESP = "icmpResponse";
+ private static final String LLDP_REQ = "lldpRequest";
+ private static final String LLDP_RESP = "lldpResponse";
+ private static final String VLAN_REQ = "vlanRequest";
+ private static final String VLAN_RESP = "vlanResponse";
+ private static final String IGMP_REQ = "igmpRequest";
+ private static final String IGMP_RESP = "igmpResponse";
+ private static final String PIM_REQ = "pimRequest";
+ private static final String PIM_RESP = "pimResponse";
+ private static final String BSN_REQ = "bsnRequest";
+ private static final String BSN_RESP = "bsnResponse";
+ private static final String UNKNOWN_REQ = "unknownRequest";
+ private static final String UNKNOWN_RESP = "unknownResponse";
+ private static final String MPLS_REQ = "mplsRequest";
+ private static final String MPLS_RESP = "mplsResponse";
+
+
+
+
+ private static final String METRIC_NAME = null;
+ private static String total = "";
+
+ private List<ConnectPoint> previous = new ArrayList<>();
+ private final Logger log = LoggerFactory.getLogger(getClass());
+ MetricFilter filter = METRIC_NAME != null ? (name, metric) -> name.equals(METRIC_NAME) : MetricFilter.ALL;
+
+ @Override
+ protected Collection<RequestHandler> createRequestHandlers() {
+ return ImmutableSet.of(
+ new ArpRequestHandler(),
+ new DhcpRequestHandler(),
+ new IcmpRequestHandler(),
+ new LldpRequestHandler(),
+ new VlanRequestHandler(),
+ new IgmpRequestHandler(),
+ new PimRequestHandler(),
+ new BsnRequestHandler(),
+ new UnknownRequestHandler(),
+ new MplsRequestHandler()
+
+ );
+
+ }
+
+ //Looking for ARP Packets
+ private final class ArpRequestHandler extends RequestHandler {
+ private ArpRequestHandler() {
+ super(ARP_REQ);
+ }
+
+ @Override
+ public void process(ObjectNode payload) {
+ MetricsService service = get(MetricsService.class);
+ Map<String, Counter> counters = service.getCounters(filter);
+ Counter arpCounter = counters.get("packetStatisticsComponent.arpFeature.arpPC");
+ long arpCount = arpCounter.getCount();
+ ObjectNode arpJson = objectNode();
+ arpJson.put("ArpCounter", arpCount);
+ sendMessage(ARP_RESP, arpJson);
+ }
+ }
+
+ //Looking for DHCP Packets
+ private final class DhcpRequestHandler extends RequestHandler {
+ private DhcpRequestHandler() {
+ super(DHCP_REQ);
+ }
+
+ @Override
+ public void process(ObjectNode payload) {
+ MetricsService service = get(MetricsService.class);
+ Map<String, Counter> counters = service.getCounters(filter);
+ Counter dhcpCounter = counters.get("packetStatisticsComponent.dhcpFeature.dhcpPC");
+ long dhcpCount = dhcpCounter.getCount();
+ ObjectNode dhcpJson = objectNode();
+ dhcpJson.put("DhcpCounter", dhcpCount);
+ log.info("Received DHCP Request");
+ sendMessage(DHCP_RESP, dhcpJson);
+ }
+ }
+ //Looking for ICMP Packets
+ private final class IcmpRequestHandler extends RequestHandler {
+ private IcmpRequestHandler() {
+ super(ICMP_REQ);
+ }
+
+ @Override
+ public void process(ObjectNode payload) {
+ MetricsService service = get(MetricsService.class);
+ Map<String, Counter> counters = service.getCounters(filter);
+ Counter icmpCounter = counters.get("packetStatisticsComponent.icmpFeature.icmpPC");
+ long icmpCount = icmpCounter.getCount();
+ ObjectNode icmpJson = objectNode();
+ icmpJson.put("IcmpCounter", icmpCount);
+ log.info("Received ICMP Request");
+ sendMessage(ICMP_RESP, icmpJson);
+ }
+ }
+ //Looking for LLDP Packets
+ private final class LldpRequestHandler extends RequestHandler {
+ private LldpRequestHandler() {
+ super(LLDP_REQ);
+ }
+
+ @Override
+ public void process(ObjectNode payload) {
+ MetricsService service = get(MetricsService.class);
+ Map<String, Counter> counters = service.getCounters(filter);
+ Counter lldpCounter = counters.get("packetStatisticsComponent.lldpFeature.lldpPC");
+ long lldpCount = lldpCounter.getCount();
+ ObjectNode lldpJson = objectNode();
+ lldpJson.put("LldpCounter", lldpCount);
+ log.info("Received LLDP Request");
+ sendMessage(LLDP_RESP, lldpJson);
+ }
+ }
+ //Looking for VLAN Packets
+ private final class VlanRequestHandler extends RequestHandler {
+ private VlanRequestHandler() {
+ super(VLAN_REQ);
+ }
+
+ @Override
+ public void process(ObjectNode payload) {
+ MetricsService service = get(MetricsService.class);
+ Map<String, Counter> counters = service.getCounters(filter);
+ Counter vlanCounter = counters.get("packetStatisticsComponent.vlanFeature.vlanPC");
+ long vlanCount = vlanCounter.getCount();
+ ObjectNode vlanJson = objectNode();
+ vlanJson.put("VlanCounter", vlanCount);
+ log.info("Received VLAN Request");
+ sendMessage(VLAN_RESP, vlanJson);
+ }
+ }
+ //Looking for IGMP Packets
+ private final class IgmpRequestHandler extends RequestHandler {
+ private IgmpRequestHandler() {
+ super(IGMP_REQ);
+ }
+
+ @Override
+ public void process(ObjectNode payload) {
+ MetricsService service = get(MetricsService.class);
+ Map<String, Counter> counters = service.getCounters(filter);
+ Counter igmpCounter = counters.get("packetStatisticsComponent.igmpFeature.igmpPC");
+ long igmpCount = igmpCounter.getCount();
+ ObjectNode igmpJson = objectNode();
+ igmpJson.put("IgmpCounter", igmpCount);
+ log.info("Received IGMP Request");
+ sendMessage(IGMP_RESP, igmpJson);
+ }
+ }
+ //Looking for PIM Packets
+ private final class PimRequestHandler extends RequestHandler {
+ private PimRequestHandler() {
+ super(PIM_REQ);
+ }
+
+ @Override
+ public void process(ObjectNode payload) {
+ MetricsService service = get(MetricsService.class);
+ Map<String, Counter> counters = service.getCounters(filter);
+ Counter pimCounter = counters.get("packetStatisticsComponent.pimFeature.pimPC");
+ long pimCount = pimCounter.getCount();
+ ObjectNode pimJson = objectNode();
+ pimJson.put("PimCounter", pimCount);
+ log.info("Received PIM Request");
+ sendMessage(PIM_RESP, pimJson);
+ }
+ }
+ //Looking for PIM Packets
+ private final class BsnRequestHandler extends RequestHandler {
+ private BsnRequestHandler() {
+ super(BSN_REQ);
+ }
+
+ @Override
+ public void process(ObjectNode payload) {
+ MetricsService service = get(MetricsService.class);
+ Map<String, Counter> counters = service.getCounters(filter);
+ Counter bsnCounter = counters.get("packetStatisticsComponent.bsnFeature.bsnPC");
+ long bsnCount = bsnCounter.getCount();
+ ObjectNode bsnJson = objectNode();
+ bsnJson.put("BsnCounter", bsnCount);
+ log.info("Received BSN Request");
+ sendMessage(BSN_RESP, bsnJson);
+ }
+ }
+ //Looking for PIM Packets
+ private final class UnknownRequestHandler extends RequestHandler {
+ private UnknownRequestHandler() {
+ super(UNKNOWN_REQ);
+ }
+
+ @Override
+ public void process(ObjectNode payload) {
+ MetricsService service = get(MetricsService.class);
+ Map<String, Counter> counters = service.getCounters(filter);
+ Counter unknownCounter = counters.get("packetStatisticsComponent.unknownFeature.unknownPC");
+ long unknownCount = unknownCounter.getCount();
+ ObjectNode unknownJson = objectNode();
+ unknownJson.put("UnknownCounter", unknownCount);
+ log.info("Received UNKNOWN Request");
+ sendMessage(UNKNOWN_RESP, unknownJson);
+ }
+ }
+ //Looking for PIM Packets
+ private final class MplsRequestHandler extends RequestHandler {
+ private MplsRequestHandler() {
+ super(MPLS_REQ);
+ }
+
+ @Override
+ public void process(ObjectNode payload) {
+ MetricsService service = get(MetricsService.class);
+ Map<String, Counter> counters = service.getCounters(filter);
+ Counter mplsCounter = counters.get("packetStatisticsComponent.mplsFeature.mplsPC");
+ long mplsCount = mplsCounter.getCount();
+ ObjectNode mplsJson = objectNode();
+ mplsJson.put("MplsCounter", mplsCount);
+ log.info("Received MPLS Request");
+ sendMessage(MPLS_RESP, mplsJson);
+ }
+ }
+
+
+}
\ No newline at end of file
diff --git a/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/cli/PacketStatisticsShowCommand.java b/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/cli/PacketStatisticsShowCommand.java
new file mode 100644
index 0000000..9e44bd4
--- /dev/null
+++ b/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/cli/PacketStatisticsShowCommand.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2016-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.packetstats.cli;
+
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.MetricFilter;
+import org.apache.karaf.shell.api.action.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onlab.metrics.MetricsService;
+import java.util.Map;
+/**
+ * Displays the entries.
+ */
+@Command(scope = "onos", name = "pkt-stats-show", description = "Displays the packet statistics values")
+public class PacketStatisticsShowCommand extends AbstractShellCommand {
+
+ private static final String METRIC_NAME = null;
+ private static final String FORMAT = "PacketType = %s, Count = %s";
+ private static final String FORMAT_LLDP = "Device = %s, Count = %s";
+ MetricFilter filter = METRIC_NAME != null ? (name, metric) -> name.equals(METRIC_NAME) : MetricFilter.ALL;
+
+
+ @Override
+ protected void doExecute() {
+ MetricsService service = get(MetricsService.class);
+ Map<String, Counter> counters = service.getCounters(filter);
+
+ Counter arpCounter = counters.get("packetStatisticsComponent.arpFeature.arpPC");
+ Counter lldpCounter = counters.get("packetStatisticsComponent.lldpFeature.lldpPC");
+ Counter nsCounter = counters.get("packetStatisticsComponent.nbrSolicitFeature.nbrSolicitPC");
+ Counter naCounter = counters.get("packetStatisticsComponent.nbrAdvertFeature.nbrAdvertPC");
+
+ print(FORMAT, "ARP ", arpCounter.getCount());
+ print(FORMAT, "LLDP ", lldpCounter.getCount());
+ print(FORMAT, "Neighbor Solicitation ", nsCounter.getCount());
+ print(FORMAT, "Neighbor Advertisement ", naCounter.getCount());
+
+ }
+
+}
diff --git a/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/cli/package-info.java b/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/cli/package-info.java
new file mode 100644
index 0000000..5b37086
--- /dev/null
+++ b/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/cli/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2014-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Sample application that provides simple packet statistics.
+ */
+package org.onosproject.packetstats.cli;
diff --git a/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/package-info.java b/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/package-info.java
new file mode 100644
index 0000000..54a806c
--- /dev/null
+++ b/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2014-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Sample application that provides simple packet statistics.
+ */
+package org.onosproject.packetstats;