Floodlight源码阅读之网络拓扑

2024-05-10 18:18

本文主要是介绍Floodlight源码阅读之网络拓扑,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在上一篇文章中介绍Floodlight怎样做拓扑发现,这篇文章介绍一下网络拓扑是怎样形成的。TopologyManager这个类负责网络拓扑的产生。这个类首先实现了IFloodlightModule这个接口,是Floodlight的一个模块。其实是实现了ILinkDiscoveryListener用于监听网络中链路的变化;还实现了IOFMessageListener用于接收和处理网络包。

和其他的Floodlight模块一样,首先看启动方法startup。

    @Overridepublic void startUp(FloodlightModuleContext context) {clearCurrentTopology();// Initialize role to floodlight provider role.this.role = floodlightProviderService.getRole();ScheduledExecutorService ses = threadPoolService.getScheduledExecutor();newInstanceTask = new SingletonTask(ses, new UpdateTopologyWorker());if (role != HARole.STANDBY) {newInstanceTask.reschedule(TOPOLOGY_COMPUTE_INTERVAL_MS, TimeUnit.MILLISECONDS);}linkDiscoveryService.addListener(this);floodlightProviderService.addOFMessageListener(OFType.PACKET_IN, this);floodlightProviderService.addHAListener(this.haListener);addRestletRoutable();}

在这个启动方法中第一行就是清理拓扑

    /*** Clears the current topology. Note that this does NOT* send out updates.*/public void clearCurrentTopology() {this.clear();linksUpdated = true;dtLinksUpdated = true;tunnelPortsUpdated = true;createNewInstance("startup");lastUpdateTime = new Date();}
clear方法清理所以内存中保存的节点链路拓扑信息。

    public void clear() {switchPorts.clear();tunnelPorts.clear();switchPortLinks.clear();portBroadcastDomainLinks.clear();directLinks.clear();}
关于这个nosql内存数据库下一章讲解。

当清理完数据后开始创建新的拓扑

  /*** This function computes a new topology instance.* It ignores links connected to all broadcast domain ports* and tunnel ports. The method returns if a new instance of* topology was created or not.*/protected boolean createNewInstance(String reason) {Set<NodePortTuple> blockedPorts = new HashSet<NodePortTuple>();if (!linksUpdated) return false;Map<NodePortTuple, Set<Link>> openflowLinks;openflowLinks =new HashMap<NodePortTuple, Set<Link>>();Set<NodePortTuple> nptList = switchPortLinks.keySet();if (nptList != null) {for (NodePortTuple npt : nptList) {Set<Link> linkSet = switchPortLinks.get(npt);if (linkSet == null) continue;openflowLinks.put(npt, new HashSet<Link>(linkSet));}}// Identify all broadcast domain ports.// Mark any port that has inconsistent set of links// as broadcast domain ports as well.Set<NodePortTuple> broadcastDomainPorts =identifyBroadcastDomainPorts();// Remove all links incident on broadcast domain ports.for (NodePortTuple npt : broadcastDomainPorts) {if (switchPortLinks.get(npt) == null) continue;for (Link link : switchPortLinks.get(npt)) {removeLinkFromStructure(openflowLinks, link);}}// Remove all tunnel links.for (NodePortTuple npt : tunnelPorts) {if (switchPortLinks.get(npt) == null) continue;for (Link link : switchPortLinks.get(npt)) {removeLinkFromStructure(openflowLinks, link);}}//switchPorts contains only ports that are part of links. Calculation of broadcast ports needs set of all ports.Map<DatapathId, Set<OFPort>> allPorts = new HashMap<DatapathId, Set<OFPort>>();;for (DatapathId sw : switchPorts.keySet()) {allPorts.put(sw, this.getPorts(sw));}TopologyInstance nt = new TopologyInstance(switchPorts,blockedPorts,openflowLinks,broadcastDomainPorts,tunnelPorts,switchPortLinks,allPorts,portBroadcastDomainLinks);nt.compute();// We set the instances with and without tunnels to be identical.// If needed, we may compute them differently.currentInstance = nt;currentInstanceWithoutTunnels = nt;TopologyEventInfo topologyInfo =new TopologyEventInfo(0, nt.getClusters().size(),new HashMap<DatapathId, List<NodePortTuple>>(),0);eventCategory.newEventWithFlush(new TopologyEvent(reason, topologyInfo));return true;}

主要计算方法是nt.conpute()这个方法

这个方法有七步看代码如下

    public void compute() {// Step 1: Compute clusters ignoring broadcast domain links// Create nodes for clusters in the higher level topology// Must ignore blocked links.identifyOpenflowDomains();// Step 1.1: Add links to clusters// Avoid adding blocked links to clustersaddLinksToOpenflowDomains();// Step 2. Compute shortest path trees in each cluster for// unicast routing.  The trees are rooted at the destination.// Cost for tunnel links and direct links are the same.calculateShortestPathTreeInClusters();// Step 3. Compute broadcast tree in each cluster.// Cost for tunnel links are high to discourage use of// tunnel links.  The cost is set to the number of nodes// in the cluster + 1, to use as minimum number of// clusters as possible.calculateBroadcastNodePortsInClusters();// Step 4. Compute e2e shortest path trees on entire topology for unicast routing.// The trees are rooted at the destination.// Cost for tunnel links and direct links are the same.calculateAllShortestPaths();// Compute the archipelagos (def: cluster of islands). An archipelago will// simply be a group of connected islands. Each archipelago will have its own// finiteBroadcastTree which will be randomly chosen.calculateArchipelagos();// Step 5. Compute broadcast tree for the whole topology (needed to avoid loops).// Cost for tunnel links are high to discourage use of// tunnel links.  The cost is set to the number of nodes// in the cluster + 1, to use as minimum number of// clusters as possible.calculateAllBroadcastNodePorts();// Step 6. Compute set of ports for broadcasting. Edge ports are included.calculateBroadcastPortMap();// Step 7. print topology.printTopology();}

identifyOpenflowDomains这个方法通过深度优先遍历算法遍历拓扑节点

addLinksToOpenflowDomains添加集群直接的的link

calculateShortestPathTreeInClusters通过给链路添加权重在通clusterDijkstra最短路径算法计算拓扑最短路径

后面几个方法是整个网络的最短路径计算,详细部分文章后面一一解说




这篇关于Floodlight源码阅读之网络拓扑的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/977190

相关文章

java 恺撒加密/解密实现原理(附带源码)

《java恺撒加密/解密实现原理(附带源码)》本文介绍Java实现恺撒加密与解密,通过固定位移量对字母进行循环替换,保留大小写及非字母字符,由于其实现简单、易于理解,恺撒加密常被用作学习加密算法的入... 目录Java 恺撒加密/解密实现1. 项目背景与介绍2. 相关知识2.1 恺撒加密算法原理2.2 Ja

Nginx屏蔽服务器名称与版本信息方式(源码级修改)

《Nginx屏蔽服务器名称与版本信息方式(源码级修改)》本文详解如何通过源码修改Nginx1.25.4,移除Server响应头中的服务类型和版本信息,以增强安全性,需重新配置、编译、安装,升级时需重复... 目录一、背景与目的二、适用版本三、操作步骤修改源码文件四、后续操作提示五、注意事项六、总结一、背景与

Android实现图片浏览功能的示例详解(附带源码)

《Android实现图片浏览功能的示例详解(附带源码)》在许多应用中,都需要展示图片并支持用户进行浏览,本文主要为大家介绍了如何通过Android实现图片浏览功能,感兴趣的小伙伴可以跟随小编一起学习一... 目录一、项目背景详细介绍二、项目需求详细介绍三、相关技术详细介绍四、实现思路详细介绍五、完整实现代码

8种快速易用的Python Matplotlib数据可视化方法汇总(附源码)

《8种快速易用的PythonMatplotlib数据可视化方法汇总(附源码)》你是否曾经面对一堆复杂的数据,却不知道如何让它们变得直观易懂?别慌,Python的Matplotlib库是你数据可视化的... 目录引言1. 折线图(Line Plot)——趋势分析2. 柱状图(Bar Chart)——对比分析3

Android实现一键录屏功能(附源码)

《Android实现一键录屏功能(附源码)》在Android5.0及以上版本,系统提供了MediaProjectionAPI,允许应用在用户授权下录制屏幕内容并输出到视频文件,所以本文将基于此实现一个... 目录一、项目介绍二、相关技术与原理三、系统权限与用户授权四、项目架构与流程五、环境配置与依赖六、完整

Android实现定时任务的几种方式汇总(附源码)

《Android实现定时任务的几种方式汇总(附源码)》在Android应用中,定时任务(ScheduledTask)的需求几乎无处不在:从定时刷新数据、定时备份、定时推送通知,到夜间静默下载、循环执行... 目录一、项目介绍1. 背景与意义二、相关基础知识与系统约束三、方案一:Handler.postDel

Java 正则表达式URL 匹配与源码全解析

《Java正则表达式URL匹配与源码全解析》在Web应用开发中,我们经常需要对URL进行格式验证,今天我们结合Java的Pattern和Matcher类,深入理解正则表达式在实际应用中... 目录1.正则表达式分解:2. 添加域名匹配 (2)3. 添加路径和查询参数匹配 (3) 4. 最终优化版本5.设计思

Java调用C++动态库超详细步骤讲解(附源码)

《Java调用C++动态库超详细步骤讲解(附源码)》C语言因其高效和接近硬件的特性,时常会被用在性能要求较高或者需要直接操作硬件的场合,:本文主要介绍Java调用C++动态库的相关资料,文中通过代... 目录一、直接调用C++库第一步:动态库生成(vs2017+qt5.12.10)第二步:Java调用C++

Python实现无痛修改第三方库源码的方法详解

《Python实现无痛修改第三方库源码的方法详解》很多时候,我们下载的第三方库是不会有需求不满足的情况,但也有极少的情况,第三方库没有兼顾到需求,本文将介绍几个修改源码的操作,大家可以根据需求进行选择... 目录需求不符合模拟示例 1. 修改源文件2. 继承修改3. 猴子补丁4. 追踪局部变量需求不符合很

Spring 中 BeanFactoryPostProcessor 的作用和示例源码分析

《Spring中BeanFactoryPostProcessor的作用和示例源码分析》Spring的BeanFactoryPostProcessor是容器初始化的扩展接口,允许在Bean实例化前... 目录一、概览1. 核心定位2. 核心功能详解3. 关键特性二、Spring 内置的 BeanFactory