(一)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 









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值