设置 ICMP 与 POX 控制器匹配
Setting ICMP match with POX controller
我正在尝试使用 POX 控制器向交换机添加流条目,我的代码是:
fm = of.ofp_flow_mod()
fm.match.in_port = 1
fm.priority = 33001
fm.match.dl_type = 0x800
fm.match.nw_src = IPAddr("10.0.0.1")
fm.match.nw_dst = IPAddr("10.0.0.5")
fm.actions.append(of.ofp_action_output( port = 2 ) )
event.connection.send( fm )
但是,当我从 10.0.0.1 ping 到 10.0.0.5 时,没有任何回复。
可能是什么问题?
(我还为 ICMP 回复添加了对称流)
谢谢
(注意:我在以下示例中将 10.0.0.5
更改为 10.0.0.3
,因为我在 mininet 中使用 1 个交换机、3 个主机拓扑进行测试。)
您的问题是 ARP 请求没有通过。您需要添加两个额外的规则来让 dl_type=0x0806 的消息通过。所以:
def _handle_ConnectionUp (event):
fm = of.ofp_flow_mod()
fm.match.in_port = 1
fm.priority = 33001
fm.match.dl_type = 0x0800
fm.match.nw_src = IPAddr("10.0.0.1")
fm.match.nw_dst = IPAddr("10.0.0.3")
fm.actions.append(of.ofp_action_output( port = 3 ) )
event.connection.send( fm )
fm = of.ofp_flow_mod()
fm.match.in_port = 3
fm.priority = 33001
fm.match.dl_type = 0x0800
fm.match.nw_src = IPAddr("10.0.0.3")
fm.match.nw_dst = IPAddr("10.0.0.1")
fm.actions.append(of.ofp_action_output( port = 1 ) )
event.connection.send( fm )
fm = of.ofp_flow_mod()
fm.match.in_port = 1
fm.priority = 33001
fm.match.dl_type = 0x0806
fm.actions.append(of.ofp_action_output( port = 3 ) )
event.connection.send( fm )
fm = of.ofp_flow_mod()
fm.match.in_port = 3
fm.priority = 33001
fm.match.dl_type = 0x0806
fm.actions.append(of.ofp_action_output( port = 1 ) )
event.connection.send( fm )
如果您的网络中没有任何环路,您也可以只添加一条规则,在每个端口上泛洪数据包,除了它来自的端口。
fm = of.ofp_flow_mod()
fm.priority = 33001
fm.match.dl_type = 0x0806
fm.actions.append(of.ofp_action_output( port = of.OFPP_FLOOD ) )
event.connection.send( fm )
更多信息:当您发送一个 ICMP 回应请求到一个 IP 地址时,会发生以下情况:
- 主机发出 ARP 请求 ("who has IP 10.0.0.3?") 以找出下一跳的硬件 MAC 地址。
- 主机然后向下一跳发送 ICMP 数据包。
如果初始查询没有得到响应,则不会发送 ICMP 数据包,因为主机不知道下一步要将它发送到哪里。您可以在本答案末尾的 tcpdump
示例中看到这一点。
这是 mininet 的输出:
mininet@mininet-vm:~$ sudo mn --topo single,3 --mac --switch ovsk,protocols=OpenFlow10 --controller remote
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2 h3
*** Adding switches:
s1
*** Adding links:
(h1, s1) (h2, s1) (h3, s1)
*** Configuring hosts
h1 h2 h3
*** Starting controller
c0
*** Starting 1 switches
s1 ...
*** Starting CLI:
mininet> pingall
*** Ping: testing ping reachability
h1 -> X h3
h2 -> X X
h3 -> h1 X
*** Results: 66% dropped (2/6 received)
mininet>
那么如果我们已经 "know" 下一跳是什么呢?在这种情况下,我们可以告诉 ping
从特定接口发送 ICMP IPv4 数据包。那时它不会使用ARP。但是,ping 请求的接收方仍会尝试使用 ARP 来确定如何发送响应。请求会到达,但响应不会。
您可以强制将初始 ping 发送到特定接口,而不使用 运行ning 的 ARP 请求:
# Run this on host h1
h1 ping -I h1-eth0 -c1 10.0.0.3
即使您没有设置 ARP 规则(因为 nw_src
和 nw_dst
匹配),初始 ICMP 数据包也会通过。如果你在 h3 上 运行 tcpdump
(运行 xterm h3
并且在新终端 tcpdump
),你可以看到 ICMP 消息在这种情况下到达,但是return 消息没有。
# Run this on host h3
root@mininet-vm:~# tcpdump
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on h3-eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
20:20:19.428465 IP 10.0.0.1 > 10.0.0.3: ICMP echo request, id 24690, seq 1, length 64
20:20:19.428481 ARP, Request who-has 10.0.0.1 tell 10.0.0.3, length 28
20:20:20.428094 ARP, Request who-has 10.0.0.1 tell 10.0.0.3, length 28
20:20:21.428097 ARP, Request who-has 10.0.0.1 tell 10.0.0.3, length 28
最后一长串 ARP 请求是接收主机试图找出应该通过哪个接口发回响应。
我正在尝试使用 POX 控制器向交换机添加流条目,我的代码是:
fm = of.ofp_flow_mod()
fm.match.in_port = 1
fm.priority = 33001
fm.match.dl_type = 0x800
fm.match.nw_src = IPAddr("10.0.0.1")
fm.match.nw_dst = IPAddr("10.0.0.5")
fm.actions.append(of.ofp_action_output( port = 2 ) )
event.connection.send( fm )
但是,当我从 10.0.0.1 ping 到 10.0.0.5 时,没有任何回复。 可能是什么问题? (我还为 ICMP 回复添加了对称流)
谢谢
(注意:我在以下示例中将 10.0.0.5
更改为 10.0.0.3
,因为我在 mininet 中使用 1 个交换机、3 个主机拓扑进行测试。)
您的问题是 ARP 请求没有通过。您需要添加两个额外的规则来让 dl_type=0x0806 的消息通过。所以:
def _handle_ConnectionUp (event):
fm = of.ofp_flow_mod()
fm.match.in_port = 1
fm.priority = 33001
fm.match.dl_type = 0x0800
fm.match.nw_src = IPAddr("10.0.0.1")
fm.match.nw_dst = IPAddr("10.0.0.3")
fm.actions.append(of.ofp_action_output( port = 3 ) )
event.connection.send( fm )
fm = of.ofp_flow_mod()
fm.match.in_port = 3
fm.priority = 33001
fm.match.dl_type = 0x0800
fm.match.nw_src = IPAddr("10.0.0.3")
fm.match.nw_dst = IPAddr("10.0.0.1")
fm.actions.append(of.ofp_action_output( port = 1 ) )
event.connection.send( fm )
fm = of.ofp_flow_mod()
fm.match.in_port = 1
fm.priority = 33001
fm.match.dl_type = 0x0806
fm.actions.append(of.ofp_action_output( port = 3 ) )
event.connection.send( fm )
fm = of.ofp_flow_mod()
fm.match.in_port = 3
fm.priority = 33001
fm.match.dl_type = 0x0806
fm.actions.append(of.ofp_action_output( port = 1 ) )
event.connection.send( fm )
如果您的网络中没有任何环路,您也可以只添加一条规则,在每个端口上泛洪数据包,除了它来自的端口。
fm = of.ofp_flow_mod()
fm.priority = 33001
fm.match.dl_type = 0x0806
fm.actions.append(of.ofp_action_output( port = of.OFPP_FLOOD ) )
event.connection.send( fm )
更多信息:当您发送一个 ICMP 回应请求到一个 IP 地址时,会发生以下情况:
- 主机发出 ARP 请求 ("who has IP 10.0.0.3?") 以找出下一跳的硬件 MAC 地址。
- 主机然后向下一跳发送 ICMP 数据包。
如果初始查询没有得到响应,则不会发送 ICMP 数据包,因为主机不知道下一步要将它发送到哪里。您可以在本答案末尾的 tcpdump
示例中看到这一点。
这是 mininet 的输出:
mininet@mininet-vm:~$ sudo mn --topo single,3 --mac --switch ovsk,protocols=OpenFlow10 --controller remote
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2 h3
*** Adding switches:
s1
*** Adding links:
(h1, s1) (h2, s1) (h3, s1)
*** Configuring hosts
h1 h2 h3
*** Starting controller
c0
*** Starting 1 switches
s1 ...
*** Starting CLI:
mininet> pingall
*** Ping: testing ping reachability
h1 -> X h3
h2 -> X X
h3 -> h1 X
*** Results: 66% dropped (2/6 received)
mininet>
那么如果我们已经 "know" 下一跳是什么呢?在这种情况下,我们可以告诉 ping
从特定接口发送 ICMP IPv4 数据包。那时它不会使用ARP。但是,ping 请求的接收方仍会尝试使用 ARP 来确定如何发送响应。请求会到达,但响应不会。
您可以强制将初始 ping 发送到特定接口,而不使用 运行ning 的 ARP 请求:
# Run this on host h1
h1 ping -I h1-eth0 -c1 10.0.0.3
即使您没有设置 ARP 规则(因为 nw_src
和 nw_dst
匹配),初始 ICMP 数据包也会通过。如果你在 h3 上 运行 tcpdump
(运行 xterm h3
并且在新终端 tcpdump
),你可以看到 ICMP 消息在这种情况下到达,但是return 消息没有。
# Run this on host h3
root@mininet-vm:~# tcpdump
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on h3-eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
20:20:19.428465 IP 10.0.0.1 > 10.0.0.3: ICMP echo request, id 24690, seq 1, length 64
20:20:19.428481 ARP, Request who-has 10.0.0.1 tell 10.0.0.3, length 28
20:20:20.428094 ARP, Request who-has 10.0.0.1 tell 10.0.0.3, length 28
20:20:21.428097 ARP, Request who-has 10.0.0.1 tell 10.0.0.3, length 28
最后一长串 ARP 请求是接收主机试图找出应该通过哪个接口发回响应。