快速的解决方案是使用python语言和os功能进行ping操作。假设您启动了mininet模拟器
sudo mn --controller=remote
首先给交换机一个ip,以便ping找到去主机的路由。打开一个新终端ssh到你的mininet vm
ssh -X mininet@192.168.56.101
如果您的mininet虚拟机有不同的IP,则更改192.168.56.101。在这种新的终端类型
ifconfig s1
你应该得到类似的东西
Link encap:Ethernet HWaddr fa:64:44:9a:f9:4f UP BROADCAST RUNNING MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
表示您的交换机没有IP。要给我们必须的交换机ip
sudo ifconfig s1 10.0.1.1
然后从您的POX程序ping连接到此开关的主机(即10.0.0.1)。
import os host_ip = "10.0.0.1" #the host ip you want to ping from controller response = os.system("ping -c 1 " + host_ip) #check the response... if response == 0: print host_ip, 'is up!' else: print host_ip, 'is down!'