diff --git a/bin/mn b/bin/mn index 0424d355754237d61ed493f36ee6ff495da34a82..474a3c20052e519288ceb1f1b56e592378eed0ca 100755 --- a/bin/mn +++ b/bin/mn @@ -226,8 +226,6 @@ class MininetRunner( object ): start = time.time() topo = buildTopo( TOPOS, self.options.topo ) - if self.options.nat: - topo.addNAT() switch = customConstructor( SWITCHES, self.options.switch ) host = customConstructor( HOSTS, self.options.host ) controller = customConstructor( CONTROLLERS, self.options.controller ) @@ -255,6 +253,10 @@ class MininetRunner( object ): autoStaticArp=arp, autoPinCpus=pin, listenPort=listenPort ) + if self.options.nat: + nat = mn.addNAT() + mn.configHosts() + if self.options.pre: CLI( mn, script=self.options.pre ) diff --git a/examples/natnet.py b/examples/natnet.py index 718ca42f981ea4970682382e2daf5e3595460940..cb0c44c62cd1162461d18f22ecdb5be6409b0f84 100755 --- a/examples/natnet.py +++ b/examples/natnet.py @@ -56,7 +56,7 @@ def __init__(self, n=2, h=1, **opts): defaultRoute='via %s' % localIP) self.addLink(host, switch) -def perfTest(): +def run(): "Create network and run simple performance test" topo = InternetTopo() net = Mininet(topo=topo) @@ -66,4 +66,4 @@ def perfTest(): if __name__ == '__main__': setLogLevel('info') - perfTest() \ No newline at end of file + run() \ No newline at end of file diff --git a/mininet/net.py b/mininet/net.py index f2f49b30d90b11fcb1a5805ad902ff87250780d2..1912fba6ec81f8b011da5bf359e662402cb83e99 100755 --- a/mininet/net.py +++ b/mininet/net.py @@ -227,14 +227,18 @@ def addController( self, name='c0', controller=None, **params ): self.nameToNode[ name ] = controller_new return controller_new - # TODO: incomplete - def addNAT( self, name='nat0', connect=True, **params ): - nat = self.addHost( name, cls=NAT, **params ) + def addNAT( self, name='nat0', connect=True, inNamespace=False, **params ): + nat = self.addHost( name, cls=NAT, inNamespace=inNamespace, + subnet=self.ipBase, **params ) # find first switch and create link - print "******* &&&&&& net/addNAT" if connect: - #connect the nat to the first switch + # connect the nat to the first switch self.addLink( nat, self.switches[ 0 ] ) + # set the default route on hosts + natIP = nat.params[ 'ip' ].split('/')[ 0 ] + for host in self.hosts: + if host.inNamespace: + host.setDefaultRoute( 'via %s' % natIP ) return nat # BL: We now have four ways to look up nodes diff --git a/mininet/node.py b/mininet/node.py index d6e8f87581204f144eb3bcdff51c029bcb311f66..edc6de81245bfd4ae00e73a4e664d7c4130ddee9 100644 --- a/mininet/node.py +++ b/mininet/node.py @@ -1253,7 +1253,7 @@ def __init__( self, name, inetIntf='eth0', subnet='10.0/8', localIntf=None, **pa inetIntf: interface for internet access subnet: Mininet subnet (default 10.0/8)=""" self.inetIntf = inetIntf - self.subnet = subnet #TODO: get subnet from Mininet directly + self.subnet = subnet self.localIntf = localIntf def config( self, **params ): @@ -1263,13 +1263,6 @@ def config( self, **params ): if not self.localIntf: self.localIntf = self.defaultIntf() - #------------------------- - print "inetIntf:", self.inetIntf - print "subnet:", self.subnet - # Identify the interface connecting to the mininet network - print "LocalIntf:", self.localIntf - #------------------------- - self.cmd( 'sysctl net.ipv4.ip_forward=0' ) # Flush any currently active rules