Example of a team-aware application
An application that is fully team-aware has the following characteristics:
It divides work and shares data across application instances using high-availability controller interfaces and services such as the Coordination Service, the System Information Service, distributed maps, distributed locks, data serialization, peer monitoring (if needed), and so forth.
If the application writes to OpenFlow devices, it ensures that only one instance of the application writes and listens to a given device by using one of the following methods:
Using the
TeamControllerService
Using
DeviceOwnerService
to determine if controller is the owner (master) for device before issuing operations on the device
The following code snippet contains an example of a fully team-aware application component.
@Component public class ExampleApplicationComponent { @Reference private volatile ControllerService controllerService; // SequencedPacketListener // OpenFlow configuration API (flows, ports, etc) @Reference private volatile DeviceOwnerService deviceOwnerService; // DeviceOwnerListener @Reference private volatile CoordinationService coordinationService; // Shared data API (put/get from maps) // member variables (distributed map, listeners, ...) private DistributedMap<MyKey, MyObject> distributedMap; private DeviceOwnerListener deviceOwnerListener; private SequencedPacketListener, packetInListener; @Activate public void activate() { distributedMap = coordinationService.getMap(NAMESPACE); deviceOwnerService.addListener(deviceOwnerListener); controllerService.addPacketListener(packetInListener, OBSERVER, ALTITUDE); } @Deactivate public void deactivate() { deviceOwnerService.removeListener(deviceOwnerListener); controllerService.removePacketListener(packetInListener); } } ... public class MyDeviceOwnerListener implements DeviceOwnerListener { @Override public void ownerChanged(DeviceOwnerEvent evt) { // evt.type(), evt.dataPathId(), evt.deviceIp() // controllerService.sendFlowMod(...) // distributedMap.put/get(...) } } ... public class MyPacketInListener implements SequencedPacketListener { @Override public void event(MessageContext msgc) { // DataPathId dpid = msgc.srcEvent().dpid(); // controllerService.sendFlowMod(...) // distributedMap.put/get(...) } } ...