Skip to content

Instantly share code, notes, and snippets.

@pichuang
Last active August 26, 2021 16:42
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pichuang/11280233 to your computer and use it in GitHub Desktop.
Save pichuang/11280233 to your computer and use it in GitHub Desktop.
Let mininet nodes can connect to the internet
#!/usr/bin/env python
import os
from mininet.net import Mininet
from mininet.node import Controller, RemoteController
from mininet.cli import CLI
from mininet.link import Intf
from mininet.log import setLogLevel, info
def myNetwork():
net = Mininet( topo=None, build=False)
info( '*** Adding controller\n' )
net.addController(name='c0')
info( '*** Add switches\n')
s1 = net.addSwitch('s1')
# Intf( 'eth0', node=s1 ) #Some Problem
info( '*** Add hosts\n')
h1 = net.addHost('h1', ip='0.0.0.0')
h2 = net.addHost('h2', ip='0.0.0.0')
info( '*** Add links\n')
net.addLink(h1, s1)
net.addLink(h2, s1)
info( '*** Starting network\n')
net.start()
os.popen('ovs-vsctl add-port s1 eth0')
h1.cmdPrint('dhclient '+h1.defaultIntf().name)
h2.cmdPrint('dhclient '+h2.defaultIntf().name)
CLI(net)
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
myNetwork()
@Yi-Tseng
Copy link

Line 18 should be work now?

@nux150
Copy link

nux150 commented May 28, 2018

I have a problem in assigning a dhcp address to h1, when i try to run that script it just stuck in this line h1.cmdPrint('dhclient '+h1.defaultIntf().name) and i don't know the reason, can you plz help me to solve it? this issue is happening also when i try to do it manually from h1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment