def addremovectrlnet(self, netidx, remove=False, conf_reqd=True):
        ''' Create a control network bridge as necessary.
        When the remove flag is True, remove the bridge that connects control
        interfaces. The conf_reqd flag, when False, causes a control network
        bridge to be added even if one has not been configured.
        '''
        prefixspeclist = self.getctrlnetprefixes()
        prefixspec = prefixspeclist[netidx]
        if not prefixspec:
            if conf_reqd:
                return None  # no controlnet needed
            else:
                prefixspec = nodes.CtrlNet.DEFAULT_PREFIX_LIST[netidx]
                
        serverintf = self.getctrlnetserverintf()[netidx]

        # return any existing controlnet bridge
        try:
            ctrlnet = self.getctrlnetobj(netidx)
            if remove:
                self.delobj(ctrlnet.objid)
                return None
            return ctrlnet
        except KeyError:
            if remove:
                return None

        # build a new controlnet bridge
        oid = "ctrl%dnet" % netidx

        # use the updown script for control net 0 only.
        updown_script = None
        if netidx == 0:
            try:
                if self.cfg['controlnet_updown_script']:
                    updown_script = self.cfg['controlnet_updown_script']
            except __HOLE__:
                pass
            # Check if session option set, overwrite if so
            if hasattr(self.options, 'controlnet_updown_script'):
                new_uds = self.options.controlnet_updown_script
            if new_uds:
                updown_script = new_uds
                

        prefixes = prefixspec.split()
        if len(prefixes) > 1: 
            # A list of per-host prefixes is provided
            assign_address = True
            if self.master:
                try:
                    # split first (master) entry into server and prefix
                    prefix = prefixes[0].split(':', 1)[1]
                except IndexError:
                    # no server name. possibly only one server
                    prefix = prefixes[0] 
            else:
                # slave servers have their name and localhost in the serverlist
                servers = self.broker.getserverlist()
                servers.remove('localhost')
                prefix = None
                for server_prefix in prefixes:
                    try:
                        # split each entry into server and prefix
                        server, p = server_prefix.split(':')
                    except ValueError:
                        server = ""
                        p = None
                        
                    if server == servers[0]:
                        # the server name in the list matches this server
                        prefix = p
                        break
                if not prefix:
                    msg = "Control network prefix not found for server '%s'" % \
                            servers[0]
                    self.exception(coreapi.CORE_EXCP_LEVEL_ERROR,
                                   "Session.addremovectrlnet()", None, msg)
                    assign_address = False
                    try:
                        prefix = prefixes[0].split(':', 1)[1]
                    except IndexError:
                        prefix = prefixes[0]
        else: # len(prefixes) == 1 
            # TODO: can we get the server name from the servers.conf or from the node assignments?
            # with one prefix, only master gets a ctrlnet address
            assign_address = self.master
            prefix = prefixes[0]

        ctrlnet = self.addobj(cls=nodes.CtrlNet, objid=oid, prefix=prefix, 
                              assign_address=assign_address,
                              updown_script=updown_script, serverintf=serverintf)

        # tunnels between controlnets will be built with Broker.addnettunnels()
        self.broker.addnet(oid)
        for server in self.broker.getserverlist():
            self.broker.addnodemap(server, oid)
        
        return ctrlnet
dataset/ETHPy150Open coreemu/core/daemon/core/session.py/Session.addremovectrlnet