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;
}

这部分代码还真他妈的不懂什么意思。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值