摘要:每個具體的模塊都會重寫這幾個函數(shù),下面舉個的例子。獲得的服務(wù)返回服務(wù)實現(xiàn)類和實現(xiàn)用的對象的。服務(wù)是指繼承了接口的類。模塊使用方法可以獲得對應(yīng)的服務(wù)列表,可以到源碼去看對應(yīng)的服務(wù)功能。
Floodlight 的 Main 解析圖 需要理解的概念 模塊(Module)
Module 是指繼承了 IFloodlightModule 接口的類
IFloodlightModule的相關(guān)注釋
Defines an interface for loadable Floodlight modules. At a high level, these functions are called in the following order: getModuleServices() : 獲得模塊實現(xiàn)的服務(wù)列表 getServiceImpls(); 實例化并返回:服務(wù)實現(xiàn)類-實現(xiàn)此服務(wù)的對象 映射 getModuleDependencies() : 獲得模塊依賴的列表 init() : internal initializations (don"t touch other modules) startUp() : external initializations (do touch other modules)
所有可加載的模塊都有這幾種方法,在接下來的加載模塊時需要使用到。
每個具體的模塊都會重寫這幾個函數(shù),下面舉個 FloodlightProvider 的例子。
@Override public Collection> getModuleServices() { Collection > services = new ArrayList >(1); services.add(IFloodlightProviderService.class); return services; }
獲得 FloodlightProvider 的服務(wù) IFloodlightProviderService
getServiceImple()@Override public Map, IFloodlightService> getServiceImpls() { controller = new Controller(); Map , IFloodlightService> m = new HashMap , IFloodlightService>(); m.put(IFloodlightProviderService.class, controller); return m; }
返回服務(wù)實現(xiàn)類和實現(xiàn)用的對象的Map。
getModuleDependencies()@Override public Collection> getModuleDependencies() { Collection > dependencies = new ArrayList >(4); dependencies.add(IStorageSourceService.class); dependencies.add(IPktInProcessingTimeService.class); dependencies.add(IRestApiService.class); dependencies.add(IDebugCounterService.class); dependencies.add(IOFSwitchService.class); dependencies.add(IThreadPoolService.class); dependencies.add(ISyncService.class); return dependencies; }
返回依賴的列表
其他init(),startup(),到對應(yīng)的模塊去看就可以了。
有的模塊是沒有服務(wù)依賴的,比如 ThreadPool模塊。
Service 是指繼承了 IFloodlightService 接口的類。
public abstract interface IFloodlightService { // This space is intentionally left blank....don"t touch it }
模塊使用getModuleServices()方法可以獲得對應(yīng)的服務(wù)列表,可以到源碼去看對應(yīng)的服務(wù)功能。
Main函數(shù)解析命令行參數(shù)
加載模塊
啟動 REST 服務(wù)器
啟動 Controller
命令行參數(shù)解析CmdLineSetting 定義了命令行參數(shù)的格式
public static final String DEFAULT_CONFIG_FILE = "src/main/resources/floodlightdefault.properties"; @Option(name="-cf", aliases="--configFile", metaVar="FILE", usage="Floodlight configuration file") private String configFile = DEFAULT_CONFIG_FILE;
如果沒有使用-cf指定配置文件路徑,則使用默認路徑“src/main/resources/floodlightdefault.properties”
CmdLineParser 解析命令參數(shù)
CmdLineParser parser = new CmdLineParser(settings) parser.parserArgument(args)加載模塊
moduleContext=fml.loadModulesFromConfig(settings.getModuleFile())
settings.getModuleFile()提供配置文件的路徑
目的是獲得配置文件里的模塊的集合configMods和prop是除去配置文件里的模塊鍵值對后剩余的配置信息(模塊的配置參數(shù))
loadModulesFromList(configsMods,prop)填充moduleNameMap,moduleServiceMap,ServiceMap
這個方法比較重要的是這個 ServiceLoader,返回服務(wù)加載器
ServiceLoadermoduleLoader = ServiceLoader.load(IFloodlightModule.class, cl);
ServiceLoader 為了注冊服務(wù),需要在類路徑 src/main/resources/META_INF/services文件夾內(nèi)列好注冊服務(wù)的模塊,可以得到繼承了 IFloodlightModule 接口的實現(xiàn)類
使用moduleLoader.iterator()迭代器去填充moduleNameMap,moduleServiceMap,ServiceMap
moduleNameMap 模塊名稱-模塊對象 Map
moduleServiceMAP 模塊名稱-模塊服務(wù) Map
ServiceMap 模塊服務(wù)-模塊名稱 Map
添加模塊到模塊的哈希集moduleMap,同時注冊它們的服務(wù)(即得到已加載模塊序列 moduleList)
解析每個模塊的配置參數(shù)
取配置文件的一條參數(shù)配置net.floodlightcontroller.forwarding.Forwarding.match=in-port, vlan, mac, ip, transport舉例
key:net.floodlightcontroller.forwarding.Forwarding.match
String configKey=key.substring(LastPeriod+1)
獲到的就是 match,即 configKey=match
String systemKey = System.getProperty(key); if (systemKey != null) { configValue = systemKey; } else { configValue = prop.getProperty(key); }
如果系統(tǒng)屬性已經(jīng)存在,則使用系統(tǒng)屬性的值,如果不存在,則configValue = prop.getProperty(key);【即 configValue 在此處為in-port, vlan, mac, ip, transport】
添加模塊的配置參數(shù)
FloodlightModuleLoader 類下的方法
public void addConfigParam(IFloodlightModule mod, String key, String value) { MapmoduleParams = configParams.get(mod.getClass()); if (moduleParams == null) { moduleParams = new HashMap (); configParams.put(mod.getClass(), moduleParams); } moduleParams.put(key, value); }
初始化已加載模塊列表下的模塊
獲得模塊的服務(wù)實例
Map, IFloodlightService> simpls = module.getServiceImpls();
添加服務(wù)到 floodlightModuleContext
if (floodlightModuleContext.getServiceImpl(s.getKey()) == null) { floodlightModuleContext.addService(s.getKey(), s.getValue());
遍歷已加載模塊集,開始初始化模塊,調(diào)用模塊的方法:init
for (IFloodlightModule module : moduleSet) { // init the module if (logger.isDebugEnabled()) { logger.debug("Initializing " + module.getClass().getCanonicalName()); } module.init(floodlightModuleContext); }
調(diào)用已加載模塊的啟動方法
遍歷已加載模塊集,調(diào)用每個模塊的啟動方法
for (IFloodlightModule m : moduleSet) { if (logger.isDebugEnabled()) { logger.debug("Starting " + m.getClass().getCanonicalName()); } m.startUp(floodlightModuleContext); }
返回公共環(huán)境變量
fml.runModules()運動控制器模塊和所有模塊
getModuleList()獲得一個按初始化順序的模塊列表
返回一個不可修改的已加載模塊序列,如果沒被初始化則返回 null
public ListgetModuleList() { if (loadedModuleList == null) return Collections.emptyList(); else return Collections.unmodifiableList(loadedModuleList); }
runModules()
for (IFloodlightModule m : getModuleList()) { for (Method method : m.getClass().getDeclaredMethods()) { Run runAnnotation = method.getAnnotation(Run.class); if (runAnnotation != null) { RunMethod runMethod = new RunMethod(m, method); if(runAnnotation.mainLoop()) { mainLoopMethods.add(runMethod); } else { runMethod.run(); } } } }
for 循環(huán)遍歷模塊中的方法,找到@run注解的方法為主方法,以下的就是 FloodlightProvider 提供的 run 方法
@Run(mainLoop=true) public void run() throws FloodlightModuleException { controller.run(); }
運行控制器的模塊
mainLoopMethods.get(0).run();
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://www.ezyhdfw.cn/yun/76541.html
摘要:每個消息將通過一個的線程進行處理,并執(zhí)行與所有模塊的消息相關(guān)聯(lián)的所有邏輯其他模塊也可以注冊類似交換機連接或斷開和端口狀態(tài)通知特定時間。默認情況下,使用地址和來識別設(shè)備。設(shè)備管理器將了解其他屬性,如地址。在消息轉(zhuǎn)發(fā)實現(xiàn)前,模塊將啟動。 FloodlightProvider 處理交換機之間的連接并將 OpenFlow 的消息轉(zhuǎn)化成其他模塊可以監(jiān)聽的時間 決定某些特定的 OpenFLow ...
摘要:本篇開始介紹自定義組件是如何渲染的。組件將自定義組件命名為,結(jié)構(gòu)如下經(jīng)過編譯后,生成如下代碼構(gòu)建頂層包裝組件跟普通元素渲染一樣,第一步先會執(zhí)行創(chuàng)建為的。調(diào)用順序已在代碼中注釋。先看圖,這部分內(nèi)容將在下回分解 前言 React 是一個十分龐大的庫,由于要同時考慮 ReactDom 和 ReactNative ,還有服務(wù)器渲染等,導(dǎo)致其代碼抽象化程度很高,嵌套層級非常深,閱讀其源碼是一個非...
摘要:此時服務(wù)器處于休眠狀態(tài),并使用進行事件輪詢,等待監(jiān)聽事件的發(fā)生。繼續(xù)執(zhí)行被調(diào)試程序,直至下一個斷點或程序結(jié)束縮寫。服務(wù)啟動包括初始化基礎(chǔ)配置數(shù)據(jù)結(jié)構(gòu)對外提供服務(wù)的準備工作還原數(shù)據(jù)庫執(zhí)行事件循環(huán)等。 一直很羨慕那些能讀 Redis 源碼的童鞋,也一直想自己解讀一遍,但迫于 C 大魔王的壓力,解讀日期遙遙無期。 相信很多小伙伴應(yīng)該也都對或曾對源碼感興趣,但一來覺得自己不會 C 語言,二來也...
摘要:但是也存在諸多的問題,隨著新設(shè)備的出現(xiàn)以及對安全的重視,這些缺點越發(fā)顯得突出,例如日志消息內(nèi)容無法驗證數(shù)據(jù)格式松散日志檢索低效有限的元數(shù)據(jù)保存無法記錄二進制數(shù)據(jù)等。該服務(wù)可以為項目增加一定數(shù)量的元數(shù)據(jù)。 前言 對于日志系統(tǒng)的重要性不言而喻,參照滬江的一篇關(guān)于日志系統(tǒng)的介紹,基本上日志數(shù)據(jù)在以下幾方面具有非常重要的作用: 數(shù)據(jù)查找:通過檢索日志信息,定位相應(yīng)的 bug ,找出解決方案 ...
閱讀 2461·2021-10-09 09:41
閱讀 3337·2021-09-26 09:46
閱讀 906·2021-09-03 10:34
閱讀 3244·2021-08-11 11:22
閱讀 3436·2019-08-30 14:12
閱讀 780·2019-08-26 11:34
閱讀 3403·2019-08-26 11:00
閱讀 1841·2019-08-26 10:26