示例#1
0
static   int
pm_start(void * pio)
{
   pf_start();
   ns_printf(pio, "Profiling started.\n");
   return 0;
}
示例#2
0
static void rpc_client(struct ns_connection *nc, int ev, void *ev_data) {
  struct http_message *hm = (struct http_message *) ev_data;
  struct ns_rpc_reply rpc_reply;
  struct ns_rpc_error rpc_error;
  struct json_token toks[20];
  char buf[100];

  switch (ev) {
    case NS_CONNECT:
      ns_rpc_create_request(buf, sizeof(buf), "sum", "1", "[f,f,f]",
                            1.0, 2.0, 13.0);
      ns_printf(nc, "POST / HTTP/1.0\r\nContent-Type: application/json\r\n"
                "Content-Length: %d\r\n\r\n%s", (int) strlen(buf), buf);
      break;
    case NS_HTTP_REPLY:
      ns_rpc_parse_reply(hm->body.p, hm->body.len,
                         toks, sizeof(toks) / sizeof(toks[0]),
                         &rpc_reply, &rpc_error);
      if (rpc_reply.result != NULL) {
        sprintf((char *) nc->user_data, "%d %.*s %.*s",
                rpc_reply.id->type, (int) rpc_reply.id->len, rpc_reply.id->ptr,
                (int) rpc_reply.result->len, rpc_reply.result->ptr);
      }
      break;
    default:
      break;
  }
}
示例#3
0
int 
nv_del_entry(void * pio, int index, struct nv_sectioninfo *sec)
{
   GEN_STRUCT entry;
   char *   cp;

   if ( index == NOT_A_SECTION )
   {
      ns_printf(pio,"Could not find info about table. Can't process cmd.\n");
      return -1;
   }

   cp = nextarg( ((GEN_IO)pio)->inbuf );  /* see if user put parm on cmd line */
   if (!*cp)
   {
      if ( sec[index].usage_func )
         sec[index].usage_func(pio);
      return -1;
   }

   entry = niche_list_getat((NICHELIST)sec[index].list,atoi(cp));
   if ( entry )
   {
      niche_del((NICHELIST)sec[index].list,entry);
      return SUCCESS;
   }
   else
      return -1;
}
示例#4
0
int
set_nv_params(void * pio)
{
   NV_FILE * fp;        /* file with nvram data */
   struct nvparm_format * curr_format = nv_formats;

   fp = nv_fopen(nvfilename, "w");
   if (!fp)
   {
      ns_printf(pio, "Unable to open NV Parameters file \"%s\"\n", nvfilename);
      return -1;
   }

   while (curr_format)
   {
      curr_format->setfunc(fp);
      curr_format = curr_format->next_format;
   }

   nv_fclose(fp);

#ifdef HT_SYNCDEV
   if (nv_writeflash)   /* make sure pointer is set */
      nv_writeflash();  /* call optional per-port flash write routine */
#endif

   return 0;
}
示例#5
0
static const char *test_http_index(void) {
  struct ns_mgr mgr;
  struct ns_connection *nc;
  const char *local_addr = "127.0.0.1:7777";
  char buf[20] = "";

  ns_mgr_init(&mgr, NULL);
  ASSERT((nc = ns_bind(&mgr, local_addr, cb1)) != NULL);
  ns_set_protocol_http_websocket(nc);

  /* Test directory. */
  ASSERT((nc = ns_connect(&mgr, local_addr, cb9)) != NULL);
  ns_set_protocol_http_websocket(nc);
  nc->user_data = buf;
  ns_printf(nc, "GET /%s HTTP/1.0\n\n", "/");

  system("echo testdata >index.html");

  /* Run event loop. Use more cycles to let file download complete. */
  poll_mgr(&mgr, 200);
  ns_mgr_free(&mgr);
  system("rm index.html");

  /* Check that test buffer has been filled by the callback properly. */
  ASSERT(strcmp(buf, "testdata\n") == 0);

  return NULL;
}
示例#6
0
int dump_buf_estats (void * pio)
{
   u_long mlocal [MEMERR_NUM_STATS];

   LOCK_NET_RESOURCE(FREEQ_RESID);
   ENTER_CRIT_SECTION(&memestats);
   MEMCPY (&mlocal, &memestats, sizeof(memestats));
   EXIT_CRIT_SECTION(&memestats);
   UNLOCK_NET_RESOURCE(FREEQ_RESID);

   ns_printf(pio, "Regular buffer error statistics:\n");
   ns_printf(pio, "Bad buffer length %lu, Guard band violations %lu\n",mlocal[BAD_REGULAR_BUF_LEN_ERR],mlocal[GUARD_BAND_VIOLATED_ERR]);
   ns_printf(pio, "Multiple frees %lu, Inconsistent location %lu\n",mlocal[MULTIPLE_FREE_ERR],mlocal[INCONSISTENT_LOCATION_ERR]);

   return 0;
}
示例#7
0
int
simquit(void * pio)
{
   PACKET   pkt;
   ip_addr  hop;
   struct ip * pip;
   
   if(simtimer)
   {
      in_timerkill(simtimer);
      simtimer = 0;
   }

   /* send all queued packets */
   while(simq.q_head)
   {
      pkt = (PACKET)getq(&simq); /* get pkt to send */
      hop = pkt->fhost;          /* get hop from host field */
      pip = ip_head(pkt);        /* get real host address */
      pkt->fhost = pip->ip_dest; /* restore host field */
      ip2mac(pkt, hop);          /* send pkt to hardware */
   }
   rfsim_routing = FALSE;
   ns_printf(pio, "rfsim stopped\n");
   return 0;
}
示例#8
0
int
tfc_done(int status, struct tfconn *cn, char *msg)
{
   ip_addr fhost = cn->tf_fhost;
   unsigned dir = cn->tf_dir;

   ns_printf(last_pio, "tftp %s %u.%u.%u.%u done; ",
             (dir == PUT) ? "to" : "from", PUSH_IPADDR(fhost));

   ns_printf(last_pio, "msg: %s, status:%s(%d)\n",
             msg ? msg : "None", (status == 0) ? "ok" : "error", status);

   last_pio = NULL;  /* clear this - default back to console */

   return 0;
}
示例#9
0
void log_with_type(log_data_t *p, logTypeEnum log_type, char *pstr, int printf_flag)
{
   char timeBuffer[100];
   if(log_type >  LOG_TYPE_NONE && log_type < LOG_TYPE_MAX_NUM)
   {
      if(p == NULL)
      {
         return;
      }
      if(log_type > p->log_level)
      {
         return;
      }
      p->log_counts[log_type]++;
      if(pstr)
      {
         convLocalTimeToString(timeBuffer);
#ifdef USE_LOGFILE
         if(p->log_fp)
         {
            nv_fprintf(p->log_fp, "%s %lu %s %s\n", logTypeStr[log_type], p->log_counts[log_type], timeBuffer, pstr);
         }
#endif
         if(printf_flag)
         {
            ns_printf(p->pio, "%s %lu %s %s\n", logTypeStr[log_type], p->log_counts[log_type], timeBuffer, pstr);
         }
      }
   }
}   /* log_with_type() */
示例#10
0
文件: task.c 项目: fjanssen/Car2X
int
tk_stats(void * pio) 
{
#ifdef NET_STATS
   task *tk;
   char *   state;

   ns_printf(pio, "tasking status:");
   ns_printf(pio, "task wakeups: %D\n", tk_wakeups);
   ns_printf(pio, "   name          \tstate   \tstack\tused\twakes\n");

   tk = tk_cur;
   do    /* measure stack usage using guardword pattern */
   {
      stack_t * up;
      int   i; /* number of unused words in stack area */

      up = tk->tk_guard;
#ifdef STK_TOPDOWN
      for (i = tk->tk_size/sizeof(stack_t) -1; i; i--)
         if (*up++ != GUARDWORD) break;
#else /* BOTTOMUP */
      for (i = tk->tk_size/sizeof(stack_t) -1; i; i--)
         if (*up-- != GUARDWORD) break;
#endif

      if (tk == tk_cur)
         state = "running ";
      else if(tk->tk_event)
         state = "event_wt";
      else if(tk->tk_waketick)
         state = "sleeping";
      else if(tk->tk_flags & TF_AWAKE)
         state = "ready   ";
      else
         state = "blocked ";

      ns_printf(pio, "%-18s\t%s\t%u\t%u\t%lu\n", 
       tk->tk_name, state,
       tk->tk_size, i*sizeof(stack_t), tk->tk_count);
      tk = tk->tk_next;
   } while (tk != tk_cur);
#else
   USE_VOID(pio);
#endif
   return 0;
}
示例#11
0
static   int
pm_stop(void * pio)
{
   pf_stop();
   ns_printf(pio, "Profiling stopped.\n");
   pf_stats(pio);
   return 0;
}
示例#12
0
int
ftp_move(void * pio, int direction)
{
   char *   sfile=NULL; /* name of source file to put/get */
   char *   dfile;   /* optional name */
   GEN_IO io= (GEN_IO) pio ;
   unsigned long int transfer_type;

   if ( ftp_get_con(pio) == NULL )
   {
      ns_printf(pio,"Open FTP session first\n");
      return -1;
   }

   /* extract args from command buffer */
   if ( io != NULL )
      sfile = nextarg(io->inbuf);   /* name of source file */
   if (!sfile || !*sfile)
   {
      ns_printf(pio,"usage: ftp put|get filename [destname]\n");
      return -1;
   }
   dfile = nextarg(sfile);
   if (dfile && *dfile) /* optional dest name given? */
      *(dfile-1) = 0;   /* null terminate source file name */
   else
      dfile = sfile;    /* use foreign name for both */

   if (direction) transfer_type = FTPC_GET_TRANSFER;
   else transfer_type = FTPC_PUT_TRANSFER;
   
#ifdef OS_PREEMPTIVE
   ftpc_send_msg4 (FTPC_CNTRL_MOVE_FILE, 
                   (u_long) pio, 
                   (u_char *) &transfer_type,
                   sizeof (transfer_type),
                   (u_char *) sfile,
                   (strlen (sfile) + 1),
                   (u_char *) dfile,
                   (strlen (dfile) + 1));
#else
   ftpc_process_move (pio, transfer_type, sfile, dfile);
#endif                   

   return 0;
}
示例#13
0
文件: testmenu.c 项目: fjanssen/Car2X
int
freeq_refill(void * pio)
{
   ns_printf(pio, "restoring free pkts queues\n");
   q_drain(&bigqback, &bigfreeq);
   q_drain(&lilqback, &lilfreeq);
   return 0;
}
示例#14
0
文件: testmenu.c 项目: fjanssen/Car2X
int
pktq_drain(void * pio)
{
   ns_printf(pio, "draining both free queue into tmp que\n");
   q_drain(&bigfreeq, &bigqback);
   q_drain(&lilfreeq, &lilqback);
   return 0;
}
示例#15
0
static const char *test_http(void) {
  struct ns_mgr mgr;
  struct ns_connection *nc;
  const char *local_addr = "127.0.0.1:7777";
  char buf[20] = "", status[20] = "", mime[20] = "";

  ns_mgr_init(&mgr, NULL);
  ASSERT((nc = ns_bind(&mgr, local_addr, cb1)) != NULL);
  ns_set_protocol_http_websocket(nc);

  /* Valid HTTP request. Pass test buffer to the callback. */
  ASSERT((nc = ns_connect(&mgr, local_addr, cb2)) != NULL);
  ns_set_protocol_http_websocket(nc);
  nc->user_data = buf;
  ns_printf(nc, "%s", "POST /foo HTTP/1.0\nContent-Length: 10\n\n"
            "0123456789");

  /* Invalid HTTP request */
  ASSERT((nc = ns_connect(&mgr, local_addr, cb2)) != NULL);
  ns_set_protocol_http_websocket(nc);
  ns_printf(nc, "%s", "bl\x03\n\n");

  /* Test static file download by downloading this executable, argv[0] */
  ASSERT((nc = ns_connect(&mgr, local_addr, cb7)) != NULL);
  ns_set_protocol_http_websocket(nc);
  nc->user_data = status;
  ns_printf(nc, "GET /%s HTTP/1.0\n\n", s_argv_0);

  /* Test mime type for static file */
  ASSERT((nc = ns_connect(&mgr, local_addr, cb10)) != NULL);
  ns_set_protocol_http_websocket(nc);
  nc->user_data = mime;
  ns_printf(nc, "%s", "GET /data/dummy.xml HTTP/1.0\n\n");

  /* Run event loop. Use more cycles to let file download complete. */
  poll_mgr(&mgr, 200);
  ns_mgr_free(&mgr);

  /* Check that test buffer has been filled by the callback properly. */
  ASSERT(strcmp(buf, "[/foo 10]") == 0);
  ASSERT(strcmp(status, "success") == 0);
  ASSERT(strcmp(mime, "text/xml") == 0);

  return NULL;
}
示例#16
0
int
sock_list(void * pio)
{
   struct inpcb * inp;
   struct socket *   so;
   struct tcpcb * tp;

   if (tcb.inp_next == NULL)
   {
      ns_printf(pio,"No TCP sockets\n");
      return 0;
   }

   ns_printf(pio,
    "TCP sock, fhost,     ports,    opts, rxbytes, txbytes, snd_una, snd_nxt, state:\n");
   for (inp = tcb.inp_next; inp != &tcb; inp = inp->inp_next) 
   {
      tp = intotcpcb(inp);
      so = inp->inp_socket;
      if (!so)
      {
         ns_printf(pio,"No socket\n");
         continue;
      }

#ifdef IP_V4
      if(so->so_domain == AF_INET)
      ns_printf(pio,"%lx,  %u.%u.%u.%u", so, PUSH_IPADDR(inp->inp_faddr.s_addr));
#endif
#ifdef IP_V6
      if(so->so_domain == AF_INET6)
      {
         char  ip6buf[46];
         ns_printf(pio,"%lx,  %s(v6), ", so, print_ip6(&inp->ip6_faddr, &ip6buf[0]));
      }
#endif   /* IP_V6 */

      ns_printf(pio,", %u->%u, ", htons(inp->inp_lport), htons(inp->inp_fport));
      ns_printf(pio,"0x%x, %u, %u, %ld, %ld, ", (unsigned)so->so_options,
       (unsigned)so->so_rcv.sb_cc,(unsigned)so->so_snd.sb_cc,
       tp->snd_una, tp->snd_nxt);
      if ((tp->t_state < 0) || 
          (tp->t_state >= sizeof(tcpstates)/sizeof(tcpstates[0])))
         ns_printf(pio, "???\n");
      else
         ns_printf(pio, "%s\n", tcpstates[tp->t_state]);
   }

   return udpsock_list(pio);
}
示例#17
0
int
tcp_cecho_close(void * pio)
{
   TCPCLIENT  tcpclient;

   tcpclient=tcp_client_from_pio(pio);
   if (tcpclient == NULL)
   {
      ns_printf(pio,"No TCP Echo Client found for this session.\n");   
      return TCPE_CLIENT_NOT_FOUND ;
   }
   else
   {
      ns_printf(pio,"Closing TCP Echo Client.\n");   
      return tcp_client_del(tcpclient);
   }

}
示例#18
0
文件: rfsim.c 项目: fjanssen/Car2X
int
simtime(void * pio)
{
   char *   arg;
   long     msecs;

   arg = nextarg(((GEN_IO)pio)->inbuf);
   msecs = atol(arg);
   if(msecs == 0)
   {
      ns_printf(pio, "To set latency to 0 just shut sim off\n");
      return 0;
   }
   sim_latency = (msecs * TPS)/1000;
   ns_printf(pio, "SIM Latency now %d ms. (%d ticks)\n", msecs, sim_latency);

   return 0;
}
示例#19
0
文件: iface.c 项目: fjanssen/Car2X
int
if_disable(void * pio)
{
   int   err;
   NET   ifp;

   ifp = if_getbypio(pio);
   if(ifp == NULL)
      return -1;

   err = ni_set_state(ifp, NI_DOWN);
   if(err)
      ns_printf(pio, "Error %d shuting down %s\n", err, ifp->name);
   else
      ns_printf(pio, "Shut down %s\n", ifp->name);

   return (err);
}
示例#20
0
文件: iface.c 项目: fjanssen/Car2X
int
if_enable(void * pio)
{
   int   err;
   NET   ifp;

   ifp = if_getbypio(pio);
   if(ifp == NULL)
      return -1;

   err = ni_set_state(ifp, NI_UP);
   if(err)
      ns_printf(pio, "Error %d enabling %s\n", err, ifp->name);
   else
      ns_printf(pio, "Enabled %s\n", ifp->name);

   return err;
}
示例#21
0
int help(void) 
{
	int i = 0;

	// Print some header text.
	ns_printf("\n" BOLD_GREEN("NanoShell available commands:") "\n");
	ns_printf("------------------\n");
		
	for (i = 0; commands[i].command_name != 0; i++) 
	{
		// Print the command name and the brief description.
		ns_printf(BOLD_YELLOW("%s") " - " BOLD_CYAN("%s\n"), commands[i].command_name,
                (commands[i].pcHelp==0)? "No Help. available" : commands[i].pcHelp);
	}
	ns_printf ("\r\n");

	return 0;
}
示例#22
0
// Outputs an HTTP 200 on the supplied connection for an OPTIONS request
void sendOptions(struct ns_connection *nc)    {
    // Send HTTP 200
    ns_printf(nc, "HTTP/1.1 200 Ok\r\n"
              "Access-Control-Allow-Origin: *\r\n"
              "Access-Control-Allow-Methods: GET, OPTIONS\r\n"
              "Access-Control-Max-Age: 86400\r\n"
              "Content-Length: 0\r\n");
    
}
示例#23
0
// Outputs an HTTP 409 on the supplied connection
void sendConflict(struct ns_connection *nc)    {
	// Send HTTP 409
	ns_printf(nc, "HTTP/1.1 409 Conflict\r\n"
		"Content-Type: application/json\r\n"
		"Cache-Control: no-cache\r\n"
        "Access-Control-Allow-Origin: *\r\n"
		"Content-Length: %d\r\n\r\n%s",
		(int)strlen(HTTP_RESPONSE_409), HTTP_RESPONSE_409);
}
示例#24
0
// Outputs an HTTP 503 on the supplied connection
void sendServiceUnavailable(struct ns_connection *nc)    {
    // Send HTTP 503
	ns_printf(nc, "HTTP/1.1 503 Service unavailable\r\n"
		"Content-Type: application/json\r\n"
		"Cache-Control: no-cache\r\n"
        "Access-Control-Allow-Origin: *\r\n"
		"Content-Length: %d\r\n\r\n%s",
		(int)strlen(HTTP_RESPONSE_503), HTTP_RESPONSE_503);
}
示例#25
0
int
upnp_stats(void * pio)
{
   int   i;

   ns_printf(pio, "UPnP stats:\n");
   
   for(i = 0; i < MAXNETS; i++)
   {
      if(nets[i] == NULL)
         break;
      ns_printf(pio, "iface %s; state:%s; current IP:%u.%u.%u.%u\n",
         nets[i]->name, upnp_states[upnp[i].state],
         PUSH_IPADDR(nets[i]->n_ipaddr));
   }

   return 0;
}
示例#26
0
int
udp_cecho_close(void * pio)
{
   UDPCLIENT udpclient;

   udpclient=udp_client_from_pio(pio);
   if (udpclient == NULL )
   {
      ns_printf(pio,"echo socket not open\n");
      return UDPE_NO_CONN_FOUND;
   }

   ns_printf(pio,"udp echo - closing client socket\n");

   udp_client_del(udpclient);

   return SUCCESS;
}
示例#27
0
文件: iface.c 项目: fjanssen/Car2X
int
if_listifs(void * pio)
{
   NET   ifp;
   IFMIB mib;
   int   i = 1;   /* Ones based iface index */

   for(ifp = (NET)netlist.q_head; ifp; ifp = ifp->n_next)
   {
      mib = ifp->n_mib;
      ns_printf(pio, "%d - %s - %s ",
         i++, ifp->name, mib->ifDescr);

      ns_printf(pio, "(Admin:%s, Oper:%s)\n",
         (mib->ifAdminStatus==NI_UP)?"up":"down" ,
         (mib->ifOperStatus==NI_UP)?"up":"down" );
   }
   return 0;
}
示例#28
0
int 
tcp_client_del(TCPCLIENT tcpclient)
{
   int   e;
   TCPCLIENT tmpclient, prevclient;

   /* Close the underlying socket */
   if (tcpclient->sock != INVALID_SOCKET)
   {  
      e = socketclose(tcpclient->sock);
      if (e)
      {
         e = t_errno(tcpclient->sock);
         ns_printf(tcpclient->pio,"tcp echo: close error %d\n", e);
      }
   }

   /* Remove from the q */
   if (tcpq == tcpclient)
   {
      /* It is the first node */
      tcpq = tcpq->next;
   }
   else
   {
      prevclient=tcpq;
      tmpclient=tcpq->next;
      while (tmpclient)
      {
         if (tmpclient == tcpclient)
         {
            /* Found the node in the list */
            prevclient->next=tmpclient->next ;
            break;
         }
         else
         {
            prevclient=tmpclient;
            tmpclient=tmpclient->next ;
         }
      }

      /* Was the node found in Q ? */
      if (tmpclient == NULL)
      {
         /* Node not found in Q !! */
         dtrap();
         return TCPE_NODE_NOT_FOUND ;
      }
   }

   npfree(tcpclient);

   return SUCCESS;
}
示例#29
0
static int
pf_stats(void * pio)
{
   int   i;
   int   pct;
   int   dec;
   u_long   total;

   if (pfrunning)
   {
      ns_printf(pio, "Profiling, please stop first.\n");
      return -1;
   }

   /* get total elapsed ticks. Check for wrap. If it wrapped more than
    * once then we are hosed:
    */
   if(stop_tick > start_tick)
      total = stop_tick - start_tick;
   else
      total = stop_tick + (0xFFFFFFFF - start_tick);

   ns_printf(pio, "total ticks:%10lu\n", total);

   if (total == 0)
      return 0;

   ns_printf(pio, "  module  ticks     (percent)\n");

   /* display the bucket times */
   for (i = 0; i< NUM_PBUCKETS; i++)
   {
      /* skip entrys which are not set */
      if (in_pbuckets[i].name == NULL)
         continue;
      pf_percent(total, in_pbuckets[i].ticks, &pct, &dec);
      ns_printf(pio, "%11s %10lu (%3u.%u)\n", in_pbuckets[i].name,
         in_pbuckets[i].ticks, pct, dec );
   }

   return 0;
}
示例#30
0
int 
udp_secho_init(void * pio)
{
   int   e;    /* error holder */
   struct sockaddr_in   me;   /* my IP info, for bind() */
   SOCKTYPE sock;

   if ( es_sock != INVALID_SOCKET )
   {
      ns_printf(pio,"udp echo server is already running.\n" );
      return SUCCESS;
   }
   ns_printf(pio,"udp echo server is starting.\n" );

   /* open UDP socket */
   sock = socket(AF_INET, SOCK_DGRAM, 0);
   if (sock == INVALID_SOCKET)
   {
      ns_printf(pio,"udp_echo: bad socket: %d\n", sock);
      return UDPE_SRV_BAD_SOCKET;
   }

   me.sin_family = AF_INET;
   me.sin_addr.s_addr = INADDR_ANY;
   me.sin_port = htons(ECHO_PORT);

   e = bind(sock, (struct sockaddr*)&me, sizeof(me));
   if (e != 0)
   {
      e = t_errno(sock);
      ns_printf(pio,"udp_echo: bind error: %d\n", e);
      socketclose(sock);
      return UDPE_SRV_BIND_FAILED;
   }

   es_sock = sock;

   /* put socket into non-blocking mode */
   setsockopt(sock, SOL_SOCKET, SO_NBIO, NULL, 0);

   return SUCCESS;
}