UNPKG

kaanalnet

Version:

Virtual Network Emulator Lab for SDN and traditional networks

232 lines (201 loc) 6.97 kB
// Generated by CoffeeScript 1.9.3 (function() { var HWADDR_PREFIX, HWADDR_START, async, extend, getHwAddress, ip, log, node, request, util, vmctrl; util = require('util'); request = require('request-json'); extend = require('util')._extend; ip = require('ip'); async = require('async'); vmctrl = require('./builder/vmCtrl'); log = require('./utils/logger').getLogger(); log.info("Node - Logger test message"); HWADDR_PREFIX = "00:00:00:00:00:"; HWADDR_START = 10; getHwAddress = function() { var hwaddr; HWADDR_START++; hwaddr = "" + HWADDR_PREFIX + HWADDR_START; return hwaddr; }; node = (function() { function node(data) { this.ifmap = []; this.lagmap = []; this.ifindex = 1; this.lagindex = 1; this.config = extend({}, data); this.config.ifmap = this.ifmap; this.config.lagmap = this.lagmap; this.statistics = {}; this.status = {}; log.debug("node object created with " + JSON.stringify(this.config)); } node.prototype.addLanInterface = function(brname, ipaddress, subnetmask, gateway, characterstics) { var interf; interf = { "ifname": "eth" + this.ifindex, "hwAddress": getHwAddress(), "brname": brname, "ipaddress": ipaddress, "netmask": subnetmask, "gateway": gateway != null ? gateway : void 0, "type": "lan", "veth": this.config.name + "_veth" + this.ifindex, "config": characterstics }; log.debug("lan interface " + JSON.stringify(interf)); this.ifindex++; this.ifmap.push(interf); return this.lanip = ipaddress; }; node.prototype.addLagInterface = function(brname, bondname, ipaddress, subnetmask, gateway, characterstics) { var lagif, lagif1, lagif2, veth1, veth2; lagif1 = "eth" + this.ifindex; veth1 = this.config.name + "_veth" + this.ifindex; this.ifindex++; lagif2 = "eth" + this.ifindex; veth2 = this.config.name + "_veth" + this.ifindex; lagif = { "bondname": bondname, "lagif1": lagif1, "hwAddress1": getHwAddress(), "veth1": veth1, "lagif2": lagif2, "hwAddress2": getHwAddress(), "veth2": veth2, "brname": brname, "ipaddress": ipaddress, "netmask": subnetmask, "gateway": gateway != null ? gateway : void 0, "type": "lan", "config": characterstics }; return this.lagmap.push(lagif); }; node.prototype.addWanInterface = function(brname, ipaddress, subnetmask, gateway, characterstics) { var interf; interf = { "ifname": "eth" + this.ifindex, "hwAddress": getHwAddress(), "brname": brname, "ipaddress": ipaddress, "netmask": subnetmask, "gateway": gateway != null ? gateway : void 0, "type": "wan", "veth": this.config.name + "_veth" + this.ifindex, "config": characterstics }; log.debug("waninterface " + JSON.stringify(interf)); this.ifindex++; return this.ifmap.push(interf); }; node.prototype.addMgmtInterface = function(ipaddress, subnetmask) { var interf; interf = { "ifname": "eth0", "hwAddress": getHwAddress(), "ipaddress": ipaddress, "netmask": subnetmask, "type": "mgmt" }; log.debug("mgmt interface" + JSON.stringify(interf)); this.ifmap.push(interf); this.mgmtip = ipaddress; return this.config.mgmtip = this.mgmtip; }; node.prototype.create = function(callback) { log.info("createing node " + JSON.stringify(this.config)); return vmctrl.create(this.config, (function(_this) { return function(result) { _this.uuid = result.id; _this.config.id = _this.uuid; _this.config.status = result.status; log.info("node creation result " + JSON.stringify(result)); return callback(result); }; })(this)); }; node.prototype.start = function(callback) { log.info("starting a node " + this.config.name); return vmctrl.start(this.uuid, (function(_this) { return function(result) { log.info("node start result " + JSON.stringify(result)); _this.config.status = result.status; return callback(result); }; })(this)); }; node.prototype.provision = function(callback) { log.info("provisioning a node " + this.config.name); return vmctrl.provision(this.uuid, (function(_this) { return function(result) { log.info("node provision result " + JSON.stringify(result)); return callback(result); }; })(this)); }; node.prototype.stop = function(callback) { log.info("stopping a node " + this.config.name); return vmctrl.stop(this.uuid, (function(_this) { return function(result) { log.info("node stop result " + JSON.stringify(result)); _this.config.status = result.status; return callback(result); }; })(this)); }; node.prototype.trace = function(callback) { return vmctrl.packettrace(this.uuid, (function(_this) { return function(res) { log.info("node packettrace result " + res); return callback(res); }; })(this)); }; node.prototype.del = function(callback) { log.info("node deleting " + this.config.name); return vmctrl.del(this.uuid, (function(_this) { return function(res) { log.info("node del result " + JSON.stringify(res)); _this.config.status = result.status; return callback(res); }; })(this)); }; node.prototype.getstatus = function(callback) { log.info("getstatus called" + this.uuid); return vmctrl.get(this.uuid, (function(_this) { return function(result) { log.info("node getstatus result " + JSON.stringify(result)); _this.config.status = result.status; return callback(result); }; })(this)); }; node.prototype.getrunningstatus = function(callback) { return vmctrl.status(this.params.id, (function(_this) { return function(res) { log.info("node running status result " + res); return callback(res); }; })(this)); }; node.prototype.setLinkChars = function(callback) { log.info("setting the link characterstics " + this.config.name); return vmctrl.setLinkChars(this.uuid, (function(_this) { return function(result) { log.info("setLinkChars result " + result); return callback(result); }; })(this)); }; node.prototype.get = function() { return { "id": this.uuid, "config": this.config }; }; return node; })(); module.exports = node; }).call(this);