Ejemplo n.º 1
0
Archivo: nodes.py Proyecto: yrs1/core
    def shutdown(self):
        """
        Control network shutdown.

        :return: nothing
        """
        if self.serverintf is not None:
            try:
                utils.check_cmd([
                    constants.BRCTL_BIN, "delif", self.brname, self.serverintf
                ])
            except CoreCommandError:
                logging.exception(
                    "error deleting server interface %s from bridge %s",
                    self.serverintf, self.brname)

        if self.updown_script is not None:
            try:
                logging.info("interface %s updown script (%s shutdown) called",
                             self.brname, self.updown_script)
                utils.check_cmd([self.updown_script, self.brname, "shutdown"])
            except CoreCommandError:
                logging.exception("error issuing shutdown script shutdown")

        LxBrNet.shutdown(self)
Ejemplo n.º 2
0
    def startup(self):
        """
        Startup functionality for the control network.

        :return: nothing
        :raises CoreCommandError: when there is a command exception
        """
        if self.detectoldbridge():
            return

        LxBrNet.startup(self)

        if self.hostid:
            addr = self.prefix.addr(self.hostid)
        else:
            addr = self.prefix.max_addr()

        logger.info("added control network bridge: %s %s", self.brname, self.prefix)

        if self.assign_address:
            addrlist = ["%s/%s" % (addr, self.prefix.prefixlen)]
            self.addrconfig(addrlist=addrlist)
            logger.info("address %s", addr)

        if self.updown_script:
            logger.info("interface %s updown script (%s startup) called", self.brname, self.updown_script)
            utils.check_cmd([self.updown_script, self.brname, "startup"])

        if self.serverintf:
            # sets the interface as a port of the bridge
            utils.check_cmd([constants.BRCTL_BIN, "addif", self.brname, self.serverintf])

            # bring interface up
            utils.check_cmd([constants.IP_BIN, "link", "set", self.serverintf, "up"])
Ejemplo n.º 3
0
Archivo: nodes.py Proyecto: yrs1/core
    def __init__(self,
                 session,
                 objid="ctrlnet",
                 name=None,
                 prefix=None,
                 hostid=None,
                 start=True,
                 assign_address=True,
                 updown_script=None,
                 serverintf=None):
        """
        Creates a CtrlNet instance.

        :param core.session.Session session: core session instance
        :param int objid: node id
        :param str name: node namee
        :param prefix: control network ipv4 prefix
        :param hostid: host id
        :param bool start: start flag
        :param str assign_address: assigned address
        :param str updown_script: updown script
        :param serverintf: server interface
        :return:
        """
        self.prefix = ipaddress.Ipv4Prefix(prefix)
        self.hostid = hostid
        self.assign_address = assign_address
        self.updown_script = updown_script
        self.serverintf = serverintf
        LxBrNet.__init__(self, session, objid=objid, name=name, start=start)
Ejemplo n.º 4
0
    def startup(self):
        """
        Startup functionality for the control network.

        :return: nothing
        """
        if self.detectoldbridge():
            return

        LxBrNet.startup(self)
        if self.hostid:
            addr = self.prefix.addr(self.hostid)
        else:
            addr = self.prefix.max_addr()
        msg = "Added control network bridge: %s %s" % (self.brname, self.prefix)
        addrlist = ["%s/%s" % (addr, self.prefix.prefixlen)]
        if self.assign_address:
            self.addrconfig(addrlist=addrlist)
            msg += " address %s" % addr
        logger.info(msg)
        if self.updown_script is not None:
            logger.info("interface %s updown script (%s startup) called",
                        self.brname, self.updown_script)
            subprocess.check_call([self.updown_script, self.brname, "startup"])
        if self.serverintf is not None:
            try:
                subprocess.check_call([constants.BRCTL_BIN, "addif", self.brname, self.serverintf])
                subprocess.check_call([constants.IP_BIN, "link", "set", self.serverintf, "up"])
            except subprocess.CalledProcessError:
                logger.exception("Error joining server interface %s to controlnet bridge %s",
                                 self.serverintf, self.brname)
Ejemplo n.º 5
0
 def linkconfig(self, netif, bw=None, delay=None, loss=None, duplicate=None, jitter=None, netif2=None):
     """
     Apply tc queing disciplines using LxBrNet.linkconfig()
     """
     # borrow the tc qdisc commands from LxBrNet.linkconfig()
     linux_bridge = LxBrNet(session=self.session, start=False)
     linux_bridge.up = True
     linux_bridge.linkconfig(netif, bw=bw, delay=delay, loss=loss, duplicate=duplicate, jitter=jitter, netif2=netif2)
     del linux_bridge
Ejemplo n.º 6
0
 def linkconfig(self, netif, bw=None, delay=None, loss=None, duplicate=None, jitter=None, netif2=None):
     """
     Apply tc queing disciplines using LxBrNet.linkconfig()
     """
     # borrow the tc qdisc commands from LxBrNet.linkconfig()
     linux_bridge = LxBrNet(session=self.session, start=False)
     linux_bridge.up = True
     linux_bridge.linkconfig(netif, bw=bw, delay=delay, loss=loss, duplicate=duplicate, jitter=jitter, netif2=netif2)
     del linux_bridge
Ejemplo n.º 7
0
    def attach(self, netif):
        """
        Attach a network interface, but limit attachment to two interfaces.

        :param core.coreobj.PyCoreNetIf netif: network interface
        :return: nothing
        """
        if len(self._netif) >= 2:
            raise ValueError("Point-to-point links support at most 2 network interfaces")
        LxBrNet.attach(self, netif)
Ejemplo n.º 8
0
Archivo: nodes.py Proyecto: gsomlo/core
    def attach(self, netif):
        """
        Attach a network interface, but limit attachment to two interfaces.

        :param core.netns.vif.VEth netif: network interface
        :return: nothing
        """
        if len(self._netif) >= 2:
            raise ValueError("Point-to-point links support at most 2 network interfaces")

        LxBrNet.attach(self, netif)
Ejemplo n.º 9
0
    def __init__(self, session, objid=None, name=None, start=True):
        """
        Creates a HubNode instance.

        :param core.session.Session session: core session instance
        :param int objid: node id
        :param str name: node namee
        :param bool start: start flag
        """
        LxBrNet.__init__(self, session, objid, name, start)
        if start:
            subprocess.check_call([constants.BRCTL_BIN, "setageing", self.brname, "0"])
Ejemplo n.º 10
0
    def attach(self, netif):
        """
        Attach a network interface.

        :param core.coreobj.PyCoreNetIf netif: network interface
        :return: nothing
        """
        LxBrNet.attach(self, netif)
        if self.model:
            netif.poshook = self.model.position_callback
            if netif.node is None:
                return
            x, y, z = netif.node.position.get()
            # invokes any netif.poshook
            netif.setposition(x, y, z)
Ejemplo n.º 11
0
    def __init__(self, session, objid=None, name=None, start=True, policy=None):
        """
        Create a WlanNode instance.

        :param core.session.Session session: core session instance
        :param int objid: node id
        :param str name: node name
        :param bool start: start flag
        :param policy: wlan policy
        """
        LxBrNet.__init__(self, session, objid, name, start, policy)
        # wireless model such as basic range
        self.model = None
        # mobility model such as scripted
        self.mobility = None
Ejemplo n.º 12
0
    def __init__(self, session, objid=None, name=None, start=True):
        """
        Creates a HubNode instance.

        :param core.session.Session session: core session instance
        :param int objid: node id
        :param str name: node namee
        :param bool start: start flag
        :raises CoreCommandError: when there is a command exception
        """
        LxBrNet.__init__(self, session, objid, name, start)

        # TODO: move to startup method
        if start:
            utils.check_cmd([constants.BRCTL_BIN, "setageing", self.brname, "0"])
Ejemplo n.º 13
0
Archivo: nodes.py Proyecto: gsomlo/core
    def __init__(self, session, objid=None, name=None, start=True, policy=None):
        """
        Create a WlanNode instance.

        :param core.session.Session session: core session instance
        :param int objid: node id
        :param str name: node name
        :param bool start: start flag
        :param policy: wlan policy
        """
        LxBrNet.__init__(self, session, objid, name, start, policy)
        # wireless model such as basic range
        self.model = None
        # mobility model such as scripted
        self.mobility = None
Ejemplo n.º 14
0
Archivo: nodes.py Proyecto: gsomlo/core
    def attach(self, netif):
        """
        Attach a network interface.

        :param core.netns.vif.VEth netif: network interface
        :return: nothing
        """
        LxBrNet.attach(self, netif)
        if self.model:
            netif.poshook = self.model.position_callback
            if netif.node is None:
                return
            x, y, z = netif.node.position.get()
            # invokes any netif.poshook
            netif.setposition(x, y, z)
Ejemplo n.º 15
0
    def shutdown(self):
        """
        Control network shutdown.

        :return: nothing
        """
        if self.serverintf is not None:
            try:
                subprocess.check_call([constants.BRCTL_BIN, "delif", self.brname, self.serverintf])
            except subprocess.CalledProcessError:
                logger.exception("Error deleting server interface %s to controlnet bridge %s",
                                 self.serverintf, self.brname)

        if self.updown_script is not None:
            logger.info("interface %s updown script (%s shutdown) called" % (self.brname, self.updown_script))
            subprocess.check_call([self.updown_script, self.brname, "shutdown"])
        LxBrNet.shutdown(self)
Ejemplo n.º 16
0
Archivo: nodes.py Proyecto: gsomlo/core
    def shutdown(self):
        """
        Control network shutdown.

        :return: nothing
        """
        if self.serverintf is not None:
            try:
                utils.check_cmd([constants.BRCTL_BIN, "delif", self.brname, self.serverintf])
            except CoreCommandError:
                logger.exception("error deleting server interface %s from bridge %s", self.serverintf, self.brname)

        if self.updown_script is not None:
            try:
                logger.info("interface %s updown script (%s shutdown) called", self.brname, self.updown_script)
                utils.check_cmd([self.updown_script, self.brname, "shutdown"])
            except CoreCommandError:
                logger.exception("error issuing shutdown script shutdown")

        LxBrNet.shutdown(self)
Ejemplo n.º 17
0
    def all_link_data(self, flags):
        """
        Retrieve all link data.

        :param flags: link flags
        :return: all link data
        :rtype: list[LinkData]
        """
        all_links = LxBrNet.all_link_data(self, flags)

        if self.model:
            all_links.extend(self.model.all_link_data(flags))

        return all_links
Ejemplo n.º 18
0
Archivo: nodes.py Proyecto: gsomlo/core
    def all_link_data(self, flags):
        """
        Retrieve all link data.

        :param flags: message flags
        :return: list of link data
        :rtype: list[core.data.LinkData]
        """
        all_links = LxBrNet.all_link_data(self, flags)

        if self.model:
            all_links.extend(self.model.all_link_data(flags))

        return all_links
Ejemplo n.º 19
0
Archivo: nodes.py Proyecto: gsomlo/core
    def __init__(self, session, objid="ctrlnet", name=None, prefix=None,
                 hostid=None, start=True, assign_address=True,
                 updown_script=None, serverintf=None):
        """
        Creates a CtrlNet instance.

        :param core.session.Session session: core session instance
        :param int objid: node id
        :param str name: node namee
        :param prefix: control network ipv4 prefix
        :param hostid: host id
        :param bool start: start flag
        :param str assign_address: assigned address
        :param str updown_script: updown script
        :param serverintf: server interface
        :return:
        """
        self.prefix = ipaddress.Ipv4Prefix(prefix)
        self.hostid = hostid
        self.assign_address = assign_address
        self.updown_script = updown_script
        self.serverintf = serverintf
        LxBrNet.__init__(self, session, objid=objid, name=name, start=start)