Script To Generate Test Data

From Observer GigaFlow Support | VIAVI Solutions Inc.
Jump to: navigation, search
//{"runPeriod":2000,"paused":false,
// "description":"Script to create flows"
// }
//Created by Kevin Wilkie 03/05/2022
var deviceCount=1;//up to 255
var flowCount=100;
var apps=2000;
var interfaces=10;
var debug = false;
var utils = Java.type('ros.CROSUtils');
var CFlowRecord = Java.type('ros.servers.CFlowRecord');
var deviceManager = actions.getDeviceManager();
var meta=utils.getJSONFromString("{}");
function createFlow(deviceip, interfaces, flows,apps) {
   var device = deviceManager.getDevice(utils.inet_atoi(deviceip), 5, new Date().getTime());
   for (var i = 0; i < flows; i++) {
       var flowRecord = new CFlowRecord();
       flowRecord.device = device;
       flowRecord.starttime = Date.now();
       flowRecord.now =  flowRecord.starttime;
       flowRecord.duration = getRandomInt(60, 0);
       flowRecord.srcport = getRandomInt(apps, 22);
       flowRecord.dstport =  flowRecord.srcport+1024;
       flowRecord.srcadd = utils.inet_atob("172.1."+(device.uniquedeviceid%2)+"."+getRandomInt(2,1));
       flowRecord.dstadd = utils.inet_atob("172.2.1."+(device.uniquedeviceid%10));
       flowRecord.outif = Math.abs(flowRecord.srcadd.intValue()%interfaces)+1;
       flowRecord.inif = Math.abs(flowRecord.dstadd.intValue()%interfaces)+1;
       flowRecord.proto = 6;
       flowRecord.packets = getRandomInt(10000, 1);
       flowRecord.bytes = parseInt( getRandomInt(100,1)*flowRecord.packets);
       // flowRecord.url="";
       // flowRecord.fwextcode="";
       // flowRecord.fwevent = actions.addFWEvent(read[headingHash.get("action")]);
       flowRecord.meta = meta;
       // log.warn(device.getIP() );
       // log.warn(device.getIP() + " " + flowRecord);
       // log.warn(device.getIP() + " " + flowRecord.device);
       device.process(flowRecord);
   }
}
function getRandomInt(m, offset) {
    return Math.floor(Math.random() * m) + offset;
}
for (var i=1;i<=deviceCount;i++) {
    createFlow("1.2.0."+i, interfaces, flowCount,apps);
}
log.warn("Creating test data of "+(deviceCount*flowCount)+" flows across "+deviceCount+" devices.");