fixing --nat option in mn

This commit is contained in:
Brian O'Connor
2013-10-03 16:29:05 -07:00
parent a802d8b19a
commit ffeb16eb66
4 changed files with 16 additions and 17 deletions
+4 -2
View File
@@ -226,8 +226,6 @@ class MininetRunner( object ):
start = time.time() start = time.time()
topo = buildTopo( TOPOS, self.options.topo ) topo = buildTopo( TOPOS, self.options.topo )
if self.options.nat:
topo.addNAT()
switch = customConstructor( SWITCHES, self.options.switch ) switch = customConstructor( SWITCHES, self.options.switch )
host = customConstructor( HOSTS, self.options.host ) host = customConstructor( HOSTS, self.options.host )
controller = customConstructor( CONTROLLERS, self.options.controller ) controller = customConstructor( CONTROLLERS, self.options.controller )
@@ -255,6 +253,10 @@ class MininetRunner( object ):
autoStaticArp=arp, autoPinCpus=pin, autoStaticArp=arp, autoPinCpus=pin,
listenPort=listenPort ) listenPort=listenPort )
if self.options.nat:
nat = mn.addNAT()
mn.configHosts()
if self.options.pre: if self.options.pre:
CLI( mn, script=self.options.pre ) CLI( mn, script=self.options.pre )
+2 -2
View File
@@ -56,7 +56,7 @@ class InternetTopo(Topo):
defaultRoute='via %s' % localIP) defaultRoute='via %s' % localIP)
self.addLink(host, switch) self.addLink(host, switch)
def perfTest(): def run():
"Create network and run simple performance test" "Create network and run simple performance test"
topo = InternetTopo() topo = InternetTopo()
net = Mininet(topo=topo) net = Mininet(topo=topo)
@@ -66,4 +66,4 @@ def perfTest():
if __name__ == '__main__': if __name__ == '__main__':
setLogLevel('info') setLogLevel('info')
perfTest() run()
+9 -5
View File
@@ -227,14 +227,18 @@ class Mininet( object ):
self.nameToNode[ name ] = controller_new self.nameToNode[ name ] = controller_new
return controller_new return controller_new
# TODO: incomplete def addNAT( self, name='nat0', connect=True, inNamespace=False, **params ):
def addNAT( self, name='nat0', connect=True, **params ): nat = self.addHost( name, cls=NAT, inNamespace=inNamespace,
nat = self.addHost( name, cls=NAT, **params ) subnet=self.ipBase, **params )
# find first switch and create link # find first switch and create link
print "******* &&&&&& net/addNAT"
if connect: if connect:
#connect the nat to the first switch # connect the nat to the first switch
self.addLink( nat, self.switches[ 0 ] ) 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 return nat
# BL: We now have four ways to look up nodes # BL: We now have four ways to look up nodes
+1 -8
View File
@@ -1253,7 +1253,7 @@ class NAT( Node ):
inetIntf: interface for internet access inetIntf: interface for internet access
subnet: Mininet subnet (default 10.0/8)=""" subnet: Mininet subnet (default 10.0/8)="""
self.inetIntf = inetIntf self.inetIntf = inetIntf
self.subnet = subnet #TODO: get subnet from Mininet directly self.subnet = subnet
self.localIntf = localIntf self.localIntf = localIntf
def config( self, **params ): def config( self, **params ):
@@ -1263,13 +1263,6 @@ class NAT( Node ):
if not self.localIntf: if not self.localIntf:
self.localIntf = self.defaultIntf() 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' ) self.cmd( 'sysctl net.ipv4.ip_forward=0' )
# Flush any currently active rules # Flush any currently active rules