Packet Stats Application with GUI Component
Change-Id: Iee1e94e77d55acb4381481dbf4c23927f7cece5a
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