2 * Copyright (c) 2015 Inocybe Technologies and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 define(['underscore'], function (_) {
11 var Topology = (function () {
13 function Topology(topoId) {
14 this.topoId = topoId || '';
15 this._bridgeNodes = {};
16 this._ovsdbNodes = {};
20 Object.defineProperties(Topology.prototype, {
23 return this._bridgeNodes;
28 return _.extend({}, this._bridgeNodes, this._ovsdbNodes);
33 return this._ovsdbNodes;
43 Topology.prototype.registerBridgeNode = function (bridgeNode) {
44 this._bridgeNodes[bridgeNode.nodeId] = bridgeNode;
47 Topology.prototype.registerOvsdbNode = function (ovsdbNode) {
48 this._ovsdbNodes[ovsdbNode.nodeId] = ovsdbNode;
51 Topology.prototype.registerLink = function (link) {
52 if (this._links[link.linkId]) {
53 console.warn('Two links have the same id (' + link.linkId + '), the first one will be overrided');
55 this._links[link.linkId] = link;
58 Topology.prototype.updateLink = function () {
59 _.each(this._links, (function (link, key) {
60 if (link instanceof Link) {
61 srcNode = _.filter(this._bridgeNodes, function(node) {
62 return node.getFLowName() === link.srcNodeId;
64 destNode = _.filter(this._bridgeNodes, function(node) {
65 return node.getFLowName() === link.destNodeId;
67 link.srcNodeId = srcNode[0].nodeId;
68 link.destNodeId = destNode[0].nodeId;
70 link.source = Object.keys(this.nodes).indexOf(link.srcNodeId);
71 link.target = Object.keys(this.nodes).indexOf(link.destNodeId);
79 var OvsNode = (function () {
80 function OvsNode(nodeId, inetMgr, inetNode, otherLocalIp, ovsVersion) {
82 this.inetMgr = inetMgr;
83 this.inetNode = inetNode;
84 this.otherLocalIp = otherLocalIp;
85 this.ovsVersion = ovsVersion;
88 OvsNode.prototype.showIpAdress = function() {
89 return this.otherLocalIp;
92 OvsNode.prototype.pretty = function() {
99 { key: 'ID', value: this.nodeId},
100 { key: 'InetMgr', value: this.inetMgr},
101 { key: 'InetNode', value: this.inetNode},
102 { key: 'Local IP', value: this.otherLocalIp},
103 { key: 'OVS Version', value: this.ovsVersion}
112 var BridgeNode = (function () {
114 function BridgeNode(nodeId, dpIp, name, controllerTarget, controllerConnected) {
115 this.nodeId = nodeId;
118 this.controllerTarget = controllerTarget;
119 this.controllerConnected = controllerConnected;
125 Object.defineProperties(BridgeNode.prototype, {
133 var dpToFlow = function (dpId) {
134 return 'openflow:' + parseInt(dpId.replace(/:/g, ''), 16);
137 BridgeNode.prototype.getFLowName = function () {
138 return (!this.dpIp) ? this.nodeId : dpToFlow(this.dpIp);
141 BridgeNode.prototype.addTerminationPoint = function (tp) {
142 this._tpList.push(tp);
143 this._tpList.sort(function(tp1, tp2) {
144 return tp1.ofPort - tp2.ofPort;
148 BridgeNode.prototype.addFlowTableInfo = function(flowTable) {
149 this.flowTable.push(flowTable);
150 this.flowTable.sort(function(ft1, ft2) {
151 return ft1.key - ft2.key;
155 BridgeNode.prototype.pretty = function() {
168 { key: 'ID', value: this.nodeId},
169 { key: 'Name', value: this.name},
170 { key: 'OpenFlow Name', value: this.getFLowName()},
171 { key: 'Controller Target', value: this.controllerTarget},
172 { key: 'Controller Connected', value: this.controllerConnected}
177 'header' : ['Of Port', 'Name', 'Mac', 'IFace Id',],
178 'datas' : this._tpList.map(function(s) {
179 return [s.ofPort, s.name, s.mac, s.ifaceId];
186 {key : 'Manufacturer', value: this.flowInfo.manufacturer},
187 {key : 'Hardware', value: this.flowInfo.hardware},
188 {key : 'Software', value: this.flowInfo.software},
189 {key : 'Feature', value: this.flowInfo.features},
190 {key : 'Ip', value: this.flowInfo.ip}
195 'headers' : ['Table Id', 'Value'],
196 'datas' :this.flowTable.map(function(t) {
197 return [t.key, t.value];
207 var TerminationPoint = (function () {
208 function TerminationPoint(name, ofPort, tpType, mac, ifaceId) {
210 this.ofPort = ofPort;
211 this.tpType = tpType;
212 this.mac = mac || '';
213 this.ifaceId = ifaceId || '';
215 return TerminationPoint;
218 var BaseLink = (function() {
219 function BaseLink(linkId, srcNodeId, destNodeId, linkType, styles) {
220 this.linkId = linkId;
221 this.srcNodeId = srcNodeId;
222 this.destNodeId = destNodeId;
223 this.linkType = linkType;
226 styles = _.extend({}, styles);
227 this.color = styles.color;
228 this.width = styles.width || 1;
229 this.dashArray = styles.dashArray || 'None';
231 // d3js needed values
238 var Link = (function () {
239 function Link(linkId, srcNodeId, destNodeId) {
244 BaseLink.call(this, linkId, srcNodeId, destNodeId, 'link', opt);
247 Link.prototype = Object.create(BaseLink.prototype);
248 Link.prototype.constructor = Link;
253 var TunnelLink = (function() {
254 function TunnelLink(linkId, srcNodeId, destNodeId, linkType, color) {
260 BaseLink.call(this, linkId, srcNodeId, destNodeId, 'tunnel', opt);
263 TunnelLink.prototype = Object.create(BaseLink.prototype);
264 TunnelLink.prototype.constructor = TunnelLink;
269 var BridgeOvsLink = (function() {
270 function BridgeOvsLink(linkId, srcNodeId, destNodeId, linkType, color) {
275 BaseLink.call(this, linkId, srcNodeId, destNodeId, 'bridgeOvsLink', opt);
278 BridgeOvsLink.prototype = Object.create(BaseLink.prototype);
279 BridgeOvsLink.prototype.constructor = BridgeOvsLink;
281 return BridgeOvsLink;
284 var Util = (function() {
285 var Maths = (function() {
289 // random function in javascript use timespan only
290 Maths.Random = function(nseed) {
291 var constant = Math.pow(2, 13)+1,
300 next : function(min, max) {
304 return min && max ? min+seed%maximum/maximum*(max-min) : seed%maximum/maximum;
311 var String = (function() {
316 String.Format = function() {
317 var s = arguments[0];
318 for (var i = 0; i < arguments.length - 1; i++) {
319 var reg = new RegExp("\\{" + i + "\\}", "gm");
320 s = s.replace(reg, arguments[i + 1]);
334 var Neutron = (function() {
336 var SubNet = (function() {
337 function SubNet(id, networkId, name, ipVersion, cidr, gatewayIp, tenantId) {
339 this.networkId = networkId;
341 this.ipVersion = ipVersion;
343 this.gatewayIp = gatewayIp;
344 this.tenantId = tenantId;
349 var Network = (function() {
350 function Network(id, name, shared, status, external, tenantId) {
354 this.shared = shared;
355 this.status = status;
356 this.external = external;
357 this.tenantId = tenantId;
363 Network.prototype.addSubNets = function(subnets) {
365 if (_.isArray(subnets)) {
367 for (; i < subnets.length; ++i) {
368 this.subnets.push(subnets[i]);
372 this.subnets.push(subnet);
377 Network.prototype.asSubnet = function(subnet) {
378 return _.every(subnet, function(sub) {
379 return _.some(this.subnets, function(s) {
385 Network.prototype.pretty = function() {
396 {key : 'ID', value: this.id},
397 {key : 'Ip', value: this.ip},
398 {key : 'Name', value: this.name},
399 {key : 'Shared', value: this.shared},
400 {key : 'Status', value: this.status},
401 {key : 'External', value: this.external},
402 {key : 'Tenant Id', value: this.tenantId}
407 'header' : ['ID', 'Name', 'Ip Version', 'Ip', 'Gateway Ip'],
408 'datas' : this.subnets.map(function(s) {
409 return [s.id, s.name, s.ipVersion, s.cidr, s.gatewayIp];
419 var Port = (function() {
420 function Port(id, networkId, name, tenantId, deviceId, deviceOwner, fixed_ips, mac) {
422 this.networkId = networkId;
424 this.tenantId = '' + tenantId || '';
425 this.deviceId = deviceId;
426 this.deviceOwner = deviceOwner;
427 this.fixed_ips = fixed_ips;
431 Port.prototype.pretty = function() {
433 { key: 'ID', value : this.id },
434 { key: 'Name', value: name },
435 { key: 'Tenant Id', value : this.tenantId },
436 { key: 'Device Id', value : this.deviceId },
437 { key: 'Device Owner', value : this.deviceOwner },
438 { key: 'MAC', value : this.mac }
445 var Router = (function() {
446 function Router(id, name, status, tenantId, externalGateway) {
449 this.status = status;
450 this.tenantId = tenantId;
451 this.interfaces = [];
452 this.externalGateway = externalGateway;
455 Router.prototype.pretty = function() {
466 { key: 'ID', value: this.id},
467 { key: 'Name', value: this.name},
468 { key: 'status', value: this.status},
469 { key: 'Tenant ID', value: this.tenantId}
474 'header' : ['ID', 'Type', 'Mac Address', 'Ip', 'Tenant Id'],
475 'datas' : this.interfaces.map(function(s) {
476 return [s.id, s.type, s.mac, s.ip.ip_address, s.tenantId];
486 var Instance = (function() {
487 function Instance(id, networkId, name, ip, mac, deviceOwner, tenantId, topoInfo) {
489 this.networkId = networkId;
493 this.type = deviceOwner;
494 this.tenantId = tenantId;
495 this.topoInfo = topoInfo || [];
496 this.floatingIp = {};
499 Instance.prototype.extractFloatingIps = function(floatingIps) {
501 this.floatingIp = _.find(floatingIps, function(fIp) {
502 return fIp.tenantId === ctx.tenantId &&
503 fIp.fixedIp === ctx.ip;
507 Instance.prototype.pretty = function() {
518 { key: 'ID', value: this.id},
519 { key: "Network Id", value : this.networkId},
520 { key: 'Name', value: this.name},
521 { key: 'Ip', value: this.ip},
522 { key: 'Floating Ip', value: (this.floatingIp) ? this.floatingIp.ip : 'Not found' },
523 { key: 'MAC', value: this.mac},
524 { key: 'Type', value: this.type},
525 { key: 'Tenant ID', value: this.tenantId}
530 'header' : ['Name', 'Of Port', 'Mac', 'Flow', 'Ovsdb Node', 'Ovsdb Node IP'],
531 'datas' : this.topoInfo.map(function(s) {
532 return [s.name, s.ofPort, s.mac, s.bridge.getFLowName(), s.ovsNode.nodeId, s.ovsNode.showIpAdress()];
542 var FloatingIp =(function() {
543 function FloatingIp(id, networkId, portId, fixedIp, floatingIp, tentantId, status) {
545 this.networkId = networkId;
546 this.portId = portId;
547 this.fixedIp = fixedIp;
548 this.ip = floatingIp;
549 this.tenantId = tentantId;
550 this.status = status;
560 FloatingIp: FloatingIp,
568 BridgeNode: BridgeNode,
569 TerminationPoint: TerminationPoint,
573 TunnelLink: TunnelLink,
574 BridgeOvsLink:BridgeOvsLink,