Operations 9 min read

Deep Dive into Openflowplugin Master Election and ContextChain Service Instantiation

This article explains how Openflowplugin uses Cluster Singleton services to elect a master controller for each switch, details the ContextChain registration and instantiation process, and describes how the MastershipChangeServiceManager and ReconciliationFramework enable north‑bound applications to detect and react to mastership changes.

NetEase Game Operations Platform
NetEase Game Operations Platform
NetEase Game Operations Platform
Deep Dive into Openflowplugin Master Election and ContextChain Service Instantiation

The Openflow protocol can support multiple controllers, but only the controller that becomes the Master provides north‑bound services for a switch. In OpenDaylight, the Master role is determined through a Cluster Singleton Service election implemented in the Openflowplugin.

1. Master election (Cluster Singleton Service) The key code is the call to contextChain.registerServices(singletonServiceProvider) , which registers the ContextChainImpl as a ClusterSingletonService . In a cluster, nodes elect a leader; in a single‑node deployment, the node becomes the Master automatically.

The elected leader then invokes ContextChainImpl.instantiateServiceInstance to create the service instance.

2. Instantiating ContextChain service instance The instantiateServiceInstance method triggers the instantiateServiceInstance of each registered Context (DeviceContext, RpcContext, StatisticsContext, RoleContext). If any exception occurs, ContextChainHolderImpl.onNotAbleToStartMastership destroys the ContextChain.

When all four contexts are successfully instantiated, the controller officially becomes the switch's Master and triggers a hook for north‑bound applications.

3. Controller becomes Switch Master After successful instantiation, the method ContextChainHolderImpl.onMasterRoleAcquired is called with the appropriate state, signalling that the switch is fully initialized as Master.

4. MastershipChangeServiceManager Without the ReconciliationFramework, the method becomeMaster iterates over the registered services and calls their onBecomeOwner callbacks:

@Override
public void becomeMaster(@Nonnull final DeviceInfo deviceInfo) {
    serviceGroup.forEach(mastershipChangeService -> mastershipChangeService.onBecomeOwner(deviceInfo));
}

Services are registered via MastershipChangeServiceManager.register :

@Override
public MastershipChangeRegistration register(@Nonnull MastershipChangeService service) {
    final MastershipServiceDelegate registration = new MastershipServiceDelegate(service, () -> serviceGroup.remove(service));
    serviceGroup.add(service);
    if (masterChecker != null && masterChecker.isAnyDeviceMastered()) {
        masterChecker.listOfMasteredDevices().forEach(service::onBecomeOwner);
    }
    return registration;
}

These hooks allow applications to react when a switch becomes Master.

5. ReconciliationFramework When used, the method becomeMasterBeforeSubmittedDS is called instead, which sequentially invokes reconcileServices on all registered services according to their priority, preventing race conditions and flow‑table conflicts:

private ListenableFuture
reconcileNode(DeviceInfo node) {
    ListenableFuture
lastFuture = Futures.immediateFuture(null);
    for (List
services : registeredServices.values()) {
        lastFuture = reconcileServices(lastFuture, services, node);
    }
    return lastFuture;
}

This framework ensures orderly processing of north‑bound applications during mastership changes.

6. Summary

The controller becomes the switch Master through OpenDaylight's Cluster Singleton Service.

Mastership triggers the instantiation of Device, RPC, Statistics, and Role contexts; only after all are initialized does the switch provide services to north‑bound applications.

Applications can detect mastership via MastershipChangeServiceManager or the ReconciliationFramework , which manage callback ordering and avoid conflicts.

SDNnetwork operationsMaster ElectionOpenFlowCluster SingletonOpenDaylight
NetEase Game Operations Platform
Written by

NetEase Game Operations Platform

The NetEase Game Automated Operations Platform delivers stable services for thousands of NetEase titles, focusing on efficient ops workflows, intelligent monitoring, and virtualization.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.