Beispiel #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)
 def test_getProcesses(self):
     self.logger.info("test_getProcesses")
     cfg_msg = config()
     hr = cfg_msg.HostResources
     hr.hrProcessorLoad = self.hostRes.getProcessorLoad()
     self.hostRes.getProcesses(hr.hrProcesses)
     self.assertTrue(hr.hrProcesses)
 def test_getStorages(self):
     self.logger.info("test_getStorages")
     cfg_msg = config()
     hr = cfg_msg.HostResources
     hr.hrMemorySize = self.hostRes.getMemorySize()
     self.hostRes.getStorages(hr.hrStorages)
     self.assertTrue(hr.hrStorages)
Beispiel #4
0
    def test_trees_merge_two_levels(self):
        data = RPD_DB()
        c = self._create_filled_cfg()
        data.set_val(['cfg'], c)

        c2 = cfg_pb2.config()
        d1 = c2.DsOfdmProfile.add()
        d1.ProfileId = 1
        # Add another subcarrier under existing profileId
        d11 = d1.DsOfdmSubcarrierModulation.add()
        d11.StartSubcarrierId = 12
        d11.EndSubcarrierId = 12
        d11.Modulation = 1
        # Change leaf which is not leaf
        d2 = c2.DsOfdmProfile.add()
        d2.ProfileId = 2
        d21 = d2.DsOfdmSubcarrierModulation.add()
        d21.StartSubcarrierId = 21
        d21.EndSubcarrierId = 21
        d21.Modulation = 3

        data.merge_from_tree(['cfg'], c2)
        value = data.get_val(['cfg', 'DsOfdmProfile'])
        self.assertEqual(len(value), 2)
        value = data.get_val(
            ['cfg', 'DsOfdmProfile', 1, 'DsOfdmSubcarrierModulation'])
        self.assertListEqual([x.StartSubcarrierId for x in value], [11, 12])
        value = data.get_val(
            ['cfg', 'DsOfdmProfile', 2, 'DsOfdmSubcarrierModulation'])
        # One from two subcarriers specified - check if second was not removed
        self.assertEqual(len(value), 2)
        self.assertListEqual([x.Modulation for x in value], [3, 3])
Beispiel #5
0
 def test_recvRpdServerCtrlMsgCb(self):
     rcp_msg = t_RcpMessage()
     rcp_msg.RcpMessageType = t_RcpMessage.RPD_CONFIGURATION
     rcp_msg.RpdDataMessage.RpdDataOperation = t_RpdDataMessage.RPD_CFG_WRITE
     cfg_msg = config()
     rpdCtrl = cfg_msg.RpdCtrl
     rpdServerCtrlCfg = rpdCtrl.CrashDataServerCtrl
     rpdServerCtrlCfg.DestIpAddress = "127.0.0.1"
     rpdServerCtrlCfg.DestPath = "/bootflash/"
     rpdServerCtrlCfg.Protocol = 2
     rcp_msg.RpdDataMessage.RpdData.CopyFrom(cfg_msg)
     cfg_payload = rcp_msg.SerializeToString()
     self.cfgMsg = HalMessage("HalConfig",
                              SrcClientID="testRpdRes",
                              SeqNum=322,
                              CfgMsgType=MsgTypeRpdCtrl,
                              CfgMsgPayload=cfg_payload)
     crashFileCtrl = self.rpdhostres.crashFileCtrlHandler
     self.assertEqual(None, self.rpdhostres.recvCfgMsgCb(self.cfgMsg))
     crashDataServerInfo = crashFileCtrl.get_server_info()
     self.assertEqual(crashDataServerInfo.destIpAddress,
                      rpdServerCtrlCfg.DestIpAddress)
     self.assertEqual(crashDataServerInfo.destPath,
                      rpdServerCtrlCfg.DestPath)
     self.assertEqual(crashDataServerInfo.protocol,
                      rpdServerCtrlCfg.Protocol)
Beispiel #6
0
    def test_read_notification_handler(self):

        rcp_msg = t_RcpMessage()
        rcp_msg.RcpDataResult = t_RcpMessage.RCP_RESULT_OK
        rcp_msg.RcpMessageType = t_RcpMessage.RPD_CONFIGURATION
        evcfg = config()
        # test PendingOrLocalLog 0
        notify_req = evcfg.EventNotification.add()
        notify_req.PendingOrLocalLog = 0
        rcp_msg.RpdDataMessage.RpdData.CopyFrom(evcfg)
        rcp_msg.RpdDataMessage.RpdDataOperation = 2
        payload = rcp_msg.SerializeToString()

        ntMsg = HalMessage("HalConfig",
                           SrcClientID="testRpdFM",
                           SeqNum=322,
                           CfgMsgType=MsgTypetEventNotification,
                           CfgMsgPayload=payload)

        self.fm.fault_ipc.read_notification_handler(ntMsg)
        # test PendingOrLocalLog 1
        notify_req.PendingOrLocalLog = 1
        rcp_msg.RpdDataMessage.RpdData.CopyFrom(evcfg)
        rcp_msg.RpdDataMessage.RpdDataOperation = 2
        payload = rcp_msg.SerializeToString()

        ntMsg = HalMessage("HalConfig",
                           SrcClientID="testRpdFM",
                           SeqNum=322,
                           CfgMsgType=MsgTypetEventNotification,
                           CfgMsgPayload=payload)

        self.fm.fault_ipc.read_notification_handler(ntMsg)
Beispiel #7
0
    def sendRpdCapReq(self):
        try:
            if self.rpd_cap:
                self.logger.debug(
                    "Already has Rpd cap in store, no need to send req")
                return True
            rcp_msg = t_RcpMessage()
            rcp_msg.RcpDataResult = t_RcpMessage.RCP_RESULT_OK
            rcp_msg.RcpMessageType = t_RcpMessage.RPD_CONFIGURATION
            rpd_data_msg = t_RpdDataMessage()
            rpd_data_msg.RpdDataOperation = t_RpdDataMessage.RPD_CFG_READ
            rcp_cfg = config()
            sub_tlv = rcp_cfg.RpdCapabilities
            GCPObject.default_gpb(gpb=sub_tlv)
            rpd_data_msg.RpdData.CopyFrom(rcp_cfg)
            rcp_msg.RpdDataMessage.CopyFrom(rpd_data_msg)

            cfgMsgContent = rcp_msg.SerializeToString()
            msg = HalMessage("HalConfig",
                             SrcClientID=self.drvID,
                             SeqNum=self.seqNum,
                             CfgMsgType=MsgTypeRpdCapabilities,
                             CfgMsgPayload=cfgMsgContent)
            self.send(msg.Serialize())
            self.seqNum += 1
            self.logger.debug("send RPD capabilities req to hal driver")
            return True
        except Exception as e:
            self.logger.warning("send RPD cap req failed :%s", str(e))
            return False
Beispiel #8
0
    def test_L2tpv3Hall_GCPP(self):
        index = 0
        rcp_msg = t_RcpMessage()
        rcp_msg.RcpMessageType = t_RcpMessage.RPD_CONFIGURATION
        rcp_msg.RpdDataMessage.RpdDataOperation = \
            t_RpdDataMessage.RPD_CFG_WRITE
        cfg_msg = config()
        staticPwConfig = cfg_msg.StaticPwConfig
        self.retCfg = StaticL2tpProvision()
        self.retCfg.add_usStaticSession(staticPwConfig, index + 163, False,
                                        False)
        self.retCfg.add_commStaticSession(staticPwConfig, index + 163,
                                          0x80007111 + index, index, 32768,
                                          True)
        rcp_msg.RpdDataMessage.RpdData.CopyFrom(cfg_msg)
        cfg_payload = rcp_msg.SerializeToString()
        staticL2tpMsg = HalMessage("HalConfig", SrcClientID="testGCPPL2Static",
                                   SeqNum=325,
                                   CfgMsgType=HalConfigMsg.MsgTypeGcppToL2tp,
                                   CfgMsgPayload=cfg_payload)

        self.hal_client.recvCfgMsgCb(staticL2tpMsg)
        ses = StaticL2tpSession(index + 163)
        ses.read()
        self.assertTrue(self.fwdCfg.check_StaticSession(staticPwConfig, ses))
Beispiel #9
0
    def testMasterRedirect(self):
        context = zmq.Context()
        socket = context.socket(zmq.REQ)
        socket.connect(MasterAPI.MasterZMQPath)

        # construct the message
        msg = master_sim_def.t_MasterSimApiMessage()
        slave_desc = master_sim_def.t_SlaveDescriptor()
        slave_desc.addr_master = "0.0.0.0"
        slave_desc.port_master = 8190
        slave_desc.interface_master = "eth0"
        slave_desc.addr_local = "127.0.0.1"
        slave_desc.port_local = 8190
        slave_desc.interface_local = "eth0"
        slave_desc.addr_family = 2

        msg.operation = msg.WRITE

        cfg = Config.config()

        redirect = cfg.RpdRedirect.add()
        redirect.RedirectIpAddress = "127.0.0.1"
        # binascii.a2b_hex("7F000001")

        msg.slave_descriptor.CopyFrom(slave_desc)
        msg.cfg.CopyFrom(cfg)

        print msg
        data = msg.SerializeToString()

        socket.send(data)
        socket.close()
        del context
Beispiel #10
0
    def test_pop_operational_event(self):
        print '*' * 80
        print 'test operational event log pop'
        print '*' * 80
        self.enable_notify_send()

        # generate log
        EventCommonOperation.store_fault_message("66070200: test message 1")
        EventCommonOperation.store_fault_message("66070200: test message 1",
                                                 operational=True)
        EventCommonOperation.store_fault_message("66070201: test message 2",
                                                 operational=True)
        EventCommonOperation.store_fault_message("66070202: test message 3",
                                                 operational=True)
        # as 203 stored in pending file, so not generate it.
        # EventCommonOperation.store_fault_message("66070203: test message 4", operational=True)
        EventCommonOperation.store_fault_message("66070204: test message 4",
                                                 operational=True)
        EventCommonOperation.store_fault_message("66070205: test message 5",
                                                 operational=True)

        cfg = config()
        notify_req = cfg.EventNotification.add()
        notify_req.RpdEvLogIndex = 3
        notify_req.PendingOrLocalLog = 1
        if notify_req.HasField("PendingOrLocalLog"):
            if notify_req.PendingOrLocalLog:
                local = EventCommonOperation.BUFFERED_LOCAL
            else:
                local = EventCommonOperation.BUFFERED_PENDING
            ntf_msg = EventCommonOperation.read_log(local)
            operational_cnt = 5

            cnt = 0
            while True:
                ret = RpdEventOrderedBuffer.pop_operational_event(ntf_msg)
                if None is not ret:
                    print ret
                    cnt += 1
                else:
                    break

            # pop initiating process event
            for key, data in ntf_msg.items():
                print data
                ntf_msg.pop(key)

            # verify the result
            self.assertEqual(
                operational_cnt,
                cnt,
                msg="pop operational event from local fail %d, %d" %
                (operational_cnt, cnt))
            self.assertEqual("operational" not in ntf_msg,
                             True,
                             msg="pop whole operational event fail")
            self.assertEqual(len(ntf_msg),
                             0,
                             msg="pop  initiating process event fail")
Beispiel #11
0
    def test_tftp_fail_status(self):
        print("case:test_tftp_fail_status")
        cfg_msg = config()
        rpdCtrl = cfg_msg.RpdCtrl
        rpdServerCtrlCfg = rpdCtrl.CrashDataServerCtrl
        rpdServerCtrlCfg.DestPath = "/./"
        rpdServerCtrlCfg.Protocol = CrashFileCtrlHandler.PROTOCOL_TFTP
        self.crashCtrlHandler.save_crash_data_server(rpdServerCtrlCfg)
        if self.crashCtrlHandler.is_upload_process_alive():
            self.crashCtrlHandler.stop_upload_process()

        time.sleep(self.ONE_SECOND)
        self.assertEquals(self.crashCtrlHandler.is_upload_process_alive(), False)
        os.system("rm -rf /tmp/crash/*")
        for fileName in self.nameList1:
            file_object = open(self.crashCtrlHandler.CORE_FILE_PATH + fileName, 'w')
            file_object.write(self.text)
            file_object.close()
        self.crashCtrlHandler.update_crash_file_table(None)

        cfg_msg = config()
        rpdCtrl = cfg_msg.RpdCtrl
        rpdServerCtrlCfg = rpdCtrl.CrashDataServerCtrl
        rpdServerCtrlCfg.DestIpAddress = ""
        rpdServerCtrlCfg.DestPath = "/./"
        rpdServerCtrlCfg.Protocol = CrashFileCtrlHandler.PROTOCOL_TFTP
        self.crashCtrlHandler.save_crash_data_server(rpdServerCtrlCfg)
        print("step5: test upload=========\n")
        cfg_msg = config()
        rpdCtrl = cfg_msg.RpdCtrl
        rpdServerCtrlCfg = rpdCtrl.CrashDataServerCtrl
        rpdServerCtrlCfg.DestIpAddress = "128.0.0.1"
        rpdServerCtrlCfg.DestPath = "/./"
        rpdServerCtrlCfg.Protocol = CrashFileCtrlHandler.PROTOCOL_TFTP
        self.crashCtrlHandler.save_crash_data_server(rpdServerCtrlCfg)
        self.crashCtrlHandler.get_crash_data_server(rpdServerCtrlCfg)
        for key in CrashFileStatusInfo.get_keys():
            crashFileStatusInfo = CrashFileStatusInfo(key)
            crashFileStatusInfo.read()
            self.crashCtrlHandler.update_pending_file_idx_list(key, self.crashCtrlHandler.CONTROL_UPLOAD)

        time.sleep(self.FIVE_SECOND)
        for key in CrashFileStatusInfo.get_keys():
            crashFileStatusInfo = CrashFileStatusInfo(key)
            crashFileStatusInfo.read()
            self.assertNotEquals(crashFileStatusInfo.fileStatus, self.crashCtrlHandler.STATUS_AVAILFORUPLOAD)
Beispiel #12
0
    def start(self):
        """Start polling the transport socket.

        :return:

        """
        self.logger.debug("Start the driver client poll...")
        self.connectionSetup()

        self.register(self.drvID)
        lastTimeout = time()

        while True:  # Todo we should support quit flag?
            socks = self.poller.poll(self.pollTimeout)
            if time() - lastTimeout > self.pollTimeout / 1000:
                lastTimeout = time()
                # self.logger.debug("Got a timeout event")
                if self.recvNtf:
                    rcp_msg = t_RcpMessage()
                    rcp_msg.RpdDataMessage.RpdDataOperation = t_RpdDataMessage.RPD_CFG_READ
                    rcp_msg.RcpMessageType = t_RcpMessage.RPD_CONFIGURATION
                    rcp_msg.RpdDataMessage.RpdData.CopyFrom(config())
                    payload = rcp_msg.SerializeToString()
                    self.sendCfgMsg(1025, payload)
                    self.recvNtf -= 1

            if not socks:
                continue
            for sock in socks:
                if self.pushSock is not None and sock == self.pushSock.monitor:
                    self.pushSock.monitorHandler(recv_monitor_message(sock))
                    continue
                if self.pullSock is not None and sock == self.pullSock.monitor:
                    self.pullSock.monitorHandler(recv_monitor_message(sock))
                    continue
                if sock == self.mgrConnection.monitor:
                    self.mgrConnection.monitorHandler(
                        recv_monitor_message(sock))
                    continue
                if socks[sock] == HalPoller.POLLIN:
                    try:
                        bin = sock.recv(flags=zmq.NOBLOCK)
                        msg = HalMessage.DeSerialize(bin)
                        self.logger.debug("Got a zmq msg:%s" % msg.msg)
                        if msg.type in self.HalMsgsHandler:
                            handler = self.HalMsgsHandler[msg.type]
                            handler(msg)
                        else:
                            self.logger.warn("Unsupported msg type:%s" %
                                             msg.type)
                    except zmq.ZMQError as e:
                        self.logger.debug(
                            "Geting an error when trying with nonblock read:" +
                            str(e))
                    except Exception as e:
                        self.logger.debug("Geting an error:" + str(e))
                continue
Beispiel #13
0
 def test_gpb_array_read_read_all(self):
     test_count = 1000
     self.assertTrue(self.create_ipv4_ipv6_record(test_count))
     data = config()
     gpb = data.RpdInfo.DepiMcastSession
     item = gpb.add()
     record = DepiMcastSessionRecord()
     mcast_array = ArrayTLVRead(gpb, C100_DepiMcastSession_5)
     mcast_array.array_read(record)
     self.assertTrue(len(data.RpdInfo.DepiMcastSession), test_count * 2)
Beispiel #14
0
 def test_gpb_array_read_read_with_keys(self):
     test_count = 10
     self.assertTrue(self.create_ipv4_ipv6_record(test_count))
     print "============ 1: key is in db==============="
     data = config()
     gpb = data.RpdInfo.DepiMcastSession
     item = gpb.add()
     item.IpAddrType = 2
     item.GroupIpAddr = "2001::1"
     item.SrcIpAddr = "2001::2"
     item.SessionId = 1
     record = DepiMcastSessionRecord()
     mcast_array = ArrayTLVRead(gpb, C100_DepiMcastSession_5)
     mcast_array.array_read(record)
     self.assertTrue(len(data.RpdInfo.DepiMcastSession), 1)
     self.assertTrue(len(data.RpdInfo.DepiMcastSession[0].ListFields()), 6)
     print "============ 2: key is not in db==============="
     data = config()
     gpb = data.RpdInfo.DepiMcastSession
     item = gpb.add()
     item.IpAddrType = 2
     item.GroupIpAddr = "2001:1::1"
     item.SrcIpAddr = "2001::2"
     item.SessionId = 1
     record = DepiMcastSessionRecord()
     mcast_array = ArrayTLVRead(gpb, C100_DepiMcastSession_5)
     mcast_array.array_read(record)
     self.assertTrue(len(data.RpdInfo.DepiMcastSession), 1)
     self.assertEqual(len(data.RpdInfo.DepiMcastSession[0].ListFields()), 5)
     print "============ 3: request keys is in db==============="
     data = config()
     gpb = data.RpdInfo.DepiMcastSession
     for ses in (0, test_count):
         item = gpb.add()
         item.IpAddrType = 2
         item.GroupIpAddr = "2001::1"
         item.SrcIpAddr = "2001::2"
         item.SessionId = ses + 1
     record = DepiMcastSessionRecord()
     mcast_array = ArrayTLVRead(gpb, C100_DepiMcastSession_5)
     mcast_array.array_read(record)
     self.assertTrue(len(data.RpdInfo.DepiMcastSession), test_count)
Beispiel #15
0
    def test_gpb_array_read_invalid_read(self):
        data = config()
        gpb = data.RpdInfo.DiagnosticStatus
        try:
            ArrayTLVRead(gpb, C100_DiagnosticStatus_4)
        except ArrayTLVReadException as e:
            self.assertEqual(str(e), "rcptlv is not Array instance")

        try:
            ArrayTLVRead(gpb, "test")
        except ArrayTLVReadException as e:
            self.assertEqual(str(e), "rcptlv is not an instance of RCPTLV")

        data = config()
        gpb = data.RpdInfo.DepiMcastSession
        try:
            mcast_array = ArrayTLVRead(gpb, C100_DepiMcastSession_5)
            mcast_array.array_read("test")
        except ArrayTLVReadException as e:
            self.assertEqual(str(e), "record is not instance of RCPRecord")
Beispiel #16
0
 def test_gpb_array_read_read_with_partial_leaf(self):
     test_count = 1000
     self.assertTrue(self.create_ipv4_ipv6_record(test_count))
     print "============ 1: request partial leaf is in db==============="
     data = config()
     gpb = data.RpdInfo.DepiMcastSession
     item = gpb.add()
     item.LocalLcceIpAddr = "10.1.1.1"
     record = DepiMcastSessionRecord()
     mcast_array = ArrayTLVRead(gpb, C100_DepiMcastSession_5)
     mcast_array.array_read(record)
     self.assertEqual(len(data.RpdInfo.DepiMcastSession), test_count * 2)
Beispiel #17
0
 def test_gpb_array_read_read_with_partial_two_keys(self):
     test_count = 1000
     self.assertTrue(self.create_ipv4_ipv6_record(test_count))
     print "============ 1: request partial keys is in db==============="
     data = config()
     gpb = data.RpdInfo.DepiMcastSession
     item = gpb.add()
     item.IpAddrType = 1
     item.GroupIpAddr = "10.79.31.1"
     record = DepiMcastSessionRecord()
     mcast_array = ArrayTLVRead(gpb, C100_DepiMcastSession_5)
     mcast_array.array_read(record)
     self.assertEqual(len(data.RpdInfo.DepiMcastSession), test_count)
Beispiel #18
0
 def test_gpb_array_read_read_with_partial_keys(self):
     test_count = 1000
     self.assertTrue(self.create_ipv4_ipv6_record(test_count))
     print "============ 1: request partial keys is in db==============="
     data = config()
     gpb = data.RpdInfo.DepiMcastSession
     for ses in range(0, test_count):
         item = gpb.add()
         item.SessionId = ses + 1
     record = DepiMcastSessionRecord()
     mcast_array = ArrayTLVRead(gpb, C100_DepiMcastSession_5)
     mcast_array.array_read(record)
     self.assertEqual(len(data.RpdInfo.DepiMcastSession), test_count * 2)
Beispiel #19
0
 def test_gpb_array_read_readcout_without_key(self):
     self.assertTrue(self.create_ipv4_ipv6_record())
     data = config()
     readCount = 3
     gpb = data.RpdInfo.DepiMcastSession
     gpb.add()
     record = DepiMcastSessionRecord()
     mcast_array = ArrayTLVRead(gpb, C100_DepiMcastSession_5)
     mcast_array.array_read(record, readCount)
     for item in gpb:
         print item
         self.assertEqual(len(item.ListFields()), 6)
         self.assertFalse(item.HasField("JoinTime"))
     self.assertTrue(len(data.RpdInfo.DepiMcastSession), readCount)
Beispiel #20
0
 def test_invalid_key(self):
     sessRec = DepiMcastSessionRecord()
     sessRec.updateDepiMcastSessionKey(IpAddrType=1,
                                       GroupIpAddr="test",
                                       SrcIpAddr="10.90.31.1",
                                       SessionId=0x80010001)
     sessRec.updateDepiMcastSessionData("10.1.1.1", "1.1.1.1", time.time())
     sessRec.write()
     data = config()
     gpb = data.RpdInfo.DepiMcastSession
     item = gpb.add()
     record = DepiMcastSessionRecord()
     mcast_array = ArrayTLVRead(gpb, C100_DepiMcastSession_5)
     mcast_array.array_read(record)
     print gpb[0]
     self.assertEqual(len(data.RpdInfo.DepiMcastSession), 1)
Beispiel #21
0
 def test_gpb_array_read_readcout_with_leaf(self):
     self.assertTrue(self.create_ipv4_ipv6_record())
     data = config()
     readCount = 10
     gpb = data.RpdInfo.DepiMcastSession
     item = gpb.add()
     item.IpAddrType = 2
     value = getattr(item, "LocalLcceIpAddr")
     setattr(item, "LocalLcceIpAddr", value)
     record = DepiMcastSessionRecord()
     mcast_array = ArrayTLVRead(gpb, C100_DepiMcastSession_5)
     mcast_array.array_read(record, readCount)
     for item in gpb:
         self.assertEqual(len(item.ListFields()), 5)
         self.assertEqual(item.IpAddrType, 2)
         self.assertFalse(item.HasField("JoinTime"))
     self.assertTrue(len(data.RpdInfo.DepiMcastSession), readCount)
Beispiel #22
0
 def _create_filled_cfg(self):
     c = cfg_pb2.config()
     d1 = c.DsOfdmProfile.add()
     d1.ProfileId = 1
     d11 = d1.DsOfdmSubcarrierModulation.add()
     d11.StartSubcarrierId = 11
     d11.EndSubcarrierId = 11
     d11.Modulation = 1
     d2 = c.DsOfdmProfile.add()
     d2.ProfileId = 2
     d21 = d2.DsOfdmSubcarrierModulation.add()
     d21.StartSubcarrierId = 21
     d21.EndSubcarrierId = 21
     d21.Modulation = 2
     d22 = d2.DsOfdmSubcarrierModulation.add()
     d22.StartSubcarrierId = 22
     d22.EndSubcarrierId = 22
     d22.Modulation = 3
     return c
Beispiel #23
0
    def _generate_full_cfg(element_count, str_len):
        from random import choice
        from string import lowercase

        long_string = "".join(choice(lowercase) for _ in range(str_len))
        # These values will be modified for repeated elements
        int_val = 0
        uint_val = 0
        enum_val_idx = 0  # first item
        bool_val = True
        # Element count can be max 7 -> we are not able to generate more unique
        # IDs for UsOfdmaDataRangingIuc (index is enum)
        if element_count > 7:
            raise ValueError("Max count of repeated elements is 7")

        conf = cfg_pb2.config()
        TestDatabase._walk_obj_and_fill_leafs(conf, long_string, int_val,
                                              uint_val, enum_val_idx, bool_val,
                                              element_count)
        return conf
Beispiel #24
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
                    ])
Beispiel #25
0
    def test_http_ctrl_hal_msg(self):
        print("case: test_http_ctrl_hal_msg")
        if not self.tftp_pid:
            self.tftp_pid = subprocess.Popen(self.start_tftp_cmd, executable='bash', shell=True)
        if self.crashCtrlHandler.is_upload_process_alive():
            self.crashCtrlHandler.stop_upload_process()
        time.sleep(self.ONE_SECOND)
        self.assertEquals(self.crashCtrlHandler.is_upload_process_alive(), False)
        os.system("rm -rf /tmp/crash/*")
        for fileName in self.nameList:
            file_object = open(self.crashCtrlHandler.CORE_FILE_PATH + fileName, 'w')
            file_object.write(self.text)
            file_object.close()
        self.crashCtrlHandler.update_crash_file_table(None)
        for key in CrashFileStatusInfo.get_keys():
            crashFileStatusInfo = CrashFileStatusInfo(key)
            crashFileStatusInfo.read()
            rcp_msg = t_RcpMessage()
            rcp_msg.RcpMessageType = t_RcpMessage.RPD_CONFIGURATION
            rcp_msg.RpdDataMessage.RpdDataOperation = \
                t_RpdDataMessage.RPD_CFG_WRITE
            cfg_msg = config()
            rpdCtrl = cfg_msg.RpdCtrl
            dataFileCtrl = rpdCtrl.CrashDataFileCtrl.add()
            dataFileCtrl.Index = crashFileStatusInfo.index
            dataFileCtrl.FileControl = CrashFileCtrlHandler.CONTROL_UPLOAD
            rpdCtrl.CrashDataServerCtrl.DestIpAddress = ""
            rpdCtrl.CrashDataServerCtrl.DestPath = "/tmp/crash/"
            rpdCtrl.CrashDataServerCtrl.Protocol = CrashFileCtrlHandler.PROTOCOL_HTTP

            rcp_msg.RpdDataMessage.RpdData.CopyFrom(cfg_msg)
            cfg_payload = rcp_msg.SerializeToString()
            rdpCtrlMsg = HalMessage("HalConfig", SrcClientID="testRpdCtrlMsg",
                                    SeqNum=325,
                                    CfgMsgType=HalConfigMsg.MsgTypeRpdCtrl,
                                    CfgMsgPayload=cfg_payload)

        self.halClient.recvCfgMsgCb(rdpCtrlMsg)
Beispiel #26
0
    def test_set_global_conf(self):
        print '*' * 80
        print 'test Global TLV handling'
        print '*' * 80
        RpdEventConfig.event_config_file = "test.config"

        # construct RpdGlobal config
        cfg_global = config()
        # cfg = t_RpdGlobal()
        cfg = cfg_global.RpdGlobal
        for lvl, _ in rcp_tlv_def.RPD_EVENT_LEVEL:
            ctrl = cfg.EvCfg.EvControl.add()
            ctrl.EvPriority = lvl
            if lvl <= rcp_tlv_def.RPD_EVENT_LEVEL_ERROR[0]:
                ctrl.EvReporting = RpdEventConfig.LOCAL_MAK + RpdEventConfig.PENDING_MARK
            else:
                ctrl.EvReporting = RpdEventConfig.PENDING_MARK
        cfg.EvCfg.EvThrottleAdminStatus = rcp_tlv_def.RPD_EVENT_THROTTLE_BELOW[
            0]
        cfg.EvCfg.EvThrottleThreshold = 10
        cfg.EvCfg.EvThrottleInterval = 10
        cfg.EvCfg.NotifyEnable = 1

        rcp_msg = t_RcpMessage()
        rcp_msg.RcpDataResult = t_RcpMessage.RCP_RESULT_OK
        rcp_msg.RcpMessageType = t_RcpMessage.RPD_CONFIGURATION
        payload = rcp_msg.SerializeToString()
        print payload
        cfgMsg = HalMessage("HalConfig",
                            SrcClientID="testRpdFM",
                            SeqNum=322,
                            CfgMsgType=MsgTypeRpdGlobal,
                            CfgMsgPayload=payload)

        cfgMsg.msg.CfgMsgPayload = rcp_msg.SerializeToString()

        self.fm.fault_ipc.set_global_conf(cfgMsg)
Beispiel #27
0
    def test_recvRpdServerCtrlMsgCbRead(self):
        rcp_msg = t_RcpMessage()
        rcp_msg.RcpMessageType = t_RcpMessage.RPD_CONFIGURATION
        rcp_msg.RpdDataMessage.RpdDataOperation = t_RpdDataMessage.RPD_CFG_READ
        cfg_msg = config()
        rpdCtrl = cfg_msg.RpdCtrl
        rcp_msg.RpdDataMessage.RpdData.CopyFrom(cfg_msg)
        cfg_payload = rcp_msg.SerializeToString()
        self.cfgMsg = HalMessage("HalConfig",
                                 SrcClientID="testRpdRes",
                                 SeqNum=322,
                                 CfgMsgType=MsgTypeRpdCtrl,
                                 CfgMsgPayload=cfg_payload)
        self.assertEqual(None, self.rpdhostres.recvCfgMsgCb(self.cfgMsg))

        rpdCtrl = cfg_msg.RpdCtrl
        rcp_msg.RpdDataMessage.RpdData.CopyFrom(cfg_msg)
        cfg_payload = rcp_msg.SerializeToString()
        self.cfgMsg = HalMessage("HalConfig",
                                 SrcClientID="testRpdRes",
                                 SeqNum=322,
                                 CfgMsgType=MsgTypeRpdState,
                                 CfgMsgPayload=cfg_payload)
        self.assertEqual(None, self.rpdhostres.recvCfgMsgCb(self.cfgMsg))

        rpdCtrl = cfg_msg.RpdCtrl
        crashDataServerCtrl = rpdCtrl.CrashDataServerCtrl
        crashDataServerCtrl.DestIpAddress = "127.0.0.1"
        rcp_msg.RpdDataMessage.RpdData.CopyFrom(cfg_msg)
        cfg_payload = rcp_msg.SerializeToString()
        self.cfgMsg = HalMessage("HalConfig",
                                 SrcClientID="testRpdRes",
                                 SeqNum=322,
                                 CfgMsgType=MsgTypeRpdCtrl,
                                 CfgMsgPayload=cfg_payload)
        self.assertEqual(None, self.rpdhostres.recvCfgMsgCb(self.cfgMsg))
Beispiel #28
0
    def test_set_config(self):
        print '*' * 80
        print 'test Global TLV handling'
        print '*' * 80
        RpdEventConfig.event_config_file = "test.config"

        # construct RpdGlobal config
        cfg_global = config()
        cfg = cfg_global.RpdGlobal
        for lvl, _ in rcp_tlv_def.RPD_EVENT_LEVEL:
            ctrl = cfg.EvCfg.EvControl.add()
            ctrl.EvPriority = lvl
            if lvl <= rcp_tlv_def.RPD_EVENT_LEVEL_ERROR[0]:
                ctrl.EvReporting = RpdEventConfig.LOCAL_MAK + RpdEventConfig.PENDING_MARK
            else:
                ctrl.EvReporting = RpdEventConfig.PENDING_MARK
        cfg.EvCfg.EvThrottleAdminStatus = rcp_tlv_def.RPD_EVENT_THROTTLE_BELOW[
            0]
        cfg.EvCfg.EvThrottleThreshold = 10
        cfg.EvCfg.EvThrottleInterval = 10
        cfg.EvCfg.NotifyEnable = 1
        RpdEventConfig.set_config(cfg_global)

        # verify the result
        self.assertEqual(RpdEventConfig.GLOBAL_CONFIG['Threshold'],
                         10,
                         msg="Threshold set fail")
        self.assertEqual(RpdEventConfig.GLOBAL_CONFIG['Interval'],
                         10,
                         msg="Interval set fail")
        self.assertEqual(RpdEventConfig.GLOBAL_CONFIG['Enable'],
                         1,
                         msg="Enable set fail")
        self.assertTrue(os.path.exists(RpdEventConfig.event_config_file),
                        msg="Failed to store the configuration file")
        os.remove(RpdEventConfig.event_config_file)
Beispiel #29
0
    def test_recvRpdResetCtrl(self):
        print("######test_recvRpdResetCtrl######")
        rcp_msg = t_RcpMessage()
        rcp_msg.RcpDataResult = t_RcpMessage.RCP_RESULT_OK
        rcp_msg.RcpMessageType = t_RcpMessage.RPD_CONFIGURATION
        self.haldriver.RESET_CTRL_FILENAME = self.rootpath + '/reset_ctrl'

        print("=====test case1: payload does not have RpdCtrl field=====")
        payload = rcp_msg.SerializeToString()
        msg = HalMessage("HalConfig",
                         SrcClientID="testRpdFM",
                         SeqNum=322,
                         CfgMsgType=MsgTypeRpdCtrl,
                         CfgMsgPayload=payload)
        return_str = self.haldriver.recvRpdResetCtrl(msg.msg)
        self.assertEquals(
            str(return_str),
            "{'Status': %d, 'ErrorDescription': 'ProvMgr Do not Have RpdCtrl Filed.'}"
            % HalCommon_pb2.SUCCESS_IGNORE_RESULT)

        print("=====test case2: payload operation neither read nor write=====")
        rpdresetcfg = config()
        rpdresetcfg.RpdCtrl.ResetCtrl.Reset = 4
        rcp_msg.RpdDataMessage.RpdData.CopyFrom(rpdresetcfg)
        rcp_msg.RpdDataMessage.RpdDataOperation = 3
        payload = rcp_msg.SerializeToString()
        msg = HalMessage("HalConfig",
                         SrcClientID="testRpdFM",
                         SeqNum=322,
                         CfgMsgType=MsgTypeRpdCtrl,
                         CfgMsgPayload=payload)
        return_str = self.haldriver.recvRpdResetCtrl(msg.msg)
        self.assertEquals(
            str(return_str),
            "{'Status': %d, 'ErrorDescription': 'Operation 3 for RpdResetCtrl is not supported'}"
            % HalCommon_pb2.FAILED)

        print("=====test case3: payload operation write=====")
        rpdresetcfg = config()
        rpdresetcfg.RpdCtrl.ResetCtrl.Reset = 2
        rcp_msg.RpdDataMessage.RpdData.CopyFrom(rpdresetcfg)
        rcp_msg.RpdDataMessage.RpdDataOperation = 1
        payload = rcp_msg.SerializeToString()
        msg = HalMessage("HalConfig",
                         SrcClientID="testRpdFM",
                         SeqNum=322,
                         CfgMsgType=MsgTypeRpdCtrl,
                         CfgMsgPayload=payload)
        return_str = self.haldriver.recvRpdResetCtrl(msg.msg)
        self.assertTrue(os.path.exists(self.haldriver.RESET_CTRL_FILENAME))
        fp = open(self.haldriver.RESET_CTRL_FILENAME, 'r')
        reset_fp = fp.read()
        self.assertEqual(int(reset_fp.strip(":")[0]), 2)
        self.assertEquals(
            str(return_str), "{'Status': %d, 'ErrorDescription': "
            "'ProMgr handle RpdResetCtrl success for 1'}" %
            HalCommon_pb2.SUCCESS)

        print(
            "=====test case4: payload operation read, reset file exists=====")
        rpdresetcfg = config()
        rpdresetcfg.RpdCtrl.ResetCtrl.Reset = 1
        rcp_msg.RpdDataMessage.RpdData.CopyFrom(rpdresetcfg)
        rcp_msg.RpdDataMessage.RpdDataOperation = 2
        payload = rcp_msg.SerializeToString()
        msg = HalMessage("HalConfig",
                         SrcClientID="testRpdFM",
                         SeqNum=322,
                         CfgMsgType=MsgTypeRpdCtrl,
                         CfgMsgPayload=payload)

        return_str = self.haldriver.recvRpdResetCtrl(msg.msg)
        self.assertTrue(os.path.exists(self.haldriver.RESET_CTRL_FILENAME))
        fp = open(self.haldriver.RESET_CTRL_FILENAME, 'r')
        reset_fp = fp.read()
        self.assertEqual(int(reset_fp.strip(":")[0]), 2)
        self.assertEquals(
            str(return_str), "{'Status': %d, 'ErrorDescription': "
            "'ProMgr handle RpdResetCtrl success for 2'}" %
            HalCommon_pb2.SUCCESS)

        print(
            "=====test case5: payload operation read, reset file not exists====="
        )
        if os.path.exists(self.haldriver.RESET_CTRL_FILENAME):
            os.remove(self.haldriver.RESET_CTRL_FILENAME)
        rpdresetcfg = config()
        rpdresetcfg.RpdCtrl.ResetCtrl.Reset = 1
        rcp_msg.RpdDataMessage.RpdData.CopyFrom(rpdresetcfg)
        rcp_msg.RpdDataMessage.RpdDataOperation = 2
        payload = rcp_msg.SerializeToString()
        msg = HalMessage("HalConfig",
                         SrcClientID="testRpdFM",
                         SeqNum=322,
                         CfgMsgType=MsgTypeRpdCtrl,
                         CfgMsgPayload=payload)

        return_str = self.haldriver.recvRpdResetCtrl(msg.msg)
        self.assertFalse(os.path.exists(self.haldriver.RESET_CTRL_FILENAME))
        self.assertEquals(
            str(return_str), "{'Status': %d, 'ErrorDescription': "
            "'ProMgr handle RpdResetCtrl success for 2'}" %
            HalCommon_pb2.SUCCESS)
Beispiel #30
0
def capabilities_get(cfg):
    logger = get_msg_handler_logger()
    logger.info("Get Capabilities srcClientID: %s, Seq num:  %d" %
                (cfg.msg.SrcClientID, cfg.msg.SeqNum))
    global_caps = {}
    pw_caps = {}
    ptp_caps = {}
    # Call vendor driver to update global_caps, pw_caps, ptp_caps dictionaries
    rcp_msg = t_RcpMessage()
    rcp_msg.RcpDataResult = t_RcpMessage.RCP_RESULT_OK
    rcp_msg.RcpMessageType = t_RcpMessage.RPD_CONFIGURATION
    rpd_data_msg = t_RpdDataMessage()
    rpd_data_msg.RpdDataOperation = t_RpdDataMessage.RPD_CFG_READ
    payload = config()
    if True:  # check vendor driver return status
        # payload.RpdCapabilities.NumBdirPorts.set_val(0)
        payload.RpdCapabilities.NumBdirPorts = 0
        payload.RpdCapabilities.NumDsRfPorts = 1
        # Note typo bug 'Mum' that comes from RpdCapabilities.proto file
        payload.RpdCapabilities.NumUsRfPorts = 2
        payload.RpdCapabilities.NumTenGeNsPorts = 1
        payload.RpdCapabilities.NumOneGeNsPorts = 1
        payload.RpdCapabilities.NumDsScQamChannels = 160
        payload.RpdCapabilities.NumDsOfdmChannels = 5
        payload.RpdCapabilities.NumUsScQamChannels = 5
        payload.RpdCapabilities.NumUsOfdmaChannels = 5
        payload.RpdCapabilities.NumDsOob55d1Channels = 16
        payload.RpdCapabilities.NumUsOob55d1Channels = 16
        payload.RpdCapabilities.NumOob55d2Modules = 1
        payload.RpdCapabilities.NumUsOob55d2Demodulators = 10
        payload.RpdCapabilities.NumNdfChannels = 8
        payload.RpdCapabilities.NumNdrChannels = 8
        payload.RpdCapabilities.SupportsUdpEncap = 1
        payload.RpdCapabilities.NumDsPspFlows = 4
        payload.RpdCapabilities.NumUsPspFlows = 4
        payload.RpdCapabilities.PilotToneCapabilities.NumCwToneGens = 4
        payload.RpdCapabilities.PilotToneCapabilities.LowestCwToneFreq = 50000000
        payload.RpdCapabilities.PilotToneCapabilities.HighestCwToneFreq = 1218000000
        payload.RpdCapabilities.PilotToneCapabilities.MaxPowerDedCwTone = 100
        payload.RpdCapabilities.PilotToneCapabilities.QamAsPilot = 1
        payload.RpdCapabilities.PilotToneCapabilities.MinPowerDedCwTone = -330
        payload.RpdCapabilities.PilotToneCapabilities.MaxPowerQamCwTone = 90
        payload.RpdCapabilities.PilotToneCapabilities.MinPowerQamCwTone = -30

        payload.RpdCapabilities.NumAsyncVideoChannels = 20
        payload.RpdCapabilities.SupportsFlowTags = 1
        payload.RpdCapabilities.SupportsFrequencyTilt = 1
        payload.RpdCapabilities.TiltRange = 10
        payload.RpdCapabilities.OfdmConfigurationCapabilities.RequiresOfdmaImDurationConfig = 1
        # payload.RpdCapabilities.RdtiCapabilities.NumPtpPortsPerEnetPort = 1 # TODO - FIX this when support added.
        payload.RpdCapabilities.RpdIdentification.VendorName = "MaxLinear"
        payload.RpdCapabilities.RpdIdentification.VendorId = "XX"  # This shouldn't be a string but a 16 bit integer
        payload.RpdCapabilities.RpdIdentification.ModelNumber = "x1"
        payload.RpdCapabilities.RpdIdentification.DeviceMacAddress = "66:55:44:33:22:11"
        payload.RpdCapabilities.RpdIdentification.CurrentSwVersion = "V1.0.5"
        payload.RpdCapabilities.RpdIdentification.BootRomVersion = "V0.0.1"
        payload.RpdCapabilities.RpdIdentification.DeviceDescription = "R-PHY from MaxLinear"
        payload.RpdCapabilities.RpdIdentification.DeviceAlias = "RPD"
        payload.RpdCapabilities.RpdIdentification.SerialNumber = "991234"
        payload.RpdCapabilities.RpdIdentification.UsBurstReceiverVendorId = "XX"  # This shouldn't be a string but a 16 bit integer
        payload.RpdCapabilities.RpdIdentification.UsBurstReceiverModelNumber = "ven1456"
        payload.RpdCapabilities.RpdIdentification.UsBurstReceiverDriverVersion = "V1.1"
        payload.RpdCapabilities.RpdIdentification.UsBurstReceiverSerialNumber = "99901"
        payload.RpdCapabilities.RpdIdentification.RpdRcpProtocolVersion = "V1.0.0"
        payload.RpdCapabilities.RpdIdentification.RpdRcpSchemaVersion = "V1.0.10"
        reachAbility = payload.RpdCapabilities.LcceChannelReachability.add()
        reachAbility.EnetPortIndex = 1
        reachAbility.ChannelType = 2
        reachAbility.RfPortIndex = 1
        reachAbility.StartChannelIndex = 9
        reachAbility.EndChannelIndex = 20
        rcp_msg.RcpDataResult = t_RcpMessage.RCP_RESULT_OK
        logger.info("Get Capabilities payload: %s" % payload)
    else:
        rcp_msg.RcpDataResult = t_RcpMessage.RCP_RESULT_GENERAL_ERROR
    rpd_data_msg.RpdData.CopyFrom(payload)
    rcp_msg.RpdDataMessage.CopyFrom(rpd_data_msg)
    cfg.msg.CfgMsgPayload = rcp_msg.SerializeToString()
    return cfg