COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
netperf_send.cpp File Reference
#include "agent/agentclass.h"
#include "support/jsondef.h"
#include "support/sliplib.h"
Include dependency graph for netperf_send.cpp:

Macros

#define INFO_SIZE   32
 

Functions

int main (int argc, char *argv[])
 

Variables

char address [20] = "127.0.0.1"
 
uint16_t bsize = 1500
 
uint16_t delay = 1
 
uint16_t packets = 10000
 
float speed = 281250.
 
double cmjd
 

Macro Definition Documentation

#define INFO_SIZE   32

Function Documentation

int main ( int  argc,
char *  argv[] 
)
44 {
45  bool error_injector_data_enable = false; // Choose to enable error in data section
46  int error_injector_data_counter = 100; // Inject error starting at packet 100
47  bool error_injector_runt_enable = false; // Choose to enable error in data section
48  int error_injector_runt_counter = 150; // Inject error starting at packet 150
49  bool error_injector_drop_enable = false; // Choose to enable error in data section
50  int error_injector_drop_counter = 175; // Inject error starting at packet 175
51 
52  int32_t iretn;
53  uint16_t count=0;
54  socket_channel chan;
55  uint8_t buf1[10000];
56  char buf2[10000];
57  int32_t lsleep;
58  uint16_t nbytes;
59 
60  switch (argc)
61  {
62  case 6:
63  delay = atoi(argv[5]);
64  case 5:
65  packets = atoi(argv[4]);
66  if (packets > 9999)
67  {
68  packets = 9999;
69  }
70  case 4:
71  speed = atoi(argv[3]);
72  case 3:
73  bsize = atoi(argv[2]);
74  if (bsize > 9999)
75  {
76  bsize = 9999;
77  }
78  if (bsize < INFO_SIZE)
79  {
80  bsize = INFO_SIZE;
81  }
82  case 2:
83  strcpy(address,argv[1]);
84  break;
85  }
86 
88  {
89  printf("Unable to open connection to [%s:6101]\n",address);
90  }
91 
92  COSMOS_USLEEP(delay*1000000);
93  while (count < packets)
94  {
95  cmjd = currentmjd(0.);
96  for (uint16_t i=0; i<bsize-INFO_SIZE; i++)
97  {
98 #if defined(COSMOS_WIN_OS)
99  buf1[i] = (char)rand();
100 #else
101  buf1[i] = (char)random();
102 #endif
103  }
104 
105 
106  sprintf(buf2,"%.15g %4d %4x %4d ",currentmjd(0.), count++, slip_calc_crc((uint8_t *)buf1,bsize-INFO_SIZE), bsize);
107  memcpy(&buf2[INFO_SIZE],(const char *)buf1,bsize-INFO_SIZE);
108 
109  // Added 20130726JC: Inject errors to test listener
110  if (error_injector_data_counter-- == 0 && error_injector_data_enable)
111  {
112  buf2[500] = (uint8_t)0xf1;
113  error_injector_data_counter = 100; // Error every 100 packets
114  }
115  if (error_injector_runt_counter-- == 0 && error_injector_runt_enable)
116  {
117  error_injector_runt_counter = 100; // Error every 100 packets
118  }
119  if (error_injector_drop_counter-- == 0 && error_injector_drop_enable)
120  {
121  // Skip packet
122  error_injector_drop_counter = 100; // Error every 100 packets
123  nbytes = 0;
124  }
125  else
126  {
127  // Send packet
128  nbytes = sendto(chan.cudp, (const char *)buf2, bsize, 0, (struct sockaddr *)&chan.caddr, sizeof(struct sockaddr_in));
129  }
130  lsleep = 1e6 * ((nbytes+28)/speed - 86400. * (currentmjd(0.) - cmjd));
131  if (lsleep < 0) lsleep = 0;
132  printf("[%6d: %4d] %6d\r", count, nbytes, lsleep);
133  fflush(stdout);
134  COSMOS_USLEEP(lsleep);
135  }
136 
137 }
uint16_t packets
Definition: netperf_send.cpp:39
Agent socket using Unicast UDP.
char address[20]
Definition: netperf_send.cpp:36
int i
Definition: rw_test.cpp:37
int count
Definition: rw_test.cpp:36
#define INFO_SIZE
Definition: netperf_send.cpp:34
int iretn
Definition: rw_test.cpp:37
uint16_t delay
Definition: netperf_send.cpp:38
#define SOCKET_TALK
Talk followed by optional listen (sendto address)
Definition: socketlib.h:82
int32_t cudp
Definition: socketlib.h:120
Definition: socketlib.h:115
struct sockaddr_in caddr
Definition: socketlib.h:122
#define SOCKET_BLOCKING
Blocking Agent.
Definition: socketlib.h:78
#define AGENTRCVTIMEO
Default AGENT socket RCVTIMEO (100 msec)
Definition: agentclass.h:208
uint16_t slip_calc_crc(uint8_t *buf, uint16_t size)
Calculate CRC-16-CCITT.
Definition: sliplib.cpp:322
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65
float speed
Definition: netperf_send.cpp:40
uint16_t bsize
Definition: netperf_send.cpp:37
int32_t socket_open(socket_channel *channel, NetworkType ntype, const char *address, uint16_t port, uint16_t role, bool blocking, uint32_t usectimeo, uint32_t rcvbuf, uint32_t sndbuf)
Open UDP socket.
Definition: socketlib.cpp:51
double cmjd
Definition: netperf_send.cpp:41

Variable Documentation

char address[20] = "127.0.0.1"
uint16_t bsize = 1500
uint16_t delay = 1
uint16_t packets = 10000
float speed = 281250.
double cmjd