コード例 #1
0
PUBLIC RETVAL sendMsg
(
TransConnId          connId,               
IPEndPoint           *pDst,
Buffer               *data
)
{
   LOG_ENTERFN();

   RETVAL   ret = ROK;

   GSimSocket  *pSock = g_gsimSockArr[connId];
   if (NULL != pSock)
   {
      if (pDst->ipAddr.ipAddrType == IP_ADDR_TYPE_V4)
      {
         ret = sendMsgV4(pSock, pDst, data);
      }
      else
      {
         ret = sendMsgV6(pSock, pDst, data);
      }
   }

   LOG_EXITFN(ret);
}
コード例 #2
0
ファイル: gtp_util.cpp プロジェクト: 2fumin/LTE-GTP-Simulator
GtpLength_t gtpConvStrToHex(const HexString *value, U8 *pDst)
{
   LOG_ENTERFN();

   U32 begin = 0;
   U32 indx = 0;

   /* hex buffer string has odd len, so the first byte of hex buffer
    * will have 0 as High nibble
    */
   const char* str = value->c_str();
   if (GSIM_IS_ODD(value->size()))
   {
      pDst[indx++] = 0x0f & gtpCharToHex(str[0]);
      begin++;
   }

   for (U32 i = begin; i < value->size(); i += 2)               
   {                                                        
      U8 HNibble = gtpCharToHex(str[i]); 
      U8 LNibble = gtpCharToHex(str[i + 1]);     
      pDst[indx++] = (HNibble << 4) | (LNibble);
   }                                                        
                                                            
   LOG_EXITFN(indx);
}
コード例 #3
0
ファイル: gtp_util.cpp プロジェクト: 2fumin/LTE-GTP-Simulator
GtpLength_t gtpConvStrToHex(const Buffer *pBuf, U8 *pDst)
{
   LOG_ENTERFN();

   U32 begin = 0;
   U32 indx = 0;

   /* hex buffer string has odd len, so the first byte of hex buffer
    * will have 0 as High nibble
    */
   if (GSIM_IS_ODD(pBuf->len))
   {
      pDst[indx++] = 0x0f & gtpCharToHex(pBuf->pVal[0]);
      begin++;
   }

   for (U32 i = begin; i < pBuf->len; i += 2)               
   {                                                        
      U8 HNibble = gtpCharToHex(pBuf->pVal[i]); 
      U8 LNibble = gtpCharToHex(pBuf->pVal[i + 1]);     
      pDst[indx++] = (HNibble << 4) | (LNibble);
   }                                                        
                                                            
   LOG_EXITFN(indx);
}
コード例 #4
0
ファイル: gtp_util.cpp プロジェクト: 2fumin/LTE-GTP-Simulator
PRIVATE U8 gtpCharToHex(U8 c)
{
   LOG_ENTERFN();

   U8 h = 0;
   switch (c)
   {
      case 'a':
         h = 0xa;
         break;
      case 'b':
         h = 0xb;
         break;
      case 'c':
         h = 0xc;
         break;
      case 'd':
         h = 0xd;
         break;
      case 'e':
         h = 0xe;
         break;
      case 'f':
         h = 0xf;
         break;
      default:
         h = GSIM_CHAR_TO_DIGIT(c);
         break;
   }
   
   LOG_EXITFN(h);
}
コード例 #5
0
ファイル: gtp_util.cpp プロジェクト: 2fumin/LTE-GTP-Simulator
/**
 * @brief 
 *    returns the pointer to imsi ie in GTP message buffer
 *
 * @return 
 *    returns the pointer to imsi ie in GTP message buffer
 */
PUBLIC U8* getImsiBufPtr(Buffer *pGtpcBuf)
{
   LOG_ENTERFN();

   U8          *pImsi = NULL;
   GtpIeHdr    ieHdr;
   GtpLength_t len = pGtpcBuf->len;
   U8          *pBuf = pGtpcBuf->pVal;

   if (GTP_CHK_T_BIT_PRESENT(pBuf))
   {
      len -= GTP_MSG_HDR_LEN;
      pBuf += GTP_MSG_HDR_LEN;
   }
   else
   {
      len -= GTP_MSG_HDR_LEN_WITHOUT_TEID;
      pBuf += GTP_MSG_HDR_LEN_WITHOUT_TEID;
   }

   while (len)
   {
      decIeHdr(pBuf, &ieHdr);
      if (ieHdr.ieType == GTP_IE_IMSI)
      {
         pImsi = pBuf;
         break;
      }

      len -= (ieHdr.len + GTP_IE_HDR_LEN);
      pBuf += (ieHdr.len + GTP_IE_HDR_LEN);
   }

   LOG_EXITFN(pImsi);
}
コード例 #6
0
ファイル: display.cpp プロジェクト: sgk/LTE-GTP-Simulator
BOOL Display::run()
{
   LOG_ENTERFN();

   m_lastRunTime = getMilliSeconds();
   disp();
   pauseTask();

   LOG_EXITFN(TRUE);
}
コード例 #7
0
ファイル: gtp_util.cpp プロジェクト: 2fumin/LTE-GTP-Simulator
GtpMsgCategory_t gtpGetMsgCategory(GtpMsgType_t msgType)
{
   LOG_ENTERFN();

   GtpMsgCategory_t msgCat = GTP_MSG_CAT_INV;
   if (msgType <= GTPC_MSG_TYPE_MAX)
   {
      msgCat = g_gtpMsgCat[msgType]; 
   }

   LOG_EXITFN(msgCat);
}
コード例 #8
0
/**
 * @brief
 *    Hanldes GTP-U socket, reads GTP-U Process control messages
 *
 * @param pSock
 *
 * @return 
 */
PRIVATE RETVAL handleGtpuSock
(
GSimSocket     *pSock
)
{
   LOG_ENTERFN();

   RETVAL      ret = ROK;


   LOG_EXITFN(ret);
}
コード例 #9
0
ファイル: gtp_util.cpp プロジェクト: 2fumin/LTE-GTP-Simulator
PUBLIC U32 gtpConvStrToU32(const S8 *pVal, U32 len)
{
   LOG_ENTERFN();

   S8 *tmp = NULL;
   S8 buf[GSIM_SIZE_32] = {'\0'};

   MEMCPY(buf, pVal, len);
   U32 v = strtoul(buf, &tmp, 10);

   LOG_EXITFN(v);
}
コード例 #10
0
ファイル: tunnel.cpp プロジェクト: 2fumin/LTE-GTP-Simulator
PUBLIC GtpcTun* findCTun(GtpTeid_t teid)
{
   GtpcTun     *pTun = NULL;

   TunMapItr itr = s_gtpcTunMap.find(teid);
   if (itr != s_gtpcTunMap.end())
   {
      pTun = itr->second;
      LOG_TRACE("Found GTP-C Tunnel, TEID [%d]", teid);
   }
  
   LOG_EXITFN(pTun);
}
コード例 #11
0
ファイル: gtp_util.cpp プロジェクト: 2fumin/LTE-GTP-Simulator
GtpIfType_t gtpConvStrToIfType(const S8 *pVal, U32 len)
{
   LOG_ENTERFN();
   
   GtpIfType_t ifType = (GtpIfType_t)gtpConvStrToU32(pVal, len);
   if (ifType >= GTP_IF_INF_INV)
   {
      ifType = GTP_IF_INF_INV;
      LOG_ERROR("Unrecognized Interface type string [%s]", pVal);
   }

   LOG_EXITFN(ifType);
}
コード例 #12
0
ファイル: keyboard.cpp プロジェクト: sgk/LTE-GTP-Simulator
/**
 * @brief
 *    Creates Keyboard socket
 */
VOID Keyboard::init()
{
   LOG_ENTERFN();

   LOG_DEBUG("Setting up STDIN Socket for keyboard");
   if (ROK != setupStdinSock())
   {
      LOG_FATAL("Setting up STDIN Socket for keyboard");
      throw ERR_KEYBOARD_INIT;
   }

   LOG_EXITFN();
}
コード例 #13
0
PRIVATE RETVAL sendMsgV4(GSimSocket *pSock, IPEndPoint *pDst, Buffer *data)
{
   LOG_ENTERFN();

   struct sockaddr_in  destAddr;

   destAddr.sin_addr.s_addr = htonl(pDst->ipAddr.u.ipv4Addr.addr);
   destAddr.sin_family = AF_INET;
   destAddr.sin_port = htons(pDst->port);
   MEMSET(destAddr.sin_zero, '\0', sizeof(destAddr.sin_zero));

   S32 ret = sendto(pSock->fd(), (VOID *)data->pVal, (size_t)data->len,\
         MSG_DONTWAIT, (struct sockaddr *)&destAddr, sizeof(destAddr));
   if (ret < 0)
   {
      LOG_FATAL("Socket sendto() failed, [%s]", strerror(errno));
      LOG_EXITFN(ERR_SYS_SOCK_SEND);
   }

   delete data;
   LOG_EXITFN(ROK);
}
コード例 #14
0
RETVAL GSimSocket::recvMsg(UdpData_t **msg)
{
   LOG_ENTERFN();

   RETVAL ret = ROK;

   if (IP_ADDR_TYPE_V4 == m_ep.ipAddr.ipAddrType)
   {
      ret = recvMsgV4(msg);
   }
   else
   {
      ret = recvMsgV6(msg);
   }

   LOG_EXITFN(ret);
}
コード例 #15
0
/**
 * @brief
 *    Creates the socket for listening on Keyboard events from the user
 */
PUBLIC RETVAL setupStdinSock()
{
   LOG_ENTERFN();

   S16      ret = ROK;

   try
   {
      GSimSocket  *pKbSock = new GSimSocket(SOCK_TYPE_STDIN);
      (VOID)pKbSock;
   }
   catch (ErrCodeEn  &e)
   {
      ret = ERR_SOCK_ALLOC;
   }

   LOG_EXITFN(ret);
}
コード例 #16
0
ファイル: traffic.cpp プロジェクト: 2fumin/LTE-GTP-Simulator
RETVAL TrafficTask::run(VOID *arg)
{
   LOG_ENTERFN();

   BOOL     abortTraffiTask = FALSE;
   LOG_DEBUG("Running TrafficTask, Session Rate [%d]", m_rate);

   Time_t currTime = getMilliSeconds();
   m_lastRunTime = currTime;
   Counter numSession = Stats::getStats(GSIM_STAT_NUM_SESSIONS_CREATED);
   for (U32 i = 0; i < m_rate; i++)
   {
      GtpImsiKey imsiKey;
      MEMSET(&imsiKey, 0, sizeof(GtpImsiKey));
      m_imsiGen.allocNew(&imsiKey);

      UeSession::createUeSession(imsiKey);
      numSession++;
      if ((0 != m_maxSessions) && (numSession >= m_maxSessions))
      {
         LOG_DEBUG("Max Sessions = [%d] Created, Stopping Traffic",\
               m_maxSessions);
         abortTraffiTask = TRUE;
         break;
      }
   }

   Display::displayStats();

   if (abortTraffiTask)
   {
      stop();
   }
   else
   {
      m_wakeTime = m_lastRunTime + m_ratePeriod;
      pause();
   }

   LOG_EXITFN(ROK);
}
コード例 #17
0
PUBLIC RETVAL initTransport()
{
   LOG_ENTERFN();

   S16            ret = ROK;
   IPEndPoint     locListnerEp;
   IPEndPoint     locSenderEp;

   Config          *pCfg = Config::getInstance();

   for (U32 i = 0; i < GSIM_MAX_POLL_FDS; i++)
   {
      s_pollFdArr[i].fd = -1;
   }

   /* Simulator sends all GTP messages with source udp port number as 
    * Default GTP port + 1, using this socket
    */
   locSenderEp.port = pCfg->getLocalGtpcPort() + 1;
   locSenderEp.ipAddr = *pCfg->getLocalIpAddr();
   s_pSender = new GSimSocket(SOCK_TYPE_GTPC, locSenderEp);
   if (ROK != s_pSender->bindSocket())
   {
      LOG_FATAL("Binding to GTP local sending Socket");
   }

   /* This is the default GTPC socket, where the simlator listens
    * for initiating messages
    */
   locListnerEp.port = pCfg->getLocalGtpcPort();
   locListnerEp.ipAddr = *pCfg->getLocalIpAddr();
   s_pListener = new GSimSocket(SOCK_TYPE_GTPC, locListnerEp);
   if (ROK != s_pListener->bindSocket())
   {
      LOG_FATAL("Binding to GTP Listener Socket");
   }

   LOG_EXITFN(ret);
}
コード例 #18
0
/**
 * @brief
 *    Hanldes GTP-C socket, reads GTP-C messages
 *
 * @param pSock
 *
 * @return 
 */
PRIVATE RETVAL handleGtpcSock(GSimSocket *pSock)
{
   LOG_ENTERFN();

   RETVAL   ret = ROK;
   U32      loops = GSIM_MAX_RECV_LOOPS;

   while (loops && (ROK == ret))
   {
      UdpData_t *msg = NULL;
      ret = pSock->recvMsg(&msg);
      if (ROK == ret)
      {
         LOG_DEBUG("Process the Received messages", pSock->fd());
         procGtpcMsg(msg);
      }

      loops--;
   };

   LOG_EXITFN(ROK);
}
コード例 #19
0
ファイル: gtp_util.cpp プロジェクト: 2fumin/LTE-GTP-Simulator
IpAddr convIpStrToIpAddr(const S8* pIp, U32 len)
{
   LOG_ENTERFN();

   IpAddr ipAddr;
   S8     ip[GSIM_SIZE_32] = {'\0'};
   MEMCPY(ip, pIp, len);

   ipAddr.ipAddrType = IP_ADDR_TYPE_INV;
   if (STRFIND(ip, ":") != NULL)
   {
      RETVAL ret = inet_pton(AF_INET6, ip, (VOID *)(ipAddr.u.ipv6Addr.addr));
      if (0 == ret)
      {
         LOG_FATAL("Invalid IPv6 Address");
      }
      else
      {
         ipAddr.u.ipv6Addr.len = STRLEN(ip);
         ipAddr.ipAddrType = IP_ADDR_TYPE_V6;
      }
   }
   else
   {
      RETVAL ret = inet_pton(AF_INET, ip, (VOID *)&(ipAddr.u.ipv4Addr.addr));
      if (0 == ret)
      {
         LOG_FATAL("Invalid IPv4 Address");
      }
      else
      {
         ipAddr.u.ipv4Addr.addr = ntohl(ipAddr.u.ipv4Addr.addr);
         ipAddr.ipAddrType = IP_ADDR_TYPE_V4;
      }
   }

   LOG_EXITFN(ipAddr);
}
コード例 #20
0
ファイル: gtp_util.cpp プロジェクト: 2fumin/LTE-GTP-Simulator
U32 encodeImsi(S8 *pImsiStr, U32 imsiStrLen, U8 *pBuf)
{
   LOG_ENTERFN();

   U32      indx = 0;
   U32      len = 0;

   /* Enocde even number of digits into hex buffer */
   for (indx = 0; indx < (imsiStrLen - 1); indx += 2)
   {
      pBuf[len++] = GSIM_CHAR_TO_DIGIT(pImsiStr[indx]) | \
            GSIM_CHAR_TO_DIGIT(pImsiStr[indx + 1]) << 4;
   }

   /* Encode the last digit into hex buffer */
   if (GSIM_IS_ODD(imsiStrLen))
   {
      pBuf[len] = GSIM_CHAR_TO_DIGIT(pImsiStr[imsiStrLen - 1]) | 0xf0;
      len++;
   }

   LOG_EXITFN(len);
}
コード例 #21
0
BOOL Procedure::addJob(Job *job)
{
   BOOL fullProc = FALSE;

   LOG_ENTERFN();

   if (JOB_TYPE_WAIT == job->type())
   {
      /* this is a wait in between a procedure */
      m_wait = job;
      m_type = PROC_TYPE_WAIT;
   }
   else
   {
      GtpMsg *gtpMsg = job->getGtpMsg();
      GtpMsgType_t msgType = gtpMsg->type();
      GtpMsgCategory_t msgCat = gtpGetMsgCategory(gtpMsg->type());

      if (GTP_MSG_CAT_CMD == msgCat)
      {
         m_initial = job;
      }
      else if (GTP_MSG_CAT_CMD_FAIL == msgCat)
      {
         m_trigMsg = job;
         fullProc = TRUE;
         m_type = PROC_TYPE_REQ_RSP;
      }
      else if (GTP_MSG_CAT_REQ == msgCat)
      {
         if ((GTPC_MSG_CB_REQ == msgType) || \
            (GTPC_MSG_MB_REQ == msgType) || \
            (GTPC_MSG_DB_REQ == msgType))
         {
            /* the request message is triggered by a command message */
            if (NULL != m_initial)
            {
               m_trigMsg = job;
            }
            else
            {
               m_initial = job;
            }
         }
         else
         {
            m_initial = job;
         }
      }
      else if (GTP_MSG_CAT_RSP == msgCat)
      {
         if ((GTPC_MSG_CB_RSP == msgType) || \
            (GTPC_MSG_MB_RSP == msgType) || \
            (GTPC_MSG_DB_RSP == msgType))
         {
            if (NULL != m_trigMsg)
            {
               m_trigReply = job;
               m_type = PROC_TYPE_REQ_TRIG_REP;
            }
            else
            {
               m_trigMsg = job;
               m_type = PROC_TYPE_REQ_RSP;
            }
         }
         else
         {
            m_trigMsg = job;
            m_type = PROC_TYPE_REQ_RSP;
         }
         
         fullProc = TRUE;
      }
   }

   LOG_EXITFN(fullProc);
}