Mininet MAC地址学习

MAC地址学习

MAC地址是识别LAN节点的标识。MAC对设备(通常是网卡)接口是全球统一的,MAC地址为48bit,用12个十六进制数表示。前6个十六进制数字由IEEE管理,用来识别生产商或者厂商,构成组织唯一识别符(OUI, Organization Unique Identifier)。后6个包括网卡序列号,或者特定硬件厂商的设定值。对于一个网卡来说,MAC地址是它的物理地址,是不可变的,而IP地址是它对应的逻辑地址,是可以更改的。在交换机中有一张记录局域网主机MAC地址与交换机接口对应关系的表,交换机根据这张表负责将数据帧传输到指定的主机上。交换机在接收到数据帧以后,首先将数据帧中的源MAC地址和对应的接口记录到MAC表中,接着检查自己的MAC表中是否有数据帧中目标MAC地址的信息,如果有,则根据MAC表中记录的对应接口将数据帧发送出去(也就是单播),如果没有,则将该数据帧从非接收口发送出去(也就是广播)。

实验

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
$ sudo mn --topo linear --mac --switch ovsk --controller=none # 没有指定控制器,交换机中没有流表的存在,无法进行转发操作,主机h1和h2无法通信。
mininet> pingall # 此时无法ping通
*** Ping: testing ping reachability
h1 -> X
h2 -> X
*** Results: 100% dropped (0/2 received)
$ sudo ovs-ofctl dump-flows s1 # 也无流表存在
NXST_FLOW reply (xid=0x4):

mininet> nodes
available nodes are:
h1 h2 s1 s2
mininet> net
h1 h1-eth0:s1-eth1
h2 h2-eth0:s2-eth1
s1 lo: s1-eth1:h1-eth0 s1-eth2:s2-eth2
s2 lo: s2-eth1:h2-eth0 s2-eth2:s1-eth2
mininet> dump
<Host h1: h1-eth0:10.0.0.1 pid=7448>
<Host h2: h2-eth0:10.0.0.2 pid=7451>
<OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None pid=7457>
<OVSSwitch s2: lo:127.0.0.1,s2-eth1:None,s2-eth2:None pid=7460>

$ sudo ovs-vsctl del-fail-mode s1 # 打开交换机s1的二层,执行该命令后s1变成普通的二层交换机
$ sudo ovs-vsctl del-fail-mode s2 # 同上

mininet> h1 ping h2 # 执行上述步骤,即可ping通
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=0.750 ms
64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=0.038 ms
64 bytes from 10.0.0.2: icmp_seq=3 ttl=64 time=0.044 ms
$ sudo ovs-ofctl dump-flows s1 # 可以看到两条数据帧转发表,这表明交换机已进行过MAC地址学习
NXST_FLOW reply (xid=0x4):
cookie=0x0, duration=63.612s, table=0, n_packets=10, n_bytes=756, idle_age=48, priority=0 actions=NORMAL
$ sudo ovs-ofctl dump-flows s2
NXST_FLOW reply (xid=0x4):
cookie=0x0, duration=64.392s, table=0, n_packets=10, n_bytes=756, idle_age=51, priority=0 actions=NORMAL