https://software.intel.com/en-us/articles/the-open-vswitch-exact-match-cache
emc_processing() [ dpif-netdev.c ] >> miniflow_extract() [ flow.c ] >> struct flow or struct ip_header
emc_processing主要是將收到的幾個封包解析key值,並且從cache中查找表格,match到的封包放入表格;返回match的封包個數。
使用miniflow_extract() 將封包解析到key值。使用emc_lookup()從hash表中找尋,並且進行key值的比較。
Flow.h #83
Struct flow /* L3 (64-bit aligned) */ ovs_be32 nw_src; /* IPv4 source address or ARP SPA. */ ovs_be32 nw_dst; /* IPv4 destination address or ARP TPA. */Packets.h
#define IP_HEADER_LEN 20struct ip_header { uint8_t ip_ihl_ver; uint8_t ip_tos; ovs_be16 ip_tot_len; ovs_be16 ip_id; ovs_be16 ip_frag_off; uint8_t ip_ttl; uint8_t ip_proto; ovs_be16 ip_csum; ovs_16aligned_be32 ip_src; ovs_16aligned_be32 ip_dst;};/usr/local/ovs/lib/flow.c
miniflow_extract @ flow.c #750
/* Network layer. */ packet->l3_ofs = (char *)data - l2; nw_frag = 0; if (OVS_LIKELY(dl_type == htons(ETH_TYPE_IP))) { const struct ip_header *nh = data; int ip_len; uint16_t tot_len; if (OVS_UNLIKELY(size < IP_HEADER_LEN)) { goto out; } ip_len = IP_IHL(nh->ip_ihl_ver) * 4; if (OVS_UNLIKELY(ip_len < IP_HEADER_LEN)) { goto out; } if (OVS_UNLIKELY(size < ip_len)) { goto out; } tot_len = ntohs(nh->ip_tot_len); if (OVS_UNLIKELY(tot_len > size || ip_len > tot_len)) { goto out; } if (OVS_UNLIKELY(size - tot_len > UINT8_MAX)) { goto out; } dp_packet_set_l2_pad_size(packet, size - tot_len); size = tot_len; /* Never pull padding. */ /* Push both source and destination address at once. */ miniflow_push_words(mf, nw_src, &nh->ip_src, 1); miniflow_push_be32(mf, ipv6_label, 0); /* Padding for IPv4. */ nw_tos = nh->ip_tos; nw_ttl = nh->ip_ttl; nw_proto = nh->ip_proto; if (OVS_UNLIKELY(IP_IS_FRAGMENT(nh->ip_frag_off))) { nw_frag = FLOW_NW_FRAG_ANY; if (nh->ip_frag_off & htons(IP_FRAG_OFF_MASK)) { nw_frag |= FLOW_NW_FRAG_LATER; } } data_pull(&data, &size, ip_len);#最新ovs版本,不太相同
ovs_be32 ct_nw_src;
ovs_be32 ct_nw_dst;
flow.c 內有用到nw_src的function
#632 miniflow_extract(struct dp_packet *packet, struct miniflow *dst)#306 #define miniflow_push_words(MF, FIELD, VALUEP, N_WORDS) \#307 miniflow_push_words_(MF, offsetof(struct flow, FIELD), VALUEP, N_WORDS)#1661 #1679
flow_wildcards_init_for_packet(struct flow, --------)
#1776 #1822
flow_wc_map(struct flow, ---------)
#1985 miniflow_hash_5tuple(const struct miniflow *flow, uint32_t basis)#2006 hash = hash_add(hash, MINIFLOW_GET_U32(flow, nw_src));packets.h
#define IP_HEADER_LEN 20struct ip_header { uint8_t ip_ihl_ver; uint8_t ip_tos; ovs_be16 ip_tot_len; ovs_be16 ip_id; ovs_be16 ip_frag_off; uint8_t ip_ttl; uint8_t ip_proto; ovs_be16 ip_csum; ovs_16aligned_be32 ip_src; ovs_16aligned_be32 ip_dst;};oj