UNPKG

kaanalnet

Version:

Virtual Network Emulator Lab for SDN and traditional networks

200 lines (173 loc) 6.49 kB
// Generated by CoffeeScript 1.9.3 (function() { var async, extend, log, request, switchctrl, switches, util; util = require('util'); request = require('request-json'); extend = require('util')._extend; switchctrl = require('./builder/switchCtrl'); async = require('async'); log = require('./utils/logger').getLogger(); log.info("Switches Logger test message"); switches = (function() { function switches(sw) { var base, base1; this.config = extend({}, sw); if ((base = this.config).make == null) { base.make = "bridge"; } if ((base1 = this.config).ofversion == null) { base1.ofversion = 1.0; } this.status = {}; this.statistics = {}; this.tapifs = []; log.info("Switches - constructor - new switch object created " + JSON.stringify(this.config)); this.tapindex = 0; } switches.prototype.create = function(callback) { log.info("Switches - creating a switch with config " + JSON.stringify(this.config)); return switchctrl.create(this.config, (function(_this) { return function(res) { log.info("Switches - switch creation result " + JSON.stringify(res)); _this.uuid = res.id; _this.config.status = res.status; return callback(res); }; })(this)); }; switches.prototype.del = function(callback) { log.info("Switches - deleting a switch " + JSON.stringify(this.config)); this.delLinks(); return switchctrl.del(this.uuid, (function(_this) { return function(res) { log.info("Switches - switch deletion result " + res); _this.config.status = res.status; return callback(res); }; })(this)); }; switches.prototype.get = function() { return { "uuid": this.uuid, "config": this.config, "tapifs": this.tapifs }; }; switches.prototype.stop = function(callback) { log.info("Switches - stoping a switch " + JSON.stringify(this.config)); return switchctrl.stop(this.uuid, (function(_this) { return function(res) { log.info("Switches - switch stop result " + JSON.stringify(res)); _this.config.status = res.status; return callback(res); }; })(this)); }; switches.prototype.start = function(callback) { log.info("Switches - starting a switch " + JSON.stringify(this.config)); return switchctrl.start(this.uuid, (function(_this) { return function(res) { log.info("Switches - switch start result " + JSON.stringify(res)); _this.config.status = res.status; return callback(res); }; })(this)); }; switches.prototype.getstatus = function(callback) { log.info("getstatus called" + this.uuid); return switchctrl.get(this.uuid, (function(_this) { return function(result) { log.info("Switches getstatus result " + JSON.stringify(result)); _this.config.status = result.status; return callback(result); }; })(this)); }; switches.prototype.connect = function(ifname, callback) { var val; val = { "ifname": ifname }; log.info("Switches - connecting a interface " + ifname + " in switch " + this.config.name); return switchctrl.addInterface(this.uuid, val, (function(_this) { return function(res) { log.info(("Switches - connect- interface " + ifname + " connection result ") + JSON.stringify(res)); return callback(res); }; })(this)); }; switches.prototype.createTapInterfaces = function(ifname1, ifname2) { var result; log.info("Switches - createTapInterfaces - input " + ifname1 + " " + ifname2); result = switchctrl.CreateTapInterfaces(ifname1, ifname2); log.info("Switches - createTapInterfaces - result " + JSON.stringify(result)); return result; }; switches.prototype.addTapInterface = function(ifname, characteristics) { var tapif; tapif = { "name": ifname, "config": characteristics }; log.info("addTapInterface " + JSON.stringify(tapif)); this.tapifs.push(tapif); }; switches.prototype.connectTapInterfaces = function(callback) { log.info("Switches - connectTapInterfaces ...connecting the inter switch links"); return async.eachSeries(this.tapifs, (function(_this) { return function(tapif, callback) { log.info("connectTapInterfaces " + JSON.stringify(tapif)); return _this.connect(tapif.name, function(result) { return callback(); }); }; })(this), (function(_this) { return function(err) { if (err) { log.error("connectTapInterfaces switches error occured " + JSON.stringify(err)); return callback(false); } else { log.info("connectTapInterfaces Switches all are processed "); return callback(true); } }; })(this)); }; switches.prototype.setLinkChars = function(callback) { var i, len, ref, results, tapif; log.info("Switches: setting the link characterstics " + this.config.name); ref = this.tapifs; results = []; for (i = 0, len = ref.length; i < len; i++) { tapif = ref[i]; log.info("Switchs setLinkChars " + JSON.stringify(tapif)); results.push(switchctrl.setLinkChars(this.uuid, tapif, (function(_this) { return function(result) { log.info("Switches: setLinkChars result " + result); return callback(result); }; })(this))); } return results; }; switches.prototype.delLinks = function() { var i, len, ref, results, tapif; ref = this.tapifs; results = []; for (i = 0, len = ref.length; i < len; i++) { tapif = ref[i]; log.info("deleting the link " + JSON.stringify(tapif)); results.push(switchctrl.dellink(tapif.name, (function(_this) { return function(result) { return log.info("Switches: del link result " + result); }; })(this))); } return results; }; switches.prototype.switchStatus = function() {}; switches.prototype.statistics = function() {}; return switches; })(); module.exports = switches; }).call(this);