From 433503cf8aa1dabec9167f99e64728e19c5b8574 Mon Sep 17 00:00:00 2001
From: Bob Lantz <rlantz@cs.stanford.edu>
Date: Mon, 14 Dec 2009 12:43:42 -0800
Subject: [PATCH] Added "from scratch" examples, to show how to create a
 network using low-level primitives.

The "nox.py" example attempts to use nox as a controller rather than
controller(8).

More edits for INSTALL and README, and refinements for sshd and xterm
examples.
---
 examples/nox.py        | 39 +++++++++++++++++++++++++++++++++++++++
 examples/scratchnet.py | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+)
 create mode 100755 examples/nox.py
 create mode 100755 examples/scratchnet.py

diff --git a/examples/nox.py b/examples/nox.py
new file mode 100755
index 00000000..493714b6
--- /dev/null
+++ b/examples/nox.py
@@ -0,0 +1,39 @@
+#!/usr/bin/python
+
+"Create a network from scratch and use NOX as the controller."
+
+from mininet import init, Controller, Switch, Host, createLink
+
+def scratchNet( cname='controller', cargs='ptcp:'):
+   # Create Network
+   controller = Node( 'c0', inNamespace=False )
+   switch = Node( 's0', inNamespace=False )
+   h0 = Node( 'h0' )
+   h1 = Node( 'h1' )
+   createLink( h0, switch )
+   createLink( h1, switch )
+   # Configure hosts
+   h0.setIP( h0.intfs[ 0 ], '192.168.123.1', '/24' )
+   h1.setIP( h1.intfs[ 0 ], '192.168.123.2', '/24' )
+   # Start network using kernel datapath
+   controller.cmdPrint( cname + ' ' + cargs + '&' )
+   switch.cmdPrint( 'dpctl deldp nl:0' )
+   switch.cmdPrint( 'dpctl adddp nl:0' )
+   for intf in switch.intfs:
+      switch.cmdPrint( 'dpctl addif nl:0 ' + intf )
+   switch.cmdPrint( 'ofprotocol nl:0 tcp:localhost &')
+   # Run test
+   h0.cmdPrint( 'ping -c1 ' + h1.IP() )
+   # Stop network
+   controller.cmdPrint( 'kill %' + cname)
+   switch.cmdPrint( 'dpctl deldp nl:0' )
+   switch.cmdPrint( 'kill %ofprotocol' )
+   switch.stop()
+   controller.stop()
+   
+if __name__ == '__main__':
+   init()   
+   scratchNet( cname='nox_core', cargs='-i ptcp:' )
+
+
+
diff --git a/examples/scratchnet.py b/examples/scratchnet.py
new file mode 100755
index 00000000..e3fde16c
--- /dev/null
+++ b/examples/scratchnet.py
@@ -0,0 +1,40 @@
+#!/usr/bin/python
+
+"""
+Build a simple network from scratch, using mininet primitives.
+This is more complicated than using the higher-level classes,
+but it exposes the configuration details and allows cusomization.
+"""
+
+from mininet import init, Node, createLink
+
+def scratchNet( cname='controller', cargs='ptcp:'):
+   # Create Network
+   controller = Node( 'c0', inNamespace=False )
+   switch = Node( 's0', inNamespace=False )
+   h0 = Node( 'h0' )
+   h1 = Node( 'h1' )
+   createLink( h0, switch )
+   createLink( h1, switch )
+   # Configure hosts
+   h0.setIP( h0.intfs[ 0 ], '192.168.123.1', '/24' )
+   h1.setIP( h1.intfs[ 0 ], '192.168.123.2', '/24' )
+   # Start network using kernel datapath
+   controller.cmdPrint( cname + ' ' + cargs + '&' )
+   switch.cmdPrint( 'dpctl deldp nl:0' )
+   switch.cmdPrint( 'dpctl adddp nl:0' )
+   for intf in switch.intfs:
+      switch.cmdPrint( 'dpctl addif nl:0 ' + intf )
+   switch.cmdPrint( 'ofprotocol nl:0 tcp:localhost &')
+   # Run test
+   h0.cmdPrint( 'ping -c1 ' + h1.IP() )
+   # Stop network
+   controller.cmdPrint( 'kill %' + cname)
+   switch.cmdPrint( 'dpctl deldp nl:0' )
+   switch.cmdPrint( 'kill %ofprotocol' )
+   switch.stop()
+   controller.stop()
+   
+if __name__ == '__main__':
+   init()   
+   scratchNet()
-- 
GitLab