Esempio n. 1
0
 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)
Esempio n. 2
0
    def __init__(self, name, json=STRATUM_INIT_PIPELINE, loglevel="warn",
                 cpuport=DEFAULT_CPU_PORT, pipeconf=DEFAULT_PIPECONF,
                 onosdevid=None, adminstate=True,
                 **kwargs):
        Switch.__init__(self, name, **kwargs)
        self.grpcPort = StratumBmv2Switch.nextGrpcPort
        StratumBmv2Switch.nextGrpcPort += 1
        self.cpuPort = cpuport
        self.json = json
        self.loglevel = loglevel
        self.tmpDir = '/tmp/%s' % self.name
        self.logfile = '%s/stratum_bmv2.log' % self.tmpDir
        self.netcfgFile = '%s/onos-netcfg.json' % self.tmpDir
        self.chassisConfigFile = '%s/chassis-config.txt' % self.tmpDir
        self.pipeconfId = pipeconf
        self.longitude = kwargs['longitude'] if 'longitude' in kwargs else None
        self.latitude = kwargs['latitude'] if 'latitude' in kwargs else None
        if onosdevid is not None and len(onosdevid) > 0:
            self.onosDeviceId = onosdevid
        else:
            # The "device:" prefix is required by ONOS.
            self.onosDeviceId = "device:%s" % self.name
        self.nodeId = DEFAULT_NODE_ID
        self.logfd = None
        self.bmv2popen = None
        self.stopped = True
        # In case of exceptions, mininet removes *.out files from /tmp. We use
        # this as a signal to terminate the switch instance (if active).
        self.keepaliveFile = '/tmp/%s-watchdog.out' % self.name
        self.adminState = "ENABLED" if adminstate else "DISABLED"

        # Remove files from previous executions
        self.cleanupTmpFiles()
        os.mkdir(self.tmpDir)
Esempio n. 3
0
    def __init__(self,
                 name,
                 config=None,
                 sw_path="simple_switch",
                 device_id=0,
                 log_file=None,
                 log_level="info",
                 thrift_port=9090,
                 debugger=False,
                 **kwargs):
        """
        :param config: Path to the JSON configuration file. Starting without a configuration will
            drop all traffic.
        :param sw_path: Switch executeable.
        :param device_id: Device ID of the switch. (--device-id)
        :param log_file: Path to a log file. `None` disabled logging. (--log-file)
        :param log_level: One of 'trace', 'debug', 'info', 'warn', 'error', 'off'. (--log-level)
        :param thrift_port: TCP port the thrift server will listen on. (--thrift-port)
        :param debugger: Enable the debugger. (--debugger)
        """
        Switch.__init__(self, name, **kwargs)

        self.config = config
        self.sw_path = sw_path
        self.device_id = device_id
        self.log_file = log_file
        self.log_level = log_level
        self.thrift_port = thrift_port
        self.debugger = debugger
Esempio n. 4
0
 def __init__(self, name, thriftPort=None, deviceId=None, debugger=False,
              loglevel="warn", elogger=False, persistent=True, **kwargs):
     Switch.__init__(self, name, **kwargs)
     self.swPath = environ['BMV2_EXE']
     self.jsonPath = environ['BMV2_JSON']
     if thriftPort:
         self.thriftPort = thriftPort
     else:
         self.thriftPort = ONOSBmv2Switch.pickUnusedPort()
     if not deviceId:
         if self.dpid:
             self.deviceId = int(self.dpid, 0 if 'x' in self.dpid else 16)
         else:
             self.deviceId = ONOSBmv2Switch.deviceId
             ONOSBmv2Switch.deviceId += 1
     else:
         self.deviceId = deviceId
         ONOSBmv2Switch.deviceId = max(deviceId, ONOSBmv2Switch.deviceId)
     self.debugger = debugger
     self.loglevel = loglevel
     self.logfile = '/tmp/bmv2-%d.log' % self.deviceId
     self.output = open(self.logfile, 'w')
     self.elogger = elogger
     self.persistent = persistent
     if persistent:
         self.exectoken = "/tmp/bmv2-%d-exec-token" % self.deviceId
         self.cmd("touch %s" % self.exectoken)
     # Store thrift port for future uses.
     self.cmd("echo %d > /tmp/bmv2-%d-thrift-port" % (self.thriftPort, self.deviceId))
Esempio n. 5
0
    def __init__(self,
                 name,
                 json=None,
                 debugger=False,
                 loglevel="warn",
                 elogger=False,
                 grpcport=None,
                 cpuport=255,
                 notifications=False,
                 thriftport=None,
                 netcfg=True,
                 dryrun=False,
                 pipeconf=DEFAULT_PIPECONF,
                 pktdump=False,
                 valgrind=False,
                 gnmi=False,
                 portcfg=True,
                 onosdevid=None,
                 stratum=False,
                 **kwargs):
        Switch.__init__(self, name, **kwargs)
        self.grpcPort = grpcport
        self.thriftPort = thriftport
        self.cpuPort = cpuport
        self.json = json
        self.useStratum = parseBoolean(stratum)
        self.debugger = parseBoolean(debugger)
        self.notifications = parseBoolean(notifications)
        self.loglevel = loglevel
        # Important: Mininet removes all /tmp/*.log files in case of exceptions.
        # We want to be able to see the bmv2 log if anything goes wrong, hence
        # avoid the .log extension.
        self.logfile = '/tmp/bmv2-%s-log' % self.name
        self.elogger = parseBoolean(elogger)
        self.pktdump = parseBoolean(pktdump)
        self.netcfg = parseBoolean(netcfg)
        self.dryrun = parseBoolean(dryrun)
        self.valgrind = parseBoolean(valgrind)
        self.netcfgfile = '/tmp/bmv2-%s-netcfg.json' % self.name
        self.chassisConfigFile = '/tmp/bmv2-%s-chassis-config.txt' % self.name
        self.pipeconfId = pipeconf
        self.injectPorts = parseBoolean(portcfg)
        self.withGnmi = parseBoolean(gnmi)
        self.longitude = kwargs['longitude'] if 'longitude' in kwargs else None
        self.latitude = kwargs['latitude'] if 'latitude' in kwargs else None
        if onosdevid is not None and len(onosdevid) > 0:
            self.onosDeviceId = onosdevid
        else:
            self.onosDeviceId = "device:bmv2:%s" % self.name
        self.p4DeviceId = BMV2_DEFAULT_DEVICE_ID
        self.logfd = None
        self.bmv2popen = None
        self.stopped = True
        # In case of exceptions, mininet removes *.out files from /tmp. We use
        # this as a signal to terminate the switch instance (if active).
        self.keepaliveFile = '/tmp/bmv2-%s-watchdog.out' % self.name
        self.targetName = STRATUM_BMV2 if self.useStratum else SIMPLE_SWITCH_GRPC

        # Remove files from previous executions
        self.cleanupTmpFiles()
Esempio n. 6
0
    def __init__( self, name, sw_path="dc_full", json_path=None,
			thrift_port=None,
			pcap_dump=True,
			verbose=True,
			device_id=None,
			enable_debugger=True,
			**kwargs ):

        Switch.__init__(self, name, **kwargs)

        assert(sw_path)
        assert(json_path)
        self.sw_path = sw_path
        self.json_path = json_path
        self.verbose = verbose
        self.logfile = '/tmp/p4s.%s.log' % self.name
        self.thrift_port = thrift_port
        self.pcap_dump = pcap_dump
        self.enable_debugger = enable_debugger
        self.nanomsg = "ipc:///bm-%d-log.ipc" % self.device_id
        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
Esempio n. 7
0
    def __init__(self,
                 name,
                 target_name='p4dockerswitch',
                 thrift_port=None,
                 target_dir='switch',
                 sai_port=None,
                 swapi_port=None,
                 pcap_dump=False,
                 verbose=False,
                 start_program='/p4factory/tools/start.sh',
                 config_fs=None,
                 pps=0,
                 qdepth=0,
                 **kwargs):

        self.verbose = verbose
        self.pcap_dump = pcap_dump
        self.start_program = start_program
        self.config_fs = config_fs
        self.target_name = target_name
        self.target_dir = target_dir
        self.thrift_port = thrift_port
        self.sai_port = sai_port
        self.swapi_port = swapi_port
        self.pps = pps
        self.qdepth = qdepth
        Switch.__init__(self, name, **kwargs)
        self.inNamespace = True
Esempio n. 8
0
 def __init__(self,
              name,
              sw_path=None,
              json_path=None,
              thrift_port=None,
              pcap_dump=False,
              verbose=False,
              device_id=None,
              enable_debugger=False,
              cpu_port=None,
              **kwargs):
     Switch.__init__(self, name, **kwargs)
     assert (sw_path)
     self.sw_path = sw_path
     self.json_path = json_path
     self.verbose = verbose
     logfile = '/tmp/p4s.%s.log' % self.name
     self.output = open(logfile, 'w')
     self.thrift_port = thrift_port
     self.pcap_dump = pcap_dump
     self.enable_debugger = enable_debugger
     self.cpu_port = cpu_port
     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-%d-log.ipc" % self.device_id
Esempio n. 9
0
 def __init__(self, name, thriftPort=None, deviceId=None, debugger=False,
              loglevel="warn", elogger=False, persistent=True, **kwargs):
     Switch.__init__(self, name, **kwargs)
     self.swPath = environ['BMV2_EXE']
     self.jsonPath = environ['BMV2_JSON']
     if not thriftPort:
         self.thriftPort = ONOSBmv2Switch.thriftPort
         ONOSBmv2Switch.thriftPort += 1
     else:
         self.thriftPort = thriftPort
         ONOSBmv2Switch.thriftPort = max(thriftPort, ONOSBmv2Switch.thriftPort)
     if not deviceId:
         if self.dpid:
             self.deviceId = int(self.dpid, 0 if 'x' in self.dpid else 16)
         else:
             self.deviceId = ONOSBmv2Switch.deviceId
             ONOSBmv2Switch.deviceId += 1
     else:
         self.deviceId = deviceId
         ONOSBmv2Switch.deviceId = max(deviceId, ONOSBmv2Switch.deviceId)
     self.debugger = debugger
     self.loglevel = loglevel
     self.logfile = '/tmp/bmv2-%d.log' % self.deviceId
     self.output = open(self.logfile, 'w')
     self.elogger = elogger
     self.persistent = persistent
     if persistent:
         self.exectoken = "/tmp/bmv2-%d-exec-token" % self.deviceId
         self.cmd("touch %s" % self.exectoken)
Esempio n. 10
0
    def __init__( self, name, target_name = 'p4dockerswitch',
                  thrift_port = None, target_dir = 'single_device',
                  sai_port = None,
                  swapi_port = None,
                  pcap_dump = False,
                  verbose = False,
                  start_program = '/p4factory/tools/start.sh',
                  config_fs = None,
                  pps = 0,
                  qdepth = 0,
                  **kwargs ):

        self.verbose = verbose
        self.pcap_dump = pcap_dump
        self.start_program = start_program
        self.config_fs = config_fs
        self.target_name = target_name
        self.target_dir = target_dir
        self.thrift_port = thrift_port
        self.sai_port = sai_port
        self.swapi_port = swapi_port
        self.pps = pps
        self.qdepth = qdepth
        Switch.__init__( self, name, **kwargs )
        self.inNamespace = True
Esempio n. 11
0
    def __init__(self,
                 name,
                 inNamespace=True,
                 sdeInstall="/root/sde/install",
                 bfSwitchdConfig="/etc/stratum/tofino_skip_p4.conf",
                 **kwargs):
        Switch.__init__(self, name, inNamespace=True, **kwargs)
        self.sdeInstall = sdeInstall
        self.bfSwitchdConfig = bfSwitchdConfig
        self.nodeId = StratumTofinoModel.nextNodeId * 64
        StratumTofinoModel.nextNodeId += 1

        self.tmpDir = '/tmp/%s' % self.name
        self.chassisConfigFile = '%s/chassis-config.txt' % self.tmpDir
        self.portVethFile = '%s/ports.json' % self.tmpDir

        # process handles for tofino model and stratum
        self.modelProcHandle = None
        self.stratumProcHandle = None
        # !(run) or run ? boolean bit
        self.stopped = True

        # In case of exceptions, mininet removes *.out files from /tmp. We use
        # this as a signal to terminate the switch instance (if active).
        self.keepalive = '/tmp/%s-watchdog.out' % self.name
        # Remove files from previous executions
        self.cmd("rm -rf %s" % self.tmpDir)
        os.mkdir(self.tmpDir)
Esempio n. 12
0
 def __init__(self, name, sw_path=None, json_path=None,
              thrift_port=None,
              pcap_dump=True,
              log_console=True,
              verbose=True,
              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)
Esempio n. 13
0
 def __init__(self,
              name,
              sw_path=None,
              json_path=None,
              thrift_port=None,
              grpc_port=None,
              pcap_dump=False,
              verbose=False,
              device_id=None,
              enable_debugger=False,
              cpu_port=None,
              **kwargs):
     Switch.__init__(self, name, **kwargs)
     assert (sw_path)
     self.sw_path = sw_path
     self.json_path = json_path
     self.verbose = verbose
     self.thrift_port = thrift_port
     self.grpc_port = grpc_port
     # self.pcap_dump = pcap_dump
     self.enable_debugger = enable_debugger
     self.cpu_port = cpu_port
     if device_id is not None:
         self.device_id = device_id
         P4Switch.device_id = max(P4Switch.device_id, device_id)
         # self.thrift_port = 9090 + device_id
     else:
         self.device_id = P4Switch.device_id
         P4Switch.device_id += 1
Esempio n. 14
0
 def __init__(self,
              name,
              json=None,
              debugger=False,
              loglevel="warn",
              elogger=False,
              persistent=False,
              grpcPort=None,
              netcfg=True,
              **kwargs):
     Switch.__init__(self, name, **kwargs)
     self.grpcPort = ONOSBmv2Switch.pickUnusedPort(
     ) if not grpcPort else grpcPort
     if self.dpid:
         self.deviceId = int(self.dpid, 0 if 'x' in self.dpid else 16)
     else:
         self.deviceId = ONOSBmv2Switch.deviceId
         ONOSBmv2Switch.deviceId += 1
     self.json = json
     self.debugger = debugger
     self.loglevel = loglevel
     self.logfile = '/tmp/bmv2-%d.log' % self.deviceId
     self.elogger = elogger
     self.persistent = persistent
     self.netcfg = netcfg
     self.netcfgfile = '/tmp/bmv2-%d-netcfg.json' % self.deviceId
     if persistent:
         self.exectoken = "/tmp/bmv2-%d-exec-token" % self.deviceId
         self.cmd("touch %s" % self.exectoken)
     # Store thrift port for future uses.
     self.cmd("echo %d > /tmp/bmv2-%d-grpc-port" %
              (self.grpcPort, self.deviceId))
Esempio n. 15
0
    def __init__(self, name, **kwargs):

        kwargs['inNamespace'] = True
        Switch.__init__(self, name, **kwargs)

        Router.ID += 1
        self.switch_id = Router.ID
Esempio n. 16
0
 def __init__(self, name, **kwargs):
     if 'notInNamespace' not in kwargs:
         kwargs['inNamespace'] = True
     else:
         kwargs.pop('notInNamespace')
     Switch.__init__(self, name, **kwargs)
     Router.ID += 1
     self.switch_id = Router.ID
Esempio n. 17
0
 def stop(self, deleteIntfs=True):
     """Terminate switch."""
     self.stopped = True
     if self.anyProcHandleLive():
         self.tryTerminate()
         self.modelProcHandle = None
         self.stratumProcHandle = None
     Switch.stop(self, deleteIntfs)
Esempio n. 18
0
    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,
                 **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)
Esempio n. 19
0
 def __init__(self,
              name,
              json=None,
              debugger=False,
              loglevel="info",
              elogger=False,
              grpcport=None,
              cpuport=255,
              notifications=False,
              thriftport=None,
              netcfg=True,
              dryrun=False,
              pipeconf="",
              pktdump=False,
              valgrind=False,
              gnmi=False,
              portcfg=True,
              onosdevid=None,
              switch_config=None,
              **kwargs):
     Switch.__init__(self, name, **kwargs)
     self.wintfs = {}  # dict of wireless port numbers
     self.wports = {}  # dict of interfaces to port numbers
     self.grpcPort = grpcport
     self.thriftPort = thriftport
     self.cpuPort = cpuport
     self.json = json
     self.debugger = parseBoolean(debugger)
     self.notifications = parseBoolean(notifications)
     self.loglevel = loglevel
     # Important: Mininet removes all /tmp/*.log files in case of exceptions.
     # We want to be able to see the bmv2 log if anything goes wrong, hence
     # avoid the .log extension.
     self.logfile = '/tmp/bmv2-%s-log' % self.name
     self.elogger = parseBoolean(elogger)
     self.pktdump = parseBoolean(pktdump)
     self.netcfg = parseBoolean(netcfg)
     self.dryrun = parseBoolean(dryrun)
     self.valgrind = parseBoolean(valgrind)
     self.netcfgfile = '/tmp/bmv2-%s-netcfg.json' % self.name
     self.pipeconfId = pipeconf
     self.injectPorts = parseBoolean(portcfg)
     self.withGnmi = parseBoolean(gnmi)
     self.longitude = kwargs['longitude'] if 'longitude' in kwargs else None
     self.latitude = kwargs['latitude'] if 'latitude' in kwargs else None
     if onosdevid is not None and len(onosdevid) > 0:
         self.onosDeviceId = onosdevid
     else:
         self.onosDeviceId = "device:bmv2:%s" % self.name
     nums = re.findall(r'\d+', name)
     self.p4DeviceId = nums[0]
     self.logfd = None
     self.bmv2popen = None
     self.stopped = False
     self.switch_config = switch_config
     # Remove files from previous executions
     self.cleanupTmpFiles()
Esempio n. 20
0
    def __init__(self,
                 name,
                 json=None,
                 debugger=False,
                 loglevel="warn",
                 elogger=False,
                 persistent=False,
                 grpcPort=None,
                 thriftPort=None,
                 netcfg=True,
                 dryrun=False,
                 pipeconfId="",
                 pktdump=False,
                 valgrind=False,
                 netcfgDelay=0,
                 **kwargs):
        Switch.__init__(self, name, **kwargs)
        self.grpcPort = ONOSBmv2Switch.pickUnusedPort(
        ) if not grpcPort else grpcPort
        self.thriftPort = ONOSBmv2Switch.pickUnusedPort(
        ) if not thriftPort else thriftPort
        if self.dpid:
            self.deviceId = int(self.dpid, 0 if 'x' in self.dpid else 16)
        else:
            self.deviceId = ONOSBmv2Switch.deviceId
            ONOSBmv2Switch.deviceId += 1
        self.json = json
        self.debugger = parseBoolean(debugger)
        self.loglevel = loglevel
        self.logfile = '/tmp/bmv2-%d.log' % self.deviceId
        self.elogger = parseBoolean(elogger)
        self.pktdump = parseBoolean(pktdump)
        self.persistent = parseBoolean(persistent)
        self.netcfg = parseBoolean(netcfg)
        self.dryrun = parseBoolean(dryrun)
        self.valgrind = parseBoolean(valgrind)
        self.netcfgDelay = netcfgDelay
        self.netcfgfile = '/tmp/bmv2-%d-netcfg.json' % self.deviceId
        self.pipeconfId = pipeconfId
        if persistent:
            self.exectoken = "/tmp/bmv2-%d-exec-token" % self.deviceId
            self.cmd("touch %s" % self.exectoken)
        # Store thrift port for future uses.
        self.cmd("echo %d > /tmp/bmv2-%d-grpc-port" %
                 (self.grpcPort, self.deviceId))

        if 'longitude' in kwargs:
            self.longitude = kwargs['longitude']
        else:
            self.longitude = None

        if 'latitude' in kwargs:
            self.latitude = kwargs['latitude']
        else:
            self.latitude = None

        self.onosDeviceId = "device:bmv2:%d" % self.deviceId
Esempio n. 21
0
 def __init__( self, name, dpid=None, allowed=True,
               switchType='ROADM', annotations={}, **params ):
     params[ 'inNamespace' ] = False
     Switch.__init__( self, name, dpid=dpid, **params )
     self.name = name
     self.annotations = annotations
     self.allowed = allowed
     self.switchType = switchType
     self.configDict = {} # dictionary that holds all of the JSON configuration data
Esempio n. 22
0
 def __init__(self,
              name,
              logFile="/dev/null",
              inNamespace=True,
              parameters=[],
              **params):
     Switch.__init__(self, name, inNamespace=inNamespace, **params)
     self._logFile = logFile
     self._params = parameters
Esempio n. 23
0
 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
Esempio n. 24
0
 def __init__( self, name, stp=False, prio=None, **kwargs ):
     """stp: use spanning tree protocol? (default False)
        prio: optional explicit bridge priority for STP"""
     self.stp = stp
     if prio:
         self.prio = prio
     else:
         self.prio = LinuxBridge.nextPrio
         LinuxBridge.nextPrio += 1
     Switch.__init__( self, name, **kwargs )
Esempio n. 25
0
 def __init__(self, name, stp=False, prio=None, **kwargs):
     """stp: use spanning tree protocol? (default False)
        prio: optional explicit bridge priority for STP"""
     self.stp = stp
     if prio:
         self.prio = prio
     else:
         self.prio = LinuxBridge.nextPrio
         LinuxBridge.nextPrio += 1
     Switch.__init__(self, name, **kwargs)
Esempio n. 26
0
 def __init__(self, name, switch_type="router", log_file=None, **params):
     Switch.__init__(self, name, **params)
     self.log_file = log_file if log_file else "log/{}.log".format(
         self.name)
     if switch_type == "simple_switch":
         self.make_config = self.simple_switch
     elif switch_type == "router":
         self.make_config = self.router
     else:
         raise NotImplementedError(switch_type)
Esempio n. 27
0
    def __init__(self, name, json=None, debugger=False, loglevel="info",
                 elogger=False, grpcport=None, cpuport=255, notifications=False,
                 thriftport=None, netcfg=False, dryrun=False, inNamespace=False,
                 inband=False, pipeconf=DEFAULT_PIPECONF, pktdump=False, valgrind=False,
                 gnmi=False, portcfg=True, onosdevid=None, stratum=False,
                 switch_config=None, **kwargs):
        Switch.__init__(self, name, inNamespace=inNamespace, **kwargs)
        self.grpcPort = grpcport
        self.grpcPortInternal = None  # Needed for Stratum (local_hercules_url)
        self.thriftPort = thriftport
        self.cpuPort = cpuport
        self.inNamespace = inNamespace
        self.inband = inband
        self.useStratum = parseBoolean(stratum)
        self.debugger = parseBoolean(debugger)
        self.notifications = parseBoolean(notifications)
        self.loglevel = loglevel
        # Important: Mininet removes all /tmp/*.log files in case of exceptions.
        # We want to be able to see the bmv2 log if anything goes wrong, hence
        # avoid the .log extension.
        self.logfile = '/tmp/bmv2-%s-log' % self.name
        self.elogger = parseBoolean(elogger)
        self.pktdump = parseBoolean(pktdump)
        self.netcfg = parseBoolean(netcfg)
        self.dryrun = parseBoolean(dryrun)
        self.valgrind = parseBoolean(valgrind)
        self.netcfgfile = '/tmp/bmv2-%s-netcfg.json' % self.name
        self.chassisConfigFile = '/tmp/bmv2-%s-chassis-config.txt' % self.name
        self.pipeconfId = pipeconf
        self.injectPorts = parseBoolean(portcfg)
        self.withGnmi = parseBoolean(gnmi)
        self.longitude = kwargs['longitude'] if 'longitude' in kwargs else None
        self.latitude = kwargs['latitude'] if 'latitude' in kwargs else None
        if onosdevid is not None and len(onosdevid) > 0:
            self.onosDeviceId = onosdevid
        else:
            self.onosDeviceId = "device:bmv2:%s" % self.name
        nums = re.findall(r'\d+', name)
        self.p4DeviceId = int(nums[0])
        self.logfd = None
        self.bmv2popen = None
        self.stopped = True
        self.sip = None
        # In case of exceptions, mininet removes *.out files from /tmp. We use
        # this as a signal to terminate the switch instance (if active).
        self.keepaliveFile = '/tmp/bmv2-%s-watchdog.out' % self.name
        self.targetName = STRATUM_BMV2 if self.useStratum else SIMPLE_SWITCH_GRPC
        self.controllers = None
        self.switch_config = switch_config

        path = os.path.dirname(os.path.abspath(__file__)) + '/examples/p4/ap-runtime.json'
        self.json = path if not json else json

        # Remove files from previous executions
        self.cleanupTmpFiles()
Esempio n. 28
0
    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
Esempio n. 29
0
 def __init__(self,
              name,
              config_file,
              log_file='/dev/null',
              inNamespace=True,
              parameters={},
              **params):
     Switch.__init__(self, name, inNamespace=inNamespace, **params)
     self.config_file = config_file
     self.log_file = log_file
     self.params = parameters
Esempio n. 30
0
    def __init__(self, name, switch_path='softswitch', dpid=None, **kwargs):
        Switch.__init__(self, name, **kwargs)

        self.switch_path = switch_path

        if dpid:
            self.dpid = dpid
            eBPFSwitch.dpid = max(eBPFSwitch.dpid, dpid)
        else:
            self.dpid = eBPFSwitch.dpid
            eBPFSwitch.dpid += 1
Esempio n. 31
0
    def __init__(self, name, **kwargs):
        kwargs['inNamespace'] = True
        Switch.__init__(self, name, **kwargs)
        print "Switch %s %s" % (name, self.inNamespace)
        Routed.ID += 1
        self.switch_id = Routed.ID
        self.kind = kwargs.get('kind')

        self.num_leafs = kwargs.get('num_leafs')
        self.num_spines = kwargs.get('num_spines')
        self.hosts_per_leaf = kwargs.get('hosts_per_leaf')
Esempio n. 32
0
 def __init__( self, name, sw_path = "dc_full",
               thrift_port = None,
               pcap_dump = False,
               verbose = False, **kwargs ):
     Switch.__init__( self, name, **kwargs )
     self.sw_path = sw_path
     self.verbose = verbose
     logfile = '/tmp/p4ns.%s.log' % self.name
     self.output = open(logfile, 'w')
     self.thrift_port = thrift_port
     self.pcap_dump = pcap_dump
Esempio n. 33
0
File: bmv2.py Progetto: lijenni/onos
    def __init__(self,
                 name,
                 json=None,
                 debugger=False,
                 loglevel="warn",
                 elogger=False,
                 grpcport=None,
                 cpuport=255,
                 thriftport=None,
                 netcfg=True,
                 dryrun=False,
                 pipeconf="",
                 pktdump=False,
                 valgrind=False,
                 gnmi=False,
                 portcfg=True,
                 onosdevid=None,
                 **kwargs):
        Switch.__init__(self, name, **kwargs)
        self.grpcPort = pickUnusedPort() if not grpcport else grpcport
        self.thriftPort = pickUnusedPort() if not thriftport else thriftport
        self.cpuPort = cpuport
        self.json = json
        self.debugger = parseBoolean(debugger)
        self.loglevel = loglevel
        # Important: Mininet removes all /tmp/*.log files in case of exceptions.
        # We want to be able to see the bmv2 log if anything goes wrong, hence
        # avoid the .log extension.
        self.logfile = '/tmp/bmv2-%s-log' % self.name
        self.elogger = parseBoolean(elogger)
        self.pktdump = parseBoolean(pktdump)
        self.netcfg = parseBoolean(netcfg)
        self.dryrun = parseBoolean(dryrun)
        self.valgrind = parseBoolean(valgrind)
        self.netcfgfile = '/tmp/bmv2-%s-netcfg.json' % self.name
        self.pipeconfId = pipeconf
        self.injectPorts = parseBoolean(portcfg)
        self.withGnmi = parseBoolean(gnmi)
        self.longitude = kwargs['longitude'] if 'longitude' in kwargs else None
        self.latitude = kwargs['latitude'] if 'latitude' in kwargs else None
        if onosdevid is not None and len(onosdevid) > 0:
            self.onosDeviceId = onosdevid
        else:
            self.onosDeviceId = "device:bmv2:%s" % self.name
        self.logfd = None
        self.bmv2popen = None
        self.stopped = False

        # Remove files from previous executions
        self.cleanupTmpFiles()

        writeToFile("/tmp/bmv2-%s-grpc-port" % self.name, self.grpcPort)
        writeToFile("/tmp/bmv2-%s-thrift-port" % self.name, self.thriftPort)
Esempio n. 34
0
    def __init__(self, name, dpid=None, config_path=None,
                 controller=None, **params):
        """Initialize this LINC-Switch.

        Most of the parameters will be passed on to the standard Mininet Link
        constructor, except for the LINC-specific attributes, such as config
        filepath.
        """
        params['inNamespace'] = False
        Switch.__init__(self, name, dpid=dpid, **params)
        self.config_path = LINC_CONFIG if config_path is None else config_path
        self.controller = controller
Esempio n. 35
0
    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
Esempio n. 36
0
 def stop(self, deleteIntfs=True):
     """Terminate switch."""
     self.stopped = True
     if self.bmv2popen is not None:
         if self.bmv2popen.poll() is None:
             self.bmv2popen.terminate()
             self.bmv2popen.wait()
         self.bmv2popen = None
     if self.logfd is not None:
         self.logfd.close()
         self.logfd = None
     Switch.stop(self, deleteIntfs)
Esempio n. 37
0
 def __init__( self, name, configPath=None, dp=None, **kwargs ):
     """Init.
        name: name for switch
        dp: netlink id (0, 1, 2, ...)
        defaultMAC: default MAC as unsigned int; random value if None"""
     Switch.__init__( self, name, **kwargs )
     self.dp = 'dp%i' % dp
     self.intf = self.dp
     # Create a copy of the config for renaming
     if not configPath:
         configPath = os.path.join(os.getcwd(), "test.click")
     self.configPath = configPath + ".intf"
     shutil.copy(configPath, self.configPath)
Esempio n. 38
0
 def __init__(self, name, dpid=None, allowed=True,
               switchType='ROADM', topo=None, annotations={}, controller=None, **params):
     params[ 'inNamespace' ] = False
     Switch.__init__(self, name, dpid=dpid, **params)
     self.name = name
     self.annotations = annotations
     self.allowed = allowed
     self.switchType = switchType
     self.configDict = {}  # dictionary that holds all of the JSON configuration data
     self.crossConnects = []
     self.deletedCrossConnects = []
     self.controller = controller
     self.lincId = self._get_linc_id()  # use to communicate with LINC
     self.lincStarted = False
Esempio n. 39
0
 def __init__(self, name, dpid=None, allowed=True,
               switchType='ROADM', topo=None, annotations={}, controller=None, **params):
     params[ 'inNamespace' ] = False
     Switch.__init__(self, name, dpid=dpid, **params)
     self.name = name
     self.annotations = annotations
     self.allowed = allowed
     self.switchType = switchType
     self.configDict = {}  # dictionary that holds all of the JSON configuration data
     self.crossConnects = []
     self.deletedCrossConnects = []
     self.controller = controller
     self.lincId = self._get_linc_id()  # use to communicate with LINC
     self.lincStarted = False
Esempio n. 40
0
 def __init__( self, name, sw_path = None, json_path = None,
               thrift_port = None,
               pcap_dump = False,
               verbose = False, **kwargs ):
     Switch.__init__( self, name, **kwargs )
     assert(sw_path)
     assert(json_path)
     self.sw_path = sw_path
     self.json_path = json_path
     self.verbose = verbose
     logfile = '/tmp/bfns.%s.log' % self.name
     self.output = open(logfile, 'w')
     self.thrift_port = thrift_port
     self.pcap_dump = pcap_dump
Esempio n. 41
0
 def __init__(self,
              name,
              sw_path="dc_full",
              thrift_port=None,
              pcap_dump=False,
              verbose=False,
              **kwargs):
     Switch.__init__(self, name, **kwargs)
     self.sw_path = sw_path
     self.verbose = verbose
     logfile = '/tmp/p4ns.%s.log' % self.name
     self.output = open(logfile, 'w')
     self.thrift_port = thrift_port
     self.pcap_dump = pcap_dump
Esempio n. 42
0
    def __init__(self, name, **kwargs):
        """

        :param name:
        :param kwargs:
        :return:
        """

        Switch.__init__(self, name, **kwargs)

        # Check if 'pydatapath' is running.
        try:
            output = subprocess.check_output('netstat -lnp | grep ' + str(ProgSwitch.CTL_PORT), shell=True).strip()
        except:
            error(
                "*** error: 'pydatapath' is not running at " + ProgSwitch.CTL_ADDRESS + "::" + str(ProgSwitch.CTL_PORT) + "\n")
            exit(1)
Esempio n. 43
0
    def __init__( self, name, target_name = 'p4dockerswitch',
                  thrift_port = None,
                  sai_port = None,
                  pcap_dump = False,
                  verbose = False,
                  start_program = '/p4factory/tools/start.sh',
                  config_fs = None,
                  **kwargs ):

        self.verbose = verbose
        self.pcap_dump = pcap_dump
        self.start_program = start_program
        self.config_fs = config_fs
        self.target_name = target_name
        self.thrift_port = thrift_port
        self.sai_port = sai_port
        Switch.__init__( self, name, **kwargs )
        self.inNamespace = True
Esempio n. 44
0
    def __init__( self, name, config_path = None,
		 # json_path = None,
                 # thrift_port = None,
                 # pcap_dump = False,
                 # verbose = False,
                  device_id = None,
                  **kwargs ):
        Switch.__init__( self, name, **kwargs )
	#self.parseConfig( config_path )
        logfile = '/tmp/p4s.%s.log' % self.name
        self.output = open(logfile, 'w')
        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-%d-log.ipc" % self.device_id
Esempio n. 45
0
    def __init__(self, name, json=None, debugger=False, loglevel="warn",
                 elogger=False, grpcport=None, cpuport=255, notifications=False,
                 thriftport=None, netcfg=True, dryrun=False, pipeconf="",
                 pktdump=False, valgrind=False, gnmi=False,
                 portcfg=True, onosdevid=None, **kwargs):
        Switch.__init__(self, name, **kwargs)
        self.grpcPort = grpcport
        self.thriftPort = thriftport
        self.cpuPort = cpuport
        self.json = json
        self.debugger = parseBoolean(debugger)
        self.notifications = parseBoolean(notifications)
        self.loglevel = loglevel
        # Important: Mininet removes all /tmp/*.log files in case of exceptions.
        # We want to be able to see the bmv2 log if anything goes wrong, hence
        # avoid the .log extension.
        self.logfile = '/tmp/bmv2-%s-log' % self.name
        self.elogger = parseBoolean(elogger)
        self.pktdump = parseBoolean(pktdump)
        self.netcfg = parseBoolean(netcfg)
        self.dryrun = parseBoolean(dryrun)
        self.valgrind = parseBoolean(valgrind)
        self.netcfgfile = '/tmp/bmv2-%s-netcfg.json' % self.name
        self.pipeconfId = pipeconf
        self.injectPorts = parseBoolean(portcfg)
        self.withGnmi = parseBoolean(gnmi)
        self.longitude = kwargs['longitude'] if 'longitude' in kwargs else None
        self.latitude = kwargs['latitude'] if 'latitude' in kwargs else None
        if onosdevid is not None and len(onosdevid) > 0:
            self.onosDeviceId = onosdevid
        else:
            self.onosDeviceId = "device:bmv2:%s" % self.name
        self.logfd = None
        self.bmv2popen = None
        self.stopped = False

        # Remove files from previous executions
        self.cleanupTmpFiles()
 def __init__( self, name, sw_path = None, json_path = None,
               thrift_port = None,
               pcap_dump = False,
               verbose = False,
               device_id = None,
               **kwargs ):
     Switch.__init__( self, name, **kwargs )
     assert(sw_path)
     assert(json_path)
     self.sw_path = sw_path
     self.json_path = json_path
     self.verbose = verbose
     logfile = '/tmp/p4s.%s.log' % self.name
     self.output = open(logfile, 'w')
     self.thrift_port = thrift_port
     self.pcap_dump = pcap_dump
     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-%d-log.ipc" % self.device_id
Esempio n. 47
0
 def __init__(self, name, **kwargs):
     Switch.__init__(self, name, **kwargs)
     self.policy = ''
 def __init__( self, name, dataPathOptions='--no-slicing', **kwargs ):
     Switch.__init__( self, name, **kwargs )
     self.packetQueue  = Queue()
     self.CustomSwitchLogger = self.get_logger("CustomSwitch")
Esempio n. 49
0
 def __init__(self, name, **kwargs):
     Switch.__init__(self, name, **kwargs)
 def __init__(self, name, blocking=False, **params):
     Switch.__init__(self, name, **params)
     self.block = blocking
    def __init__( self, name, control_flag=False, control_type="",
                  address="127.0.0.1", port=6633, ports="", dpid=None,
                  max_retry_delay=16, extra="", listenPort=None, **params):
        """Init.
           name: name for switch
           control_flag: spawn personal controller?
           control_type: personal controller type
           address: IP address to listen to (and personal controller address)
           port: TCP port to listen to (and personal controller port)
           ports: network interfaces to connect
           dpid: dpid for switch (or None to derive from name, e.g. s1 -> 1)
           max_retry_delay: max time between retries to connect to controller
           extra: extra parameters
           listenPort: port to listen on for dpctl connections
           params: Node parameters (see config() for details)"""
        Switch.__init__(self, name, dpid, listenPort=listenPort, **params)

        self.print_personal_debug = False
        print "iiiiiiiiiiiiiiiiiiii"
        ps = "Args: "
        ps += "\n  name           \t"      + str(name)
        ps += "\n  control_flag   \t"      + str(control_flag)
        ps += "\n  control_type   \t"      + str(control_type)
        ps += "\n  address        \t"      + str(address)
        ps += "\n  port           \t"      + str(port)
        ps += "\n  ports          \t"      + str(ports)
        ps += "\n  dpid           \t"      + str(dpid)
        ps += "\n  max_retry_delay\t"      + str(max_retry_delay)
        ps += "\n  extra          \t"      + str(extra)
        ps += "\n  listenPort     \t"      + str(listenPort)
        ps += "\n  params         \t"      + str(params)
        if self.print_personal_debug: print ps

        if 'POX_CORE_DIR' not in os.environ:
            #exit( 'exiting; please set missing POX_CORE_DIR env var' )
            self.poxCoreDir = "/home/mininet/pox"
        else:
            self.poxCoreDir = os.environ[ 'POX_CORE_DIR' ]

        self.use_remote_controller = (not control_flag)
        self.controller_type = control_type
        self.controller_ip = address if address else "127.0.0.1"
        self.controller_port = int(port) if port else 6633
        self.input_intf_ports = ports.split(";") if ports else []
        self.max_retry_delay = max_retry_delay if max_retry_delay else 16
        self.extra = format_pox_extra(extra).split(";") if extra else []

        # NOTE: In case these are needed elsewhere...
        self.run_file = ""
        self.ctrl_args = ""
        self.cmd_args = ""
        self.cmd_log = ""
        self.cmd_tail = ""
        self.command = ""
        self.intf_ports = []
        self.pox_pid = None
        # @GLY
        self.lastPid = None
        self.started_switch = False

        ps = "Input to POXSwitch.__init__(): "
        ps += "\n  poxCoreDir      \t"      + str(self.poxCoreDir)
        ps += "\n  switch_name     \t"      + str(self.name)
        ps += "\n  use_remote_controller\t" + str(self.use_remote_controller)
        ps += "\n  controller_type \t"      + str(self.controller_type)
        ps += "\n  controller_ip   \t"      + str(self.controller_ip)
        ps += "\n  controller_port \t"      + str(self.controller_port)
        ps += "\n  input_intf_ports\t"      + str(self.input_intf_ports)
        ps += "\n  switch_dpid     \t"      + str(self.dpid)
        ps += "\n  max_retry_delay \t"      + str(self.max_retry_delay)
        ps += "\n  extra_parameters\t"      + str(self.extra)
        ps += "\n  listenPort      \t"      + str(self.listenPort)
        if self.print_personal_debug: print ps
Esempio n. 52
0
 def __init__(self, name, **kwargs):
     kwargs['inNamespace'] = True
     Switch.__init__(self, name, **kwargs)
     Router.ID += 1
     self.switch_id = Router.ID
Esempio n. 53
0
 def popen( self, *args, **kwargs ):
     mncmd = [ 'docker', 'exec', "mininet-"+self.name ]
     return Switch.popen( self, *args, mncmd=mncmd, **kwargs )
Esempio n. 54
0
 def stop(self, deleteIntfs=True):
     """Terminate switch."""
     self.stopped = True
     self.killBmv2(log=True)
     Switch.stop(self, deleteIntfs)