UNPKG

kaanalnet

Version:

Virtual Network Emulator Lab for SDN and traditional networks

298 lines (250 loc) 11.5 kB
// Generated by CoffeeScript 1.9.3 (function() { var DeviceDel, DeviceGet, DeviceStart, DeviceStop, argv, async, config, fs, log, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, restify, server, systemcheck, testSuiteDelete, testSuiteGet, testSuiteList, testSuitePost, topology, topologyDelete, topologyGet, topologyList, topologyPost, util; restify = require('restify'); util = require('util'); fs = require('fs'); async = require('async'); argv = require('minimist')(process.argv.slice(2)); if (argv.h != null) { console.log("-h view this help\n-l logfile (default: /var/log/kaanalnet.log)\n-z log level: (trace, debug, info, warn, error - default value: info)\n-C sdn controller ip (Ex: tcp:0.0.0.0:6633 - No default values) \n-S switch type (openvswitch' or linuxbridge , default : linuxbridge)\n-W wan subnet (default - 172.17.1.0)\n-L Lan subnet (default - 10.10.10.0)\n-M Mgmt subnet (default - 10.0.3.0)\n-I Lxc image name (default: \"nodeimg\") \n-O openflow version (1.0 or 1.1 or 1.2 or 1.3 default: null)"); return; } config = { logfile: (ref = argv.l) != null ? ref : "/var/log/kaanalnet.log", loglevel: (ref1 = argv.z) === 'trace' || ref1 === 'debug' || ref1 === 'info' || ref1 === 'warn' || ref1 === 'error' ? argv.z : 'info', controller: (ref2 = argv.C) != null ? ref2 : null, switchtype: (ref3 = argv.S) === 'openvswitch' || ref3 === 'linuxbridge' ? argv.S : 'linuxbridge', virtualization: 'lxc', wansubnet: (ref4 = argv.W) != null ? ref4 : '172.27.1.0', lansubnet: (ref5 = argv.L) != null ? ref5 : '10.10.10.0', mgmtsubnet: (ref6 = argv.M) != null ? ref6 : '10.0.3.0', lxcimage: (ref7 = argv.I) != null ? ref7 : 'nodeimg', ofversion: (ref8 = argv.O) === 1.0 || ref8 === 1.1 || ref8 === 1.2 || ref8 === 1.3 ? argv.O : null }; log = require('./utils/logger').createLogger(config.loglevel, config.logfile); log.info("kaanalNet application starts..... "); log.info("System Configuration " + JSON.stringify(config)); console.log("System Configuration " + JSON.stringify(config)); systemcheck = function() { return async.series([ (function(_this) { return function(callback) { var container, lxc; log.info("SYSTEMCHECK : Checking the LXC..."); lxc = require('lxcdriver'); container = new lxc(config.lxcimage); return container.exists(function(result) { if (result === true) { log.info("SYSTEMCHECK: LXC Image < " + config.lxcimage + " > present in the system.. PASSED "); return callback(null, "LXC Check success"); } else { log.error("SYSTEMCHECK: LXC Image <" + config.lxcimage + "> NOT present in the system.. FAILED"); return callback(new Error('LXC Check failed')); } }); }; })(this), (function(_this) { return function(callback) { var brctl, testbridge; log.info("SYSTEMCHECK : Checking the Linux bridge..."); brctl = require('brctldriver'); testbridge = "testbridge"; return brctl.createBridge(testbridge, function(result) { if (result === true) { log.info("SYSTEMCHECK: LinuxBridge " + testbridge + " creation success -- PASSED"); brctl.deleteBridge(testbridge, function(result) {}); return callback(null, "LinuxBridege Check success"); } else { log.error("SYSTEMCHECK: LinuxBridge " + testbridge + " creation Failure ..Failed"); return callback(new Error('LinuxBridge check failed')); } }); }; })(this), (function(_this) { return function(callback) { var ovs, testbridge; log.info("SYSTEMCHECK : Checking the OpenVSwitch..."); ovs = require('ovsdriver'); testbridge = "testbridge1"; return ovs.createBridge(testbridge, function(result) { if (result === true) { log.info("SYSTEMCHECK: OpenVSwitch " + testbridge + " creation success -- PASSED"); ovs.deleteBridge(testbridge, function(result) {}); return callback(null, "OpenVSwitch Check success"); } else { log.error("SYSTEMCHECK: OpenVSwitch " + testbridge + " creation Failure ..Failed"); return callback(new Error('OpenVSwitch check failed')); } }); }; })(this), (function(_this) { return function(callback) { var enableBonding; log.info("SYSTEMCHECK : Loading the Linux Bonding Module for Link Aggregation feature..."); enableBonding = require('./utils/bonding'); return enableBonding(function(result) { if (result === true) { log.info("SYSTEMCHECK: Loaded bonding driver success -- PASSED"); } else { log.info("SYSTEMCHECK: Loaded bonding driver failure -- FAILED"); } return callback(null, "bonding driver loading -completed"); }); }; })(this) ], (function(_this) { return function(err, result) { log.info("SYSTEMCHECK - result is %s ", result); console.log("SYSTEMCHECK - result is %s ", result); if (err) { throw new Error("Dependent packages are not available - Failed"); } }; })(this)); }; systemcheck(); log.info("starting the REST api services..."); topology = require('./Topology'); topology.configure(config); topologyPost = function(req, res, next) { log.info("REST API - POST /Topology received, body contents - " + JSON.stringify(req.body)); return topology.create(req.body, (function(_this) { return function(result) { log.info("POST /Topology result " + JSON.stringify(result)); res.send(result); return next(); }; })(this)); }; topologyList = function(req, res, next) { log.info("REST API - GET /Topology received "); return topology.list((function(_this) { return function(result) { log.info("REST API - GET /Topology result " + JSON.stringify(result)); res.send(result); return next(); }; })(this)); }; topologyGet = function(req, res, next) { log.info("REST API - GET /Topology/:id received ", req.params.id); return topology.get(req.params.id, (function(_this) { return function(result) { util.log("REST API - GET /Topology/id result " + JSON.stringify(result)); res.send(result); return next(); }; })(this)); }; topologyDelete = function(req, res, next) { log.info("REST API - DELETE /Topology/:id received - ", req.params.id); return topology.del(req.params.id, (function(_this) { return function(result) { log.info("REST API - DELETE /Topology/:id result " + JSON.stringify(result)); res.send(result); return next(); }; })(this)); }; DeviceGet = function(req, res, next) { log.info("REST API - GET /Topology/" + req.params.id + "/Device/" + req.params.did + " received "); return topology.deviceGet(req.params.id, req.params.did, (function(_this) { return function(result) { log.info("REST API - GET /Topology/:id/Device/:did result " + JSON.stringify(result)); res.send(result); return next(); }; })(this)); }; DeviceDel = function(req, res, next) { log.info("REST API - DELETE /Topology/" + req.params.id + "/Device/" + req.params.did + " received "); return topology.deviceDelete(req.params.id, req.params.did, (function(_this) { return function(result) { log.info("REST API - DELETE /Topology/:id/Device/:did result " + JSON.stringify(result)); res.send(result); return next(); }; })(this)); }; DeviceStart = function(req, res, next) { log.info("REST API - PUT /Topology/" + req.params.id + "/Device/" + req.params.did + "/start received "); return topology.deviceStart(req.params.id, req.params.did, (function(_this) { return function(result) { log.info("REST API - PUT /Topology/:id/Device/:did/Start result " + JSON.stringify(result)); res.send(result); return next(); }; })(this)); }; DeviceStop = function(req, res, next) { log.info("REST API - PUT /Topology/" + req.params.id + "/Device/" + req.params.did + "/stop received "); return topology.deviceStop(req.params.id, req.params.did, (function(_this) { return function(result) { log.info("REST API - PUT /Topology/:id/Device/:did/stop result " + JSON.stringify(result)); res.send(result); return next(); }; })(this)); }; testSuitePost = function(req, res, next) { log.info("REST API - POST /Topology/" + req.params.id + "/Test received "); return topology.testSuiteCreate(req.params.id, req.body, (function(_this) { return function(result) { log.info("REST API - POST /Topology/:id/Test result " + JSON.stringify(result)); res.send(result); return next(); }; })(this)); }; testSuiteList = function(req, res, next) { log.info("REST API - GET /Topology/" + req.params.id + "/Device/" + req.params.did + "/stop received "); return topology.testSuiteList(req.params.id, (function(_this) { return function(result) { log.info("REST API - GET /Topology/:id/Test result " + JSON.stringify(result)); res.send(result); return next(); }; })(this)); }; testSuiteGet = function(req, res, next) { log.info("REST API - GET /Topology/" + req.params.id + "/Test/" + req.params.tid + " received "); return topology.testSuiteGet(req.params.id, req.params.tid, (function(_this) { return function(result) { log.info("REST API - GET /Topology/:id/Test/:tid result " + JSON.stringify(result)); res.send(result); return next(); }; })(this)); }; testSuiteDelete = function(req, res, next) { log.info("REST API - DELETE /Topology/" + req.params.id + "/Test/" + req.params.tid + " received "); return topology.testSuiteDelete(req.params.id, req.params.tid, (function(_this) { return function(result) { log.info("REST API - DELETE /Topology/:id/Test/:tid result " + JSON.stringify(result)); res.send(result); return next(); }; })(this)); }; server = restify.createServer(); server.use(restify.acceptParser(server.acceptable)); server.use(restify.queryParser()); server.use(restify.jsonp()); server.use(restify.bodyParser()); server.post('/Topology', topologyPost); server.get('/Topology', topologyList); server.get('/Topology/:id', topologyGet); server.del('/Topology/:id', topologyDelete); server.get('/Topology/:id/Device/:did', DeviceGet); server.del('/Topology/:id/Device/:did', DeviceDel); server.put('/Topology/:id/Device/:did/Start', DeviceStart); server.put('/Topology/:id/Device/:did/Stop', DeviceStop); server.post('/Topology/:id/Test', testSuitePost); server.get('/Topology/:id/Test', testSuiteList); server.get('/Topology/:id/Test/:tid', testSuiteGet); server.del('/Topology/:id/Test/:tid', testSuiteDelete); server.listen(5050, function() { return console.log('kaanalNet listening on port : 5050.....'); }); }).call(this);