ODL openflowjava和openflowplugin的启动流程,代码详解。

本文详细解析了OpenDaylight中openflowjava工程的启动流程,包括openflow-protocol-impl bundle的配置解析、SwitchConnectionProvider的实例化过程,以及如何与openflowplugin工程配合启动监听端口。关键步骤涉及yang文件配置、服务注册、线程池配置和Socket服务器创建,最终完成OpenFlow协议栈的启动准备。
摘要由CSDN通过智能技术生成


我们从南向北开始分析,首先看openflowjava工程,重点关注openflow-protocol-impl bundle。
首先查看该工程\src\main\yang目录下的yang文件,该文件指定了这个bundle启动的一些配置。
重点关注下面这段代码:
augment "/config:modules/config:module/config:configuration" {
  
case openflow-switch-connection-provider-impl {
when "/config:modules/config:module/config:type = 'openflow-switch-connection-provider-impl'";

leaf port { //openflow协议使用的端口,(of1.0 6633) (of1.3 6653)
description "local listening port";
type uint16;
mandatory true;
}
leaf address {//监听的ip
description "address of local listening interface";
type ietf-inet:ip-address;
}
leaf transport-protocol {//传输协议一般是tcp
description "Transport protocol used for communication.";
type of-config:transport-protocol;
mandatory true;
}
leaf switch-idle-timeout {//设备超时时间
description "idle timeout in [ms]";
type uint32;
mandatory true;
}
container tls {//安全传输层协议
leaf keystore {
description "keystore location";
type string;
}
leaf keystore-type {
description "keystore type (JKS or PKCS12)";
type of-config:keystore-type;
}
leaf keystore-path-type {
description "keystore path type (CLASSPATH or PATH)";
type of-config:path-type;
}
leaf keystore-password {
description "password protecting keystore";
type string;
}
leaf certificate-password {
description "password protecting certificate";
type string;
}
leaf truststore {
description "truststore location";
type string;
}
leaf truststore-type {
description "truststore type (JKS or PKCS12)";
type of-config:keystore-type;
}
leaf truststore-path-type {
description "truststore path type (CLASSPATH or PATH)";
type of-config:path-type;
}
leaf truststore-password {
description "password protecting truststore";
type string;
}
}
container threads {
leaf boss-threads {
type uint16;
}
leaf worker-threads {
type uint16;
}
}
leaf outbound-queue-size {
description "Sets size of ChannelOutboundQueue";
type uint16;
default 1024;
}
}
}

SwitchConnectionProviderModule为该bundle的启动类,关注creatInstance()方法:
public java.lang.AutoCloseable createInstance() {
  
LOG.info("SwitchConnectionProvider started.");
SwitchConnectionProviderImpl switchConnectionProviderImpl = new SwitchConnectionProviderImpl();
try {
ConnectionConfiguration connConfiguration = createConnectionConfiguration();
switchConnectionProviderImpl.setConfiguration(connConfiguration);
} catch (UnknownHostException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
return switchConnectionProviderImpl;
}
可见其首先实例化了一个SwitchConnectionProviderImpl对象,该对象的构造方法如下:
/** Constructor */
public SwitchConnectionProviderImpl() {
serializerRegistry = new SerializerRegistryImpl();
serializerRegistry.init();
serializationFactory = new SerializationFactory();
serializationFactory.setSerializerTable(serializerRegistry);
deserializerRegistry = new DeserializerRegistryImpl();
deserializerRegistry.init();
deserializationFactory = new DeserializationFactory();
deserializationFactory.setRegistry(deserializerRegistry);
}
在该构造方法里主要完成,注册openflow消息的编解码工厂
例如:
version = EncodeConstants.OF13_VERSION_ID;
registryHelper = new CommonMessageRegistryHelper(version, serializerRegistry);
registryHelper.registerSerializer(BarrierInput.class, new BarrierInputMessageFactory());
registryHelper.registerSerializer(EchoInput.class, new EchoInputMessageFactory());
registryHelper.registerSerializer(EchoReplyInput.class, new EchoReplyInputMessageFactory());
registryHelper.registerSerializer(FlowModInput.class, new FlowModInputMessageFactory());
到此,openflow-protocol-impl启动完毕。
这时大家可能有疑问,这好像什么也没干啊,但通过查看openflow-protocol-spi中的yang文件发现,接口SwitchConnectionProvider作为一个服务被导出,而这个接口的实现正是前文实例化的SwitchConnectionProviderImpl对象,所以大胆猜测,引入接口SwitchConnectionProvider的bundle会继续调用接口SwitchConnectionProviderImpl实例。
而唯一可能调用该实例的bundle,应该位于openfllowplugin工程中。
查看openflowplugin工程的openflowplugin bundle中的yang文件openflow-plugin-cfg-impl.yang,可见其确实引入了SwitchConnectionProvider接口。
import openflow-switch-connection-provider 
还要注意该yang文件中的这段定义:
augment "/config:modules/config:module/config:configuration" {
    
case openflow-provider-impl {
when "/config:modules/config:module/config:type = 'openflow-provider-impl'";

container binding-aware-broker {
uses config:service-ref {
refine type {
mandatory true;
config:required-identity md-sal-binding:binding-broker-osgi-registry;
}
}
}
list openflow-switch-connection-provider {
uses config:service-ref {
refine type {
mandatory true;
config:required-identity openflow-switch-connection-provider:openflow-switch-connection-provider;
}
}
}
}
标黄的语句表明,openfllowplugin应该会使用多个SwitchConnectionProvider实例,通过分析openflowplugin-controller-config中的42-openflowplugin.xml文件可以得知,运行时会存在两个SwitchConnectionProvider实例分别监听6633和6653端口。
接下来查看openflowplugin 的启动类,ConfigurableOpenFlowProviderModule
@Override
public java.lang.AutoCloseable createInstance() {
pluginProvider = new OpenflowPluginProvider();
pluginProvider.setBroker(getBindingAwareBrokerDependency());
pluginProvider.setSwitchConnectionProviders(getOpenflowSwitchConnectionProviderDependency());
pluginProvider.initialization();
return pluginProvider;
}
这里面的getOpenflowSwitchConnectionProviderDependency()需要注意下,返回的是Collection<SwitchConnectionProvider> ,该Collection应该只有两个元素。
可见SwitchConnectionProvider的集合被set到了OpenflowPluginProvider的实例中。然后调用了OpenflowPluginProvider的初始化方法,如下:
public void initialization() {
  
messageCountProvider = new MessageSpyCounterImpl();
extensionConverterManager = new ExtensionConverterManagerImpl();
this.registerProvider();
}
在执行this.registerProvider()时,会调用OpenflowPluginProvider中的onSessionInitiated()方法
@Override
public void onSessionInitiated(ProviderContext session) {
LOG.debug("onSessionInitiated");
registrationManager = new SalRegistrationManager();
registrationManager.onSessionInitiated(session);
mdController = new MDController();
mdController.setSwitchConnectionProviders(switchConnectionProviders);
mdController.setMessageSpyCounter(messageCountProvider);
mdController.setExtensionConverterProvider(extensionConverterManager);
mdController.init();
mdController.start();
}
这段代码主要实现了:
获取notification服务,databroker服务,注册了session观察者SalRegistrationManager,
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值