(一)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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章