Example #1
0
    def test_create_vlan_with_existing_id(self):
        Logger().debug("TestVlan: test_create_vlan_with_existing_id ...")
        # Create VLAN 1
        vlan1 = Vlan('eth0', 'vlan1', 10, '192.168.1.10', 24)
        assert isinstance(vlan1, Vlan)
        vlan1.create_interface("192.168.1.11", 24)

        # Create VLAN 2
        vlan2 = Vlan('eth0', 'vlan2', 10, '192.168.1.10', 24)
        assert isinstance(vlan2, Vlan)
        vlan2.create_interface("192.168.1.11", 24)

        # Test if the VLAN now exists
        process = Popen(["ifconfig", vlan2.vlan_iface_name], stdout=PIPE, stderr=PIPE)
        stdout, sterr = process.communicate()
        assert sterr.decode('utf-8') != ""

        # Remove the VLAN
        vlan2.delete_interface()
        process = Popen(["ifconfig", vlan2.vlan_iface_name], stdout=PIPE, stderr=PIPE)
        stdout, sterr = process.communicate()
        assert stdout.decode('utf-8') == ""

        # Remove the VLAN
        vlan1.delete_interface()
        process = Popen(["ifconfig", vlan1.vlan_iface_name], stdout=PIPE, stderr=PIPE)
        stdout, sterr = process.communicate()
        assert stdout.decode('utf-8') == ""
Example #2
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_vlan_with_existing_name(self):
        Logger().debug("TestVlan: test_create_vlan_with_existing_name ...")
        # Create VLAN 1
        vlan = Vlan('eth0', 'vlan1', 10, '192.168.1.10', 24)
        vlan.create_interface("192.168.1.11", 24)
        assert isinstance(vlan, Vlan)
        # Create VLAN 2
        vlan = Vlan('eth0', 'vlan1', 11, '192.168.1.10', 24)
        vlan.create_interface("192.168.1.11", 24)
        assert isinstance(vlan, Vlan)

        # Test if the VLAN now exists
        process = Popen(["ifconfig", vlan.vlan_iface_name],
                        stdout=PIPE,
                        stderr=PIPE)
        stdout, sterr = process.communicate()
        assert sterr.decode('utf-8') == ""
        assert vlan.vlan_iface_name in stdout.decode('utf-8')

        # Remove the VLAN
        vlan.delete_interface()
        process = Popen(["ifconfig", vlan.vlan_iface_name],
                        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') == ""
    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
Example #7
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
Example #8
0
    def test_create_vlan(self):
        Logger().debug("TestVlan: test_create_vlan ...")
        # Create VLAN
        vlan = Vlan('eth0', 'vlan1', 10, '192.168.1.10', 24)
        vlan.create_interface("192.168.1.11", 24)
        assert isinstance(vlan, Vlan)

        # Test if the VLAN now exists
        process = Popen(["ifconfig", vlan.vlan_iface_name], stdout=PIPE, stderr=PIPE)
        stdout, sterr = process.communicate()
        assert sterr.decode('utf-8') == ""
        assert vlan.vlan_iface_name in stdout.decode('utf-8')

        # Remove the VLAN
        vlan.delete_interface()
        process = Popen(["ifconfig", vlan.vlan_iface_name], stdout=PIPE, stderr=PIPE)
        stdout, sterr = process.communicate()
        assert stdout.decode('utf-8') == ""
Example #9
0
    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 test_create_vlan(self):
        print("Test if a VLAN can be created")
        router = self._create_router()

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

        # Test if the VLAN now exists
        process = Popen(["ip", "link", "show", "dev", vlan.vlan_iface_name], stdout=PIPE, stderr=PIPE)
        stdout, sterr = process.communicate()
        assert sterr.decode('utf-8') == ""
        assert vlan.vlan_iface_name in stdout.decode('utf-8')

        # Remove the VLAN
        vlan.delete_interface(close_ipdb=True)
        process = Popen(["ip", "link", "show", "dev", vlan.vlan_iface_name], stdout=PIPE, stderr=PIPE)
        stdout, sterr = process.communicate()
        assert stdout.decode('utf-8') == ""
Example #11
0
    def test_create_vlan(self):
        print("Test if a VLAN can be created")
        router = self._create_router()

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

        # Test if the VLAN now exists
        process = Popen(["ip", "link", "show", "dev", vlan.vlan_iface_name],
                        stdout=PIPE,
                        stderr=PIPE)
        stdout, sterr = process.communicate()
        assert sterr.decode('utf-8') == ""
        assert vlan.vlan_iface_name in stdout.decode('utf-8')

        # Remove the VLAN
        vlan.delete_interface(close_ipdb=True)
        process = Popen(["ip", "link", "show", "dev", vlan.vlan_iface_name],
                        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') == ""
Example #13
0
    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()
Example #14
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)
Example #15
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)
Example #16
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
Example #17
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