From ad09c1e086ba349501999198252411d1aacdc957 Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Thu, 28 Feb 2013 17:56:36 -0800 Subject: [PATCH] Add new example of making a custom Switch() class. --- examples/controllers.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 examples/controllers.py diff --git a/examples/controllers.py b/examples/controllers.py new file mode 100755 index 0000000..c26f436 --- /dev/null +++ b/examples/controllers.py @@ -0,0 +1,28 @@ +#!/usr/bin/python + +""" +Create a network where different switches are connected to +different controllers, by creating a custom Switch() subclass. +""" + +from mininet.net import Mininet +from mininet.node import OVSSwitch, Controller +from mininet.topolib import TreeTopo +from mininet.cli import CLI + +c0 = Controller( 'c0' ) +c1 = Controller( 'c1', ip='127.0.0.2' ) +cmap = { 's1': c0, 's2': c1, 's3': c1 } + +class MultiSwitch( OVSSwitch ): + "Custom Switch() subclass that connects to different controllers" + def start( self, controllers ): + return OVSSwitch.start( self, [ cmap[ self.name ] ] ) + +topo = TreeTopo( depth=2, fanout=2 ) +net = Mininet( topo=topo, switch=MultiSwitch, build=False ) +net.controllers = [ c0, c1 ] +net.build() +net.start() +CLI( net ) +net.stop()