Exemple #1
0
def ngloadkernelmodule(name):
    """
    Load a kernel module by invoking kldstat. This is needed for the
    ng_ether module which automatically creates Netgraph nodes when loaded.

    :param str name: module name
    :return: nothing
    """
    utils.mutecall(["kldload", name])
Exemple #2
0
    def shutdown(self):
        """
        Bring the interface down. Remove any addresses and queuing
        disciplines.

        :return: nothing
        """
        if not self.up:
            return
        subprocess.check_call([constants.IP_BIN, "link", "set", self.localname, "down"])
        subprocess.check_call([constants.IP_BIN, "addr", "flush", "dev", self.localname])
        utils.mutecall([constants.TC_BIN, "qdisc", "del", "dev", self.localname, "root"])
        self.up = False
        self.restorestate()
Exemple #3
0
    def shutdown(self):
        logger.warn("XEN PVM shutdown() called")
        if not self.up:
            return
        self.lock.acquire()
        try:
            if self.up:
                # sketch from SimpleLxcNode
                for netif in self.netifs():
                    netif.shutdown()

                try:
                    # RJE XXX what to do here
                    if self.booted:
                        utils.mutecheck_call([XM_PATH, "destroy", self.vmname])
                        self.booted = False
                except (OSError, subprocess.CalledProcessError):
                    # ignore this error too, the VM may have exited already
                    logger.exception("error during shutdown")

                # discard LVM volume
                lvm_remove_count = 0
                while os.path.exists(self.lvpath):
                    try:
                        subprocess.check_call([UDEVADM_PATH, "settle"])
                        utils.mutecall([LVCHANGE_PATH, "-an", self.lvpath])
                        lvm_remove_count += 1
                        utils.mutecall([LVREMOVE_PATH, "-f", self.lvpath])
                    except OSError:
                        logger.exception("error during shutdown")

                if lvm_remove_count > 1:
                    logger.warn(
                        "XEN PVM shutdown() required %d lvremove executions.",
                        lvm_remove_count)

                self._netif.clear()
                del self.session

                self.up = False

        finally:
            self.rmnodedir()
            self.lock.release()
Exemple #4
0
    def shutdown(self):
        """
        Linux bridge shutdown logic.

        :return: nothing
        """
        if not self.up:
            return
        ebq.stopupdateloop(self)
        utils.mutecall([constants.IP_BIN, "link", "set", self.brname, "down"])
        utils.mutecall([constants.BRCTL_BIN, "delbr", self.brname])
        ebtablescmds(utils.mutecall, [[
            constants.EBTABLES_BIN, "-D", "FORWARD", "--logical-in",
            self.brname, "-j", self.brname
        ], [constants.EBTABLES_BIN, "-X", self.brname]])
        for netif in self.netifs():
            # removes veth pairs used for bridge-to-bridge connections
            netif.shutdown()
        self._netif.clear()
        self._linked.clear()
        del self.session
        self.up = False
Exemple #5
0
    def shutdown(self):
        if not self.up:
            logger.info("exiting shutdown, object is not up")
            return

        ebtables_queue.stopupdateloop(self)

        utils.mutecall([constants.IP_BIN, "link", "set", self.bridge_name, "down"])
        utils.mutecall([constants.OVS_BIN, "del-br", self.bridge_name])

        ebtables_commands(utils.mutecall, [
            [constants.EBTABLES_BIN, "-D", "FORWARD", "--logical-in", self.bridge_name, "-j", self.bridge_name],
            [constants.EBTABLES_BIN, "-X", self.bridge_name]
        ])

        for interface in self.netifs():
            # removes veth pairs used for bridge-to-bridge connections
            interface.shutdown()

        self._netif.clear()
        self._linked.clear()
        del self.session
        self.up = False
Exemple #6
0
# run iperf to measure the effective throughput between two nodes when
# n nodes are connected to a virtual hub/switch; run test for testsec
# and repeat for minnodes <= n <= maxnodes with a step size of
# nodestep

import datetime
import optparse
import sys

from core.misc import ipaddress, nodeutils, nodemaps
from core.misc.utils import mutecall
from core.netns import nodes
from core.session import Session

try:
    mutecall(["iperf", "-v"])
except OSError:
    sys.stderr.write("ERROR: running iperf failed\n")
    sys.exit(1)


def test(numnodes, testsec):
    # node list
    n = []
    # IP subnet
    prefix = ipaddress.Ipv4Prefix("10.83.0.0/16")
    session = Session(1)
    # emulated network
    net = session.add_object(cls=nodes.SwitchNode)
    for i in xrange(1, numnodes + 1):
        tmp = session.add_object(cls=nodes.LxcNode, name="n%d" % i)
from core.misc.utils import mutecall
from core.netns import nodes

# this is the /etc/core/core.conf default
from core.session import Session

quagga_sbin_search = ("/usr/local/sbin", "/usr/sbin", "/usr/lib/quagga")
quagga_path = "zebra"

# sanity check that zebra is installed
try:
    for p in quagga_sbin_search:
        if os.path.exists(os.path.join(p, "zebra")):
            quagga_path = p
            break
    mutecall(
        [os.path.join(quagga_path, "zebra"), "-u", "root", "-g", "root", "-v"])
except OSError:
    sys.stderr.write("ERROR: running zebra failed\n")
    sys.exit(1)


class ManetNode(nodes.LxcNode):
    """ An Lxc namespace node configured for Quagga OSPFv3 MANET MDR
    """
    conftemp = Template("""\
interface eth0
  ip address $ipaddr
  ipv6 ospf6 instance-id 65
  ipv6 ospf6 hello-interval 2
  ipv6 ospf6 dead-interval 6
  ipv6 ospf6 retransmit-interval 5
Exemple #8
0
    from core import pycore
from core.misc import ipaddr
from core.misc.utils import mutecall
from core.constants import QUAGGA_STATE_DIR

# this is the /etc/core/core.conf default
quagga_sbin_search = ("/usr/local/sbin", "/usr/sbin", "/usr/lib/quagga")
quagga_path = "zebra"

# sanity check that zebra is installed
try:
    for p in quagga_sbin_search:
        if os.path.exists(os.path.join(p, "zebra")):
            quagga_path = p
            break
    mutecall([os.path.join(quagga_path, "zebra"),
             "-u", "root", "-g", "root", "-v"])
except OSError:
    sys.stderr.write("ERROR: running zebra failed\n")
    sys.exit(1)

class ManetNode(pycore.nodes.LxcNode):
    """ An Lxc namespace node configured for Quagga OSPFv3 MANET MDR
    """
    conftemp = Template("""\
interface eth0
  ip address $ipaddr
  ipv6 ospf6 instance-id 65
  ipv6 ospf6 hello-interval 2
  ipv6 ospf6 dead-interval 6
  ipv6 ospf6 retransmit-interval 5
  ipv6 ospf6 network manet-designated-router
Exemple #9
0
    if "/usr/lib/python2.6/site-packages" in sys.path:
        sys.path.append("/usr/local/lib/python2.6/site-packages")
    if "/usr/lib64/python2.6/site-packages" in sys.path:
        sys.path.append("/usr/local/lib64/python2.6/site-packages")
    if "/usr/lib/python2.7/site-packages" in sys.path:
        sys.path.append("/usr/local/lib/python2.7/site-packages")
    if "/usr/lib64/python2.7/site-packages" in sys.path:
        sys.path.append("/usr/local/lib64/python2.7/site-packages")
    from core import pycore
from core.misc import ipaddr
from core.misc.utils import mutecall
from core.constants import QUAGGA_STATE_DIR

# sanity check that zebra is installed
try:
    mutecall(["zebra", "-u", "root", "-g", "root", "-v"])
except OSError:
    sys.stderr.write("ERROR: running zebra failed\n")
    sys.exit(1)

class ManetNode(pycore.nodes.LxcNode):
    """ An Lxc namespace node configured for Quagga OSPFv3 MANET MDR
    """
    conftemp = Template("""\
interface eth0
  ip address $ipaddr
  ipv6 ospf6 instance-id 65
  ipv6 ospf6 hello-interval 2
  ipv6 ospf6 dead-interval 6
  ipv6 ospf6 retransmit-interval 5
  ipv6 ospf6 network manet-designated-router
Exemple #10
0
# Copyright (c)2010-2012 the Boeing Company.
# See the LICENSE file included in this distribution.

# run iperf to measure the effective throughput between two nodes when
# n nodes are connected to a virtual wlan; run test for testsec
# and repeat for minnodes <= n <= maxnodes with a step size of
# nodestep

import optparse, sys, os, datetime

from core import pycore
from core.misc import ipaddr
from core.misc.utils import mutecall

try:
    mutecall(["iperf", "-v"])
except OSError:
    sys.stderr.write("ERROR: running iperf failed\n")
    sys.exit(1)

def test(numnodes, testsec):
    # node list
    n = []
    # IP subnet
    prefix = ipaddr.IPv4Prefix("10.83.0.0/16")
    session = pycore.Session()
    # emulated network
    net = session.addobj(cls = pycore.nodes.WlanNode)
    for i in range(1, numnodes + 1):
        tmp = session.addobj(cls = pycore.nodes.LxcNode, name = "n%d" % i)
        tmp.newnetif(net, ["%s/%s" % (prefix.addr(i), prefix.prefixlen)])
Exemple #11
0
 def localdevexists():
     cmd = (constants.IP_BIN, "link", "show", self.localname)
     return utils.mutecall(cmd)