REST API added in Packet stats app

Packet Stats Rest API onos-1.13 Cherry pick

Change-Id: I09293aefef9e1b17359e02f4b703808f10b8fb19
diff --git a/apps/packet-stats/BUCK b/apps/packet-stats/BUCK
index e3cf58e..83e771d 100644
--- a/apps/packet-stats/BUCK
+++ b/apps/packet-stats/BUCK
@@ -1,21 +1,15 @@
-COMPILE_DEPS = [
-    '//lib:CORE_DEPS',
-    '//lib:JACKSON',
-    '//lib:METRICS',
-    '//core/store/serializers:onos-core-serializers',
-    '//core/store/primitives:onos-core-primitives',
-    '//core/api:onos-api',
-    '//lib:org.apache.karaf.shell.console',
-    '//cli:onos-cli',
+BUNDLES = [
+    '//apps/packet-stats/app:onos-apps-packet-stats-app',
+    '//apps/packet-stats/web:onos-apps-packet-stats-web',
 ]
 
-osgi_jar_with_tests (
-    deps = COMPILE_DEPS,
-)
+
 
 onos_app (
+    app_name = "org.onosproject.packet-stats",
     title = 'Packet Statistics',
-    category = 'Traffic Steering',
-    url = 'http://onosproject.org',
-    description = 'Application to calculate the number of packets of different types',
+    category = "Utility",
+    description = " Application to calculate the number of packets of different types",
+    included_bundles = BUNDLES,
+    url = "http://onosproject.org",
 )
diff --git a/apps/packet-stats/app/BUCK b/apps/packet-stats/app/BUCK
new file mode 100644
index 0000000..31ef351
--- /dev/null
+++ b/apps/packet-stats/app/BUCK
@@ -0,0 +1,12 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//lib:JACKSON',
+    '//lib:METRICS',
+    '//lib:org.apache.karaf.shell.console',
+    '//cli:onos-cli',
+]
+
+osgi_jar_with_tests (
+
+    deps = COMPILE_DEPS,
+)
diff --git a/apps/packet-stats/app/pom.xml b/apps/packet-stats/app/pom.xml
new file mode 100644
index 0000000..cbc6574
--- /dev/null
+++ b/apps/packet-stats/app/pom.xml
@@ -0,0 +1,181 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2017-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.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>onos-apps-packet-stats</artifactId>
+        <groupId>org.onosproject</groupId>
+        <version>1.13.8-SNAPSHOT</version>
+    </parent>
+
+    <groupId>org.onosproject</groupId>
+    <artifactId>onos-apps-packet-stats-app</artifactId>
+    <version>1.13.8-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+
+    <description>ONOS OSGi bundle archetype</description>
+    <url>http://onosproject.org</url>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <onos.version>1.13.8-SNAPSHOT</onos.version>
+        <onos.app.name>org.onosproject.packetstats</onos.app.name>
+        <onos.app.title>onos-apps-packet-stats-app</onos.app.title>
+        <onos.app.origin>Raleigh, NC Comcast</onos.app.origin>
+        <onos.app.category>protocols</onos.app.category>
+        <onos.app.url>http://onosproject.org</onos.app.url>
+        <onos.app.readme>ONOS OSGi bundle archetype.</onos.app.readme>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-incubator-api</artifactId>
+            <version>1.9.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onlab-osgi</artifactId>
+            <version>${onos.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.12</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-cli</artifactId>
+            <version>${onos.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-apps-route-service-app</artifactId>
+            <version>${onos.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onlab-misc</artifactId>
+            <version>${onos.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>5.0.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.karaf.shell</groupId>
+            <artifactId>org.apache.karaf.shell.console</artifactId>
+            <version>3.0.8</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymock</artifactId>
+            <version>3.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+            <version>1.9.12</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-core-serializers</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-apps-route-service-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>3.0.1</version>
+                <extensions>true</extensions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>2.5.1</version>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+                <version>1.21.0</version>
+                <executions>
+                    <execution>
+                        <id>generate-scr-srcdescriptor</id>
+                        <goals>
+                            <goal>scr</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <supportedProjectTypes>
+                        <supportedProjectType>bundle</supportedProjectType>
+                        <supportedProjectType>war</supportedProjectType>
+                    </supportedProjectTypes>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.onosproject</groupId>
+                <artifactId>onos-maven-plugin</artifactId>
+                <version>1.10</version>
+                <executions>
+                    <execution>
+                        <id>cfg</id>
+                        <phase>generate-resources</phase>
+                        <goals>
+                            <goal>cfg</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>swagger</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>swagger</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>app</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>app</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/apps/packet-stats/src/main/java/org/onosproject/packetstats/PacketStatistics.java b/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/PacketStatistics.java
similarity index 81%
rename from apps/packet-stats/src/main/java/org/onosproject/packetstats/PacketStatistics.java
rename to apps/packet-stats/app/src/main/java/org/onosproject/packetstats/PacketStatistics.java
index 6d3f77f..abf0f0e 100644
--- a/apps/packet-stats/src/main/java/org/onosproject/packetstats/PacketStatistics.java
+++ b/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/PacketStatistics.java
@@ -23,6 +23,8 @@
 import org.apache.felix.scr.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;
@@ -63,7 +65,7 @@
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected MetricsService metricService;
 
-    private ReactivePacketProcessor processor = new ReactivePacketProcessor();
+    private PacketCounter processor = new PacketCounter();
     private final Logger log = getLogger(getClass());
 
     private ApplicationId appId;
@@ -82,6 +84,12 @@
     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;
@@ -95,8 +103,6 @@
     private MetricsFeature unknownFeature;
     private Counter unknownCounter;
 
-
-
     @Activate
     public void activate(ComponentContext context) {
         this.packetStatisticsComponent =
@@ -113,6 +119,12 @@
                 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 =
@@ -135,6 +147,12 @@
                 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 =
@@ -146,13 +164,10 @@
         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
@@ -166,9 +181,9 @@
 
 
     /**
-     * Packet processor responsible for forwarding packets along their paths.
+     * Packet processor responsible for counting various types of packets.
      */
-    private class ReactivePacketProcessor implements PacketProcessor {
+    private class PacketCounter implements PacketProcessor {
         @Override
         public void process(PacketContext context) {
             InboundPacket pkt = context.inPacket();
@@ -217,12 +232,21 @@
                             dhcpCounter.inc();
                         }
                     }
-
-                } else {
-                    log.info("Packet is unknown.");
-                    unknownCounter.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();
             }
-            }
-
-        }
\ No newline at end of file
+        }
+    }
+}
\ No newline at end of file
diff --git a/apps/packet-stats/src/main/java/org/onosproject/packetstats/PacketStatsUiComponent.java b/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/PacketStatsUiComponent.java
similarity index 100%
rename from apps/packet-stats/src/main/java/org/onosproject/packetstats/PacketStatsUiComponent.java
rename to apps/packet-stats/app/src/main/java/org/onosproject/packetstats/PacketStatsUiComponent.java
diff --git a/apps/packet-stats/src/main/java/org/onosproject/packetstats/PacketStatsUiMessageHandler.java b/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/PacketStatsUiMessageHandler.java
similarity index 100%
rename from apps/packet-stats/src/main/java/org/onosproject/packetstats/PacketStatsUiMessageHandler.java
rename to apps/packet-stats/app/src/main/java/org/onosproject/packetstats/PacketStatsUiMessageHandler.java
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..932d37c
--- /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.commands.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 execute() {
+            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/src/main/java/org/onosproject/packetstats/package-info.java b/apps/packet-stats/app/src/main/java/org/onosproject/packetstats/package-info.java
similarity index 100%
rename from apps/packet-stats/src/main/java/org/onosproject/packetstats/package-info.java
rename to apps/packet-stats/app/src/main/java/org/onosproject/packetstats/package-info.java
diff --git a/apps/packet-stats/app/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/apps/packet-stats/app/src/main/resources/OSGI-INF/blueprint/shell-config.xml
new file mode 100644
index 0000000..af51080
--- /dev/null
+++ b/apps/packet-stats/app/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -0,0 +1,23 @@
+<!--
+  ~ 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.
+  -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+    <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
+        <command>
+            <action class="org.onosproject.packetstats.cli.PacketStatisticsShowCommand"/>
+        </command>
+    </command-bundle>
+</blueprint>
diff --git a/apps/packet-stats/src/main/resources/app/view/sampleCustom/sampleCustom.css b/apps/packet-stats/app/src/main/resources/app/view/sampleCustom/sampleCustom.css
similarity index 100%
rename from apps/packet-stats/src/main/resources/app/view/sampleCustom/sampleCustom.css
rename to apps/packet-stats/app/src/main/resources/app/view/sampleCustom/sampleCustom.css
diff --git a/apps/packet-stats/src/main/resources/app/view/sampleCustom/sampleCustom.html b/apps/packet-stats/app/src/main/resources/app/view/sampleCustom/sampleCustom.html
similarity index 100%
rename from apps/packet-stats/src/main/resources/app/view/sampleCustom/sampleCustom.html
rename to apps/packet-stats/app/src/main/resources/app/view/sampleCustom/sampleCustom.html
diff --git a/apps/packet-stats/src/main/resources/app/view/sampleCustom/sampleCustom.js b/apps/packet-stats/app/src/main/resources/app/view/sampleCustom/sampleCustom.js
similarity index 100%
rename from apps/packet-stats/src/main/resources/app/view/sampleCustom/sampleCustom.js
rename to apps/packet-stats/app/src/main/resources/app/view/sampleCustom/sampleCustom.js
diff --git a/apps/packet-stats/src/main/resources/sampleCustom/css.html b/apps/packet-stats/app/src/main/resources/sampleCustom/css.html
similarity index 100%
rename from apps/packet-stats/src/main/resources/sampleCustom/css.html
rename to apps/packet-stats/app/src/main/resources/sampleCustom/css.html
diff --git a/apps/packet-stats/src/main/resources/sampleCustom/js.html b/apps/packet-stats/app/src/main/resources/sampleCustom/js.html
similarity index 100%
rename from apps/packet-stats/src/main/resources/sampleCustom/js.html
rename to apps/packet-stats/app/src/main/resources/sampleCustom/js.html
diff --git a/apps/packet-stats/pom.xml b/apps/packet-stats/pom.xml
index d78832b..33a83cf 100644
--- a/apps/packet-stats/pom.xml
+++ b/apps/packet-stats/pom.xml
@@ -1,75 +1,37 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-  ~ 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.
-  -->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ ~ Copyright 2017 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.
+ --><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
-
     <parent>
-        <groupId>org.onosproject</groupId>
         <artifactId>onos-apps</artifactId>
         <version>1.13.8-SNAPSHOT</version>
+        <groupId>org.onosproject</groupId>
+        <relativePath>../pom.xml</relativePath>
     </parent>
 
-    <artifactId>onos-app-packet-stats</artifactId>
+    <groupId>org.onosproject</groupId>
+    <artifactId>onos-apps-packet-stats</artifactId>
+    <version>1.13.8-SNAPSHOT</version>
     <packaging>bundle</packaging>
 
-    <description>Packet Statistics application using flow subsystem</description>
+    <description>ONOS OSGi bundle archetype</description>
+    <url>http://onosproject.org</url>
 
-    <properties>
-        <onos.app.name>org.onosproject.packet-stats</onos.app.name>
-        <onos.app.title>Packet Statistics App</onos.app.title>
-        <onos.app.category>Traffic Steering</onos.app.category>
-        <onos.app.url>http://onosproject.org</onos.app.url>
-        <onos.app.readme>Packet Statistics application using flow subsystem.</onos.app.readme>
-    </properties>
-
-    <dependencies>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.compendium</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.onosproject</groupId>
-            <artifactId>onos-core-serializers</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.onosproject</groupId>
-            <artifactId>onos-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.onosproject</groupId>
-            <artifactId>onos-core-primitives</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.onosproject</groupId>
-            <artifactId>onos-cli</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.karaf.shell</groupId>
-            <artifactId>org.apache.karaf.shell.console</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr.annotations</artifactId>
-        </dependency>
-    </dependencies>
-
+    <modules>
+        <module>app</module>
+        <module>web</module>
+    </modules>
 </project>
diff --git a/apps/packet-stats/web/BUCK b/apps/packet-stats/web/BUCK
new file mode 100644
index 0000000..ed375d5
--- /dev/null
+++ b/apps/packet-stats/web/BUCK
@@ -0,0 +1,16 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//lib:JACKSON',
+    '//utils/rest:onlab-rest',
+    '//lib:javax.ws.rs-api',
+    '//lib:METRICS',
+]
+
+osgi_jar (
+   deps = COMPILE_DEPS,
+   web_context = '/onos/v1/packet-stats',
+   api_title = 'Packet Stats API',
+   api_version = '1.0',
+   api_description = 'REST API for Packet Stats',
+   api_package = 'org.onosproject.packetstats.web',
+)
diff --git a/apps/packet-stats/web/pom.xml b/apps/packet-stats/web/pom.xml
new file mode 100644
index 0000000..6498a48
--- /dev/null
+++ b/apps/packet-stats/web/pom.xml
@@ -0,0 +1,167 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2018-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.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.onosproject</groupId>
+        <artifactId>onos-apps-packet-stats</artifactId>
+        <version>1.13.8-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>onos-apps-packet-stats-web</artifactId>
+    <packaging>bundle</packaging>
+
+    <properties>
+        <web.context>/onos/v1/packet-stats</web.context>
+        <api.version>1.0.0</api.version>
+        <api.title>ONOS REST API for Packet Stats</api.title>
+        <api.description>
+            APIs for interacting with the Packet Stats.
+        </api.description>
+        <api.package>org.onosproject.packetstats.web</api.package>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-incubator-api</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-apps-packet-stats-app</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onlab-junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-api</artifactId>
+            <scope>test</scope>
+            <classifier>tests</classifier>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.karaf.shell</groupId>
+            <artifactId>org.apache.karaf.shell.console</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-core-serializers</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-cli</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-apps-route-service-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-apps-route-service-api</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+            <classifier>tests</classifier>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>3.0.1</version>
+                <extensions>true</extensions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>2.5.1</version>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+                <version>1.21.0</version>
+                <executions>
+                    <execution>
+                        <id>generate-scr-srcdescriptor</id>
+                        <goals>
+                            <goal>scr</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <supportedProjectTypes>
+                        <supportedProjectType>bundle</supportedProjectType>
+                        <supportedProjectType>war</supportedProjectType>
+                    </supportedProjectTypes>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.onosproject</groupId>
+                <artifactId>onos-maven-plugin</artifactId>
+                <version>1.10</version>
+                <executions>
+                    <execution>
+                        <id>cfg</id>
+                        <phase>generate-resources</phase>
+                        <goals>
+                            <goal>cfg</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>swagger</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>swagger</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>app</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>app</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/apps/packet-stats/web/src/main/java/org/onosproject/packetstats/web/PacketStatsWebApplication.java b/apps/packet-stats/web/src/main/java/org/onosproject/packetstats/web/PacketStatsWebApplication.java
new file mode 100644
index 0000000..8ffc5c9
--- /dev/null
+++ b/apps/packet-stats/web/src/main/java/org/onosproject/packetstats/web/PacketStatsWebApplication.java
@@ -0,0 +1,30 @@
+/*
+ * 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.web;
+
+import org.onlab.rest.AbstractWebApplication;
+
+import java.util.Set;
+
+/**
+ * Packet Stats Web application.
+ */
+public class PacketStatsWebApplication extends AbstractWebApplication {
+    @Override
+    public Set<Class<?>> getClasses() {
+        return getClasses(PacketStatsWebResource.class);
+    }
+}
diff --git a/apps/packet-stats/web/src/main/java/org/onosproject/packetstats/web/PacketStatsWebResource.java b/apps/packet-stats/web/src/main/java/org/onosproject/packetstats/web/PacketStatsWebResource.java
new file mode 100644
index 0000000..a698d34
--- /dev/null
+++ b/apps/packet-stats/web/src/main/java/org/onosproject/packetstats/web/PacketStatsWebResource.java
@@ -0,0 +1,65 @@
+/*
+ * 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.web;
+import javax.ws.rs.Path;
+import javax.ws.rs.GET;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.onosproject.rest.AbstractWebResource;
+import com.codahale.metrics.MetricFilter;
+import com.codahale.metrics.Counter;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onlab.metrics.MetricsService;
+import java.util.Map;
+
+/**
+ * Packet Stats REST API.
+ */
+@Path("")
+public class PacketStatsWebResource extends AbstractWebResource {
+    private static final String METRIC_NAME = null;
+    MetricFilter filter = METRIC_NAME != null ? (name, metric) -> name.equals(METRIC_NAME) : MetricFilter.ALL;
+
+    @GET
+    @Path("counters")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response packetStatsCounters() {
+        ObjectNode node = getPacketStatsCountersJson();
+        return Response.status(200).entity(node).build();
+    }
+
+    private ObjectNode getPacketStatsCountersJson() {
+        MetricsService service = get(MetricsService.class);
+        ObjectNode node = mapper().createObjectNode();
+        ObjectNode pktCounterNode = mapper().createObjectNode();
+        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");
+
+        pktCounterNode.put("arpCounter", arpCounter.getCount());
+        pktCounterNode.put("lldpCounter", lldpCounter.getCount());
+        pktCounterNode.put("nsCounter", nsCounter.getCount());
+        pktCounterNode.put("naCounter", naCounter.getCount());
+
+        node.put("packet_stats_counters", pktCounterNode);
+        return node;
+
+    }
+}
diff --git a/apps/packet-stats/web/src/main/java/org/onosproject/packetstats/web/package-info.java b/apps/packet-stats/web/src/main/java/org/onosproject/packetstats/web/package-info.java
new file mode 100644
index 0000000..22cd3ed
--- /dev/null
+++ b/apps/packet-stats/web/src/main/java/org/onosproject/packetstats/web/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.
+ */
+
+/**
+ * Packet Stats REST API.
+ */
+package org.onosproject.packetstats.web;
diff --git a/apps/packet-stats/web/src/main/webapp/WEB-INF/web.xml b/apps/packet-stats/web/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..ebdaf54
--- /dev/null
+++ b/apps/packet-stats/web/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2018-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.
+  -->
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xmlns="http://java.sun.com/xml/ns/javaee"
+         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+         id="ONOS" version="2.5">
+    <display-name>PACKET STATS REST API v1.0</display-name>
+
+    <security-constraint>
+        <web-resource-collection>
+            <web-resource-name>Secured</web-resource-name>
+            <url-pattern>/*</url-pattern>
+        </web-resource-collection>
+        <auth-constraint>
+            <role-name>admin</role-name>
+        </auth-constraint>
+    </security-constraint>
+
+    <security-role>
+        <role-name>admin</role-name>
+    </security-role>
+
+    <login-config>
+        <auth-method>BASIC</auth-method>
+        <realm-name>karaf</realm-name>
+    </login-config>
+
+    <servlet>
+        <servlet-name>JAX-RS Service</servlet-name>
+        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+        <init-param>
+            <param-name>javax.ws.rs.Application</param-name>
+            <param-value>org.onosproject.packetstats.web.PacketStatsWebApplication</param-value>
+        </init-param>
+        <load-on-startup>1</load-on-startup>
+    </servlet>
+
+    <servlet-mapping>
+        <servlet-name>JAX-RS Service</servlet-name>
+        <url-pattern>/*</url-pattern>
+    </servlet-mapping>
+</web-app>