1 function MediatorConfig(obj) {
\r
2 if (obj !== undefined) {
\r
3 this.Name = obj.Name;
\r
4 this.DeviceType = obj.DeviceType;
\r
5 this.DeviceIp = obj.DeviceIp;
\r
6 this.DevicePort = 'DevicePort' in obj?obj.DevicePort:161;
\r
7 this.TrapsPort = obj.TrapPort;
\r
8 this.IsNetConfConnected = obj.IsNCConnected;
\r
9 this.IsNetworkElementConnected = obj.IsNeConnected;
\r
10 this.NeModel = obj.NeXMLFile;
\r
11 this.NetconfPort = obj.NcPort;
\r
13 this.IsLocked = obj.islocked;
\r
14 this.Autorun = obj.autorun;
\r
15 this.FirewallRuleActive = obj.fwactive;
\r
16 this.OpenDaylightConfigs = obj.ODLConfig;
\r
19 this.DeviceType = -1;
\r
21 this.DevicePort = 161;
\r
23 this.IsNetConfConnected = false;
\r
24 this.IsNetworkElementConnected = false;
\r
26 this.NetconfPort = 0;
\r
28 this.IsLocked = false;
\r
29 this.Autorun = false;
\r
30 this.FirewallRuleActive = false;
\r
31 this.OpenDaylightConfigs=[];
\r
33 this.DeviceTypeString = this.getDeviceTypeString();
\r
34 this.ConnectionStatus = {Netconf:this.IsNetConfConnected,NetworkElement:this.IsNetworkElementConnected}
\r
37 MediatorConfig.prototype.refreshData = function(obj)
\r
41 //this.Name = obj.Name;
\r
42 this.DeviceType = obj.DeviceType;
\r
43 this.DeviceIp = obj.DeviceIp;
\r
44 this.DevicePort = 'DevicePort' in obj?obj.DevicePort:161;
\r
45 this.TrapsPort = obj.TrapPort;
\r
46 this.IsNetConfConnected = obj.IsNCConnected;
\r
47 this.IsNetworkElementConnected = obj.IsNeConnected;
\r
48 this.NeModel = obj.NeXMLFile;
\r
49 this.NetconfPort = obj.NcPort;
\r
51 this.IsLocked = obj.islocked;
\r
52 this.Autorun = false;
\r
53 this.FirewallRuleActive = obj.fwactive;
\r
54 this.OpenDaylightConfigs = obj.ODLConfig;
\r
56 this.DeviceTypeString = this.getDeviceTypeString();
\r
57 this.ConnectionStatus = {Netconf:this.IsNetConfConnected,NetworkElement:this.IsNetworkElementConnected}
\r
60 MediatorConfig.prototype.getDeviceTypeString = function()
\r
63 for(i=0;i<MediatorConfig.DeviceTypes.length;i++)
\r
65 if(MediatorConfig.DeviceTypes[i].Value==this.DeviceType)
\r
66 return MediatorConfig.DeviceTypes[i].Name;
\r
70 /* enum for devicetypes */
\r
71 MediatorConfig.DEVICETYPE_SIMULATOR =0;
\r
74 function MediatorConfigStatus(obj){
\r
75 this.Status=obj.Status;
\r
78 MediatorConfigStatus.STATUS_OKAY = 1;
\r
79 MediatorConfigStatus.STATUS_CORRUPTED = 2;
\r
80 MediatorConfigStatus.STATUS_LOCKED = 3;
\r
81 MediatorConfigStatus.STATUS_REPAIRED = 4;
\r
82 MediatorConfigStatus.StatusTypes=[
\r
83 {Value:MediatorConfigStatus.STATUS_OKAY,Name:"Okay"},
\r
84 {Value:MediatorConfigStatus.STATUS_CORRUPTED,Name:"Corrupted"},
\r
85 {Value:MediatorConfigStatus.STATUS_LOCKED,Name:"Locked"},
\r
86 {Value:MediatorConfigStatus.STATUS_REPAIRED,Name:"Repaired"}
\r
89 /* Names for enum for devicetypes */
\r
90 MediatorConfig.DeviceTypes=[
\r
91 {Value:MediatorConfig.DEVICETYPE_SIMULATOR,Name:"Simulator"}];
\r
93 MediatorConfig.prototype.IsRunning = function() {
\r
94 return this.PID > 0;
\r
96 MediatorConfig.prototype.TestParams = function() {
\r
97 if(this.Name===undefined || this.Name.length<=0)
\r
98 throw "Name is not given";
\r
99 // Name without spaces
\r
100 var inValidName = /\s/;
\r
101 if(inValidName.test(this.Name))
\r
102 throw "Name cannot have whitespaces";
\r
103 // DeviceType: int from 0 to ...
\r
104 if(this.DeviceType<0 || this.DeviceType>MediatorConfig.DeviceTypes[MediatorConfig.DeviceTypes.length-1].Value)
\r
105 throw "DeviceType is not set";
\r
106 // DeviceIp: valid IP-Address
\r
107 var validIpTest =/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.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9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/;
\r
108 if(!validIpTest.test(this.DeviceIp))
\r
109 throw "IP-Address is not valid";
\r
110 // TrapsPort: valid Port
\r
111 if(this.TrapsPort<=0 || this.TrapsPort>65535)
\r
112 throw "TrapsPort is not valid";
\r
113 // NeModel: valid XMLFilename
\r
114 if(this.NeModel===undefined || this.NeModel.length<=0)
\r
115 throw "NE XML Filename is not valid";
\r
116 // NetconfPort: valid Port
\r
117 if(this.NetconfPort<=0 || this.NetconfPort>65535)
\r
118 throw "Netconf Port is not valid";
\r
122 function PortRange(a)
\r
135 function JavaMemParam(str)
\r
137 if(str!==undefined)
\r
143 function ServerConfig(obj){
\r
144 if (obj !== undefined) {
\r
145 this.HomeDir = obj.home;
\r
146 this.Host = obj.host;
\r
147 this.Port = obj.port;
\r
148 this.NetconfRange=new PortRange(obj.ncrange);
\r
149 this.SnmpRange = new PortRange(obj.snmprange);
\r
150 this.JmxRange = new PortRange(obj.jmxrange);
\r
151 this.LogLevel = obj.loglevel;
\r
152 this.LogFile = obj.logfile;
\r
153 this.MediatorLogLevel = obj.mediator-loglevel;
\r
154 this.MediatorDevicePingTimeout=obj.mediator-devicepingtimeout;
\r
155 this.MediatorSnmpLatency = obj.mediator-snmplatency;
\r
156 this.MediatorMemory = new JavaMemParam(obj.mediator-memory);
\r
163 this.NetconfRange=new PortRange();
\r
164 this.SnmpRange = new PortRange();
\r
165 this.JmxRange = new PortRange();
\r
166 this.LogLevel = "";
\r
168 this.MediatorLogLevel = "";
\r
169 this.MediatorDevicePingTimeout=0;
\r
170 this.MediatorSnmpLatency = 0;
\r
171 this.MediatorMemory = new JavaMemParam();
\r
174 function MediatorServer(url) {
\r
176 // if(this._root.endsWith("/"))
\r
177 this._root = this._root + "/";
\r
178 this._mediatorConfigs = [];
\r
179 this._neXMLFilenames = undefined;
\r
180 this.defaultODLConfig = {Server:"sendateodl5.fritz.box",Port:8181,User:"admin",Password:"admin"};
\r
183 MediatorServer.prototype.getConfigs = function(){return this._mediatorConfigs;}
\r
185 MediatorServer.prototype.SetDefaultODLConfig = function(cfg)
\r
187 this.defaultODLConfig = cfg;
\r
189 MediatorServer.prototype.GetDefaultODLConfig = function()
\r
191 return this.defaultODLConfig;
\r
193 MediatorServer.prototype.refreshConfig = function(configs,cb)
\r
196 if(this._mediatorConfigs===undefined)
\r
202 if(configs!==undefined && configs.length>0)
\r
205 for(i=0;i<configs.length;i++)
\r
207 //find config in array by name
\r
208 for(j=0;j<this._mediatorConfigs.length;j++)
\r
210 if(this._mediatorConfigs[j].Name==configs[i].Name)
\r
213 this._mediatorConfigs[j].refreshData(configs[i]);
\r
214 changed.push(configs[i]);
\r
223 MediatorServer.prototype.onConfigsReceived = function(configJSONArray) {
\r
224 this._mediatorConfigs = [];
\r
225 for (var i = 0; i < configJSONArray.length; i++) {
\r
226 var c = new MediatorConfig(configJSONArray[i]);
\r
227 this._mediatorConfigs.push(c);
\r
230 MediatorServer.prototype.onNeXMLReceived = function(neXMLFilenamesArray) {
\r
231 this._neXMLFilenames = neXMLFilenamesArray;
\r
234 MediatorServer.prototype.LoadNetworkElementXMLFiles = function(cb,cbError) {
\r
236 this.post("getnemodels", function(response) {
\r
237 if (response.code == 1) {
\r
238 _self.onNeXMLReceived(response.data);
\r
239 if (cb !== undefined)
\r
240 cb(_self._neXMLFilenames);
\r
243 _self.log(response.data);
\r
244 if(cbError!==undefined)
\r
245 cbError(response.data);
\r
248 if(cbError!==undefined)
\r
252 MediatorServer.prototype.LoadLogs = function(name,cb,cbError)
\r
255 this.post("getlog&name="+name,function(response){
\r
256 if (response.code == 1) {
\r
257 if (cb !== undefined)
\r
260 { _self.log(response.data);
\r
261 if(cbError!==undefined)
\r
262 cbError(response.data);
\r
265 if(cbError!==undefined)
\r
269 MediatorServer.prototype.LoadAvailableNCPorts = function(cb,cbError)
\r
272 this.post("getncports",function(response){
\r
273 if (response.code == 1) {
\r
274 if (cb !== undefined)
\r
277 { _self.log(response.data);
\r
278 if(cbError!==undefined)
\r
279 cbError(response.data);
\r
282 if(cbError!==undefined)
\r
286 MediatorServer.prototype.LoadAvailableSnmpPorts = function(cb,cbError)
\r
289 this.post("getsnmpports",function(response){
\r
290 if (response.code == 1) {
\r
291 if (cb !== undefined)
\r
296 _self.log(response.data);
\r
297 if(cbError!==undefined)
\r
298 cbError(response.data);
\r
301 if(cbError!==undefined)
\r
305 MediatorServer.prototype.StartMediator = function(name, cb, cbError) {
\r
307 this.post("start",{name:name}, function(response) {
\r
308 if (response.code == 1) {
\r
309 if (cb !== undefined)
\r
312 _self.log(response.data);
\r
313 if(cbError!==undefined)
\r
314 cbError(response.data);
\r
317 if(cbError!==undefined)
\r
321 MediatorServer.prototype.StopMediator = function(name, cb, cbError) {
\r
323 this.post("stop",{name:name}, function(response) {
\r
324 if (response.code == 1) {
\r
325 if (cb !== undefined)
\r
328 _self.log(response.data);
\r
329 if(cbError!==undefined)
\r
330 cbError(response.data);
\r
333 if(cbError!==undefined)
\r
337 MediatorServer.prototype.ReloadConfig = function(name,cb,cbError)
\r
340 this.post("getconfig",{name:name},function(response){
\r
341 if (response.code == 1) {
\r
342 _self.refreshConfig(response.data,function(changes){
\r
343 if (cb !== undefined)
\r
347 _self.log(response.data);
\r
348 if(cbError!==undefined)
\r
349 cbError(response.data);
\r
353 if(cbError!==undefined)
\r
358 MediatorServer.prototype.LoadConfigs = function(cb,cbError) {
\r
360 this.post("getconfig", function(response) {
\r
361 if (response.code == 1) {
\r
362 _self.onConfigsReceived(response.data);
\r
363 if (cb !== undefined)
\r
364 cb(_self._mediatorConfigs);
\r
366 _self.log(response.data);
\r
370 if(cbError!==undefined)
\r
374 MediatorServer.prototype.Repair = function(cb,cbError)
\r
377 this.post("repair", function(response) {
\r
378 if (response.code == 1) {
\r
379 if (cb !== undefined)
\r
382 _self.log(response.data);
\r
383 if(cbError!==undefined)
\r
384 cbError(response.data);
\r
387 if(cbError!==undefined)
\r
391 MediatorServer.prototype.LoadVersion = function(cb,cbError)
\r
394 this.post("version", function(response) {
\r
395 if (response.code == 1) {
\r
396 if (cb !== undefined)
\r
399 _self.log(response.data);
\r
403 if(cbError!==undefined)
\r
408 * name: <String> deviceType: <int> deviceip: <Ipv4-String> trapsPort:<int>
\r
409 * nexml:<String> ncport:<int> cb: callback-function
\r
411 MediatorServer.prototype.CreateMediator = function(name,devicetype,deviceip,deviceport,trapsPort,nexml,ncport, cb, cbError) {
\r
416 obj=new MediatorConfig({
\r
418 DeviceType:devicetype,
\r
420 DevicePort:deviceport,
\r
421 TrapPort:trapsPort,
\r
429 if(cbError!==undefined)
\r
432 this.post("create", {
\r
433 config : JSON.stringify({
\r
435 DeviceType : obj.DeviceType,
\r
436 DeviceIp : obj.DeviceIp,
\r
437 DevicePort : obj.DevicePort,
\r
438 TrapPort : obj.TrapsPort,
\r
439 NeXMLFile : obj.NeModel,
\r
440 NcPort : obj.NetconfPort,
\r
441 ODLConfig:[this.defaultODLConfig]
\r
443 }, function(response) {
\r
444 if(response.code==1)
\r
451 if(cbError!==undefined)
\r
452 cbError(response.data);
\r
455 if(cbError!==undefined)
\r
459 MediatorServer.prototype.DeleteMediator = function(name, cb, cbError)
\r
462 this.post('delete', {name:name}, function(response){
\r
463 if(response.code==1)
\r
475 if(cbError!==undefined)
\r
479 MediatorServer.prototype.ClearLock = function(name, cb, cbError) {
\r
481 this.post("clearlock", {
\r
483 }, function(response) {
\r
484 if (response.code == 1) {
\r
485 if (cb !== undefined)
\r
488 _self.log(response.data);
\r
489 if (cbError !== undefined)
\r
490 cbError(response.data);
\r
493 if(cbError!==undefined)
\r
502 MediatorServer.prototype.post = function(task, data, callback,callbackError) {
\r
504 if (typeof (data) === "function")
\r
506 callbackError = callback;
\r
509 var cb=function(r) {
\r
510 if (callback !== undefined) {
\r
512 if (typeof (r) === "string")
\r
517 if(callbackError!==undefined)
\r
523 if(this.usejQueryv3)
\r
526 url : this._root + "api/?task=" + task,
\r
533 if(typeof(data)=== "function")
\r
535 $.post(this._root + "api/?task=" + task,cb).done(function() {
\r
536 _self.log( "second success" );
\r
538 .fail(function(e) {
\r
539 _self.log( "error" +e);
\r
540 if(callbackError!==undefined)
\r
543 .always(function() {
\r
544 _self.log( "finished" );
\r
549 $.post(this._root + "api/?task=" + task,data,cb).done(function() {
\r
550 _self.log( "second success" );
\r
552 .fail(function(e) {
\r
553 _self.log( "error" +e);
\r
554 if(callbackError!==undefined)
\r
557 .always(function() {
\r
558 _self.log( "finished" );
\r
564 MediatorServer.prototype._error = function(message) {
\r
565 console.log(message);
\r
567 MediatorServer.prototype.log = function(message) {
\r
568 // console.log(message);
\r