Software Defined Networking
1828013 Members
1681 Online
109973 Solutions
New Discussion

Re: ControllerService and authentication in java

 
AlfonsoZendos
Occasional Visitor

ControllerService and authentication in java

Hello,

 

My name is Alfonso, I'm newbie in developing SDN. I have several problems on SDN programming in Java.

Problem Description:
I have a network created with MiniNet, managed by the HP VAN SDN controller with 4 switches, each connected to 2 or 3 host
I want to get information DataPath, as I have seen in the HP  
VAN SDN Controller programming guide on page 31.
How I can implement?:
     private ControllerService cs = ...;

 

Could you send me an example of implementation of ControllerService?

 

My code is:

 

import com.hp.api.NotFoundException;
import com.hp.of.ctl.ControllerService;
import com.hp.of.ctl.impl.ControllerManager;
import com.hp.of.lib.dt.DataPathId;
import com.hp.of.lib.dt.DataPathInfo;
import com.hp.of.lib.msg.Port;

public class infoDataPath {

    public static void main(String[] args) {
        
        //ControllerManager cm;
        ControllerService cs = ...;
        
        
        
        DataPathId dpid = DataPathId.valueOf("00:00:00:00:00:00:00:01");

        DataPathInfo dpi;
        try {
        dpi = cs.getDataPathInfo(dpid);
        System.out.println("Datapath with ID"+ dpid + "is connected");
        System.out.println("Negotiated protocol version is"+ dpi.negotiated());
        for (Port p: dpi.ports()) {
        
        }
        } catch (NotFoundException e) {
        System.out.println("Datapath with ID"+dpid+" is not connected");
        }
        
    }

}


Do you need to be authenticated ? with /auth , to run this code.

How you can authenticate through java code accesing to Rest Service with Jersey Rest?

Is better accesing to Rest Service with Maven?

 

 


thank you very much

 


Greetings

 

 

 

 

 

 

4 REPLIES 4
cmaxwell
Advisor

Re: ControllerService and authentication in java

Hello Alfonso,

 

I can answer one of your questions.

 

Using the ControllerService API via java does not require authentication since this is considered an Internal Application.  Only applications that are external to the controller will need to authenticate themselves and they do that through the REST API.  This is explained further in the "Internal Applications vs. External Applications" section of the SDN Controller Programming Guide (http://h20628.www2.hp.com/km-ext/kmcsdirect/emr_na-c04003169-2.pdf).

cmaxwell
Advisor

Re: ControllerService and authentication in java

Hello Alfonso,

 

I don't have an example that shows how to implement ControllerService but you will create the cs reference variable just like any other object reference:

 

private ControllerService cs = new ControllerService();

 

If you have installed the SDN SDK, which comes with the controller software, you can find details about the methods provided by ControllerService by pointing your browser to

 

file:///<PATH TO CONTROLLER PACKAGE DOWNLOADED FROM HP>/2.2.5.0016_hp-van-sdn-ctlr-2.2.5-x64/hp-sdn-apidoc-2.2.5/index.html.

 

Once there, select 'ControllerService' from the lower frame on the left-hand side.

sdnindia
Trusted Contributor

Re: ControllerService and authentication in java

Hello AlfonsoZendos,

 

               Below is the sequence of steps by which the controller service can be invoked in an application.

 

 

                //handler for controller service

                @Reference(cardinality = OPTIONAL_UNARY, policy = DYNAMIC,

               name="ControllerService")

  

               //Declare the controller service

               private volatile ControllerService cs;

 

               /**

              * Hook for notification of available {@link ControllerService} via

              * declarative services.

              *

              * @param cs the service being made available

              */

              protected void bindControllerService(ControllerService cs) {

               if (this.cs != null)

               return;

 

              this.cs = cs;

              log.debug("{}-bindControllerService() method invoked", NAME);

      

              }

 

             /**

           * Announces the unavailability of the controller service.

           *

           * @param cs the service that is being revoked

           */

          protected void unbindControllerService(ControllerService cs) {

          if (this.cs == cs)

            this.cs = null;

          log.debug("{}-unbindControllerService() method invoked", NAME);

         }

 

 

        //calculate the DPID to start the Flow Mirror Service

        Set<DataPathInfo> dpId = cs.getAllDataPathInfo();

 

 

Hope this helps.

 

Thanks,

HP SDN Team

sdnindia
Trusted Contributor

Re: ControllerService and authentication in java

Hello AlfonsoZendos,

Doing a follow up to check if you need any further assistance with respect to the query posted.
Please do let us know  if your problem is solved.

If you have more questions on the same topic please do reply on the same thread or open a new post if new topic.

Thanks
HP SDN Team