1、struct datapath {//网桥结构
    struct rcu_head rcu;//rcu使用结构
    struct list_head list_node;//链入网桥链的节点
    struct kobject ifobj;//网桥在文件系统中对应的结构(内核设备在/sys/class/net中的映射)
    struct flow_table __rcu *table;//网桥对应的流表
    struct hlist_head *ports;//交换机的端口
    struct dp_stats_percpu __percpu *stats_percpu;//统计信息(在不同的cpu上均有)
#ifdef CONFIG_NET_NS
    struct net *net;//网络命名空间
#endif
};

2、struct vport {//网桥的端口结构
    struct rcu_head rcu;//rcu使用结构
    u16 port_no;//端口number
    struct datapath    *dp;//指向端口所在网桥的指针
    struct kobject kobj;//端口在文件系统中对应的结构(内核设备在/sys/class/net中的映射)
    char linkname[IFNAMSIZ];//端口在文件系统中的名称(在/sys/class/net/<datapath>/brif/目录下能看到的端口对应的名称)
    struct list_head node;
    u32 upcall_pid;//netlink对应的upcall_pid
    struct hlist_node hash_node;//链入dev_table的节点
    struct hlist_node dp_hash_node;//链入网桥的ports的节点
    const struct vport_ops *ops;//端口操作表
    struct vport_percpu_stats __percpu *percpu_stats;//端口统计信息(在不同的cpu上均有)
    spinlock_t stats_lock;//对端口的err_stats和offset_stats的读写锁
    struct vport_err_stats err_stats;//错误信息统计结构
    struct ovs_vport_stats offset_stats;//更详细的统计信息结构
};

以下3、4、5结构顾名思义:

3、struct vport_percpu_stats {
    u64 rx_bytes;
    u64 rx_packets;
    u64 tx_bytes;
    u64 tx_packets;
    struct u64_stats_sync sync;
};

4、
struct vport_err_stats {
    u64 rx_dropped;
    u64 rx_errors;
    u64 tx_dropped;
    u64 tx_errors;
};

5、
struct ovs_vport_stats {
    __u64   rx_packets;        /* total packets received       */
    __u64   tx_packets;        /* total packets transmitted    */
    __u64   rx_bytes;        /* total bytes received         */
    __u64   tx_bytes;        /* total bytes transmitted      */
    __u64   rx_errors;        /* bad packets received         */
    __u64   tx_errors;        /* packet transmit problems     */
    __u64   rx_dropped;        /* no space in linux buffers    */
    __u64   tx_dropped;        /* no space available in linux  */
};

6、struct vport_parms {//端口参数结构(或端口配置结构),创建端口结构vport时临时存放vport所需的参数
    const char *name;//端口名称
    enum ovs_vport_type type;//端口类型(system、internal、tap、patch、gre、ipsec_gre、capwap、null)
    struct nlattr *options;//netlink用的一些选项(默认懂netlink)
    struct datapath *dp;//端口所在的网桥
    u16 port_no;//端口number
    u32 upcall_pid;//netlink用的upcall_pid
};

以下是端口的操作表,其中的每个函数顾名思义

7、struct vport_ops {//端口操作表
    enum ovs_vport_type type;//端口类型
    u32 flags;
    /* Called at module init and exit respectively. */
    int (*init)(void);
    void (*exit)(void);

    /* Called with RTNL lock. */
    struct vport *(*create)(const struct vport_parms *);
    void (*destroy)(struct vport *);

    int (*set_options)(struct vport *, struct nlattr *);
    int (*get_options)(const struct vport *, struct sk_buff *);

    int (*set_addr)(struct vport *, const unsigned char *);

    /* Called with rcu_read_lock or RTNL lock. */
    const char *(*get_name)(const struct vport *);
    const unsigned char *(*get_addr)(const struct vport *);
    void (*get_config)(const struct vport *, void *);
    struct kobject *(*get_kobj)(const struct vport *);

    unsigned (*get_dev_flags)(const struct vport *);
    int (*is_running)(const struct vport *);
    unsigned char (*get_operstate)(const struct vport *);

    int (*get_ifindex)(const struct vport *);

    int (*get_mtu)(const struct vport *);

    int (*send)(struct vport *, struct sk_buff *);
};

8、
struct flow_table {//流表结构
    struct flex_array *buckets;//流表项数组
    unsigned int count, n_buckets;//流表项统计
    struct rcu_head rcu;//rcu使用结构(默认懂RCU)
    int node_ver;//流表项flow->hash_node[]数组的下表(具体为什么要用两个节点暂未清楚)
    u32 hash_seed;//哈斯种子(只要知道流表项要加到流表项数组中用来计算哈斯值的就行了)
    bool keep_flows;//是否保留流表项,true表示保留不允许删除
};
 

9、struct sw_flow {//流表项结构
    struct rcu_head rcu;//rcu所使用结构
    struct hlist_node hash_node[2];//链入流表的节点,即通过它链入相应的流表的buckets中
    u32 hash;//哈斯值,根据该哈斯值链入流表的相应哈斯桶
    struct sw_flow_key key;//流表项的的key
    struct sw_flow_actions __rcu *sf_acts;//该流表项对应的动作
    atomic_t refcnt;//引用次数,创建时设为1
    bool dead;//是否已经过期
    spinlock_t lock;    /* Lock for values below. */
    unsigned long used;    /* Last used time (in jiffies). */
    u64 packet_count;    //匹配包的个数
    u64 byte_count;       //匹配的bit
    u8 tcp_flags;        /* Union of seen TCP flags. */
};


10、struct sw_flow_key {//流表项的key结构,几乎涵盖报文的四层以及四层一下的每个字段(默认对报文结构很熟)
    struct {
        __be64    tun_id;        /* Encapsulating tunnel ID. */
        u32    priority;    /* Packet QoS priority. */
        u16    in_port;    /* Input switch port (or DP_MAX_PORTS). */
    } phy;
    struct {
        u8     src[ETH_ALEN];    /* Ethernet source address. */
        u8     dst[ETH_ALEN];    /* Ethernet destination address. */
        __be16 tci;        /* 0 if no VLAN, VLAN_TAG_PRESENT set otherwise. */
        __be16 type;        /* Ethernet frame type. */
    } eth;
    struct {
        u8     proto;        /* IP protocol or lower 8 bits of ARP opcode. */
        u8     tos;        /* IP ToS. */
        u8     ttl;        /* IP TTL/hop limit. */
        u8     frag;        /* One of OVS_FRAG_TYPE_*. */
    } ip;
    union {
        struct {
            struct {
                __be32 src;    /* IP source address. */
                __be32 dst;    /* IP destination address. */
            } addr;
            union {
                struct {
                    __be16 src;        /* TCP/UDP source port. */
                    __be16 dst;        /* TCP/UDP destination port. */
                } tp;
                struct {
                    u8 sha[ETH_ALEN];    /* ARP source hardware address. */
                    u8 tha[ETH_ALEN];    /* ARP target hardware address. */
                } arp;
            };
        } ipv4;
        struct {
            struct {
                struct in6_addr src;    /* IPv6 source address. */
                struct in6_addr dst;    /* IPv6 destination address. */
            } addr;
            __be32 label;            /* IPv6 flow label. */
            struct {
                __be16 src;        /* TCP/UDP source port. */
                __be16 dst;        /* TCP/UDP destination port. */
            } tp;
            struct {
                struct in6_addr target;    /* ND target address. */
                u8 sll[ETH_ALEN];    /* ND source link layer address. */
                u8 tll[ETH_ALEN];    /* ND target link layer address. */
            } nd;
        } ipv6;
    };
};
 

11、struct sw_flow_actions {//流表项对应的动作结构
    struct rcu_head rcu;
    u32 actions_len;//动作的长度
    struct nlattr actions[];//所有的动作
};