def test_create_namespace(self):
        router = self._create_router()

        # Create VLAN
        ipdb = IPDB()
        vlan = Vlan(ipdb, router, "eth0")
        assert isinstance(vlan, Vlan)
        vlan.create_interface()

        # Create Namespace
        namespace = Namespace(ipdb, router.namespace_name)
        assert isinstance(namespace, Namespace)

        # encapsulate VLAN
        namespace.encapsulate_interface(vlan.vlan_iface_name)

        # Test if the namespace now exists
        process = Popen(["ip", "netns"], stdout=PIPE, stderr=PIPE)
        stdout, sterr = process.communicate()
        assert sterr.decode('utf-8') == ""
        assert namespace.nsp_name in stdout.decode('utf-8')

        # Remove the Namespace
        vlan.delete_interface(close_ipdb=True)
        namespace.remove()
        ipdb.release()
        process = Popen(["ip", "netns"], stdout=PIPE, stderr=PIPE)
        stdout, sterr = process.communicate()
        assert stdout.decode('utf-8') == ""
    def test_create_namespace(self):
        Logger().debug("TestNamespace: test_create_namespace ...")
        # Create VLAN
        vlan = Vlan('eth0', 'vlan1', 10, '192.168.1.10', 24)
        assert isinstance(vlan, Vlan)
        vlan.create_interface("192.168.1.11", 24)

        # Create Namespace
        namespace = Namespace('nsp1', vlan.ipdb)
        assert isinstance(namespace, Namespace)

        #encapsulate VLAN
        namespace.encapsulate_interface(vlan.vlan_iface_name)

        # Test if the namespace now exists
        process = Popen(["ip", "netns"], stdout=PIPE, stderr=PIPE)
        stdout, sterr = process.communicate()
        assert sterr.decode('utf-8') == ""
        assert namespace.nsp_name in stdout.decode('utf-8')

        # Remove the Namespace
        namespace.remove()
        process = Popen(["ip", "netns"], stdout=PIPE, stderr=PIPE)
        stdout, sterr = process.communicate()
        assert stdout.decode('utf-8') == ""
    def create_namespace_vlan(self, remote_system: RemoteSystem):
        """
        Creats a Namespace and a VLAN. Encapsulate the VLAN inside the Namespace.

        :param remote_system: Router-Obj or Powerstrip-Obj with which we want to connect to.
        """
        if remote_system.namespace_name in self.nsp_dict.keys():
            logging.debug("%s[-] Namespace already exists", LoggerSetup.get_log_deep(2))
            return

        vlan = Vlan(self.ipdb, remote_system, self.link_iface_name)
        vlan.create_interface()
        self.vlan_dict[vlan.vlan_iface_name] = vlan

        namespace = Namespace(self.ipdb, str(remote_system.namespace_name))
        namespace.encapsulate_interface(vlan.vlan_iface_name)
        self.nsp_dict[namespace.nsp_name] = namespace
示例#4
0
    def create_namespace_vlan(self, remote_system: RemoteSystem):
        """
        Creats a Namespace and a VLAN. Encapsulate the VLAN inside the Namespace.

        :param remote_system: Router or powerstrip
        """
        if remote_system.namespace_name in self.nsp_dict.keys():
            logging.debug("%s[-] Namespace already exists", LoggerSetup.get_log_deep(2))
            return

        vlan = Vlan(self.ipdb, remote_system, self.link_iface_name)
        vlan.create_interface()
        self.vlan_dict[vlan.vlan_iface_name] = vlan

        namespace = Namespace(self.ipdb, str(remote_system.namespace_name))
        namespace.encapsulate_interface(vlan.vlan_iface_name)
        self.nsp_dict[namespace.nsp_name] = namespace
示例#5
0
    def test_create_namespace(self):
        Logger().debug("TestNamespace: test_create_namespace ...")
        # Create VLAN
        vlan = Vlan('eth0', 'vlan1', 10, '192.168.1.10', 24)
        assert isinstance(vlan, Vlan)
        vlan.create_interface("192.168.1.11", 24)

        # Create Namespace
        namespace = Namespace('nsp1', vlan.ipdb)
        assert isinstance(namespace, Namespace)

        # encapsulate VLAN
        namespace.encapsulate_interface(vlan.vlan_iface_name)

        # Test if the namespace now exists
        process = Popen(["ip", "netns"], stdout=PIPE, stderr=PIPE)
        stdout, sterr = process.communicate()
        assert sterr.decode('utf-8') == ""
        assert namespace.nsp_name in stdout.decode('utf-8')

        # Remove the Namespace
        namespace.remove()
        process = Popen(["ip", "netns"], stdout=PIPE, stderr=PIPE)
        stdout, sterr = process.communicate()
        assert stdout.decode('utf-8') == ""
    def test_create_namespace(self):
        router = self._create_router()

        # Create VLAN
        ipdb = IPDB()
        vlan = Vlan(ipdb, router, "eth0")
        assert isinstance(vlan, Vlan)
        vlan.create_interface()

        # Create Namespace
        namespace = Namespace(ipdb, router.namespace_name)
        assert isinstance(namespace, Namespace)

        # encapsulate VLAN
        namespace.encapsulate_interface(vlan.vlan_iface_name)

        # Test if the namespace now exists
        process = Popen(["ip", "netns"], stdout=PIPE, stderr=PIPE)
        stdout, sterr = process.communicate()
        assert sterr.decode('utf-8') == ""
        assert namespace.nsp_name in stdout.decode('utf-8')

        # Remove the Namespace
        vlan.delete_interface(close_ipdb=True)
        namespace.remove()
        ipdb.release()
        process = Popen(["ip", "netns"], stdout=PIPE, stderr=PIPE)
        stdout, sterr = process.communicate()
        assert stdout.decode('utf-8') == ""
示例#7
0
    def create_namespace_vlan(self,
                              namespace_name: str,
                              link_iface_name: str,
                              vlan_iface_name: str,
                              vlan_iface_id: int,
                              vlan_iface_ip=None,
                              vlan_iface_ip_mask=None):
        """
        Creats a Namespace and a VLAN. Encapsulate the VLAN inside the Namespace.

        :param namespace_name: Namespace name
        :param link_iface_name: name of the existing interface (eth0, wlan0, ...)
        :param vlan_iface_name: name of the vlan
        :param vlan_iface_id: the id of the vlan
        :param vlan_iface_ip: ip of the virtual interface
        :param vlan_iface_ip_mask: network-mask of the virtual interface
        :return: Namespace object
        """
        self.vlan = Vlan(link_iface_name, vlan_iface_name, vlan_iface_id,
                         vlan_iface_ip, vlan_iface_ip_mask)
        self.vlan.create_interface()
        self.namespace = Namespace(namespace_name, self.vlan.ipdb)
        self.namespace.encapsulate_interface(self.vlan.vlan_iface_name)
示例#8
0
    def create_namespace_vlan(self, namespace_name: str, link_iface_name: str, vlan_iface_name: str, vlan_iface_id: int,
                              vlan_iface_ip=None, vlan_iface_ip_mask=None):
        """
        Creats a Namespace and a VLAN. Encapsulate the VLAN inside the Namespace.

        :param namespace_name: Namespace name
        :param link_iface_name: name of the existing interface (eth0, wlan0, ...)
        :param vlan_iface_name: name of the vlan
        :param vlan_iface_id: the id of the vlan
        :param vlan_iface_ip: ip of the virtual interface
        :param vlan_iface_ip_mask: network-mask of the virtual interface
        :return: Namespace object
        """
        self.vlan = Vlan(link_iface_name, vlan_iface_name, vlan_iface_id, vlan_iface_ip, vlan_iface_ip_mask)
        self.vlan.create_interface()
        self.namespace = Namespace(namespace_name, self.vlan.ipdb)
        self.namespace.encapsulate_interface(self.vlan.vlan_iface_name)
示例#9
0
class NVAssistent:
    """
    1. Creats VLANs
    2. Creats Namespaces and encapsulte a given VLAN
    """
    def __init__(self):
        self._vlan = None
        self._namespace = None

    def create_vlan(self,
                    link_iface_name: str,
                    vlan_iface_name: str,
                    vlan_iface_id: int,
                    vlan_iface_ip=None,
                    vlan_iface_ip_mask=None):
        """
        Creats a VLAN.

        :param link_iface_name: name of the existing interface (eth0, wlan0, ...)
        :param vlan_iface_name: name of the vlan
        :param vlan_iface_id: the id of the vlan
        :param vlan_iface_ip: ip of the virtual interface
        :param vlan_iface_ip_mask: network-mask of the virtual interface
        :return: VLAN object
        """
        self.vlan = Vlan(link_iface_name, vlan_iface_name, vlan_iface_id,
                         vlan_iface_ip, vlan_iface_ip_mask)
        self.vlan.create_interface()

    def create_namespace_vlan(self,
                              namespace_name: str,
                              link_iface_name: str,
                              vlan_iface_name: str,
                              vlan_iface_id: int,
                              vlan_iface_ip=None,
                              vlan_iface_ip_mask=None):
        """
        Creats a Namespace and a VLAN. Encapsulate the VLAN inside the Namespace.

        :param namespace_name: Namespace name
        :param link_iface_name: name of the existing interface (eth0, wlan0, ...)
        :param vlan_iface_name: name of the vlan
        :param vlan_iface_id: the id of the vlan
        :param vlan_iface_ip: ip of the virtual interface
        :param vlan_iface_ip_mask: network-mask of the virtual interface
        :return: Namespace object
        """
        self.vlan = Vlan(link_iface_name, vlan_iface_name, vlan_iface_id,
                         vlan_iface_ip, vlan_iface_ip_mask)
        self.vlan.create_interface()
        self.namespace = Namespace(namespace_name, self.vlan.ipdb)
        self.namespace.encapsulate_interface(self.vlan.vlan_iface_name)

    def delete_vlan(self):
        self.vlan.delete_interface()

    def delete_namespace(self):
        self.namespace.remove()

    @property
    def vlan(self) -> Vlan:
        """
        The VLAN of the RemoteSystem

        :return: Vlan
        """
        return self._vlan

    @vlan.setter
    def vlan(self, value: Vlan):
        """
        :type value: Vlan
        """
        assert isinstance(value, Vlan)
        self._vlan = value

    @property
    def namespace(self) -> Namespace:
        """
        The Namespace of the RemoteSystem

        :return: Vlan
        """
        return self._namespace

    @namespace.setter
    def namespace(self, value: Namespace):
        """
        :type value: Namespace
        """
        assert isinstance(value, Namespace)
        self._namespace = value
示例#10
0
class NVAssistent:
    """
    1. Creats VLANs
    2. Creats Namespaces and encapsulte a given VLAN
    """

    def __init__(self):
        self._vlan = None
        self._namespace = None

    def create_vlan(self, link_iface_name: str, vlan_iface_name: str, vlan_iface_id: int,
                    vlan_iface_ip=None, vlan_iface_ip_mask=None):
        """
        Creats a VLAN.

        :param link_iface_name: name of the existing interface (eth0, wlan0, ...)
        :param vlan_iface_name: name of the vlan
        :param vlan_iface_id: the id of the vlan
        :param vlan_iface_ip: ip of the virtual interface
        :param vlan_iface_ip_mask: network-mask of the virtual interface
        :return: VLAN object
        """
        self.vlan = Vlan(link_iface_name, vlan_iface_name, vlan_iface_id, vlan_iface_ip, vlan_iface_ip_mask)
        self.vlan.create_interface()

    def create_namespace_vlan(self, namespace_name: str, link_iface_name: str, vlan_iface_name: str, vlan_iface_id: int,
                              vlan_iface_ip=None, vlan_iface_ip_mask=None):
        """
        Creats a Namespace and a VLAN. Encapsulate the VLAN inside the Namespace.

        :param namespace_name: Namespace name
        :param link_iface_name: name of the existing interface (eth0, wlan0, ...)
        :param vlan_iface_name: name of the vlan
        :param vlan_iface_id: the id of the vlan
        :param vlan_iface_ip: ip of the virtual interface
        :param vlan_iface_ip_mask: network-mask of the virtual interface
        :return: Namespace object
        """
        self.vlan = Vlan(link_iface_name, vlan_iface_name, vlan_iface_id, vlan_iface_ip, vlan_iface_ip_mask)
        self.vlan.create_interface()
        self.namespace = Namespace(namespace_name, self.vlan.ipdb)
        self.namespace.encapsulate_interface(self.vlan.vlan_iface_name)

    def delete_vlan(self):
        self.vlan.delete_interface()

    def delete_namespace(self):
        self.namespace.remove()

    @property
    def vlan(self) -> Vlan:
        """
        The VLAN of the RemoteSystem

        :return: Vlan
        """
        return self._vlan

    @vlan.setter
    def vlan(self, value: Vlan):
        """
        :type value: Vlan
        """
        assert isinstance(value, Vlan)
        self._vlan = value

    @property
    def namespace(self) -> Namespace:
        """
        The Namespace of the RemoteSystem

        :return: Vlan
        """
        return self._namespace

    @namespace.setter
    def namespace(self, value: Namespace):
        """
        :type value: Namespace
        """
        assert isinstance(value, Namespace)
        self._namespace = value