-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathumsub.c
1777 lines (1631 loc) · 58.4 KB
/
umsub.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
"umsub.c: application that receives messages from a set of topics
" Streaming, Persistence, or Queuing (multiple receivers).
Copyright (c) 2005-2012 Informatica Corporation Permission is granted to licensees to use
or alter this software for any purpose, including commercial applications,
according to the terms laid out in the Software License Agreement.
This source code example is provided by Informatica for educational
and evaluation purposes only.
THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES
EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF
NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE
UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE
LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR
INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE
TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF
THE LIKELIHOOD OF SUCH DAMAGES.
*/
#ifdef __VOS__
#define _POSIX_C_SOURCE 200112L
#include <sys/time.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#ifdef _WIN32
#include <winsock2.h>
#include <sys/timeb.h>
#define strcasecmp stricmp
#define snprintf _snprintf
#else
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <signal.h>
#include <sys/time.h>
#include <pthread.h>
#endif
#if !defined(_WIN32)
#include <sys/utsname.h>
#endif
#include "replgetopt.h"
#include <lbm/lbm.h>
#include <lbm/lbmmon.h>
#include "monmodopts.h"
#include "lbm-example-util.h"
#define UM_PUB_VERSION "0.1"
#if defined(_WIN32)
# define SLEEP_SEC(x) Sleep((x)*1000)
# define SLEEP_MSEC(x) Sleep(x)
#else
# define SLEEP_SEC(x) sleep(x)
# define SLEEP_MSEC(x) \
do{ \
if ((x) >= 1000){ \
sleep((x) / 1000); \
usleep((x) % 1000 * 1000); \
} \
else{ \
usleep((x)*1000); \
} \
}while (0)
#endif /* _WIN32 */
const char Purpose[] = "Purpose: Receive messages on multiple topics.";
const char Usage[] =
"Usage: %s [options]\n"
" -A, --ascii-mode Print message payload as ASCII text\n"
" -B, --bufsize=# Set receive socket buffer size to # (in MB)\n"
" -c, --config=FILE Use LBM configuration file FILE.\n"
" Multiple config files are allowed.\n"
" Example: '-c file1.cfg -c file2.cfg'\n"
" -C, --contexts=NUM use NUM lbm_context_t objects\n"
" -E, --exit exit and end upon receiving End-of-Stream notification\n"
" -e, --end-flag=FILE clean up and exit when file FILE is created\n"
" -F, --hot-failover Use hot failover receivers\n"
" -h, --help display this help and exit\n"
" -i, --initial-topic=NUM use NUM as initial topic number\n"
" -N, --channel Use as initial channel number for Spectrum\n"
" -o, --ouput=FILE Dump metrics to CSV file\n"
" -L, --linger=NUM linger for NUM seconds after done\n"
" -p, --print-metrics Print metrics to stdout every N milliseconds\n"
" -Q, --event-queue Enable UM event queue\n"
" -r, --root=STRING use topic names with root of STRING\n"
" -R, --receivers=NUM create NUM receivers\n"
" -s, --statistics print statistics along with bandwidth\n"
" -S, --reset Resets the latency stats every print interval\n"
" -t, --measure-latency Calculate latency based on message payload timestamp. Use twice for round trip latency\n"
" -T, --eq-threads Use N threads for event queue processing\n"
" -v, --verbose be verbose\n"
" -w, --wildcard-pattern Create topic as wildcard pattern (appends .*)\n"
MONOPTS_RECEIVER
MONMODULEOPTS_SENDER;
const char * OptionString = "AB:c:C:Ee:Fhi:N:o:L:p:Qr:R:sStT:vw";
#define OPTION_MONITOR_RCV 0
#define OPTION_MONITOR_CTX 1
#define OPTION_MONITOR_TRANSPORT 2
#define OPTION_MONITOR_TRANSPORT_OPTS 3
#define OPTION_MONITOR_FORMAT 4
#define OPTION_MONITOR_FORMAT_OPTS 5
#define OPTION_MONITOR_APPID 6
#define DEFAULT_RESPONSE_LEN 25
typedef enum {
RCV_READAY,
START_RCVS,
NO_VALUE
} ReqType;
const struct option OptionTable[] =
{
{ "ascii", no_argument, NULL, 'A' },
{ "bufsize", required_argument, NULL, 'B' },
{ "config", required_argument, NULL, 'c' },
{ "contexts", required_argument, NULL, 'C' },
{ "help", no_argument, NULL, 'h' },
{ "exit", no_argument, NULL, 'E'},
{ "end-flag", required_argument, NULL, 'e' },
{ "hot-failover", no_argument, NULL, 'F' },
{ "initial-topic", required_argument, NULL, 'i' },
{ "channel", required_argument, NULL, 'N' },
{ "output-file", required_argument, NULL, 'o' },
{ "linger", required_argument, NULL, 'L' },
{ "print-metrics", required_argument, NULL, 'p' },
{ "event-queue", no_argument, NULL, 'Q' },
{ "root", required_argument, NULL, 'r' },
{ "receivers", required_argument, NULL, 'R' },
{ "statistics", no_argument, NULL, 's' },
{ "reset", no_argument, NULL, 'S' },
{ "measure-latency", no_argument, NULL, 't' },
{ "eq-threads", required_argument, NULL, 'T' },
{ "verbose", no_argument, NULL, 'v' },
{ "wildcard-pattern", no_argument, NULL, 'w' },
{ "monitor-rcv", required_argument, NULL, OPTION_MONITOR_RCV },
{ "monitor-ctx", required_argument, NULL, OPTION_MONITOR_CTX },
{ "monitor-transport", required_argument, NULL, OPTION_MONITOR_TRANSPORT },
{ "monitor-transport-opts", required_argument, NULL, OPTION_MONITOR_TRANSPORT_OPTS },
{ "monitor-format", required_argument, NULL, OPTION_MONITOR_FORMAT },
{ "monitor-format-opts", required_argument, NULL, OPTION_MONITOR_FORMAT_OPTS },
{ "monitor-appid", required_argument, NULL, OPTION_MONITOR_APPID },
{ NULL, 0, NULL, 0 }
};
#define DEFAULT_MAX_MESSAGES 10000000
#define MAX_NUM_RCVS 1000001
#define MAX_TOPIC_NAME_LEN 80
#define DEFAULT_NUM_RCVS 100
#define MAX_NUM_CTXS 50
#define MAX_OUTPUT_FILE_NAME_SIZE 256
#define DEFAULT_NUM_CTXS 1
#define DEFAULT_TOPIC_ROOT "29west.example.multi"
#define DEFAULT_INITIAL_TOPIC_NUMBER 0
#define DEFAULT_MAX_NUM_SRCS 10000
#define DEFAULT_NUM_SRCS 10
#define DEFAULT_LINGER_SECONDS 0
#define MAX_NUM_THREADS 16
int thrdidxs[MAX_NUM_THREADS];
struct Options {
char application_id_string[1024];
long bufsize;
char *end_flg_file;
int end_on_end;
const lbmmon_format_func_t *format;
const lbmmon_transport_func_t *transport;
char format_options_string[1024];
int initial_topic_number;
int linger;
int monitor_context;
int monitor_context_ivl;
int monitor_receiver;
int monitor_receiver_ivl;
int num_ctxs;
int num_rcvs;
int reserve_specific_index;
int reserve_index;
lbm_umq_index_info_t index;
int pstats;
char topicroot[80];
char transport_options_string[1024];
int verbose;
int ascii;
int use_hf;
int channel;
int eventq;
int threads;
int wildcard;
int dump_to_file;
char *output_file;
FILE *ofp;
int print_metrics;
int measure_latency;
int reset;
} options;
lbm_event_queue_t *evq = NULL;
int count = 0;
int msg_count = 0, total_msg_count = 0;
int byte_count = 0;
int unrec_count = 0, total_unrec_count = 0;
int close_recv = 0;
FILE *end_flg_fp = NULL;
int burst_loss = 0, total_burst_loss = 0;
/* Total stats */
int rxs = 0;
int otrs = 0;
int lstream = 0;
/* Previous Iteration */
int pre_rxs = 0;
int pre_otrs = 0;
int pre_lstream = 0;
lbm_ulong_t lost = 0, last_lost = 0;
lbm_rcv_transport_stats_t * stats = NULL;
int nstats = DEFAULT_NUM_SRCS;
lbm_response_t *response = NULL;
lbm_msg_t *response_msg = NULL;
ReqType isReady = NO_VALUE;
#if defined(_WIN32)
#define _SYS_NAMELEN 256
struct utsname {
char sysname[_SYS_NAMELEN]; /* Name of OS */
char nodename[_SYS_NAMELEN]; /* Name of this network node */
char release[_SYS_NAMELEN]; /* Release level */
char version[_SYS_NAMELEN]; /* Version level */
char machine[_SYS_NAMELEN]; /* Hardware type */
};
#endif
void print_platform_info()
{
#if defined(__linux__) || defined(Darwin)
struct utsname unm;
if (uname(&unm) == 0)
printf("* %s %s %s %s %s \n", unm.sysname, unm.nodename, unm.release, unm.version, unm.machine);
else
printf("* Could not determine system type\n");
#elif defined(_WIN32)
SYSTEM_INFO sinfo;
OSVERSIONINFO vinfo;
struct utsname unm;
DWORD namelen = sizeof(unm.nodename);
GetSystemInfo(&sinfo);
vinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&vinfo);
mul_snprintf(unm.sysname, sizeof(unm.sysname), "Windows");
if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
mul_snprintf(unm.release, sizeof(unm.release), "Windows 95/98/Me (%d.%d)", vinfo.dwMajorVersion, vinfo.dwMinorVersion);
} else if (vinfo.dwPlatformId = VER_PLATFORM_WIN32_NT) {
mul_snprintf(unm.release, sizeof(unm.release), "Windows NT %d.%d", vinfo.dwMajorVersion, vinfo.dwMinorVersion);
} else {
mul_snprintf(unm.release, sizeof(unm.release), "Unknown(%d %d.%d)", vinfo.dwPlatformId, vinfo.dwMajorVersion, vinfo.dwMinorVersion);
}
mul_snprintf(unm.version, sizeof(unm.version), "Build %d %s", vinfo.dwBuildNumber, vinfo.szCSDVersion);
switch (sinfo.wProcessorArchitecture) {
case PROCESSOR_ARCHITECTURE_AMD64:
mul_snprintf(unm.machine, sizeof(unm.machine), "x64-%x-%x %dx", sinfo.wProcessorLevel, sinfo.wProcessorRevision, sinfo.dwNumberOfProcessors);
break;
case PROCESSOR_ARCHITECTURE_IA64:
mul_snprintf(unm.machine, sizeof(unm.machine), "IA64-%x-%x %dx", sinfo.wProcessorLevel, sinfo.wProcessorRevision, sinfo.dwNumberOfProcessors);
break;
case PROCESSOR_ARCHITECTURE_INTEL:
mul_snprintf(unm.machine, sizeof(unm.machine), "x86-%x-%x %dx", sinfo.wProcessorLevel, sinfo.wProcessorRevision, sinfo.dwNumberOfProcessors);
break;
default:
mul_snprintf(unm.machine, sizeof(unm.machine), "%x-%x-%x %dx", sinfo.wProcessorArchitecture,
sinfo.wProcessorLevel, sinfo.wProcessorRevision, sinfo.dwNumberOfProcessors);
break;
}
GetComputerName(unm.nodename, &namelen);
printf("* %s %s %s %s %s\n", unm.sysname, unm.nodename, unm.release, unm.version, unm.machine);
#endif /* Linux */
}
double ow_total = 0.0, ow_min = 1000.0, ow_max = 0.0, ow_avg = 0.0;
int owts = 0;
char *rmessage;
/* Update 1-way latency stats */
void update_oneway_latency_stats(struct timeval *tsp, struct timeval *etv)
{
double sec = 0.0;
etv->tv_sec -= tsp->tv_sec;
etv->tv_usec -= tsp->tv_usec;
normalize_tv(etv);
sec = (double)etv->tv_sec + (double)etv->tv_usec / 1000000.0;
ow_total += sec;
if (sec < ow_min)
ow_min = sec;
if (sec >= ow_max)
ow_max = sec;
owts++;
}
/*
* For the elapsed time, calculate and print the msgs/sec and bits/sec as well
* as any unrecoverable data.
*/
void print_bw(FILE *fp, struct timeval *tv, unsigned int msgs, unsigned int bytes, int unrec, lbm_ulong_t lost, int rxs, int otrs)
{
char scale[] = {'\0', 'K', 'M', 'G'};
int msg_scale_index = 0, bit_scale_index = 0, rps_scale_index = 0;
double sec = 0.0, mps = 0.0, bps = 0.0, rps = 0.0;
double kscale = 1000.0;
if (tv->tv_sec == 0 && tv->tv_usec == 0) return;/* avoid div by 0 */
sec = (double)tv->tv_sec + (double)tv->tv_usec / 1000000.0;
mps = (double)msgs/sec;
rps = (double)rxs/sec;
bps = (double)bytes*8/sec;
while (mps >= kscale) {
mps /= kscale;
msg_scale_index++;
}
while (rps >= kscale) {
rps /= kscale;
rps_scale_index++;
}
while (bps >= kscale) {
bps /= kscale;
bit_scale_index++;
}
fprintf(fp, "%-5.4g secs. %-5.4g %cmsgs/sec. %-5.4g %cbps [Total: %d]", sec, mps, scale[msg_scale_index], bps, scale[bit_scale_index], total_msg_count);
if (lost != 0 || unrec != 0 || burst_loss != 0) {
fprintf(fp, " [%lu pkts lost, %u msgs unrecovered, %d loss bursts]", lost, unrec, burst_loss);
burst_loss = 0;
}
fputs("\n",fp);
fflush(fp);
}
/* Callback function used for printing metrics to stdout and dumping to file if configured */
int print_metrics(lbm_context_t *ctx, const void *clientd)
{
struct Options *opts = &options;
printf("Messages Received: Live[%d] RX[%d] OTR[%d]", lstream - pre_lstream, rxs - pre_rxs, otrs - pre_otrs);
if (opts->measure_latency > 0)
{
double ow_avg = ow_total / owts;
printf(" Latency seconds: Min[%.06f] Max[%.06f] Avg[%.06f]", ow_min, ow_max, ow_avg);
}
printf("\n");
if (opts->dump_to_file)
{
fprintf(opts->ofp, "%d,%d,%d,%.04f,%.04f,%.04f\n", lstream - pre_lstream, rxs - pre_rxs, otrs - pre_otrs, ow_min, ow_max, ow_avg);
fflush(opts->ofp);
}
if (opts->reset)
{
ow_total = 0.0;
ow_min = 1000.0;
ow_max = 0.0;
ow_avg = 0.0;
owts = 0;
}
}
/* Utility to print the contents of a buffer in hex/ASCII format */
void dump(const char *buffer, int size)
{
int i,j;
unsigned char c;
char textver[20];
for (i=0;i<(size >> 4);i++) {
for (j=0;j<16;j++) {
c = buffer[(i << 4)+j];
printf("%02x ",c);
textver[j] = ((c<0x20)||(c>0x7e))?'.':c;
}
textver[j] = 0;
printf("\t%s\n",textver);
}
for (i=0;i<size%16;i++) {
c = buffer[size-size%16+i];
printf("%02x ",c);
textver[i] = ((c<0x20)||(c>0x7e))?'.':c;
}
for (i=size%16;i<16;i++) {
printf(" ");
textver[i] = ' ';
}
textver[i] = 0;
printf("\t%s\n",textver);
}
/* Print transport statistics */
void print_stats(FILE *fp, lbm_rcv_transport_stats_t stats)
{
switch (stats.type) {
case LBM_TRANSPORT_STAT_TCP:
fprintf(fp, " [%s], received %lu, LBM %lu/%lu/%lu\n",
stats.source,stats.transport.tcp.bytes_rcved,
stats.transport.tcp.lbm_msgs_rcved,
stats.transport.tcp.lbm_msgs_no_topic_rcved,
stats.transport.tcp.lbm_reqs_rcved);
break;
case LBM_TRANSPORT_STAT_LBTRM:
{
char stmstr[256] = "", txstr[256] = "";
if (stats.transport.lbtrm.nak_tx_max > 0) {
/* we usually don't use sprintf, but should be OK here for the moment. */
sprintf(stmstr, ", nak stm %lu/%lu/%lu",
stats.transport.lbtrm.nak_stm_min, stats.transport.lbtrm.nak_stm_mean,
stats.transport.lbtrm.nak_stm_max);
sprintf(txstr, ", nak tx %lu/%lu/%lu",
stats.transport.lbtrm.nak_tx_min, stats.transport.lbtrm.nak_tx_mean,
stats.transport.lbtrm.nak_tx_max);
}
fprintf(fp, " [%s], received %lu/%lu, dups %lu, loss %lu, naks %lu/%lu, ncfs %lu-%lu-%lu-%lu, unrec %lu/%lu%s%s\n",
stats.source,
stats.transport.lbtrm.msgs_rcved, stats.transport.lbtrm.bytes_rcved,
stats.transport.lbtrm.duplicate_data,
stats.transport.lbtrm.lost,
stats.transport.lbtrm.naks_sent, stats.transport.lbtrm.nak_pckts_sent,
stats.transport.lbtrm.ncfs_ignored, stats.transport.lbtrm.ncfs_shed,
stats.transport.lbtrm.ncfs_rx_delay, stats.transport.lbtrm.ncfs_unknown,
stats.transport.lbtrm.unrecovered_txw,
stats.transport.lbtrm.unrecovered_tmo,
stmstr, txstr);
}
break;
case LBM_TRANSPORT_STAT_LBTRU:
{
char stmstr[256] = "", txstr[256] = "";
if (stats.transport.lbtru.nak_tx_max > 0) {
/* we usually don't use sprintf, but should be OK here for the moment. */
sprintf(stmstr, ", nak stm %lu/%lu/%lu",
stats.transport.lbtru.nak_stm_min, stats.transport.lbtru.nak_stm_mean,
stats.transport.lbtru.nak_stm_max);
sprintf(txstr, ", nak tx %lu/%lu/%lu",
stats.transport.lbtru.nak_tx_min, stats.transport.lbtru.nak_tx_mean,
stats.transport.lbtru.nak_tx_max);
}
fprintf(fp, " [%s], LBM %lu/%lu/%lu, received %lu/%lu, dups %lu, loss %lu, naks %lu/%lu, ncfs %lu-%lu-%lu-%lu, unrec %lu/%lu%s%s\n",
stats.source,
stats.transport.lbtru.lbm_msgs_rcved,
stats.transport.lbtru.lbm_msgs_no_topic_rcved,
stats.transport.lbtru.lbm_reqs_rcved,
stats.transport.lbtru.msgs_rcved, stats.transport.lbtru.bytes_rcved,
stats.transport.lbtru.duplicate_data,
stats.transport.lbtru.lost,
stats.transport.lbtru.naks_sent, stats.transport.lbtru.nak_pckts_sent,
stats.transport.lbtru.ncfs_ignored, stats.transport.lbtru.ncfs_shed,
stats.transport.lbtru.ncfs_rx_delay, stats.transport.lbtru.ncfs_unknown,
stats.transport.lbtru.unrecovered_txw,
stats.transport.lbtru.unrecovered_tmo,
stmstr, txstr);
}
break;
case LBM_TRANSPORT_STAT_LBTIPC:
{
fprintf(fp, " [%s] Received %lu msgs/%lu bytes. "
"%lu LBM msgs, %lu no topics, %lu requests.\n",
stats.source,
stats.transport.lbtipc.msgs_rcved,
stats.transport.lbtipc.bytes_rcved,
stats.transport.lbtipc.lbm_msgs_rcved,
stats.transport.lbtipc.lbm_msgs_no_topic_rcved,
stats.transport.lbtipc.lbm_reqs_rcved);
}
break;
case LBM_TRANSPORT_STAT_LBTRDMA:
{
fprintf(fp, " [%s] Received %lu msgs/%lu bytes. "
"%lu LBM msgs, %lu no topics, %lu requests.\n",
stats.source,
stats.transport.lbtrdma.msgs_rcved,
stats.transport.lbtrdma.bytes_rcved,
stats.transport.lbtrdma.lbm_msgs_rcved,
stats.transport.lbtrdma.lbm_msgs_no_topic_rcved,
stats.transport.lbtrdma.lbm_reqs_rcved);
}
break;
default:
break;
}
fflush(fp);
}
/* Event queue monitor callback (passed into lbm_event_queue_create()) */
int evq_monitor(lbm_event_queue_t *evq, int event, size_t evq_size,
lbm_ulong_t event_delay_usec, void *clientd)
{
printf("event queue threshold exceeded - event %x, sz %lu, delay %lu\n",
event, evq_size, event_delay_usec);
return 0;
}
/* context event handler for UMQ events */
int handle_ctx_event(lbm_context_t *ctx, int event, void *ed, void *cd)
{
switch (event) {
case LBM_CONTEXT_EVENT_UMQ_REGISTRATION_ERROR:
{
const char *errstr = (const char *)ed;
printf("Error registering ctx with UMQ queue: %s\n", errstr);
}
break;
case LBM_CONTEXT_EVENT_UMQ_REGISTRATION_SUCCESS_EX:
{
lbm_context_event_umq_registration_ex_t *reg = (lbm_context_event_umq_registration_ex_t *)ed;
printf("UMQ queue \"%s\"[%x][%s][%u] ctx registration. ID %" PRIx64 " Flags %x ", reg->queue, reg->queue_id, reg->queue_instance, reg->queue_instance_index,
reg->registration_id, reg->flags);
if (reg->flags & LBM_CONTEXT_EVENT_UMQ_REGISTRATION_COMPLETE_EX_FLAG_QUORUM)
printf("QUORUM ");
printf("\n");
}
break;
case LBM_CONTEXT_EVENT_UMQ_REGISTRATION_COMPLETE_EX:
{
lbm_context_event_umq_registration_complete_ex_t *reg = (lbm_context_event_umq_registration_complete_ex_t *)ed;
printf("UMQ queue \"%s\"[%x] ctx registration complete. ID %" PRIx64 " Flags %x ", reg->queue, reg->queue_id, reg->registration_id, reg->flags);
if (reg->flags & LBM_CONTEXT_EVENT_UMQ_REGISTRATION_COMPLETE_EX_FLAG_QUORUM)
printf("QUORUM ");
printf("\n");
}
break;
case LBM_CONTEXT_EVENT_UMQ_INSTANCE_LIST_NOTIFICATION:
{
const char *evstr = (const char *)ed;
printf("UMQ IL Notification: %s\n", evstr);
}
break;
default:
printf("Unknown context event %d\n", event);
break;
}
return 0;
}
/* Callback received message handler (passed into lbm_rcv_create()) */
int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd)
{
struct Options *opts = &options;
char indexstr[LBM_UMQ_MAX_INDEX_LEN + 1] = "";
char response_msg[DEFAULT_RESPONSE_LEN] = {'\0'};
switch (msg->type) {
case LBM_MSG_DATA:
/*
* Data message received.
* All we do is increment the counters.
* We want to display aggregate reception rates for all
* receivers.
*/
msg_count++;
total_msg_count++;
byte_count += msg->len;
if (opts->ascii) {
int n = msg->len;
const char *p = msg->data;
while (n--)
{
putchar(*p++);
}
if (opts->ascii > 1) putchar('\n');
}
if (opts->verbose) {
printf("[@%d.%06d]", (int)msg->tsp.tv_sec, (int)msg->tsp.tv_usec);
if(msg->channel_info != NULL) {
printf("[%s:%u][%s][%u]%s%s%s%s, %lu bytes\n",
msg->topic_name, msg->channel_info->channel_number,
msg->source, msg->sequence_number,
((msg->flags & LBM_MSG_FLAG_RETRANSMIT) ? "-RX-" : ""),
((msg->flags & LBM_MSG_FLAG_HF_DUPLICATE) ? "-HFDUP-" : ""),
((msg->flags & LBM_MSG_FLAG_HF_PASS_THROUGH) ? "-PASS-" : ""),
((msg->flags & LBM_MSG_FLAG_OTR) ? "-OTR-" : ""),
msg->len);
} else {
printf("[%s][%s][%u]%s%s%s%s, %lu bytes\n",
msg->topic_name, msg->source, msg->sequence_number,
((msg->flags & LBM_MSG_FLAG_RETRANSMIT) ? "-RX-" : ""),
((msg->flags & LBM_MSG_FLAG_HF_DUPLICATE) ? "-HFDUP-" : ""),
((msg->flags & LBM_MSG_FLAG_HF_PASS_THROUGH) ? "-PASS-" : ""),
((msg->flags & LBM_MSG_FLAG_OTR) ? "-OTR-" : ""),
msg->len);
}
if (opts->verbose > 1)
dump(msg->data, msg->len);
}
if (opts->measure_latency > 0)
{
struct timeval msgstarttv, msgendtv;
/* Update 1-way latency metrics */
current_tv(&msgendtv);
memcpy(&msgstarttv, msg->data, sizeof(msgstarttv));
update_oneway_latency_stats(&msgstarttv, &msgendtv);
}
if (opts->measure_latency > 1)
{
/* Return source pointer should be in the clientd */
lbm_src_t *rsrc = (lbm_src_t *) clientd;
/* Send timestamp back to publisher to calculate round trip time */
memcpy(rmessage, msg->data, msg->len);
if (lbm_src_send(rsrc, rmessage, msg->len, LBM_MSG_FLUSH | LBM_SRC_NONBLOCK) == LBM_FAILURE) {
fprintf(stderr, "lbm_src_send: %s. Not all return messages will make it back.\n", lbm_errmsg());
}
}
/* Global app level stats */
if(msg->flags & LBM_MSG_FLAG_RETRANSMIT)
rxs++;
else if(msg->flags & LBM_MSG_FLAG_OTR)
otrs++;
else
lstream++;
break;
case LBM_MSG_BOS:
printf("[%s][%s], Beginning of Transport Session\n", msg->topic_name, msg->source);
break;
case LBM_MSG_EOS:
printf("[%s][%s], End of Transport Session\n", msg->topic_name, msg->source);
if (opts->end_on_end)
close_recv = 1;
break;
case LBM_MSG_NO_SOURCE_NOTIFICATION:
if (opts->verbose)
printf("[%s], no sources found for topic\n", msg->topic_name);
break;
case LBM_MSG_UNRECOVERABLE_LOSS:
unrec_count++;
total_unrec_count++;
if (opts->verbose) {
printf("[%s][%s][%u], LOST\n",
msg->topic_name, msg->source, msg->sequence_number);
}
break;
case LBM_MSG_UNRECOVERABLE_LOSS_BURST:
burst_loss++;
total_burst_loss++;
if (opts->verbose) {
printf("[%s][%s][%u], LOST BURST\n",
msg->topic_name, msg->source, msg->sequence_number);
}
break;
case LBM_MSG_REQUEST:
/*
* Request message received.
* Just increment counters. We don't bother with responses here.
*/
msg_count++;
total_msg_count++;
byte_count += msg->len;
response = NULL;
if (opts->verbose) {
printf("[%s][%s][%u], Request\n",
msg->topic_name, msg->source, msg->sequence_number);
}
printf("[%s][%s][%u] [%s], Request\n",
msg->topic_name, msg->source, msg->sequence_number, msg->data);
lbm_msg_retain(msg);
if (strcmp (msg->data, "IS_RCV_READAY") == 0)
{
printf("Setting isReady = RCV_READAY\n");
isReady = RCV_READAY;
}
else if (strcmp (msg->data, "START_RCVS") == 0)
{
printf("Setting isReady = START_RCVS\n");
isReady = START_RCVS;
}
response = msg->response;
break;
case LBM_MSG_UME_REGISTRATION_ERROR:
printf("[%s][%s] UME registration error: %s\n", msg->topic_name, msg->source, msg->data);
break;
case LBM_MSG_UME_REGISTRATION_SUCCESS:
{
lbm_msg_ume_registration_t *reg = (lbm_msg_ume_registration_t *)(msg->data);
printf("[%s][%s] UME registration successful. SrcRegID %u RcvRegID %u\n",
msg->topic_name, msg->source, reg->src_registration_id, reg->rcv_registration_id);
}
break;
case LBM_MSG_UME_REGISTRATION_SUCCESS_EX:
{
lbm_msg_ume_registration_ex_t *reg = (lbm_msg_ume_registration_ex_t *)(msg->data);
printf("[%s][%s] store %u: %s UME registration successful. SrcRegID %u RcvRegID %u. Flags %x ",
msg->topic_name, msg->source, reg->store_index, reg->store,
reg->src_registration_id, reg->rcv_registration_id, reg->flags);
if (reg->flags & LBM_MSG_UME_REGISTRATION_SUCCESS_EX_FLAG_OLD)
printf("OLD[SQN %x] ", reg->sequence_number);
if (reg->flags & LBM_MSG_UME_REGISTRATION_SUCCESS_EX_FLAG_NOCACHE)
printf("NOCACHE ");
if (reg->flags & LBM_MSG_UME_REGISTRATION_SUCCESS_EX_FLAG_RPP)
printf("RPP ");
printf("\n");
}
break;
case LBM_MSG_UME_REGISTRATION_COMPLETE_EX:
{
lbm_msg_ume_registration_complete_ex_t *reg = (lbm_msg_ume_registration_complete_ex_t *)(msg->data);
printf("[%s][%s] UME registration complete. SQN %x. Flags %x ",
msg->topic_name, msg->source, reg->sequence_number, reg->flags);
if (reg->flags & LBM_MSG_UME_REGISTRATION_COMPLETE_EX_FLAG_QUORUM)
printf("QUORUM ");
if (reg->flags & LBM_MSG_UME_REGISTRATION_COMPLETE_EX_FLAG_RXREQMAX)
printf("RXREQMAX ");
printf("\n");
}
break;
case LBM_MSG_UME_DEREGISTRATION_SUCCESS_EX:
{
lbm_msg_ume_deregistration_ex_t *dereg = (lbm_msg_ume_deregistration_ex_t *)(msg->data);
printf("[%s][%s] store %u: %s UME deregistration successful. SrcRegID %u RcvRegID %u. Flags %x ",
msg->topic_name, msg->source, dereg->store_index, dereg->store,
dereg->src_registration_id, dereg->rcv_registration_id, dereg->flags);
if (dereg->flags & LBM_MSG_UME_REGISTRATION_SUCCESS_EX_FLAG_OLD)
printf("OLD[SQN %x] ", dereg->sequence_number);
if (dereg->flags & LBM_MSG_UME_REGISTRATION_SUCCESS_EX_FLAG_NOCACHE)
printf("NOCACHE ");
if (dereg->flags & LBM_MSG_UME_REGISTRATION_SUCCESS_EX_FLAG_RPP)
printf("RPP ");
printf("\n");
}
break;
case LBM_MSG_UME_DEREGISTRATION_COMPLETE_EX:
{
printf("[%s][%s] UME deregistration complete.\n", msg->topic_name, msg->source);
}
break;
case LBM_MSG_UME_REGISTRATION_CHANGE:
printf("[%s][%s] UME registration change: %s\n", msg->topic_name, msg->source, msg->data);
break;
case LBM_MSG_UMQ_REGISTRATION_COMPLETE_EX:
{
lbm_msg_umq_registration_complete_ex_t *reg = (lbm_msg_umq_registration_complete_ex_t *)(msg->data);
const char *type = "UMQ";
if (reg->flags & LBM_MSG_UMQ_REGISTRATION_COMPLETE_EX_FLAG_ULB)
type = "ULB";
printf("[%s][%s] %s \"%s\"[%x] registration complete. AssignID %x. Flags %x ", msg->topic_name, msg->source, type, reg->queue, reg->queue_id,
reg->assignment_id, reg->flags);
if (reg->flags & LBM_MSG_UMQ_REGISTRATION_COMPLETE_EX_FLAG_QUORUM)
printf("QUORUM ");
printf("\n");
if (opts->reserve_index) {
if (lbm_rcv_umq_index_reserve(rcv, NULL, opts->reserve_specific_index ? &(opts->index) : NULL) == LBM_FAILURE) {
fprintf(stderr, "lbm_rcv_umq_index_reserve: %s\n", lbm_errmsg());
exit(1);
}
}
}
break;
case LBM_MSG_UMQ_DEREGISTRATION_COMPLETE_EX:
{
lbm_msg_umq_deregistration_complete_ex_t *reg = (lbm_msg_umq_deregistration_complete_ex_t *)(msg->data);
const char *type = "UMQ";
if (reg->flags & LBM_MSG_UMQ_DEREGISTRATION_COMPLETE_EX_FLAG_ULB)
type = "ULB";
printf("[%s][%s] %s \"%s\"[%x] deregistration complete. Flags %x ", msg->topic_name, msg->source, type, reg->queue, reg->queue_id, reg->flags);
printf("\n");
close_recv = 1;
}
break;
case LBM_MSG_UMQ_INDEX_ASSIGNMENT_ELIGIBILITY_ERROR:
printf("[%s][%s] UMQ index assignment eligibility error: %s\n", msg->topic_name, msg->source, msg->data);
break;
case LBM_MSG_UMQ_INDEX_ASSIGNMENT_ERROR:
printf("[%s][%s] UMQ index assignment error: %s\n", msg->topic_name, msg->source, msg->data);
break;
case LBM_MSG_UMQ_INDEX_ASSIGNMENT_ELIGIBILITY_START_COMPLETE_EX:
{
lbm_msg_umq_index_assignment_eligibility_start_complete_ex_t *ias = (lbm_msg_umq_index_assignment_eligibility_start_complete_ex_t *)(msg->data);
const char *type = "UMQ";
if (ias->flags & LBM_MSG_UMQ_INDEX_ASSIGNMENT_ELIGIBILITY_START_COMPLETE_EX_FLAG_ULB)
type = "ULB";
printf("[%s][%s] %s \"%s\"[%x] index assignment eligibility start complete. Flags %x\n", msg->topic_name, msg->source, type, ias->queue, ias->queue_id, ias->flags);
}
break;
case LBM_MSG_UMQ_INDEX_ASSIGNMENT_ELIGIBILITY_STOP_COMPLETE_EX:
{
lbm_msg_umq_index_assignment_eligibility_stop_complete_ex_t *ias = (lbm_msg_umq_index_assignment_eligibility_stop_complete_ex_t *)(msg->data);
const char *type = "UMQ";
if (ias->flags & LBM_MSG_UMQ_INDEX_ASSIGNMENT_ELIGIBILITY_STOP_COMPLETE_EX_FLAG_ULB)
type = "ULB";
printf("[%s][%s] %s \"%s\"[%x] index assignment eligibility stop complete. Flags %x\n", msg->topic_name, msg->source, type, ias->queue, ias->queue_id, ias->flags);
}
break;
case LBM_MSG_UMQ_INDEX_ASSIGNED_EX:
{
lbm_msg_umq_index_assigned_ex_t *ia = (lbm_msg_umq_index_assigned_ex_t *)(msg->data);
const char *type = "UMQ";
if (ia->flags & LBM_MSG_UMQ_INDEX_ASSIGNED_EX_FLAG_ULB)
type = "ULB";
if (ia->index_info.flags & LBM_UMQ_INDEX_FLAG_NUMERIC)
snprintf(indexstr, sizeof(indexstr), "%" PRIu64, *(lbm_uint64_t *)(&(ia->index_info.index)));
else
snprintf(indexstr, sizeof(indexstr), "\"%s\"", ia->index_info.index);
printf("[%s][%s] %s \"%s\"[%x] beginning of index assignment for index %s. Flags %x\n", msg->topic_name, msg->source, type, ia->queue, ia->queue_id, indexstr, ia->flags);
}
break;
case LBM_MSG_UMQ_INDEX_RELEASED_EX:
{
lbm_msg_umq_index_released_ex_t *ir = (lbm_msg_umq_index_released_ex_t *)(msg->data);
const char *type = "UMQ";
if (ir->flags & LBM_MSG_UMQ_INDEX_RELEASED_EX_FLAG_ULB)
type = "ULB";
if (ir->index_info.flags & LBM_UMQ_INDEX_FLAG_NUMERIC)
snprintf(indexstr, sizeof(indexstr), "%" PRIu64, *(lbm_uint64_t *)(&(ir->index_info.index)));
else
snprintf(indexstr, sizeof(indexstr), "\"%s\"", ir->index_info.index);
printf("[%s][%s] %s \"%s\"[%x] end of index assignment for index %s. Flags %x\n", msg->topic_name, msg->source, type, ir->queue, ir->queue_id, indexstr, ir->flags);
}
break;
default:
printf("Unknown lbm_msg_t type %x [%s][%s]\n", msg->type, msg->topic_name, msg->source);
break;
}
/* LBM automatically deletes the lbm_msg_t object unless we retain it. */
return 0;
}
#if !defined(_WIN32)
static int LossRate = 0;
static
void
SigHupHandler(int signo)
{
if (LossRate >= 100)
{
return;
}
LossRate += 5;
if (LossRate > 100)
{
LossRate = 100;
}
lbm_set_lbtrm_loss_rate(LossRate);
lbm_set_lbtru_loss_rate(LossRate);
}
static
void
SigUsr1Handler(int signo)
{
if (LossRate >= 100)
{
return;
}
LossRate += 10;
if (LossRate > 100)
{
LossRate = 100;
}
lbm_set_lbtrm_loss_rate(LossRate);
lbm_set_lbtru_loss_rate(LossRate);
}
static
void
SigUsr2Handler(int signo)
{
LossRate = 0;
lbm_set_lbtrm_loss_rate(LossRate);
lbm_set_lbtru_loss_rate(LossRate);
}
void INThandler(int sig)
{
signal(sig, SIG_IGN);
printf("Process Interrupted!\n");
printf("Quitting.... received %u messages\n", total_msg_count);
close_recv = 1;
SLEEP_SEC(2);
exit(0);
}
#endif
void process_cmdline(int argc, char **argv) {
struct Options *opts = &options;
int c, errflag = 0, i;
/* Print header */
printf("*********************************************************************\n");
printf("*\n");
printf("* UMTools\n");
printf("* umsub - Version %s\n", UM_PUB_VERSION);
printf("* %s\n", lbm_version());
print_platform_info();
printf("*\n");
printf("* Parameters: ");
for (i = 0; i < argc; i++)
printf("%s ", argv[i]);
printf("\n*\n");
printf("*********************************************************************\n");
/* Set default values */
memset(opts, 0, sizeof(*opts));
opts->bufsize = 8;
opts->end_flg_file = NULL;
opts->format = lbmmon_format_csv_module();
opts->initial_topic_number = DEFAULT_INITIAL_TOPIC_NUMBER;
opts->linger = DEFAULT_LINGER_SECONDS;
opts->num_ctxs = DEFAULT_NUM_CTXS;
opts->num_rcvs = DEFAULT_NUM_RCVS;
strncpy(opts->topicroot, DEFAULT_TOPIC_ROOT, sizeof(opts->topicroot));
opts->transport = lbmmon_transport_lbm_module();
while ((c = getopt_long(argc, argv, OptionString, OptionTable, NULL)) != EOF)
{
switch (c)
{
case 'A':
opts->ascii++;
break;
case 'B':
opts->bufsize = atoi(optarg);
break;
case 'c':
/* Initialize configuration parameters from a file. */
if (lbm_config(optarg) == LBM_FAILURE) {
fprintf(stderr, "lbm_config: %s\n", lbm_errmsg());
exit(1);
}
break;
case 'C':
opts->num_ctxs = atoi(optarg);
if (opts->num_ctxs > MAX_NUM_CTXS)
{
fprintf(stderr, "Too many contexts specified. "
"Max number of contexts is %d\n", MAX_NUM_CTXS);
errflag++;
}
break;
case 'E':
opts->end_on_end = 1;
break;
case 'e':
opts->end_flg_file = optarg;
break;
case 'F':
opts->use_hf++;
break;
case 'i':
opts->initial_topic_number = atoi(optarg);
break;
case 'L':