open vswitch源代码解析(二)flow table解析函数入口ovs_flow_tbl_lookup_stats

flow table解析函数入口ovs_flow_tbl_lookup_stats

flow table解析函数ovs_flow_tbl_lookup_stats主要完成从flow table db中寻找可用于key的flow rule,其中用到了hash机制首先快速查找,如果miss再进行full lookup;

首先咱们注解一下hash查找的过程:

ce = NULL;
entries = this_cpu_ptr(tbl->mask_cache);

/* Find the cache entry 'ce' to operate on. */
for (seg = 0; seg < MC_HASH_SEGS; seg++) {
int index = hash & (MC_HASH_ENTRIES - 1);
struct mask_cache_entry *e;

e = &entries[index];
if (e->skb_hash == skb_hash) {
struct sw_flow_mask *cache;
int i = e->mask_index;

if (likely(i < ma->max)) {
cache = rcu_dereference(ma->masks[i]);
if (cache) {
flow = masked_flow_lookup(ti, key,
cache, n_mask_hit);
/*cache contains avaliable sector to find all hit*/
if (flow)
return flow;
}
}

/* Cache miss. This is the best cache
 * replacement candidate.  */
e->skb_hash = 0;
ce = e;
break;
}

if (!ce || e->skb_hash < ce->skb_hash)
ce = e;  /* A better replacement cache candidate. */

hash >>= MC_HASH_SHIFT;
}


该代码片断即为hash查找的主要过程,

hash = flow_hash(&masked_key, key_start, key_end);
head = find_bucket(ti, hash);
(*n_mask_hit)++;
hlist_for_each_entry_rcu(flow, head, hash_node[ti->node_ver]) {
if (flow->mask == mask && flow->hash == hash &&
    flow_cmp_masked_key(flow, &masked_key,
  key_start, key_end))
return flow;
}

你可能感兴趣的:(学习)