代码拉取完成,页面将自动刷新
同步操作将从 hh2o4/visualization_NS3 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
var fs = require('fs'),
path = require('path');
var ROOT = path.resolve(__dirname, '../traces/self_defined_traces/');
var currentFlow,
currentFlowSizeCDFRule,
currentPacketSizeCDFRule,
currentPacketIntervalCDFRule;
var protoMap = {
'SMTP': 1,
'HTTP': 1,
'FTP': 0,
'DNS': 0
};
function getRandom(cdf) {
var random = Math.random(),
value;
for (var i = 0, len = cdf.length; i < len; i++) {
if (random <= parseFloat(cdf[i].cdf)) {
if (i == 0) {
value = Math.random() * parseInt(cdf[i].value);
} else {
value = Math.random() * (parseInt(cdf[i].value) - parseInt(cdf[i-1].value));
}
value = Math.floor(value);
break;
}
}
return value;
}
function generateFlowByCDF(startTime, simuTime, fileName) {
var random, flowSize, packetSize,
currentTime = startTime,
stopTime = startTime,
index = 0,
packets = [];
// generate flow size
flowSize = getRandom(currentFlowSizeCDFRule);
// generate packets of the flow
while (currentTime <= simuTime) {
packetSize = getRandom(currentPacketSizeCDFRule);
if (packetSize > flowSize) break;
flowSize -= packetSize;
packets.push([index++, 'I', currentTime-startTime, packetSize].join(' '));
stopTime = currentTime;
currentTime += getRandom(currentPacketIntervalCDFRule);
}
// write packets to file
fs.writeFileSync(fileName, packets.join('\n'));
return stopTime;
}
/**
* Main Entry
*/
function generateFlowDescription(simuTime, flow, rule) {
// UNIT: us
simuTime *= 1000000;
currentFlow = flow;
currentFlowSizeCDFRule = rule.flowSize;
currentPacketSizeCDFRule = rule.packetSize;
currentPacketIntervalCDFRule = rule.packetInterval;
var fileName = [flow.src, flow.dst, flow.proto, flow.num].join('-'),
content = '',
server = [],
startTime, stopTime, dstPort, tos, outFile;
for (var i = 0, len = Number(flow.num); i < len; i++) {
outFile = path.resolve(ROOT, fileName + '-' + i + '.txt');
dstPort = Math.floor(Math.random() * 90 + 10);
tos = Math.floor(Math.random() * 3);
startTime = Math.floor(Math.random()*simuTime);
stopTime = generateFlowByCDF(startTime, simuTime, outFile);
server.push([flow.dst, dstPort, protoMap[flow.proto]].join('-'));
content += [flow.src, flow.dst, dstPort, outFile, tos, startTime / 1000000, stopTime / 1000000, protoMap[flow.proto], '\n'].join(' ');
}
console.log("[SIMULATION] content from self-defined cdf are\n", content);
return {
content: content,
server: server
};
}
// module exports
exports.generateFlowDescription = generateFlowDescription;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。