ofproto作为openflow的通用层,实现了对外通用配置接口(比如端口,dp)及openflow协议的处理。

image.png

初始化


image.png

实例创建


  1. int
  2. ofproto_create(const char *datapath_name, const char *datapath_type,
  3. struct ofproto **ofprotop)
  • 作用:完成ofproto实例的构建,后续所有的操作都在实例上面操作。一个实例对应一个datapath,多个datapath可能对应同一个,一种类型只有一个。
  • 参数里面最重要的是datapath_type(比如system等),这个是对应dp的类型,一个ofproto实现类可能实现了多种类型,通过这个类型找到对应的ofproto实现类。

image.png

添加端口


  1. /* Attempts to add 'netdev' as a port on 'ofproto'. If 'ofp_portp' is
  2. * non-null and '*ofp_portp' is not OFPP_NONE, attempts to use that as
  3. * the port's OpenFlow port number.
  4. */
  5. int ofproto_port_add(struct ofproto *ofproto, struct netdev *netdev,
  6. ofp_port_t *ofp_portp)
  • netdev由上层应用创建传入

image.png

RUN


xx_run函数执行ofproto的内部任务。通过xx_wait函数来决定唤醒的时机。主要包括以下:

  • 定时任务
  • openflow的消息处理
  • 调用实现类处理
    1. int ofproto_run(struct ofproto *);
    2. void ofproto_wait(struct ofproto *);
    3. int ofproto_type_run(const char *datapath_type);
    4. void ofproto_type_wait(const char *datapath_type);
    image.png