SDN Controller Programming Guide
31
In the following code examples, it is assumed that a reference to the controller service
implementation has been stored in the field cs:
private ControllerService cs = ... ;
Datapath Information
Information about datapaths that have connected to the controller is available; either all connected
datapaths, or a datapath with a given ID:
getAllDataPathInfo() : Set<DataPathInfo>
getDataPathInfo(DataPathId) : DataPathInfo
The DataPathInfo API provides information about a datapath:
the datapath ID
the negotiated protocol version
the time at which the datapath connected to the controller
the time at which the last message was received from the datapath
the list of OpenFlow-enabled ports
the reported number of buffers
the reported number of tables
the set of capabilities
the remote (IP) address of the connection
the remote (TCP) port of the connection
The following listing describes an example of how to use Datapath information:
Datapath Information Example:
DataPathId dpid = DataPathId.valueOf("00:00:00:00:00:00:00:01");
DataPathInfo dpi;
try {
dpi = cs.getDataPathInfo(dpid);
log.info("Datapath with ID {} is connected", dpid);
log.info("Negotiated protocol version is {}", dpi.negotiated());
for (Port p: dpi.ports()) {
...
}
} catch (NotFoundException e) {
log.warn("Datapath with ID {} is not connected", dpid);
}
Listeners
Application code may wish to be notified of events via a callback mechanism. A number of
methods allow the consumer to register as a listener for certain types of event:
Message Listeners – notified when OpenFlow messages arrive from a datapath. At
registration, the listener specifies the message types of interest. Note that one exception to