From 555d10dea7232588cb5039a0c6989e197232be40 Mon Sep 17 00:00:00 2001
From: Brian O'Connor <bocon13@gmail.com>
Date: Thu, 3 Oct 2013 15:15:40 -0700
Subject: [PATCH] adding internet / nat example

---
 examples/natnet.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100755 examples/natnet.py

diff --git a/examples/natnet.py b/examples/natnet.py
new file mode 100755
index 00000000..718ca42f
--- /dev/null
+++ b/examples/natnet.py
@@ -0,0 +1,69 @@
+#!/usr/bin/python
+
+"""
+natnet.py: Example network with NATs
+
+
+           h0
+           |
+           s0
+           |        
+    ----------------
+    |              |
+   nat1           nat2
+    |              |
+   s1              s2
+    |              |
+   h1              h2 
+
+"""
+
+from mininet.topo import Topo
+from mininet.net import Mininet
+from mininet.node import NAT
+from mininet.log import setLogLevel
+from mininet.cli import CLI
+from mininet.util import irange
+
+class InternetTopo(Topo):
+    "Single switch connected to n hosts."
+    def __init__(self, n=2, h=1, **opts):
+        Topo.__init__(self, **opts)
+
+        # set up inet switch
+        inetSwitch = self.addSwitch('s0')
+        # add inet host
+        inetHost = self.addHost('h0')
+        self.addLink(inetSwitch, inetHost)
+
+        # add local nets
+        for i in irange(1, n):
+            inetIntf = 'nat%d-eth0' % i
+            localIntf = 'nat%d-eth1' % i
+            localIP = '192.168.%d.1' % i
+            localSubnet = '192.168.%d.0/24' % i
+            natParams = { 'ip' : '%s/24' % localIP }
+            # add NAT to topology
+            nat = self.addNode('nat%d' % i, cls=NAT, subnet=localSubnet, 
+                               inetIntf=inetIntf, localIntf=localIntf)
+            switch = self.addSwitch('s%d' % i)
+            # connect NAT to inet and local switches
+            self.addLink(nat, inetSwitch, intfName1=inetIntf)
+            self.addLink(nat, switch, intfName1=localIntf, params1=natParams)
+            # add host and connect to local switch
+            host = self.addHost('h%d' % i, 
+                                ip='192.168.%d.100/24' % i, 
+                                defaultRoute='via %s' % localIP)
+            self.addLink(host, switch)
+
+def perfTest():
+    "Create network and run simple performance test"
+    topo = InternetTopo()
+    net = Mininet(topo=topo)
+    net.start()
+    CLI(net)
+    net.stop()
+
+if __name__ == '__main__':
+    setLogLevel('info')
+    perfTest()
\ No newline at end of file
-- 
GitLab