Ejemplo n.º 1
0
    def test_fast_decode2(self):
        for _ in range(0, X):
            for buf in data_ira:
                rcp_message_id = rcp_tlv_def.RCP_MSG_TYPE_IRA
                rcp_seq = RCPSequence(gcp_msg_def.ManagementREQ,
                                      rcp_message_id, 0,
                                      rcp_tlv_def.RCP_OPERATION_TYPE_NONE)
                rcp_seq.buffer = buf
                parent_fmt = rcp_tlv_def.RCP_SEQ_RCP_MSG_TLV_SET_MAPPING[
                    rcp_message_id]
                parent_gpb = config()
                ret = rcp_seq._fast_decode2(parent_fmt, parent_gpb, 0,
                                            len(buf), 0)
                self.assertEqual(ret, gcp_object.GCPObject.DECODE_DONE)

            for buf in data_rex:
                rcp_message_id = rcp_tlv_def.RCP_MSG_TYPE_REX
                rcp_seq = RCPSequence(gcp_msg_def.ManagementREQ,
                                      rcp_message_id, 0,
                                      rcp_tlv_def.RCP_OPERATION_TYPE_NONE)
                rcp_seq.buffer = buf
                parent_fmt = rcp_tlv_def.RCP_SEQ_RCP_MSG_TLV_SET_MAPPING[
                    rcp_message_id]
                parent_gpb = config()
                ret = rcp_seq._fast_decode2(parent_fmt, parent_gpb, 0,
                                            len(buf), 0)
                self.assertEqual(ret, gcp_object.GCPObject.DECODE_DONE)
Ejemplo n.º 2
0
    def test_value_constraint(self):
        # Same like previous test, but we set TLV with limited range of values

        seq = RCPSequence(gcp_msg_def.NotifyREQ, rcp_tlv_def.RCP_MSG_TYPE_NTF,
                          1, rcp_tlv_def.RCP_OPERATION_TYPE_WRITE)

        # Bool constraint
        with self.assertRaises(ValueError):
            seq.RpdCapabilities.SupportsUdpEncap.set_val(2)

        sub_tlv = \
            seq.RpdCapabilities.LcceChannelReachability.add_new_repeated()

        # Range constraint less than <1,10>
        with self.assertRaises(ValueError):
            sub_tlv.ChannelType.set_val(0)

        # Range constraint greater than <1,10>
        with self.assertRaises(ValueError):
            sub_tlv.ChannelType.set_val(15)

        buf = seq.encode()
        self.assertEqual(len(buf), RCP_SEQUENCE_MIN_LEN)
        self.assertIsNotNone(buf)

        seq.offset = 0
        seq.buf_data_len = 0
        seq.buffer = None

        # Range constraint <1,10> - valid value
        sub_tlv.ChannelType.set_val(10)

        buf = seq.encode()
        dec_seq = RCPSequence(gcp_msg_def.NotifyREQ,
                              rcp_tlv_def.RCP_MSG_TYPE_NTF, 2,
                              rcp_tlv_def.RCP_OPERATION_TYPE_WRITE)
        self.assertEqual(dec_seq.decode(buf, offset=0, buf_data_len=len(buf)),
                         dec_seq.DECODE_DONE)
        self.assertTrue(dec_seq._ut_compare(seq))
Ejemplo n.º 3
0
    def test_fuzzing_fast_decode2(self):
        if ENABLE_FUZZING <= 0:
            return

        class Logger:
            def error(self, *args):
                pass

            def warn(self, *args):
                pass

        for n in [0, 0xFF] + range(
                1, 0xFE):  # run edge cases, then intermediate values
            for ref_data in data_ira + data_rex + data_ntf:
                l = len(ref_data)
                for i in reversed(range(0, l)):
                    buf = ref_data[:]  # copy data
                    buf[i] = n  # mutate

                    # Decode
                    rcp_message_id = rcp_tlv_def.RCP_MSG_TYPE_REX
                    rcp_seq = RCPSequence(gcp_msg_def.ManagementREQ,
                                          rcp_message_id, 0,
                                          rcp_tlv_def.RCP_OPERATION_TYPE_NONE)
                    rcp_seq.buffer = buf
                    rcp_seq.logger = Logger()
                    parent_fmt = rcp_tlv_def.RCP_SEQ_RCP_MSG_TLV_SET_MAPPING[
                        rcp_message_id]
                    parent_gpb = config()
                    #print(n, i)
                    ret = rcp_seq._fast_decode2(parent_fmt, parent_gpb, 0,
                                                len(buf), 0)
                    #if ret is gcp_object.GCPObject.DECODE_FAILED:
                    #   print(n, i)
                    self.assertTrue(ret in [
                        gcp_object.GCPObject.DECODE_DONE,
                        gcp_object.GCPObject.DECODE_FRAGMENTED
                    ])