void CEntryPointApp::SaveTimeouts(std::map<unsigned int, int> &p_rExpiredCmds) { IEPDBMngtBase::DBResponse oDBRsp; CTagGroup oRsp("DBParameters"); CTagParameters::TagParam oTimeoutParam; oTimeoutParam.name = "Timeout"; oTimeoutParam.type = CTagParameters::TVT_NUMBER; map<unsigned int, int>::iterator it = p_rExpiredCmds.begin(); for (; it != p_rExpiredCmds.end(); it++) { oTimeoutParam.buffer = IntToStr(it->second); oRsp.AddTagParameter(oTimeoutParam); oDBRsp.trackingNo = it->first; CTagParamsParser::RootTagGroupToXML(oRsp, oDBRsp.parsedResp); if (m_dbMngt->SaveDBResp(oDBRsp, 0)) { NLOG_INFO("[MainApp] command marked as timeouted, trackingID=%d timeOut=%d", oDBRsp.trackingNo, it->second); } else { NLOG_INFO("[MainApp] command mark as timeouted failed, trackingID=%d timeOut=%d", oDBRsp.trackingNo, it->second); } oRsp.Clear(); } }
void Run() { NLOG_INFO("Thread [%s] Start...", m_threadName); int ret = 0; for(int i= GetCounter(); i <= m_requestCount; i= GetCounter()){ ClientCtx* ctx = GetCtx(); ret = m_requestCb(i, ctx, m_args); if(ret== 0){ AtomInt_Inc(&g_errors[0]); }else{ if(ret < 0){ AtomInt_Inc(&g_errors[ERRNO_UNKNOW]); }else{ AtomInt_Inc(&g_errors[ret%0xFFFF]); } } if(i % m_num == 0){ double usedtime = g_now_second -g_start; //NLOG_DEBUG("start:%.3f - now:%.3f", g_start, g_now_second); printf("Request %d time:%.3f\n", i, usedtime); } if(g_stop) break; } NLOG_INFO("Thread [%s] Stop...", m_threadName); }
void CIPGRegUpdCmd::Execute() { NLOG_INFO("[IPGRegUpdCmd]: received msg = %s", MsgToStr(m_rMsg).c_str()); CMgmtPOption::OptionIPGatewayInfoData *pOpData1 = NULL; std::list<CMgmtPOption::OptionIPRoutesListData> rawRouteInfo; CMgmtPOption::OptionKeepAliveIntervalData *pOpData2 = NULL; if (!ProcessMsg(&pOpData1, rawRouteInfo, &pOpData2)) { if (m_rIPGList.find(CIPGInfo (m_rMsg.m_oNetAddr)) == m_rIPGList.end()) NLOG_ERR("[IPGRegUpdCmd]: MODULE=%s was not added in CACHE because of invalid register/update INFO ", AddrToStr(m_rMsg.m_oNetAddr).c_str()); return; } ///add module if it doesn't exist CIPGInfo key(m_rMsg.m_oNetAddr); std::set<CIPGInfo>::iterator i = m_rIPGList.find(key); bool isNewIPG = false; if (i == m_rIPGList.end()) { ///FIRST CTunnelKey info(pOpData1->m_IPGAddrIPv4, pOpData1->m_szIPGAddrIPv6, 128); if (m_rFARAndIPGPubInf.insert(info).second == false) { NLOG_WARN("[IPGRegUpdCmd]: MODULE=%s was not added in CACHE because of duplicated publicInfo=%s, " "skip processing msg = %s", AddrToStr(m_rMsg.m_oNetAddr).c_str(), TunnelKeyToStr(info).c_str(), MsgToStr(m_rMsg).c_str()); return; } isNewIPG = true; i = m_rIPGList.insert(CIPGInfo(m_rMsg.m_oNetAddr, CModuleInfo::MT_REGISTERED)).first; i->SetPendingTimedout(m_rApp.GetConfig().m_nPendingRelationTimedoutS); } CIPGInfo *pIPGInfo = (CIPGInfo*)&(*i); pIPGInfo->SetTimedOut(CModuleInfo::MTT_KEEP_ALIVE, pOpData2->m_IntSec, pOpData2->m_IntUSec); pIPGInfo->SetPublicIpgInfo(*pOpData1); if(pIPGInfo->GetState() != CModuleInfo::MT_REGISTERED) pIPGInfo->SetState(CModuleInfo::MT_REGISTERED); ///process std::list<CMgmtPOption::OptionIPRoutesListData> IPGAddedRoute; std::list<CMgmtPOption::OptionIPRoutesListData> IPGEraseRoute; ProcessRegIPG(i, isNewIPG, rawRouteInfo, IPGAddedRoute, IPGEraseRoute); NLOG_INFO("[IPGRegUpdCmd]: raw(routes=%d), add(routes=%d), erase(routes=%d)", rawRouteInfo.size(), IPGAddedRoute.size(), IPGEraseRoute.size()); ///send result if (IPGAddedRoute.size() > 0) //SendAddTunnOnIPG(m_rMsg.m_oNetAddr, IPGAddedTun); -- not add only the difference but all SendSetTunnOnIPG(i); if (IPGEraseRoute.size() > 0) SendDelTunnOnIPG(m_rMsg.m_oNetAddr, IPGEraseRoute, m_rApp); }
/** * 上下文初始化 */ int TestContext::ctx_init(ngx_cycle_t* cycle) { test_config_t* cfg = &this->m_config; this->m_cycle = cycle; this->m_mysql_pool = mysql_pool_new(cfg->mysql_config.conns, &cfg->mysql_config); NLOG_INFO("[%d] mysql_pool: %p", ngx_getpid(), this->m_mysql_pool); #define SQL_CREATE_TBL "drop table if exists ngx_test; "\ "create table ngx_test(`key` varchar(32) primary key,value int default 0); "\ "insert into ngx_test values('testkey', 0);" int ret = 0; MYSQL* mysql = this->mysql_get(); if(mysql == NULL){ NLOG_ERROR("get mysql connection failed!"); ret = ERRNO_SYSTEM; return ret; } NLOG_INFO("init ngx_test table!"); ret = mysql_queryex(mysql, SQL_CREATE_TBL); NLOG_INFO("init ngx_test table ret:%d", ret); if(ret == 0){ mysql_free_all_result(mysql); }else{ NLOG_ERROR("init table failed!ret:%d, sql:[%s]", ret, SQL_CREATE_TBL); ret = ERRNO_SYSTEM; } // 在Init中取得的链接必须关闭掉,因为这个链接不是非阻塞的。 this->mysql_close(mysql); return NGX_OK; }
/////////////////////////////////////////////////////////////////////////////// ///@author Costin Grigorescu ///@brief Forward DAO to EntryPoint ///@param [in] p_nDataFieldDescriptor - Data field descriptor ///@param [in] p_pPayload - DAO message ///@param [in] p_nPayloadLength - DAO message len ///@retval 0 - failed to send ///@retval 1 - success /////////////////////////////////////////////////////////////////////////////// void CRplRootApp::AddDAORelayEncap(MgmtProtocol::CMgmtPMessage::MsgDAORelayData::DataFieldDescriptorType p_nDataFieldDescriptor, const uint8_t* p_pPayload, uint16_t p_nPayloadLength){ MgmtProtocol::CMgmtPMessage::Ptr pMsg(new MgmtProtocol::CMgmtPMessage); //init header pMsg->m_Header.SetMsgType(MgmtProtocol::CMgmtPMessage::DAO_RELAY); pMsg->m_Header.m_u32SeqNo = m_pMgmtClientLink->m_oSeqNoGenerator.GetNextMsgId ( ); MgmtProtocol::CMgmtPMessage::MsgDAORelayData oMsgDAORelayData; // set far id oMsgDAORelayData.m_pu8_FAR_ID = GetFarId(); // set data field descriptor oMsgDAORelayData.m_u8_DataFieldDescriptor = p_nDataFieldDescriptor; // set DIO MOP oMsgDAORelayData.m_u8_DIO_MOP = GET_MOP( &g_oRplInstance.m_oRplConfig ); // set lifetime_unit oMsgDAORelayData.m_u16_DIOLifetimeUnit = m_stCfg.m_oMapConfig.m_oRplProfile.m_nDefRouteLifetimeUnit; // set DAO message oMsgDAORelayData.m_pu8_DAOData = p_pPayload; oMsgDAORelayData.m_u32_DAODataLen = p_nPayloadLength; NLOG_INFO( "Encap+ DAO_RELAY: far=%s, dfd=%d, dao_len=%d", GetHex( oMsgDAORelayData.m_pu8_FAR_ID, oMsgDAORelayData.m_st_u8_FAR_ID_Len ), oMsgDAORelayData.m_u8_DataFieldDescriptor, oMsgDAORelayData.m_u32_DAODataLen ); NLOG_DBG( "\tdao=%s", GetHex( oMsgDAORelayData.m_pu8_DAOData, oMsgDAORelayData.m_u32_DAODataLen ) ); pMsg->SetData(&oMsgDAORelayData); m_shpoCnsDaoMsg->OptionAddEncap(pMsg.get()); }
int main (int argc, char ** argv) { CUdpSocket s; g_stLog.OpenStdout() ; s.Create (SOCK_DGRAM, AF_INET6); if (setsockopt (s, SOL_SOCKET, SO_BINDTODEVICE, "eth0", strlen ("eth0"))) { LOG_ERR("setsockopt"); return false; } s.Bind (atoi (argv[2]), argv[1], "eth0"); //"2001:db8:0:85a3::ac1f:8001" size_t N = 1000; char msg[N]; //s.SendTo6 ("2001:db8:0:85a3::ac1f:8001", 2345, MSG, sizeof (MSG)); while (strncmp ("quit", msg, 4)) { memset (msg,0,1000); s.RecvFrom6(msg, &N); NLOG_INFO ("MSG: %d %s", N, msg); N=1000; } }
void CRplNodeRsp::ProcessPublish() { IEPDBMngtBase::DBPublish dbPubl; memcpy(dbPubl.sourceID, m_rDevMsg->m_oDstAddr.GetIPv6() + 8, sizeof(dbPubl.sourceID)); if (!MsgDataToXML(dbPubl.parsedMsg, false)) { return; } NLOG_DBG("[RplNodeRsp::ProcessPublish]: XML publish: %s", dbPubl.parsedMsg.c_str()); if (!m_rDBMngt.SaveNodePublish(m_rDevMsg->MsgType(), dbPubl, m_rDevMsg)) { NLOG_ERR("[RplNodeRsp::ProcessPublish]: failed to save msg from %s", BuffToHEXStr(dbPubl.sourceID, sizeof(dbPubl.sourceID)).c_str()); return; } if (m_rDevMsg->MsgType() == UdpEventNodeRegistration) { NLOG_INFO("[RplNodeRsp::ProcessPublish]: Sending ACK for UdpEventNodeRegistration"); //build message unsigned int size = sizeof(struct QueryHdr); unsigned char msg[size]; memset(msg,0,size); //hdr SetQueryHdr(msg, UdpQueryAck, 2, m_rDevMsg->SequenceNum()); TDeviceMsg *pDevMsg = new TDeviceMsg(m_rDevMsg->m_oDstAddr, msg, size, m_rDevMsg->SequenceNum(), false); m_rWriteQueue->Push(TDeviceMsg::Ptr(pDevMsg)); } }
MgmtProtocol::CMgmtPMessage::Ptr CRplRootNetStat :: ReportMgmtMessage( MgmtProtocol::CMgmtPMessage::Ptr &p_pMessage ) { MgmtProtocol::CMgmtPMessage::MsgFarNetStatCommData oMsgNetStatComm; bool prev; if ( !p_pMessage->GetData( &oMsgNetStatComm ) ) { NLOG_WARN( "ReportMgmtMessage: Invalid NetStat request." ); } p_pMessage->m_Header.SetMsgType( MgmtProtocol::CMgmtPMessage::FAR_NETSTAT, true ); p_pMessage->m_Header.m_u8DestinationType = p_pMessage->m_Header.m_u8SourceType; p_pMessage->m_Header.m_u8SourceType = MgmtProtocol::MOD_GR; if (oMsgNetStatComm.m_ucFlags & MgmtProtocol::CMgmtPMessage::MsgFarNetStatCommData::LastPeriod ) { NLOG_INFO( "ReportMgmtMessage: reporting on previous record." ); prev = true; } else { NLOG_INFO( "ReportMgmtMessage: reporting on current record." ); prev = false; } if (oMsgNetStatComm.m_ucFlags & MgmtProtocol::CMgmtPMessage::MsgFarNetStatCommData::ResetCurrentStats ) { NLOG_INFO( "ReportMgmtMessage: resetting records." ); } else { NLOG_INFO( "ReportMgmtMessage: not resetting stats." ); } FarNetStatRecord &rReportedRecord = ( oMsgNetStatComm.m_ucFlags & MgmtProtocol::CMgmtPMessage::MsgFarNetStatCommData::LastPeriod ) ? m_oPrevRecord : m_oCrntRecord; SetMgmtMessageData(p_pMessage, rReportedRecord, prev); //if (!( oMsgNetStatComm.m_ucFlags & MgmtProtocol::CMgmtPMessage::MsgFarNetStatCommData::LastPeriod )) // m_oPrevRecord = m_oCrntRecord; if ( oMsgNetStatComm.m_ucFlags & MgmtProtocol::CMgmtPMessage::MsgFarNetStatCommData::ResetCurrentStats ) m_oCrntRecord.ResetStats(); return p_pMessage; }
////////////////////////////////////////////////////////////////////////////// /// @brief Parse the current CRadioMessage and creates a string /// @param [in] If true and message encrypted will display it decrypted /// @retval The string describing object structure information - detalied ////////////////////////////////////////////////////////////////////////////// string CRadioMessage::ToString(bool p_bDecrypt /*= false*/) { ostringstream oBuf; uint8_t *pu8DecryptedPayload = NULL; uint32_t u32DecryptedLength = 0; bool bEncryptedWithDefaultKey = false; oBuf << TypeStr() << " CRadioMessage [ ID: " << m_u32ID << " ] "; oBuf << " Time: " << m_u32ReceivedTime << " "; if(m_u1HMAC) oBuf << "<HMAC> "; if(m_u1Signed) oBuf << "<Signed> "; if(m_u1Compressed) oBuf << "<Compressed> "; if(m_u1Encrypted) oBuf << "<Encrypted> "; // All useful information oBuf << "\nRemote: " << CAdapterUtil::IntToHexStr(m_u32RemoteLANAddress) << " [" << CAdapterUtil::Int64ToHexStr(m_u64RemoteWANAddress) << "]" << ", "; oBuf << "Local: " << CAdapterUtil::IntToHexStr(m_u32LocalLANAddress) << " [" << CAdapterUtil::Int64ToHexStr(m_u64LocalWANAddress) << "]" << "\n"; oBuf << "Priority: " << (int)m_u8Priority << ", TTL: " << m_u16TimeToLive << ", Hops: " << (int)m_u8MaxHops; oBuf << ", Mood: " << (int)m_u8Mood << ", Receipt: " << (int)m_u8ReturnReceipt; // Check if it is a small/big resident DCW if(m_u32RemoteLANAddress == 0xFEFEFE7D) oBuf << " <Small DCW>"; else if(m_u32RemoteLANAddress == 0xFEFEFE7E) oBuf << " <Big DCW>"; // Display hex formatted payload oBuf << ", Payload " << ((p_bDecrypt && m_u1Encrypted) ? "<Decrypted>" : "" ) << ": \n" << "------------------------------------------------------------------------\n"; if(p_bDecrypt && m_u1Encrypted) { // Decrypt packet u32DecryptedLength = m_u32PayloadLength - ENC_HMAC_SIZE_USED + AES_BLOCK_SIZE; pu8DecryptedPayload = new uint8_t[u32DecryptedLength]; if(!CEncryption::LGDecrypt(m_pu8Payload, m_u32PayloadLength, m_u32RemoteLANAddress, m_u32ID, m_u8ReturnReceipt, m_u4MessageType, m_u1Encrypted, pu8DecryptedPayload, u32DecryptedLength, bEncryptedWithDefaultKey)) { NLOG_ERR("Cannot decrypt packet to display data!"); oBuf << CAdapterUtil::GetFormattedHex(m_pu8Payload, m_u32PayloadLength); } else { NLOG_INFO("Packet was succesfully decrypted to be displayed."); oBuf << CAdapterUtil::GetFormattedHex(pu8DecryptedPayload, u32DecryptedLength); } delete[] pu8DecryptedPayload; } else oBuf << CAdapterUtil::GetFormattedHex(m_pu8Payload, m_u32PayloadLength); return oBuf.str(); }
bool CEPAppLink::RepairConnection() { if(m_oUdpSocket.IsValid()) { NLOG_INFO("Link[%s]: no need to repair, link seems to be valid", m_szLinkName); return true; } return (m_oUdpSocket.Create(SOCK_DGRAM, m_nSocketFamily) && m_oUdpSocket.Bind(m_nPort)); }
void CSumiNodeTesterApp::Close() { delete [] m_pu8UdpPyld; NLOG_INFO("Closing serial device..."); if( m_poBufferedSerialLink != NULL ) m_poBufferedSerialLink->CloseLink(); delete m_poBufferedSerialLink; CApp::Close(); }
bool CRplRootNetStat :: Restore( const char *p_szFileName ) { NLOG_INFO( "CRplRootNetStat::Restore()" ); char szTemp[128]; char *result; FILE *fp = fopen( p_szFileName, "r" ); if ( fp == NULL ) return false; do { result = fgets( szTemp, sizeof( szTemp ), fp ); if ( result == NULL ) return false; } while ( *result == '\n' ); if ( strncmp( szTemp, "[STAT]", strlen( "[STAT]" ) ) ) return false; int tmpOn; if ( fscanf( fp, "ON = %d\n", &tmpOn ) != 1 ) return false; else m_bOn = tmpOn; do { result = fgets( szTemp, sizeof( szTemp ), fp ); if ( result == NULL ) return false; } while ( *result == '\n' ); if ( strncmp( szTemp, "[CRNT]", strlen( "[CRNT]" ) ) ) return false; ReadRecordContent( m_oCrntRecord, fp ); do { result = fgets( szTemp, sizeof( szTemp ), fp ); if ( result == NULL ) return false; } while ( *result == '\n' ); if ( strncmp( szTemp, "[PREV]", strlen( "[PREV]" ) ) ) return false; ReadRecordContent( m_oPrevRecord, fp ); fclose( fp ); return true; }
bool CSumiNodeTesterApp::SendUdpData() { static unsigned int s_unUdpMsgId = 0; //msg header uint8_t u8CurrSerialMsgId = g_u8SerialMsgId; API_MSG_HDR *pUDPSendDatagramHdr = (API_MSG_HDR*)g_pucSendBuf; SET_API_HDR(pUDPSendDatagramHdr, UDP_SPECIFIC, API_MSG_REQ, UDP_SEND_DATAGRAM, g_u8SerialMsgId, sizeof(UDP_SEND_DATAGRAM_PYLD) + m_stCfg.GetUdpPyldSize()); ++g_u8SerialMsgId; //msg payload UDP_SEND_DATAGRAM_PYLD *pUDPSendDatagramPyld = (UDP_SEND_DATAGRAM_PYLD*)(g_pucSendBuf + sizeof(API_MSG_HDR)); UDP_SEND_DATAGRAM_SET_SRC_PORT(pUDPSendDatagramPyld, m_stCfg.GetUdpLocalPort()); UDP_SEND_DATAGRAM_SET_DST_PORT(pUDPSendDatagramPyld, m_stCfg.GetCoordIpv6()->GetPort()); memcpy(pUDPSendDatagramPyld->m_au8DstIpv6, m_stCfg.GetCoordIpv6()->GetIPv6(), 16); //msg udp payload UDP_PYLD_ID *pUDPPyldId = (UDP_PYLD_ID*)(g_pucSendBuf + sizeof(API_MSG_HDR) + sizeof(UDP_SEND_DATAGRAM_PYLD)); unsigned int unUdpMsgId = s_unUdpMsgId; SET_UDP_PYLD_ID(pUDPPyldId, unUdpMsgId); s_unUdpMsgId++; memcpy(g_pucSendBuf + sizeof(API_MSG_HDR) + sizeof( UDP_SEND_DATAGRAM_PYLD ) + sizeof(s_unUdpMsgId), m_pu8UdpPyld, m_stCfg.GetUdpPyldSize() - sizeof(s_unUdpMsgId) ); int nBytesToSend = sizeof(API_MSG_HDR) + sizeof(UDP_SEND_DATAGRAM_PYLD) + m_stCfg.GetUdpPyldSize(); //Send over serial device int nSentData = m_poBufferedSerialLink->Write(g_pucSendBuf, nBytesToSend); if(nSentData <= 0) { NLOG_ERR("FAILED TO SEND UDP_SEND_DATAGRAM ON SERIAL LINK!"); return false; } //log msg NLOG_INFO("Sent data: addr=%s:%d, len=%d, UDP_ID=%d", GetHex(m_stCfg.GetCoordIpv6()->GetIPv6(),16), m_stCfg.GetCoordIpv6()->GetPort(), m_stCfg.GetUdpPyldSize(), unUdpMsgId); memset(g_aucLogBuf,0,sizeof(g_aucLogBuf)); Bin2Hex((char*)g_aucLogBuf, sizeof(g_aucLogBuf), (char*)g_pucSendBuf + sizeof(API_MSG_HDR) + sizeof(UDP_SEND_DATAGRAM_PYLD), m_stCfg.GetUdpPyldSize()); NLOG_INFO("Datagram payload: %s", g_aucLogBuf); // g_oSumiStats.AddSentNewUdpMsg(u8CurrSerialMsgId, unUdpMsgId, m_stCfg.GetUDPRespTimedoutSec()); return true; }
int CTimer::RestartTimer(double first, double interval){ //时间间隔有变化 。 if(m_first != first || m_interval != interval){ NLOG_INFO("Timer [%s] Restarted [first:%.3lf, interval:%.3lf]", m_name, first, interval); StopTimer(); return StartTimer(first, interval); } return 0; }
int CConfig_DNS::Init(const char* p_szModuleName) { if (!CConfig::Init(p_szModuleName)) return 0; READ_DEFAULT_VARIABLE_INT("PORT", m_nPort, DEFAULT_PORT); READ_DEFAULT_VARIABLE_INT("RELOAD_PERIOD", m_nReloadPeriodSeconds, DEFAULT_RELOAD_PERIOD); READ_DEFAULT_VARIABLE_NET_ADDR_EXT("NOTIF_ADDR", m_oNotifAddr, DEFAULT_NOTIF_ADDR); /*********************************************************************** * Load name patterns **********************************************************************/ char szPatternValue[MAX_PATTERN_LEN]; for (int pos = 0; GetVar("NAME_PATTERN", szPatternValue, sizeof szPatternValue, pos); ++pos) { char szPrefix[MAX_PATTERN_LEN] = { 0, }; unsigned uDeviceIdLen = 0; char szSuffix[MAX_PATTERN_LEN] = { 0, }; if ( int p = sscanf( szPatternValue, "%[0-9a-zA-Z._-],%d,%[0-9a-zA-Z._-]", szPrefix, &uDeviceIdLen, szSuffix ) < 3 ) { NLOG_WARN( "Read %d parts (exp=3) from name pattern=%s", p, szPatternValue ); } CQNamePatternMatcher oQNamePatternMatcher; oQNamePatternMatcher.CompilePattern( szPrefix, 16, szSuffix ); m_oQNamePatternMatcherList.push_back( oQNamePatternMatcher ); } if (m_oQNamePatternMatcherList.empty()) { NLOG_INFO("Load default pattern"); CQNamePatternMatcher oQNamePatternMatcher; oQNamePatternMatcher.CompilePattern(DEFAULT_URL_PREFIX, 16, DEFAULT_URL_SUFFIX); m_oQNamePatternMatcherList.push_back(oQNamePatternMatcher); } NLOG_INFO("Loaded name patterns:"); for (TQNamePatternMatcherList::iterator it = m_oQNamePatternMatcherList.begin(); it != m_oQNamePatternMatcherList.end(); ++it) { NLOG_INFO("\t%s[%d]%s", it->GetPrefix(), it->GetDeviceIdLen(), it->GetSuffix()); } /**********************************************************************/ return 1; };
////////////////////////////////////////////////////////////////////////////// /// @brief Create our abstract socket, SSL or not /// @retval true if everything is ok, false otherwise /// @param [in] p_nType Socket type, like SOCK_STREAM /// @param [in] p_nFamily Socket family, like AF_INET ////////////////////////////////////////////////////////////////////////////// bool CAbstractSocket::Create(int p_nType /*= SOCK_STREAM*/, int p_nFamily /*= AF_INET*/) { if(m_bSSLFlag) { // Create socket if(m_oSecureSocket.Create(p_nType, p_nFamily)) { if(!m_oSecureSocket.InitSSL(CTcpSecureSocket::CLIENT_SIDE, NULL, NULL, NULL, TLS_1_0)) { NLOG_ERR("Cannot initialize SSL context!"); return false; } NLOG_INFO("SSL socket was succesfully created."); return true; } else { NLOG_ERR("Cannot create SSL socket!"); return false; } } // TcpSocket else { if(m_oNormalSocket.Create(p_nType, p_nFamily)) { NLOG_INFO("TcpSocket was succesfully created."); return true; } else { NLOG_ERR("Cannot create the TcpSocket!"); return false; } } }
void CIPGRegUpdCmd::ProcessRegIPG(IPGInfoListT::iterator p_itIPG, bool p_newIPG, std::list<CMgmtPOption::OptionIPRoutesListData> &p_rawRouteInfo, std::list<CMgmtPOption::OptionIPRoutesListData> &p_iIPGAddedRoute, std::list<CMgmtPOption::OptionIPRoutesListData> &p_rIPGEraseRoute) { const CIPGInfo *pIPGInfo = &(*p_itIPG); //clean-up input of garbage if necessary std::list<CMgmtPOption::OptionIPRoutesListData> routeToDel; CFAR_IPG_Proc::ClearGarbInRouteInfoFromIpg(pIPGInfo->GetPublicIpgInfo(), p_rawRouteInfo, routeToDel); ///it might be newIPG from cache point of view but with already info set on it if (p_newIPG) { //tunnels std::list<CMgmtPOption::OptionIPRoutesListData>::iterator kt = p_rawRouteInfo.begin(); int i = 0; for(; kt != p_rawRouteInfo.end(); ++kt) { CMgmtPOption::OptionIPRoutesListData &routeInf = *kt; NLOG_INFO("DELETEME: ipv4=%s", IPv4ToStr(*(unsigned int*)&routeInf.m_GatewayAddr[12]).c_str()); CTunnelKey farKey(*(unsigned int*)&routeInf.m_GatewayAddr[12], routeInf.m_NetPrefix, routeInf.m_NetPrefixLen); pIPGInfo->InsertPendRelatFAR(farKey); NLOG_INFO("[ProcessRegIPG]: new ipg_source_addr=%s comes with routeInfo[%d]=%s", AddrToStr(pIPGInfo->GetSourceAddr()).c_str(), i, RouteDataToStr(routeInf).c_str()); i++; } } ///inter_module_process m_rFAR_IPG_Proc.ProcessRegIPG(p_itIPG, p_newIPG, m_rFARList, p_rawRouteInfo, p_iIPGAddedRoute, p_rIPGEraseRoute); p_rIPGEraseRoute.insert(p_rIPGEraseRoute.end(), routeToDel.begin(), routeToDel.end()); }
void CRplRootNetStat :: Init( unsigned int p_unStatPeriodSec, unsigned int p_unNetStatGuardSec ) { NLOG_INFO( "CRplRootNetStat::Init()" ); if ( p_unStatPeriodSec == 0 ) { NLOG_WARN( "CRplRootNetStat::Init(): Can not start with period 0." ); return; } m_oCrntRecord.Init( p_unStatPeriodSec ); m_unNetStatGuardSec = p_unNetStatGuardSec; m_bOn = true; }
bool CEPAppLink::WriteMessage(const CEPAppMsg* p_pAppPMsg) { char addrBuffer[64]; p_pAppPMsg->m_netAddr.Print(addrBuffer, sizeof addrBuffer); bool sendResult = m_oUdpSocket.SendTo(&p_pAppPMsg->m_netAddr, (void*)p_pAppPMsg->m_ucPayload, p_pAppPMsg->m_unPayloadSize); if (!sendResult) { NLOG_ERR("Link[%s]: Send msg failed: dst[%s]", m_szLinkName, addrBuffer); if(!RepairConnection()) { NLOG_ERR("Link[%s]: failed to repair connection", m_szLinkName); } else { NLOG_INFO("Link[%s]: connection repaired", m_szLinkName); } } else { NLOG_INFO("Link[%s]:Send msg: %s", m_szLinkName, p_pAppPMsg->ToString().c_str()); } return sendResult; }
void CRplRootApp::AddTopologyNotificationEncap(MgmtProtocol::CMgmtPMessage::EventType p_enumEventType, const uint8_t* p_pu8NodeId, const TIpv6Prefix& p_rNodePrefix, MgmtProtocol::DeviceType p_enumNodeType, const uint8_t* p_pu8ParentId, MgmtProtocol::DeviceType p_enumParentType) { if (!m_stCfg.m_nTopologyMgmtMsgsEnabled) { return; } MgmtProtocol::CMgmtPMessage::Ptr pMsg(new MgmtProtocol::CMgmtPMessage); //init header pMsg->m_Header.SetMsgType(MgmtProtocol::CMgmtPMessage::TOPOLOGY_NOTIFICATION); pMsg->m_Header.m_u32SeqNo = m_pMgmtClientLink->m_oSeqNoGenerator.GetNextMsgId ( ); //init data MgmtProtocol::CMgmtPMessage::MsgTopologyNotifData oData; memset(&oData, 0, sizeof(oData)); oData.m_u8NotifType = (uint8_t) p_enumEventType; if (p_pu8NodeId) { memcpy (oData.m_au8DeviceId,p_pu8NodeId,IPv6_HOST_ID_LEN); } else { memcpy(oData.m_au8DeviceId, p_rNodePrefix.m_oIPv6Addr.m_pucBytes + PrefixLenInBytes(p_rNodePrefix.m_u8PrefixLen) - IPV6_DEVID_LEN, IPV6_DEVID_LEN); } oData.m_u8DeviceType = p_enumNodeType; memcpy (oData.m_au8DeviceAddrIPv6, p_rNodePrefix.m_oIPv6Addr.m_pucBytes, PrefixLenInBytes(p_rNodePrefix.m_u8PrefixLen)); oData.m_u8ParentType = p_enumParentType; memcpy(oData.m_au8ParentId, p_pu8ParentId, IPv6_HOST_ID_LEN); oData.m_u32Timestamp = (uint32_t)(time(NULL)); NLOG_INFO("Encap+ %s", oData.GetPrintable()); oData.HtoN(); pMsg->SetData((uint8_t*)(&oData), sizeof(oData)); m_shpoCnsTopoNotifMsg->OptionAddEncap(pMsg.get()); }
bool CNMS_DBMngt::GetSystemSetProp(unsigned int &val) { IDbSPHelper *pHelper = Connect(); if (pHelper == NULL) return false; // pHelper->CreateSPCommand("GetSystemSettingsProperty"); if (!pHelper->AddINParam(1, "NetworkPrefixesTimestamp")) { NLOG_ERR("NMS_DBMngt:GetSystemSetProp: failed to add param for sp -> GetSystemSettingsProperty!"); delete pHelper; return false; } char szValue[70]; if (!pHelper->AddOUTParam(2, (char*)szValue, (int)sizeof(szValue))) { NLOG_ERR("NMS_DBMngt:GetSystemSetProp: failed to add param for sp -> GetSystemSettingsProperty!"); delete pHelper; return false; } int errCode = 0; if (!pHelper->AddOUTParam(3, &errCode)) { NLOG_ERR("NMS_DBMngt:GetSystemSetProp: failed to add param for sp -> GetSystemSettingsProperty!"); delete pHelper; return false; } if (!pHelper->ExecuteQuery()) { NLOG_ERR("NMS_DBMngt:GetSystemSetProp: failed to execute query for sp -> GetSystemSettingsProperty!"); delete pHelper; return false; } if (errCode == 1) { NLOG_ERR("NMS_DBMngt:GetSystemSetProp: failed to execute query for sp -> GetSystemSettingsProperty! with err=%d", errCode); delete pHelper; return false; } sscanf(szValue, "%u", &val); NLOG_INFO("szValue=%s, and int=%d", szValue, val); delete pHelper; return true; }
CEPAppMsg* CEPAppLink::ReadMessage(int p_nTimeout) { if (!m_oUdpSocket.CheckRecv(p_nTimeout)) { return NULL; } CNetAddressExt oNetAddr; uint8_t pBuff[m_nMaxRcvBuffer]; size_t nLen = sizeof(pBuff); if (!m_oUdpSocket.RecvFrom(&oNetAddr, pBuff, &nLen)) { return NULL; } CEPAppMsg* msg = new CEPAppMsg(oNetAddr, pBuff, nLen, m_inMsgType); char addrBuffer[64]; msg->m_netAddr.Print(addrBuffer, sizeof addrBuffer); NLOG_INFO("Link[%s]:Rcv msg: %s", m_szLinkName, msg->ToString().c_str()); return msg; }
ngx_int_t ngx_http_shmtest_init_process(ngx_cycle_t *cycle) { shmtest_main_conf_t* conf = (shmtest_main_conf_t*)ngx_get_conf(cycle->conf_ctx, ngx_http_shmtest_module); if(conf == NULL){ NLOG_INFO("conf is null!"); return 0; } printf("process [%d] inited!\n", ngx_getpid()); //多进程并发测试 int i; int64_t ret=0; for(i=0;i<10000;i++){ ngx_str_t key = ngx_string("test"); ngx_shmap_inc_int(conf->shmap, &key, 1, 0, &ret); } printf("process [%d] init ok! ret=%lld\n", ngx_getpid(), (long long)ret); return 0; }
bool CRplNodeRsp::MsgDataToXML(std::string& p_rXml, bool p_bIsBroadcast) { struct QueryHdr *pQueryHdr = (struct QueryHdr *)m_rDevMsg->m_pucData; CTagGroup rootRsp(DB_ROOT_TAG); // if (p_bIsBroadcast) rootRsp.AddHexBinParam("ResponseTargetID", m_rDevMsg->m_oDstAddr.GetIPv6() + 8, CNetAddressExt::m_nIPv6AddrLen - 8); bool result; switch (QH_MSGTYPE(pQueryHdr)) { case UdpQueryNetStat: { result = CNeighbStatRspBuilder(p_rXml, m_rDevMsg->m_pucData, m_rDevMsg->m_unSize).Build(); NLOG_INFO("Response data : %s",p_rXml.c_str()); return result; } break; case UdpQueryRplDodag: result = CDodagTableRspBuilder(rootRsp, m_rDevMsg->m_pucData, m_rDevMsg->m_unSize).Build(); break; case UdpQueryRplInstance: result = CInstanceInfoRspBuilder(rootRsp, m_rDevMsg->m_pucData, m_rDevMsg->m_unSize).Build(); break; case UdpQueryRadioStats: result = CRadioStatsRspBuilder(rootRsp, m_rDevMsg->m_pucData, m_rDevMsg->m_unSize).Build(); break; case UdpQueryGetPublishSettings: case UdpQuerySetPublishSettings: result = CStatsPubSettingsRspBuilder(rootRsp, m_rDevMsg->m_pucData, m_rDevMsg->m_unSize).Build(); break; case UdpQueryGetConfiguration: case UdpQuerySetConfiguration: result = CConfigurationRspBuilder(rootRsp, m_rDevMsg->m_pucData, m_rDevMsg->m_unSize).Build(); break; case UdpQuery4EStats: result = CL4EStatsRspBuilder(rootRsp, m_rDevMsg->m_pucData, m_rDevMsg->m_unSize).Build(); break; #ifdef SIM_METER_APP case UdpQueryMeteringSnap: result = CMeteringSnapRspBuilder ( rootRsp, m_rDevMsg->m_pucData, m_rDevMsg->m_unSize ).Build ( ); break; case UdpQueryMeteringLpData: result = CMeteringLpDataRspBuilder ( rootRsp, m_rDevMsg->m_pucData, m_rDevMsg->m_unSize ).Build ( ); break; #endif case UdpQueryForceNodeToRegister: result = CForceRegisterRspBuilder(rootRsp, m_rDevMsg->m_pucData, m_rDevMsg->m_unSize).Build(); break; case UdpQueryGetNodeInfo: case UdpEventNodeRegistration: result = CNodeInfoRspBuilder(rootRsp, m_rDevMsg->m_pucData, m_rDevMsg->m_unSize).Build(); break; default: NLOG_ERR("[RplNodeRsp::MsgDataToXML]: invalid db_reqCode, db_cmd = %d", QH_MSGTYPE(pQueryHdr)); return false; } if (!result || rootRsp.IsEmpty()) { NLOG_ERR("[RplNodeRsp::MsgDataToXML]: failed to build XML"); return false; } rootRsp.Log("Response data"); CTagParamsParser::RootTagGroupToXML(rootRsp, p_rXml); return true; }
void CSumiNodeTesterApp::Run() { //init if(!g_oUtils.APISendCreateSocket(m_stCfg.GetUdpLocalPort(), g_u8SerialMsgId, m_poBufferedSerialLink)) return; g_u8SerialMsgId++; //receive ACK or NACK CSimpleTimer oTimer(m_stCfg.GetUDPCreateSockTimedoutSec()*1000); int nRecvLen = 0; bool bNoReply = true; while(!oTimer.IsSignaling() && bNoReply) { if( !m_poBufferedSerialLink->IsLinkOpen() || !m_poBufferedSerialLink->HaveData( WAITUS ) ) { continue; } nRecvLen = m_poBufferedSerialLink->Read( g_pucRcvBuf, BUFSIZE ); //check if (nRecvLen <= 0) continue; if (nRecvLen < (int)sizeof(API_MSG_HDR)) { NLOG_ERR("FAILED TO READ MSG HEADER ON SERIAL LINK!"); break; } //process rsp for APISendCreateSocket API_MSG_HDR *pHdr = (API_MSG_HDR*)g_pucRcvBuf; if (!API_GET_IS_RSP_FLAG(pHdr)) { NLOG_WARN("Expected a response for APISendCreateSocket but received a request!"); continue; } switch(API_GET_MSG_CLASS(pHdr)) { case API_ACK: if(API_GET_MESSAGE_ID(pHdr) == (g_u8SerialMsgId - 1)) { NLOG_INFO("UDP PORT %d SUCCESSFULLY OPENED!", m_stCfg.GetUdpLocalPort()); bNoReply = false; } break; case API_NACK: if(API_GET_MESSAGE_ID(pHdr) != (g_u8SerialMsgId - 1)) { continue; } switch(API_GET_TYPE(pHdr)) { case API_UDP_PORT_ALREADY_IN_USE: NLOG_INFO("API_UDP_PORT_ALREADY_IN_USE, UDP port=%d!", m_stCfg.GetUdpLocalPort()); bNoReply = false; break; case API_MAX_SOCKETS_NO_REACHED: NLOG_ERR("API_MAX_SOCKETS_NO_REACHED!"); return; case API_COULD_NOT_CREATE_SOCKET: NLOG_ERR("API_COULD_NOT_CREATE_SOCKET UDP port=%d!", m_stCfg.GetUdpLocalPort()); return; default: NLOG_ERR("UNKNOWN NACK MSG TYPE: %d!", API_GET_TYPE(pHdr)); return; } break; default: NLOG_ERR("UNKNOWN MSG CLASS: %d!", API_GET_MSG_CLASS(pHdr)); return; } } if( bNoReply ) { NLOG_ERR("NO REPLY TO UDP_CREATE_SOCKET!"); return; } //process every received msg CSimpleTimer oUdpSendTimer(m_stCfg.GetUdpSendIntervalSec()* 1000); CSimpleTimer oUdpSentPollTimer(m_stCfg.GetUdpSentPollIntervalSec()*1000); CSimpleTimer oStatisticsTimer(300000); CSimpleTimer oSigFileCheckTimer(m_stCfg.GetSigFileCheckIntervalSec()*1000); while (!CApp::IsStop()) { TouchPidFile(g_pApp->m_szAppPidFile); //On Send UDP EVENT if( oUdpSendTimer.IsSignaling() ) { SendUdpData(); oUdpSendTimer.SetTimer(m_stCfg.GetUdpSendIntervalSec()* 1000); } //On Receive Data EVENT ProcessRcv(); //On Poll Sent UDP Msg EVENT if( oUdpSentPollTimer.IsSignaling()) { g_oSumiStats.PollSentUdpMsg(); oUdpSentPollTimer.SetTimer(m_stCfg.GetUdpSentPollIntervalSec()*1000); } //On Log Statistics EVENT if( oStatisticsTimer.IsSignaling() ) { g_oSumiStats.LogStatistics(); oStatisticsTimer.SetTimer(300000); } //On Check SIG File EVENT if( oSigFileCheckTimer.IsSignaling() ) { CSignalsMgr::Raise( SIGHUP ); oSigFileCheckTimer.SetTimer(m_stCfg.GetSigFileCheckIntervalSec()* 1000); } //On Signals Check EVENT CheckSignals(); } NLOG_INFO("Closing the socket..."); if( !g_oUtils.APISendDeleteSocket(m_stCfg.GetUdpLocalPort(), g_u8SerialMsgId, m_poBufferedSerialLink) ) return; g_u8SerialMsgId++; //receive ACK oTimer.SetTimer(UDP_DELETE_SOCK_TIMEDOUT_MS); nRecvLen = 0; bNoReply = true; while(!oTimer.IsSignaling() && bNoReply) { if( !m_poBufferedSerialLink->IsLinkOpen() || !m_poBufferedSerialLink->HaveData( WAITUS ) ) { continue; } nRecvLen = m_poBufferedSerialLink->Read( g_pucRcvBuf, BUFSIZE ); //check if (nRecvLen <= 0) continue; if (nRecvLen < (int)sizeof(API_MSG_HDR)) { NLOG_ERR("FAILED TO READ MSG HEADER ON SERIAL LINK!"); break; } //process rsp API_MSG_HDR *pHdr = (API_MSG_HDR*)g_pucRcvBuf; if (!API_GET_IS_RSP_FLAG(pHdr)) { NLOG_WARN("Expected a response for APISendDeleteSocket but received a request!"); continue; } switch(API_GET_MSG_CLASS(pHdr)) { case API_ACK: if(API_GET_MESSAGE_ID(pHdr) == (g_u8SerialMsgId - 1)) { NLOG_INFO("UDP PORT %d SUCCESSFULLY CLOSED!", m_stCfg.GetUdpLocalPort()); bNoReply = false; } break; case API_NACK: if(API_GET_MESSAGE_ID(pHdr) != (g_u8SerialMsgId - 1)) { continue; } switch(API_GET_TYPE(pHdr)) { case API_IVALID_DELETE_SOCKET: NLOG_WARN("API_INVALID_DELETE_SOCKET UDP port=%d!", m_stCfg.GetUdpLocalPort()); bNoReply = false; break; default: NLOG_ERR("UNKNOWN NACK MSG TYPE: %d!", API_GET_TYPE(pHdr)); return; } break; default: NLOG_ERR("UNKNOWN MSG CLASS: %d!", API_GET_MSG_CLASS(pHdr)); return; } } if( bNoReply ) { NLOG_ERR("NO REPLY TO UDP_CLOSE_SOCKET!"); return; } }
void CSumiNodeTesterApp::CheckSignals() { if (CSignalsMgr::IsRaised( SIGHUP )) { if ( !unlink(NIVIS_TMP"enable_log.sig")) { NLOG_INFO("SIGNAL TO ENABLE LOG"); g_oUtils.APISendActivateLogs(g_u8SerialMsgId, m_poBufferedSerialLink); g_u8SerialMsgId++; g_oUtils.APISendDebugStrCmd(CSumiUtils::m_szDBGONStrCmd, g_u8SerialMsgId, m_poBufferedSerialLink); g_u8SerialMsgId++; } else if ( !unlink(NIVIS_TMP"disable_log.sig")) { NLOG_INFO("SIGNAL TO DISABLE LOG"); g_oUtils.APISendDeactivateLogs(g_u8SerialMsgId, m_poBufferedSerialLink); g_u8SerialMsgId++; } else if ( !unlink(NIVIS_TMP"inc_mac_lev.sig")) { NLOG_INFO("SIGNAL TO INCREMENT MAC LEVEL LOG"); g_oUtils.APISendDebugChrCmd(CSumiUtils::m_ucIncMacLogLevChrCmd, g_u8SerialMsgId, m_poBufferedSerialLink); g_u8SerialMsgId++; } else if ( !unlink(NIVIS_TMP"dec_mac_lev.sig")) { NLOG_INFO("SIGNAL TO DECREMENT MAC LEVEL LOG"); g_oUtils.APISendDebugChrCmd(CSumiUtils::m_ucDecMacLogLevChrCmd, g_u8SerialMsgId, m_poBufferedSerialLink); g_u8SerialMsgId++; } else if ( !unlink(NIVIS_TMP"inc_rpl_lev.sig")) { NLOG_INFO("SIGNAL TO INCREMENT RPL LEVEL LOG"); g_oUtils.APISendDebugChrCmd(CSumiUtils::m_ucIncRplLogLevChrCmd, g_u8SerialMsgId, m_poBufferedSerialLink); g_u8SerialMsgId++; } else if ( !unlink(NIVIS_TMP"dec_rpl_lev.sig")) { NLOG_INFO("SIGNAL TO DECREMENT RPL LEVEL LOG"); g_oUtils.APISendDebugChrCmd(CSumiUtils::m_ucDecRplLogLevChrCmd, g_u8SerialMsgId, m_poBufferedSerialLink); g_u8SerialMsgId++; } else if ( !unlink(NIVIS_TMP"show_mac_status.sig")) { NLOG_INFO("SIGNAL TO SHOW MAC STATUS"); g_oUtils.APISendDebugChrCmd(CSumiUtils::m_ucShowMACStatusChrCmd, g_u8SerialMsgId, m_poBufferedSerialLink); g_u8SerialMsgId++; } else if ( !unlink(NIVIS_TMP"show_nd_status.sig")) { NLOG_INFO("SIGNAL TO SHOW ND STATUS"); g_oUtils.APISendDebugChrCmd(CSumiUtils::m_ucShowNDStatusChrCmd, g_u8SerialMsgId, m_poBufferedSerialLink); g_u8SerialMsgId++; } else if ( !unlink(NIVIS_TMP"show_statistics.sig") ) { NLOG_INFO("SIGNAL TO SHOW STATISTICS"); g_oSumiStats.LogStatistics(); } CSignalsMgr::Reset(SIGHUP); } }
//PROCESS bool CSumiNodeTesterApp::ProcessRcv() { //input data if( !m_poBufferedSerialLink->IsLinkOpen() || !m_poBufferedSerialLink->HaveData( WAITUS ) ) return false; //check int nRecvLen = m_poBufferedSerialLink->Read( g_pucRcvBuf, BUFSIZE ); if (nRecvLen <= 0) return false; if (nRecvLen < (int)sizeof(API_MSG_HDR)) { NLOG_ERR("FAILED TO READ MSG HEADER ON SERIAL LINK!"); return false; } //process rsp API_MSG_HDR *pHdr = (API_MSG_HDR*)g_pucRcvBuf; if (API_GET_IS_RSP_FLAG(pHdr)) { switch(API_GET_MSG_CLASS(pHdr)) { case API_ACK: NLOG_INFO("RECV ACK msg_id = %u", API_GET_MESSAGE_ID(pHdr)); g_oSumiStats.MarkSentUdpMsgAsAcked(API_GET_MESSAGE_ID(pHdr)); return true; case API_NACK: switch(API_GET_TYPE(pHdr)) { case API_INVALID_SIZE: NLOG_ERR("RECV NACK(API_INVALID_SIZE) for msg_id = %u", API_GET_MESSAGE_ID(pHdr)); break; case API_UDP_ERR_INTERNAL: NLOG_INFO("RECV NACK(API_UDP_ERR_INTERNAL) for msg_id = %u", API_GET_MESSAGE_ID(pHdr)); break; case API_UDP_ERR_DEV_NOT_JOINED: NLOG_INFO("RECV NACK(API_UDP_ERR_DEV_NOT_JOINED) for msg_id = %u", API_GET_MESSAGE_ID(pHdr)); break; case API_UDP_ERR_INVALID_SOCKET: NLOG_INFO("RECV NACK(API_UDP_ERR_INVALID_SOCKET) for msg_id = %u", API_GET_MESSAGE_ID(pHdr)); break; case API_UDP_ERR_NO_MEMORY: NLOG_INFO("RECV NACK(API_UDP_ERR_NO_MEMORY) for msg_id = %u", API_GET_MESSAGE_ID(pHdr)); break; case API_UDP_ERR_ND_NOT_READY: NLOG_INFO("RECV NACK(API_UDP_ERR_ND_NOT_READY) for msg_id = %u", API_GET_MESSAGE_ID(pHdr)); break; default: NLOG_INFO("RECV NACK(UNKNOWN) for msg_id = %u", API_GET_MESSAGE_ID(pHdr)); break; } g_oSumiStats.RemoveSentUdpMsg(API_GET_MESSAGE_ID(pHdr)); return false; default: NLOG_ERR("RECV OTHER RESPONSE, MSG CLASS= %d!", API_GET_MSG_CLASS(pHdr)); return false; } } //process request from RM switch(API_GET_MSG_CLASS(pHdr)) { case UDP_SPECIFIC: { if (API_GET_TYPE(pHdr) != UDP_RECEIVE_DATAGRAM) break; //check for serial duplicates if( g_bIsFirstDatagramRecv ) { g_u8RecvSerialMsgId = API_GET_MESSAGE_ID(pHdr); g_bIsFirstDatagramRecv = false; } else if( API_GET_MESSAGE_ID(pHdr) == g_u8RecvSerialMsgId ) { NLOG_WARN("UDP_RECEIVE_DATAGRAM already read! Ignoring it..."); return false; } else { g_u8RecvSerialMsgId = API_GET_MESSAGE_ID(pHdr); } // UDP_RECV_DATAGRAM_PYLD* pRcvUdpDatagram = (UDP_RECV_DATAGRAM_PYLD*)((unsigned char*)pHdr + sizeof(API_MSG_HDR)); UDP_PYLD_ID *pUDPPyldId = (UDP_PYLD_ID*)((unsigned char*)pHdr + sizeof(API_MSG_HDR) + sizeof(UDP_RECV_DATAGRAM_PYLD)); unsigned int unUdpId = GET_UDP_PYLD_ID(pUDPPyldId); //log msg NLOG_INFO("Received data: addr=%s:%d, len=%d, UDP_ID=%d", GetHex(pRcvUdpDatagram->m_au8SrcIpv6, 16), UDP_RECV_DATAGRAM_GET_SRC_PORT(pRcvUdpDatagram), nRecvLen - sizeof(API_MSG_HDR) - sizeof(UDP_RECV_DATAGRAM_PYLD), unUdpId); memset(g_aucLogBuf,0,sizeof(g_aucLogBuf)); Bin2Hex((char*)g_aucLogBuf, sizeof(g_aucLogBuf), (char*)pRcvUdpDatagram + sizeof(UDP_RECV_DATAGRAM_PYLD), nRecvLen - sizeof(API_MSG_HDR)- sizeof(UDP_RECV_DATAGRAM_PYLD)); NLOG_INFO("Datagram payload: %s", g_aucLogBuf); // g_oSumiStats.MarkSentUdpMsgAsResponded( unUdpId ); //send ack if (!g_oUtils.SendACK(API_GET_MESSAGE_ID(pHdr), m_poBufferedSerialLink)) return false; } break; case API_DEBUG: { if (API_GET_TYPE(pHdr) != API_PRINT_LOG) break; if( API_GET_DATA_SIZE(pHdr) >= sizeof(g_aucLogBuf) ) { NLOG_ERR("LOG BUFFER TOO SMALL! Log buff=%d, API DATA SIZE=%d", sizeof(g_aucLogBuf), API_GET_DATA_SIZE(pHdr)); return false; } memcpy(g_aucLogBuf, g_pucRcvBuf + sizeof(API_MSG_HDR), API_GET_DATA_SIZE(pHdr)); g_aucLogBuf[API_GET_DATA_SIZE(pHdr)]='\0'; LOG("Log on dev: %s",g_aucLogBuf); } break; case STACK_SPECIFIC: { switch(API_GET_TYPE(pHdr)) { case NOTIFY_JOIN: { STACK_NOTIFY_JOIN *pNotifyJoin = (STACK_NOTIFY_JOIN*)((unsigned char*)pHdr + sizeof(API_MSG_HDR)); switch(pNotifyJoin->m_u8Status) { case MAC_IDLE_STATE: NLOG_INFO("Recv NOTIFY_JOIN, status= MAC_IDLE_STATE"); break; case ENERGY_DETECT_SCANNING_STATE: NLOG_INFO("Recv NOTIFY_JOIN, status= ENERGY_DETECT_SCANNING_STATE"); break; case ACTIVE_SCANNING_STATE: NLOG_INFO("Recv NOTIFY_JOIN, status= ACTIVE_SCANNING_STATE"); break; case SECURITY_STATE: NLOG_INFO("Recv NOTIFY_JOIN, status= SECURITY_STATE"); break; case ASSOCIATING_STATE: NLOG_INFO("Recv NOTIFY_JOIN, status= ASSOCIATING_STATE"); break; case ASSOCIATED_STATE: NLOG_INFO("Recv NOTIFY_JOIN, status= ASSOCIATED_STATE"); break; case ORPHAN_STATE: NLOG_INFO("Recv NOTIFY_JOIN, status= ORPHAN_STATE"); break; default: NLOG_WARN("Recv NOTIFY_JOIN, status = %u, UNKNOWN msg_id=%u!", pNotifyJoin->m_u8Status, API_GET_MESSAGE_ID(pHdr)); break; } //send ack if (!g_oUtils.SendACK(API_GET_MESSAGE_ID(pHdr), m_poBufferedSerialLink)) return false; } break; default: NLOG_ERR("UNKNOWN STACK_SPECIFIC TYPE!"); break; } } break; default: NLOG_WARN("RECV OTHER REQUEST MSG CLASS = %d", API_GET_MSG_CLASS(pHdr)); return false; } return true; }
int CEntryPointApp::Init() { if (!CApp::Init (NIVIS_TMP"NMS_EntryPoint.log")) { NLOG_ERR("[MainApp-Init]: failed!"); return 0; } ///for debugging purpose CSignalsMgr::Install(SIGUSR1); ///on this signal the app will display the subscription servers CSignalsMgr::Install(SIGUSR2); ///on this signal app log some internal structures (device cache) CSignalsMgr::Install(SIGHUP); ///on this signal app will reload some running parameters from config file if (!m_stCfg.Init ()) { NLOG_ERR("[MainApp-Init]: failed to read config!"); return 0; } NLOG_INFO("[MainApp-Init]: dispatcher_addr = %s", AddrToStr(m_stCfg.m_oDispAddr).c_str()); if (!m_oSubscToNMS.Init(m_stCfg.m_oDispAddr, m_stCfg.m_oEPAddr, this, 0/*lifetime*/, m_stCfg.m_nIpv4EPPort)) { NLOG_ERR("[MainApp-Init]: failed to init subscriber to dispatcher_addr = %s!", AddrToStr(m_stCfg.m_oDispAddr).c_str()); return false; } m_oSubscToNMS.SetLinkPrintHexEnabled ( m_stCfg.m_bMgmtpLinkRawPacketLog ); m_oSubscToNMS.SetLinkHexLimit ( m_stCfg.m_nMgmtpLinkHexLimit ); srand(time(NULL)); m_pPersistentMsgId = CEPPersistentMsgId::Ptr( new CEPPersistentMsgId(&(m_oSubscToNMS.GetPersistentMsgId())) ); /* Firmware update manager thread*/ CEPFwUpdateMngThread * fwUpdateMng = new CEPFwUpdateMngThread(m_stCfg, m_pAppDbToConnQueue); m_pFwUploadMng = IEPFwUpdateMng::Ptr(fwUpdateMng); CEPThread* pThread = fwUpdateMng; m_threadsList.push_back(CEPThread::Ptr(pThread)); /* Connection thread for management messages */ pThread = new CEPConnMgmtThread(m_stCfg, m_pPersistentMsgId, m_NSList, m_pMgmtDbToConnQueue, m_pMgmtConnToDbQueue); m_threadsList.push_back(CEPThread::Ptr(pThread)); /* Connection thread for app messages */ pThread = new CEPConnAppThread(m_stCfg, m_pAppDbToConnQueue, m_pAppConnToDbQueue); m_threadsList.push_back(CEPThread::Ptr(pThread)); /* Connection thread for node messages */ pThread = new CEPConnNodeThread(m_pNodeDbToConnQueue, m_pNodeConnToDbQueue, m_pDevCmdTracker, m_stCfg.m_nNetStatLocalPort, m_stCfg.m_BroadcastRspTimedout); ( ( CEPConnNodeThread* ) pThread )->SetPrintHexEnabled ( m_stCfg.m_bSimpleLinkRawPacketLog ); ( ( CEPConnNodeThread* ) pThread )->SetHexLimit ( m_stCfg.m_nSimpleLinkHexLimit ); m_threadsList.push_back(CEPThread::Ptr(pThread)); /* DB threads that read commands and pass them to connection threads */ for (int i = 0; i < m_stCfg.m_nDBReaderThreads; i++) { pThread = new CEPDBReaderThread(m_stCfg, m_pPersistentMsgId, m_dbAppCmdTrackList, m_dbTrackList, m_pAppDbToConnQueue, m_pMgmtDbToConnQueue, m_pNodeDbToConnQueue, m_pFwUploadMng); m_threadsList.push_back(CEPThread::Ptr(pThread)); } /* DB threads that write management messages recvd from mgmt conn thread */ for (int i = 0; i < m_stCfg.m_nDBMgmtWriterThreads; i++) { pThread = new CEPDBMgmtWriterThread(m_stCfg, m_dbTrackList, m_pMgmtConnToDbQueue, m_pMgmtDbToConnQueue); m_threadsList.push_back(CEPThread::Ptr(pThread)); } /* DB threads that write app messages recvd from app conn thread */ for (int i = 0; i < m_stCfg.m_nDBAppWriterThreads; i++) { pThread = new CEPDBAppWriterThread(m_stCfg, m_dbAppCmdTrackList, m_pAppConnToDbQueue, m_pAppDbToConnQueue, m_pFwUploadMng); m_threadsList.push_back(CEPThread::Ptr(pThread)); } /* DB threads that write node messages recvd from node conn thread */ for (int i = 0; i < m_stCfg.m_nDBNodeWriterThreads; i++) { pThread = new CEPDBNodeWriterThread(m_stCfg, m_pNodeConnToDbQueue, m_pNodeDbToConnQueue); m_threadsList.push_back(CEPThread::Ptr(pThread)); } pThread = new CEPDBCleanupThread(m_stCfg); m_threadsList.push_back(CEPThread::Ptr(pThread)); /* * Threads init */ CPThreadWrapper::LibInit(); CEPThread::PtrList::iterator it; for (it = m_threadsList.begin(); it != m_threadsList.end(); it++) { if (*it) { if (!(*it)->Init()) { NLOG_ERR("[MainApp-Init] thr init failed"); return 0; } } else { NLOG_ERR("[MainApp-Init] NULL app link"); return 0; } } m_dbMngt = CEPDBFactory::Create("MainApp-Init:", m_stCfg); return 1; }
void CEPDBNodeWriterThread::Log() { NLOG_INFO("Thread Stats ThrId=%d - DBNodeThr: deq=%d in_q_size=%d", GetWrapThId(), m_nDequeued, m_rReadQueue->Size()); }
static void ngx_http_shmtest_exit_master(ngx_cycle_t *cycle) { NLOG_INFO("nginx master exit...."); return ; }