コード例 #1
0
ファイル: test_rcp.py プロジェクト: hujiangyi/or
    def test_tlv_data_repeated_negative(self):
        seq = RCPSequence(gcp_msg_def.NotifyREQ, rcp_tlv_def.RCP_MSG_TYPE_NTF,
                          1, rcp_tlv_def.RCP_OPERATION_TYPE_WRITE)

        seq.RpdCapabilities.NumBdirPorts.set_val(4)
        seq.RpdCapabilities.AllocDsChanResources.add_new_repeated()
        buf = seq.encode()
        self.assertIsNotNone(buf)

        seq_dec = RCPSequence(gcp_msg_def.NotifyREQ,
                              rcp_tlv_def.RCP_MSG_TYPE_NTF, 2,
                              rcp_tlv_def.RCP_OPERATION_TYPE_WRITE)
        self.assertEqual(seq_dec.decode(buf, offset=0, buf_data_len=len(buf)),
                         seq_dec.DECODE_DONE)
        self.assertFalse(seq._ut_compare(seq_dec))
コード例 #2
0
ファイル: test_rcp.py プロジェクト: hujiangyi/or
    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))