(一)SDN 控制器 NOX 源碼分析之—— nox_main.cc

nox_main.cc

Application_list parse_application_list(int optind, int argc, char** argv) 
從NOX啓動命令行中獲得啓動程序的名字以及所帶參數,返回(程序名,參數)的列表
void hello(const char* program_name)
打印NOX版本信息以及編譯事件
void usage(const char* program_name)
打印NOX的使用方法
int daemon()
使程序成爲守護進程
static void finish_booting(Kernel*, const Application_list&)
將需要加載的應用程序模塊加載到kernel中完成NOX最終引導
void shutdown(int param)
由信號param引起的關閉NOX
Kernel::init(info_file, argc, argv)
啓動NOX內核,info_file記錄了NOX控制器啓動的次數,以及控制器的UUID(universally unique identifier of this NOX instance)
Kernel::get_instance()
啓動取得NOX 的Kernel實例,這個實例全局只有一個
kernel->set_argument(app.first, app.second);
向NOX的kernel傳遞模塊名以及模塊的參數
Component_context* event_dispatcher_context = 
new Static_component_context( 
boost::bind(&Event_dispatcher::instantiate, _1, n_threads), 
typeid(Event_dispatcher).name(), 
"event-dispatcher", 
platform_config_path);
添加事件分發器
Static_component_context爲靜態組件上下文環境類,繼承自組件上下文環境類,構造函數的參數爲:
1、輸入組件上下文獲得對應組件實例的方法;
2、組件的類名;
3、組件模塊名;
4、模塊配置文件路徑
kernel->install(event_dispatcher_context, INSTALLED);
給內核加載組件,參數爲組件上下文對象和要達到的加載狀態
 Component_context* dso_deployer_context =
new Static_component_context(
boost::bind(&DSO_deployer::instantiate, _1, lib_dirs),
typeid(DSO_deployer).name(),
"dso-deployer",
platform_config_path);
kernel->install(dso_deployer_context, INSTALLED);
添加動態組件部署器
Component_context* connection_manager_context =
new Static_component_context(
boost::bind(&Connection_manager::instantiate, _1, interfaces),
typeid(Connection_manager).name(),
"connection-manager",
platform_config_path);
kernel->install(connection_manager_context, INSTALLED);
添加連接管理器,管理網絡連接
static void finish_booting(Kernel* kernel, const Application_list& applications)
將已經設置到內核中的應用組件啓動
Event_dispatcher* ed =
            dynamic_cast<Event_dispatcher*>(event_dispatcher_context->get_instance());
取得事件分發器的實例。每一個上下文類都有一個get_instance()的方法用來得到相應的實例對象
post_shutdown = boost::bind(&Event_dispatcher::post, ed, shutdown_event);
bind的一種用法,用來將類方法導出爲一個外部方法,bind(&類名::方法名,此類的對象指針,參數)
ed->register_handler(Shutdown_event::static_get_name(),
boost::bind(&remove_pid_file, pid_file, _1),
9998);
爲事件分發器註冊句柄,參數爲(事件名,處理方法,同事件發生時的調用次序(或優先級))

ed->join_all();
事件分發器的方法,用途爲: Join the threads until the end of execution 









發佈了29 篇原創文章 · 獲贊 9 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章