ofproto作为openflow的通用层,实现了对外通用配置接口(比如端口,dp)及openflow协议的处理。
初始化
实例创建
int
ofproto_create(const char *datapath_name, const char *datapath_type,
struct ofproto **ofprotop)
- 作用:完成ofproto实例的构建,后续所有的操作都在实例上面操作。一个实例对应一个datapath,多个datapath可能对应同一个,一种类型只有一个。
- 参数里面最重要的是datapath_type(比如system等),这个是对应dp的类型,一个ofproto实现类可能实现了多种类型,通过这个类型找到对应的ofproto实现类。
添加端口
/* Attempts to add 'netdev' as a port on 'ofproto'. If 'ofp_portp' is
* non-null and '*ofp_portp' is not OFPP_NONE, attempts to use that as
* the port's OpenFlow port number.
*/
int ofproto_port_add(struct ofproto *ofproto, struct netdev *netdev,
ofp_port_t *ofp_portp)
- netdev由上层应用创建传入
RUN
xx_run
函数执行ofproto的内部任务。通过xx_wait
函数来决定唤醒的时机。主要包括以下:
- 定时任务
- openflow的消息处理
- 调用实现类处理
int ofproto_run(struct ofproto *);
void ofproto_wait(struct ofproto *);
int ofproto_type_run(const char *datapath_type);
void ofproto_type_wait(const char *datapath_type);