def __init__(self, name, dpopts='--no-slicing', **kwargs): """Init. name: name for the switch dpopts: additional arguments to ofdatapath (--no-slicing)""" Switch.__init__(self, name, **kwargs) pathCheck('switch', moduleName='the Fluid library example switch' + '(CPqD)')
def call(self, command, silent= False, data=''): """Call <client> <cargs> on node.""" if self.cdir is not None: self.cmd( 'cd ' + self.cdir ) cmd = self.client pathCheck( cmd ) if data: method = '''POST -H "Content-Type: application/json" -d '{data}' '''.format(data = data) else: method = "GET" if self.cargs: cmd += " " + self.cargs.format(command=command, method=method, name=self.name, IP=self.IP(), port=self.port, cdir=self.cdir, sdir=self.sdir) else: cmd += " " + command if silent: result = self.cmd( cmd ) else: result = self.cmdPrint( cmd ) debug("command: %s = %s" % (cmd, result)) return result
def setup(): "Ensure any dependencies are loaded; if not, try to load them." pathCheck('ovs-dpctl', 'ovs-openflowd', moduleName='Open vSwitch (openvswitch.org)') if not os.path.exists('/dev/net/tun'): moduleDeps(add=TUN)
def __init__(self, name, sw_path = None, json_path = None, grpc_port = None, thrift_port = None, pcap_dump = False, log_console = False, verbose = False, device_id = None, enable_debugger = False, log_file = None, cpu_port = None, **kwargs): Switch.__init__(self, name, **kwargs) assert (sw_path) self.sw_path = sw_path # make sure that the provided sw_path is valid pathCheck(sw_path) if json_path is not None: # make sure that the provided JSON file exists if not os.path.isfile(json_path): error("Invalid JSON file: {}\n".format(json_path)) exit(1) self.json_path = json_path else: self.json_path = None if grpc_port is not None: self.grpc_port = grpc_port else: self.grpc_port = P4RuntimeSwitch.next_grpc_port P4RuntimeSwitch.next_grpc_port += 1 if thrift_port is not None: self.thrift_port = thrift_port else: self.thrift_port = P4RuntimeSwitch.next_thrift_port P4RuntimeSwitch.next_thrift_port += 1 if check_listening_on_port(self.grpc_port): error('%s cannot bind port %d because it is bound by another process\n' % (self.name, self.grpc_port)) exit(1) self.verbose = verbose logfile = "/tmp/p4s.{}.log".format(self.name) self.output = open(logfile, 'w') self.pcap_dump = pcap_dump self.enable_debugger = enable_debugger self.log_console = log_console if log_file is not None: self.log_file = log_file else: self.log_file = "/tmp/p4s.{}.log".format(self.name) if device_id is not None: self.device_id = device_id P4Switch.device_id = max(P4Switch.device_id, device_id) else: self.device_id = P4Switch.device_id P4Switch.device_id += 1 self.nanomsg = "ipc:///tmp/bm-{}-log.ipc".format(self.device_id) self.cpu_port = cpu_port
def setup(cls): "Make sure POFSwitch is installed" pathCheck('pofswitch', moduleName='POF Switch (poforwarding.org)') out, err, exitcode = errRun('pofswitch -h') if exitcode: error(out + err + 'pofswitch exited with code %d\n' % exitcode) exit(1)
def __init__( self, name, dpopts='--no-slicing', **kwargs ): """Init. name: name for the switch dpopts: additional arguments to ofdatapath (--no-slicing)""" Switch.__init__( self, name, **kwargs ) pathCheck('switch', moduleName='the Fluid library example switch' + '(CPqD)' )
def __init__(self, name, sw_path = None, json_path = None, thrift_port = None, pcap_dump = False, log_console = False, verbose = False, device_id = None, enable_debugger = False, **kwargs): Switch.__init__(self, name, **kwargs) assert(sw_path) assert(json_path) # make sure that the provided sw_path is valid pathCheck(sw_path) # make sure that the provided JSON file exists if not os.path.isfile(json_path): error("Invalid JSON file.\n") exit(1) self.sw_path = sw_path self.json_path = json_path self.verbose = verbose logfile = "/tmp/p4s.{}.log".format(self.name) self.output = open(logfile, 'w') self.thrift_port = thrift_port self.pcap_dump = pcap_dump self.enable_debugger = enable_debugger self.log_console = log_console if device_id is not None: self.device_id = device_id P4Switch.device_id = max(P4Switch.device_id, device_id) else: self.device_id = P4Switch.device_id P4Switch.device_id += 1 self.nanomsg = "ipc:///tmp/bm-{}-log.ipc".format(self.device_id)
def __init__(self, name, **kwargs): """Init. name: name for the switch""" Switch.__init__(self, name, **kwargs) pathCheck("ofdatapath", "ofprotocol", moduleName="the OpenFlow reference user switch" + "(openflow.org)") if self.listenPort: self.opts += " --listen=ptcp:%i " % self.listenPort
def setup(): "Ensure any dependencies are loaded; if not, try to load them." moduleName = ( 'the OpenFlow reference kernel switch' ' (openflow.org) (NOTE: not available in OpenFlow 1.0+!)') pathCheck('ofprotocol', moduleName=moduleName) moduleDeps(subtract=OVS_KMOD, add=OF_KMOD, moduleName=moduleName)
def __init__(self, name, **kwargs): """Init. name: name for the switch""" Switch.__init__(self, name, **kwargs) pathCheck( 'ofdatapath', 'ofprotocol', moduleName='the OpenFlow reference user switch (openflow.org)')
def start(self): """Start <controller> <args> on controller. Log to /tmp/cN.log""" pathCheck(self.command) cout = "/tmp/" + self.name + ".log" if self.cdir is not None: self.cmd("cd " + self.cdir) self.cmd(self.command, self.cargs % self.port, ">&", cout, "&")
def start( self ): """Start <controller> <args> on controller. Log to /tmp/cN.log""" pathCheck( self.command ) cout = '/tmp/' + self.name + '.log' if self.cdir is not None: self.cmd( 'cd ' + self.cdir ) self.cmd( self.command, self.cargs % self.port, '>&', cout, '&' )
def __init__( self, name, **kwargs ): """Init. name: name for the switch""" Switch.__init__( self, name, **kwargs ) pathCheck( 'ofdatapath', 'ofprotocol', moduleName='the OpenFlow reference user switch (openflow.org)' ) self.cmd( 'kill %ofdatapath' ) self.cmd( 'kill %ofprotocol' )
def start(self): """Start <controller> <args> on controller. Log to /tmp/cN.log""" pathCheck(self.command) cout = '/tmp/' + self.name + '.log' if self.cdir is not None: self.cmd('cd ' + self.cdir) self.cmd(self.command, self.cargs % self.port, '>&', cout, '&')
def setup(): "Ensure any dependencies are loaded; if not, try to load them." moduleName = 'Open vSwitch (openvswitch.org)' pathCheck('ovs-vsctl', 'ovsdb-server', 'ovs-vswitchd', moduleName=moduleName) moduleDeps(subtract=OF_KMOD, add=OVS_KMOD, moduleName=moduleName) if not checkRunning('ovsdb-server', 'ovs-vswitchd'): ovsdb_server_cmd = [ 'ovsdb-server', '--remote=punix:/tmp/mn-openvswitch-db.sock', '--remote=db:Open_vSwitch,manager_options' ] # We need to specify the DB path for OVS before 1.2.0 ovs_ver = quietRun('ovsdb-server -V').split('\n')[0] # Note the space in front of the version strings. # TODO: Maybe we should extract the version instead of # substr matching if ' 1.1.' in ovs_ver or ' 1.0.' in ovs_ver: ovsdb_server_cmd.insert(1, '/usr/local/etc/openvswitch/conf.db') # Every OVS command *except* ovsdb-server has a default path # to the database socket hardcoded. Problem is: if we need # to run ovsdb-server ourselves we cannot figure out what # this path is. Grr. ovsdb_instance = Popen(ovsdb_server_cmd, stderr=STDOUT, stdout=open('/tmp/mn-ovsdb-server.log', "w")) sleep(0.1) if ovsdb_instance.poll() is not None: error( "ovsdb-server was not running and we could not start it - exiting\n" ) sys.exit(1) vswitchd_instance = Popen( ['ovs-vswitchd', 'unix:/tmp/mn-openvswitch-db.sock'], stderr=STDOUT, stdout=open('/tmp/mn-vswitchd.log', "w")) if vswitchd_instance.poll() is not None: error( "ovs-vswitchd was not running and we could not start it - exiting\n" ) sys.exit(1) sleep(0.1) OVSKernelSwitchNew.vsctl_cmd = 'ovs-vsctl -t 2 --db=unix:/tmp/mn-openvswitch-db.sock ' else: OVSKernelSwitchNew.vsctl_cmd = 'ovs-vsctl -t 2 ' # Remove old mininet datapaths to make sure they don't interfere brlist = quietRun(OVSKernelSwitchNew.vsctl_cmd + ' list-br') for line in brlist.split("\n"): line = line.rstrip() if re.match('^mn-dp[0-9]+$', line): quietRun(OVSKernelSwitchNew.vsctl_cmd + ' del-br ' + line)
def start(self): pathCheck(self.command) cout = '/tmp/' + self.name + '.log' command = self.command + ' ' + (self.cargs % self.port) print command self.fout = open(cout, 'w') self.controller_popen = self.popen(command.split(' '), stdout=self.fout, stderr=self.fout)
def setup( cls ): "Check dependencies and warn about firewalling" pathCheck( 'brctl', moduleName='bridge-utils' ) # Disable Linux bridge firewalling so that traffic can flow! for table in 'arp', 'ip', 'ip6': cmd = 'sysctl net.bridge.bridge-nf-call-%stables' % table out = quietRun( cmd ).strip() if out.endswith( '1' ): warn( 'Warning: Linux bridge may not work with', out, '\n' )
def start(self): """Start <controller> <args> on controller. Log to /tmp/cN.log""" pathCheck(self.command) cout = "/tmp/" + self.name + ".log" if self.cdir is not None: self.cmd("cd " + self.cdir) self.cmd(self.command + " " + self.cargs % self.port + " 1>" + cout + " 2>" + cout + "&") self.execed = False
def __init__( self, name, **kwargs ): """Init. name: name for the switch""" Switch.__init__( self, name, **kwargs ) pathCheck( 'ofdatapath', 'ofprotocol', moduleName='the OpenFlow reference user switch' + '(openflow.org)' ) if self.listenPort: self.opts += ' --listen=ptcp:%i ' % self.listenPort
def setup(): pathCheck('brctl') brlist = quietRun('brctl show') for line in brlist.split("\n"): line = line.rstrip() m = re.match('^lxbr-(\w+)', line) if (m): print "Cleaning old bridge lxbr-%s" % m.group(1) self.cmd ('brctl', 'delbr', 'lxbr-%s' % m.group(1))
def setup(cls): "Check dependencies and warn about firewalling" pathCheck("brctl", moduleName="bridge-utils") # Disable Linux bridge firewalling so that traffic can flow! for table in "arp", "ip", "ip6": cmd = "sysctl net.bridge.bridge-nf-call-%stables" % table out = quietRun(cmd).strip() if out.endswith("1"): warn("Warning: Linux bridge may not work with", out, "\n")
def setup(): pathCheck('brctl') brlist = quietRun('brctl show') for line in brlist.split("\n"): line = line.rstrip() m = re.match('^lxbr-(\w+)', line) if (m): print "Cleaning old bridge lxbr-%s" % m.group(1) self.cmd('brctl', 'delbr', 'lxbr-%s' % m.group(1))
def start( self ): """Start <controller> <args> on controller. Log to /tmp/cN.log""" pathCheck( self.command ) cout = '/tmp/' + self.name + '.log' if self.cdir is not None: self.cmd( 'cd ' + self.cdir ) self.cmd( self.command + ' ' + self.cargs % self.port + ' 1>' + cout + ' 2>' + cout + '&' ) self.execed = False
def start(self): """Start <controller> <args> on controller. Log to /tmp/cN.log""" log.info('Starting controller...\n') pathCheck(self.command) cout = '/tmp/' + self.name + '.log' chdir(self.fl_root_dir) self.cmd(self.command + ' ' + self.cargs + ' 1>' + cout + ' 2>' + cout + '&') self.execed = False
def __init__( self, name, bw=100000000, **kwargs ): #100mbps """Init. name: name for the switch bw: interface maximum bandwidth""" Switch.__init__( self, name, **kwargs ) self.bandwidth = bw pathCheck( 'ofdatapath', 'ofprotocol', moduleName='QoSFlow 0.1 datapath') if self.listenPort: # dpctl self.opts += ' --listen=ptcp:%i ' % self.listenPort
def __init__(self, name, sw_path=None, json_path=None, thrift_port=None, pcap_dump=False, log_console=False, verbose=False, device_id=None, enable_debugger=False, **kwargs): Switch.__init__(self, name, **kwargs) assert (sw_path) assert (json_path) # make sure that the provided sw_path is valid pathCheck(sw_path) # make sure that the provided JSON file exists if not os.path.isfile(json_path): error("Invalid JSON file.\n") exit(1) self.sw_path = sw_path self.json_path = json_path self.verbose = verbose logfile = "/log/p4s.{}.log".format(self.name) self.output = open(logfile, 'w') self.thrift_port = thrift_port if check_listening_on_port(self.thrift_port): error( '%s cannot bind port %d because it is bound by another process\n' % (self.name, self.grpc_port)) exit(1) self.pcap_dump = pcap_dump self.enable_debugger = enable_debugger self.log_console = log_console self.device_id = P4Switch.device_id P4Switch.device_id += 1 self.nanomsg = "ipc:///log/bm-{}-log.ipc".format(self.device_id) if "operating_mode" in kwargs: self.operating_mode = kwargs["operating_mode"] else: self.operating_mode = "NORMAL" if "switch_rel_cpu_speed" in kwargs: self.switch_rel_cpu_speed = kwargs["switch_rel_cpu_speed"] else: self.switch_rel_cpu_speed = 1.0 if "n_round_insns" in kwargs: self.n_round_insns = kwargs["n_round_insns"] else: self.n_round_insns = 1000000 self.tracer_path = "/usr/bin/tracer" self.switch_pid = None
def __init__( self, name, dpopts='--no-slicing', **kwargs ): """Init. name: name for the switch dpopts: additional arguments to ofdatapath (--no-slicing)""" Switch.__init__( self, name, **kwargs ) pathCheck( 'ofdatapath', 'ofprotocol', moduleName='the OpenFlow reference user switch' + '(openflow.org)' ) if self.listenPort: self.opts += ' --listen=ptcp:%i ' % self.listenPort self.dpopts = dpopts
def setup( cls ): "Make sure IVS is installed" pathCheck( 'ivs-ctl', 'ivs', moduleName="Indigo Virtual Switch (projectfloodlight.org)" ) out, err, exitcode = errRun( 'ivs-ctl show' ) if exitcode: error( out + err + 'ivs-ctl exited with code %d\n' % exitcode + '*** The openvswitch kernel module might ' 'not be loaded. Try modprobe openvswitch.\n' ) exit( 1 )
def __init__(self, name, sw_path=None, json_path=None, log_file=None, thrift_port=None, pcap_dump=False, pcap_dir="", log_console=False, verbose=False, device_id=None, enable_debugger=False, sw_ip="10.0.1.254", **kwargs): Switch.__init__(self, name, **kwargs) assert sw_path assert json_path # make sure that the provided sw_path is valid pathCheck(sw_path) # make sure that the provided JSON file exists if not os.path.isfile(json_path): error("Invalid JSON file.\n") exit(1) self.sw_path = sw_path self.json_path = json_path self.pcap_dir = pcap_dir self.verbose = verbose self.pcap_dump = pcap_dump self.enable_debugger = enable_debugger self.log_console = log_console self.log_file = log_file if self.log_file is None: self.log_file = "/tmp/p4s.{}.log".format(self.name) if self.log_console: self.output = open(self.log_file, 'w') self.thrift_port = thrift_port if check_listening_on_port(self.thrift_port): error( '%s cannot bind port %d because it is bound by another process\n' % (self.name, self.thrift_port)) exit(1) if device_id is not None: self.device_id = device_id P4Switch.device_id = max(P4Switch.device_id, device_id) else: self.device_id = P4Switch.device_id P4Switch.device_id += 1 self.nanomsg = "ipc:///tmp/bm-{}-log.ipc".format(self.device_id) self.simple_switch_pid = None self.sw_ip = sw_ip
def kwstart(self): """Start keyworker on node. Log to /tmp/kw_<name>.log""" if self.keyworker: pathCheck(self.keyworker) cout = '/tmp/kw_' + self.name + '.log' if self.kdir is not None: self.cmd('cd ' + self.kdir) debug(self.keyworker + ' ' + self.kargs + ' 1>' + cout + ' 2>' + cout + ' &') self.cmd(self.keyworker + ' ' + self.kargs + ' 1>' + cout + ' 2>' + cout + ' &') self.kexeced = False
def start(self): """Start <controller> <args> on controller. Log to /tmp/cN.log""" cmds = [] pathCheck( self.command ) if self.cdir is not None: cmds.append( 'cd ' + self.cdir ) cmds.append( self.command + ' ' + self.cargs % self.port) # Execute cmd self.bashTerm('RyuController', cmds) self.execed = False
def __init__(self, name, dpopts='--no-slicing', **kwargs): """Init. name: name for the switch dpopts: additional arguments to ofdatapath (--no-slicing)""" APSensor.__init__(self, name, **kwargs) super(UserAP, self).__init__(name, dpopts='--no-slicing', **kwargs) pathCheck('ofdatapath', 'ofprotocol', moduleName='the OpenFlow reference user switch' + '(openflow.org)') if self.listenPort: self.opts += ' --listen=ptcp:%i ' % self.listenPort else: self.opts += ' --listen=punix:/tmp/%s.listen' % self.name self.dpopts = dpopts
def setup(cls): "Make sure Open vSwitch is installed and working" pathCheck('ovs-vsctl', moduleName='Open vSwitch (openvswitch.org)') # This should no longer be needed, and it breaks # with OVS 1.7 which has renamed the kernel module: # moduleDeps( subtract=OF_KMOD, add=OVS_KMOD ) out, err, exitcode = errRun('ovs-vsctl -t 1 show') if exitcode: error(out + err + 'ovs-vsctl exited with code %d\n' % exitcode + '*** Error connecting to ovs-db with ovs-vsctl\n' 'Make sure that Open vSwitch is installed, ' 'that ovsdb-server is running, and that\n' '"ovs-vsctl show" works correctly.\n' 'You may wish to try ' '"service openvswitch-switch start".\n') exit(1)
def __init__(self, name, sw_path=None, json_path=None, thrift_port=None, pcap_dump=False, log_console=False, verbose=False, device_id=None, enable_debugger=False, **kwargs): Switch.__init__(self, name, **kwargs) assert (sw_path) assert (json_path) # make sure that the provided sw_path is valid pathCheck(sw_path) # make sure that the provided JSON file exists if not os.path.isfile(json_path): error("Invalid JSON file.\n") exit(1) # disable IPv6 self.cmd("sysctl -w net.ipv6.conf.all.disable_ipv6=1") self.cmd("sysctl -w net.ipv6.conf.default.disable_ipv6=1") self.cmd("sysctl -w net.ipv6.conf.lo.disable_ipv6=1") self.sw_path = sw_path self.json_path = json_path self.verbose = verbose logfile = "/tmp/p4s.{}.log".format(self.name) self.output = open(logfile, 'w') self.thrift_port = thrift_port if check_listening_on_port(self.thrift_port): error( '%s cannot bind port %d because it is bound by another process\n' % (self.name, self.grpc_port)) exit(1) self.pcap_dump = pcap_dump self.enable_debugger = enable_debugger self.log_console = log_console if device_id is not None: self.device_id = device_id P4Switch.device_id = max(P4Switch.device_id, device_id) else: self.device_id = P4Switch.device_id P4Switch.device_id += 1 self.nanomsg = "ipc:///tmp/bm-{}-log.ipc".format(self.device_id)
def setup(): "Ensure any dependencies are loaded; if not, try to load them." moduleName='Open vSwitch (openvswitch.org)' pathCheck( 'ovs-vsctl', 'ovsdb-server', 'ovs-vswitchd', moduleName=moduleName ) moduleDeps( subtract=OF_KMOD, add=OVS_KMOD, moduleName=moduleName ) if not checkRunning('ovsdb-server', 'ovs-vswitchd'): ovsdb_server_cmd = ['ovsdb-server', '--remote=punix:/tmp/mn-openvswitch-db.sock', '--remote=db:Open_vSwitch,manager_options'] # We need to specify the DB path for OVS before 1.2.0 ovs_ver = quietRun('ovsdb-server -V').split('\n')[0] # Note the space in front of the version strings. # TODO: Maybe we should extract the version instead of # substr matching if ' 1.1.' in ovs_ver or ' 1.0.' in ovs_ver: ovsdb_server_cmd.insert(1, '/usr/local/etc/openvswitch/conf.db') # Every OVS command *except* ovsdb-server has a default path # to the database socket hardcoded. Problem is: if we need # to run ovsdb-server ourselves we cannot figure out what # this path is. Grr. ovsdb_instance = Popen(ovsdb_server_cmd, stderr = STDOUT, stdout = open('/tmp/mn-ovsdb-server.log', "w") ) sleep(0.1) if ovsdb_instance.poll() is not None: error("ovsdb-server was not running and we could not start it - exiting\n") sys.exit(1) vswitchd_instance = Popen(['ovs-vswitchd', 'unix:/tmp/mn-openvswitch-db.sock'], stderr = STDOUT, stdout = open('/tmp/mn-vswitchd.log', "w") ) if vswitchd_instance.poll() is not None: error("ovs-vswitchd was not running and we could not start it - exiting\n") sys.exit(1) sleep(0.1) OVSKernelSwitchNew.vsctl_cmd = 'ovs-vsctl -t 2 --db=unix:/tmp/mn-openvswitch-db.sock ' else: OVSKernelSwitchNew.vsctl_cmd = 'ovs-vsctl -t 2 ' # Remove old mininet datapaths to make sure they don't interfere brlist = quietRun ( OVSKernelSwitchNew.vsctl_cmd + ' list-br' ) for line in brlist.split("\n"): line = line.rstrip() if re.match('^mn-dp[0-9]+$', line): quietRun ( OVSKernelSwitchNew.vsctl_cmd + ' del-br ' + line )
def setup( cls ): "Make sure Open vSwitch is installed and working" pathCheck( 'ovs-vsctl', moduleName='Open vSwitch (openvswitch.org)') # This should no longer be needed, and it breaks # with OVS 1.7 which has renamed the kernel module: # moduleDeps( subtract=OF_KMOD, add=OVS_KMOD ) out, err, exitcode = errRun( 'ovs-vsctl -t 1 show' ) if exitcode: error( out + err + 'ovs-vsctl exited with code %d\n' % exitcode + '*** Error connecting to ovs-db with ovs-vsctl\n' 'Make sure that Open vSwitch is installed, ' 'that ovsdb-server is running, and that\n' '"ovs-vsctl show" works correctly.\n' 'You may wish to try ' '"service openvswitch-switch start".\n' ) exit( 1 )
def start(self): """Start <bcnode> <args> on node. Log to /tmp/bc_<name>.log""" if self.server: pathCheck(self.server) cout = '/tmp/bc_' + self.name + '.log' if self.sdir is not None: self.cmd('cd ' + self.sdir) cmd = self.server if self.sargs: cmd += " " + self.sargs.format(name=self.name, IP=self.IP(), port=self.port, cdir=self.cdir, sdir=self.sdir) debug(cmd + ' 1>' + cout + ' 2>' + cout + ' &') self.cmd(cmd + ' 1>' + cout + ' 2>' + cout + ' &') self.execed = False
def start(self): """Start <bcnode> <args> on node. Log to /tmp/bc_<name>.log""" if self.server: pathCheck(self.server) cout = '/tmp/bc_' + self.name + '.log' if self.sdir is not None: import os self.cmd('cd ' + self.sdir) sdir = '%s/%s' % (self.sdir, self.IP()) try: os.stat(sdir) except: os.mkdir(sdir) self.sargs += ' -datadir=' + sdir debug(self.server + ' ' + self.sargs + ' 1>' + cout + ' 2>' + cout + ' &') self.cmd(self.server + ' ' + self.sargs + ' 1>' + cout + ' 2>' + cout + ' &') self.execed = False
def __init__(self, name, sw_path=None, grpc_port=None, thrift_port=None, cpu_port=None, p4info=None, pipeline=None, table_entries=[], **kwargs): Switch.__init__(self, name, **kwargs) assert sw_path self.sw_path = sw_path # make sure that the provided sw_path is valid pathCheck(sw_path) self.p4info = p4info self.pipeline = pipeline self.table_entries = table_entries if grpc_port is not None: self.grpc_port = grpc_port else: self.grpc_port = P4Switch.next_grpc_port P4Switch.next_grpc_port += 1 if thrift_port is not None: self.thrift_port = thrift_port else: self.thrift_port = P4Switch.next_thrift_port P4Switch.next_thrift_port += 1 if self.check_listening_on_port(self.grpc_port): error( '%s cannot bind port %d because it is bound by another process\n' % (self.name, self.grpc_port)) exit(1) self.device_id = P4Switch.next_device_id P4Switch.next_device_id += 1 self.cpu_port = cpu_port
def __init__(self, name, path=None, **kwargs): # double check if java is available (it is needed for RiseV2G) pathCheck('java') # set the path of RiseV2G if path is not None: self.RISE_PATH = path else: self.RISE_PATH = "/usr/share/.miniV2G/RiseV2G" # check if it exists if "No such file or directory" in popen('ls {}'.format( self.RISE_PATH)).read(): exit( "*** Fatal error: directory %s not found. Select the right folder which contains the needed jar files." ) # initialize the subprocess object self.proc = None Node.__init__(self, name, **kwargs) # setup a random prefix for folders (to better cleanup everything in the end) prefix_len = 4 self.FOLDER_PREFIX = ''.join( random.choice(string.ascii_lowercase) for i in range(prefix_len)) # initialize the folder for the RiseV2G copy self.folder = "" # cleanup of the generated folder def cleaner(): print('*** Cleaning up the mess') popen("rm -rd {}*".format(self.FOLDER_PREFIX)) # this will be called more than the needed times, so the output is supressed popen("rm -rd RISE-V2G-Certificates > /dev/null 2>&1 ") atexit.register(cleaner)
def call(self, command, data=''): """Call <client> <cargs> on node.""" if self.cdir is not None: self.cmd('cd ' + self.cdir) cmd = self.client pathCheck(cmd) if self.cargs: cmd += " " + self.cargs.format(command=command, data=data, name=self.name, IP=self.IP(), port=self.port, cdir=self.cdir, sdir=self.sdir) if data: cmd += " " + self.cargs.format(data=data) else: cmd += " " + command result = self.cmdPrint(cmd) debug("command: %s = %s" % (cmd, result)) return result
def _build_cmd_args( self ): "Build command-line argument of POX." self.run_file = "" self.ctrl_args = "" self.cmd_args = "" self.cmd_log = "" self.cmd_tail = "" self.run_file = self.poxCoreDir + "/pox.py" pathCheck( self.run_file ) if self.use_remote_controller: self.ctrl_args = "--no-openflow" elif self.controller_type: self.ctrl_args = self.controller_type + " openflow.of_01" self.ctrl_args += " --address=" + str(self.controller_ip) self.ctrl_args += " --port=" + str(self.controller_port) self.cmd_args = "datapaths.pcap_switch" self.cmd_args += " --address=" + str(self.controller_ip) self.cmd_args += " --port=" + str(self.controller_port) self.cmd_args += " --max_retry_delay=" + str(self.max_retry_delay) self.cmd_args += " --dpid=" + str(self.dpid) self.cmd_args += " --ports=" + ",".join(self.intf_ports) self.cmd_args += " --extra=" + ",".join(self.extra) self.cmd_log = "/tmp/" + self.name + ".log" self.cmd( 'echo "" > %s' % self.cmd_log ) # Clear previous self.cmd_tail = "1>> " + self.cmd_log + " 2>> " + self.cmd_log + " &" if self.print_personal_debug: print "WARN: self.listenPort is UNUSED" self.command = self.run_file self.command += " " + self.ctrl_args self.command += " " + self.cmd_args self.command += " " + self.cmd_tail if self.print_personal_debug: print "EVAL: " + self.command
def setup(cls): pathCheck('brctl', moduleName='Bridge Control') pathCheck('ebtables', moduleName='Ethernet filter')
def setup(): "Ensure any dependencies are loaded; if not, try to load them." moduleName='Open vSwitch (openvswitch.org)' pathCheck( 'ovs-vsctl', 'ovsdb-server', 'ovs-vswitchd', moduleName=moduleName ) output = quietRun('ovs-vsctl --version') if "1.7" in output: # The kernel module name is changed some time in 2012 # http://openvswitch.org/cgi-bin/gitweb.cgi?p=openvswitch; # a=commitdiff;h=9b80f761bed9a32c1b0eb22ee3361966057ea973 moduleDeps( subtract=OF_KMOD, add="openvswitch", moduleName=moduleName ) else: moduleDeps( subtract=OF_KMOD, add=OVS_KMOD, moduleName=moduleName ) if not checkRunning('ovsdb-server', 'ovs-vswitchd'): # db, socket, pid, log file paths ovsInstanceDir = "/var/run/openvswitch" quietRun('mkdir -p %s' % ovsInstanceDir) confDbPath = "%s/conf.db" % ovsInstanceDir dbSockPath = "%s/db.sock" % ovsInstanceDir ovsdbServerPidPath = "%s/ovsdb-server.pid" % ovsInstanceDir ovsdbServerLogPath = "%s/ovsdb-server.log" % ovsInstanceDir ovsVswitchdPidPath = "%s/ovs-vswitchd.pid" % ovsInstanceDir ovsVswitchdLogPath = "%s/ovs-vswitchd.log" % ovsInstanceDir # Create ovs database quietRun("ovsdb-tool create %s" % confDbPath) # Start ovsdb-server ovsdb_instance = Popen(['ovsdb-server', confDbPath, '--remote=punix:%s' % dbSockPath, '--remote=db:Open_vSwitch,manager_options', '--detach', '--pidfile=%s' % ovsdbServerPidPath, '--log-file=%s' % ovsdbServerLogPath], stderr = sys.stderr, stdout = sys.stdout) assert ovsdb_instance.wait() == 0 # Start ovs-vswitchd vswitchd_instance = Popen(['ovs-vswitchd', 'unix:%s' % dbSockPath, '--detach', '--pidfile=%s' % ovsVswitchdPidPath, '--log-file=%s' % ovsVswitchdLogPath], stderr = sys.stderr, stdout = sys.stdout) assert vswitchd_instance.wait() == 0 # Append ovs-vsctl with database information OVSKernelSwitchNew.vsctl_cmd = \ 'ovs-vsctl -t 2 --db=unix:%s ' % dbSockPath # Save the pids of ovsdb-server and ovs-vswitchd OVSKernelSwitchNew.ovsdbServerPid = \ int(file(ovsdbServerPidPath).read().strip()) OVSKernelSwitchNew.ovsVswitchdPid = \ int(file(ovsVswitchdPidPath).read().strip()) else: OVSKernelSwitchNew.vsctl_cmd = 'ovs-vsctl -t 2 ' # Remove old mininet datapaths to make sure they don't interfere brlist = quietRun ( OVSKernelSwitchNew.vsctl_cmd + ' list-br' ) for line in brlist.split("\n"): line = line.rstrip() if re.match('^mn-dp[0-9]+$', line): quietRun ( OVSKernelSwitchNew.vsctl_cmd + ' del-br ' + line )
def setup(): "Ensure any dependencies are loaded; if not, try to load them." pathCheck( 'click-install', 'click-uninstall', moduleName='Click Kernel Switch')
def setup(cls): pathCheck('linc', 'linc_config_gen', 'linc_rel', moduleName='the user-space OpenFlow LINC-Switch' + ' (https://github.com/FlowForwarding/LINC-Switch)')
def setup( cls ): "Make sure our class dependencies are available" pathCheck( 'mnexec', 'ifconfig', moduleName='Mininet')
def setup(): "Ensure any dependencies are loaded; if not, try to load them." pathCheck( 'ovs-dpctl', 'ovs-openflowd', moduleName='Open vSwitch (openvswitch.org)') if not os.path.exists( '/dev/net/tun' ): moduleDeps( add=TUN )
def setup( cls ): "Ensure any dependencies are loaded; if not, try to load them." pathCheck( 'ovs-dpctl', 'ovs-openflowd', moduleName='Open vSwitch (openvswitch.org)') moduleDeps( subtract=OF_KMOD, add=OVS_KMOD )
def setup( cls ): "Make sure Fluid Switch is installed" pathCheck( 'switch', moduleName='the Fluid library example switch' + '(CPqD)')
def setup(): "Ensure any dependencies are loaded; if not, try to load them." pathCheck( 'ofprotocol', moduleName='the OpenFlow reference kernel switch' ' (openflow.org) (NOTE: not available in OpenFlow 1.0!)' ) moduleDeps( subtract=OVS_KMOD, add=OF_KMOD )
def setup( cls ): "Make sure our class dependencies are available" pathCheck( 'brctl', moduleName='bridge-utils' )