Floodlight 处理交换机加入/移除过程
来源:互联网 发布:js给value赋值 编辑:程序博客网 时间:2024/06/08 11:42
Floodlight 使用的是Netty架构,在Controller.java 入口函数中显示创建ServerBootstrap,设置套接字选项,ChannelPipeline,此时监听套接字就准备好处理来自SW的各种消息;这里最核心的就是 OpenflowPipelineFactory ,会加入各个业务相关的Handler,代码如下:
public ChannelPipeline getPipeline() throws Exception {
OFChannelState state = new OFChannelState();
ChannelPipeline pipeline = Channels. pipeline();
pipeline.addLast( "ofmessagedecoder", new OFMessageDecoder());
pipeline.addLast( "ofmessageencoder", new OFMessageEncoder());
pipeline.addLast( "idle", idleHandler );
pipeline.addLast( "timeout", readTimeoutHandler );
pipeline.addLast( "handshaketimeout",
new HandshakeTimeoutHandler(state, timer , 15));
if (pipelineExecutor != null)
pipeline.addLast( "pipelineExecutor",
new ExecutionHandler(pipelineExecutor ));
//OFChannelHandler 是核心
pipeline.addLast( "handler", controller.getChannelHandler(state));
return pipeline;
}
接下来的main loop就是处理交换机或者Controller角色变化等消息,这是我们关注的地方,代码如下:
// main loop
// 不断处理阻塞队列中SW的更新信息
while (true ) {
try {
IUpdate update = updates.take();
update.dispatch();
} catch (InterruptedException e) {
return;
} catch (StorageException e) {
log.error("Storage exception in controller "
+ "updates loop; terminating process", e);
return;
} catch (Exception e) {
log.error("Exception in controller updates loop", e);
}
}
那么Controller中的BlockingQueue中的更新信息是在何时加入的呢?这里只跟踪交换机加入的情况,很容易想到当监听套接字收到一个来自OF SW请求的时候。所以我们看 OFChannelHandler ,可以视为是业务相关的第一个UpstreamHandler,在通道连接的时候会回送一个HELLO消息,这里的重点看处理消息的过程,进入函数 messageReceived 接下来的处理流程(如下),在收到 GET_CONFIG_REPLY 消息之后说明这个SW准备好了(会把握手状态改为 HandshakeState.READY),而后会把这个SW加入到activeSwitches 和 updates中:
更新阻塞队列的代码是:
updateActiveSwitchInfo(sw);
SwitchUpdate update = new SwitchUpdate(sw, true);
try {
// 把update加到BlockingQueue里,如果BlockQueue没有空间,则调用此方法的线程被阻断
// 直到BlockingQueue里面有空间再继续.
this.updates .put(update);
} catch (InterruptedException e) {
log.error("Failure adding update to queue" , e);
}
通过上面的分析,相当于有了一个生产消费者模型,生产者就是交换机的加入或者移除消息,消费者就是Controller的处理过程,取出消息进行计算,为拓扑更新服务。具体过程仍然是一个监听者模式,把SW的更新信息分发到各个订阅者中进行处理(看SwitchUpdate类),代码如下:
public void dispatch() {
if (log .isDebugEnabled()) {
log.debug("Dispatching switch update {} {}", sw, added);
}
// 遍历这些listeners,处理加入或移除事件
if (switchListeners != null) {
for (IOFSwitchListener listener : switchListeners) {
if (added )
listener.addedSwitch( sw);
else
listener.removedSwitch( sw);
}
}
}
那么订阅 SwitchUpdate 消息的类是谁呢?LinkDiscoveryManager!交换机的加入或者移除活动肯定会带来链路信息的改变,当加入一个新SW的时候,就会通过发送 LLDP frame 来发现拓扑结构(参见 Floodlight Controller 路由原理 )。代码如下
public void addedSwitch(IOFSwitch sw) {
//这里的设计需要优化
// It's probably overkill to send LLDP from all switches, but we don't
// know which switches might be connected to the new switch.
// Need to optimize when supporting a large number of switches.
sendLLDPTask.reschedule(2000, TimeUnit.MILLISECONDS );
// Update event history
evHistTopoSwitch(sw, EvAction. SWITCH_CONNECTED, "None");
}
转载注明出处:http://blog.csdn.net/vonzhoufz/article/details/38043111
2 0
- Floodlight 处理交换机加入/移除过程
- floodlight安装过程总结以及错误处理方法
- iOS 子视图加入到父视图及移除父视图的过程
- 关于打印过程中强制移除打印机的处理
- Floodlight(controller)+OpenFlow交换机:环境搭建
- 让人无语的交换机故障处理过程
- linux内核网络监听哈希表介绍:如何将sk加入表和将sk移除表的过程
- Floodlight(v1.2)+OpenFlow交换机测试环境搭建
- Floodlight下发流表过程分析
- SDN模拟环境floodlight+mininet配置过程
- Android融云判断是否用户已经加入黑名单和加入&移除黑名单
- C#字符串处理:截取、替换、移除
- C#字符串处理:裁剪,替换,移除
- SDN控制器Floodlight源码学习(三)--控制器和交换机交互(1)
- SDN控制器Floodlight源码学习(四)--控制器和交换机交互(2)
- SDN控制器Floodlight源码学习(五)--控制器和交换机交互(3)
- 交换机报文处理方式
- Floodlight控制器创建一个模块的简单过程
- 常用颜色值表1
- 常用颜色值表2
- XML布局
- lvm命令详解
- 优秀博文链接
- Floodlight 处理交换机加入/移除过程
- socket()用法
- 生泰宝
- 状态机,层次状态机和行为树的区别以及联系
- CS领域会议最佳论文集合 Best Paper Awards in Computer Science (since 1996)
- 大一在ACM的一些感想
- FileUtils 文件工具类org.apache.commons.io.FileUtils
- Android关机流程源码分析
- 仿开源中国,分享代码时候的多文件上传