Revision 3f2355a3 mininet/node.py

View differences:

mininet/node.py
1246 1246
class NAT( Node ):
1247 1247
    """NAT: Provides connectivity to external network"""
1248 1248

  
1249
    def __init__( self, name, inetIntf='eth0', subnet='10.0/8', **params):
1249
    def __init__( self, name, inetIntf='eth0', subnet='10.0/8', localIntf=None, **params):
1250 1250
        super( NAT, self ).__init__( name, **params )
1251 1251

  
1252 1252
        """Start NAT/forwarding between Mininet and external network
......
1254 1254
        subnet: Mininet subnet (default 10.0/8)="""
1255 1255
        self.inetIntf = inetIntf
1256 1256
        self.subnet = subnet #TODO: get subnet from Mininet directly
1257
        self.localIntf = localIntf
1257 1258

  
1258
    def config( self, inetIntf='eth0', subnet='10.0/8', **params ):
1259
    def config( self, **params ):
1259 1260
        super( NAT, self).config( **params )
1260 1261
        """Configure the NAT and iptables"""
1261 1262

  
1263
        if not self.localIntf:
1264
            self.localIntf =  self.defaultIntf()
1265

  
1266
        #-------------------------
1267
        print "inetIntf:", self.inetIntf
1268
        print "subnet:", self.subnet
1262 1269
        # Identify the interface connecting to the mininet network
1263
        localIntf =  self.defaultIntf()
1270
        print "LocalIntf:", self.localIntf
1271
        #-------------------------
1272

  
1264 1273
        self.cmd( 'sysctl net.ipv4.ip_forward=0' )
1265 1274

  
1266 1275
        # Flush any currently active rules
......
1274 1283
        self.cmd( 'iptables -P FORWARD DROP' )
1275 1284

  
1276 1285
        # Configure NAT
1277
        self.cmd( 'iptables -I FORWARD -i', localIntf, '-d', self.subnet, '-j DROP' )
1278
        self.cmd( 'iptables -A FORWARD -i', localIntf, '-s', self.subnet, '-j ACCEPT' )
1286
        self.cmd( 'iptables -I FORWARD -i', self.localIntf, '-d', self.subnet, '-j DROP' )
1287
        self.cmd( 'iptables -A FORWARD -i', self.localIntf, '-s', self.subnet, '-j ACCEPT' )
1279 1288
        self.cmd( 'iptables -A FORWARD -i', self.inetIntf, '-d', self.subnet, '-j ACCEPT' )
1280 1289
        self.cmd( 'iptables -t nat -A POSTROUTING -o ', self.inetIntf, '-j MASQUERADE' )
1281 1290

  
......
1284 1293

  
1285 1294
        # Prevent network-manager from messing with our interface
1286 1295
        # by specifying manual configuration in /etc/network/interfaces
1287
        intf = localIntf
1296
        intf = self.localIntf
1288 1297
        cfile = '/etc/network/interfaces'
1289 1298
        line = '\niface %s inet manual\n' % intf
1290 1299
        config = open( cfile ).read()

Also available in: Unified diff