From e8623fdc91b3b936b68812a9570487aaa2e7ff70 Mon Sep 17 00:00:00 2001
From: Tomasz Buchert <tomek.buchert@gmail.com>
Date: Wed, 13 Aug 2014 16:45:40 +0200
Subject: [PATCH] introducing OVSBridge

---
 bin/mn          |  3 ++-
 mininet/node.py | 66 +++++++++++++++++++++++++++++++++++--------------
 2 files changed, 50 insertions(+), 19 deletions(-)

diff --git a/bin/mn b/bin/mn
index edd4d984..e94515d3 100755
--- a/bin/mn
+++ b/bin/mn
@@ -26,7 +26,7 @@ from mininet.log import lg, LEVELS, info, debug, error
 from mininet.net import Mininet, MininetWithControlNet, VERSION
 from mininet.node import ( Host, CPULimitedHost, Controller, OVSController,
                            NOX, RemoteController, DefaultController,
-                           UserSwitch, OVSSwitch,
+                           UserSwitch, OVSBridge, OVSSwitch,
                            OVSLegacyKernelSwitch, IVSSwitch )
 from mininet.nodelib import LinuxBridge
 from mininet.link import Link, TCLink
@@ -48,6 +48,7 @@ TOPOS = { 'minimal': lambda: SingleSwitchTopo( k=2 ),
 SWITCHDEF = 'ovsk'
 SWITCHES = { 'user': UserSwitch,
              'ovs':  OVSSwitch,
+             'ovsb' : OVSBridge,
              # Keep ovsk for compatibility with 2.0
              'ovsk': OVSSwitch,
              'ovsl': OVSLegacyKernelSwitch,
diff --git a/mininet/node.py b/mininet/node.py
index d5b30362..a10abbf2 100644
--- a/mininet/node.py
+++ b/mininet/node.py
@@ -996,20 +996,8 @@ def stop( self ):
         self.deleteIntfs()
 
 
-class OVSSwitch( Switch ):
-    "Open vSwitch switch. Depends on ovs-vsctl."
-
-    def __init__( self, name, failMode='secure', datapath='kernel',
-                 inband=False, **params ):
-        """Init.
-           name: name for switch
-           failMode: controller loss behavior (secure|open)
-           datapath: userspace or kernel mode (kernel|user)
-           inband: use in-band control (False)"""
-        Switch.__init__( self, name, **params )
-        self.failMode = failMode
-        self.datapath = datapath
-        self.inband = inband
+class OVSSwitchBase( Switch ):
+    'a base class for OVS switches; does not contain OpenFlow code at all'
 
     @classmethod
     def setup( cls ):
@@ -1045,10 +1033,6 @@ def batchShutdown( cls, switches ):
                   ' -- '.join( '--if-exists del-br %s' % s
                                for s in switches ) )
 
-    def dpctl( self, *args ):
-        "Run ovs-ofctl command"
-        return self.cmd( 'ovs-ofctl', args[ 0 ], self, *args[ 1: ] )
-
     @staticmethod
     def TCReapply( intf ):
         """Unfortunately OVS and Mininet are fighting
@@ -1067,6 +1051,52 @@ def detach( self, intf ):
         "Disconnect a data port"
         self.cmd( 'ovs-vsctl del-port', self, intf )
 
+
+class OVSBridge( OVSSwitchBase ):
+    "OpenVSwitch Bridge (similar to OVSSwitch, but no OpenFlow)"
+
+    def __init__( self, name, **kwargs ):
+        OVSSwitchBase.__init__( self, name, **kwargs )
+
+    def connected( self ):
+        return True
+
+    def start( self, controllers ):
+        if self.inNamespace:
+            raise Exception(
+                'OVS kernel switch does not work in a namespace' )
+        self.cmd( 'ovs-vsctl del-br', self )
+        intfs = ' '.join( '-- add-port %s %s ' % ( self, intf )
+                         for intf in self.intfList() if not intf.IP() )
+        cmd = ( 'ovs-vsctl add-br %s ' % self + intfs )
+        self.cmd( cmd )
+        for intf in self.intfList():
+            self.TCReapply( intf )
+
+    def stop( self ):
+        self.cmd( 'ovs-vsctl del-br', self )
+        self.deleteIntfs()
+
+
+class OVSSwitch( OVSSwitchBase ):
+    "Open vSwitch switch using OpenFlow controller. Depends on ovs-vsctl."
+
+    def __init__( self, name, failMode='secure', datapath='kernel',
+                 inband=False, **params ):
+        """Init.
+           name: name for switch
+           failMode: controller loss behavior (secure|open)
+           datapath: userspace or kernel mode (kernel|user)
+           inband: use in-band control (False)"""
+        OVSSwitchBase.__init__( self, name, **params )
+        self.failMode = failMode
+        self.datapath = datapath
+        self.inband = inband
+
+    def dpctl( self, *args ):
+        "Run ovs-ofctl command"
+        return self.cmd( 'ovs-ofctl', args[ 0 ], self, *args[ 1: ] )
+
     def controllerUUIDs( self ):
         "Return ovsdb UUIDs for our controllers"
         uuids = []
-- 
GitLab