├── js ├── nf9 │ ├── nfinfotempl.js │ ├── nf9decode.js │ └── nftypes.js ├── nf1 │ └── nf1decode.js ├── nf5 │ └── nf5decode.js └── nf7 │ └── nf7decode.js ├── .gitignore ├── package.json ├── test └── test.decoding.js ├── netflowv9.js ├── README.md └── LICENSE /js/nf9/nfinfotempl.js: -------------------------------------------------------------------------------- 1 | function nfInfoTemplates(rinfo) { 2 | if (typeof this.templates === 'undefined') { 3 | this.templates = {}; 4 | } 5 | var templates = this.templates; 6 | var id = rinfo.address + ':' + rinfo.port; 7 | if (typeof templates[id] === 'undefined') { 8 | this.templates[id] = {}; 9 | } 10 | return templates[id]; 11 | } 12 | 13 | module.exports = nfInfoTemplates; 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Backups 2 | *~ 3 | .idea 4 | 5 | # Logs 6 | logs 7 | *.log 8 | 9 | # Runtime data 10 | pids 11 | *.pid 12 | *.seed 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | # Deployed apps should consider commenting this line out: 28 | # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git 29 | node_modules* 30 | 31 | package-lock.json 32 | 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-netflowv9", 3 | "version": "0.2.16", 4 | "description": "NetFlow Version 1,5,7,9 compatible library for Node.JS. It also support NetFlow v9 options template & data", 5 | "main": "netflowv9.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/delian/node-netflowv9.git" 12 | }, 13 | "keywords": [ 14 | "netflow", 15 | "v9", 16 | "cisco", 17 | "node", 18 | "node.js", 19 | "javascript" 20 | ], 21 | "author": "Delian Delchev (http://deliantech.blogspot.com/)", 22 | "license": "GPLv2", 23 | "bugs": { 24 | "url": "https://github.com/delian/node-netflowv9/issues" 25 | }, 26 | "dependencies": { 27 | "clone": "^1.0.4", 28 | "debug": "^4.1.0", 29 | "dequeue": "^1.0.5" 30 | }, 31 | "homepage": "https://github.com/delian/node-netflowv9", 32 | "devDependencies": { 33 | "chai": "^4.2.0", 34 | "mocha": "^5.2.0" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /js/nf1/nf1decode.js: -------------------------------------------------------------------------------- 1 | function nf1PktDecode(msg,rinfo) { 2 | var out = { header: { 3 | version: msg.readUInt16BE(0), 4 | count: msg.readUInt16BE(2), 5 | uptime: msg.readUInt32BE(4), 6 | seconds: msg.readUInt32BE(8), 7 | nseconds: msg.readUInt32BE(12) 8 | }, flows: []}; 9 | var buf = msg.slice(16); 10 | var t; 11 | while(buf.length>0) { 12 | out.flows.push({ 13 | ipv4_src_addr: (t=buf.readUInt32BE(0),(parseInt(t/16777216)%256)+'.'+(parseInt(t/65536)%256)+'.'+(parseInt(t/256)%256)+'.'+(t%256)), 14 | ipv4_dst_addr: (t=buf.readUInt32BE(4),(parseInt(t/16777216)%256)+'.'+(parseInt(t/65536)%256)+'.'+(parseInt(t/256)%256)+'.'+(t%256)), 15 | ipv4_next_hop: (t=buf.readUInt32BE(8),(parseInt(t/16777216)%256)+'.'+(parseInt(t/65536)%256)+'.'+(parseInt(t/256)%256)+'.'+(t%256)), 16 | input_snmp: buf.readUInt16BE(12), 17 | output_snmp: buf.readUInt16BE(14), 18 | in_pkts: buf.readUInt32BE(16), 19 | in_bytes: buf.readUInt32BE(20), 20 | first_switched: buf.readUInt32BE(24), 21 | last_switched: buf.readUInt32BE(28), 22 | l4_src_port: buf.readUInt16BE(32), 23 | l4_dst_port: buf.readUInt16BE(34), 24 | protocol: buf.readUInt8(38), 25 | src_tos: buf.readUInt8(39), 26 | tcp_flags: buf.readUInt8(40) 27 | }); 28 | buf = buf.slice(48); 29 | } 30 | return out; 31 | } 32 | 33 | module.exports = nf1PktDecode; -------------------------------------------------------------------------------- /js/nf5/nf5decode.js: -------------------------------------------------------------------------------- 1 | function nf5PktDecode(msg,rinfo) { 2 | var out = { header: { 3 | version: msg.readUInt16BE(0), 4 | count: msg.readUInt16BE(2), 5 | uptime: msg.readUInt32BE(4), 6 | seconds: msg.readUInt32BE(8), 7 | nseconds: msg.readUInt32BE(12), 8 | sequence: msg.readUInt32BE(16), 9 | engine_type: msg.readUInt8(20), 10 | engine_id: msg.readUInt8(21), 11 | sampling_interval: msg.readUInt16BE(22) 12 | }, flows: []}; 13 | var buf = msg.slice(24); 14 | var t; 15 | while(buf.length>0) { 16 | out.flows.push({ 17 | ipv4_src_addr: (t=buf.readUInt32BE(0),(parseInt(t/16777216)%256)+'.'+(parseInt(t/65536)%256)+'.'+(parseInt(t/256)%256)+'.'+(t%256)), 18 | ipv4_dst_addr: (t=buf.readUInt32BE(4),(parseInt(t/16777216)%256)+'.'+(parseInt(t/65536)%256)+'.'+(parseInt(t/256)%256)+'.'+(t%256)), 19 | ipv4_next_hop: (t=buf.readUInt32BE(8),(parseInt(t/16777216)%256)+'.'+(parseInt(t/65536)%256)+'.'+(parseInt(t/256)%256)+'.'+(t%256)), 20 | input_snmp: buf.readUInt16BE(12), 21 | output_snmp: buf.readUInt16BE(14), 22 | in_pkts: buf.readUInt32BE(16), 23 | in_bytes: buf.readUInt32BE(20), 24 | first_switched: buf.readUInt32BE(24), 25 | last_switched: buf.readUInt32BE(28), 26 | ipv4_src_port: buf.readUInt16BE(32), 27 | ipv4_dst_port: buf.readUInt16BE(34), 28 | tcp_flags: buf.readUInt8(37), 29 | protocol: buf.readUInt8(38), 30 | src_tos: buf.readUInt8(39), 31 | in_as: buf.readUInt16BE(40), 32 | out_as: buf.readUInt16BE(42), 33 | src_mask: buf.readUInt8(44), 34 | dst_mask: buf.readUInt8(45) 35 | }); 36 | buf = buf.slice(48); 37 | } 38 | return out; 39 | } 40 | 41 | 42 | module.exports = nf5PktDecode; -------------------------------------------------------------------------------- /js/nf7/nf7decode.js: -------------------------------------------------------------------------------- 1 | function nf7PktDecode(msg,rinfo) { 2 | var out = { header: { 3 | version: msg.readUInt16BE(0), 4 | count: msg.readUInt16BE(2), 5 | uptime: msg.readUInt32BE(4), 6 | seconds: msg.readUInt32BE(8), 7 | nseconds: msg.readUInt32BE(12), 8 | sequence: msg.readUInt32BE(16) 9 | }, flows: []}; 10 | var buf = msg.slice(24); 11 | var t; 12 | while(buf.length>0) { 13 | out.flows.push({ 14 | ipv4_src_addr: (t=buf.readUInt32BE(0),(parseInt(t/16777216)%256)+'.'+(parseInt(t/65536)%256)+'.'+(parseInt(t/256)%256)+'.'+(t%256)), 15 | ipv4_dst_addr: (t=buf.readUInt32BE(4),(parseInt(t/16777216)%256)+'.'+(parseInt(t/65536)%256)+'.'+(parseInt(t/256)%256)+'.'+(t%256)), 16 | ipv4_next_hop: (t=buf.readUInt32BE(8),(parseInt(t/16777216)%256)+'.'+(parseInt(t/65536)%256)+'.'+(parseInt(t/256)%256)+'.'+(t%256)), 17 | input_snmp: buf.readUInt16BE(12), 18 | output_snmp: buf.readUInt16BE(14), 19 | in_pkts: buf.readUInt32BE(16), 20 | in_bytes: buf.readUInt32BE(20), 21 | first_switched: buf.readUInt32BE(24), 22 | last_switched: buf.readUInt32BE(28), 23 | l4_src_port: buf.readUInt16BE(32), 24 | l4_dst_port: buf.readUInt16BE(34), 25 | flags: buf.readUInt8(36), 26 | tcp_flags: buf.readUInt8(37), 27 | protocol: buf.readUInt8(38), 28 | src_tos: buf.readUInt8(39), 29 | in_as: buf.readUInt16BE(40), 30 | out_as: buf.readUInt16BE(42), 31 | src_mask: buf.readUInt8(44), 32 | dst_mask: buf.readUInt8(45), 33 | flow_flags: buf.readUInt16BE(46), 34 | router_sc: (t=buf.readUInt32BE(48),(parseInt(t/16777216)%256)+'.'+(parseInt(t/65536)%256)+'.'+(parseInt(t/256)%256)+'.'+(t%256)) 35 | }); 36 | buf = buf.slice(48); 37 | } 38 | return out; 39 | } 40 | 41 | module.exports = nf7PktDecode; 42 | -------------------------------------------------------------------------------- /test/test.decoding.js: -------------------------------------------------------------------------------- 1 | var expect = require('chai').expect; 2 | 3 | var NetFlowV9 = require('../netflowv9'); 4 | 5 | var VYOS_PACKET = '000900070002549b53b289a200000001000000000000005c0400001500150004001600040001000400020004003c0001000a0002000e0002003d00010003000400080004000c000400070002000b00020005000100060001000400010038000600500006003a000200c90004003000010000005c0401001500150004001600040001000400020004003c0001000a0002000e0002003d00010003000400080004000c000400070002000b00020005000100060001000400010051000600390006003b000200c90004003000010000005c0800001500150004001600040001000400020004003c0001000a0002000e0002003d000100030004001b0010001c00100005000100070002000b000200060001000400010038000600500006003a000200c90004003000010000005c0801001500150004001600040001000400020004003c0001000a0002000e0002003d000100030004001b0010001c00100005000100070002000b000200060001000400010051000600390006003b000200c90004003000010001001a10000004000c000100040030000100310001003200041000000e000000000102000001f4040000400000209e0000209e0000002800000001040003000000000000000a640054c0004c0264aa0050001006001b2fb9484980ee7395562800000000000301'; 6 | 7 | 8 | 9 | describe('NetFlowV9', function () { 10 | 11 | it('should be a function', function (done) { 12 | expect(NetFlowV9).to.be.an('function'); //is actually a constructor 13 | done(); 14 | }); 15 | 16 | it('should have nfPktDecode', function (done) { 17 | expect(NetFlowV9).to.have.property('nfPktDecode'); 18 | done(); 19 | }); 20 | 21 | describe('nfPktDecode', function () { 22 | it('should be able to decode vyos packet', function (done) { 23 | var buffer = new Buffer(VYOS_PACKET, 'hex'); 24 | var templates = {}; 25 | expect(buffer).to.have.length(VYOS_PACKET.length/2); 26 | var r = NetFlowV9.nfPktDecode(buffer, templates); 27 | expect(templates).to.have.property('1024'); 28 | expect(templates).to.have.property('1025'); 29 | expect(templates).to.have.property('2048'); 30 | expect(templates).to.have.property('2049'); 31 | expect(r).to.have.property('header'); 32 | expect(r).to.have.property('flows'); 33 | 34 | var header = r.header; 35 | expect(header).to.have.property('version', 9); 36 | expect(header).to.have.property('count', 7); 37 | expect(header).to.have.property('uptime', 152731); 38 | expect(header).to.have.property('seconds', 1404209570); 39 | expect(header).to.have.property('sequence', 1); 40 | expect(header).to.have.property('sourceId', 0); 41 | 42 | var flows = r.flows; 43 | expect(flows).to.have.length(1); 44 | 45 | var f1 = flows[0]; 46 | expect(f1).to.have.property('ipv4_src_addr', '10.100.0.84'); 47 | expect(f1).to.have.property('ipv4_dst_addr', '192.0.76.2'); 48 | expect(f1).to.have.property('in_pkts', 1); 49 | //TODO:test everything 50 | done(); 51 | }); 52 | }); 53 | 54 | }); -------------------------------------------------------------------------------- /netflowv9.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This version support only compiled code and works with streams API 3 | */ 4 | 5 | //require('debug').enable('NetFlowV9'); 6 | var debug = require('debug')('NetFlowV9'); 7 | var dgram = require('dgram'); 8 | var clone = require('clone'); 9 | var util = require('util'); 10 | var e = require('events').EventEmitter; 11 | var Dequeue = require('dequeue'); 12 | 13 | var nft = require('./js/nf9/nftypes'); 14 | var nf1PktDecode = require('./js/nf1/nf1decode'); 15 | var nf5PktDecode = require('./js/nf5/nf5decode'); 16 | var nf7PktDecode = require('./js/nf7/nf7decode'); 17 | var nf9PktDecode = require('./js/nf9/nf9decode'); 18 | var nfInfoTemplates = require('./js/nf9/nfinfotempl'); 19 | 20 | function nfPktDecode(msg,rinfo) { 21 | var version = msg.readUInt16BE(0); 22 | switch (version) { 23 | case 1: 24 | return this.nf1PktDecode(msg,rinfo); 25 | break; 26 | case 5: 27 | return this.nf5PktDecode(msg,rinfo); 28 | break; 29 | case 7: 30 | return this.nf7PktDecode(msg,rinfo); 31 | break; 32 | case 9: 33 | return this.nf9PktDecode(msg,rinfo); 34 | break; 35 | default: 36 | debug('bad header version %d', version); 37 | return; 38 | } 39 | } 40 | 41 | function NetFlowV9(options) { 42 | if (!(this instanceof NetFlowV9)) return new NetFlowV9(options); 43 | var me = this; 44 | this.templates = {}; 45 | this.nfTypes = clone(nft.nfTypes); 46 | this.nfScope = clone(nft.nfScope); 47 | this.cb = null; 48 | this.templateCb = null; 49 | this.socketType = 'udp4'; 50 | this.port = null; 51 | this.proxy = null; 52 | this.fifo = new Dequeue(); 53 | if (typeof options == 'function') this.cb = options; else 54 | if (typeof options.cb == 'function') this.cb = options.cb; 55 | if (typeof options.templateCb == 'function') this.templateCb = options.templateCb; 56 | if (typeof options == 'object') { 57 | if (options.ipv4num) decIpv4Rule[4] = "o['$name']=buf.readUInt32BE($pos);"; 58 | if (options.nfTypes) this.nfTypes = util._extend(this.nfTypes,options.nfTypes); // Inherit nfTypes 59 | if (options.nfScope) this.nfScope = util._extend(this.nfScope,options.nfScope); // Inherit nfTypes 60 | if (options.socketType) this.socketType = options.socketType; 61 | if (options.port) this.port = options.port; 62 | if (options.templates) this.templates = options.templates; 63 | if (options.fwd) this.fwd = options.fwd; 64 | if (typeof options.proxy == 'object' || 65 | typeof options.proxy == 'string') { 66 | this.proxy = []; 67 | if (typeof options.proxy == 'string') { 68 | debug('Defining proxy destination %s',options.proxy); 69 | var m = options.proxy.match(/^(.*)(\:(\d+))$/); 70 | if (m) { 71 | this.proxy.push({host: m[1], port: m[3]||5555}); 72 | debug('Proxy added %s:%s',m[1],m[3]||5555); 73 | } 74 | } else { 75 | for (var k in options.proxy) { 76 | var v = options.proxy[k]; 77 | if (typeof v == 'string') { 78 | debug('Defining proxy destination %s = %s',k,v); 79 | var m = v.match(/^(.*)(\:(\d+))$/); 80 | if (m) { 81 | this.proxy.push({host: m[1], port: m[3]||5555}); 82 | debug('Proxy added %s:%s',m[1],m[3]||5555); 83 | } 84 | } 85 | } 86 | } 87 | 88 | if (this.proxy.length == 0) this.proxy = null; 89 | } 90 | e.call(this,options); 91 | } 92 | 93 | this.server = dgram.createSocket(this.socketType); 94 | this.server.on('message',function(msg,rinfo){ 95 | me.fifo.push([msg, rinfo]); 96 | if (!me.closed && me.set) { 97 | me.set = false; 98 | setImmediate(me.fetch); 99 | } 100 | if (me.proxy) { // Resend the traffic 101 | me.proxy.forEach(function(p) { 102 | me.server.send(msg,0,msg.length,p.port,p.host,function() {}); 103 | }); 104 | } 105 | }); 106 | 107 | this.server.on('close', function() { 108 | this.closed = true; 109 | }); 110 | 111 | this.listen = function(port,host,cb) { 112 | me.fetch(); 113 | setTimeout(function() { 114 | if (host && typeof host === 'function') 115 | me.server.bind(port,host); 116 | else if (host && typeof host === 'string' && cb) 117 | me.server.bind(port,host,cb); 118 | else if (host && typeof host === 'string' && !cb) 119 | me.server.bind(port,host); 120 | else if (!host && cb) 121 | me.server.bind(port, cb); 122 | else 123 | me.server.bind(port); 124 | },50); 125 | }; 126 | 127 | this.fetch = function() { 128 | while (me.fifo.length > 0 && !this.closed) { 129 | var data = me.fifo.shift(); 130 | var msg = data[0]; 131 | var rinfo = data[1]; 132 | var startTime = new Date().getTime(); 133 | if (me.fwd) { 134 | var data = JSON.parse(msg.toString()); 135 | msg = new Buffer(data.buffer); 136 | rinfo = data.rinfo; 137 | } 138 | if (rinfo.size<20) return; 139 | var o = me.nfPktDecode(msg,rinfo); 140 | var timeMs = (new Date().getTime()) - startTime; 141 | if (o && o.flows.length > 0) { // If the packet does not contain flows, only templates we do not decode 142 | o.rinfo = rinfo; 143 | o.packet = msg; 144 | o.decodeMs = timeMs; 145 | if (me.cb) 146 | me.cb(o); 147 | else 148 | me.emit('data',o); 149 | } else if (o && o.templates) { 150 | o.rinfo = rinfo; 151 | o.packet = msg; 152 | o.decodeMs = timeMs; 153 | if (me.templateCb) 154 | me.templateCb(o); 155 | else 156 | me.emit('template', o); 157 | } else { 158 | debug('Undecoded flows',o); 159 | } 160 | } 161 | 162 | me.set = true; 163 | }; 164 | 165 | if (this.port) this.listen(options.port, options.host); 166 | } 167 | 168 | util.inherits(NetFlowV9,e); 169 | NetFlowV9.prototype.nfInfoTemplates = nfInfoTemplates; 170 | NetFlowV9.prototype.nfPktDecode = nfPktDecode; 171 | NetFlowV9.prototype.nf1PktDecode = nf1PktDecode; 172 | NetFlowV9.prototype.nf5PktDecode = nf5PktDecode; 173 | NetFlowV9.prototype.nf7PktDecode = nf7PktDecode; 174 | NetFlowV9.prototype.nf9PktDecode = nf9PktDecode; 175 | module.exports = NetFlowV9; 176 | -------------------------------------------------------------------------------- /js/nf9/nf9decode.js: -------------------------------------------------------------------------------- 1 | var debug = require('debug')('NetFlowV9'); 2 | 3 | var decMacRule = { 4 | 0: "o['$name']=buf.toString('hex',$pos,$pos+$len);" 5 | }; 6 | 7 | function nf9PktDecode(msg,rinfo) { 8 | var templates = this.nfInfoTemplates(rinfo); 9 | var nfTypes = this.nfTypes || {}; 10 | var nfScope = this.nfScope || {}; 11 | 12 | var out = { header: { 13 | version: msg.readUInt16BE(0), 14 | count: msg.readUInt16BE(2), 15 | uptime: msg.readUInt32BE(4), 16 | seconds: msg.readUInt32BE(8), 17 | sequence: msg.readUInt32BE(12), 18 | sourceId: msg.readUInt32BE(16) 19 | }, flows: [] }; 20 | 21 | function appendTemplate(tId) { 22 | var id = rinfo.address + ':' + rinfo.port; 23 | out.templates = out.templates || {}; 24 | out.templates[id] = out.templates[id] || {}; 25 | out.templates[id][tId] = templates[tId]; 26 | } 27 | 28 | function compileStatement(type, pos, len) { 29 | var nf = nfTypes[type]; 30 | var cr = null; 31 | if (nf && nf.compileRule) { 32 | cr = nf.compileRule[len] || nf.compileRule[0]; 33 | if (cr) { 34 | return cr.toString().replace(/(\$pos)/g, function (n) { 35 | return pos 36 | }).replace(/(\$len)/g, function (n) { 37 | return len 38 | }).replace(/(\$name)/g, function (n) { 39 | return nf.name 40 | }); 41 | } 42 | } 43 | debug('Unknown compile rule TYPE: %d POS: %d LEN: %d',type,pos,len); 44 | return ""; 45 | } 46 | 47 | function compileTemplate(list) { 48 | var i, z, nf, n; 49 | var f = "var o = Object.create(null); var t;\n"; 50 | var listLen = list ? list.length : 0; 51 | for (i = 0, n = 0; i < listLen; i++, n += z.len) { 52 | z = list[i]; 53 | nf = nfTypes[z.type]; 54 | if (!nf) { 55 | debug('Unknown NF type %d', z.type); 56 | nf = nfTypes[z.type] = { 57 | name: 'unknown_type_'+ z.type, 58 | compileRule: decMacRule 59 | }; 60 | } 61 | f += compileStatement(z.type, n, z.len) + ";\n"; 62 | } 63 | f += "return o;\n"; 64 | debug('The template will be compiled to %s',f); 65 | return new Function('buf', 'nfTypes', f); 66 | } 67 | 68 | function readTemplate(buffer) { 69 | // var fsId = buffer.readUInt16BE(0); 70 | var len = buffer.readUInt16BE(2); 71 | var buf = buffer.slice(4, len); 72 | while (buf.length > 0) { 73 | var tId = buf.readUInt16BE(0); 74 | var cnt = buf.readUInt16BE(2); 75 | var list = []; 76 | var len = 0; 77 | for (var i = 0; i < cnt; i++) { 78 | list.push({type: buf.readUInt16BE(4 + 4 * i), len: buf.readUInt16BE(6 + 4 * i)}); 79 | len += buf.readUInt16BE(6 + 4 * i); 80 | } 81 | debug('compile template %s for %s:%d', tId, rinfo.address, rinfo.port); 82 | templates[tId] = {len: len, list: list, compiled: compileTemplate(list)}; 83 | appendTemplate(tId); 84 | buf = buf.slice(4 + cnt * 4); 85 | } 86 | } 87 | 88 | function decodeTemplate(fsId, buf) { 89 | if (typeof templates[fsId].compiled !== 'function') { 90 | templates[fsId].compiled = compileTemplate(templates[fsId].list); 91 | } 92 | var o = templates[fsId].compiled(buf, nfTypes); 93 | o.fsId = fsId; 94 | return o; 95 | } 96 | 97 | function compileScope(type,pos,len) { 98 | if (!nfScope[type]) { 99 | nfScope[type] = { name: 'unknown_scope_'+type, compileRule: decMacRule }; 100 | debug('Unknown scope TYPE: %d POS: %d LEN: %d',type,pos,len); 101 | } 102 | 103 | var nf = nfScope[type]; 104 | var cr = null; 105 | if (nf.compileRule) { 106 | cr = nf.compileRule[len] || nf.compileRule[0]; 107 | if (cr) { 108 | return cr.toString().replace(/(\$pos)/g, function (n) { 109 | return pos 110 | }).replace(/(\$len)/g, function (n) { 111 | return len 112 | }).replace(/(\$name)/g, function (n) { 113 | return nf.name 114 | }); 115 | } 116 | } 117 | debug('Unknown compile scope rule TYPE: %d POS: %d LEN: %d',type,pos,len); 118 | return ""; 119 | } 120 | 121 | function readOptions(buffer) { 122 | var len = buffer.readUInt16BE(2); 123 | var tId = buffer.readUInt16BE(4); 124 | var osLen = buffer.readUInt16BE(6); 125 | var oLen = buffer.readUInt16BE(8); 126 | var buff = buffer.slice(10,len); 127 | debug('readOptions: len:%d tId:%d osLen:%d oLen:%d for %s:%d',len,tId,osLen,oLen,buff,rinfo.address,rinfo.port); 128 | var plen = 0; 129 | var cr = "var o={ isOption: true }; var t;\n"; 130 | var type; var tlen; 131 | 132 | // Read the SCOPE 133 | var buf = buff.slice(0,osLen); 134 | while (buf.length > 3) { 135 | type = buf.readUInt16BE(0); 136 | tlen = buf.readUInt16BE(2); 137 | debug(' SCOPE type: %d (%s) len: %d, plen: %d', type,nfTypes[type] ? nfTypes[type].name : 'unknown',tlen,plen); 138 | if (type>0) cr+=compileScope(type, plen, tlen); 139 | buf = buf.slice(4); 140 | plen += tlen; 141 | } 142 | 143 | // Read the Fields 144 | buf = buff.slice(osLen); 145 | while (buf.length > 3) { 146 | type = buf.readUInt16BE(0); 147 | tlen = buf.readUInt16BE(2); 148 | debug(' FIELD type: %d (%s) len: %d, plen: %d', type,nfTypes[type] ? nfTypes[type].name : 'unknown',tlen,plen); 149 | if (type>0) cr+=compileStatement(type, plen, tlen); 150 | buf = buf.slice(4); 151 | plen += tlen; 152 | } 153 | cr+="// option "+tId+"\n"; 154 | cr+="return o;"; 155 | debug('option template compiled to %s',cr); 156 | templates[tId] = { len: plen, compiled: new Function('buf','nfTypes',cr) }; 157 | appendTemplate(tId); 158 | } 159 | 160 | var buf = msg.slice(20); 161 | while (buf.length > 3) { // length > 3 allows us to skip padding 162 | var fsId = buf.readUInt16BE(0); 163 | var len = buf.readUInt16BE(2); 164 | if (fsId == 0) readTemplate(buf); 165 | else if (fsId == 1) readOptions(buf); 166 | else if (fsId > 1 && fsId < 256) { 167 | debug('Unknown Flowset ID %d!', fsId); 168 | } 169 | else if (fsId > 255 && typeof templates[fsId] != 'undefined') { 170 | var tbuf = buf.slice(4, len); 171 | while (tbuf.length >= templates[fsId].len) { 172 | out.flows.push(decodeTemplate(fsId, tbuf)); 173 | tbuf = tbuf.slice(templates[fsId].len); 174 | } 175 | } else if (fsId > 255) { 176 | debug('Unknown template/option data with flowset id %d for %s:%d',fsId,rinfo.address,rinfo.port); 177 | } 178 | buf = buf.slice(len); 179 | } 180 | 181 | return out; 182 | } 183 | 184 | module.exports = nf9PktDecode; 185 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | node-netflowv9 2 | ============== 3 | 4 | NetFlow Version 1,5,7,9 library for Node.JS 5 | NetFlow Version 10 (IPFix) is next (a lot of the IPFIX types are implemented already)! 6 | 7 | The library is still under development, please be careful! It has been tested with Cisco IOS XR and IPv4 although it must work with IPv6 too! Please log problems in the issues section! 8 | 9 | ## Usage 10 | 11 | The usage of the netflowv9 collector library is very very simple. You just have to do something like this: 12 | 13 | 14 | var Collector = require('node-netflowv9'); 15 | 16 | Collector(function(flow) { 17 | console.log(flow); 18 | }).listen(3000); 19 | 20 | or you can use it as event provider: 21 | 22 | Collector({port: 3000}).on('data',function(flow) { 23 | console.log(flow); 24 | }); 25 | 26 | 27 | The flow will be presented in a format very similar to this: 28 | 29 | 30 | { header: 31 | { version: 9, 32 | count: 25, 33 | uptime: 2452864139, 34 | seconds: 1401951592, 35 | sequence: 254138992, 36 | sourceId: 2081 }, 37 | rinfo: 38 | { address: '15.21.21.13', 39 | family: 'IPv4', 40 | port: 29471, 41 | size: 1452 }, 42 | packet: Buffer <00 00 00 00 ....> 43 | flow: [ 44 | { in_pkts: 3, 45 | in_bytes: 144, 46 | ipv4_src_addr: '15.23.23.37', 47 | ipv4_dst_addr: '16.16.19.165', 48 | input_snmp: 27, 49 | output_snmp: 16, 50 | last_switched: 2452753808, 51 | first_switched: 2452744429, 52 | l4_src_port: 61538, 53 | l4_dst_port: 62348, 54 | out_as: 0, 55 | in_as: 0, 56 | bgp_ipv4_next_hop: '16.16.1.1', 57 | src_mask: 32, 58 | dst_mask: 24, 59 | protocol: 17, 60 | tcp_flags: 0, 61 | src_tos: 0, 62 | direction: 1, 63 | fw_status: 64, 64 | flow_sampler_id: 2 } } ] 65 | 66 | 67 | There will be one callback for each packet, which may contain more than one flow. 68 | 69 | Additionally, you can use the collector to listen for template updates: 70 | 71 | var collector = Collector({port: 3000}); 72 | collector.on('data', function(data) { 73 | console.log(data); 74 | }); 75 | collector.on('template', function(data) { 76 | console.log(data); 77 | }); 78 | 79 | You can also access a NetFlow decode function directly. Do something like this: 80 | 81 | var netflowPktDecoder = require('node-netflowv9').nfPktDecode; 82 | .... 83 | console.log(netflowPktDecoder(buffer)) 84 | 85 | Currently we support netflow version 1, 5, 7 and 9. 86 | 87 | ## Options 88 | 89 | You can initialize the collector with either callback function only or a group of options within an object. 90 | 91 | The following options are available during initialization: 92 | 93 | **port** - defines the port where our collector will listen to. 94 | 95 | Collector({ port: 5000, cb: function (flow) { console.log(flow) } }) 96 | 97 | If no port is provided, then the underlying socket will not be initialized (bind to a port) until you call listen method with a port as a parameter: 98 | 99 | Collector(function (flow) { console.log(flow) }).listen(port) 100 | 101 | **host** - binds to a particular host on the local interfaces. 102 | 103 | Collector({ port: 5000, host: '0.0.0.0', cb: function (flow) { console.log(flow) } }) 104 | 105 | **templates** - provides the default templates to be used for incoming traffic 106 | 107 | Collector({ port: 5000, templates: { '127.0.0.1:5323': { '235': { len: 344, ... 108 | 109 | **cb** - defines a callback function to be executed for every flow. If no call back function is provided, then the collector fires 'data' event for each received flow 110 | 111 | Collector({ cb: function (flow) { console.log(flow) } }).listen(5000) 112 | 113 | **templateCb** - defines a callback function to be executed for templates. If no call back function is provided, then the collector fires 'template' event for the received templates. 114 | 115 | Collector({ templateCb: function(data) { console.log(data) } }).listen(5000); 116 | 117 | **ipv4num** - defines that we want to receive the IPv4 ip address as a number, instead of decoded in a readable dot format 118 | 119 | Collector({ ipv4num: true, cb: function (flow) { console.log(flow) } }).listen(5000) 120 | 121 | **socketType** - defines to what socket type we will bind to. Default is udp4. You can change it to udp6 is you like. 122 | 123 | Collector({ socketType: 'udp6', cb: function (flow) { console.log(flow) } }).listen(5000) 124 | 125 | **nfTypes** - defines your own decoders to NetFlow v9+ types 126 | 127 | **nfScope** - defines your own decoders to NetFlow v9+ Option Template scopes 128 | 129 | **proxy** - define a proxy destination (one or many) where the netflow packets will be retransmitted 130 | 131 | ## Define your own decoders for NetFlow v9+ types 132 | 133 | NetFlow v9 could be extended with vendor specific types and many vendors define their own. There could be no netflow collector in the world that decodes all the specific vendor types. 134 | By default this library decodes in readable format all the types it recognises. All the unknown types are decoded as 'unknown_type_XXX' where XXX is the type ID. The data is provided as a HEX string. 135 | But you can extend the library yourself. You can even replace how current types are decoded. You can even do that on fly (you can dynamically change how the type is decoded in different periods of time). 136 | 137 | To understand how to do that, you have to learn a bit about the internals of how this module works. 138 | 139 | * When a new flowset template is received from the NetFlow Agent, this netflow module generates and compile (with new Function()) a decoding function 140 | * When a netflow is received for a known flowset template (we have a compiled function for it) - the function is simply executed 141 | 142 | This approach is quite simple and provides enormous performance. The function code is as small as possible and as well on first execution Node.JS compiles it with JIT and the result is really fast. 143 | 144 | The function code is generated with templates that contains the javascript code to be add for each netflow type, identified by its ID. 145 | 146 | Each template consist of an object of the following form: 147 | 148 | { name: 'property-name', compileRule: compileRuleObject } 149 | 150 | *compileRuleObject* contains rules how that netflow type to be decoded, depending on its length. 151 | The reason for that is, that some of the netflow types are variable length. And you may have to execute different code to decode them depending on the length. 152 | The *compileRuleObject* format is simple: 153 | 154 | { 155 | length: 'javascript code as a string that decode this value', 156 | ... 157 | } 158 | 159 | There is a special length property of 0. This code will be used, if there is no more specific decode defined for a length. For example: 160 | 161 | { 162 | 4: 'code used to decode this netflow type with length of 4', 163 | 8: 'code used to decode this netflow type with length of 8', 164 | 0: 'code used to decode ANY OTHER length' 165 | } 166 | 167 | ### decoding code 168 | 169 | The decoding code must be a string that contains javascript code. This code will be concatenated to the function body before compilation. If that code contain errors or simply does not work as expected it could crash the collector. So be careful. 170 | 171 | There are few variables you have to use: 172 | 173 | **$pos** - this string is replaced with a number containing the current position of the netflow type within the binary buffer. 174 | 175 | **$len** - this string is replaced with a number containing the length of the netflow type 176 | 177 | **$name** - this string is replaced with a string containing the name property of the netflow type (defined by you above) 178 | 179 | **buf** - is Node.JS Buffer object containing the Flow we want to decode 180 | 181 | **o** - this is the object where the decoded flow is written to. 182 | 183 | Everything else is pure javascript. It is good if you know the restrictions of the javascript and Node.JS capabilities of the Function() method, but not necessary to allow you to write simple decoding by yourself. 184 | 185 | If you want to decode a string, of variable length, you could write a compileRuleObject of the form: 186 | 187 | { 188 | 0: 'o["$name"] = buf.toString("utf8",$pos,$pos+$len)' 189 | } 190 | 191 | The example above will say that for this netfow type, whatever length it has, we will decode the value as utf8 string. 192 | 193 | ### Example 194 | 195 | Lets assume you want to write you own code for decoding a NetFlow type, lets say 4444, which could be of variable length, and contains a integer number. 196 | 197 | You can write a code like this: 198 | 199 | Collector({ 200 | port: 5000, 201 | nfTypes: { 202 | 4444: { // 4444 is the NetFlow Type ID which decoding we want to replace 203 | name: 'my_vendor_type4444', // This will be the property name, that will contain the decoded value, it will be also the value of the $name 204 | compileRule: { 205 | 1: "o['$name']=buf.readUInt8($pos);", // This is how we decode type of length 1 to a number 206 | 2: "o['$name']=buf.readUInt16BE($pos);", // This is how we decode type of length 2 to a number 207 | 3: "o['$name']=buf.readUInt8($pos)*65536+buf.readUInt16BE($pos+1);", // This is how we decode type of length 3 to a number 208 | 4: "o['$name']=buf.readUInt32BE($pos);", // This is how we decode type of length 4 to a number 209 | 5: "o['$name']=buf.readUInt8($pos)*4294967296+buf.readUInt32BE($pos+1);", // This is how we decode type of length 5 to a number 210 | 6: "o['$name']=buf.readUInt16BE($pos)*4294967296+buf.readUInt32BE($pos+2);", // This is how we decode type of length 6 to a number 211 | 8: "o['$name']=buf.readUInt32BE($pos)*4294967296+buf.readUInt32BE($pos+4);", // This is how we decode type of length 8 to a number 212 | 0: "o['$name']='Unsupported Length of $len';" 213 | } 214 | } 215 | }, 216 | cb: function (flow) { 217 | console.log(flow) 218 | } 219 | }); 220 | 221 | It looks to be a bit complex, but actually it is not. 222 | In most of the cases, you don't have to define a compile rule for each different length. 223 | The following example defines a decoding for a netflow type 6789 that carry a string: 224 | 225 | var colObj = Collector(function (flow) { 226 | console.log(flow) 227 | }); 228 | 229 | colObj.listen(5000); 230 | 231 | colObj.nfTypes[6789] = { 232 | name: 'vendor_string', 233 | compileRule: { 234 | 0: 'o["$name"] = buf.toString("utf8",$pos,$pos+$len);' // Never forget the ; at the end! 235 | } 236 | } 237 | 238 | As you can see, we can also change the decoding on fly, by defining a property for that netflow type within the nfTypes property of the colObj (the Collector object). 239 | Next time when the NetFlow Agent send us a NetFlow Template definition containing this netflow type, the new rule will be used (the routers usually send temlpates from time to time, so even currently compiled templates are recompiled). 240 | 241 | You could also overwrite the default property names where the decoded data is written. For example: 242 | 243 | 244 | var colObj = Collector(function (flow) { 245 | console.log(flow) 246 | }); 247 | colObj.listen(5000); 248 | 249 | colObj.nfTypes[14].name = 'outputInterface'; 250 | colObj.nfTypes[10].name = 'inputInterface'; 251 | 252 | 253 | 254 | ## Logging / Debugging the module 255 | 256 | You can use the debug module to turn on the logging, in order to debug how the library behave. 257 | The following example show you how: 258 | 259 | require('debug').enable('NetFlowV9'); 260 | var Collector = require('node-netflowv9'); 261 | Collector(function(flow) { 262 | console.log(flow); 263 | }).listen(5555); 264 | 265 | ## Proxy 266 | 267 | The netflow module allows being configured as proxy and to resend the netflow packets as-is to another destination(s) 268 | 269 | You can do that by using the proxy option in the configurations. For example: 270 | 271 | require('debug').enable('NetFlowV9'); 272 | var Collector = require('node-netflowv9'); 273 | Collector({ 274 | proxy: "127.0.0.1:55555", // It could be as well array or object if you need multiple destinations 275 | cb: function(flow) { 276 | console.log(flow); 277 | } 278 | }).listen(5555); 279 | 280 | In the example above every netflow packet received at port 5555 will be resent as well to 127.0.0.1:55555 281 | 282 | The examples bellow resends the packets to multiple destinations: 283 | 284 | require('debug').enable('NetFlowV9'); 285 | var Collector = require('node-netflowv9'); 286 | Collector({ 287 | proxy: [ "127.0.0.1:55555","5.5.5.5:5566" ], 288 | cb: function(flow) { 289 | console.log(flow); 290 | } 291 | }).listen(5555); 292 | 293 | Another example with multiple destinations: 294 | 295 | require('debug').enable('NetFlowV9'); 296 | var Collector = require('node-netflowv9'); 297 | Collector({ 298 | proxy: { 299 | "target1": "127.0.0.1:55555", 300 | "target2": "5.5.5.5:5566" 301 | }, 302 | cb: function(flow) { 303 | console.log(flow); 304 | } 305 | }).listen(5555); 306 | 307 | 308 | 309 | ## Multiple collectors 310 | 311 | The module allows you to define multiple collectors at the same time. 312 | For example: 313 | 314 | var Collector = require('node-netflowv9'); 315 | 316 | Collector(function(flow) { // Collector 1 listening on port 5555 317 | console.log(flow); 318 | }).listen(5555); 319 | 320 | Collector(function(flow) { // Collector 2 listening on port 6666 321 | console.log(flow); 322 | }).listen(6666); 323 | 324 | ## NetFlowV9 Options Template 325 | 326 | NetFlowV9 support Options template, where there could be an option Flow Set that contains data for a predefined fields within a certain scope. 327 | This module supports the Options Template and provides the output of it as it is any other flow. The only difference is that there is a property **isOption** set to true to remind to your code, that this data has come from an Option Template. 328 | 329 | Currently the following nfScope are supported - system, interface, line_card, netflow_cache. 330 | You can overwrite the decoding of them, or add another the same way (and using absolutley the same format) as you overwrite nfTypes. 331 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. -------------------------------------------------------------------------------- /js/nf9/nftypes.js: -------------------------------------------------------------------------------- 1 | var decNumRule = { 2 | 1: "o['$name']=buf.readUInt8($pos);", 3 | 2: "o['$name']=buf.readUInt16BE($pos);", 4 | 3: "o['$name']=buf.readUInt8($pos)*65536+buf.readUInt16BE($pos+1);", 5 | 4: "o['$name']=buf.readUInt32BE($pos);", 6 | 5: "o['$name']=buf.readUInt8($pos)*4294967296+buf.readUInt32BE($pos+1);", 7 | 6: "o['$name']=buf.readUInt16BE($pos)*4294967296+buf.readUInt32BE($pos+2);", 8 | 8: "o['$name']=buf.readUInt32BE($pos)*4294967296+buf.readUInt32BE($pos+4);" 9 | }; 10 | 11 | var decTimestamp = decNumRule; 12 | var decTsMs = decTimestamp; 13 | var decTsMcs = decTimestamp; 14 | var decTsNs = decTimestamp; 15 | 16 | var decIpv4Rule = { 17 | 4: "o['$name']=(t=buf.readUInt32BE($pos),(parseInt(t/16777216)%256)+'.'+(parseInt(t/65536)%256)+'.'+(parseInt(t/256)%256)+'.'+(t%256));" 18 | }; 19 | 20 | var decIpv6Rule = { 21 | 16: "o['$name']=buf.toString('hex',$pos,$pos+$len);" 22 | }; 23 | 24 | var decMacRule = { 25 | 0: "o['$name']=buf.toString('hex',$pos,$pos+$len);" 26 | }; 27 | 28 | var decStringRule = { 29 | 0: 'o[\'$name\']=buf.toString(\'utf8\',$pos,$pos+$len).replace(/\\0/g,\'\');' 30 | }; 31 | 32 | var decAsciiStringRule = { 33 | 0: 'o[\'$name\']=buf.toString(\'ascii\',$pos,$pos+$len).replace(/\\0/g,\'\');' 34 | }; 35 | 36 | var nfTypes = { 37 | 1: {name: 'in_bytes', compileRule: decNumRule}, 38 | 2: {name: 'in_pkts', compileRule: decNumRule}, 39 | 3: {name: 'flows', compileRule: decNumRule}, 40 | 4: {name: 'protocol', compileRule: decNumRule}, 41 | 5: {name: 'src_tos', compileRule: decNumRule}, 42 | 6: {name: 'tcp_flags', compileRule: decNumRule}, 43 | 7: {name: 'l4_src_port', compileRule: decNumRule}, 44 | 8: {name: 'ipv4_src_addr', compileRule: decIpv4Rule}, 45 | 9: {name: 'src_mask', compileRule: decNumRule}, 46 | 10: {name: 'input_snmp', compileRule: decNumRule}, 47 | 11: {name: 'l4_dst_port', compileRule: decNumRule}, 48 | 12: {name: 'ipv4_dst_addr', compileRule: decIpv4Rule}, 49 | 13: {name: 'dst_mask', compileRule: decNumRule}, 50 | 14: {name: 'output_snmp', compileRule: decNumRule}, 51 | 15: {name: 'ipv4_next_hop', compileRule: decIpv4Rule}, 52 | 16: {name: 'src_as', compileRule: decNumRule}, 53 | 17: {name: 'dst_as', compileRule: decNumRule}, 54 | 18: {name: 'bgp_ipv4_next_hop', compileRule: decIpv4Rule}, 55 | 19: {name: 'mul_dst_pkts', compileRule: decNumRule}, 56 | 20: {name: 'mul_dst_bytes', compileRule: decNumRule}, 57 | 21: {name: 'last_switched', compileRule: decNumRule}, 58 | 22: {name: 'first_switched', compileRule: decNumRule}, 59 | 23: {name: 'out_bytes', compileRule: decNumRule}, 60 | 24: {name: 'out_pkts', compileRule: decNumRule}, 61 | 25: {name: 'min_pkt_lngth', compileRule: decNumRule}, 62 | 26: {name: 'max_pkt_lngth', compileRule: decNumRule}, 63 | 27: {name: 'ipv6_src_addr', compileRule: decIpv6Rule}, 64 | 28: {name: 'ipv6_dst_addr', compileRule: decIpv6Rule}, 65 | 29: {name: 'ipv6_src_mask', compileRule: decNumRule}, 66 | 30: {name: 'ipv6_dst_mask', compileRule: decNumRule}, 67 | 31: {name: 'ipv6_flow_label', compileRule: decNumRule}, 68 | 32: {name: 'icmp_type', compileRule: decNumRule}, 69 | 33: {name: 'mul_igmp_type', compileRule: decNumRule}, 70 | 34: {name: 'sampling_interval', compileRule: decNumRule}, 71 | 35: {name: 'sampling_algorithm', compileRule: decNumRule}, 72 | 36: {name: 'flow_active_timeout', compileRule: decNumRule}, 73 | 37: {name: 'flow_inactive_timeout', compileRule: decNumRule}, 74 | 38: {name: 'engine_type', compileRule: decNumRule}, 75 | 39: {name: 'engine_id', compileRule: decNumRule}, 76 | 40: {name: 'total_bytes_exp', compileRule: decNumRule}, 77 | 41: {name: 'total_pkts_exp', compileRule: decNumRule}, 78 | 42: {name: 'total_flows_exp', compileRule: decNumRule}, 79 | 44: {name: 'ipv4_src_prefix', compileRule: decIpv4Rule}, 80 | 45: {name: 'ipv4_dst_prefix', compileRule: decIpv4Rule}, 81 | 46: {name: 'mpls_top_label_type', compileRule: decIpv4Rule}, 82 | 47: {name: 'mpls_top_label_ip_addr', compileRule: decIpv4Rule}, 83 | 48: {name: 'flow_sampler_id', compileRule: decNumRule}, 84 | 49: {name: 'flow_sampler_mode', compileRule: decNumRule}, 85 | 50: {name: 'flow_sampler_random_interval', compileRule: decNumRule}, 86 | 52: {name: 'min_ttl', compileRule: decNumRule}, 87 | 53: {name: 'max_ttl', compileRule: decNumRule}, 88 | 54: {name: 'ipv4_ident', compileRule: decNumRule}, 89 | 55: {name: 'dst_tos', compileRule: decNumRule}, 90 | 56: {name: 'in_src_mac', compileRule: decMacRule}, 91 | 57: {name: 'out_dst_mac', compileRule: decMacRule}, 92 | 58: {name: 'src_vlan', compileRule: decNumRule}, 93 | 59: {name: 'dst_vlan', compileRule: decNumRule}, 94 | 60: {name: 'ip_protocol_version', compileRule: decNumRule}, 95 | 61: {name: 'direction', compileRule: decNumRule}, 96 | 62: {name: 'ipv6_next_hop', compileRule: decIpv6Rule}, 97 | 63: {name: 'bpg_ipv6_next_hop', compileRule: decIpv6Rule}, 98 | 64: {name: 'ipv6_option_headers', compileRule: decNumRule}, 99 | 70: {name: 'mpls_label_1', compileRule: decNumRule}, 100 | 71: {name: 'mpls_label_2', compileRule: decNumRule}, 101 | 72: {name: 'mpls_label_3', compileRule: decNumRule}, 102 | 73: {name: 'mpls_label_4', compileRule: decNumRule}, 103 | 74: {name: 'mpls_label_5', compileRule: decNumRule}, 104 | 75: {name: 'mpls_label_6', compileRule: decNumRule}, 105 | 76: {name: 'mpls_label_7', compileRule: decNumRule}, 106 | 77: {name: 'mpls_label_8', compileRule: decNumRule}, 107 | 78: {name: 'mpls_label_9', compileRule: decNumRule}, 108 | 79: {name: 'mpls_label_10', compileRule: decNumRule}, 109 | 80: {name: 'in_dst_mac', compileRule: decMacRule}, 110 | 81: {name: 'out_src_mac', compileRule: decMacRule}, 111 | 82: {name: 'if_name', compileRule: decStringRule}, 112 | 83: {name: 'if_desc', compileRule: decStringRule}, 113 | 84: {name: 'sampler_name', compileRule: decStringRule}, 114 | 85: {name: 'in_permanent_bytes', compileRule: decNumRule}, 115 | 86: {name: 'in_permanent_pkts', compileRule: decNumRule}, 116 | 87: {name: 'flagsAndSamplerId', compileRule: decNumRule}, // Deprecated 117 | 88: {name: 'fragment_offset', compileRule: decNumRule}, 118 | 89: {name: 'fw_status', compileRule: decNumRule}, 119 | 90: {name: 'mpls_pal_rd', compileRule: decNumRule}, 120 | 91: {name: 'mpls_prefix_len', compileRule: decNumRule}, 121 | 92: {name: 'src_traffic_index', compileRule: decNumRule}, 122 | 93: {name: 'dst_traffic_index', compileRule: decNumRule}, 123 | 94: {name: 'application_descr', compileRule: decStringRule}, 124 | 95: {name: 'application_tag', compileRule: decMacRule}, 125 | 96: {name: 'application_name', compileRule: decStringRule}, 126 | 98: {name: 'postIpDiffServCodePoint', compileRule: decNumRule}, 127 | 99: {name: 'replication_factor', compileRule: decNumRule}, 128 | 100: {name: 'className', compileRule: decStringRule}, 129 | 101: {name: 'classificationEngineId', compileRule: decNumRule}, 130 | 102: {name: 'layer2packetSectionOffset', compileRule: decNumRule}, // Deprecated 131 | 103: {name: 'layer2packetSectionSize', compileRule: decNumRule}, // Deprecated 132 | 104: {name: 'layer2packetSectionData', compileRule: decMacRule}, 133 | //above 127 is in ipfix 134 | 128: {name: 'in_as', compileRule: decNumRule}, 135 | 129: {name: 'out_as', compileRule: decNumRule}, 136 | 130: {name: 'exporterIPv4Address', compileRule: decIpv4Rule}, 137 | 131: {name: 'exporterIPv6Address', compileRule: decIpv6Rule}, 138 | 132: {name: 'droppedOctetDeltaCount', compileRule: decNumRule}, 139 | 133: {name: 'droppedPacketDeltaCount', compileRule: decNumRule}, 140 | 134: {name: 'droppedOctetTotalCount', compileRule: decNumRule}, 141 | 135: {name: 'droppedPacketTotalCount', compileRule: decNumRule}, 142 | 136: {name: 'flowEndReason', compileRule: decNumRule}, 143 | 137: {name: 'commonPropertiesId', compileRule: decNumRule}, 144 | 138: {name: 'observationPointId', compileRule: decNumRule}, 145 | 139: {name: 'icmpTypeCodeIPv6', compileRule: decNumRule}, 146 | 140: {name: 'mplsTopLabelIPv6Address', compileRule: decIpv6Rule}, 147 | 141: {name: 'lineCardId', compileRule: decNumRule}, 148 | 142: {name: 'portId', compileRule: decNumRule}, 149 | 143: {name: 'meteringProcessId', compileRule: decNumRule}, 150 | 144: {name: 'exportingProcessId', compileRule: decNumRule}, 151 | 145: {name: 'templateId', compileRule: decNumRule}, 152 | 146: {name: 'wlanChannelId', compileRule: decNumRule}, 153 | 147: {name: 'wlanSSID', compileRule: decStringRule}, 154 | 148: {name: 'flowId', compileRule: decNumRule}, 155 | 149: {name: 'observationDomainId', compileRule: decNumRule}, 156 | 150: {name: 'flowStartSeconds', compileRule: decTimestamp}, 157 | 151: {name: 'flowEndSeconds', compileRule: decTimestamp}, 158 | 152: {name: 'flowStartMilliseconds', compileRule: decTsMs}, 159 | 153: {name: 'flowEndMilliseconds', compileRule: decTsMs}, 160 | 154: {name: 'flowStartMicroseconds', compileRule: decTsMcs}, 161 | 155: {name: 'flowEndMicroseconds', compileRule: decTsMcs}, 162 | 156: {name: 'flowStartNanoseconds', compileRule: decTsNs}, 163 | 157: {name: 'flowEndNanoseconds', compileRule: decTsNs}, 164 | 158: {name: 'flowStartDeltaMicroseconds', compileRule: decNumRule}, 165 | 159: {name: 'flowEndDeltaMicroseconds', compileRule: decNumRule}, 166 | 160: {name: 'systemInitTimeMilliseconds', compileRule: decTsMs}, 167 | 161: {name: 'flowDurationMilliseconds', compileRule: decNumRule}, 168 | 162: {name: 'flowDurationMicroseconds', compileRule: decNumRule}, 169 | 163: {name: 'observedFlowTotalCount', compileRule: decNumRule}, 170 | 164: {name: 'ignoredPacketTotalCount', compileRule: decNumRule}, 171 | 165: {name: 'ignoredOctetTotalCount', compileRule: decNumRule}, 172 | 166: {name: 'notSentFlowTotalCount', compileRule: decNumRule}, 173 | 167: {name: 'notSentPacketTotalCount', compileRule: decNumRule}, 174 | 168: {name: 'notSentOctetTotalCount', compileRule: decNumRule}, 175 | 169: {name: 'destinationIPv6Prefix', compileRule: decIpv6Rule}, 176 | 170: {name: 'sourceIPv6Prefix', compileRule: decIpv6Rule}, 177 | 171: {name: 'postOctetTotalCount', compileRule: decNumRule}, 178 | 172: {name: 'postPacketTotalCount', compileRule: decNumRule}, 179 | 173: {name: 'flowKeyIndicator', compileRule: decNumRule}, 180 | 174: {name: 'postMCastPacketTotalCount', compileRule: decNumRule}, 181 | 175: {name: 'postMCastOctetTotalCount', compileRule: decNumRule}, 182 | 176: {name: 'icmpTypeIPv4', compileRule: decNumRule}, 183 | 177: {name: 'icmpCodeIPv4', compileRule: decNumRule}, 184 | 178: {name: 'icmpTypeIPv6', compileRule: decNumRule}, 185 | 179: {name: 'icmpCodeIPv6', compileRule: decNumRule}, 186 | 180: {name: 'udpSourcePort', compileRule: decNumRule}, 187 | 181: {name: 'udpDestinationPort', compileRule: decNumRule}, 188 | 182: {name: 'tcpSourcePort', compileRule: decNumRule}, 189 | 183: {name: 'tcpDestinationPort', compileRule: decNumRule}, 190 | 184: {name: 'tcpSequenceNumber', compileRule: decNumRule}, 191 | 185: {name: 'tcpAcknowledgementNumber', compileRule: decNumRule}, 192 | 186: {name: 'tcpWindowSize', compileRule: decNumRule}, 193 | 187: {name: 'tcpUrgentPointer', compileRule: decNumRule}, 194 | 188: {name: 'tcpHeaderLength', compileRule: decNumRule}, 195 | 189: {name: 'ipHeaderLength', compileRule: decNumRule}, 196 | 190: {name: 'totalLengthIPv4', compileRule: decNumRule}, 197 | 191: {name: 'payloadLengthIPv6', compileRule: decNumRule}, 198 | 192: {name: 'ipTTL', compileRule: decNumRule}, 199 | 193: {name: 'nextHeaderIPv6', compileRule: decNumRule}, 200 | 194: {name: 'mplsPayloadLength', compileRule: decNumRule}, 201 | 195: {name: 'ipDiffServCodePoint', compileRule: decNumRule}, 202 | //the following are taken from from http://www.iana.org/assignments/ipfix/ipfix.xhtml 203 | 196: {name: 'ipPrecedence', compileRule: decNumRule}, 204 | 197: {name: 'fragmentFlags', compileRule: decNumRule}, 205 | 198: {name: 'octetDeltaSumOfSquares', compileRule: decNumRule}, 206 | 199: {name: 'octetTotalSumOfSquares', compileRule: decNumRule}, 207 | 200: {name: 'mplsTopLabelTTL', compileRule: decNumRule}, 208 | 201: {name: 'mplsLabelStackLength', compileRule: decNumRule}, 209 | 202: {name: 'mplsLabelStackDepth', compileRule: decNumRule}, 210 | 203: {name: 'mplsTopLabelExp', compileRule: decNumRule}, 211 | 204: {name: 'ipPayloadLength', compileRule: decNumRule}, 212 | 205: {name: 'udpMessageLength', compileRule: decNumRule}, 213 | 206: {name: 'isMulticast', compileRule: decNumRule}, 214 | 207: {name: 'ipv4IHL', compileRule: decNumRule}, 215 | 208: {name: 'ipv4Options', compileRule: decNumRule}, 216 | 209: {name: 'tcpOptions', compileRule: decNumRule}, 217 | 210: {name: 'paddingOctets', compileRule: decMacRule}, 218 | 211: {name: 'collectorIPv4Address', compileRule: decIpv4Rule}, 219 | 212: {name: 'collectorIPv6Address', compileRule: decIpv6Rule}, 220 | 213: {name: 'exportInterface', compileRule: decNumRule}, 221 | 214: {name: 'exportProtocolVersion', compileRule: decNumRule}, 222 | 215: {name: 'exportTransportProtocol', compileRule: decNumRule}, 223 | 216: {name: 'collectorTransportPort', compileRule: decNumRule}, 224 | 217: {name: 'exporterTransportPort', compileRule: decNumRule}, 225 | 218: {name: 'tcpSynTotalCount', compileRule: decNumRule}, 226 | 219: {name: 'tcpFinTotalCount', compileRule: decNumRule}, 227 | 220: {name: 'tcpRstTotalCount', compileRule: decNumRule}, 228 | 221: {name: 'tcpPshTotalCount', compileRule: decNumRule}, 229 | 222: {name: 'tcpAckTotalCount', compileRule: decNumRule}, 230 | 223: {name: 'tcpUrgTotalCount', compileRule: decNumRule}, 231 | 224: {name: 'ipTotalLength', compileRule: decNumRule}, 232 | 225: {name: 'postNATSourceIPv4Address', compileRule: decIpv4Rule}, 233 | 226: {name: 'postNATDestinationIPv4Address', compileRule: decIpv4Rule}, 234 | 227: {name: 'postNAPTSourceTransportPort', compileRule: decNumRule}, 235 | 228: {name: 'postNAPTDestinationTransportPort', compileRule: decNumRule}, 236 | 229: {name: 'natOriginatingAddressRealm', compileRule: decNumRule}, 237 | 230: {name: 'natEvent', compileRule: decNumRule}, 238 | 231: {name: 'initiatorOctets', compileRule: decNumRule}, 239 | 232: {name: 'responderOctets', compileRule: decNumRule}, 240 | 233: {name: 'firewallEvent', compileRule: decNumRule}, 241 | 234: {name: 'ingressVRFID', compileRule: decNumRule}, 242 | 235: {name: 'egressVRFID', compileRule: decNumRule}, 243 | 236: {name: 'VRFname', compileRule: decStringRule}, 244 | 237: {name: 'postMplsTopLabelExp', compileRule: decNumRule}, 245 | 238: {name: 'tcpWindowScale', compileRule: decNumRule}, 246 | 239: {name: 'biflow_direction', compileRule: decNumRule}, 247 | 240: {name: 'ethernetHeaderLength', compileRule: decNumRule}, 248 | 241: {name: 'ethernetPayloadLength', compileRule: decNumRule}, 249 | 242: {name: 'ethernetTotalLength', compileRule: decNumRule}, 250 | 243: {name: 'dot1qVlanId', compileRule: decNumRule}, 251 | 244: {name: 'dot1qPriority', compileRule: decNumRule}, 252 | 245: {name: 'dot1qCustomerVlanId', compileRule: decNumRule}, 253 | 246: {name: 'dot1qCustomerPriority', compileRule: decNumRule}, 254 | 247: {name: 'metroEvcId', compileRule: decStringRule}, 255 | 248: {name: 'metroEvcType', compileRule: decNumRule}, 256 | 249: {name: 'pseudoWireId', compileRule: decNumRule}, 257 | 250: {name: 'pseudoWireType', compileRule: decNumRule}, 258 | 251: {name: 'pseudoWireControlWord', compileRule: decNumRule}, 259 | 252: {name: 'ingressPhysicalInterface', compileRule: decNumRule}, 260 | 253: {name: 'egressPhysicalInterface', compileRule: decNumRule}, 261 | 254: {name: 'postDot1qVlanId', compileRule: decNumRule}, 262 | 255: {name: 'postDot1qCustomerVlanId', compileRule: decNumRule}, 263 | 256: {name: 'ethernetType', compileRule: decNumRule}, 264 | 257: {name: 'postIpPrecedence', compileRule: decNumRule}, 265 | 258: {name: 'collectionTimeMilliseconds', compileRule: decTsMs}, 266 | 259: {name: 'exportSctpStreamId', compileRule: decNumRule}, 267 | 260: {name: 'maxExportSeconds', compileRule: decTimestamp}, 268 | 261: {name: 'maxFlowEndSeconds', compileRule: decTimestamp}, 269 | 262: {name: 'messageMD5Checksum', compileRule: decMacRule}, 270 | 263: {name: 'messageScope', compileRule: decNumRule}, 271 | 264: {name: 'minExportSeconds', compileRule: decTimestamp}, 272 | 265: {name: 'minFlowStartSeconds', compileRule: decTimestamp}, 273 | 266: {name: 'opaqueOctets', compileRule: decMacRule}, 274 | 267: {name: 'sessionScope', compileRule: decNumRule}, 275 | 268: {name: 'maxFlowEndMicroseconds', compileRule: decTsMcs}, 276 | 269: {name: 'maxFlowEndMilliseconds', compileRule: decTsMs}, 277 | 270: {name: 'maxFlowEndNanoseconds', compileRule: decTsNs}, 278 | 271: {name: 'minFlowStartMicroseconds', compileRule: decTsMcs}, 279 | 272: {name: 'minFlowStartMilliseconds', compileRule: decTsMs}, 280 | 273: {name: 'minFlowStartNanoseconds', compileRule: decTsNs}, 281 | 274: {name: 'collectorCertificate', compileRule: decMacRule}, 282 | 275: {name: 'exporterCertificate', compileRule: decMacRule}, 283 | 276: {name: 'dataRecordsReliability', compileRule: decNumRule}, 284 | 277: {name: 'observationPointType', compileRule: decNumRule}, 285 | 278: {name: 'connectionCountNew', compileRule: decNumRule}, 286 | 279: {name: 'connectionSumDuration', compileRule: decNumRule}, 287 | 280: {name: 'conn_tx_id',compileRule: decNumRule}, 288 | // 289 | 281: {name: 'postNATSourceIPv6Address',compileRule: decIpv6Rule}, 290 | 282: {name: 'postNATDestinationIPv6Address',compileRule: decIpv6Rule}, 291 | 283: {name: 'natPoolId',compileRule: decNumRule}, 292 | 284: {name: 'natPoolName',compileRule: decStringRule}, 293 | 285: {name: 'anonymizationFlags',compileRule: decNumRule}, 294 | 286: {name: 'anonymizationTechnique',compileRule: decNumRule}, 295 | 287: {name: 'informationElementIndex',compileRule: decNumRule}, 296 | 288: {name: 'p2pTechnology',compileRule: decStringRule}, 297 | 289: {name: 'tunnelTechnology',compileRule: decStringRule}, 298 | 290: {name: 'encryptedTechnology',compileRule: decStringRule}, 299 | // 291: {name: 'basicList',compileRule: decNumRule}, // List type, not yet supported 300 | // 292: {name: 'subTemplateList',compileRule: decNumRule}, 301 | // 293: {name: 'subTemplateMultiList',compileRule: decNumRule}, 302 | 294: {name: 'bgpValidityState',compileRule: decNumRule}, 303 | 295: {name: 'IPSecSPI',compileRule: decNumRule}, 304 | 296: {name: 'greKey',compileRule: decNumRule}, 305 | 297: {name: 'natType',compileRule: decNumRule}, 306 | 298: {name: 'initiatorPackets',compileRule: decNumRule}, 307 | 299: {name: 'responderPackets',compileRule: decNumRule}, 308 | 300: {name: 'observationDomainName',compileRule: decStringRule}, 309 | 301: {name: 'selectionSequenceId',compileRule: decNumRule}, 310 | 302: {name: 'selectorId',compileRule: decNumRule}, 311 | 303: {name: 'informationElementId',compileRule: decNumRule}, 312 | 304: {name: 'selectorAlgorithm',compileRule: decNumRule}, 313 | 305: {name: 'samplingPacketInterval',compileRule: decNumRule}, 314 | 306: {name: 'samplingPacketSpace',compileRule: decNumRule}, 315 | 307: {name: 'samplingTimeInterval',compileRule: decNumRule}, 316 | 308: {name: 'samplingTimeSpace',compileRule: decNumRule}, 317 | 309: {name: 'samplingSize',compileRule: decNumRule}, 318 | 310: {name: 'samplingPopulation',compileRule: decNumRule}, 319 | // 311: {name: 'samplingProbability',compileRule: decNumRule}, // Float type has to be introduced 320 | 312: {name: 'dataLinkFrameSize',compileRule: decNumRule}, 321 | 313: {name: 'ipHeaderPacketSection',compileRule: decMacRule}, 322 | 314: {name: 'ipPayloadPacketSection',compileRule: decMacRule}, 323 | 315: {name: 'dataLinkFrameSection',compileRule: decMacRule}, 324 | 316: {name: 'mplsLabelStackSection',compileRule: decMacRule}, 325 | 317: {name: 'mplsPayloadPacketSection',compileRule: decMacRule}, 326 | 318: {name: 'selectorIdTotalPktsObserved',compileRule: decNumRule}, 327 | 319: {name: 'selectorIdTotalPktsSelected',compileRule: decNumRule}, 328 | // 320: {name: 'absoluteError',compileRule: decNumRule}, // Float type 329 | // 321: {name: 'relativeError',compileRule: decNumRule}, // Float type 330 | 322: {name: 'observationTimeSeconds',compileRule: decTimestamp}, 331 | 323: {name: 'observationTimeMilliseconds',compileRule: decTsMs}, 332 | 324: {name: 'observationTimeMicroseconds',compileRule: decTsMcs}, 333 | 325: {name: 'observationTimeNanoseconds',compileRule: decTsNs}, 334 | 326: {name: 'digestHashValue',compileRule: decNumRule}, 335 | 327: {name: 'hashIPPayloadOffset',compileRule: decNumRule}, 336 | 328: {name: 'hashIPPayloadSize',compileRule: decNumRule}, 337 | 329: {name: 'hashOutputRangeMin',compileRule: decNumRule}, 338 | 330: {name: 'hashOutputRangeMax',compileRule: decNumRule}, 339 | 331: {name: 'hashSelectedRangeMin',compileRule: decNumRule}, 340 | 332: {name: 'hashSelectedRangeMax',compileRule: decNumRule}, 341 | 333: {name: 'hashDigestOutput',compileRule: decNumRule}, 342 | 334: {name: 'hashInitialiserValue',compileRule: decNumRule}, 343 | 335: {name: 'selectorName',compileRule: decStringRule}, 344 | // 336: {name: 'upperCILimit',compileRule: decNumRule}, // Float type 345 | // 337: {name: 'lowerCILimit',compileRule: decNumRule}, // Float 346 | // 338: {name: 'confidenceLevel',compileRule: decNumRule}, // Float 347 | 339: {name: 'informationElementDataType',compileRule: decNumRule}, 348 | 340: {name: 'informationElementDescription',compileRule: decStringRule}, 349 | 341: {name: 'informationElementName',compileRule: decStringRule}, 350 | 342: {name: 'informationElementRangeBegin',compileRule: decNumRule}, 351 | 343: {name: 'informationElementRangeEnd',compileRule: decNumRule}, 352 | 344: {name: 'informationElementSemantics',compileRule: decNumRule}, 353 | 345: {name: 'informationElementUnits',compileRule: decNumRule}, 354 | 346: {name: 'privateEnterpriseNumber',compileRule: decNumRule}, 355 | 347: {name: 'virtualStationInterfaceId',compileRule: decMacRule}, 356 | 348: {name: 'virtualStationInterfaceName',compileRule: decStringRule}, 357 | 349: {name: 'virtualStationUUID',compileRule: decMacRule}, 358 | 350: {name: 'virtualStationName',compileRule: decStringRule}, 359 | 351: {name: 'layer2SegmentId',compileRule: decNumRule}, 360 | 352: {name: 'layer2OctetDeltaCount',compileRule: decNumRule}, 361 | 353: {name: 'layer2OctetTotalCount',compileRule: decNumRule}, 362 | 354: {name: 'ingressUnicastPacketTotalCount',compileRule: decNumRule}, 363 | 355: {name: 'ingressMulticastPacketTotalCount',compileRule: decNumRule}, 364 | 356: {name: 'ingressBroadcastPacketTotalCount',compileRule: decNumRule}, 365 | 357: {name: 'egressUnicastPacketTotalCount',compileRule: decNumRule}, 366 | 358: {name: 'egressBroadcastPacketTotalCount',compileRule: decNumRule}, 367 | 359: {name: 'monitoringIntervalStartMilliSeconds',compileRule: decTsMs}, 368 | 360: {name: 'monitoringIntervalEndMilliSeconds',compileRule: decTsMs}, 369 | 361: {name: 'portRangeStart',compileRule: decNumRule}, 370 | 362: {name: 'portRangeEnd',compileRule: decNumRule}, 371 | 363: {name: 'portRangeStepSize',compileRule: decNumRule}, 372 | 364: {name: 'portRangeNumPorts',compileRule: decNumRule}, 373 | 365: {name: 'staMacAddress',compileRule: decMacRule}, 374 | 366: {name: 'staIPv4Address',compileRule: decIpv4Rule}, 375 | 367: {name: 'wtpMacAddress',compileRule: decMacRule}, 376 | 368: {name: 'ingressInterfaceType',compileRule: decNumRule}, 377 | 369: {name: 'egressInterfaceType',compileRule: decNumRule}, 378 | 370: {name: 'rtpSequenceNumber',compileRule: decNumRule}, 379 | 371: {name: 'userName',compileRule: decStringRule}, 380 | 372: {name: 'applicationCategoryName',compileRule: decStringRule}, 381 | 373: {name: 'applicationSubCategoryName',compileRule: decStringRule}, 382 | 374: {name: 'applicationGroupName',compileRule: decStringRule}, 383 | 375: {name: 'originalFlowsPresent',compileRule: decNumRule}, 384 | 376: {name: 'originalFlowsInitiated',compileRule: decNumRule}, 385 | 377: {name: 'originalFlowsCompleted',compileRule: decNumRule}, 386 | 378: {name: 'distinctCountOfSourceIPAddress',compileRule: decNumRule}, 387 | 379: {name: 'distinctCountOfDestinationIPAddress',compileRule: decNumRule}, 388 | 380: {name: 'distinctCountOfSourceIPv4Address',compileRule: decNumRule}, 389 | 381: {name: 'distinctCountOfDestinationIPv4Address',compileRule: decNumRule}, 390 | 382: {name: 'distinctCountOfSourceIPv6Address',compileRule: decNumRule}, 391 | 383: {name: 'distinctCountOfDestinationIPv6Address',compileRule: decNumRule}, 392 | 384: {name: 'valueDistributionMethod',compileRule: decNumRule}, 393 | 385: {name: 'rfc3550JitterMilliseconds',compileRule: decNumRule}, 394 | 386: {name: 'rfc3550JitterMicroseconds',compileRule: decNumRule}, 395 | 387: {name: 'rfc3550JitterNanoseconds',compileRule: decNumRule}, 396 | 388: {name: 'dot1qDEI',compileRule: decNumRule}, 397 | 389: {name: 'dot1qCustomerDEI',compileRule: decNumRule}, 398 | 390: {name: 'flowSelectorAlgorithm',compileRule: decNumRule}, 399 | 391: {name: 'flowSelectedOctetDeltaCount',compileRule: decNumRule}, 400 | 392: {name: 'flowSelectedPacketDeltaCount',compileRule: decNumRule}, 401 | 393: {name: 'flowSelectedFlowDeltaCount',compileRule: decNumRule}, 402 | 394: {name: 'selectorIDTotalFlowsObserved',compileRule: decNumRule}, 403 | 395: {name: 'selectorIDTotalFlowsSelected',compileRule: decNumRule}, 404 | 396: {name: 'samplingFlowInterval',compileRule: decNumRule}, 405 | 397: {name: 'samplingFlowSpacing',compileRule: decNumRule}, 406 | 398: {name: 'flowSamplingTimeInterval',compileRule: decNumRule}, 407 | 399: {name: 'flowSamplingTimeSpacing',compileRule: decNumRule}, 408 | 400: {name: 'hashFlowDomain',compileRule: decNumRule}, 409 | 401: {name: 'transportOctetDeltaCount',compileRule: decNumRule}, 410 | 402: {name: 'transportPacketDeltaCount',compileRule: decNumRule}, 411 | 403: {name: 'originalExporterIPv4Address',compileRule: decIpv4Rule}, 412 | 404: {name: 'originalExporterIPv6Address',compileRule: decIpv6Rule}, 413 | 405: {name: 'originalObservationDomainId',compileRule: decNumRule}, 414 | 406: {name: 'intermediateProcessId',compileRule: decNumRule}, 415 | 407: {name: 'ignoredDataRecordTotalCount',compileRule: decNumRule}, 416 | 408: {name: 'dataLinkFrameType',compileRule: decNumRule}, 417 | 409: {name: 'sectionOffset',compileRule: decNumRule}, 418 | 410: {name: 'sectionExportedOctets',compileRule: decNumRule}, 419 | 411: {name: 'dot1qServiceInstanceTag',compileRule: decMacRule}, 420 | 412: {name: 'dot1qServiceInstanceId',compileRule: decNumRule}, 421 | 413: {name: 'dot1qServiceInstancePriority',compileRule: decNumRule}, 422 | 414: {name: 'dot1qCustomerSourceMacAddress',compileRule: decMacRule}, 423 | 415: {name: 'dot1qCustomerDestinationMacAddress',compileRule: decMacRule}, 424 | 417: {name: 'postLayer2OctetDeltaCount',compileRule: decNumRule}, 425 | 418: {name: 'postMCastLayer2OctetDeltaCount',compileRule: decNumRule}, 426 | 420: {name: 'postLayer2OctetTotalCount',compileRule: decNumRule}, 427 | 421: {name: 'postMCastLayer2OctetTotalCount',compileRule: decNumRule}, 428 | 422: {name: 'minimumLayer2TotalLength',compileRule: decNumRule}, 429 | 423: {name: 'maximumLayer2TotalLength',compileRule: decNumRule}, 430 | 424: {name: 'droppedLayer2OctetDeltaCount',compileRule: decNumRule}, 431 | 425: {name: 'droppedLayer2OctetTotalCount',compileRule: decNumRule}, 432 | 426: {name: 'ignoredLayer2OctetTotalCount',compileRule: decNumRule}, 433 | 427: {name: 'notSentLayer2OctetTotalCount',compileRule: decNumRule}, 434 | 428: {name: 'layer2OctetDeltaSumOfSquares',compileRule: decNumRule}, 435 | 429: {name: 'layer2OctetTotalSumOfSquares',compileRule: decNumRule}, 436 | 430: {name: 'layer2FrameDeltaCount',compileRule: decNumRule}, 437 | 431: {name: 'layer2FrameTotalCount',compileRule: decNumRule}, 438 | 432: {name: 'pseudoWireDestinationIPv4Address',compileRule: decIpv4Rule}, 439 | 433: {name: 'ignoredLayer2FrameTotalCount',compileRule: decNumRule}, 440 | 33000: {name: 'inputACL', compileRule: decMacRule}, 441 | 33001: {name: 'outputACL', compileRule: decMacRule}, 442 | 33002: {name: 'firewallExtendedEvent', compileRule: decNumRule}, 443 | 40000: {name: 'username', compileRule: decAsciiStringRule} 444 | }; 445 | 446 | var nfScope = { 447 | 1: { name: 'scope_system', compileRule: decMacRule }, 448 | 2: { name: 'scope_interface', compileRule: decStringRule }, 449 | 3: { name: 'scope_linecard', compileRule: decNumRule }, 450 | 4: { name: 'scope_netflow_cache', compileRule: decNumRule }, 451 | 5: { name: 'scope_template', compileRule: decStringRule } 452 | }; 453 | 454 | module.exports = { 455 | nfTypes: nfTypes, 456 | nfScope: nfScope 457 | }; 458 | --------------------------------------------------------------------------------