Reference Guide

Table Of Contents
private final SystemInformationService sysInfoService;
// Mandatory dependency.
private final RoleService roleService;
public void doAct() {
IpAddress masterIp = roleService.getMaster(dpid).ip();
if(masterIp.equals(sysInfoService.
getSystem().getAddress())){
log.debug(“this controller is the master to {}”,
dpid);
// now that we know this controller has master privilages
// we could for example initiate write operations on the
// datapath like sending flow-mods
}
}
}
- To determine the role that a controller is playing with respect to a given datapath
import com.hp.of.lib.msg.ControllerRole;
import com.hp.sdn.adm.role.RoleService;
import com.hp.sdn.region.ControllerNode;
import com.hp.sdn.region.ControllerNodeModel;
public class SampleService {
// Mandatory dependency.
private final RoleService roleService;
public void doAct() {
...
ControllerNode controller = new ControllerNodeModel(“10.1.1.1”);
ControllerRole role = roleService.getCurrentRole(controller,deviceIp);
switch(role){
case MASTER:
// the given controller has master privilages
// we can trigger write-operations from that controller
...
Break;
Case SLAVE:
// we have only read privileges
...
break;
default:
// indicates the controller and device are not associated
220