Before You Start
Check the list of all OpenDaylight projects and the list of already integrated lighty.io modules — your project may already be there.
Since lighty.io is not dependent on OSGi/Karaf, you cannot add features from the Karaf command line. Integration must be explicit.
Step 1: Create a New Java Project
Create a new Maven project for your module. This will wrap the OpenDaylight project in a lighty.io module class.
Step 2: Extend AbstractLightyModule
Create a class extending AbstractLightyModule. You only need to implement two abstract methods:
initProcedure()— initialize all beans and servicesstopProcedure()— call destroy methods on all beans
Use the Builder pattern to create instances, especially when the module requires many input parameters.
Step 3: Find Blueprint Files
Clone the ODL project from opendaylight-gerrit and find all blueprint files. Look for autowire.xml:
target/generated-sources/blueprint/OSGI-INF.blueprint/autowire.xml src/main/resources/OSGI-INF.blueprint/
Blueprint files specify beans with their constructor arguments, init methods, and destroy methods. Each of these becomes an object you create in initProcedure().
Step 4: Implement initProcedure
Example from the OpenFlow southbound plugin:
protected boolean initProcedure() {
ForwardingPingPongDataBroker forwardingPingPongDataBroker =
new ForwardingPingPongDataBroker(lightyServices.getBindingDataBroker());
SwitchConnectionProviderList switchConnectionProviders =
new SwitchConnectionProviderList(providers);
this.mastershipChangeServiceManager = new MastershipChangeServiceManagerImpl();
final OpenflowDiagStatusProvider diagStat =
new OpenflowDiagStatusProviderImpl(lightyServices.getDiagStatusService());
this.openFlowPluginProvider = new OpenFlowPluginProviderImpl(
this.configurationService,
switchConnectionProviders,
forwardingPingPongDataBroker,
this.lightyServices.getRpcProviderService(),
this.lightyServices.getBindingNotificationPublishService(),
this.lightyServices.getClusterSingletonServiceProvider(),
this.lightyServices.getEntityOwnershipService(),
this.mastershipChangeServiceManager, diagStat,
this.lightyServices.getSystemReadyMonitor());
this.openFlowPluginProvider.initialize();
return true;
}
Step 5: Implement stopProcedure
@Override
protected boolean stopProcedure() {
destroy(this.packetListenerNotificationRegistration);
destroy(this.flowCapableTopologyProvider);
destroy(this.forwardingRulesManagerImpl);
destroy(this.openFlowPluginProvider);
destroy(this.mastershipChangeServiceManager);
return true;
}
Step 6: Wire a Runnable Application
A lighty.io application is a plain Java main() method. Start all dependencies first, then your module:
// Get configuration
final Set<YangModuleInfo> modelPaths = Stream.concat(
RestConfConfigUtils.YANG_MODELS.stream(),
OpenflowConfigUtils.OFP_MODELS.stream()
).collect(Collectors.toSet());
controllerConfiguration = ControllerConfigUtils.getDefaultSingleNodeConfiguration(modelPaths);
// 1. Start lighty controller
final LightyController lightyController = new LightyControllerBuilder()
.from(controllerConfiguration).build();
lightyController.start().get();
// 2. Start RESTCONF
final CommunityRestConf communityRestConf = new CommunityRestConfBuilder()
.from(RestConfConfigUtils.getRestConfConfiguration(
restConfConfiguration, lightyController.getServices()))
.build();
communityRestConf.start();
// 3. Start your module
final OpenflowSouthboundPlugin plugin = new OpenflowSouthboundPluginBuilder()
.from(configuration, lightyController.getServices())
.withPacketListener(new PacketInListener())
.build();
plugin.start();
Summary
The integration steps are:
- Create a new Maven project for your module
- Find all blueprint files in the original ODL project
- Extend
AbstractLightyModuleand implement init/stop procedures - Initialize all beans from the blueprints in
initProcedure() - Destroy all beans in
stopProcedure() - Wire a plain Java
main()that starts dependencies then your module