简体   繁体   中英

Using Mininet's Python API addHost() Method

I am experiencing connectivity issues when adding hosts to a topology by calling Mininet's addHost() method. The hosts are unable to ping one another, or any outside ip address (by way of the NAT). A simple example of what I am trying to do would be the following:

from mininet.net import Mininet
from mininet.cli import CLI

net = Mininet()
h1 = net.addHost('h1')
h2 = net.addHost('h2')
s1 = net.addSwitch('s1')

net.addLink(s1,h1)
net.addLink(s1,h2)
net.addNAT().configDefault()
net.build()

CLI(net)  

I also don't experience this problem when supplying a topology to the Mininet class constructor, however for what I am doing I require the ability to add hosts after the Mininet instance has been instantiated (like in the above example). Am I doing something wrong?

Edit: I should note that I am using Mininet 2.2.1 inside the supplied VM image.

将第一个主机net.addLink(s1,h1)的顺序更改为net.addLink( h1, s1 )不是交换机,中级API: 网络对象

I figured out the problem. If you pass the Mininet constructor a topology it will automatically add the controller instance for you. However if you build the topology after the Mininet instance has been instantiated (like in the example above) you must add the controller manually using

net.addController('c0')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM