Using JQuery to call OpenDaylight REST NBI to fetch all nodes

As more and more apps become available on using SDN Controller NBI’s, I thought it might be a good idea to know how easily we can access these using some standard JS frameworks available.

I generally use JQuery for calling SDN Controllers NBI’s directly from the HTML files.

Here is a sample code to find all the nodes discovered by OpenDaylight SDN Controller

 //ODL NBI Endpoint
 var nbiLoc = "/controller/nb/v2/switchmanager/default/nodes";
 //ODL Server Location
 var sdnServer = "http://192.168.1.1:8080";
//Calling the function
console.log(findAllNodes(sdnServer, nbiLoc));
function findAllNodes(sdnServer, nbiLoc) {
 var nodes;
 var url = sdnServer + nbiLoc;
 console.log(url);
 $.ajax({
   url : url,
   type : "GET",
   async : false,
   contentType : "application/json",
   success : function(data, textStatus, jqXHR) {
     console.log(data);
     if (data) {
       nodes = data;
     }
   },
   error : function(jqXHR, textStatus, errorThrown) {
     console.log("Failure", errorThrown);
   },
   beforeSend : function(xhr) {
     //Default Base64 Encoding for (admin/admin)
     xhr.setRequestHeader("Authorization", "Basic YWRtaW46YWRtaW4=");
   }
 });

This call should fetch you all the nodes discovered in the topology of OpenDaylight.

More details about ODL NBI can be found on their Wiki.

Advertisements