📄 ss7_mtp2.cpp
字号:
{ case LSCEventRetrievalRequestAndFSNC: // L3 AppendEvent( MTP2_FSM_TXC, TXCEventRetrievalRequestAndFSNC ); break; case LSCEventFISUMSUReceived: // RC AppendEvent( MTP2_FSM_POC, POCEventRemoteProcRecovered ); // L3( Remote processor recovered ); break; case LSCEventRetrieveBSNT: // L3 AppendEvent( MTP2_FSM_RC, RCEventRetrieveBSNT ); break; case LSCEventL3Failure: case LSCEventLocalProcOutage: // MGMT AppendEvent( MTP2_FSM_POC, POCEventLocalProcOutage ); AppendEvent( MTP2_FSM_TXC, TXCEventSendSIPO ); break; case LSCEventGotSIPO: // RC // L3( Remote processor outage ); AppendEvent( MTP2_FSM_POC, POCEventRemoteProcOutage ); break; case LSCEventLocalProcRecovered: // MGMT AppendEvent( MTP2_FSM_POC, POCEventLocalProcRecovered ); AppendEvent( MTP2_FSM_RC, RCEventRetrieveFSNX ); AppendEvent( MTP2_FSM_TXC, TXCEventSendFISU ); break; case LSCEventFlushBuffers: case LSCEventContinue: // L3 if( event == LSCEventFlushBuffers ) { AppendEvent( MTP2_FSM_TXC, TXCEventFlushBuffers ); } level3IndicationReceived = true; if( processorOutage ) { lscState = LSCStateProcessorOutage; } else { level3IndicationReceived = false; AppendEvent( MTP2_FSM_TXC, TXCEventSendMSUFISU ); localProcessorOutage = false; AppendEvent( MTP2_FSM_RC, RCEventAcceptMSUFISU ); lscState = LSCStateInService; } break; case LSCEventNoProcOutage: // POC processorOutage = false; if( level3IndicationReceived ) { level3IndicationReceived = false; AppendEvent( MTP2_FSM_TXC, TXCEventSendMSUFISU ); localProcessorOutage = false; AppendEvent( MTP2_FSM_RC, RCEventAcceptMSUFISU ); lscState = LSCStateInService; } else { lscState = LSCStateProcessorOutage; } break; case LSCEventLinkFailure: // SUERM , RC case LSCEventGotSIO: // RC case LSCEventGotSIE: // RC case LSCEventGotSIOS: // RC case LSCEventGotSIN: // RC // L3( Out of service ); AppendEvent( MTP2_FSM_SUERM, SUERMEventStop ); AppendEvent( MTP2_FSM_RC, RCEventStop ); AppendEvent( MTP2_FSM_POC, POCEventStop ); AppendEvent( MTP2_FSM_TXC, TXCEventSendSIOS ); emergency = false; localProcessorOutage = false; lscState = LSCStateOutOfService; gettimeofday( & LSCRestartTimer, NULL ); // the command to OOS LSC break; case LSCEventStop: // L3 AppendEvent( MTP2_FSM_SUERM, SUERMEventStop ); AppendEvent( MTP2_FSM_RC, RCEventStop ); AppendEvent( MTP2_FSM_POC, POCEventStop ); AppendEvent( MTP2_FSM_TXC, TXCEventSendSIOS ); emergency = false; localProcessorOutage = false; lscState = LSCStateOutOfService; gettimeofday( & LSCRestartTimer, NULL ); // the command to OOS LSC break; default: break; } break; default: break; } return 0;}int SS7_MTP2::writeMessage(unsigned char * _buffer, int _count){// if( FD_ISSET( devfd, & wrfdset ) )// {// int ret = write( devfd, _buffer, _count );// } return 0;}// Triggered by L3, we'll insert the MSU into the sendBuffer if we could// In "data", we have only the data excluding the LI and CK//TODO: Need to move to TXC(...)int SS7_MTP2::sendMessage(unsigned char * _data, int _count){ printf("SS7_MTP2::sendMessage(), dataptr=%d, count=%d!\n", (unsigned int)_data, _count ); int ret = 0; // Add to the MSU sending Buffer with correct FSN // Before inserting, add FSN/FIB/BSN/BIB MSUQueueElementL2 * pElementL2 = (MSUQueueElementL2 *) malloc( sizeof(unsigned short) + sizeof(MSUL2) + MAX_MSU_LEN ); if( pElementL2 ) { // we just put the MSU into the sendBuffer // its FSN will be set at the first sending time // If the sendBuffer is full, fail this operation // count is the length of the MSU - after LI and before CK pElementL2->msuL2.suHeader.LI = (_count >= 63) ? 63 : _count; memcpy( (unsigned char *)& pElementL2->msuL2.SIO, (unsigned char *)_data, _count ); // MSU beginning from SIO pElementL2->len = (unsigned short)(sizeof(SUHeaderL2) + _count); // write the len following by the MSU ret = sendBuffer.write( (unsigned char*) pElementL2, sizeof(unsigned short) + sizeof(SUHeaderL2) + _count ); free( pElementL2 ); if( ret == 0 ) { // AppendEvent ? L3 --> TXC, Message for transmission // Seems no need for this, since the FSM will repeatedly check the buffer, // and will send FISU if nothing to send Cm += 1; // the count of MSUs in TB is incremented printf("SS7_MTP2::sendMessage(), Cm = %d!\n", Cm ); } } else { return -1; } return ret;}// Now this function is not usedint SS7_MTP2::sendMessage(int _number){ int sent_message_num = 0; // check the sending buffer for(int i=0 ; i<_number ; i++) { if( sendBuffer.getStoredBytesNumber() < 1 ) { break; }// unsigned char * ptr = sendBuffer.getSentMsgPtr( ); // get the data ptr and data length // The structure begin with a short which indicates the length// unsigned char * ptrSU;// int len;// if( FD_ISSET( devfd, & wrfdset ) )// {// int ret = write( devfd, ptrSU, len );// sent_message_num += ret;// if( ret != len )// {// }// } } return sent_message_num;}// L3 request to read data from L2 recvBufferint SS7_MTP2::readMesssage(unsigned char * _buffer, int _len){ // copy messages into buffer until _buffer full OR no more message left return 0;}int SS7_MTP2::TXC_SendFISU(void){ FISU fisu; MTP2_FSM_Event event_out; struct timeval t; gettimeofday( & t, NULL ); long diff = (t.tv_sec - FISUTimer.tv_sec)*1000000 + (t.tv_usec - FISUTimer.tv_usec); if( diff < 300000 ) // not too much FISU { AppendEvent( MTP2_FSM_DAEDT, DAEDTEventSignalUnit ); return 0; } // update FISUTimer for next checking FISUTimer = t; printf("SS7_MTP2::TXC_SendFISU!\n" ); BIBT = TXC_BIB; BSNT = (TXC_FSNX - 1 + 128) % 128; FIBT = TXC_FIB; // Generate FISU fisu.suHeader.LI = 0; fisu.suHeader.FSN = TXC_FSNT; // ?? fisu.suHeader.FIB = FIBT; fisu.suHeader.BSN = BSNT; // could be updated by RC() fisu.suHeader.BIB = BIBT; printf("SS7_MTP2::TXC_SendFISU() - FSN=%d,FIB=%d,BSN=%d,BIB=%d!\n", TXC_FSNT, FIBT, BSNT, BIBT ); // populate the SndSigUnit pSndSigUnit->Length = SND_SU_HEADER_SIZE + sizeof(fisu); pSndSigUnit->Type = 0;
// pSndSigUnit->TimeStamp[0] = 0; // It's for L1 or L2 to populate
pSndSigUnit->ChName = (unsigned short)portNumber; memcpy( (unsigned char *)pSndSigUnit->PktBuf, (unsigned char *)& fisu, sizeof(fisu) ); writeSUDowntoL1( pSndSigUnit ); // only need it to insert (MTP2_FSM_TXC, TXCEventTransmissionRequest) // which seems useless and may be removed later (not efficient) AppendEvent( MTP2_FSM_DAEDT, DAEDTEventSignalUnit ); return 0;}int SS7_MTP2::TXC_SendLSSU(void){// printf("SS7_MTP2::TXC_SendLSSU() !\n" ); LSSU lssu; MTP2_FSM_Event event_out; if( LSSUBuffer.read( (unsigned char *)& lssu, sizeof(lssu) ) == 0 ) { BIBT = TXC_BIB; BSNT = (TXC_FSNX - 1 + 128) % 128; FIBT = TXC_FIB; lssu.suHeader.FSN = TXC_FSNT; lssu.suHeader.FIB = FIBT; lssu.suHeader.BSN = BSNT; lssu.suHeader.BIB = BIBT; // printf("SS7_MTP2::TXC_SendLSSU() - LI=%d, len=%d, FSN=%d,FIB=%d,BSN=%d,BIB=%d!\n", // lssu.suHeader.LI, sizeof(lssu), FSNT, FIBT, BSNT, BIBT ); // populate the SndSigUnit pSndSigUnit->Length = SND_SU_HEADER_SIZE + sizeof(SUHeaderL2) + lssu.suHeader.LI; pSndSigUnit->Type = 0;
// pSndSigUnit->TimeStamp[0] = 0; // It's for L1 or L2 to populate?
pSndSigUnit->ChName = (unsigned short)portNumber; memcpy( (unsigned char *)pSndSigUnit->PktBuf, (unsigned char *)& lssu, sizeof(SUHeaderL2) + lssu.suHeader.LI ); if( (LSSUType)(lssu.SF & 0x07) == LSSUTypeSIB ) { printf("SS7_MTP2::TXC_SendLSSU() - got SIB!\n" ); LSSUAvailable = false; } writeSUDowntoL1( pSndSigUnit ); // only need it to insert (MTP2_FSM_TXC, TXCEventTransmissionRequest) // which seems useless and may be removed later (not efficient) AppendEvent( MTP2_FSM_DAEDT, DAEDTEventSignalUnit ); } else { // nothing to send // only need it to insert (MTP2_FSM_TXC, TXCEventTransmissionRequest) // which seems useless and may be removed later (not efficient) // printf("SS7_MTP2::TXC_SendLSSU() - no LSSU in the queue, waiting for next one!\n" ); AppendEvent( MTP2_FSM_DAEDT, DAEDTEventSignalUnit ); // LSSUAvailable = false; // Added during UT // If we set LSSUAvailable to false, then next time, we have no chance to send LSSU // It seems that after sending FISU/MSU or SIB, LSSUAvailable will be set to false // Since we have no LSSU to send, have a rest here to save CPU workload usleep( 20000 ); } return 0;}// Must make sure we have at least one MSU to deleteint SS7_MTP2::EraseRTBMSU(int maxFSN){ printf("SS7_MTP2::EraseRTBMSU() - FSNF=%d, maxFSN=%d!\n", TXC_FSNF, maxFSN ); if( TXC_FSNF == ((maxFSN + 1) % 128) ) { return -1; } do { // featch MSU from RTB (and throw away) resendBuffer.read( (unsigned char *)& pSUWithLen->len, sizeof(unsigned short) ); resendBuffer.read( (unsigned char *)& pSUWithLen->header, pSUWithLen->len ); } while( pSUWithLen->header.FSN != maxFSN ); return 0;}int SS7_MTP2::TXC(int event_in, unsigned long param){// if( event_in != TXCEventTransmissionRequest )// {// printf("SS7_MTP2::TXC() - event=%d, param=%d!\n",// event_in, (unsigned int)param );// } TXCEvent event = (TXCEvent)event_in; MTP2_FSM_Event event_out; LSSU lssu; int tmpBSNR, tmpBIBR; switch( txcState ) { case TXCStateIdle: printf("SS7_MTP2::TXC() - State = TXCStateIdle!\n" ); switch( event ) { case TXCEventStart: // LSC printf("SS7_MTP2::TXC() - Event = TXCEventStart!\n" ); sendBuffer.reset(); resendBuffer.reset(); AppendEvent( MTP2_FSM_DAEDT, DAEDTEventStart ); LSSUAvailable = false; SIBreceived = false; // Status Indicator "Busy" RTBfull = false; // Retransmission Buffer Full MSUinhibited = false; TXC_FSNL = 127; // FSN of the last MSU in the RTB TXC_FSNT = 127; // FSN of the last MSU transmitted TXC_FSNX = 0; // FSN expected TXC_FIB = 1; // Forward indicator bit TXC_BIB = 1; // backward indicator bit
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -