1 // Copyright (c) 2018 Maen Artimy
\r
3 // Licensed under the Apache License, Version 2.0 (the "License");
\r
4 // you may not use this file except in compliance with the License.
\r
5 // You may obtain a copy of the License at
\r
7 // http://www.apache.org/licenses/LICENSE-2.0
\r
9 // Unless required by applicable law or agreed to in writing, software
\r
10 // distributed under the License is distributed on an "AS IS" BASIS,
\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 // See the License for the specific language governing permissions and
\r
13 // limitations under the License.
\r
16 * All global objects are here.
\r
19 var myGlobalObject = (function () {
\r
20 console.log("myGlobalObject");
\r
21 var dpid = 1; //current datapath (switch) ID
\r
22 var myMasterURL = ""; //"http://localhost:8080";
\r
24 // returns full url for the command sent to the SDN controller
\r
25 var url = function(command) {
\r
26 var cmd = command.replace("<dpid>",dpid); //dpidStr(dpid));
\r
27 return myMasterURL + cmd;
\r
30 // sends asynchronous request to the SDN controller
\r
31 function httpGetAsync(command, callback, element) {
\r
32 //console.log("httpGetAsync");
\r
36 var UNAVAILABLE = 503;
\r
37 // this script is for sending a GET request to a server
\r
38 var xmlHttp = new XMLHttpRequest();
\r
39 xmlHttp.onreadystatechange = function() {
\r
40 if (xmlHttp.readyState == COMPLETE) {
\r
41 if(xmlHttp.status == OK) {
\r
42 callback(xmlHttp.responseText, element);
\r
44 console.log(xmlHttp.status);
\r
48 xmlHttp.open("GET", url(command), true); // true for asynchronous
\r
52 function httpPostAsync(command, parm, callback, element) {
\r
53 //console.log("httpPostAsync");
\r
57 var UNAVAILABLE = 503;
\r
58 // this script is for sending a GET request to a server
\r
59 var xmlHttp = new XMLHttpRequest();
\r
60 xmlHttp.onreadystatechange = function() {
\r
61 if (xmlHttp.readyState == COMPLETE) {
\r
62 if(xmlHttp.status == OK) {
\r
63 callback(xmlHttp.responseText, element);
\r
65 console.log(xmlHttp.status);
\r
69 xmlHttp.open("POST", url(command), true); // true for asynchronous
\r
70 //xmlHttp.setRequestHeader("Content-Type", "application/json");
\r
71 xmlHttp.setRequestHeader("Content-Type", "plain/text");
\r
75 function dpidStr(dpid) {
\r
76 return ("000000000000000" + dpid.toString(16)).substr(-16);
\r
79 function setDPID(str) {
\r
80 dpid = parseInt(str);
\r
83 function getDPID() {
\r
87 // these are the public objects
\r
91 httpGetAsync: httpGetAsync,
\r
92 httpPostAsync: httpPostAsync,
\r