def construct_eds_pkt_RpdGlobal(): seq = RCPSequence(gcp_msg_def.DataStructREQ, rcp_tlv_def.RCP_MSG_TYPE_IRA, 0xffff, rcp_tlv_def.RCP_OPERATION_TYPE_READ) # Set RCP sequence ctrl = seq.parent_gpb.RpdGlobal.EvCfg.EvControl.add() ctrl.EvPriority = 1 ctrl.EvReporting = 1 rcp_msg = RCPMessage(gcp_msg_def.DataStructREQ, rcp_tlv_def.RCP_MSG_TYPE_IRA) rcp_msg.sequences.append(seq) gcp_msg = Message(gcp_msg_def.DataStructREQ) # TODO implement correct setting of message fields transaction_id = 0xffff gcp_msg.msg_fields.TransactionID.set_val(transaction_id) gcp_msg.msg_fields.Mode.set_val(0) gcp_msg.msg_fields.Port.set_val(11) gcp_msg.msg_fields.Channel.set_val(111) gcp_msg.msg_fields.VendorID.set_val(1111) gcp_msg.msg_fields.VendorIndex.set_val(254) gcp_msg.tlv_data.rcp_msgs.append(rcp_msg) pkt = RCPPacket() pkt.transaction_identifier = transaction_id pkt.protocol_identifier = RCP_PROTOCOL_ID pkt.unit_id = 0 pkt.msgs.append(gcp_msg) return [pkt, gcp_msg]
def construct_eds_pkt_ActivePrincipalCore(): seq = RCPSequence(gcp_msg_def.DataStructREQ, rcp_tlv_def.RCP_MSG_TYPE_IRA, 0xffff, rcp_tlv_def.RCP_OPERATION_TYPE_READ) seq.parent_gpb.ActivePrincipalCore = '1.1.1.1' rcp_msg = RCPMessage(gcp_msg_def.DataStructREQ, rcp_tlv_def.RCP_MSG_TYPE_IRA) rcp_msg.sequences.append(seq) gcp_msg = Message(gcp_msg_def.DataStructREQ) # TODO implement correct setting of message fields transaction_id = 0xffff gcp_msg.msg_fields.TransactionID.set_val(transaction_id) gcp_msg.msg_fields.Mode.set_val(0) gcp_msg.msg_fields.Port.set_val(11) gcp_msg.msg_fields.Channel.set_val(111) gcp_msg.msg_fields.VendorID.set_val(1111) gcp_msg.msg_fields.VendorIndex.set_val(254) gcp_msg.tlv_data.rcp_msgs.append(rcp_msg) pkt = RCPPacket() pkt.transaction_identifier = transaction_id pkt.protocol_identifier = RCP_PROTOCOL_ID pkt.unit_id = 0 pkt.msgs.append(gcp_msg) return [pkt, gcp_msg]
def test_msg_with_tlvs_of_all_classes_only_subTLV(self): seq = RCPSequence(gcp_msg_def.NotifyError, rcp_tlv_def.RCP_MSG_TYPE_NTF, 0, rcp_tlv_def.RCP_OPERATION_TYPE_WRITE, unittest=True) seq.RpdCapabilities.RpdIdentification.VendorName.set_val('ABC') msg = Message(gcp_msg_def.NotifyError) rcp_msg = RCPMessage(gcp_msg_def.NotifyError, rcp_tlv_def.RCP_MSG_TYPE_NTF) msg.tlv_data.rcp_msgs.append(rcp_msg) rcp_msg.sequences.append(seq) msg.msg_fields.TransactionID.set_val(5) msg.msg_fields.ReturnCode.set_val( gcp_msg_def.GCP_RC_MESSAGE_FAILURE.rc) buf = msg.encode() self.assertIsNotNone(buf) buf_str = binascii.hexlify(buf) # C_RpdCapabilities_2 C2_RpdIdentification_19 vendor_name_pattern = "010003414243" self.assertNotEqual(buf_str.find(vendor_name_pattern), -1)
def test_msg_with_op_aw(self): print "test_msg_with_aw_tlv" # Encode message with mandatory fields, decode buffer and compare objs msg = Message(gcp_msg_def.NotifyREQ) msg.msg_fields.TransactionID.set_val(5) msg.msg_fields.EventCode.set_val(1) msg.msg_fields.Mode.set_val(0b10000000) msg.msg_fields.Status.set_val(2) seq = self.vsp_tlv_seq.create_vendor_tlvs_sequence( gcp_msg_def.NotifyREQ, rcp_tlv_def.RCP_MSG_TYPE_IRA, rcp_tlv_def.RCP_OPERATION_TYPE_ALLOCATE_WRITE) rcp_msg = RCPMessage(gcp_msg_def.NotifyREQ, rcp_tlv_def.RCP_MSG_TYPE_NTF) msg.tlv_data.rcp_msgs.append(rcp_msg) rcp_msg.sequences.append(seq) buf = msg.encode() self.assertIsNotNone(buf) msg_dec = Message(gcp_msg_def.NotifyREQ) self.assertEqual(msg_dec.decode(buf, offset=0, buf_data_len=len(buf)), msg_dec.DECODE_DONE)
def construct_eds_pkt_CcapCoreIdentification_AW(inital=CORE_STATE_INIT): seq = None # Set RCP sequence if inital == TestOrchestrator.CORE_STATE_INIT: seq = RCPSequence(gcp_msg_def.DataStructREQ, rcp_tlv_def.RCP_MSG_TYPE_IRA, 0xffff, rcp_tlv_def.RCP_OPERATION_TYPE_ALLOCATE_WRITE) ccap = seq.parent_gpb.CcapCoreIdentification.add() ccap.Index = 0 ccap.IsPrincipal = True ccap.CoreMode = 1 ccap.CoreId = 'CoreId' ccap.CoreIpAddress = '1.1.1.1' ccap.CoreName = 'CoreName' ccap.VendorId = 12 elif inital == TestOrchestrator.CORE_STATE_CFG_COMPLETE: seq = RCPSequence(gcp_msg_def.DataStructREQ, rcp_tlv_def.RCP_MSG_TYPE_IRA, 0xffff, rcp_tlv_def.RCP_OPERATION_TYPE_WRITE) ccap = seq.parent_gpb.CcapCoreIdentification.add() ccap.Index = 1 ccap.InitialConfigurationComplete = True elif inital == TestOrchestrator.CORE_STATE_MOVE_TO_OPTIONAL: seq = RCPSequence(gcp_msg_def.DataStructREQ, rcp_tlv_def.RCP_MSG_TYPE_IRA, 0xffff, rcp_tlv_def.RCP_OPERATION_TYPE_WRITE) ccap = seq.parent_gpb.CcapCoreIdentification.add() ccap.Index = 1 ccap.MoveToOperational = True else: return rcp_msg = RCPMessage(gcp_msg_def.DataStructREQ, rcp_tlv_def.RCP_MSG_TYPE_IRA) rcp_msg.sequences.append(seq) gcp_msg = Message(gcp_msg_def.DataStructREQ) # TODO implement correct setting of message fields transaction_id = 0xffff gcp_msg.msg_fields.TransactionID.set_val(transaction_id) gcp_msg.msg_fields.Mode.set_val(0) gcp_msg.msg_fields.Port.set_val(11) gcp_msg.msg_fields.Channel.set_val(111) gcp_msg.msg_fields.VendorID.set_val(1111) gcp_msg.msg_fields.VendorIndex.set_val(254) gcp_msg.tlv_data.rcp_msgs.append(rcp_msg) pkt = RCPPacket() pkt.transaction_identifier = transaction_id pkt.protocol_identifier = RCP_PROTOCOL_ID pkt.unit_id = 0 pkt.msgs.append(gcp_msg) return [pkt, gcp_msg]
def test_msg_with_tlvs_of_multi_core(self): # Encode message with mandatory fields, decode buffer and compare objs msg = Message(gcp_msg_def.DataStructError) msg.msg_fields.TransactionID.set_val(5) msg.msg_fields.ExceptionCode.set_val( gcp_msg_def.GCP_RC_MESSAGE_FAILURE.rc) seq = RCPSequence(gcp_msg_def.DataStructError, rcp_tlv_def.RCP_MSG_TYPE_REX, 0, rcp_tlv_def.RCP_OPERATION_TYPE_WRITE, unittest=True) rcp_msg = RCPMessage(gcp_msg_def.DataStructError, rcp_tlv_def.RCP_MSG_TYPE_REX) msg.tlv_data.rcp_msgs.append(rcp_msg) rcp_msg.sequences.append(seq) resSet = seq.MultiCore.ResourceSet.add_new_repeated() resSet.ResourceSetIndex.set_val(1) resSet.CcapCoreOwner.set_val( utils.Convert.mac_to_tuple_of_bytes("00:00:00:00:00:00")) resSet.DsRfPortStart.set_val(0) resSet.DsRfPortEnd.set_val(0) dsChanGroup = resSet.DsChanGroup.add_new_repeated() dsChanGroup.DsChanGroupIndex.set_val(1) dsChanGroup.DsChanType.set_val(3) dsChanGroup.DsChanIndexStart.set_val(0) dsChanGroup.DsChanIndexEnd.set_val(10) dsChanGroup = resSet.DsChanGroup.add_new_repeated() dsChanGroup.DsChanGroupIndex.set_val(2) dsChanGroup.DsChanType.set_val(4) dsChanGroup.DsChanIndexStart.set_val(11) dsChanGroup.DsChanIndexEnd.set_val(12) resSet.UsRfPortStart.set_val(0) resSet.UsRfPortEnd.set_val(1) usChanGroup = resSet.UsChanGroup.add_new_repeated() usChanGroup.UsChanGroupIndex.set_val(0) usChanGroup.UsChanType.set_val(5) usChanGroup.UsChanIndexStart.set_val(0) usChanGroup.UsChanIndexEnd.set_val(2) usChanGroup = resSet.UsChanGroup.add_new_repeated() usChanGroup.UsChanGroupIndex.set_val(1) usChanGroup.UsChanType.set_val(6) usChanGroup.UsChanIndexStart.set_val(3) usChanGroup.UsChanIndexEnd.set_val(4) buf = msg.encode() self.assertNotEqual(buf, None) msg_dec = Message(gcp_msg_def.DataStructError) self.assertEqual(msg_dec.decode(buf, offset=0, buf_data_len=len(buf)), msg_dec.DECODE_DONE)
def test_rcp_message(self): msg = Message(gcp_msg_def.DataStructREQ) msg.msg_fields.TransactionID.set_val(5) msg.msg_fields.Mode.set_val(0) msg.msg_fields.Port.set_val(11) msg.msg_fields.Channel.set_val(111) msg.msg_fields.VendorID.set_val(1111) msg.msg_fields.VendorIndex.set_val(254) # rcp_msg rcp_msg = RCPMessage(msg.message_id, rcp_tlv_def.RCP_MSG_TYPE_REX) msg.tlv_data.rcp_msgs.append(rcp_msg)
def test_msg_with_unexpected_tlvs(self): # Encode message with mandatory fields, decode buffer and compare objs msg = Message(gcp_msg_def.NotifyREQ) seq = RCPSequence(gcp_msg_def.NotifyREQ, rcp_tlv_def.RCP_MSG_TYPE_NTF, 123, rcp_tlv_def.RCP_OPERATION_TYPE_WRITE) rcp_msg = RCPMessage(gcp_msg_def.NotifyREQ, rcp_tlv_def.RCP_MSG_TYPE_NTF) msg.tlv_data.rcp_msgs.append(rcp_msg) rcp_msg.sequences.append(seq) # Try to fill TLV, which is not expected with self.assertRaises(AttributeError): seq.CcapCoreIdentification.Index.set_val(6)
def test_rcp_message_in_gcp_msg(self): msg = Message(gcp_msg_def.DataStructREQ) msg.msg_fields.TransactionID.set_val(5) msg.msg_fields.Mode.set_val(0) msg.msg_fields.Port.set_val(11) msg.msg_fields.Channel.set_val(111) msg.msg_fields.VendorID.set_val(1111) msg.msg_fields.VendorIndex.set_val(254) rcp_msg = RCPMessage(msg.message_id, rcp_tlv_def.RCP_MSG_TYPE_REX) msg.tlv_data.rcp_msgs.append(rcp_msg) seq = self.create_testing_cfg_sequence(msg.message_id, rcp_msg.rcp_message_id) rcp_msg.sequences.append(seq) buf_enc = msg.encode() msg_dec = Message() msg_dec.decode(buf_enc, 0, len(buf_enc))
def test_msg_with_tlvs_of_all_classes_find_TVL(self): seq = RCPSequence(gcp_msg_def.NotifyError, rcp_tlv_def.RCP_MSG_TYPE_NTF, 0, rcp_tlv_def.RCP_OPERATION_TYPE_WRITE) seq.RpdCapabilities.RpdIdentification.VendorName.set_val('ABC') msg = Message(gcp_msg_def.NotifyError) rcp_msg = RCPMessage(gcp_msg_def.NotifyError, rcp_tlv_def.RCP_MSG_TYPE_NTF) msg.tlv_data.rcp_msgs.append(rcp_msg) rcp_msg.sequences.append(seq) msg.msg_fields.TransactionID.set_val(10) msg.msg_fields.ReturnCode.set_val( gcp_msg_def.GCP_RC_MESSAGE_FAILURE.rc) seq.RpdCapabilities.NumBdirPorts.set_val(11) seq.RpdCapabilities.RpdIdentification.VendorName.set_val('ABC') seq.RpdCapabilities.RpdIdentification.DeviceMacAddress.set_val( (0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56)) sub_tlv = seq.CcapCoreIdentification.add_new_repeated() sub_tlv.Index.set_val(0x34) sub_tlv.CoreIpAddress.set_val( (0xA1, 0xA2, 0xA3, 0xA4, 0xB1, 0xB2, 0xB3, 0xB4, 0xC1, 0xC2, 0xC3, 0xC4, 0xD1, 0xD2, 0xD3, 0xD4)) buf3 = msg.encode() self.assertIsNotNone(buf3) buf3_str = binascii.hexlify(buf3) num_bidir_ports_pattern = "010002000b" vendor_name_pattern = "010003414243" device_mac_address_pattern = "040006abcdef123456" index_pattern = "01000134" core_ip_address_pattern = "030010a1a2a3a4b1b2b3b4c1c2c3c4d1d2d3d4" self.assertNotEqual(buf3_str.find(num_bidir_ports_pattern), -1) self.assertNotEqual(buf3_str.find(vendor_name_pattern), -1) self.assertNotEqual(buf3_str.find(device_mac_address_pattern), -1) self.assertNotEqual(buf3_str.find(index_pattern), -1) self.assertNotEqual(buf3_str.find(core_ip_address_pattern), -1)
def test_msg_with_tlv(self): # Encode message with mandatory fields, decode buffer and compare objs msg = Message(gcp_msg_def.NotifyREQ) msg.msg_fields.TransactionID.set_val(5) msg.msg_fields.EventCode.set_val(1) msg.msg_fields.Mode.set_val(0b10000000) msg.msg_fields.Status.set_val(2) seq = RCPSequence(gcp_msg_def.NotifyREQ, rcp_tlv_def.RCP_MSG_TYPE_NTF, 0, rcp_tlv_def.RCP_OPERATION_TYPE_WRITE) rcp_msg = RCPMessage(gcp_msg_def.NotifyREQ, rcp_tlv_def.RCP_MSG_TYPE_NTF) msg.tlv_data.rcp_msgs.append(rcp_msg) rcp_msg.sequences.append(seq) seq.RpdCapabilities.NumBdirPorts.set_val(1) buf = msg.encode() self.assertIsNotNone(buf) msg_dec = Message(gcp_msg_def.NotifyREQ) self.assertEqual(msg_dec.decode(buf, offset=0, buf_data_len=len(buf)), msg_dec.DECODE_DONE)
def construct_eds_pkt_CcapCoreIdentification( need_info=False, op=rcp_tlv_def.RCP_OPERATION_TYPE_READ): seq = RCPSequence(gcp_msg_def.DataStructREQ, rcp_tlv_def.RCP_MSG_TYPE_IRA, 0xffff, op) # Set RCP sequence ccap = seq.parent_gpb.CcapCoreIdentification.add() ccap.Index = 1 if need_info: ccap.IsPrincipal = True ccap.CoreMode = 1 ccap.CoreId = 'CoreId' ccap.CoreIpAddress = '1.1.1.1' ccap.CoreName = 'CoreName' ccap.VendorId = 12 rcp_msg = RCPMessage(gcp_msg_def.DataStructREQ, rcp_tlv_def.RCP_MSG_TYPE_IRA) rcp_msg.sequences.append(seq) gcp_msg = Message(gcp_msg_def.DataStructREQ) # TODO implement correct setting of message fields transaction_id = 0xffff gcp_msg.msg_fields.TransactionID.set_val(transaction_id) gcp_msg.msg_fields.Mode.set_val(0) gcp_msg.msg_fields.Port.set_val(11) gcp_msg.msg_fields.Channel.set_val(111) gcp_msg.msg_fields.VendorID.set_val(1111) gcp_msg.msg_fields.VendorIndex.set_val(254) gcp_msg.tlv_data.rcp_msgs.append(rcp_msg) pkt = RCPPacket() pkt.transaction_identifier = transaction_id pkt.protocol_identifier = RCP_PROTOCOL_ID pkt.unit_id = 0 pkt.msgs.append(gcp_msg) return [pkt, gcp_msg]
def test_msg_with_tlvs_of_all_classes(self): # Encode message with mandatory fields, decode buffer and compare objs msg = Message(gcp_msg_def.DataStructError) msg.msg_fields.TransactionID.set_val(5) msg.msg_fields.ExceptionCode.set_val( gcp_msg_def.GCP_RC_MESSAGE_FAILURE.rc) seq = RCPSequence(gcp_msg_def.DataStructError, rcp_tlv_def.RCP_MSG_TYPE_REX, 0, rcp_tlv_def.RCP_OPERATION_TYPE_WRITE, unittest=True) rcp_msg = RCPMessage(gcp_msg_def.DataStructError, rcp_tlv_def.RCP_MSG_TYPE_REX) msg.tlv_data.rcp_msgs.append(rcp_msg) rcp_msg.sequences.append(seq) seq.RpdCapabilities.RpdIdentification.VendorName.set_val('ABC') seq.RpdCapabilities.NumBdirPorts.set_val(1) # TODO this can be uncommented when conflicting numbering is solved # seq.RpdCapabilities.NumAsyncVideoChannels.set_val(2) seq.RpdCapabilities.RpdIdentification.VendorName.set_val('31') seq.RpdCapabilities.RpdIdentification.VendorId.set_val(9) seq.RpdCapabilities.RpdIdentification.DeviceMacAddress.set_val( (0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56)) seq.RpdCapabilities.RpdIdentification.SerialNumber.set_val('33') sub_tlv =\ seq.RpdCapabilities.LcceChannelReachability.add_new_repeated() sub_tlv.EnetPortIndex.set_val(4) sub_tlv.EndChannelIndex.set_val(5) seq.RpdCapabilities.PilotToneCapabilities.NumCwToneGens.set_val(6) seq.RpdCapabilities.PilotToneCapabilities.QamAsPilot.set_val(1) sub_tlv = seq.RpdCapabilities.AllocDsChanResources.add_new_repeated() sub_tlv.DsPortIndex.set_val(8) sub_tlv.AllocatedNdfChannels.set_val(9) sub_tlv = seq.RpdCapabilities.AllocUsChanResources.add_new_repeated() sub_tlv.UsPortIndex.set_val(10) sub_tlv.AllocatedNdrChannels.set_val(11) sub_tlv = seq.CcapCoreIdentification.add_new_repeated() sub_tlv.Index.set_val(12) sub_tlv.CoreIpAddress.set_val((0x01, 0x02, 0x03, 0x04)) sub_tlv.VendorId.set_val(13) sub_tlv = seq.RfPort.add_new_repeated() sub_tlv.RfPortSelector.RfPortIndex.set_val(0) # sub_tlv.DsRfPort.PortIndex.set_val(14) sub_tlv.DsRfPort.TiltMaximumFrequency.set_val(15) sub_tlv = seq.RfChannel.add_new_repeated() sub_tlv.RfChannelSelector.RfChannelIndex.set_val(0) sub_tlv.DsScQamChannelConfig.AdminState.set_val(1) sub_tlv.DsScQamChannelConfig.PowerAdjust.set_val(17) sub_tlv.DsOfdmChannelConfig.AdminState.set_val(2) sub_tlv.DsOfdmChannelConfig.SubcarrierSpacing.set_val(1) sub_tlv2 = sub_tlv.DsOfdmChannelConfig.DsOfdmSubcarrierType.add_new_repeated( ) sub_tlv2.StartSubcarrierId.set_val(21) sub_tlv2.EndSubcarrierId.set_val(22) sub_tlv2.SubcarrierUsage.set_val(1) sub_tlv2 = sub_tlv.DsOfdmProfile sub_tlv2.ProfileId.set_val(15) # sub_tlv3 = sub_tlv2.DsOfdmSubcarrierModulation.add_new_repeated() # sub_tlv3.StartSubcarrierId.set_val(21) # sub_tlv3.EndSubcarrierId.set_val(22) # sub_tlv3.Modulation.set_val(1) sub_tlv.UsScQamChannelConfig.AdminState.set_val(3) sub_tlv.UsScQamChannelConfig.TargetRxPower.set_val(24) sub_tlv2 = sub_tlv.UsScQamChannelConfig.IntervalUsageCode.\ add_new_repeated() sub_tlv2.Code.set_val(14) sub_tlv2.GuardTime.set_val(26) sub_tlv.UsOfdmaChannelConfig.AdminState.set_val(4) sub_tlv.UsOfdmaChannelConfig.TargetRxPowerAdjust.set_val(28) sub_tlv.UsOfdmaInitialRangingIuc.NumSubcarriers.set_val(10) sub_tlv.UsOfdmaInitialRangingIuc.Guardband.set_val(10) sub_tlv.UsOfdmaFineRangingIuc.NumSubcarriers.set_val(14) sub_tlv.UsOfdmaFineRangingIuc.Guardband.set_val(10) sub_tlv2 = sub_tlv.UsOfdmaDataIuc.add_new_repeated() sub_tlv2.DataIuc.set_val(5) sub_tlv2.DataSymbolModulation.set_val(1) sub_tlv2 = sub_tlv.UsOfdmaSubcarrierCfgState.add_new_repeated() sub_tlv2.StartingSubcarrierId.set_val(0) sub_tlv2.SubcarrierUsage.set_val(4) sub_tlv2 = sub_tlv.SidQos.add_new_repeated() sub_tlv2.StartSid.set_val(100) sub_tlv2.NumSids.set_val(10) sub_tlv2.SidSfType.set_val(2) sub_tlv2 = sub_tlv.SidQos.add_new_repeated() sub_tlv2.StartSid.set_val(15800) sub_tlv2.NumSids.set_val(5) sub_tlv2.SidSfType.set_val(3) buf = msg.encode() self.assertNotEqual(buf, None) msg_dec = Message(gcp_msg_def.DataStructError) self.assertEqual(msg_dec.decode(buf, offset=0, buf_data_len=len(buf)), msg_dec.DECODE_DONE)