"use strict";(function(){"use strict";var e=require("util");var t=require("events");var i=require("./DeviceBusinessDb");var r=0;function s(e,r){t.EventEmitter.call(this);if(false===this instanceof s){return new s}this.preIntfFlows=[];this.DeviceBusinessDbInstance=new i(e,r);this.preIntfFlowsInDb=[];this.previousTime=new Date;this.preBusinessData=[]}e.inherits(s,t.EventEmitter);s.prototype.getDeviceBusinessInfo=function(e,t,i,s){var n=this;var a=[];var f=function P(e){if(e){console.log(e)}};var c=new Date;var v=parseInt((c-n.previousTime)/1e3);if(v==0){v=100}var o=function p(e){var t={video:"视频应用",voice:"语音通讯",office:"日常办公",meeting:"会议应用"};if(e.SPort=="9129"){return t.video}if(e.SPort=="8000"){return t.meeting}if(e.SPort=="0"){return t.voice}return t.office};var l=function D(e,c){var v=e.split(/\r?\n/gi);var l=false;var u=false;var h=0;var d=0;if(r==1){}for(var P=0;P<v.length;P++){if(v[P].search("SrcIf")!==-1){h=P}}for(var P=0;P<v.length;P++){if(v[P].search("Protocol")!==-1){d=P}}if(h>0){for(var P=h+2;P<v.length;P++){if(v[P]==""){break}var p=v[P].split(/\s{2,}/gi);var D=v[++P].split(/\s{2,}/gi);var I={SrcIf:p[0],SrcIPAddress:p[1],DstIf:p[2],DstIPAddress:p[3],Pr:p[4],Tos:p[5],Flgs:p[6],Pkts:p[7],SPort:D[0],SMsk:D[1],SAS:D[2],DPort:D[3],DMsk:D[4],DAS:D[5],NextHop:D[6],BPk:D[7],Active:D[8],time:s,deviceName:t,seriaNo:i};if(I.Active=="0"||I.BPK=="0"||I.Pkts=="0"){continue}var b=n.preBusinessData;var w=false;for(var g=0;g<b.length;g++){if(I.SrcIf==b[g].SrcIf&&I.SrcIPAddress==b[g].SrcIPAddress&&I.DstIf==b[g].DstIf&&I.DstIPAddress==b[g].DstIPAddress&&I.SPort==b[g].SPort&&I.DPort==b[g].DPort){w=true;I.bytes=I.BPk*I.Pkts-b[g].BPk*b[g].Pkts;if(I.bytes<=0){I.bytes=I.BPk*I.Pkts}I.interval=I.Active-b[g].Active;if(I.interval<=0){I.interval=I.Active}break}}if(w==false){I.bytes=I.BPk*I.Pkts;I.interval=I.Active}a.push(I);for(var m=0;m<c.length;m++){if(I.SrcIf==c[m].intfName){I.bandwidth=c[m].bandwidth}}if(I.bandwidth==undefined){I.bandwidth=1e6}I.business=o(I)}n.preBusinessData=a.concat();for(var g=0;g<a.length;g++){n.DeviceBusinessDbInstance.insertIntoBusinessTable(a[g],f)}}if(d>0){var S=0;var B=0;for(var P=0;P<a.length;P++){}}};var u=function I(t,i){var r=t.split(/\r?\n/gi);var s=false;var n=0;var a=[];for(var f=0;f<r.length;f++){var c=new Object;if(r[f].search("show int")!==-1){continue}if(r[f].search("BW")!==-1){if(i[n].intfClass!="physical"){break}c.intfName=i[n]["intfName"];c.bandwidth=r[f].split("BW")[1].trim().split(" ")[0];c.intfClass=i[n]["intfClass"];c.intfName=i[n]["intfName"];n++}a.push(c)}e.exec("show ip flow cache",function(e){l(e,a)})};var h=function b(t){var i=t.split(/\r?\n/gi);var r=[];var s=false;for(var n=0;n<i.length;n++){var a=new Object;if(i[n].search("show int")!==-1){continue}if(i[n].search("===")!==-1){a.intfName=i[n].split("= ")[1].split(" =")[0].trim();a.bandwidth=1e5;if(a.intfName.search("Ethernet")!==-1){a.intfClass="physical"}else{a.intfClass="notphysical";s=true}r.push(a)}}e.exec("show interfaces | include , BW",function(e){u(e,r)})};var d=e.isConnect();if(d===true){e.exec("show interfaces | include ===",function(e){h(e)})}};module.exports=s})();