def __init__(self, simulator=False): """ :param simulator: Simulator is used to run the program with interface simulator mode """ # initiate agent dict which need to start, and corresponding instance created self.agent_dict = self.build_agent_dict(simulator) self.simulator_flag = simulator if simulator: self.manager_cmd_line = "python -m rpd.provision.manager.src.manager_process -s".split( ) self.hal_cmd_line = None self.fake_driver_cmd_line = None self.ptp_driver_cmd_line = None self.ssd_driver_cmd_line = None self.res_hal_cmd_line = None else: self.manager_cmd_line = "python -m rpd.provision.manager.src.manager_process".split( ) self.hal_cmd_line = "python -m rpd.hal.src.HalMain --conf=/etc/config/hal.conf".split( ) self.res_hal_cmd_line = "python -m rpd.resource.src.RpdResHalClient".split( ) if SysTools.is_vrpd(): self.fake_driver_cmd_line = "python -m rpd.hal.lib.drivers.HalDriver0".split( ) self.ptp_driver_cmd_line = "python -m rpd.hal.lib.drivers.HalPtpDriver".split( ) self.ssd_driver_cmd_line = None else: # pragma: no cover self.fake_driver_cmd_line = "python -m rpdHalDrv.HalDriverClient".split( ) self.ptp_driver_cmd_line = "python -m rpdPtpHalDrv.PtpHalDriverClient".split( ) self.ssd_driver_cmd_line = "python -m rpd.ssd.HalSsdDriver".split( ) self.fault_manager_cmd_line = "python -m rpd.common.rpd_fault_manager".split( ) self.agent_obj = {} self.manager_process = None self.hal_process = None self.fake_driver_process = None self.ptp_driver_process = None self.monitor_driver_process = None self.res_driver_process = None self.ssd_driver_process = None
def config_rsyslog_remote(self, address): # write to remote server, check whether it's been configured already. conf = open('/etc/rsyslog.conf', 'r') server_configed = conf.read() address_configed = server_configed.find(address) conf.close() if address_configed > 0: self.logger.info( "Log Server IP address provided for remote logging already configed" ) return conf = open('/etc/rsyslog.conf', 'a+') # write to remote logserver, TCP to logserver conf.write("\n") remote_channel = "*." + self.rsyslog_loglevel + " @" + address conf.write(remote_channel) conf.write("\n") conf.close() if SysTools.is_vrpd(): hostmac = SysTools.get_mac_address("eth0") else: hostmac = SysTools.get_sys_mac_address() hostname = 'RPD' + hostmac.replace(':', '') set_host_cmd = 'echo ' + hostname + '>/proc/sys/kernel/hostname' os.system(set_host_cmd) new_hostline = hostname + " localhost" # write to /etc/hosts new_host = open('/tmp/new_hosts', 'w') old_host = open('/etc/hosts', 'r') line = old_host.read() found = line.find('localhost') configed = line.find('RPD') if found > 0 and configed < 0: new_host.write(line.replace('localhost', str(new_hostline))) else: new_host.write(line) old_host.close() new_host.flush() new_host.close() os.remove('/etc/hosts') shutil.move('/tmp/new_hosts', '/etc/hosts') return
def rpd_dependency(self): rpd_rsyslogd = 0 rpd_redis_server = 0 rpd_platform = 0 while rpd_rsyslogd == 0 or rpd_redis_server == 0: for proc in psutil.process_iter(): # check rsyslogd try: if proc.name() == "rsyslogd": rpd_rsyslogd = 1 if proc.name() == "redis-server": rpd_redis_server = 1 except psutil.NoSuchProcess: # pragma: no cover pass time.sleep(3) while rpd_platform == 0 and not SysTools.is_vrpd(): # pragma: no cover if os.path.exists("/tmp/platform_ok"): rpd_platform = 1 time.sleep(3) print "rpd dependencies software is up" return
def _decode_process(self): """Implements decoding of RCP sequences :raises RCPSequenceDecodeError """ if self.get_max_len() < self.DOCSIS_AND_MAC_HEADER_LEN: raise DocsisMsgDecodeError( "Docsis mac message buffer length ({}) is too low, min length " "is {} bytes".format(self.get_max_len(), self.DOCSIS_AND_MAC_HEADER_LEN)) # decode the Mac Header MacHeaderLen = 0 headVal = list() while MacHeaderLen < self.DOCSIS_AND_MAC_HEADER_LEN: headVal.extend(unpack_from("!B", self.buffer, self.offset)) self.offset += 1 MacHeaderLen += 1 # version = headVal[-3] # Parse the length field (offsets 12-13) from the MMM header. This # length includes the remainder of the MMM header (DSAP to end = 6 # bytes) and the payload. It does not include the CRC. length = ((headVal[self.DOCSIS_MAC_HEADER_LEN + 12] << 8) + headVal[self.DOCSIS_MAC_HEADER_LEN + 13]) # Make sure that the length field value is large enough to include the # rest of the DOCSIS MMM header (DSAP to end = 6 bytes). if length < 6: raise DocsisMsgDecodeError("DOCSIS MMM header length field value " "is too small ({} < 6)".format(length)) # Subtract the length of the rest of the DOCSIS MMM header. The length # value will now equal the length of the MMM payload (no CRC). length = length - 6 # Make sure that the length field value is not larger than the rest of # the buffer. if length > self.get_max_len(): raise DocsisMsgDecodeError("DOCSIS MMM header length field value " "is too large ({} > {})".format( length, self.get_max_len())) # Calculate the number of bytes in the buffer after the MMM payload. appended_length = self.get_max_len() - length if (appended_length != 0) and (appended_length != 4): raise DocsisMsgDecodeError( "DOCSIS message has an unexpected number " "of bytes appended ({}).".format(appended_length)) # Reduce the buffer size to only include the MMM payload, eliminating # the CRC (if present). self.trim_max_len(appended_length) type = headVal[-2] if type in [ 2, 29, 35, ]: self.logger.debug("this is a Docsis Message with UCD") self.msgtype = MsgTypeDocsisMsgUCD self.tlvFmts = rcp_tlv_def.UCD_TLV_SET.child_dict_by_id self.macMsgHdrLen = self.UCD_MAC_MESSAGE_HDR_LEN self.HeaderDef = self.UCDHeaderDef self.convert_to_RCPSequence = self.UCD_to_RCPSequence self._update_tlv_dict(parent_gpb=ucd_gpb(), parent_fmt=rcp_tlv_def.UCD_TLV_SET) self.BurstProfile = list() elif type in [ 51, ]: self.logger.debug("this is a Docsis Message with OFDMA UCD") self.tlvFmts = rcp_tlv_def.UCD_TLV_SET.child_dict_by_id self.macMsgHdrLen = self.UCD_MAC_MESSAGE_HDR_LEN self.HeaderDef = self.UCDHeaderDef if SysTools.is_vrpd() and SKIP_PARSING_DOCSIS_3p1 == False: self.msgtype = MsgTypeDocsisMsgUCD self.convert_to_RCPSequence = self.UCD3d1_to_RCPSequence else: self.msgtype = None self.convert_to_RCPSequence = self.skip_convert self.logger.debug( "UCD OFDMA parsing is skipped and msgtype is set to: %s" % (self.msgtype)) self._update_tlv_dict(parent_gpb=ucd_gpb(), parent_fmt=rcp_tlv_def.UCD_TLV_SET) self.BurstProfile = list() elif type in [ 49, ]: self.logger.debug("this is a Docsis Message with OCD") self.msgtype = MsgTypeDocsisMsgOCD self.tlvFmts = rcp_tlv_def.OCD_TLV_SET.child_dict_by_id self.macMsgHdrLen = self.OCD_MAC_MESSAGE_HDR_LEN self.HeaderDef = self.OCDHeaderDef if SysTools.is_vrpd(): self.convert_to_RCPSequence = self.OCD_to_RCPSequence else: self.convert_to_RCPSequence = self.skip_convert self._update_tlv_dict(parent_gpb=ocd_gpb(), parent_fmt=rcp_tlv_def.OCD_TLV_SET) elif type in [ 50, ]: self.logger.debug("this is a Docsis Message with DPD") self.msgtype = MsgTypeDocsisMsgDPD self.tlvFmts = rcp_tlv_def.DPD_TLV_SET.child_dict_by_id self.macMsgHdrLen = self.DPD_MAC_MESSAGE_HDR_LEN self.HeaderDef = self.DPDHeaderDef if SysTools.is_vrpd(): self.convert_to_RCPSequence = self.DPD_to_RCPSequence else: self.convert_to_RCPSequence = self.skip_convert self._update_tlv_dict(parent_gpb=dpd_gpb(), parent_fmt=rcp_tlv_def.DPD_TLV_SET) else: self.logger.error( "this is a Docsis Message " "with unsupported type: %d", type) self.convert_to_RCPSequence = self.skip_convert return gcp_object.GCPObject.DECODE_FAILED # self.logger.info ("_decode_process: len %d, offset: %d" %(self.get_max_len(), self.offset)) for entry in self.HeaderDef: val = unpack_from(entry[1], self.buffer, self.offset) self.headDict[entry[0]] = val[0] self.offset += 1 sequence_length = self.get_max_len() try: ret = self._fast_decode(self.parent_fmt, self.parent_gpb, self.offset, sequence_length, 0, tl_format="!BB", tl_offset=2) self.offset += sequence_length # update the offset except Exception as e: self.logger.error( "Docsis message Failed to decode TLVs of " "sequence, unexpected reason: %s", str(e)) return gcp_object.GCPObject.DECODE_FAILED if ret != gcp_object.GCPObject.DECODE_DONE: self.logger.error( "Docsis message Failed to decode TLVs of " "sequence, unexpected result: %u", ret) return gcp_object.GCPObject.DECODE_FAILED # self.logger.info ("_decode_process: len %d, offset: %d, done!" %(self.get_max_len(), self.offset)) # extra data need to be decoded if type in [ 2, 29, 35, ] or (type == 51 and SKIP_PARSING_DOCSIS_3p1 == False): # decode the BurstProfile for burstProfiles in (self.parent_gpb.BurstDescDocsis1x, self.parent_gpb.BurstDescDocsis2x3x, self.parent_gpb.BurstDescDocsis3d1): burstType = 4 if (burstProfiles == self.parent_gpb.BurstDescDocsis2x3x): burstType = 5 elif (burstProfiles == self.parent_gpb.BurstDescDocsis3d1): burstType = 23 for burstProfileData in burstProfiles: burstProfile = UCDBurstProfile(burstType, 0, ucdBurst_gpb()) if burstProfile.decode(burstProfileData, 0, len(burstProfileData)) == \ gcp_object.GCPObject.DECODE_DONE: self.BurstProfile.append(burstProfile) else: self.logger.info("DocsisMessage DECODE FAILED") return gcp_object.GCPObject.DECODE_FAILED return gcp_object.GCPObject.DECODE_DONE