Analysis of Openflowplugin ContextChain Creation and Lifecycle Management

This article provides a detailed walkthrough of Openflowplugin's ContextChain creation process, explaining how DeviceContext, RpcContext, StatisticsContext, and RoleContext are instantiated and linked, and how the resulting ContextChain supports switch lifecycle handling and master/slave role election in an SDN controller.

NetEase Game Operations Platform
NetEase Game Operations Platform
NetEase Game Operations Platform
Analysis of Openflowplugin ContextChain Creation and Lifecycle Management

The article examines the second part of the Openflowplugin source code analysis, focusing on the core logic that creates the ContextChain for a newly connected switch after the handshake phase.

When a switch connects, ContextChainHolderImpl.deviceConnected invokes ContextChainHolderImpl.createContextChain, which builds a unique ContextChain object to manage the switch's lifecycle within Openflowplugin.

1. Create DeviceContext

The method calls deviceManager.createContext(connectionContext) to obtain a DeviceContext. It registers a mastership watcher, configures the packet‑in filter, creates an OutboundQueueHandler, a DeviceContextImpl, and an OpenflowProtocolListenerFullImpl to handle all messages from the switch.

final DeviceContext deviceContext = deviceManager.createContext(connectionContext);
deviceContext.registerMastershipWatcher(this);

2. Create RpcContext

Using the previously created deviceContext, the code calls rpcManager.createContext(deviceContext) to obtain an RpcContext and registers the same mastership watcher.

final RpcContext rpcContext = rpcManager.createContext(deviceContext);
rpcContext.registerMastershipWatcher(this);

3. Create StatisticsContext

The method creates a StatisticsContext via

statisticsManager.createContext(deviceContext, ownershipChangeListener.isReconciliationFrameworkRegistered())

, registers a watcher, and also creates a MultipartWriterProvider to write operational YANG data to the device.

final StatisticsContext statisticsContext = statisticsManager.createContext(deviceContext, ownershipChangeListener.isReconciliationFrameworkRegistered());
statisticsContext.registerMastershipWatcher(this);

4. Create RoleContext

A RoleContext is created with roleManager.createContext(deviceContext), a RoleContextImpl and a SalRoleServiceImpl are instantiated to manage master/slave role assignment.

final RoleContext roleContext = roleManager.createContext(deviceContext);
roleContext.registerMastershipWatcher(this);

5. Assemble ContextChain

After the four individual contexts are ready, a ContextChainImpl is instantiated. Each context is wrapped in a GuardedContextImpl and added via addContext. The chain registers a device‑removed handler, stores the chain in ContextChainHolderImpl.contextChainMap, and finally registers services with contextChain.registerServices(singletonServiceProvider).

@Override
public <T extends OFPContext> void addContext(@Nonnull final T context) {
    contexts.add(new GuardedContextImpl(context));
}

6. Master/Slave Election

The article notes that after the ContextChain is built, the next crucial step is the call to contextChain.registerServices, which triggers the master/slave role election among multiple controllers in a cluster.

Summary

In summary, once a switch completes the Openflow handshake, Openflowplugin creates four specialized contexts (Device, Rpc, Statistics, Role), aggregates them into a ContextChain, and prepares the switch for further operations, including high‑availability master/slave role election.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

javabackend-developmentSDNContextChainNetwork Controller
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

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.