虚拟 router 原理分析

666.png

上一节咱们建立了虚拟路由器“router_100_101”,并经过 ping 验证了 vlan100 和 vlan101 已经连通。linux

本节将重点分析其中的原理。网络

首先咱们查看控制节点的 linux bridge 结构发生了什么变化。spa

vlan101 的 bridge 上多了一个 tape17162c5-00,从命名上能够推断该 TAP 设备对应 router_100_101 的 interface (e17162c5-00fa)。router

vlan100 的 bridge 上多了一个 tapd568ba1a-74,从命名上能够推断该 TAP 设备对应 router_100_101 的 interface (d568ba1a-740e)。blog

当前网络结构如图所示:ip

但发现一个问题:两个 TAP 设备上并无配置相应的 Gateway IP。路由

若是没有 Gateway IP,router_100_101 是如何完成路由的呢?it

答案是: l3 agent 会为每一个 router 建立了一个 namespace,经过 veth pair 与 TAP 相连,而后将 Gateway IP 配置在位于 namespace 里面的 veth interface 上,这样就能提供路由了。原理

经过 ip netns 查看 namespace:
配置

router 对应的 namespace 命名为 qrouter-<router id>。

经过 ip netns exec <namespace name> ip a 命令查看 router_100_101 namespace 中的 veth interface 配置。

namespace 中有两个 interface:

  1. qr-e17162c5-00 上设置了 Gateway IP 172.16.101.1,与 root namespace 中的 tape17162c5-00 组成 veth pair。

  2. qr-d568ba1a-74 上设置了 Gateway IP 172.16.100.1,与 root namespace 中的 tapd568ba1a-74 组成 veth pair。

网络结构如图所示:

namespace 中的路由表也保证了 subnet_172_16_100_0 和 subnet_172_16_101_0 之间是能够路由的。

分析到这里,咱们已经搞清楚 router_100_101 是如何打通 vlan100 和 vlan 101 了。

但这里有一个关键问题须要进一步分析:
为何要把 router_100_101 放到 namespace 中?

下一节咱们将详细分析这个问题。

 

blob.png

相关文章
相关标签/搜索