Packet Stats Application with GUI Component
Change-Id: Iee1e94e77d55acb4381481dbf4c23927f7cece5a
diff --git a/apps/packet-stats/src/main/java/org/onosproject/packetstats/PacketStatistics.java b/apps/packet-stats/src/main/java/org/onosproject/packetstats/PacketStatistics.java
index 3b09618..f726cbe 100644
--- a/apps/packet-stats/src/main/java/org/onosproject/packetstats/PacketStatistics.java
+++ b/apps/packet-stats/src/main/java/org/onosproject/packetstats/PacketStatistics.java
@@ -10,9 +10,10 @@
* 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
+ * 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.apache.felix.scr.annotations.Activate;
@@ -43,7 +44,7 @@
* Application for Packet Statistics.
*/
@Component(immediate = true)
-public class PacketStatistics {
+public class PacketStatistics {
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected PacketService packetService;
@@ -125,30 +126,30 @@
this.unknownFeature =
packetStatisticsComponent.registerFeature("unknownFeature");
this.arpCounter =
- metricService.createCounter(packetStatisticsComponent, arpFeature, "ARP Packet Counter");
+ metricService.createCounter(packetStatisticsComponent, arpFeature, "arpPC");
this.dhcpCounter =
- metricService.createCounter(packetStatisticsComponent, dhcpFeature, "DHCP Packet Counter");
+ metricService.createCounter(packetStatisticsComponent, dhcpFeature, "dhcpPC");
this.lldpCounter =
- metricService.createCounter(packetStatisticsComponent, lldpFeature, "LLDP Packet Counter");
+ metricService.createCounter(packetStatisticsComponent, lldpFeature, "lldpPC");
this.vlanCounter =
- metricService.createCounter(packetStatisticsComponent, vlanFeature, "VLAN Packet Counter");
+ metricService.createCounter(packetStatisticsComponent, vlanFeature, "vlanPC");
this.icmpCounter =
- metricService.createCounter(packetStatisticsComponent, icmpFeature, "ICMP Packet Counter");
+ metricService.createCounter(packetStatisticsComponent, icmpFeature, "icmpPC");
this.igmpCounter =
- metricService.createCounter(packetStatisticsComponent, igmpFeature, "IGMP Packet Counter");
+ metricService.createCounter(packetStatisticsComponent, igmpFeature, "igmpPC");
this.pimCounter =
- metricService.createCounter(packetStatisticsComponent, pimFeature, "PIM Packet Counter");
+ metricService.createCounter(packetStatisticsComponent, pimFeature, "pimPC");
this.bsnCounter =
- metricService.createCounter(packetStatisticsComponent, bsnFeature, "BSN Packet Counter");
+ metricService.createCounter(packetStatisticsComponent, bsnFeature, "bsnPC");
this.mplsCounter =
- metricService.createCounter(packetStatisticsComponent, bsnFeature, "MPLS Packet Counter");
+ metricService.createCounter(packetStatisticsComponent, mplsFeature, "mplsPC");
this.unknownCounter =
- metricService.createCounter(packetStatisticsComponent, bsnFeature, "Unknown Packet Counter");
+ metricService.createCounter(packetStatisticsComponent, unknownFeature, "unknownPC");
appId = coreService.registerApplication("org.onosproject.packet-stats");
- packetService.addProcessor(processor, PacketProcessor.director(2));
+ packetService.addProcessor(processor, PacketProcessor.director(0));
log.info("Started", appId.id());
diff --git a/apps/packet-stats/src/main/java/org/onosproject/packetstats/PacketStatsUiComponent.java b/apps/packet-stats/src/main/java/org/onosproject/packetstats/PacketStatsUiComponent.java
new file mode 100644
index 0000000..c55c40b
--- /dev/null
+++ b/apps/packet-stats/src/main/java/org/onosproject/packetstats/PacketStatsUiComponent.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.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_UNARY)
+ 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/src/main/java/org/onosproject/packetstats/PacketStatsUiMessageHandler.java b/apps/packet-stats/src/main/java/org/onosproject/packetstats/PacketStatsUiMessageHandler.java
new file mode 100644
index 0000000..418d703
--- /dev/null
+++ b/apps/packet-stats/src/main/java/org/onosproject/packetstats/PacketStatsUiMessageHandler.java
@@ -0,0 +1,274 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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/src/main/resources/app/view/sampleCustom/sampleCustom.css b/apps/packet-stats/src/main/resources/app/view/sampleCustom/sampleCustom.css
new file mode 100644
index 0000000..84f9685
--- /dev/null
+++ b/apps/packet-stats/src/main/resources/app/view/sampleCustom/sampleCustom.css
@@ -0,0 +1,116 @@
+/* css for sample app custom view */
+
+#ov-sample-custom {
+ padding: 20px;
+}
+.light #ov-sample-custom {
+ color: navy;
+}
+.dark #ov-sample-custom {
+ color: #88f;
+}
+
+#ov-sample-custom .button-panel {
+ margin: 10px;
+ width: 200px;
+}
+
+.light #ov-sample-custom .button-panel {
+ background-color: #ccf;
+}
+.dark #ov-sample-custom .button-panel {
+ background-color: #444;
+}
+
+#ov-sample-custom .my-button {
+ cursor: pointer;
+ padding: 4px;
+ text-align: center;
+}
+
+.light #ov-sample-custom .my-button {
+ color: white;
+ background-color: #8b8386;
+}
+.dark #ov-sample-custom .my-button {
+ color: black;
+ background-color: #aaa;
+}
+
+#ov-sample-custom .number {
+ font-size: 140%;
+ text-align: right;
+}
+
+#ov-sample-custom .quote {
+ margin: 10px 20px;
+ font-style: italic;
+}
+
+.bar rect {
+ fill: steelblue;
+}
+
+.bar text {;
+ font: 15px sans-serif;
+}
+
+
+.chart div {
+ font: 10px sans-serif;
+ background-color: steelblue;
+ text-align: right;
+ padding: 3px;
+ margin: 1px;
+ color: white;
+}
+ body {
+ width: 1450px;
+ height: 500px;
+ position: relative;
+ background-color:#DFE5EA;
+ }
+
+ svg {
+ width: 100%;
+ height: 100%;
+ position: center;
+ }
+
+ .toolTip {
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
+ position: absolute;
+ display: none;
+ width: auto;
+ height: auto;
+ background: none repeat scroll 0 0 white;
+ border: 0 none;
+ border-radius: 8px 8px 8px 8px;
+ box-shadow: -3px 3px 15px #888888;
+ color: black;
+ font: 12px sans-serif;
+ padding: 5px;
+ text-align: center;
+ }
+
+ text {
+ font: 17px sans-serif;
+ }
+ text.value {
+ font-size: 150%;
+ fill: white;
+ }
+
+ .axisHorizontal path{
+ fill: none;
+ }
+
+ .axisHorizontal .tick line {
+ stroke-width: 1;
+ stroke: rgba(0, 0, 0, 0.2);
+ }
+
+ .bar {
+ fill: steelblue;
+ fill-opacity: .9;
+ }
\ No newline at end of file
diff --git a/apps/packet-stats/src/main/resources/app/view/sampleCustom/sampleCustom.html b/apps/packet-stats/src/main/resources/app/view/sampleCustom/sampleCustom.html
new file mode 100644
index 0000000..ef8d1aa
--- /dev/null
+++ b/apps/packet-stats/src/main/resources/app/view/sampleCustom/sampleCustom.html
@@ -0,0 +1,18 @@
+<!-- partial HTML of patch panel app -->
+<meta charset="utf-8">
+<head>
+</head>
+
+<body style="background-color:powderblue;">
+
+<h2><center>Packet Statistics</center></h2>
+
+<div id="ov-sample-custom" ng-controller="OvSampleCustomCtrl">
+ <center><div class="button-panel">
+ <div class="my-button" ng-click="dthreestuff()">
+ Generate Graph
+ </div>
+ </div>
+ </center>
+
+</div>
\ No newline at end of file
diff --git a/apps/packet-stats/src/main/resources/app/view/sampleCustom/sampleCustom.js b/apps/packet-stats/src/main/resources/app/view/sampleCustom/sampleCustom.js
new file mode 100644
index 0000000..5122047
--- /dev/null
+++ b/apps/packet-stats/src/main/resources/app/view/sampleCustom/sampleCustom.js
@@ -0,0 +1,295 @@
+// js for patch panel app custom view
+/**
+IMPORTANT CHANGES THAT MUST BE MADE BEFORE SUBMITTING
+
+-Graph is not being updated with packet counters. The counters is only set to 0.
+ This is a New bug, after individual buttons were removed.
+-HTML Page is not being resized depending on the the size of the screen.
+-Must Enable Scrolling
+-Can Remove Redundant Code and create one json file, instead of multiple.
+-Add comments and work on the code formatting.
+
+Due to a paucity of time, I couldn't work on some of these important changes.
+The first bug is very important to correct and the code should not be in the ONOS
+codebase without the change.
+
+Feel free to contact me for any issues.
+**/
+var strdhcpval = "h";
+ (function () {
+ 'use strict';
+ // injected refs
+ var $log, $scope, wss, d3Elem;
+
+ // constants remember to change this stuff!!s
+ var arpReq = 'arpRequest',
+ arpResp = 'arpResponse';
+ var dhcpReq = 'dhcpRequest',
+ dhcpResp = 'dhcpResponse';
+ var icmpReq = 'icmpRequest',
+ icmpResp = 'icmpResponse';
+ var lldpReq = 'lldpRequest',
+ lldpResp = 'lldpResponse';
+ var vlanReq = 'vlanRequest',
+ vlanResp = 'vlanResponse';
+ var igmpReq = 'igmpRequest',
+ igmpResp = 'igmpResponse';
+ var pimReq = 'pimRequest',
+ pimResp = 'pimResponse';
+ var bsnReq = 'bsnRequest',
+ bsnResp = 'bsnResponse';
+ var unknownReq = 'unknownRequest',
+ unknownResp = 'unknownResponse';
+ var mplsReq = 'mplsRequest',
+ mplsResp = 'mplsResponse';
+ var arpval = 0;
+ var dhcpval = 0;
+ var icmpval = 0;
+ var lldpval = 0;
+ var vlanval = 0;
+ var igmpval = 0;
+ var pimval = 0;
+ var bsnval =0;
+ var unknownval =0;
+ var mplsval = 0;
+
+ var arpMsg = "";
+ var dhcpMsg = "";
+ var icmpMsg = "";
+ var lldpMsg = "";
+ var vlanMsg = "";
+ var igmpMsg = "";;
+ var pimMsg = "";
+ var bsnMsg = "";
+ var unknownMsg = "";
+ var mplsMsg = "";
+
+ function arpGetter() {
+ wss.sendEvent(arpReq);
+ }
+ function icmpGetter() {
+ wss.sendEvent(icmpReq);
+ }
+ function lldpGetter() {
+ wss.sendEvent(lldpReq);
+ }
+ function dhcpGetter() {
+ wss.sendEvent(dhcpReq);
+ }
+ function vlanGetter() {
+ wss.sendEvent(vlanReq);
+ }
+
+ function igmpGetter() {
+ wss.sendEvent(igmpReq);
+ }
+ function pimGetter() {
+ wss.sendEvent(pimReq);
+ }
+ function bsnGetter() {
+ wss.sendEvent(bsnReq);
+ }
+ function unknownGetter() {
+ wss.sendEvent(unknownReq);
+ }
+ function mplsGetter() {
+ wss.sendEvent(mplsReq);
+ }
+
+
+ function dthreestuff() {
+ wss.sendEvent(dhcpReq);
+ wss.sendEvent(unknownReq);
+ wss.sendEvent(mplsReq);
+ var data = [
+ {label:"ARP", value:arpval},
+ {label:"ICMP", value:icmpval},
+ {label:"DHCP", value:dhcpval},
+ {label:"PIM", value:pimval},
+ {label:"BSN", value:bsnval},
+ {label:"IGMP", value:igmpval},
+ {label:"LLDP", value:lldpval},
+ {label:"VLAN", value:vlanval},
+ {label:"MPLS", value:mplsval},
+ {label:"Unknown", value:unknownval}
+ ];
+
+
+ var div = d3.select("body").append("div").attr("class", "toolTip");
+
+ var axisMargin = 20,
+ margin = 40,
+ valueMargin = 4,
+ width = parseInt(d3.select('body').style('width'), 10),
+ height = parseInt(d3.select('body').style('height'), 10),
+ barHeight = (height-axisMargin-margin*2)* 0.4/data.length,
+ barPadding = (height-axisMargin-margin*2)*0.6/data.length,
+ data, bar, svg, scale, xAxis, labelWidth = 0;
+
+ var max = d3.max(data, function(d) { return d.value; });
+
+ var svg = d3.select('body')
+ .append("svg")
+ .attr("width", width)
+ .attr("height", height);
+
+
+ var bar = svg.selectAll("g")
+ .data(data)
+ .enter()
+ .append("g");
+
+ bar.attr("class", "bar")
+ .attr("cx",0)
+ .attr("transform", function(d, i) {
+ return "translate(" + margin + "," + (i * (barHeight + barPadding) + barPadding) + ")";
+ });
+
+ bar.append("text")
+ .attr("class", "label")
+ .attr("y", barHeight / 2)
+ .attr("dy", ".35em") //vertical align middle
+ .text(function(d){
+ return d.label;
+ }).each(function() {
+ labelWidth = Math.ceil(Math.max(labelWidth, this.getBBox().width));
+ });
+
+ var scale = d3.scale.linear()
+ .domain([0, max])
+ .range([0, width - margin*2 - labelWidth]);
+
+ var xAxis = d3.svg.axis()
+ .scale(scale)
+ .tickSize(-height + 2*margin + axisMargin)
+ .orient("bottom");
+
+ bar.append("rect")
+ .attr("transform", "translate("+labelWidth+", 0)")
+ .attr("height", barHeight)
+ .attr("width", function(d){
+ return scale(d.value);
+ });
+
+ bar.append("text")
+ .attr("class", "value")
+ .attr("y", barHeight / 2)
+ .attr("dx", -valueMargin + labelWidth) //margin right
+ .attr("dy", ".35em") //vertical align middle
+ .attr("text-anchor", "end")
+ .text(function(d){
+ return (d.value+" Packets");
+ })
+ .attr("x", function(d){
+ var width = this.getBBox().width;
+ return Math.max(width + valueMargin, scale(d.value));
+ });
+
+ bar
+ .on("mousemove", function(d){
+ div.style("left", d3.event.pageX+10+"px");
+ div.style("top", d3.event.pageY-25+"px");
+ div.style("display", "inline-block");
+ div.html((d.label)+"<br>"+(d.value)+" Packets");
+ });
+ bar
+ .on("mouseout", function(d){
+ div.style("display", "none");
+ });
+
+ svg.insert("g",":first-child")
+ .attr("class", "axisHorizontal")
+ .attr("transform", "translate(" + (margin + labelWidth) + ","+ (height - axisMargin - margin)+")")
+ .call(xAxis);
+
+ }
+
+ function responseArp(data) {
+ arpval = data.DhcpCounter;
+ }
+
+
+ function responseDhcp(data) {
+ dhcpval = data.DhcpCounter;
+ }
+
+ function responseIcmp(data) {
+ icmpval = data.IcmpCounter;
+ }
+ function responseLldp(data) {
+ lldpval = data.LldpCounter;
+ }
+ function responseVlan(data) {
+ vlanval = data.VlanCounter;
+ }
+ function responseIgmp(data) {
+ igmpval = data.IgmpCounter;
+ }
+ function responsePim(data) {
+ pimval = data.PimCounter;
+ }
+ function responseBsn(data) {
+ bsnval = data.BsnCounter;
+ }
+ function responseUnknown(data) {
+ unknownval = data.UnknownCounter;
+ }
+
+ function responseMPLS(data) {
+ mplsval = data.MplsCounter;
+ }
+
+ var app = angular.module('ovSampleCustom', [])
+ .controller('OvSampleCustomCtrl',
+ ['$log', '$scope', 'WebSocketService',
+
+ function (_$log_, _$scope_, _wss_, ) {
+ $log = _$log_;
+ $scope = _$scope_;
+ wss = _wss_;
+
+
+ var handlers = {};
+ $scope.data = {};
+
+ // data response handler
+ handlers[arpResp] = responseArp;
+ handlers[dhcpResp] = responseDhcp;
+ handlers[icmpResp] = responseIcmp;
+ handlers[lldpResp] = responseLldp;
+ handlers[vlanResp] = responseVlan;
+ handlers[igmpResp] = responseIgmp;
+ handlers[pimResp] = responsePim;
+ handlers[bsnResp] = responseBsn;
+ handlers[unknownResp] = responseUnknown;
+ handlers[mplsResp] = responseMPLS;
+ wss.bindHandlers(handlers);
+
+
+ // custom click handler
+ $scope.arpGetter = arpGetter;
+ $scope.icmpGetter = icmpGetter;
+ $scope.dhcpGetter = dhcpGetter;
+ $scope.lldpGetter = lldpGetter;
+ $scope.vlanGetter = vlanGetter;
+ $scope.igmpGetter = igmpGetter;
+ $scope.pimGetter = pimGetter;
+ $scope.bsnGetter = bsnGetter;
+ $scope.unknownGetter = unknownGetter;
+ $scope.mplsGetter = mplsGetter;
+ $scope.dthreestuff = dthreestuff;
+
+
+
+ // cleanup
+ $scope.$on('$destroy', function () {
+ wss.unbindHandlers(handlers);
+ $log.log('OvSampleCustomCtrl has been destroyed');
+ });
+
+ $log.log('OvSampleCustomCtrl has been created');
+ }]);
+
+
+
+ }());
\ No newline at end of file
diff --git a/apps/packet-stats/src/main/resources/sampleCustom/css.html b/apps/packet-stats/src/main/resources/sampleCustom/css.html
new file mode 100644
index 0000000..4e7b709
--- /dev/null
+++ b/apps/packet-stats/src/main/resources/sampleCustom/css.html
@@ -0,0 +1 @@
+<link rel="stylesheet" href="app/view/sampleCustom/sampleCustom.css">
\ No newline at end of file
diff --git a/apps/packet-stats/src/main/resources/sampleCustom/js.html b/apps/packet-stats/src/main/resources/sampleCustom/js.html
new file mode 100644
index 0000000..6550b85
--- /dev/null
+++ b/apps/packet-stats/src/main/resources/sampleCustom/js.html
@@ -0,0 +1 @@
+<script src="app/view/sampleCustom/sampleCustom.js"></script>
\ No newline at end of file