Ejemplo n.º 1
0
BOOL P2PManager::PushPacket(BYTE* pData, int Length)
{
	P2PData* pP2PData = new P2PData();
	pP2PData->Write(pData, Length);

	lfds611_queue_guaranteed_enqueue(m_pQueue, pP2PData);
	return TRUE;
}
Ejemplo n.º 2
0
//------------------------------------------------------------------------------
void
msc_log_declare_proto (
  const msc_proto_t protoP)
//------------------------------------------------------------------------------
{
  int                                     rv = 0;
  msc_queue_item_t                       *new_item_p = NULL;
  char                                   *char_message_p = NULL;

  if ((MIN_MSC_PROTOS <= protoP) && (MAX_MSC_PROTOS > protoP)) {
    // may be build a memory pool for that also ?
    new_item_p = malloc (sizeof (msc_queue_item_t));

    if (NULL != new_item_p) {
      rv = lfds611_stack_pop (g_msc_memory_stack_p, (void **)&char_message_p);

      if (0 == rv) {
        msc_flush_messages ();
        rv = lfds611_stack_pop (g_msc_memory_stack_p, (void **)&char_message_p);
      }

      if (1 == rv) {
        rv = snprintf (char_message_p, MSC_MAX_MESSAGE_LENGTH, "%" PRIu64 " [PROTO] %d %s\n", __sync_fetch_and_add (&g_message_number, 1), protoP, &g_msc_proto2str[protoP][0]);

        if (0 > rv) {
          fprintf (stderr, "Error while declaring new protocol in MSC: %s", strerror (errno));
        }

        new_item_p->message_str = char_message_p;
        new_item_p->message_str_size = rv;
        new_item_p->message_bin = NULL;
        new_item_p->message_bin_size = 0;
        rv = lfds611_queue_enqueue (g_msc_message_queue_p, new_item_p);

        if (0 == rv) {
          rv = lfds611_queue_guaranteed_enqueue (g_msc_message_queue_p, new_item_p);

          if (0 == rv) {
            fprintf (stderr, "Error while lfds611_queue_guaranteed_enqueue message %s in MSC", char_message_p);
            rv = lfds611_stack_guaranteed_push (g_msc_memory_stack_p, char_message_p);
            free (new_item_p);
          }
        }

        return;
      } else {
        fprintf (stderr, "Error while lfds611_stack_pop()\n");
      }

      free (new_item_p);
    } else {
      fprintf (stderr, "Error while malloc in MSC");
    }
  }
}
Ejemplo n.º 3
0
BOOL SFTCPNetwork::Update()
{
	while (1)
	{
		BasePacket* pPacket = LogicGatewaySingleton::instance()->PopPacket(0);

		if (pPacket != NULL)
		{
			switch (pPacket->GetPacketType())
			{

			case SFPACKET_DATA:		
				m_pTCPCallBack->HandleNetworkMessage(pPacket);
				m_TCPClient->ReleasePacket(pPacket);
				break;

			case SFPACKET_RPC:
				lfds611_queue_guaranteed_enqueue(m_pQueue, pPacket);
				break;

			case SFPACKET_CONNECT:			
				m_pTCPCallBack->HandleConnect(pPacket->GetOwnerSerial());
				delete pPacket;
				break;
			case  SFPACKET_DISCONNECT:			
				m_pTCPCallBack->HandleDisconnect(pPacket->GetOwnerSerial());
				delete pPacket;
				break;
			}

			
		}
		else
		{
			break;
		}
	}

	return TRUE;
}
Ejemplo n.º 4
0
//-----------------------------------------------------------------------------
static
void *pdcp_netlink_thread_fct(void *arg)
//-----------------------------------------------------------------------------
{
    int                            len             = 0;
    struct pdcp_netlink_element_s *new_data_p      = NULL;
    uint8_t                        pdcp_thread_read_state ;
    eNB_flag_t                     eNB_flag        = 0;
    module_id_t                    module_id       = 0;
    pdcp_thread_read_state = 0;
    memset(nl_rx_buf, 0, NL_MAX_PAYLOAD);
    LOG_I(PDCP, "[NETLINK_THREAD] binding to fd  %d\n",nas_sock_fd);
    MSC_START_USE();
    while (1) {

        len = recvmsg(nas_sock_fd, &nas_msg_rx, 0);

        if (len == 0) {
            /* Other peer (kernel) has performed an orderly shutdown
             */
            LOG_E(PDCP, "[NETLINK_THREAD] Kernel module has closed the netlink\n");
            exit(EXIT_FAILURE);
        } else if (len < 0) {
            /* There was an error */
            LOG_E(PDCP, "[NETLINK_THREAD] An error occured while reading netlink (%d:%s)\n",
                  errno, strerror(errno));
            exit(EXIT_FAILURE);
        } else {
            /* Normal read.
             * NOTE: netlink messages can be assembled to form a multipart message
             */
            for (nas_nlh_rx = (struct nlmsghdr *) nl_rx_buf;
                    NLMSG_OK(nas_nlh_rx, (unsigned int)len);
                    nas_nlh_rx = NLMSG_NEXT (nas_nlh_rx, len)) {
                start_meas(&ip_pdcp_stats_tmp);

                /* There is no need to check for nlmsg_type because
                 * the header is not set in our drivers.
                 */
                if (pdcp_thread_read_state == 0) {
                    new_data_p = malloc(sizeof(struct pdcp_netlink_element_s));

                    if (nas_nlh_rx->nlmsg_len == sizeof (pdcp_data_req_header_t) + sizeof(struct nlmsghdr)) {
                        pdcp_thread_read_state = 1;
                        memcpy((void *)&new_data_p->pdcp_read_header, (void *)NLMSG_DATA(nas_nlh_rx), sizeof(pdcp_data_req_header_t));
                        LOG_I(PDCP, "[NETLINK_THREAD] RX pdcp_data_req_header_t inst %u, "
                              "rb_id %u data_size %d\n",
                              new_data_p->pdcp_read_header.inst,
                              new_data_p->pdcp_read_header.rb_id,
                              new_data_p->pdcp_read_header.data_size);
                    } else {
                        LOG_E(PDCP, "[NETLINK_THREAD] WRONG size %d should be sizeof "
                              "%d ((pdcp_data_req_header_t) + sizeof(struct nlmsghdr))\n",
                              nas_nlh_rx->nlmsg_len,
                              sizeof (pdcp_data_req_header_t) + sizeof(struct nlmsghdr));
                    }
                } else {
                    pdcp_thread_read_state = 0;

#ifdef OAI_EMU

                    // LG: new_data_p->pdcp_read_header.inst will contain in fact a module id
                    if (new_data_p->pdcp_read_header.inst >= oai_emulation.info.nb_enb_local) {
                        module_id = new_data_p->pdcp_read_header.inst
                                    - oai_emulation.info.nb_enb_local +
                                    + oai_emulation.info.first_ue_local;
                        eNB_flag = 0;
                    } else {
                        module_id = new_data_p->pdcp_read_header.inst
                                    + oai_emulation.info.first_enb_local;
                        eNB_flag = 1;
                    }

#else
                    module_id = 0;
#endif
                    new_data_p->data = malloc(sizeof(uint8_t) * new_data_p->pdcp_read_header.data_size);
                    /* Copy the data */
                    memcpy(new_data_p->data, NLMSG_DATA(nas_nlh_rx), new_data_p->pdcp_read_header.data_size);

                    if (eNB_flag) {
                        if (pdcp_netlink_nb_element_enb[module_id]
                                > PDCP_QUEUE_NB_ELEMENTS) {
                            LOG_E(PDCP, "[NETLINK_THREAD][Mod %02x] We reached maximum number of elements in eNB pdcp queue (%d)\n",
                                  module_id, pdcp_netlink_nb_element_enb);
                        }

                        LOG_I(PDCP,"[NETLINK_THREAD] IP->PDCP : En-queueing packet for eNB module id %d\n", module_id);

                        /* Enqueue the element in the right queue */
                        lfds611_queue_guaranteed_enqueue(pdcp_netlink_queue_enb[module_id], new_data_p);
                        stop_meas(&ip_pdcp_stats_tmp);
                        copy_meas(&eNB_pdcp_stats[module_id].pdcp_ip,&ip_pdcp_stats_tmp);
                    } else {
                        if (pdcp_netlink_nb_element_ue[module_id]
                                > PDCP_QUEUE_NB_ELEMENTS) {
                            LOG_E(PDCP, "[NETLINK_THREAD][Mod %02x] We reached maximum number of elements in UE pdcp queue (%d)\n",
                                  module_id, pdcp_netlink_nb_element_ue);
                        }

                        LOG_I(PDCP,"[NETLINK_THREAD] IP->PDCP : En-queueing packet for UE module id  %d\n", module_id);

                        /* Enqueue the element in the right queue */
                        lfds611_queue_guaranteed_enqueue(pdcp_netlink_queue_ue[module_id], new_data_p);
                        stop_meas(&ip_pdcp_stats_tmp);
                        copy_meas(&UE_pdcp_stats[module_id].pdcp_ip,&ip_pdcp_stats_tmp);
                    }
                }
            }
        }
    }

    return NULL;
}