def test_msg_dispatch_coreident_read(self): print("########test_msg_dispatch_null_coreident_read##########") try: self.process.send_ipc_msg('error') except SystemExit as e: self.assertEqual(e.code, EX_DATAERR) data_list = [] seq = RCPSequence(gcp_msg_def.DataStructREQ, rcp_tlv_def.RCP_MSG_TYPE_REX, 0, rcp_tlv_def.RCP_OPERATION_TYPE_READ, unittest=True) sub_tlv = seq.CcapCoreIdentification.add_new_repeated() seq.ipc_msg = None data_list.append(seq) self.process.hal_ipc.disconnected = False self.process.hal_ipc.clientID = '12345' self.process.send_ipc_msg({ "session": self.session, "req_packet": 'tmp', "gcp_msg": "tmp", "req_data": data_list })
def test_msg_dispatch(self): try: self.process.send_ipc_msg('error') except SystemExit as e: self.assertEqual(e.code, EX_DATAERR) self.process.send_ipc_msg({ "session": self.session, "req_packet": None, "req_data": "error" }) timeout_msg = t_RcpMessage() timeout_msg.RcpMessageType = timeout_msg.CONNECT_CLOSE_NOTIFICATION self.process.send_ipc_msg({ "session": self.session, "req_packet": None, "req_data": timeout_msg }) data_list = [] seq = RCPSequence(gcp_msg_def.DataStructREQ, rcp_tlv_def.RCP_MSG_TYPE_REX, 0, rcp_tlv_def.RCP_OPERATION_TYPE_WRITE, unittest=True) seq.RpdCapabilities.NumBdirPorts.set_val(1) seq.RpdCapabilities.RpdIdentification.VendorName.set_val('31') seq.RpdCapabilities.RpdIdentification.VendorId.set_val(9) data_list.append(seq) seq = RCPSequence(gcp_msg_def.DataStructREQ, rcp_tlv_def.RCP_MSG_TYPE_REX, 0, rcp_tlv_def.RCP_OPERATION_TYPE_WRITE, unittest=True) sub_tlv = seq.RfPort.add_new_repeated() sub_tlv.RfPortSelector.RfPortIndex.set_val(0) sub_tlv.DsRfPort.AdminState.set_val(1) sub_tlv.DsRfPort.BasePower.set_val(30) sub_tlv.DsRfPort.RfMute.set_val(0) sub_tlv.DsRfPort.TiltSlope.set_val(8) sub_tlv.DsRfPort.TiltMaximumFrequency.set_val(15) data_list.append(seq) seq = RCPSequence(gcp_msg_def.DataStructREQ, rcp_tlv_def.RCP_MSG_TYPE_REX, 0, rcp_tlv_def.RCP_OPERATION_TYPE_WRITE, unittest=True) seq.RpdConfigurationDone.set_val(1) data_list.append(seq) seq = RCPSequence(gcp_msg_def.DataStructREQ, rcp_tlv_def.RCP_MSG_TYPE_REX, 0, rcp_tlv_def.RCP_OPERATION_TYPE_WRITE) seq.ipc_msg = None data_list.append(seq) self.process.hal_ipc.disconnected = False self.process.hal_ipc.clientID = '12345' self.process.send_ipc_msg({ "session": self.session, "req_packet": 'tmp', "gcp_msg": "tmp", "req_data": data_list })
def test_msg_dispatch_I08(self): print("##################test_msg_dispatch_I08##################") try: self.process.send_ipc_msg('error') except SystemExit as e: self.assertEqual(e.code, EX_DATAERR) self.process.send_ipc_msg({ "session": self.session, "req_packet": None, "req_data": "error" }) timeout_msg = t_RcpMessage() timeout_msg.RcpMessageType = timeout_msg.CONNECT_CLOSE_NOTIFICATION self.process.send_ipc_msg({ "session": self.session, "req_packet": None, "req_data": timeout_msg }) data_list = [] seq = RCPSequence(gcp_msg_def.DataStructREQ, rcp_tlv_def.RCP_MSG_TYPE_REX, 0, rcp_tlv_def.RCP_OPERATION_TYPE_WRITE, unittest=True) sub_tlv = seq.CcapCoreIdentification.add_new_repeated() sub_tlv.Index.set_val(1) sub_tlv.CoreId.set_val('1234567890') sub_tlv.CoreIpAddress.set_val( Convert.ipaddr_to_tuple_of_bytes("127.0.0.1")) sub_tlv.IsPrincipal.set_val(False) sub_tlv.CoreMode.set_val(1) sub_tlv.InitialConfigurationComplete.set_val(True) sub_tlv.MoveToOperational.set_val(True) sub_tlv.CoreFunction.set_val(1) sub_tlv.ResourceSetIndex.set_val(2) data_list.append(seq) seq = RCPSequence(gcp_msg_def.DataStructREQ, rcp_tlv_def.RCP_MSG_TYPE_REX, 0, rcp_tlv_def.RCP_OPERATION_TYPE_ALLOCATE_WRITE, unittest=True) sub_tlv = seq.RfPort.add_new_repeated() sub_tlv.RfPortSelector.RfPortIndex.set_val(0) sub_tlv.DsRfPort.AdminState.set_val(1) sub_tlv.DsRfPort.BasePower.set_val(30) sub_tlv.DsRfPort.RfMute.set_val(0) sub_tlv.DsRfPort.TiltSlope.set_val(8) sub_tlv.DsRfPort.TiltMaximumFrequency.set_val(15) data_list.append(seq) seq = RCPSequence(gcp_msg_def.DataStructREQ, rcp_tlv_def.RCP_MSG_TYPE_REX, 0, rcp_tlv_def.RCP_OPERATION_TYPE_ALLOCATE_WRITE, unittest=True) seq.RpdConfigurationDone.set_val(1) data_list.append(seq) seq = RCPSequence(gcp_msg_def.DataStructREQ, rcp_tlv_def.RCP_MSG_TYPE_REX, 0, rcp_tlv_def.RCP_OPERATION_TYPE_ALLOCATE_WRITE) seq.ipc_msg = None data_list.append(seq) self.process.hal_ipc.disconnected = False self.process.hal_ipc.clientID = '12345' self.process.send_ipc_msg({ "session": self.session, "req_packet": 'tmp', "gcp_msg": "tmp", "req_data": data_list })
def test_rcp_msg_cb_event(self): print '############test rcp_msg_cb event case#############' RCPDB.DB_CFG_FILE = CONF_FILE seq = RCPSequence(gcp_msg_def.DataStructREQ, rcp_tlv_def.RCP_MSG_TYPE_REX, 1, rcp_tlv_def.RCP_OPERATION_TYPE_READ, unittest=True) desc = GCPSlaveDescriptor( '1.1.1.1', port_master='8190', addr_local='1.1.1.2', interface_local='eth0', addr_family=socket.AF_INET) orch = self.agent.process.orchestrator session = RCPSlaveSession(desc, self.agent.process.dispatcher, orch.session_initiate_cb, orch.session_timeout_cb, orch.session_connecting_timeout_cb) # reboot rcp_msg = t_RcpMessage() rcp_msg.RcpMessageType = rcp_msg.RPD_REBOOT ccap_core_para = {'addr_remote': '1.1.1.1', 'interface_local': 'eth1', 'info': "test"} rcp_msg.parameter = json.dumps(ccap_core_para) self.agent.rcp_msg_cb(rcp_msg) # redirect rcp_msg = t_RcpMessage() rcp_msg.RcpMessageType = rcp_msg.REDIRECT_NOTIFICATION ccap_core_para = {'addr_remote': '1.1.1.1', 'interface_local': 'eth0', 'info': "test"} rcp_msg.parameter = json.dumps(ccap_core_para) rcp_msg.RedirectCCAPAddresses.append('3.3.3.3') self.agent.rcp[('eth0', '1.1.1.1')]['status'] = self.agent.UP self.agent.rcp_msg_cb(rcp_msg) # configuration rcp_msg = t_RcpMessage() rcp_msg.RcpMessageType = rcp_msg.RPD_CONFIGURATION cfg = rcp_msg.RpdDataMessage.RpdData rcp_msg.parameter = 'eth0' capability = cfg.CcapCoreIdentification.add() capability.Index = 1 capability.CoreId = 'CoreId' capability.CoreIpAddress = '1.1.1.1' capability.IsPrincipal = True capability.CoreMode = 1 capability.CoreName = "CiscoRPD" capability.VendorId = 1 capability.InitialConfigurationComplete = True capability.MoveToOperational = True capability.CoreFunction = 1 capability.ResourceSetIndex = 2 self.agent.rcp[('eth0', '1.1.1.1')]['status'] = self.agent.DOWN self.agent.rcp_msg_cb(rcp_msg) # RedundantCoreIpAddress rcp_msg = t_RcpMessage() rcp_msg.RcpMessageType = rcp_msg.RPD_CONFIGURATION cfg = rcp_msg.RpdDataMessage.RpdData rcp_msg.parameter = 'eth0' red = cfg.RedundantCoreIpAddress.add() red.ActiveCoreIpAddress = '1.1.1.1' red.StandbyCoreIpAddress = '1.1.1.3' self.agent.rcp_msg_cb(rcp_msg) # no must field desc1 = GCPSlaveDescriptor( '1.1.1.1', port_master='8190', addr_local='1.1.1.2', interface_local='eth0', addr_family=socket.AF_INET) orch = self.agent.process.orchestrator session_1 = RCPSlaveSession(desc1, self.agent.process.dispatcher, orch.session_initiate_cb, orch.session_timeout_cb, orch.session_connecting_timeout_cb) self.agent.process.orchestrator.sessions_active[desc1.get_uniq_id()] = session_1 caps1 = CcapCoreIdentification(index=1, core_id="CoreId-1", core_ip_addr='1.1.1.1', is_principal=True, core_name="SIM_GCPP", vendor_id=0, core_mode=True, initial_configuration_complete=True, move_to_operational=True, core_function=1, resource_set_index=2) session_1.ccap_identification = caps1 desc2 = GCPSlaveDescriptor( '1.1.1.3', port_master='8190', addr_local='1.1.1.2', interface_local='eth0', addr_family=socket.AF_INET) orch = self.agent.process.orchestrator session_2 = RCPSlaveSession(desc2, self.agent.process.dispatcher, orch.session_initiate_cb, orch.session_timeout_cb, orch.session_connecting_timeout_cb) # self.agent.process.orchestrator.add_sessions([desc2]) self.agent.process.orchestrator.sessions_active[desc2.get_uniq_id()] = session_2 caps2 = CcapCoreIdentification(index=1, core_id="CoreId-2", core_ip_addr='1.1.1.1', is_principal=True, core_name="SIM_GCPP", vendor_id=0, core_mode=True, initial_configuration_complete=True, move_to_operational=True, core_function=1, resource_set_index=2) session_2.ccap_identification = caps2 caps1.is_active = False caps2.is_active = True red.Operation = ManagerProcess.OPERATION_ADD self.agent.rcp_msg_cb(rcp_msg) caps1.is_active = True caps2.is_active = False red.Operation = ManagerProcess.OPERATION_CHANGE self.agent.rcp_msg_cb(rcp_msg) # ConfiguredCoreTable # miss operation field rcp_msg = t_RcpMessage() rcp_msg.RcpMessageType = rcp_msg.RPD_CONFIGURATION cfg = rcp_msg.RpdDataMessage.RpdData cfg_core = cfg.ConfiguredCoreTable.add() cfg_core.ConfiguredCoreIp = '1.1.1.1' self.agent.rcp_msg_cb(rcp_msg) cfg_core.Operation = 0 self.agent.rcp_msg_cb(rcp_msg) # ActivePrincipalCore rcp_msg = t_RcpMessage() rcp_msg.RcpMessageType = rcp_msg.RPD_CONFIGURATION cfg = rcp_msg.RpdDataMessage.RpdData cfg.ActivePrincipalCore = '1.1.1.1' seq.ipc_msg = rcp_msg self.agent.rcp_msg_cb(seq, (session, 'transaction_identifier', 'trans_id')) # RPD_CONFIGURATION else rcp_msg = t_RcpMessage() rcp_msg.RcpMessageType = rcp_msg.RPD_CONFIGURATION cfg = rcp_msg.RpdDataMessage.RpdData cfg_core = cfg.Ssd cfg_core.SsdServerAddress = '1.1.1.1' self.agent.rcp_msg_cb(rcp_msg) # configuration done rcp_msg = t_RcpMessage() rcp_msg.RcpMessageType = rcp_msg.RPD_CONFIGURATION_DONE rcp_msg.parameter = ';'.join(['eth0', '1.1.1.1']) self.agent.principal_core_interface = 'eth0' self.agent.principal_core = '1.1.1.1' self.agent.rcp_msg_cb(rcp_msg, (session, 'transaction_identifier', 'trans_id')) # CONNECT_CLOSE_NOTIFICATION rcp_msg = t_RcpMessage() rcp_msg.RcpMessageType = rcp_msg.CONNECT_CLOSE_NOTIFICATION ccap_core_para = {'addr_remote': '1.1.1.1', 'interface_local': 'eth0', "reconnect": True} rcp_msg.parameter = json.dumps(ccap_core_para) self.agent.ccap_cores.pop('CORE-1234567890') self.agent.rcp_msg_cb(rcp_msg) ccap_core_para = {'addr_remote': '1.1.1.1', 'interface_local': 'eth0', "reconnect": False} rcp_msg.parameter = json.dumps(ccap_core_para) self.agent.rcp_msg_cb(rcp_msg)