Exemple #1
0
    def test_tlv_data(self):
        print "Test test_tlv_data...."
        seq = RCPSequence(gcp_msg_def.NotifyREQ, rcp_tlv_def.RCP_MSG_TYPE_NTF,
                          1234, rcp_tlv_def.RCP_OPERATION_TYPE_WRITE)
        print "Test test_tlv_data...."
        seq.RpdCapabilities.NumBdirPorts.set_val(4)
        alloc_ds =\
            seq.RpdCapabilities.AllocDsChanResources.add_new_repeated()
        alloc_ds.DsPortIndex.set_val(1)
        alloc_ds.AllocatedDsOfdmChannels.set_val(11)
        alloc_ds.AllocatedDsScQamChannels.set_val(111)

        alloc_ds = \
            seq.RpdCapabilities.AllocDsChanResources.add_new_repeated()
        alloc_ds.DsPortIndex.set_val(2)
        alloc_ds.AllocatedDsOfdmChannels.set_val(22)
        alloc_ds.AllocatedDsScQamChannels.set_val(222)

        alloc_ds = \
            seq.RpdCapabilities.AllocDsChanResources.add_new_repeated()
        alloc_ds.DsPortIndex.set_val(3)
        alloc_ds.AllocatedDsOfdmChannels.set_val(33)
        alloc_ds.AllocatedDsScQamChannels.set_val(333)

        buf = seq.encode()
        self.assertIsNotNone(buf)

        seq_dec = RCPSequence(gcp_msg_def.NotifyREQ,
                              rcp_tlv_def.RCP_MSG_TYPE_NTF, 11,
                              rcp_tlv_def.RCP_OPERATION_TYPE_WRITE)
        self.assertEqual(seq_dec.decode(buf, offset=0, buf_data_len=len(buf)),
                         seq_dec.DECODE_DONE)
Exemple #2
0
    def test_tlv_len_mismatch(self):
        seq = "0900570a000200020b000105130001003c004701000100020004313233340300" \
            + "10262000002b107ffe00000000000000020400010105000843434150434f524506000" \
            + "2118b0700010108000100090001000a000200000b000100"

        seq_buf = binascii.a2b_hex(seq)
        print repr(seq_buf)
        decoder = RCPSequence(gcp_msg_def.DataStructRSP,
                              rcp_tlv_def.RCP_MSG_TYPE_REX, 1,
                              rcp_tlv_def.RCP_OPERATION_TYPE_WRITE_RESPONSE)

        decoder.decode(seq_buf, offset=0, buf_data_len=len(seq_buf))
        # change vendor id to 1 byte
        decoder = RCPSequence(gcp_msg_def.DataStructRSP,
                              rcp_tlv_def.RCP_MSG_TYPE_REX, 1,
                              rcp_tlv_def.RCP_OPERATION_TYPE_WRITE_RESPONSE)
        seq = "0900560a000200020b000105130001003c004601000100020004313233340300102620" \
            + "00002b107ffe00000000000000020400010105000843434150434f52450600018b070001010" \
            + "8000100090001000a000200000b000100"
        seq_buf = binascii.a2b_hex(seq)
        decoder.decode(seq_buf, offset=0, buf_data_len=len(seq_buf))

        # change vendor id to 3 byte
        decoder = RCPSequence(gcp_msg_def.DataStructRSP,
                              rcp_tlv_def.RCP_MSG_TYPE_REX, 1,
                              rcp_tlv_def.RCP_OPERATION_TYPE_WRITE_RESPONSE)

        seq = "0900570a000200020b000105130001003c00470100010002000431323334030010262000002b" \
            + "107ffe00000000000000020400010105000843434150434f524506000311118b0700010108000100" \
            + "090001000a000200000b000100"
        seq_buf = binascii.a2b_hex(seq)
        decoder.decode(seq_buf, offset=0, buf_data_len=len(seq_buf))
Exemple #3
0
    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))
Exemple #4
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))