コード例 #1
0
    def test_create_network_interface(self):
        network_interface = NetworkInterface("eth0")
        assert isinstance(network_interface, NetworkInterface)
        self.assertEqual(Status.unknown, network_interface.status)

        network_interface.mac = "d8:31:26:45:56:2f"

        ipv4 = IPv4("192.168.1.1", 24)
        network_interface.ipv4_lst.append(ipv4)

        ipv6 = IPv6("fe80::a11:96ff:fe05:3024", 64)
        network_interface.ipv6_lst.append(ipv6)

        network_interface.status = Status.up

        self.assertEqual("eth0", network_interface.name)
        self.assertEqual("d8:31:26:45:56:2f", network_interface.mac)
        self.assertEqual(Status.up, network_interface.status)
        self.assertEqual(ipv4, network_interface.ipv4_lst[0])
        self.assertEqual(ipv6, network_interface.ipv6_lst[0])

        ipv4 = IPv4("192.168.1.1", 24)
        assert isinstance(ipv4, IPv4)
        self.assertEqual("192.168.1.1", ipv4.ip)
        self.assertEqual(24, ipv4.mask)
コード例 #2
0
    def test_create_network_interface(self):
        network_interface = NetworkInterface(0, "eth0")

        assert isinstance(network_interface, NetworkInterface)

        self.assertEqual(Status.unknown, network_interface.status)

        network_interface.mac = "d8:31:26:45:56:2f"

        network_interface.add_ip_address("192.168.1.1", 24)
        network_interface.add_ip_address("fe80::a11:96ff:fe05:3024", 64)

        network_interface.status = Status.up

        network_interface.wifi_information = self._get_wifi_informations()

        self.assertEqual("eth0", network_interface.name)
        self.assertEqual("d8:31:26:45:56:2f", network_interface.mac)
        self.assertEqual(Status.up, network_interface.status)
        self.assertEqual(ipaddress.ip_interface("192.168.1.1/24"),
                         network_interface.ipaddress_lst[0])
        self.assertEqual(ipaddress.ip_interface("fe80::a11:96ff:fe05:3024/64"),
                         network_interface.ipaddress_lst[1])
        self.assertEqual("0x1", network_interface.wifi_information.wdev)
        self.assertEqual(WlanType.managed,
                         network_interface.wifi_information.type)
        self.assertEqual(1, network_interface.wifi_information.channel)
        self.assertEqual(20, network_interface.wifi_information.channel_width)
        self.assertEqual(2412,
                         network_interface.wifi_information.channel_center1)
コード例 #3
0
    def test_create_network_interface(self):
        network_interface = NetworkInterface(0, "eth0")

        assert isinstance(network_interface, NetworkInterface)

        self.assertEqual(Status.unknown, network_interface.status)

        network_interface.mac = "d8:31:26:45:56:2f"

        network_interface.add_ip_address("192.168.1.1", 24)
        network_interface.add_ip_address("fe80::a11:96ff:fe05:3024", 64)

        network_interface.status = Status.up

        network_interface.wifi_information = self._get_wifi_informations()

        self.assertEqual("eth0", network_interface.name)
        self.assertEqual("d8:31:26:45:56:2f", network_interface.mac)
        self.assertEqual(Status.up, network_interface.status)
        self.assertEqual(ipaddress.ip_interface("192.168.1.1/24"), network_interface.ipaddress_lst[0])
        self.assertEqual(ipaddress.ip_interface("fe80::a11:96ff:fe05:3024/64"), network_interface.ipaddress_lst[1])
        self.assertEqual("0x1", network_interface.wifi_information.wdev)
        self.assertEqual(WlanType.managed, network_interface.wifi_information.type)
        self.assertEqual(1, network_interface.wifi_information.channel)
        self.assertEqual(20, network_interface.wifi_information.channel_width)
        self.assertEqual(2412, network_interface.wifi_information.channel_center1)
コード例 #4
0
    def test_optional_getter_setter(self):
        router = Router(0, "vlan21", 21, "10.223.254.254", 16, "192.168.1.1",
                        24, "root", "root", 1)

        assert isinstance(router, Router)

        router.mode = Mode.configuration
        router.model = "TP-LINK TL-WR841N/ND v9"
        router.mac = "e8:de:27:b7:7c:e2"
        router.node_name = "64293-testframework1"
        router.public_key = "1234567890abcdef16171819"

        network_interface = NetworkInterface(0, "eth0")
        assert isinstance(network_interface, NetworkInterface)
        router.network_interfaces[network_interface.name] = network_interface

        cpu_process = CPUProcess(11, "root", 1.1, 11.2, "echo")
        assert isinstance(cpu_process, CPUProcess)
        router.cpu_processes.append(cpu_process)

        socket = InternetSocket()
        assert isinstance(socket, InternetSocket)
        router.sockets.append(socket)

        ram = RAM(8000, 4000, 4000, 0, 0)
        assert isinstance(ram, RAM)
        router.ram = ram

        flash_driver = Flashdriver(8000, 2000, 6000)
        assert isinstance(flash_driver, Flashdriver)
        router.flashdriver = flash_driver

        router.uci["autoupdater.settings.enabled"] = "1"

        bat_originator = BatOriginator(
            "00:00:00:00:00:00", 12.2, "01:00:01:00:01:00", "mesh0",
            ["01:00:01:00:01:00", "21:00:21:00:21:00", "03:00:03:00:03:00"])
        assert isinstance(bat_originator, BatOriginator)
        router.bat_originators.append(bat_originator)

        self.assertEqual(Mode.configuration, router.mode)
        self.assertEqual("TP-LINK TL-WR841N/ND v9", router.model)
        self.assertEqual("e8:de:27:b7:7c:e2", router.mac)
        self.assertEqual("64293-testframework1", router.node_name)
        self.assertEqual("1234567890abcdef16171819", router.public_key)
        self.assertEqual(network_interface,
                         router.network_interfaces[network_interface.name])
        self.assertEqual(cpu_process, router.cpu_processes.pop())
        self.assertEqual(socket, router.sockets.pop())
        self.assertEqual(ram, router.ram)
        self.assertEqual(flash_driver, router.flashdriver)
        self.assertEqual('Firmware not known', router.firmware.name)
        self.assertEqual("1", router.uci["autoupdater.settings.enabled"])
        self.assertEqual(bat_originator, router.bat_originators.pop())
コード例 #5
0
ファイル: router_info.py プロジェクト: codedust/TestFramework
    def _get_router_network_interfaces(self) -> Dict:
        """
        :return: the network interfaces of the given Router object
        """
        interfaces = dict()
        raw_iface_names = self.network_ctrl.send_command("ip a | grep '^[0-9]*:*:'").split("\\n'")[0:-1]
        iface_names = list()

        # transform a line tmp:
        # '2: enp0s25: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000'
        # into 'enp0s25' and lists it.
        for raw_iface_name in raw_iface_names:
            iface_name = raw_iface_name.split(":")[1].replace(" ", "")
            if "@" in iface_name:
                iface_name = iface_name.split("@")[0]
            if iface_names.count(iface_name) == 0:
                iface_names.append(iface_name)

        for iface_name in iface_names:
            interface = NetworkInterface(iface_name)

            # MAC
            raw_iface_infos = self.network_ctrl.send_command("ip addr show " + iface_name + " | grep 'link/ether'")
            raw_iface_infos = raw_iface_infos.replace("[", "").replace("]", "").replace("'", "")
            if len(raw_iface_infos) > 0:
                raw_mac = raw_iface_infos.split(" ")
                i = raw_mac.count("")
                for i in range(0, i):
                    raw_mac.remove("")
                interface.mac = raw_mac[1]

            # Status
            raw_iface_infos = self.network_ctrl.send_command("ip addr show " + iface_name + " | grep " + iface_name)
            raw_iface_infos = raw_iface_infos.replace("[", "").replace("]", "").replace("'", "")
            raw_status = raw_iface_infos.split("state")
            if len(raw_status) > 1:
                status = raw_status[1].split(" ")[1]
                # Status: UP | DOWN | UNKNOWN
                if status == "UP":
                    interface.status = Status.up
                elif status == "DOWN":
                    interface.status = Status.down
                else:
                    interface.status = Status.unknown

            # IPv4 addresses
            raw_iface_infos = self.network_ctrl.send_command("ip addr show " + iface_name + " | grep 'inet '")
            raw_iface_infos = raw_iface_infos.replace("[", "").replace("]", "").replace("'", "")
            if len(raw_iface_infos) > 0:
                inet_lst = raw_iface_infos.split("\\n")
                for inet in inet_lst:
                    if not ("inet" in inet):
                        continue
                    ip = inet.split("/")[0].split("inet ")[1]
                    ip_mask = int(inet.split("/")[1].split(" ")[0])
                    interface.ipv4_lst.append(IPv4(ip, ip_mask))

            # IPv6 addresses
            raw_iface_infos = self.network_ctrl.send_command("ip addr show " + iface_name + " | grep 'inet6 '")
            raw_iface_infos = raw_iface_infos.replace("[", "").replace("]", "").replace("'", "")
            if len(raw_iface_infos) > 0:
                inet_lst = raw_iface_infos.split("\\n")
                for inet in inet_lst:
                    if not ("inet6" in inet):
                        continue
                    ip = inet.split("/")[0].split("inet6 ")[1]
                    ip_prefix_len = int(inet.split("/")[1].split(" ")[0])
                    interface.ipv6_lst.append(IPv6(ip, ip_prefix_len))
            interfaces[iface_name] = interface
        return interfaces
コード例 #6
0
    def _get_router_network_interfaces(self) -> Dict:
        """
        :return: the network interfaces of the given Router object
        """
        interfaces = dict()
        # Get all network interfaces
        raw_iface_lst = self.network_ctrl.send_command("ip a | grep '^[0-9]*:*:'")
        iface_names_lst = list()
        iface_id_lst = list()

        # Get only the wifi interfaces
        raw_wifi_inface_name_lst = self.network_ctrl.send_command("iw dev | grep Interface")
        wifi_iface_name_lst = list()
        for raw_wifi_iface_name in raw_wifi_inface_name_lst:
            wifi_iface_name_lst.append(raw_wifi_iface_name.split("Interface ")[1].replace("\n", ""))

        # transform a line tmp:
        # '2: enp0s25: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000'
        # into '2'; 'enp0s25' and lists it.
        for raw_iface in raw_iface_lst:
            # Iface Id
            iface_id = int(raw_iface.split(":")[0])
            if iface_id_lst.count(iface_id) == 0:
                iface_id_lst.append(iface_id)

            # Iface Name
            iface_name = raw_iface.split(":")[1].replace(" ", "")
            if "@" in iface_name:
                iface_name = iface_name.split("@")[0]
            if iface_names_lst.count(iface_name) == 0:
                iface_names_lst.append(iface_name)

        # Take the information of the interfaces separately
        for i, iface_id in enumerate(iface_id_lst):
            iface_name = iface_names_lst[i]
            interface = NetworkInterface(iface_id, iface_name)
            raw_iface_info_lst = self.network_ctrl.send_command("ip addr show " + iface_name)
            for raw_iface_info in raw_iface_info_lst:
                # Status
                raw_status = raw_iface_info.split("state")
                if len(raw_status) > 1:
                    status = raw_status[1].split(" ")[1]
                    # Status: UP | DOWN | UNKNOWN
                    if status == "UP":
                        interface.status = Status.up
                    elif status == "DOWN":
                        interface.status = Status.down
                    else:
                        interface.status = Status.unknown

                # MAC
                raw_mac = raw_iface_info.split("link/ether")
                if len(raw_mac) > 1:
                    raw_mac = raw_mac[1].split()
                    interface.mac = raw_mac[0]

                # IP Address
                raw_ip = raw_iface_info.split("inet")
                if len(raw_ip) > 1:
                    raw_ip = raw_ip[1].split(" ")[1].split("/")
                    interface.add_ip_address(raw_ip[0], int(raw_ip[1]))

                # Wifi information
                if wifi_iface_name_lst.count(iface_name) != 0:
                    interface.wifi_information = self.__get_wifi_information(iface_name)
            interfaces[iface_name] = interface
        return interfaces
コード例 #7
0
    def _get_router_network_interfaces(self) -> Dict:
        """
        :return: the network interfaces of the given Router object
        """
        interfaces = dict()
        # Get all network interfaces
        raw_iface_lst = self.network_ctrl.send_command(
            "ip a | grep '^[0-9]*:*:'")
        iface_names_lst = list()
        iface_id_lst = list()

        # Get only the wifi interfaces
        raw_wifi_inface_name_lst = self.network_ctrl.send_command(
            "iw dev | grep Interface")
        wifi_iface_name_lst = list()
        for raw_wifi_iface_name in raw_wifi_inface_name_lst:
            wifi_iface_name_lst.append(
                raw_wifi_iface_name.split("Interface ")[1].replace("\n", ""))

        # transform a line tmp:
        # '2: enp0s25: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000'
        # into '2'; 'enp0s25' and lists it.
        for raw_iface in raw_iface_lst:
            # Iface Id
            iface_id = int(raw_iface.split(":")[0])
            if iface_id_lst.count(iface_id) == 0:
                iface_id_lst.append(iface_id)

            # Iface Name
            iface_name = raw_iface.split(":")[1].replace(" ", "")
            if "@" in iface_name:
                iface_name = iface_name.split("@")[0]
            if iface_names_lst.count(iface_name) == 0:
                iface_names_lst.append(iface_name)

        # Take the information of the interfaces separately
        for i, iface_id in enumerate(iface_id_lst):
            iface_name = iface_names_lst[i]
            interface = NetworkInterface(iface_id, iface_name)
            raw_iface_info_lst = self.network_ctrl.send_command(
                "ip addr show " + iface_name)
            for raw_iface_info in raw_iface_info_lst:
                # Status
                raw_status = raw_iface_info.split("state")
                if len(raw_status) > 1:
                    status = raw_status[1].split(" ")[1]
                    # Status: UP | DOWN | UNKNOWN
                    if status == "UP":
                        interface.status = Status.up
                    elif status == "DOWN":
                        interface.status = Status.down
                    else:
                        interface.status = Status.unknown

                # MAC
                raw_mac = raw_iface_info.split("link/ether")
                if len(raw_mac) > 1:
                    raw_mac = raw_mac[1].split()
                    interface.mac = raw_mac[0]

                # IP Address
                raw_ip = raw_iface_info.split("inet")
                if len(raw_ip) > 1:
                    raw_ip = raw_ip[1].split(" ")[1].split("/")
                    interface.add_ip_address(raw_ip[0], int(raw_ip[1]))

                # Wifi information
                if wifi_iface_name_lst.count(iface_name) != 0:
                    interface.wifi_information = self.__get_wifi_information(
                        iface_name)
            interfaces[iface_name] = interface
        return interfaces