def test_from_iterable(self):
        subtree = (1, 3, 6, 1, 2, 1, 1, 1, 0)
        obj = ObjectIdentifier.from_iterable(subtree)
        self.assertEqual(str(obj), '.1.3.6.1.2.1.1.1.0')

        subtree = (1, 2, 3, 4)
        obj = ObjectIdentifier.from_iterable(subtree)
        self.assertEqual(str(obj), '.1.2.3.4')
    def test_oid_zero(self):
        null_oid_ints = (0, 0, 0, 0)
        null_oid_bytes = struct.pack('!BBBB', *null_oid_ints)

        null_oid = ObjectIdentifier.from_bytes(null_oid_bytes, '!')
        self.assertEqual(null_oid.n_subid, 0)
        self.assertEqual(null_oid.prefix_, 0)
        self.assertEqual(null_oid.include, 0)
        self.assertEqual(null_oid.reserved, 0)
        self.assertIs(null_oid.subids, ())
Beispiel #3
0
    def test_getnextpdu_eth3_asic1(self):
        # oid.include = 1
        oid = ObjectIdentifier(12, 0, 1, 0,
                               (1, 0, 8802, 1, 1, 2, 1, 4, 1, 1, 7, 1, 9))
        get_pdu = GetNextPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0,
                                              0),
                             oids=[oid])

        print("GetNextPDU sr=", get_pdu.sr)
        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)
        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.OCTET_STRING)
        print("test_getnextpdu_exactmatch: ", str(oid))
        self.assertEqual(
            str(value0.name),
            str(
                ObjectIdentifier(11, 0, 1, 0,
                                 (1, 0, 8802, 1, 1, 2, 1, 4, 1, 1, 7, 1, 9))))
        self.assertEqual(str(value0.data), "Ethernet3")
Beispiel #4
0
    def test_high_speed(self):
        """
        For a speed higher than 4,294,967,295 the retrun should be 4294967295
        """
        oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 5, 1))
        get_pdu = GetNextPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0,
                                              0),
                             oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.GAUGE_32)
        self.assertEqual(
            str(value0.name),
            str(
                ObjectIdentifier(11, 0, 1, 0,
                                 (1, 3, 6, 1, 2, 1, 2, 2, 1, 5, 5))))
        self.assertEqual(value0.data, 4294967295)
Beispiel #5
0
    def test_mgmt_iface_alias(self):
        """
        Test that mgmt port alias
        """
        oid = ObjectIdentifier(11, 0, 0, 0,
                               (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 1, 10001))
        get_pdu = GetPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
                         oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.OCTET_STRING)
        self.assertEqual(
            str(value0.name),
            str(
                ObjectIdentifier(11, 0, 1, 0,
                                 (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 1, 10001))))
        self.assertEqual(str(value0.data), 'mgmt1')
Beispiel #6
0
    def test_vlan_iface_description(self):
        """
        Test vlan interface description (which is simply the name)
        """
        oid = ObjectIdentifier(11, 0, 0, 0,
                               (1, 3, 6, 1, 2, 1, 2, 2, 1, 2, 3000))
        get_pdu = GetPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
                         oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.OCTET_STRING)
        self.assertEqual(
            str(value0.name),
            str(
                ObjectIdentifier(11, 0, 1, 0,
                                 (1, 3, 6, 1, 2, 1, 2, 2, 1, 2, 3000))))
        self.assertEqual(str(value0.data), 'Vlan1000')
Beispiel #7
0
    def test_mgmt_iface_description_ifMIB(self):
        """
        Test mgmt port description (which is simply an alias) in the ifMIB OID path of the MIB
        """
        oid = ObjectIdentifier(12, 0, 0, 0,
                               (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 10001))
        get_pdu = GetPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
                         oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.OCTET_STRING)
        self.assertEqual(
            str(value0.name),
            str(
                ObjectIdentifier(12, 0, 1, 0,
                                 (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 10001))))
        self.assertEqual(str(value0.data), 'snowflake')
Beispiel #8
0
    def test_getnextpdu_noneifindex(self):
        # oid.include = 1
        oid = ObjectIdentifier(10, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 1))
        get_pdu = GetNextPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0,
                                              0),
                             oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        n = len(response.values)
        # self.assertEqual(n, 7)
        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.INTEGER)
        self.assertEqual(
            str(value0.name),
            str(
                ObjectIdentifier(11, 0, 1, 0,
                                 (1, 3, 6, 1, 2, 1, 2, 2, 1, 1, 1))))
        self.assertEqual(value0.data, 0)
Beispiel #9
0
    def test_mgmt_iface_admin_status(self):
        """
        Test mgmt port admin status
        """
        oid = ObjectIdentifier(11, 0, 0, 0,
                               (1, 3, 6, 1, 2, 1, 2, 2, 1, 7, 10001))
        get_pdu = GetPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
                         oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.INTEGER)
        self.assertEqual(
            str(value0.name),
            str(
                ObjectIdentifier(11, 0, 1, 0,
                                 (1, 3, 6, 1, 2, 1, 2, 2, 1, 7, 10001))))
        self.assertEqual(value0.data, 1)
Beispiel #10
0
    def test_if_type_eth(self):
        """
        For ethernet the type shpuld be 6
        """
        oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 3, 1))
        get_pdu = GetNextPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0,
                                              0),
                             oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.INTEGER)
        self.assertEqual(
            str(value0.name),
            str(
                ObjectIdentifier(11, 0, 1, 0,
                                 (1, 3, 6, 1, 2, 1, 2, 2, 1, 3, 5))))
        self.assertEqual(value0.data, 6)
Beispiel #11
0
    def test_low_speed(self):
        """
        For an interface with a speed inside the 32 bit counter returns the speed of the interface in bps
        """
        oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 5, 9))
        get_pdu = GetNextPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0,
                                              0),
                             oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.GAUGE_32)
        self.assertEqual(
            str(value0.name),
            str(
                ObjectIdentifier(11, 0, 1, 0,
                                 (1, 3, 6, 1, 2, 1, 2, 2, 1, 5, 13))))
        self.assertEqual(value0.data, 1000000000)
Beispiel #12
0
    def test_getnextpdu_empty(self):
        get_pdu = GetNextPDU(
            header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
            oids=(ObjectIdentifier(12, 0, 0, 0,
                                   (1, 3, 6, 1, 2, 1, 4, 24, 4, 1, 1, 255)), ))

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        n = len(response.values)
        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.END_OF_MIB_VIEW)
Beispiel #13
0
    def test_getpdu_internal_noinstance(self):
        get_pdu = GetPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
                         oids=(ObjectIdentifier(
                             20, 0, 0, 0, (1, 3, 6, 1, 2, 1, 4, 24, 4, 1, 1, 0,
                                           0, 0, 0, 0, 10, 10, 0, 5)), ))

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        n = len(response.values)
        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.NO_SUCH_INSTANCE)
    def test_vlan_iface(self):
        """
        Test that vlan interface is present in the MIB
        """
        oid = ObjectIdentifier(11, 0, 0, 0,
                               (1, 3, 6, 1, 2, 1, 2, 2, 1, 1, 2999))
        get_pdu = GetNextPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0,
                                              0),
                             oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.INTEGER)
        self.assertEqual(
            str(value0.name),
            str(
                ObjectIdentifier(11, 0, 1, 0,
                                 (1, 3, 6, 1, 2, 1, 2, 2, 1, 1, 3000))))
        self.assertEqual(value0.data, 2999)
    def test_getnextpdu_local_port_identification(self):
        # oid.include = 1
        oid = ObjectIdentifier(11, 0, 1, 0,
                               (1, 0, 8802, 1, 1, 2, 1, 3, 7, 1, 3))
        get_pdu = GetNextPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0,
                                              0),
                             oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.OCTET_STRING)
        self.assertEqual(str(value0.data), "etp1")
Beispiel #16
0
    def test_high_speed(self):
        """
        should return the speed of the interface
        """
        oid = ObjectIdentifier(12, 0, 0, 0,
                               (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 15, 1))
        get_pdu = GetNextPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0,
                                              0),
                             oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.GAUGE_32)
        self.assertEqual(
            str(value0.name),
            str(
                ObjectIdentifier(12, 0, 1, 0,
                                 (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 15, 5))))
        self.assertEqual(value0.data, 100000)
Beispiel #17
0
    def test_getpdu_noinstance_eth0_docker0(self):
        oid = ObjectIdentifier(
            20, 0, 1, 0, (1, 3, 6, 1, 2, 1, 4, 22, 1, 2, 9, 240, 127, 1, 1))
        get_pdu = GetPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
                         oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        n = len(response.values)
        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.NO_SUCH_INSTANCE)
Beispiel #18
0
    def test_no_speed(self):
        """
        For a port with no speed in the db the result should be 0
        """
        oid = ObjectIdentifier(11, 0, 0, 0,
                               (1, 3, 6, 1, 2, 1, 2, 2, 1, 5, 9004))
        get_pdu = GetNextPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0,
                                              0),
                             oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.GAUGE_32)
        self.assertEqual(
            str(value0.name),
            str(
                ObjectIdentifier(11, 0, 1, 0,
                                 (1, 3, 6, 1, 2, 1, 2, 2, 1, 5, 9008))))
        self.assertEqual(value0.data, 0)
Beispiel #19
0
    def test_getpdu_disappeared(self):
        oid = ObjectIdentifier(
            20, 0, 0, 0, (1, 3, 6, 1, 4, 1, 9, 9, 187, 1, 2, 5, 1, 3, 2, 16,
                          252, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10))
        get_pdu = GetPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
                         oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.NO_SUCH_INSTANCE)
Beispiel #20
0
    def test_getPsu2Status(self):
        oid = ObjectIdentifier(2, 0, 0, 0,
                               (1, 3, 6, 1, 4, 1, 9, 9, 117, 1, 1, 2, 1, 2, 2))
        get_pdu = GetPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
                         oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)

        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.INTEGER)
        self.assertEqual(str(value0.name), str(oid))
        self.assertEqual(value0.data, 2)
    def test_getnextpdu_firstifalias(self):
        # oid.include = 1
        oid = ObjectIdentifier(10, 0, 1, 0,
                               (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18))
        get_pdu = GetNextPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0,
                                              0),
                             oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        n = len(response.values)
        # self.assertEqual(n, 7)
        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.OCTET_STRING)
        self.assertEqual(
            str(value0.name),
            str(
                ObjectIdentifier(11, 0, 1, 0,
                                 (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 1))))
        self.assertEqual(str(value0.data), 'Ethernet0')
Beispiel #22
0
    def test_no_description(self):
        """
        For a port with no description in the db the result should be ian empty string
        """
        oid = ObjectIdentifier(12, 0, 0, 0,
                               (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 113))
        get_pdu = GetNextPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0,
                                              0),
                             oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.OCTET_STRING)
        self.assertEqual(
            str(value0.name),
            str(
                ObjectIdentifier(12, 0, 1, 0,
                                 (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 117))))
        self.assertEqual(str(value0.data), '')
Beispiel #23
0
    def test_getnextpdu(self):
        get_pdu = GetNextPDU(
            header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
            oids=(ObjectIdentifier(
                20, 0, 0, 0, (1, 3, 6, 1, 2, 1, 17, 7, 1, 2, 2, 1, 2, 999)), ))

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        n = len(response.values)
        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.INTEGER)
        self.assertEqual(value0.data, 113)
Beispiel #24
0
    def test_getPduIndicationForPort(self):
        oid = ObjectIdentifier(32, 0, 0, 0,
                               (1, 3, 6, 1, 4, 1, 9, 9, 813, 1, 1, 1, 2, 1))
        get_pdu = GetPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
                         oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut_port)
        print(response)

        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.COUNTER_64)
        self.assertEqual(str(value0.name), str(oid))
        self.assertEqual(value0.data, 4)
    def test_getnextpdu_noeth(self):
        # oid.include = 1
        oid = ObjectIdentifier(
            12, 0, 1, 0, (1, 0, 8802, 1, 1, 2, 1, 4, 1, 1, 7, 18545, 126, 1))
        get_pdu = GetNextPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0,
                                              0),
                             oids=[oid])

        print("GetNextPDU sr=", get_pdu.sr)
        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)
        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.END_OF_MIB_VIEW)
Beispiel #26
0
    def test_getpdu(self):
        oid = ObjectIdentifier(
            20, 0, 0, 0, (1, 3, 6, 1, 2, 1, 4, 22, 1, 2, 37, 10, 0, 0, 19))
        get_pdu = GetPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
                         oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.OCTET_STRING)
        self.assertEqual(str(value0.name), str(oid))
        self.assertEqual(value0.data.string, b'\x52\x54\x00\x04\x52\x5d')
Beispiel #27
0
    def _check_getpdu(self, sub_id, expected_mib):
        oids = [
            ObjectIdentifier(
                12, 0, 1, 0,
                (1, 3, 6, 1, 2, 1, 47, 1, 1, 1, 1, field_sub_id, sub_id))
            for field_sub_id in expected_mib
        ]

        get_pdu = GetNextPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0,
                                              0),
                             oids=oids)

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)

        for mib_key, value in zip(expected_mib, response.values):
            expected_oid = ObjectIdentifier(
                12, 0, 1, 0,
                (1, 3, 6, 1, 2, 1, 47, 1, 1, 1, 1, mib_key, sub_id))
            expected_type, expected_value = expected_mib[mib_key]
            self.assertEqual(str(value.name), str(expected_oid))
            self.assertEqual(value.type_, expected_type)
            self.assertEqual(str(value.data), str(expected_value))
Beispiel #28
0
    def test_getpdu_established_asic2(self):
        oid = ObjectIdentifier(
            20, 0, 0, 0,
            (1, 3, 6, 1, 4, 1, 9, 9, 187, 1, 2, 5, 1, 3, 1, 4, 10, 10, 0, 5))
        get_pdu = GetPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
                         oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.INTEGER)
        self.assertEqual(str(value0.name), str(oid))
        self.assertEqual(value0.data, 6)
Beispiel #29
0
    def test_getnextpdu(self):
        get_pdu = GetNextPDU(
            header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
            oids=(ObjectIdentifier(21, 0, 0, 0,
                                   (1, 3, 6, 1, 2, 1, 4, 24, 4, 1, 1, 0)), ))

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        n = len(response.values)
        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.IP_ADDRESS)
        self.assertEqual(str(value0.data),
                         ipaddress.ip_address("0.0.0.0").packed.decode())
Beispiel #30
0
    def test_getPduRequestForPriority(self):
        oid = ObjectIdentifier(8, 0, 0, 0, (1, 3, 6, 1, 4, 1, 9, 9, 813, 1, 2, 1, 2, 9, 0))
        get_pdu = GetPDU(
            header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
            oids=[oid]
        )

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut_prio)
        print(response)

        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.COUNTER_64)
        self.assertEqual(str(value0.name), str(oid))
        self.assertEqual(value0.data, 209347219842134092490 % pow(2, 64)) # Test integer truncation
Beispiel #31
0
    def test_roundtrip(self):
        open_pdu = OpenPDU(
            header=PDUHeader(1, 1, 16, 0, 0, 0, 0, 0),
            timeout=42,
            oid=ObjectIdentifier(4, 2, 0, 0, (1, 1, 1, 0)),
            descr="HOWDY-HO, NEIGHBOR!"
        )

        encoded = open_pdu.encode()
        decoded = PDU.decode(encoded)

        self.assertEqual(decoded.header.type_, PduTypes.OPEN)
        self.assertIsInstance(open_pdu, OpenPDU)
        self.assertEqual(open_pdu, decoded)
        print(open_pdu)
Beispiel #32
0
    def test_getMulticastQueueCounters(self):
        oid = ObjectIdentifier(
            8, 0, 0, 0,
            (1, 3, 6, 1, 4, 1, 9, 9, 580, 1, 5, 5, 1, 4, 5, 2, 1, 9))
        get_pdu = GetPDU(header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
                         oids=[oid])

        encoded = get_pdu.encode()
        response = get_pdu.make_response(self.lut)
        print(response)

        value0 = response.values[0]
        self.assertEqual(value0.type_, ValueType.NO_SUCH_INSTANCE)
        self.assertEqual(str(value0.name), str(oid))
        self.assertEqual(value0.data, None)
    def test_search_range(self):
        oid_start = ObjectIdentifier(4, 2, 0, 0, (1, 1, 1, 0))
        oid_end = ObjectIdentifier(0, 0, 0, 0, ())
        sr1 = SearchRange(oid_start, oid_end)
        sr2 = SearchRange.from_bytes(oid_start.to_bytes('!') + oid_end.to_bytes('!'), '!')
        self.assertEqual(sr1, sr2)
        self.assertEqual(sr1.size, 24)
        print(sr1)

        oid_start = ObjectIdentifier(4, 2, 0, 0, (1, 1, 1, 0))
        oid_end = ObjectIdentifier(4, 2, 0, 0, (2, 2, 2, 0))
        sr1 = SearchRange(oid_start, oid_end)
        sr2 = SearchRange.from_bytes(oid_start.to_bytes('!') + oid_end.to_bytes('!'), '!')
        self.assertEqual(sr1, sr2)
        self.assertEqual(sr1.size, 40)
        print(sr1)

        self.assertEqual(SearchRange.from_bytes(sr1.to_bytes('!'), '!'), sr1)
    def test_bad_unpack(self):
        with self.assertRaises(struct.error):
            # garbage data. Don't assume '' -> 0, 0, 0...
            ObjectIdentifier.from_bytes(b'', '')

        with self.assertRaises(struct.error):
            # n_subid = 4 -> should be at least 20 bytes -> input is too short.
            ObjectIdentifier.from_bytes(b'\x04\x00\x00\x00', '!')

        with self.assertRaises(struct.error):
            # Bad format specifier.
            ObjectIdentifier.from_bytes(b'\x00\x00\x00\x00', '-')
    def test_oid(self):
        oid1 = ObjectIdentifier(4, 2, 0, 0, (1, 1, 1, 0))
        self.assertEqual(str(oid1), '.1.3.6.1.2.1.1.1.0')
        self.assertEqual(oid1.size, 20)
        print(oid1)
        oid2 = ObjectIdentifier.from_bytes(oid1.to_bytes('!'), '!')  # round-trip
        self.assertEqual(str(oid2), '.1.3.6.1.2.1.1.1.0')
        self.assertEqual(oid2.size, 20)

        oid_literal = ObjectIdentifier(4, 0, 0, 0, (1, 2, 3, 4))
        self.assertEqual(str(oid_literal), '.1.2.3.4')
        print(oid_literal)

        oid_small = ObjectIdentifier(0, 0, 0, 0, ())
        self.assertEqual(oid_small.size, 4)

        dell_oid = ObjectIdentifier(n_subid=7, prefix_=4, include=0, reserved=0, subids=(1, 6027, 3, 10, 1, 2, 9))
        check = ObjectIdentifier.from_bytes(dell_oid.to_bytes('!'), '!')
        self.assertEqual(check, dell_oid)