static void Main(String[] args) { LBMContext ctx = null; /* Context object: container for UM "instance". */ LBMSource src = null; /* Source object: for sending messages. */ LBM lbm = new LBM(); /*** Initialization: create necessary UM objects. ***/ try { LBMTopic topic = null; LBMSourceAttributes srcAttr = null; lbm.setLogger(new LBMLogging(logger)); ctx = new LBMContext(); srcAttr = new LBMSourceAttributes(); srcAttr.setValue("late_join", "1"); topic = ctx.allocTopic("test.topic", srcAttr); src = ctx.createSource(topic, null, null, null); } catch (LBMException ex) { System.Console.Error.Write("Error initializing LBM objects: " + ex.Message); System.Environment.Exit(1); } /* Cleanup */ src.close(); ctx.close(); }
static void Main(String[] args) { LBMContext ctx = null; /* Context object: container for UM "instance". */ LBMSource src = null; /* Source object: for sending messages. */ LBM lbm = new LBM(); /*** Initialization: create necessary UM objects. ***/ try { LBMTopic topic = null; LBMSourceAttributes srcAttr = null; lbm.setLogger(new LBMLogging(logger)); ctx = new LBMContext(); srcAttr = new LBMSourceAttributes(); srcAttr.setValue("late_join", "1"); topic = ctx.allocTopic("test.topic", srcAttr); src = ctx.createSource(topic, null, null, null); } catch (LBMException ex) { System.Console.Error.Write("Error initializing LBM objects: " + ex.Message); System.Environment.Exit(1); } /* Cleanup */ src.close(); ctx.close(); } /* main */
static void Main(string[] args) { if (System.Environment.GetEnvironmentVariable("LBM_LICENSE_FILENAME") == null && System.Environment.GetEnvironmentVariable("LBM_LICENSE_INFO") == null) { SetEnvironmentVariable("LBM_LICENSE_FILENAME", "lbm_license.txt"); } LBM lbm = new LBM(); lbm.setLogger(new LBMLogging(logger)); LBMObjectRecycler objRec = new LBMObjectRecycler(); int send_rate = 0; // Used for lbmtrm | lbtru transports int retrans_rate = 0; // char protocol = '\0'; // int msglen = 25; int linger = 5; int delay = 1; ulong bytes_sent = 0; int pause = 0; int i; bool block = true; int hfbits = 32; int n = args.Length; bool monitor_context = false; int monitor_context_ivl = 0; bool monitor_source = false; int monitor_source_ivl = 0; string application_id = null; int mon_format = LBMMonitor.FORMAT_CSV; int mon_transport = LBMMonitor.TRANSPORT_LBM; string mon_format_options = null; string mon_transport_options = null; bool error = false; bool done = false; bool use_hf = false; ulong seq_counter = 0; long channel = -1; string tape_file = null; StreamReader tape_scanner = null; int tape_msgs_sent = 0; const string OPTION_MONITOR_CTX = "--monitor-ctx"; const string OPTION_MONITOR_SRC = "--monitor-src"; const string OPTION_MONITOR_TRANSPORT = "--monitor-transport"; const string OPTION_MONITOR_TRANSPORT_OPTS = "--monitor-transport-opts"; const string OPTION_MONITOR_FORMAT = "--monitor-format"; const string OPTION_MONITOR_FORMAT_OPTS = "--monitor-format-opts"; const string OPTION_MONITOR_APPID = "--monitor-appid"; for (i = 0; i < n; i++) { try { switch (args[i]) { case OPTION_MONITOR_APPID: if (++i >= n) { error = true; break; } application_id = args[i]; break; case OPTION_MONITOR_CTX: if (++i >= n) { error = true; break; } monitor_context = true; monitor_context_ivl = Convert.ToInt32(args[i]); break; case OPTION_MONITOR_SRC: if (++i >= n) { error = true; break; } monitor_source = true; monitor_source_ivl = Convert.ToInt32(args[i]); break; case OPTION_MONITOR_FORMAT: if (++i >= n) { error = true; break; } if (args[i].ToLower().CompareTo("csv") == 0) { mon_format = LBMMonitor.FORMAT_CSV; } else { error = true; break; } break; case OPTION_MONITOR_TRANSPORT: if (++i >= n) { error = true; break; } if (args[i].ToLower().CompareTo("lbm") == 0) { mon_transport = LBMMonitor.TRANSPORT_LBM; } else if (args[i].ToLower().CompareTo("udp") == 0) { mon_transport = LBMMonitor.TRANSPORT_UDP; } else if (args[i].ToLower().CompareTo("lbmsnmp") == 0) { mon_transport = LBMMonitor.TRANSPORT_LBMSNMP; } else { error = true; break; } break; case OPTION_MONITOR_TRANSPORT_OPTS: if (++i >= n) { error = true; break; } mon_transport_options += args[i]; break; case OPTION_MONITOR_FORMAT_OPTS: if (++i >= n) { error = true; break; } mon_format_options += args[i]; break; case "-c": if (++i >= n) { error = true; break; } try { LBM.setConfiguration(args[i]); } catch (LBMException Ex) { System.Console.Error.WriteLine("lbmsrc error: " + Ex.Message); error = true; } break; case "-d": if (++i >= n) { error = true; break; } delay = Convert.ToInt32(args[i]); break; case "-D": if (verifiable) { System.Console.Error.WriteLine("Unable to use SDM because verifiable messages are on. Turn off verifiable messages (-V)."); System.Environment.Exit(1); } sdm = true; break; case "-f": use_hf = true; break; case "-i": if (++i >= n) { error = true; break; } seq_counter = ulong.Parse(args[i]); break; case "-h": print_help_exit(0); break; case "-l": if (++i >= n) { error = true; break; } msglen = Convert.ToInt32(args[i]); break; case "-n": block = false; break; case "-L": if (++i >= n) { error = true; break; } linger = Convert.ToInt32(args[i]); break; case "-M": if (++i >= n) { error = true; break; } msgs = long.Parse(args[i]); break; case "-N": if (++i >= n) { error = true; break; } channel = Convert.ToInt64(args[i]); break; case "-P": if (++i >= n) { error = true; break; } pause = Convert.ToInt32(args[i]); break; case "-R": if (++i >= n) { error = true; break; } ParseRateVars parseRateVars = lbmExampleUtil.parseRate(args[i]); if (parseRateVars.error) { print_help_exit(1); } send_rate = parseRateVars.rate; retrans_rate = parseRateVars.retrans; protocol = parseRateVars.protocol; break; case "-s": if (++i >= n) { error = true; break; } stats_sec = Convert.ToInt32(args[i]); break; case "-t": if (++i >= n) { error = true; break; } tape_file = args[i]; if (!File.Exists(tape_file)) { System.Console.Error.WriteLine("{0} does not exist. Verify the file specified by (-t) exists.", tape_file); print_help_exit(1); } tape_scanner = new StreamReader(tape_file); break; case "-V": if (sdm) { System.Console.Error.WriteLine("Unable to use verifiable messages because sdm is on. Turn off sdm (-D)."); System.Environment.Exit(1); } verifiable = true; break; case "-x": if (++i >= n) { error = true; break; } hfbits = Convert.ToInt32(args[i]); if (hfbits != 32 && hfbits != 64) { Console.WriteLine("-x " + hfbits + " invalid, HF sequence numbers must be 32 or 64 bit"); print_help_exit(1); } break; default: if (args[i].StartsWith("-")) { error = true; } else { done = true; } break; } if (error || done) { break; } } catch (Exception e) { /* type conversion exception */ System.Console.Error.WriteLine("lbmsrc: error\n" + e.Message + "\n"); print_help_exit(1); } } if (error || i >= n) { /* An error occurred processing the command line - print help and exit */ print_help_exit(1); } if (tape_scanner != null && !use_hf) { print_help_exit(1); } byte [] message = new byte[msglen]; if (verifiable) { int min_msglen = VerifiableMessage.MINIMUM_VERIFIABLE_MSG_LEN; if (msglen < min_msglen) { System.Console.WriteLine("Specified message length " + msglen + " is too small for verifiable message."); System.Console.WriteLine("Setting message length to minimum (" + min_msglen + ")."); msglen = min_msglen; } } LBMSourceAttributes sattr = new LBMSourceAttributes(); sattr.setObjectRecycler(objRec, null); LBMContextAttributes cattr = new LBMContextAttributes(); cattr.setObjectRecycler(objRec, null); /* Check if protocol needs to be set to lbtrm | lbtru */ if (protocol == 'M') { try { sattr.setValue("transport", "LBTRM"); cattr.setValue("transport_lbtrm_data_rate_limit", send_rate.ToString()); cattr.setValue("transport_lbtrm_retransmit_rate_limit", retrans_rate.ToString()); } catch (LBMException ex) { System.Console.Error.WriteLine("Error setting LBTRM rate: " + ex.Message); System.Environment.Exit(1); } } if (protocol == 'U') { try { sattr.setValue("transport", "LBTRU"); cattr.setValue("transport_lbtru_data_rate_limit", send_rate.ToString()); cattr.setValue("transport_lbtru_retransmit_rate_limit", retrans_rate.ToString()); } catch (LBMException ex) { System.Console.Error.WriteLine("Error setting LBTRU rate: " + ex.Message); System.Environment.Exit(1); } } LBMContext ctx = new LBMContext(cattr); LBMTopic topic = ctx.allocTopic(args[i], sattr); LBMSource src; SrcCB srccb = new SrcCB(); if (use_hf) { src = ctx.createHotFailoverSource(topic, new LBMSourceEventCallback(srccb.onSourceEvent), null, null); } else { src = ctx.createSource(topic, new LBMSourceEventCallback(srccb.onSourceEvent), null, null); } LBMSourceChannelInfo channel_info = null; LBMSourceSendExInfo exInfo = null; if (channel != -1) { if (use_hf) { Console.WriteLine("Error creating channel: cannot send on channels with hot failover."); Environment.Exit(1); } channel_info = src.createChannel(channel); exInfo = new LBMSourceSendExInfo(LBM.SRC_SEND_EX_FLAG_CHANNEL, null, channel_info); } SrcStatsTimer stats; if (stats_sec > 0) { stats = new SrcStatsTimer(ctx, src, stats_sec * 1000, null, objRec); } LBMMonitorSource lbmmonsrc = null; if (monitor_context || monitor_source) { lbmmonsrc = new LBMMonitorSource(mon_format, mon_format_options, mon_transport, mon_transport_options); if (monitor_context) { lbmmonsrc.start(ctx, application_id, monitor_context_ivl); } else { lbmmonsrc.start(src, application_id, monitor_source_ivl); } } if (delay > 0) { System.Console.Out.WriteLine("Will start sending in {0} second{1}...\n", delay, ((delay > 1) ? "s" : "")); System.Threading.Thread.Sleep(delay * 1000); } System.Console.Out.WriteLine("Sending {0} messages of size {1} bytes to topic [{2}]\n", msgs, msglen, args[i]); System.Console.Out.Flush(); long start_time = System.DateTime.Now.Ticks; long msgcount = 0; if (verifiable) { message = VerifiableMessage.constructVerifiableMessage(msglen); } else if (sdm) // If using SDM messages, create the message now { CreateSDMessage(); } // hfexinfo holds hot failover sequence number at bit size LBMSourceSendExInfo hfexinfo = null; if (use_hf) { int hfflags = (hfbits == 64) ? LBM.SRC_SEND_EX_FLAG_HF_64 : LBM.SRC_SEND_EX_FLAG_HF_32; hfexinfo = new LBMSourceSendExInfo(hfflags, null); } for (msgcount = 0; msgcount < msgs;) { try { // If using SDM messages, Update the sequence number if (sdm) { byte [] m = UpdateSDMessage(seq_counter); if (m != null) { message = m; msglen = message.Length; } } bool sendReset = false; srccb.blocked = true; if (use_hf) { if (tape_scanner != null) { string tape_str, tape_line = null; tape_line = tape_scanner.ReadLine(); if (tape_line == null) { break; } // Make sure the hf optional send ex flag is off hfexinfo.setFlags(hfexinfo.flags() & ~LBM.SRC_SEND_EX_FLAG_HF_OPTIONAL); if (tape_line.EndsWith("o")) { tape_str = tape_line.Substring(0, tape_line.Length - 1); hfexinfo.setFlags(hfexinfo.flags() | LBM.SRC_SEND_EX_FLAG_HF_OPTIONAL); } else if (tape_line.EndsWith("r")) { tape_str = tape_line.Substring(0, tape_line.Length - 1); sendReset = true; } else { tape_str = tape_line; } if (hfbits == 64) { hfexinfo.setHfSequenceNumber64(ulong.Parse(tape_str)); } else { hfexinfo.setHfSequenceNumber32(uint.Parse(tape_str)); } } else if (hfbits == 64) { hfexinfo.setHfSequenceNumber64(seq_counter); } else { hfexinfo.setHfSequenceNumber32((uint)seq_counter); } if (sendReset) { ((LBMHotFailoverSource)src).sendReceiverReset(LBM.MSG_FLUSH, hfexinfo); } else { ((LBMHotFailoverSource)src).send(message, msglen, 0, block ? 0 : LBM.SRC_NONBLOCK, hfexinfo); } if (tape_scanner != null) { tape_msgs_sent++; } } else if (exInfo != null) { src.send(message, msglen, block ? 0 : LBM.SRC_NONBLOCK, exInfo); } else { src.send(message, msglen, block ? 0 : LBM.SRC_NONBLOCK); } srccb.blocked = false; if (tape_scanner == null) { seq_counter++; msgcount++; } } catch (LBMEWouldBlockException) { while (srccb.blocked) { System.Threading.Thread.Sleep(100); } continue; } bytes_sent += (ulong)msglen; if (pause > 0) { System.Threading.Thread.Sleep(pause); } } long end_time = System.DateTime.Now.Ticks; double secs = (end_time - start_time) / 10000000.0; System.Console.Out.WriteLine("Sent {0} messages of size {1} bytes in {2} seconds.\n", (tape_scanner == null) ? msgs : tape_msgs_sent, msglen, secs); print_bw(secs, (tape_scanner == null) ? msgs : tape_msgs_sent, bytes_sent); System.Console.Out.Flush(); if (linger > 0) { System.Console.Out.WriteLine("Lingering for {0} second{1}...\n", linger, ((linger > 1) ? "s" : "")); System.Threading.Thread.Sleep(linger * 1000); } stats = new SrcStatsTimer(ctx, src, 0, null, objRec); if (channel_info != null) { src.deleteChannel(channel_info); } objRec.close(); src.close(); if (tape_scanner != null) { tape_scanner.Close(); tape_scanner.Dispose(); } ctx.close(); }
static void Main(string[] args) { if (System.Environment.GetEnvironmentVariable("LBM_LICENSE_FILENAME") == null && System.Environment.GetEnvironmentVariable("LBM_LICENSE_INFO") == null) { SetEnvironmentVariable("LBM_LICENSE_FILENAME", "lbm_license.txt"); } LBM lbm = new LBM(); lbm.setLogger(new LBMLogging(logger)); LBMObjectRecycler objRec = new LBMObjectRecycler(); string qdelay = null; string qsize = null; int i; int n = args.Length; bool monitor_context = false; int monitor_context_ivl = 0; bool monitor_receiver = false; int monitor_receiver_ivl = 0; string application_id = null; int mon_format = LBMMonitor.FORMAT_CSV; int mon_transport = LBMMonitor.TRANSPORT_LBM; string mon_format_options = null; string mon_transport_options = null; bool error = false; bool done = false; List <String> interfaces = new List <String>(); const string OPTION_MONITOR_CTX = "--monitor-ctx"; const string OPTION_MONITOR_RCV = "--monitor-rcv"; const string OPTION_MONITOR_TRANSPORT = "--monitor-transport"; const string OPTION_MONITOR_TRANSPORT_OPTS = "--monitor-transport-opts"; const string OPTION_MONITOR_FORMAT = "--monitor-format"; const string OPTION_MONITOR_FORMAT_OPTS = "--monitor-format-opts"; const string OPTION_MONITOR_APPID = "--monitor-appid"; for (i = 0; i < n; i++) { try { switch (args[i]) { case OPTION_MONITOR_APPID: if (++i >= n) { error = true; break; } application_id = args[i]; break; case OPTION_MONITOR_CTX: if (++i >= n) { error = true; break; } monitor_context = true; monitor_context_ivl = Convert.ToInt32(args[i]); break; case OPTION_MONITOR_RCV: if (++i >= n) { error = true; break; } monitor_receiver = true; monitor_receiver_ivl = Convert.ToInt32(args[i]); break; case OPTION_MONITOR_FORMAT: if (++i >= n) { error = true; break; } if (args[i].ToLower().CompareTo("csv") == 0) { mon_format = LBMMonitor.FORMAT_CSV; } else { error = true; break; } break; case OPTION_MONITOR_TRANSPORT: if (++i >= n) { error = true; break; } if (args[i].ToLower().CompareTo("lbm") == 0) { mon_transport = LBMMonitor.TRANSPORT_LBM; } else if (args[i].ToLower().CompareTo("udp") == 0) { mon_transport = LBMMonitor.TRANSPORT_UDP; } else if (args[i].ToLower().CompareTo("lbmsnmp") == 0) { mon_transport = LBMMonitor.TRANSPORT_LBMSNMP; } else { error = true; break; } break; case OPTION_MONITOR_TRANSPORT_OPTS: if (++i >= n) { error = true; break; } mon_transport_options += args[i]; break; case OPTION_MONITOR_FORMAT_OPTS: if (++i >= n) { error = true; break; } mon_format_options += args[i]; break; case "-c": if (++i >= n) { error = true; break; } try { LBM.setConfiguration(args[i]); } catch (LBMException Ex) { System.Console.Error.WriteLine("lbmhfxrcv error: " + Ex.Message); error = true; } break; case "-d": if (++i >= n) { error = true; break; } qdelay = args[i]; eventq = true; break; case "-E": end_on_eos = true; break; case "-h": print_help_exit(0); break; case "-I": if (++i >= n) { error = true; break; } try { interfaces.Add(args[i]); } catch (Exception e) { System.Console.Error.WriteLine("lbmhfxrcv error: " + e.Message); error = true; } break; case "-q": eventq = true; break; case "-r": if (++i >= n) { error = true; break; } reap_msgs = Convert.ToInt32(args[i]); break; case "-S": end_on_eos = true; summary = true; break; case "-s": if (++i >= n) { error = true; break; } stat_secs = Convert.ToInt32(args[i]); break; case "-v": verbose = true; break; case "-V": verifiable = true; break; case "-z": if (++i >= n) { error = true; break; } qsize = args[i]; eventq = true; break; default: if (args[i].StartsWith("-")) { error = true; } else { done = true; } break; } if (error || done) { break; } } catch (Exception e) { /* type conversion exception */ System.Console.Error.WriteLine("lbmhfxrcv: error\n" + e.Message + "\n"); print_help_exit(1); } } if (error || i >= n) { /* An error occurred processing the command line - print help and exit */ print_help_exit(1); } LBMRcvReceiver rcv = new LBMRcvReceiver(verbose, end_on_eos, summary); LBMContextAttributes ctx_attr = new LBMContextAttributes(); ctx_attr.setObjectRecycler(objRec, null); if (eventq) { System.Console.Error.WriteLine("Using an event queue"); LBMEventQueueAttributes evqattr = null; if (qsize != null || qdelay != null) { evqattr = new LBMEventQueueAttributes(); if (qdelay != null) { evqattr.setValue("queue_delay_warning", qdelay); } if (qsize != null) { evqattr.setValue("queue_size_warning", qsize); } } evq = new LBMRcvEventQueue(evqattr); ctx_attr.setImmediateMessageCallback(new LBMImmediateMessageCallback(rcv.onReceive), evq); } else { System.Console.Error.WriteLine("No event queue"); ctx_attr.setImmediateMessageCallback(new LBMImmediateMessageCallback(rcv.onReceive)); } LBMHFXAttributes hfxattr = new LBMHFXAttributes(); hfxattr.setObjectRecycler(objRec, null); LBMHFX hfx = new LBMHFX(hfxattr, args[i], rcv.onReceive, evq); List <LBMContext> ctxs = new List <LBMContext>(); List <LBMHFXReceiver> hfxrcvs = new List <LBMHFXReceiver>(); if (interfaces.Count > 0) { foreach (String iface in interfaces) { LBMContext ctx; ctx_attr.setValue("resolver_multicast_interface", iface); ctxs.Add(new LBMContext(ctx_attr)); ctx = ctxs[ctxs.Count - 1]; if (ctx.getAttributeValue("request_tcp_bind_request_port") != "0") { string request_tcp_iface = ctx.getAttributeValue("request_tcp_interface"); // Check if a different interface was specified for request_tcp_interface if (!request_tcp_iface.Equals("0.0.0.0")) { System.Console.Out.WriteLine("Immediate messaging target: TCP:" + request_tcp_iface + ":" + ctx.getAttributeValue("request_tcp_port")); } else { System.Console.Out.WriteLine("Immediate messaging target: TCP:" + ctx.getAttributeValue("resolver_multicast_interface") + ":" + ctx.getAttributeValue("request_tcp_port")); } } else { System.Console.Out.WriteLine("Request port binding disabled, no immediate messaging target"); } LBMReceiverAttributes rattr = new LBMReceiverAttributes(); rattr.setValue("transport_lbtru_interface", iface); rattr.setValue("transport_tcp_interface", iface); rattr.setObjectRecycler(objRec, null); hfxrcvs.Add(hfx.createReceiver(ctx, rattr, iface)); } } else { LBMContext ctx; ctxs.Add(new LBMContext(ctx_attr)); ctx = ctxs[ctxs.Count - 1]; if (ctx.getAttributeValue("request_tcp_bind_request_port") != "0") { string request_tcp_iface = ctx.getAttributeValue("request_tcp_interface"); // Check if a different interface was specified for request_tcp_interface if (!request_tcp_iface.Equals("0.0.0.0")) { System.Console.Out.WriteLine("Immediate messaging target: TCP:" + request_tcp_iface + ":" + ctx.getAttributeValue("request_tcp_port")); } else { System.Console.Out.WriteLine("Immediate messaging target: TCP:" + ctx.getAttributeValue("resolver_multicast_interface") + ":" + ctx.getAttributeValue("request_tcp_port")); } } else { System.Console.Out.WriteLine("Request port binding disabled, no immediate messaging target"); } LBMReceiverAttributes rattr = new LBMReceiverAttributes(); rattr.setObjectRecycler(objRec, null); hfxrcvs.Add(hfx.createReceiver(ctx, rattr, null)); } LBMMonitorSource lbmmonsrc = null; if (monitor_context || monitor_receiver) { lbmmonsrc = new LBMMonitorSource(mon_format, mon_format_options, mon_transport, mon_transport_options); if (monitor_context) { foreach (LBMContext ctx in ctxs) { lbmmonsrc.start(ctx, application_id, monitor_context_ivl); } } else { foreach (LBMHFXReceiver lbmhfxrcv in hfxrcvs) { lbmmonsrc.start(lbmhfxrcv, application_id, monitor_receiver_ivl); } } } System.Console.Out.Flush(); long start_time; long end_time; long last_lost = 0, lost_tmp = 0, lost = 0; bool have_stats; LBMReceiverStatistics stats = null; long stat_time = System.DateTime.Now.AddSeconds(stat_secs).Ticks; for (; ;) { start_time = System.DateTime.Now.Ticks; if (eventq) { evq.run(1000); } else { System.Threading.Thread.Sleep(1000); } end_time = System.DateTime.Now.Ticks; lost = 0; foreach (LBMHFXReceiver lbmhfxrcv in hfxrcvs) { have_stats = false; while (!have_stats) { try { stats = lbmhfxrcv.getStatistics(nstats); have_stats = true; } catch (LBMException ex) { /* Double the number of stats passed to the API to be retrieved */ /* Do so until we retrieve stats successfully or hit the max limit */ nstats *= 2; if (nstats > DEFAULT_MAX_NUM_SRCS) { System.Console.Error.WriteLine("Error getting receiver statistics: " + ex.Message); System.Environment.Exit(1); } /* have_stats is still false */ } } /* If we get here, we have the stats */ for (i = 0; i < stats.size(); i++) { lost += stats.lost(i); } if (stat_secs > 0 && stat_time <= end_time) { stat_time = System.DateTime.Now.AddSeconds(stat_secs).Ticks; print_stats(stats, evq); } objRec.doneWithReceiverStatistics(stats); } /* Account for loss in previous iteration */ lost_tmp = lost; if (last_lost <= lost) { lost -= last_lost; } else { lost = 0; } last_lost = lost_tmp; print_bw((end_time - start_time) / 10000, rcv.msg_count, rcv.byte_count, rcv.unrec_count, lost, rcv.burst_loss, rcv.rx_msgs, rcv.otr_msgs); rcv.msg_count = 0; rcv.byte_count = 0; rcv.unrec_count = 0; rcv.burst_loss = 0; rcv.rx_msgs = 0; rcv.otr_msgs = 0; if (reap_msgs != 0 && rcv.total_msg_count >= reap_msgs) { break; } } System.Console.Error.WriteLine("Quitting.... received " + rcv.total_msg_count + " messages"); objRec.close(); LBMOperationCompleteCallback cb = new LBMOperationCompleteCallback(deletionComplete); System.Console.Error.WriteLine("Deleting Receivers."); foreach (LBMHFXReceiver lbmhfxrcv in hfxrcvs) { lbmhfxrcv.close(cb, "Receiver"); } System.Console.Error.WriteLine("Waiting for deletions to complete"); while (deletions_complete < hfxrcvs.Count) { if (eventq) { evq.run(1000); } else { System.Threading.Thread.Sleep(1000); } } System.Console.Error.WriteLine("Deleting Contexts"); foreach (LBMContext ctx in ctxs) { ctx.close(); } deletions_complete = 0; System.Console.Error.WriteLine("Deleting HFX."); hfx.close(cb, "HFX"); System.Console.Error.WriteLine("Waiting for HFX deletion to complete"); while (deletions_complete < 1) { if (eventq) { evq.run(1000); } else { System.Threading.Thread.Sleep(1000); } } if (eventq) { evq.close(); } }
static void Main(string[] args) { if (System.Environment.GetEnvironmentVariable("LBM_LICENSE_FILENAME") == null && System.Environment.GetEnvironmentVariable("LBM_LICENSE_INFO") == null) { SetEnvironmentVariable("LBM_LICENSE_FILENAME", "lbm_license.txt"); } LBM lbm = new LBM(); lbm.setLogger(new LBMLogging(logger)); int send_rate = 0; // Used for lbmtrm | lbtru transports int retrans_rate = 0; // char protocol = '\0'; // int linger = 5; int delay = 1; string target = null; string topic = null; int msglen = 25; long bytes_sent = 0; int pause = 0; int i; int n = args.Length; bool error = false; bool done = false; bool topic_less = false; for (i = 0; i < n; i++) { try { switch (args[i]) { case "-c": if (++i >= n) { error = true; break; } try { LBM.setConfiguration(args[i]); } catch (LBMException Ex) { System.Console.Error.WriteLine("lbmimsg error: " + Ex.Message); error = true; } break; case "-d": if (++i >= n) { error = true; break; } delay = Convert.ToInt32(args[i]); break; case "-h": print_help_exit(0); break; case "-l": if (++i >= n) { error = true; break; } msglen = Convert.ToInt32(args[i]); break; case "-L": if (++i >= n) { error = true; break; } linger = Convert.ToInt32(args[i]); break; case "-M": if (++i >= n) { error = true; break; } msgs = Convert.ToInt32(args[i]); break; case "-o": topic_less = true; break; case "-P": if (++i >= n) { error = true; break; } pause = Convert.ToInt32(args[i]); break; case "-R": if (++i >= n) { error = true; break; } ParseRateVars parseRateVars = lbmExampleUtil.parseRate(args[i]); if (parseRateVars.error) { print_help_exit(1); } send_rate = parseRateVars.rate; retrans_rate = parseRateVars.retrans; protocol = parseRateVars.protocol; break; case "-T": if (++i >= n) { error = true; break; } target = args[i]; break; default: if (args[i].StartsWith("-")) { error = true; } else { done = true; } break; } if (error || done) { break; } } catch (Exception e) { /* type conversion exception */ System.Console.Error.WriteLine("lbmimsg: error\n" + e.Message + "\n"); print_help_exit(1); } } if (error || (i >= n && !topic_less)) { /* An error occurred processing the command line - print help and exit */ print_help_exit(1); } if (n > i && topic_less) { /* User chose topic-less and yet specified a topic - print help and exit */ System.Console.Error.WriteLine("lbmimsg: error--selected topic-less option and still specified topic"); print_help_exit(1); } if (i < n) { topic = args[i]; } byte [] message = new byte[msglen]; LBMSourceAttributes sattr = new LBMSourceAttributes(); LBMContextAttributes cattr = new LBMContextAttributes(); /* Check if protocol needs to be set to lbtrm | lbtru */ if (protocol == 'M') { try { sattr.setValue("transport", "LBTRM"); cattr.setValue("transport_lbtrm_data_rate_limit", send_rate.ToString()); cattr.setValue("transport_lbtrm_retransmit_rate_limit", retrans_rate.ToString()); } catch (LBMException ex) { System.Console.Error.WriteLine("Error setting LBTRM rate: " + ex.Message); System.Environment.Exit(1); } } if (protocol == 'U') { try { sattr.setValue("transport", "LBTRU"); cattr.setValue("transport_lbtru_data_rate_limit", send_rate.ToString()); cattr.setValue("transport_lbtru_retransmit_rate_limit", retrans_rate.ToString()); } catch (LBMException ex) { System.Console.Error.WriteLine("Error setting LBTRU rate: " + ex.Message); System.Environment.Exit(1); } } LBMContext ctx = new LBMContext(cattr); if (delay > 0) { System.Console.Out.WriteLine("Will start sending in {0} second{1}...\n", delay, ((delay > 1) ? "s" : "")); System.Threading.Thread.Sleep(delay * 1000); } System.Console.Out.WriteLine("Sending {0}{1} immediate messages of size {2} bytes to target <{3}> topic <{4}>\n", msgs, (topic_less == true ? " topic-less" : ""), msglen, (target == null ? "" : target), (topic == null ? "" : topic)); System.Console.Out.Flush(); long start_time = System.DateTime.Now.Ticks; for (int count = 0; count < msgs; count++) { try { if (target == null) { ctx.send(topic, message, msglen, 0); } else { ctx.send(target, topic, message, msglen, 0); } } catch (LBMException ex) { if (target != null && ex.errorNumber() == LBM.EOP) { System.Console.Error.WriteLine("LBM send() error: no connection to target while sending unicast immediate message"); } else { System.Console.Error.WriteLine("LBM send() error: " + ex.Message); } } bytes_sent += msglen; if (pause > 0) { System.Threading.Thread.Sleep(pause); } } long end_time = System.DateTime.Now.Ticks; double secs = (end_time - start_time) / 10000000.0; System.Console.Out.WriteLine("Sent {0} messages of size {1} bytes in {2} seconds.\n", msgs, msglen, secs); print_bw(secs, msgs, bytes_sent); System.Console.Out.Flush(); if (linger > 0) { System.Console.Out.WriteLine("Lingering for {0} second{1}...\n", linger, ((linger > 1) ? "s" : "")); System.Threading.Thread.Sleep(linger * 1000); } }
static void Main(string[] args) { if (System.Environment.GetEnvironmentVariable("LBM_LICENSE_FILENAME") == null && System.Environment.GetEnvironmentVariable("LBM_LICENSE_INFO") == null) { SetEnvironmentVariable("LBM_LICENSE_FILENAME", "lbm_license.txt"); } LBM lbm = new LBM(); lbm.setLogger(new LBMLogging(logger)); LBMObjectRecycler objRec = new LBMObjectRecycler(); string num_srcs = null; int i; int n = args.Length; bool monitor_context = false; int monitor_context_ivl = 0; bool monitor_receiver = false; int monitor_receiver_ivl = 0; string application_id = null; int mon_format = LBMMonitor.FORMAT_CSV; int mon_transport = LBMMonitor.TRANSPORT_LBM; string mon_format_options = null; string mon_transport_options = null; bool error = false; bool done = false; LBMRoundRobinXSPMappingHandler rrHelper = null; const string OPTION_MONITOR_CTX = "--monitor-ctx"; const string OPTION_MONITOR_RCV = "--monitor-rcv"; const string OPTION_MONITOR_TRANSPORT = "--monitor-transport"; const string OPTION_MONITOR_TRANSPORT_OPTS = "--monitor-transport-opts"; const string OPTION_MONITOR_FORMAT = "--monitor-format"; const string OPTION_MONITOR_FORMAT_OPTS = "--monitor-format-opts"; const string OPTION_MONITOR_APPID = "--monitor-appid"; for (i = 0; i < n; i++) { try { switch (args[i]) { case OPTION_MONITOR_APPID: if (++i >= n) { error = true; break; } application_id = args[i]; break; case OPTION_MONITOR_CTX: if (++i >= n) { error = true; break; } monitor_context = true; monitor_context_ivl = Convert.ToInt32(args[i]); break; case OPTION_MONITOR_RCV: if (++i >= n) { error = true; break; } monitor_receiver = true; monitor_receiver_ivl = Convert.ToInt32(args[i]); break; case OPTION_MONITOR_FORMAT: if (++i >= n) { error = true; break; } if (args[i].ToLower().CompareTo("csv") == 0) { mon_format = LBMMonitor.FORMAT_CSV; } else { error = true; break; } break; case OPTION_MONITOR_TRANSPORT: if (++i >= n) { error = true; break; } if (args[i].ToLower().CompareTo("lbm") == 0) { mon_transport = LBMMonitor.TRANSPORT_LBM; } else if (args[i].ToLower().CompareTo("udp") == 0) { mon_transport = LBMMonitor.TRANSPORT_UDP; } else if (args[i].ToLower().CompareTo("lbmsnmp") == 0) { mon_transport = LBMMonitor.TRANSPORT_LBMSNMP; } else { error = true; break; } break; case OPTION_MONITOR_TRANSPORT_OPTS: if (++i >= n) { error = true; break; } mon_transport_options += args[i]; break; case OPTION_MONITOR_FORMAT_OPTS: if (++i >= n) { error = true; break; } mon_format_options += args[i]; break; case "-c": if (++i >= n) { error = true; break; } try { LBM.setConfiguration(args[i]); } catch (LBMException Ex) { System.Console.Error.WriteLine("lbmrcvxsp error: " + Ex.Message); error = true; } break; case "-d": defer_xsp_deletion = true; break; case "-D": use_default_xsp = true; break; case "-E": end_on_eos = true; break; case "-h": print_help_exit(0); break; case "-P": rr_preallocate = true; break; case "-Q": sequential_xsps = true; break; case "-r": if (++i >= n) { error = true; break; } reap_msgs = Convert.ToInt32(args[i]); break; case "-R": if (++i >= n) { error = true; break; } round_robin = Convert.ToInt32(args[i]); break; case "-S": end_on_eos = true; summary = true; break; case "-s": if (++i >= n) { error = true; break; } stat_secs = Convert.ToInt32(args[i]); break; case "-v": verbose = true; break; case "-V": verifiable = true; break; default: if (args[i].StartsWith("-")) { error = true; } else { done = true; } break; } if (error || done) { break; } } catch (Exception e) { /* type conversion exception */ System.Console.Error.WriteLine("lbmrcvxsp: error\n" + e.Message + "\n"); print_help_exit(1); } } if (error || i >= n) { /* An error occurred processing the command line - print help and exit */ print_help_exit(1); } LBMRcvReceiver rcv = new LBMRcvReceiver(verbose, end_on_eos, summary, objRec); LBMContextAttributes ctx_attr = new LBMContextAttributes(); ctx_attr.setImmediateMessageCallback(new LBMImmediateMessageCallback(rcv.onReceive)); ctx_attr.setObjectRecycler(objRec, null); if (use_default_xsp) { ctx_attr.setTransportMappingCallback(new LBMTransportMappingCallback(onTransportMapping), null); } else { if (round_robin <= 0) { System.Console.Out.WriteLine("!! round_robin must be >= 1 - setting to 1"); round_robin = 1; } System.Console.Out.WriteLine("\nUsing a round-robin strategy with " + round_robin + " XSPs. Preallocation is " + (rr_preallocate ? "ON" : "OFF") + "\n"); rrHelper = new LBMRoundRobinXSPMappingHandler(); ctx_attr.setTransportMappingCallback(new LBMTransportMappingCallback(rrHelper.onTransportMapping), null); } LBMContext ctx = new LBMContext(ctx_attr); if (ctx.getAttributeValue("request_tcp_bind_request_port") != "0") { string request_tcp_iface = ctx.getAttributeValue("request_tcp_interface"); // Check if a different interface was specified for request_tcp_interface if (!request_tcp_iface.Equals("0.0.0.0")) { System.Console.Out.WriteLine("Immediate messaging target: TCP:" + request_tcp_iface + ":" + ctx.getAttributeValue("request_tcp_port")); } else { System.Console.Out.WriteLine("Immediate messaging target: TCP:" + ctx.getAttributeValue("resolver_multicast_interface") + ":" + ctx.getAttributeValue("request_tcp_port")); } } else { System.Console.Out.WriteLine("Request port binding disabled, no immediate messaging target"); } if ((rrHelper != null) && (rr_preallocate)) { rrHelper.preallocateXSPs(ctx); } LBMReceiverAttributes rattr = new LBMReceiverAttributes(); if (num_srcs != null) { rattr.setValue("resolution_number_of_sources_query_threshold", num_srcs); } rattr.setObjectRecycler(objRec, null); LBMTopic topic = ctx.lookupTopic(args[i], rattr); LBMReceiver lbmrcv; lbmrcv = new LBMReceiver(ctx, topic, rcv.onReceive, null); System.Console.Out.Flush(); LBMMonitorSource lbmmonsrc = null; if (monitor_context || monitor_receiver) { lbmmonsrc = new LBMMonitorSource(mon_format, mon_format_options, mon_transport, mon_transport_options); if (monitor_context) { lbmmonsrc.start(ctx, application_id, monitor_context_ivl); } else { lbmmonsrc.start(lbmrcv, application_id, monitor_receiver_ivl); } } long start_time; long end_time; long last_lost = 0, lost_tmp = 0, lost = 0; bool have_stats = false; LBMReceiverStatistics stats = null; long stat_time = System.DateTime.Now.AddSeconds(stat_secs).Ticks; for (; ;) { start_time = System.DateTime.Now.Ticks; System.Threading.Thread.Sleep(1000); have_stats = false; while (!have_stats) { try { stats = lbmrcv.getStatistics(nstats); have_stats = true; } catch (LBMException ex) { /* Double the number of stats passed to the API to be retrieved */ /* Do so until we retrieve stats successfully or hit the max limit */ nstats *= 2; if (nstats > DEFAULT_MAX_NUM_SRCS) { System.Console.Error.WriteLine("Error getting receiver statistics: " + ex.Message); System.Environment.Exit(1); } /* have_stats is still false */ } } /* If we get here, we have the stats */ lost = 0; for (i = 0; i < stats.size(); i++) { lost += stats.lost(i); } /* Account for loss in previous iteration */ lost_tmp = lost; if (last_lost <= lost) { lost -= last_lost; } else { lost = 0; } last_lost = lost_tmp; end_time = System.DateTime.Now.Ticks; print_bw((end_time - start_time) / 10000, rcv.msg_count, rcv.byte_count, rcv.unrec_count, lost, rcv.burst_loss, rcv.rx_msgs, rcv.otr_msgs); if (stat_secs > 0 && stat_time <= end_time) { stat_time = System.DateTime.Now.AddSeconds(stat_secs).Ticks; print_stats(stats); } // recycle stats object when finished so it can be reused by LBM objRec.doneWithReceiverStatistics(stats); rcv.msg_count = 0; rcv.byte_count = 0; rcv.unrec_count = 0; rcv.burst_loss = 0; rcv.rx_msgs = 0; rcv.otr_msgs = 0; if (reap_msgs != 0 && rcv.total_msg_count >= reap_msgs) { break; } } System.Console.Error.WriteLine("Quitting.... received " + rcv.total_msg_count + " messages"); objRec.close(); lbmrcv.close(); ctx.close(); }
static void Main(string[] args) { if (System.Environment.GetEnvironmentVariable("LBM_LICENSE_FILENAME") == null && System.Environment.GetEnvironmentVariable("LBM_LICENSE_INFO") == null) { SetEnvironmentVariable("LBM_LICENSE_FILENAME", "lbm_license.txt"); } LBM lbm = new LBM(); lbm.setLogger(new LBMLogging(logger)); int response_len = 25; int responses = 1; int i; int n = args.Length; bool error = false; bool done = false; LBMObjectRecycler objRec = new LBMObjectRecycler(); //Lower the defaults for messages since we expect a lower rate that request will be arriving objRec.setLocalMsgPoolSize(10); objRec.setSharedMsgPoolSize(20); for (i = 0; i < n; i++) { try { switch (args[i]) { case "-c": if (++i >= n) { error = true; break; } try { LBM.setConfiguration(args[i]); } catch (LBMException Ex) { System.Console.Error.WriteLine("lbmresp error: " + Ex.Message); error = true; } break; case "-E": end_on_eos = true; break; case "-h": print_help_exit(0); break; case "-l": if (++i >= n) { error = true; break; } response_len = Convert.ToInt32(args[i]); break; case "-q": eventq = true; break; case "-r": if (++i >= n) { error = true; break; } responses = Convert.ToInt32(args[i]); if (responses <= 0) { /*Negative # of responses not allowed*/ print_help_exit(1); } break; case "-v": verbose++; break; default: if (args[i].StartsWith("-")) { error = true; } else { done = true; } break; } if (error || done) { break; } } catch (Exception e) { /* type conversion exception */ System.Console.Error.WriteLine("lbmresp: error\n" + e.Message + "\n"); print_help_exit(1); } } if (error || i >= n) { /* An error occurred processing the command line - print help and exit */ print_help_exit(1); } byte[] response_buffer = new byte[response_len]; LBMContextAttributes cattr = new LBMContextAttributes(); cattr.setObjectRecycler(objRec, null); LBMContext ctx = new LBMContext(cattr); LBMRespEventQueue evq = null; //LBMTopic topic = ctx.lookupTopic(args[i]); LBMReceiverAttributes rattr = new LBMReceiverAttributes(); rattr.setObjectRecycler(objRec, null); LBMTopic topic = new LBMTopic(ctx, args[i], rattr); LBMRespReceiver rcv; if (eventq) { System.Console.Error.WriteLine("Event queue in use"); evq = new LBMRespEventQueue(); rcv = new LBMRespReceiver(ctx, topic, evq, verbose, end_on_eos); ctx.enableImmediateMessageReceiver(evq); } else { System.Console.Error.WriteLine("No event queue"); rcv = new LBMRespReceiver(ctx, topic, verbose, end_on_eos); ctx.enableImmediateMessageReceiver(); } ctx.addImmediateMessageReceiver(new LBMImmediateMessageCallback(rcv.onReceiveImmediate)); try { ASCIIEncoding enc = new ASCIIEncoding(); while (true) { if (!eventq) { System.Threading.Thread.Sleep(100); } else { evq.run(100); } if (rcv.request != null) { System.Console.Out.WriteLine("Sending response. " + "{0} response{1} of {2} bytes{3} ({4} total bytes).\n", responses, (responses == 1 ? "" : "s"), response_len, (responses == 1 ? "" : " each"), responses * response_len); System.Console.Out.Flush(); for (i = 0; i < responses; i++) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("response {0}", i); enc.GetBytes(sb.ToString(), 0, sb.ToString().Length, response_buffer, 0); rcv.request.respond(response_buffer, response_len, 0); } rcv.request.dispose(); objRec.doneWithMessage(rcv.request); rcv.request = null; } } } catch (Exception e) { Console.WriteLine("An error occurred: {0}", e.Message); } }
static void Main(string[] args) { LBM lbm = new LBM(); lbm.setLogger(new LBMLogging(logger)); int i; int n = args.Length; bool error = false; bool done = false; for (i = 0; i < n; i++) { try { switch (args[i]) { case "-a": flags |= LBM.TOPIC_RES_REQUEST_ADVERTISEMENT; break; case "-c": if (++i >= n) { error = true; break; } try { LBM.setConfiguration(args[i]); } catch (LBMException Ex) { System.Console.Error.WriteLine("lbmtrreq error: {0}", Ex.Message); error = true; } break; case "-d": if (++i >= n) { error = true; break; } duration = UInt32.Parse(args[i]); break; case "-h": print_help_exit(0); break; case "-i": if (++i >= n) { error = true; break; } interval = UInt32.Parse(args[i]); break; case "-L": if (++i >= n) { error = true; break; } linger = Int32.Parse(args[i]); break; case "-q": flags |= LBM.TOPIC_RES_REQUEST_QUERY; break; case "-w": flags |= LBM.TOPIC_RES_REQUEST_WILDCARD_QUERY; break; default: error = true; break; } if (error) { break; } } catch (Exception e) { /* type conversion exception */ System.Console.Error.WriteLine("lbmtrreq: error\n{0}\n", e.Message); print_help_exit(1); } } if (error) { /* An error occurred processing the command line - print help and exit */ print_help_exit(1); } LBMContext ctx = new LBMContext(); ctx.requestTopicResolution(flags, interval, duration); if (linger > 0) { System.Console.WriteLine("Lingering for {0} seconds.", linger); Thread.Sleep(1000 * linger); } ctx.close(); }
static void Main(string[] args) { if (System.Environment.GetEnvironmentVariable("LBM_LICENSE_FILENAME") == null && System.Environment.GetEnvironmentVariable("LBM_LICENSE_INFO") == null) { SetEnvironmentVariable("LBM_LICENSE_FILENAME", "lbm_license.txt"); } LBM lbm = new LBM(); lbm.setLogger(new LBMLogging(logger)); LBMObjectRecycler objRec = new LBMObjectRecycler(); string qdelay = null; string qsize = null; string num_srcs = null; int i; int n = args.Length; bool monitor_context = false; int monitor_context_ivl = 0; bool monitor_receiver = false; int monitor_receiver_ivl = 0; string application_id = null; int mon_format = LBMMonitor.FORMAT_CSV; int mon_transport = LBMMonitor.TRANSPORT_LBM; string mon_format_options = null; string mon_transport_options = null; bool error = false; bool done = false; bool use_hf = false; List <uint> channels = new List <uint>(); const string OPTION_MONITOR_CTX = "--monitor-ctx"; const string OPTION_MONITOR_RCV = "--monitor-rcv"; const string OPTION_MONITOR_TRANSPORT = "--monitor-transport"; const string OPTION_MONITOR_TRANSPORT_OPTS = "--monitor-transport-opts"; const string OPTION_MONITOR_FORMAT = "--monitor-format"; const string OPTION_MONITOR_FORMAT_OPTS = "--monitor-format-opts"; const string OPTION_MONITOR_APPID = "--monitor-appid"; for (i = 0; i < n; i++) { try { switch (args[i]) { case OPTION_MONITOR_APPID: if (++i >= n) { error = true; break; } application_id = args[i]; break; case OPTION_MONITOR_CTX: if (++i >= n) { error = true; break; } monitor_context = true; monitor_context_ivl = Convert.ToInt32(args[i]); break; case OPTION_MONITOR_RCV: if (++i >= n) { error = true; break; } monitor_receiver = true; monitor_receiver_ivl = Convert.ToInt32(args[i]); break; case OPTION_MONITOR_FORMAT: if (++i >= n) { error = true; break; } if (args[i].ToLower().CompareTo("csv") == 0) { mon_format = LBMMonitor.FORMAT_CSV; } else { error = true; break; } break; case OPTION_MONITOR_TRANSPORT: if (++i >= n) { error = true; break; } if (args[i].ToLower().CompareTo("lbm") == 0) { mon_transport = LBMMonitor.TRANSPORT_LBM; } else if (args[i].ToLower().CompareTo("udp") == 0) { mon_transport = LBMMonitor.TRANSPORT_UDP; } else if (args[i].ToLower().CompareTo("lbmsnmp") == 0) { mon_transport = LBMMonitor.TRANSPORT_LBMSNMP; } else { error = true; break; } break; case OPTION_MONITOR_TRANSPORT_OPTS: if (++i >= n) { error = true; break; } mon_transport_options += args[i]; break; case OPTION_MONITOR_FORMAT_OPTS: if (++i >= n) { error = true; break; } mon_format_options += args[i]; break; case "-c": if (++i >= n) { error = true; break; } try { LBM.setConfiguration(args[i]); } catch (LBMException Ex) { System.Console.Error.WriteLine("lbmrcv error: " + Ex.Message); error = true; } break; case "-d": if (++i >= n) { error = true; break; } qdelay = args[i]; eventq = true; break; case "-D": if (verifiable) { System.Console.Error.WriteLine("Unable to use SDM because verifiable messages are on. Turn off verifiable messages (-V)."); System.Environment.Exit(1); } sdm = true; break; case "-f": use_hf = true; break; case "-E": end_on_eos = true; break; case "-h": print_help_exit(0); break; case "-n": if (++i >= n) { error = true; break; } num_srcs = args[i]; break; case "-q": eventq = true; break; case "-r": if (++i >= n) { error = true; break; } reap_msgs = Convert.ToInt32(args[i]); break; case "-N": if (++i >= n) { error = true; break; } try { channels.Add(Convert.ToUInt32(args[i])); } catch (Exception e) { Console.Error.WriteLine(e.Message); error = true; } break; case "-S": end_on_eos = true; summary = true; break; case "-s": if (++i >= n) { error = true; break; } stat_secs = Convert.ToInt32(args[i]); break; case "-v": verbose = true; break; case "-V": if (sdm) { System.Console.Error.WriteLine("Unable to use verifiable messages because sdm is on. Turn off sdm (-D)."); System.Environment.Exit(1); } verifiable = true; break; case "-z": if (++i >= n) { error = true; break; } qsize = args[i]; eventq = true; break; default: if (args[i].StartsWith("-")) { error = true; } else { done = true; } break; } if (error || done) { break; } } catch (Exception e) { /* type conversion exception */ System.Console.Error.WriteLine("lbmrcv: error\n" + e.Message + "\n"); print_help_exit(1); } } if (error || i >= n) { /* An error occurred processing the command line - print help and exit */ print_help_exit(1); } LBMRcvReceiver rcv = new LBMRcvReceiver(verbose, end_on_eos, summary, objRec); LBMContextAttributes ctx_attr = new LBMContextAttributes(); LBMRcvEventQueue evq = null; if (eventq) { System.Console.Error.WriteLine("Event queue in use"); LBMEventQueueAttributes evqattr = null; if (qsize != null || qdelay != null) { evqattr = new LBMEventQueueAttributes(); if (qdelay != null) { evqattr.setValue("queue_delay_warning", qdelay); } if (qsize != null) { evqattr.setValue("queue_size_warning", qsize); } } evq = new LBMRcvEventQueue(evqattr); ctx_attr.setImmediateMessageCallback(new LBMImmediateMessageCallback(rcv.onReceive), evq); } else { ctx_attr.setImmediateMessageCallback(new LBMImmediateMessageCallback(rcv.onReceive)); } ctx_attr.setObjectRecycler(objRec, null); LBMContext ctx = new LBMContext(ctx_attr); if (ctx.getAttributeValue("request_tcp_bind_request_port") != "0") { string request_tcp_iface = ctx.getAttributeValue("request_tcp_interface"); // Check if a different interface was specified for request_tcp_interface if (!request_tcp_iface.Equals("0.0.0.0")) { System.Console.Out.WriteLine("Immediate messaging target: TCP:" + request_tcp_iface + ":" + ctx.getAttributeValue("request_tcp_port")); } else { System.Console.Out.WriteLine("Immediate messaging target: TCP:" + ctx.getAttributeValue("resolver_multicast_interface") + ":" + ctx.getAttributeValue("request_tcp_port")); } } else { System.Console.Out.WriteLine("Request port binding disabled, no immediate messaging target"); } LBMReceiverAttributes rattr = new LBMReceiverAttributes(); if (num_srcs != null) { rattr.setValue("resolution_number_of_sources_query_threshold", num_srcs); } rattr.setObjectRecycler(objRec, null); LBMTopic topic = ctx.lookupTopic(args[i], rattr); LBMReceiver lbmrcv; if (use_hf) { System.Console.Error.Write("Hot-Failover, "); } if (eventq) { if (use_hf) { lbmrcv = new LBMHotFailoverReceiver(ctx, topic, rcv.onReceive, null, evq); } else { lbmrcv = new LBMReceiver(ctx, topic, rcv.onReceive, null, evq); } } else { System.Console.Error.WriteLine("No event queue"); if (use_hf) { lbmrcv = new LBMHotFailoverReceiver(ctx, topic, rcv.onReceive, null); } else { lbmrcv = new LBMReceiver(ctx, topic, rcv.onReceive, null); } } System.Console.Out.Flush(); if (channels.Count > 0) { System.Console.Error.Write("Subscribing to channels: "); foreach (uint channel in channels) { try { lbmrcv.subscribeChannel(channel, rcv.onReceive, null); System.Console.Error.Write("{0} ", channel); } catch (Exception e) { System.Console.Error.WriteLine(); System.Console.Error.WriteLine(e.Message); } } System.Console.Error.WriteLine(); } LBMMonitorSource lbmmonsrc = null; if (monitor_context || monitor_receiver) { lbmmonsrc = new LBMMonitorSource(mon_format, mon_format_options, mon_transport, mon_transport_options); if (monitor_context) { lbmmonsrc.start(ctx, application_id, monitor_context_ivl); } else { lbmmonsrc.start(lbmrcv, application_id, monitor_receiver_ivl); } } long start_time; long end_time; long last_lost = 0, lost_tmp = 0, lost = 0; bool have_stats = false; LBMReceiverStatistics stats = null; long stat_time = System.DateTime.Now.AddSeconds(stat_secs).Ticks; for (; ;) { start_time = System.DateTime.Now.Ticks; if (eventq) { evq.run(1000); } else { System.Threading.Thread.Sleep(1000); } have_stats = false; while (!have_stats) { try { stats = lbmrcv.getStatistics(nstats); have_stats = true; } catch (LBMException ex) { /* Double the number of stats passed to the API to be retrieved */ /* Do so until we retrieve stats successfully or hit the max limit */ nstats *= 2; if (nstats > DEFAULT_MAX_NUM_SRCS) { System.Console.Error.WriteLine("Error getting receiver statistics: " + ex.Message); System.Environment.Exit(1); } /* have_stats is still false */ } } /* If we get here, we have the stats */ lost = 0; for (i = 0; i < stats.size(); i++) { lost += stats.lost(i); } /* Account for loss in previous iteration */ lost_tmp = lost; if (last_lost <= lost) { lost -= last_lost; } else { lost = 0; } last_lost = lost_tmp; end_time = System.DateTime.Now.Ticks; print_bw((end_time - start_time) / 10000, rcv.msg_count, rcv.byte_count, rcv.unrec_count, lost, rcv.burst_loss, rcv.rx_msgs, rcv.otr_msgs); if (stat_secs > 0 && stat_time <= end_time) { stat_time = System.DateTime.Now.AddSeconds(stat_secs).Ticks; print_stats(stats, evq); } // recycle stats object when finished so it can be reused by LBM objRec.doneWithReceiverStatistics(stats); rcv.msg_count = 0; rcv.byte_count = 0; rcv.unrec_count = 0; rcv.burst_loss = 0; rcv.rx_msgs = 0; rcv.otr_msgs = 0; if (reap_msgs != 0 && rcv.total_msg_count >= reap_msgs) { break; } } System.Console.Error.WriteLine("Quitting.... received " + rcv.total_msg_count + " messages"); if (channels.Count > 0) { /* Unsubscribe from channels */ foreach (uint channel in channels) { lbmrcv.unsubscribeChannel(channel); } } objRec.close(); lbmrcv.close(); ctx.close(); if (eventq) { evq.close(); } }
public static void Main(string[] args) { LBM lbm = new LBM(); lbm.setLogger(new LBMLogging(logger)); LBMObjectRecyclerBase objRec = new LBMObjectRecycler(); int transport = LBMMonitor.TRANSPORT_LBM; int format = LBMMonitor.FORMAT_CSV; string transport_options = ""; string format_options = ""; const string OPTION_MONITOR_TRANSPORT = "--transport"; const string OPTION_MONITOR_TRANSPORT_OPTS = "--transport-opts"; const string OPTION_MONITOR_FORMAT = "--format"; const string OPTION_MONITOR_FORMAT_OPTS = "--format-opts"; int n = args.Length; int i; bool error = false; for (i = 0; i < n; i++) { switch (args[i]) { case "-h": print_help_exit(0); break; case "-f": case OPTION_MONITOR_FORMAT: if (++i >= n) { error = true; break; } if (args[i].ToLower().CompareTo("csv") == 0) { format = LBMMonitor.FORMAT_CSV; } else { error = true; break; } break; case "-t": case OPTION_MONITOR_TRANSPORT: if (++i >= n) { error = true; break; } if (args[i].ToLower().CompareTo("lbm") == 0) { transport = LBMMonitor.TRANSPORT_LBM; } else if (args[i].ToLower().CompareTo("udp") == 0) { transport = LBMMonitor.TRANSPORT_UDP; } else if (args[i].ToLower().CompareTo("lbmsnmp") == 0) { transport = LBMMonitor.TRANSPORT_LBMSNMP; } else { error = true; break; } break; case OPTION_MONITOR_TRANSPORT_OPTS: if (++i >= n) { error = true; break; } transport_options += args[i]; break; case OPTION_MONITOR_FORMAT_OPTS: if (++i >= n) { error = true; break; } format_options += args[i]; break; default: error = true; break; } if (error) { break; } } if (error) { /* An error occurred processing the command line - print help and exit */ print_help_exit(1); } LBMMonitorReceiver lbmmonrcv = new LBMMonitorReceiver(format, format_options, transport, transport_options, objRec, null); //If not using object recycling //LBMMonitorReceiver lbmmonrcv = new LBMMonitorReceiver(format, format_options, transport, transport_options); LBMMonCallbacks lbmmoncbs = new LBMMonCallbacks(lbmmonrcv, objRec); LBMMonitorSourceStatisticsCallback scb; scb = new LBMMonitorSourceStatisticsCallback(lbmmoncbs.onReceive); LBMMonitorReceiverStatisticsCallback rcb; rcb = new LBMMonitorReceiverStatisticsCallback(lbmmoncbs.onReceive); LBMMonitorEventQueueStatisticsCallback evqcb; evqcb = new LBMMonitorEventQueueStatisticsCallback(lbmmoncbs.onReceive); LBMMonitorContextStatisticsCallback ctxcb; ctxcb = new LBMMonitorContextStatisticsCallback(lbmmoncbs.onReceive); LBMMonitorImmediateMessageReceiverStatisticsCallback imrcvcb; imrcvcb = new LBMMonitorImmediateMessageReceiverStatisticsCallback(lbmmoncbs.onReceive); LBMMonitorImmediateMessageSourceStatisticsCallback imsrccb; imsrccb = new LBMMonitorImmediateMessageSourceStatisticsCallback(lbmmoncbs.onReceive); lbmmonrcv.addStatisticsCallback(scb, rcb, evqcb, ctxcb); lbmmonrcv.addStatisticsCallback(imsrccb); lbmmonrcv.addStatisticsCallback(imrcvcb); for (; ;) { System.Threading.Thread.Sleep(2000); } }
static void Main(string[] args) { if (System.Environment.GetEnvironmentVariable("LBM_LICENSE_FILENAME") == null && System.Environment.GetEnvironmentVariable("LBM_LICENSE_INFO") == null) { SetEnvironmentVariable("LBM_LICENSE_FILENAME", "lbm_license.txt"); } LBM lbm = new LBM(); lbm.setLogger(new LBMLogging(logger)); int i; int n = args.Length; bool error = false; bool done = false; List <uint> channels = new List <uint>(); bool monitor_context = false; int monitor_context_ivl = 0; long dereg = 0; string application_id = null; int mon_format = LBMMonitor.FORMAT_CSV; int mon_transport = LBMMonitor.TRANSPORT_LBM; string mon_format_options = null; string mon_transport_options = null; const string OPTION_MONITOR_CTX = "--monitor-ctx"; const string OPTION_MONITOR_TRANSPORT = "--monitor-transport"; const string OPTION_MONITOR_TRANSPORT_OPTS = "--monitor-transport-opts"; const string OPTION_MONITOR_FORMAT = "--monitor-format"; const string OPTION_MONITOR_FORMAT_OPTS = "--monitor-format-opts"; const string OPTION_MONITOR_APPID = "--monitor-appid"; for (i = 0; i < n; i++) { try { switch (args[i]) { case OPTION_MONITOR_APPID: if (++i >= n) { error = true; break; } application_id = args[i]; break; case OPTION_MONITOR_CTX: if (++i >= n) { error = true; break; } monitor_context = true; monitor_context_ivl = Convert.ToInt32(args[i]); break; case OPTION_MONITOR_FORMAT: if (++i >= n) { error = true; break; } if (args[i].ToLower().CompareTo("csv") == 0) { mon_format = LBMMonitor.FORMAT_CSV; } else { error = true; break; } break; case OPTION_MONITOR_TRANSPORT: if (++i >= n) { error = true; break; } if (args[i].ToLower().CompareTo("lbm") == 0) { mon_transport = LBMMonitor.TRANSPORT_LBM; } else if (args[i].ToLower().CompareTo("udp") == 0) { mon_transport = LBMMonitor.TRANSPORT_UDP; } else if (args[i].ToLower().CompareTo("lbmsnmp") == 0) { mon_transport = LBMMonitor.TRANSPORT_LBMSNMP; } else { error = true; break; } break; case OPTION_MONITOR_TRANSPORT_OPTS: if (++i >= n) { error = true; break; } mon_transport_options += args[i]; break; case OPTION_MONITOR_FORMAT_OPTS: if (++i >= n) { error = true; break; } mon_format_options += args[i]; break; case "-c": if (++i >= n) { error = true; break; } try { LBM.setConfiguration(args[i]); } catch (LBMException Ex) { System.Console.Error.WriteLine("lbmwrcv error: " + Ex.Message); error = true; } break; case "-E": end_on_eos = true; break; case "-D": dereg = 1; break; case "-h": print_help_exit(0); break; case "-q": eventq = true; break; case "-r": if (++i >= n) { error = true; break; } reap_msgs = Convert.ToInt32(args[i]); break; case "-s": print_stats_flag = true; break; case "-N": if (++i >= n) { error = true; break; } channels.Add(Convert.ToUInt32(args[i])); break; case "-v": verbose = true; break; default: if (args[i].StartsWith("-")) { error = true; } else { done = true; } break; } if (error || done) { break; } } catch (Exception e) { /* type conversion exception */ System.Console.Error.WriteLine("lbmwrcv: error\n" + e.Message + "\n"); print_help_exit(1); } } if (error || i >= n) { /* An error occurred processing the command line - print help and exit */ print_help_exit(1); } LBMWRcvSourceNotify srcNotify = new LBMWRcvSourceNotify(); LBMContextAttributes lbmContextAttributes = new LBMContextAttributes(); lbmContextAttributes.enableSourceNotification(); LBMContext ctx = new LBMContext(lbmContextAttributes); ctx.addSourceNotifyCallback(new LBMSourceNotification(srcNotify.sourceNotification)); LBMWildcardReceiverAttributes lbmWildcardReceiverAttributes = new LBMWildcardReceiverAttributes(); string pattern = args[i]; string pattern_type = lbmWildcardReceiverAttributes.getValue("pattern_type"); LBMWRcvTopicFilter topicFilter; if (pattern == "*" && (pattern_type.ToUpper() == "PCRE" || pattern_type.ToLower() == "regex")) { topicFilter = new LBMWRcvTopicFilter(); pattern_type = "appcb"; lbmWildcardReceiverAttributes.setValue("pattern_type", pattern_type); lbmWildcardReceiverAttributes.setPatternCallback(new LBMWildcardPatternCallback(topicFilter.comparePattern), null); } System.Console.Error.WriteLine("Creating wildcard receiver for pattern [" + pattern + "] - using pattern type: " + pattern_type); LBMWRcvReceiver wrcv = new LBMWRcvReceiver(verbose, end_on_eos); LBMWildcardReceiver lbmWildcardReceiver; LBMWRcvEventQueue evq = null; if (eventq) { System.Console.Error.WriteLine("Event queue in use"); evq = new LBMWRcvEventQueue(); lbmWildcardReceiver = new LBMWildcardReceiver(ctx, pattern, null, lbmWildcardReceiverAttributes, wrcv.onReceive, null, evq); ctx.enableImmediateMessageReceiver(evq); } else { System.Console.Error.WriteLine("No event queue"); lbmWildcardReceiver = new LBMWildcardReceiver(ctx, pattern, null, lbmWildcardReceiverAttributes, wrcv.onReceive, null); ctx.enableImmediateMessageReceiver(); } ctx.addImmediateMessageReceiver(new LBMImmediateMessageCallback(wrcv.onReceiveImmediate), null); wrcv.setWrcvr(lbmWildcardReceiver); wrcv.setDereg(dereg); if (channels.Count > 0) { System.Console.Error.Write("Subscribing to channels: "); foreach (uint channel in channels) { try { lbmWildcardReceiver.subscribeChannel(channel, wrcv.onReceive, null); System.Console.Error.Write("{0} ", channel); } catch (Exception e) { System.Console.Error.WriteLine(); System.Console.Error.WriteLine(e.Message); } } System.Console.Error.WriteLine(); } LBMMonitorSource lbmmonsrc = null; if (monitor_context) { lbmmonsrc = new LBMMonitorSource(mon_format, mon_format_options, mon_transport, mon_transport_options); lbmmonsrc.start(ctx, application_id, monitor_context_ivl); } System.Console.Out.Flush(); long start_time; long end_time; long last_lost = 0, lost_tmp = 0, lost = 0; bool have_stats; LBMReceiverStatistics stats = null; while (true) { start_time = System.DateTime.Now.Ticks; if (eventq) { evq.run(1000); } else { System.Threading.Thread.Sleep(1000); } end_time = System.DateTime.Now.Ticks; have_stats = false; while (!have_stats) { try { stats = ctx.getReceiverStatistics(nstats); have_stats = true; } catch (LBMException ex) { /* Double the number of stats passed to the API to be retrieved */ /* Do so until we retrieve stats successfully or hit the max limit */ nstats *= 2; if (nstats > DEFAULT_MAX_NUM_SRCS) { System.Console.Error.WriteLine("Error getting receiver statistics: " + ex.Message); System.Environment.Exit(1); } /* have_stats is still false */ } } lost = 0; for (int stat = 0; stat < stats.size(); stat++) { lost += stats.lost(stat); } /* Account for loss in previous iteration */ lost_tmp = lost; if (last_lost <= lost) { lost -= last_lost; } else { lost = 0; } last_lost = lost_tmp; print_bw((end_time - start_time) / 10000, wrcv.msg_count, wrcv.byte_count, wrcv.unrec_count, lost, wrcv.burst_loss, wrcv.rx_msgs, wrcv.otr_msgs); wrcv.msg_count = 0; wrcv.byte_count = 0; wrcv.unrec_count = 0; wrcv.burst_loss = 0; wrcv.rx_msgs = 0; wrcv.otr_msgs = 0; if (print_stats_flag) { print_stats(stats, evq); } if (reap_msgs != 0 && wrcv.total_msg_count >= reap_msgs) { break; } } System.Console.Error.WriteLine("Quitting.... received " + wrcv.total_msg_count + " messages"); if (channels.Count > 0) { /* Unsubscribe from channels */ foreach (uint channel in channels) { lbmWildcardReceiver.unsubscribeChannel(channel); } } lbmWildcardReceiver.close(); ctx.close(); if (eventq) { evq.close(); } }
private lbmpong(string[] args) { if (System.Environment.GetEnvironmentVariable("LBM_LICENSE_FILENAME") == null && System.Environment.GetEnvironmentVariable("LBM_LICENSE_INFO") == null) { SetEnvironmentVariable("LBM_LICENSE_FILENAME", "lbm_license.txt"); } LBM lbm = new LBM(); lbm.setLogger(new LBMLogging(logger)); process_cmdline(args); if (use_mim && !eventq) { System.Console.Out.WriteLine("Using mim requires event queue to send from receive callback - forcing use"); eventq = true; } if (msecpause > 0 && !eventq) { System.Console.Out.WriteLine("Setting pause value requires event queue - forcing use"); eventq = true; } LBMSourceAttributes sattr = new LBMSourceAttributes(); LBMContextAttributes cattr = new LBMContextAttributes(); /* Check if protocol needs to be set to lbtrm | lbtru */ if (protocol == 'M') { try { sattr.setValue("transport", "LBTRM"); cattr.setValue("transport_lbtrm_data_rate_limit", send_rate.ToString()); cattr.setValue("transport_lbtrm_retransmit_rate_limit", retrans_rate.ToString()); } catch (LBMException ex) { System.Console.Error.WriteLine("Error setting LBTRM rate: " + ex.Message); System.Environment.Exit(1); } } if (protocol == 'U') { try { sattr.setValue("transport", "LBTRU"); cattr.setValue("transport_lbtru_data_rate_limit", send_rate.ToString()); cattr.setValue("transport_lbtru_retransmit_rate_limit", retrans_rate.ToString()); } catch (LBMException ex) { System.Console.Error.WriteLine("Error setting LBTRU rate: " + ex.Message); System.Environment.Exit(1); } } LBMContext ctx = new LBMContext(cattr); PongLBMEventQueue evq = null; if (eventq) { System.Console.Error.WriteLine("Event queue in use"); evq = new PongLBMEventQueue(); } else { System.Console.Error.WriteLine("No event queue"); } System.Console.Out.Flush(); LBMSource src = null; PongLBMReceiver rcv; LBMTopic src_topic = null; LBMTopic rcv_topic; if (ping) { System.Console.Error.WriteLine( "Sending " + msgs + " " + msglen + " byte messages to topic lbmpong/ping pausing " + msecpause + " msec between"); if (!use_mim) { src_topic = ctx.allocTopic("lbmpong/ping", sattr); } rcv_topic = ctx.lookupTopic("lbmpong/pong"); } else { rcv_topic = ctx.lookupTopic("lbmpong/ping"); if (!use_mim) { src_topic = ctx.allocTopic("lbmpong/pong", sattr); } } PongSrcCB srccb = new PongSrcCB(); if (!use_mim) { src = ctx.createSource(src_topic, new LBMSourceEventCallback(srccb.onSourceEvent), null); use_smx = src.getAttributeValue("transport").ToLower().Contains("smx"); if (use_smx) { /* Perform configuration validation */ const int smx_header_size = 16; int max_payload_size = Convert.ToInt32(src.getAttributeValue("transport_lbtsmx_datagram_max_size")) + smx_header_size; if (msglen > max_payload_size) { /* The SMX transport doesn't fragment, so payload must be within maximum size limits */ System.Console.WriteLine("Error: Message size requested is larger than configured SMX datagram size."); System.Environment.Exit(1); } } } rcv = new PongLBMReceiver(ctx, rcv_topic, evq, src, ping, msecpause, msgs, verbose, end_on_eos, rtt_collect, rtt_ignore, use_mim); System.Threading.Thread.Sleep(5000); if (ping) { byte [] message = new byte[msglen]; rcv.start(); format(message, 0, System.Diagnostics.Stopwatch.GetTimestamp() * lbmpong.pspertick / 1000); if (use_mim) { ctx.send("lbmpong/ping", message, msglen, LBM.MSG_FLUSH); } else if (use_smx) { try { IntPtr writeBuff; if (src.buffAcquire(out writeBuff, (uint)msglen, 0) == 0) { Marshal.Copy(message, 0, writeBuff, msglen); src.buffsComplete(); } } catch (LBMException ex) { System.Console.Error.WriteLine("Error (while doing SMX acquire/complete): " + ex.Message); System.Environment.Exit(1); } } else { src.send(message, msglen, LBM.MSG_FLUSH); } } if (eventq) { evq.run(run_secs * 1000); } else { System.Threading.Thread.Sleep(run_secs * 1000); } System.Console.Error.WriteLine("Quitting...."); if (!use_mim) { src.close(); } rcv.close(); ctx.close(); if (eventq) { evq.close(); } }
static void Main(string[] args) { if (System.Environment.GetEnvironmentVariable("LBM_LICENSE_FILENAME") == null && System.Environment.GetEnvironmentVariable("LBM_LICENSE_INFO") == null) { SetEnvironmentVariable("LBM_LICENSE_FILENAME", "lbm_license.txt"); } LBM lbm = new LBM(); lbm.setLogger(new LBMLogging(logger)); LBMObjectRecycler objRec = new LBMObjectRecycler(); int send_rate = 0; // Used for lbmtrm | lbtru transports int retrans_rate = 0; // char protocol = '\0'; // int linger = 5; int delay = 1; int msglen = 25; int pause = 0; bool do_stats = false; int initial_topic_number = default_initial_topic_number; string topicroot = default_topic_root; int num_srcs = default_num_sources; int num_thrds = default_num_threads; int i; int n = args.Length; bool monitor_context = false; int monitor_context_ivl = 0; bool monitor_source = false; int monitor_source_ivl = 0; string application_id = null; int mon_format = LBMMonitor.FORMAT_CSV; int mon_transport = LBMMonitor.TRANSPORT_LBM; string mon_format_options = null; string mon_transport_options = null; bool error = false; bool done = false; const string OPTION_MONITOR_CTX = "--monitor-ctx"; const string OPTION_MONITOR_SRC = "--monitor-src"; const string OPTION_MONITOR_TRANSPORT = "--monitor-transport"; const string OPTION_MONITOR_TRANSPORT_OPTS = "--monitor-transport-opts"; const string OPTION_MONITOR_FORMAT = "--monitor-format"; const string OPTION_MONITOR_FORMAT_OPTS = "--monitor-format-opts"; const string OPTION_MONITOR_APPID = "--monitor-appid"; for (i = 0; i < n; i++) { try { switch (args[i]) { case OPTION_MONITOR_APPID: if (++i >= n) { error = true; break; } application_id = args[i]; break; case OPTION_MONITOR_CTX: if (++i >= n) { error = true; break; } monitor_context = true; monitor_context_ivl = Convert.ToInt32(args[i]); break; case OPTION_MONITOR_SRC: if (++i >= n) { error = true; break; } monitor_source = true; monitor_source_ivl = Convert.ToInt32(args[i]); break; case OPTION_MONITOR_FORMAT: if (++i >= n) { error = true; break; } if (args[i].ToLower().CompareTo("csv") == 0) { mon_format = LBMMonitor.FORMAT_CSV; } else { error = true; break; } break; case OPTION_MONITOR_TRANSPORT: if (++i >= n) { error = true; break; } if (args[i].ToLower().CompareTo("lbm") == 0) { mon_transport = LBMMonitor.TRANSPORT_LBM; } else if (args[i].ToLower().CompareTo("udp") == 0) { mon_transport = LBMMonitor.TRANSPORT_UDP; } else if (args[i].ToLower().CompareTo("lbmsnmp") == 0) { mon_transport = LBMMonitor.TRANSPORT_LBMSNMP; } else { error = true; break; } break; case OPTION_MONITOR_TRANSPORT_OPTS: if (++i >= n) { error = true; break; } mon_transport_options += args[i]; break; case OPTION_MONITOR_FORMAT_OPTS: if (++i >= n) { error = true; break; } mon_format_options += args[i]; break; case "-c": if (++i >= n) { error = true; break; } try { LBM.setConfiguration(args[i]); } catch (LBMException Ex) { System.Console.Error.WriteLine("lbmmsrc error: " + Ex.Message); error = true; } break; case "-d": if (++i >= n) { error = true; break; } delay = Convert.ToInt32(args[i]); System.Console.Out.WriteLine("DELAY " + delay); break; case "-h": print_help_exit(0); break; case "-i": if (++i >= n) { error = true; break; } initial_topic_number = Convert.ToInt32(args[i]); break; case "-l": if (++i >= n) { error = true; break; } msglen = Convert.ToInt32(args[i]); break; case "-L": if (++i >= n) { error = true; break; } linger = Convert.ToInt32(args[i]); break; case "-M": if (++i >= n) { error = true; break; } msgs = Convert.ToInt32(args[i]); break; case "-P": if (++i >= n) { error = true; break; } pause = Convert.ToInt32(args[i]); break; case "-r": if (++i >= n) { error = true; break; } topicroot = args[i]; break; case "-R": if (++i >= n) { error = true; break; } ParseRateVars parseRateVars = lbmExampleUtil.parseRate(args[i]); if (parseRateVars.error) { print_help_exit(1); } send_rate = parseRateVars.rate; retrans_rate = parseRateVars.retrans; protocol = parseRateVars.protocol; break; case "-s": do_stats = true; break; case "-S": if (++i >= n) { error = true; break; } num_srcs = Convert.ToInt32(args[i]); if (num_srcs > max_num_sources) { System.Console.Error.WriteLine("Too many sources specified. Max number of sources is " + max_num_sources); System.Environment.Exit(1); } break; case "-T": if (++i >= n) { error = true; break; } num_thrds = Convert.ToInt32(args[i]); if (num_thrds > max_num_threads) { System.Console.Error.WriteLine("Too many threads specified. Max number of threads is " + max_num_threads); System.Environment.Exit(1); } break; default: if (args[i].StartsWith("-")) { System.Console.Out.WriteLine("DEFAULT ERROR=TRUE"); error = true; } else { done = true; } break; } if (error || done) { break; } } catch (Exception e) { /* type conversion exception */ System.Console.Error.WriteLine("lbmmsrc: error\n" + e.Message + "\n"); print_help_exit(1); } } if (error) { /* An error occurred processing the command line - print help and exit */ print_help_exit(1); } byte [] message = new byte[msglen]; if (num_thrds > num_srcs) { System.Console.Error.WriteLine("Number of threads must be less than or equal to number of sources"); System.Environment.Exit(1); } LBMSourceAttributes sattr = new LBMSourceAttributes(); sattr.setObjectRecycler(objRec, null); LBMContextAttributes cattr = new LBMContextAttributes(); cattr.setObjectRecycler(objRec, null); /* Check if protocol needs to be set to lbtrm | lbtru */ if (protocol == 'M') { try { sattr.setValue("transport", "LBTRM"); cattr.setValue("transport_lbtrm_data_rate_limit", send_rate.ToString()); cattr.setValue("transport_lbtrm_retransmit_rate_limit", retrans_rate.ToString()); } catch (LBMException ex) { System.Console.Error.WriteLine("Error setting LBTRM rate: " + ex.Message); System.Environment.Exit(1); } } if (protocol == 'U') { try { sattr.setValue("transport", "LBTRU"); cattr.setValue("transport_lbtru_data_rate_limit", send_rate.ToString()); cattr.setValue("transport_lbtru_retransmit_rate_limit", retrans_rate.ToString()); } catch (LBMException ex) { System.Console.Error.WriteLine("Error setting LBTRU rate: " + ex.Message); System.Environment.Exit(1); } } LBMContext ctx = new LBMContext(cattr); LBMMonitorSource lbmmonsrc = null; if (monitor_context || monitor_source) { lbmmonsrc = new LBMMonitorSource(mon_format, mon_format_options, mon_transport, mon_transport_options); if (monitor_context) { lbmmonsrc.start(ctx, application_id, monitor_context_ivl); } } MSrcCB srccb = new MSrcCB(); LBMSource [] sources = new LBMSource[num_srcs];; for (i = 0; i < num_srcs; i++) { int topicnum = initial_topic_number + i; string topicname = topicroot + "." + topicnum; LBMTopic topic = ctx.allocTopic(topicname, sattr); sources[i] = ctx.createSource(topic, new LBMSourceEventCallback(srccb.onSourceEvent), null, null); if (i > 1 && (i % 1000) == 0) { System.Console.Out.WriteLine("Created " + i + " sources"); } if (monitor_source) { lbmmonsrc.start(sources[i], application_id + "(" + i + ")", monitor_source_ivl); } } if (delay > 0) { System.Console.Out.WriteLine("Delaying sending for {0} second{1}...\n", delay, ((delay > 1) ? "s" : "")); Thread.Sleep(delay * 1000); } System.Console.Out.WriteLine("Created " + num_srcs + " sources. Will start sending data now.\n"); System.Console.Out.WriteLine("Using " + num_thrds + " threads to send " + msgs + " messages of size " + msglen + " bytes (" + (msgs / num_thrds) + " messages per thread)."); System.Console.Out.Flush(); LBMSrcThread [] srcthreads = new LBMSrcThread[num_thrds]; for (i = 1; i < num_thrds; i++) { srcthreads[i] = new LBMSrcThread(i, num_thrds, message, msglen, msgs / num_thrds, sources, num_srcs, pause); srcthreads[i].start(); } srcthreads[0] = new LBMSrcThread(0, num_thrds, message, msglen, msgs / num_thrds, sources, num_srcs, pause); srcthreads[0].run(); System.Console.Out.WriteLine("\nDone sending on thread 0. Waiting for any other threads to finish."); for (i = 1; i < num_thrds; i++) { System.Console.Out.WriteLine("Joining thread " + i); srcthreads[i].join(); System.Console.Out.WriteLine("Joined thread " + i); } System.Console.Out.Flush(); if (linger > 0) { System.Console.Out.WriteLine("\nLingering for {0} second{1}...\n", linger, ((linger > 1) ? "s" : "")); System.Threading.Thread.Sleep(linger * 1000); } if (do_stats) { print_stats(ctx, num_srcs, sources[0].getAttributeValue("transport"), objRec); } System.Console.Out.WriteLine("Quitting..."); objRec.close(); for (i = 0; i < num_srcs; i++) { sources[i].close(); } ctx.close(); }
static void Main(string[] args) { if (System.Environment.GetEnvironmentVariable("LBM_LICENSE_FILENAME") == null && System.Environment.GetEnvironmentVariable("LBM_LICENSE_INFO") == null) { SetEnvironmentVariable("LBM_LICENSE_FILENAME", "lbm_license.txt"); } LBM lbm = new LBM(); lbm.setLogger(new LBMLogging(logger)); LBMObjectRecycler objRec = new LBMObjectRecycler(); string qdelay = null; string qsize = null; string num_srcs = null; int i; int n = args.Length; bool monitor_context = false; int monitor_context_ivl = 0; bool monitor_receiver = false; int monitor_receiver_ivl = 0; string application_id = null; int mon_format = LBMMonitor.FORMAT_CSV; int mon_transport = LBMMonitor.TRANSPORT_LBM; string mon_format_options = null; string mon_transport_options = null; bool error = false; bool done = false; string regid_offset = "1000"; int seqnum_offset = 0; bool sqn_info = false; const string OPTION_MONITOR_CTX = "--monitor-ctx"; const string OPTION_MONITOR_RCV = "--monitor-rcv"; const string OPTION_MONITOR_TRANSPORT = "--monitor-transport"; const string OPTION_MONITOR_TRANSPORT_OPTS = "--monitor-transport-opts"; const string OPTION_MONITOR_FORMAT = "--monitor-format"; const string OPTION_MONITOR_FORMAT_OPTS = "--monitor-format-opts"; const string OPTION_MONITOR_APPID = "--monitor-appid"; for (i = 0; i < n; i++) { try { switch (args[i]) { case OPTION_MONITOR_APPID: if (++i >= n) { error = true; break; } application_id = args[i]; break; case OPTION_MONITOR_CTX: if (++i >= n) { error = true; break; } monitor_context = true; monitor_context_ivl = Convert.ToInt32(args[i]); break; case OPTION_MONITOR_RCV: if (++i >= n) { error = true; break; } monitor_receiver = true; monitor_receiver_ivl = Convert.ToInt32(args[i]); break; case OPTION_MONITOR_FORMAT: if (++i >= n) { error = true; break; } if (args[i].ToLower().CompareTo("csv") == 0) { mon_format = LBMMonitor.FORMAT_CSV; } else { error = true; break; } break; case OPTION_MONITOR_TRANSPORT: if (++i >= n) { error = true; break; } if (args[i].ToLower().CompareTo("lbm") == 0) { mon_transport = LBMMonitor.TRANSPORT_LBM; } else if (args[i].ToLower().CompareTo("udp") == 0) { mon_transport = LBMMonitor.TRANSPORT_UDP; } else if (args[i].ToLower().CompareTo("lbmsnmp") == 0) { mon_transport = LBMMonitor.TRANSPORT_LBMSNMP; } else { error = true; break; } break; case OPTION_MONITOR_TRANSPORT_OPTS: if (++i >= n) { error = true; break; } mon_transport_options += args[i]; break; case OPTION_MONITOR_FORMAT_OPTS: if (++i >= n) { error = true; break; } mon_format_options += args[i]; break; case "-c": if (++i >= n) { error = true; break; } try { LBM.setConfiguration(args[i]); } catch (LBMException Ex) { System.Console.Error.WriteLine("umercv error: " + Ex.Message); error = true; } break; case "-d": if (++i >= n) { error = true; break; } qdelay = args[i]; eventq = true; break; case "-E": end_on_eos = true; break; case "-D": dereg = 1; break; case "-e": if (++i >= n) { error = true; break; } exack = Convert.ToInt32(args[i]); break; case "-i": if (++i >= n) { error = true; break; } regid_offset = args[i]; break; case "-h": print_help_exit(0); break; case "-n": if (++i >= n) { error = true; break; } num_srcs = args[i]; break; case "-N": if (++i >= n) { error = true; break; } seqnum_offset = Convert.ToInt32(args[i]); sqn_info = true; break; case "-q": eventq = true; break; case "-r": if (++i >= n) { error = true; break; } reap_msgs = Convert.ToInt32(args[i]); break; case "-S": end_on_eos = true; summary = true; break; case "-s": if (++i >= n) { error = true; break; } stat_secs = Convert.ToInt32(args[i]); break; case "-v": verbose = true; break; case "-z": if (++i >= n) { error = true; break; } qsize = args[i]; eventq = true; break; default: if (args[i].StartsWith("-")) { error = true; } else { done = true; } break; } if (error || done) { break; } } catch (Exception e) { /* type conversion exception */ System.Console.Error.WriteLine("umercv: error\n" + e.Message); print_help_exit(1); } } if (error || i >= n) { /* An error occurred processing the command line - print help and exit */ print_help_exit(1); } LBMContextAttributes cattr = new LBMContextAttributes(); cattr.setObjectRecycler(objRec, null); LBMContext ctx = new LBMContext(cattr); LBMReceiverAttributes rattr = null; UMERegistrationId umeregid; rattr = new LBMReceiverAttributes(); rattr.setObjectRecycler(objRec, null); if (num_srcs != null) { rattr.setValue("resolution_number_of_sources_query_threshold", num_srcs); } if (regid_offset != null) { umeregid = new UMERegistrationId(regid_offset); rattr.setRegistrationIdCallback(new UMERegistrationIdExCallback(umeregid.setRegistrationId), null); System.Console.Out.WriteLine("Will use RegID offset " + regid_offset + "."); } else { System.Console.Out.WriteLine("Will not use specific RegID."); } if (sqn_info) { UMERcvRecInfo umerecinfocb = new UMERcvRecInfo(seqnum_offset); rattr.setRecoverySequenceNumberCallback(umerecinfocb.setRecoverySequenceNumberInfo, null); System.Console.Out.WriteLine("Will use seqnum info with low offset " + seqnum_offset + "."); } if (exack > 0) { try { rattr.setValue("ume_explicit_ack_only", "1"); } catch (LBMException e) { System.Console.Error.WriteLine("Error setting ume_explicit_ack_only=" + exack + e.Message); System.Environment.Exit(1); } } LBMTopic topic = ctx.lookupTopic(args[i], rattr); UMERcvReceiver rcv = new UMERcvReceiver(verbose, end_on_eos, summary, exack, dereg); LBMReceiver lbmrcv; UMERcvEventQueue evq = null; if (eventq) { System.Console.Error.WriteLine("Event queue in use"); LBMEventQueueAttributes evqattr = null; if (qsize != null || qdelay != null) { evqattr = new LBMEventQueueAttributes(); if (qdelay != null) { evqattr.setValue("queue_delay_warning", qdelay); } if (qsize != null) { evqattr.setValue("queue_size_warning", qsize); } } evq = new UMERcvEventQueue(evqattr); lbmrcv = new LBMReceiver(ctx, topic, rcv.onReceive, null, evq); ctx.enableImmediateMessageReceiver(evq); } else { System.Console.Error.WriteLine("No event queue"); lbmrcv = new LBMReceiver(ctx, topic, rcv.onReceive, null); ctx.enableImmediateMessageReceiver(); } rcv.setRcvr(lbmrcv); // This immediate-mode receiver is *only* used for topicless // immediate-mode sends. Immediate sends that use a topic // are received with normal receiver objects. ctx.addImmediateMessageReceiver(new LBMImmediateMessageCallback(rcv.onReceive)); LBMMonitorSource lbmmonsrc = null; if (monitor_context || monitor_receiver) { lbmmonsrc = new LBMMonitorSource(mon_format, mon_format_options, mon_transport, mon_transport_options); if (monitor_context) { lbmmonsrc.start(ctx, application_id, monitor_context_ivl); } else { lbmmonsrc.start(lbmrcv, application_id, monitor_receiver_ivl); } } System.Console.Out.Flush(); long start_time; long end_time; long last_lost = 0, lost_tmp = 0, lost = 0; bool have_stats; LBMReceiverStatistics stats = null; long stat_time = System.DateTime.Now.AddSeconds(stat_secs).Ticks; for (; ;) { start_time = System.DateTime.Now.Ticks; if (eventq) { evq.run(1000); } else { System.Threading.Thread.Sleep(1000); } have_stats = false; while (!have_stats) { try { stats = lbmrcv.getStatistics(nstats); have_stats = true; } catch (LBMException ex) { /* Double the number of stats passed to the API to be retrieved */ /* Do so until we retrieve stats successfully or hit the max limit */ nstats *= 2; if (nstats > DEFAULT_MAX_NUM_SRCS) { System.Console.Error.WriteLine("Error getting receiver statistics: " + ex.Message); System.Environment.Exit(1); } /* have_stats is still false */ } } /* If we get here, we have the stats */ lost = 0; for (i = 0; i < stats.size(); i++) { lost += stats.lost(i); } /* Account for loss in previous iteration */ lost_tmp = lost; if (last_lost <= lost) { lost -= last_lost; } else { lost = 0; } last_lost = lost_tmp; end_time = System.DateTime.Now.Ticks; print_bw((end_time - start_time) / 10000, rcv.msg_count, rcv.byte_count, rcv.unrec_count, lost, rcv.burst_loss, rcv.rx_msgs, rcv.otr_msgs); if (stat_secs > 0 && stat_time <= end_time) { stat_time = System.DateTime.Now.AddSeconds(stat_secs).Ticks; print_stats(stats, evq); } objRec.doneWithReceiverStatistics(stats); rcv.msg_count = 0; rcv.byte_count = 0; rcv.unrec_count = 0; rcv.burst_loss = 0; rcv.rx_msgs = 0; rcv.otr_msgs = 0; if (reap_msgs != 0 && rcv.total_msg_count >= reap_msgs) { break; } } System.Console.Error.WriteLine("Quitting.... received " + rcv.total_msg_count + " messages"); objRec.close(); lbmrcv.close(); ctx.close(); if (eventq) { evq.close(); } GC.KeepAlive(lbm); }
static void Main(string[] args) { if (System.Environment.GetEnvironmentVariable("LBM_LICENSE_FILENAME") == null && System.Environment.GetEnvironmentVariable("LBM_LICENSE_INFO") == null) { SetEnvironmentVariable("LBM_LICENSE_FILENAME", "lbm_license.txt"); } LBM lbm = new LBM(); lbm.setLogger(new LBMLogging(logger)); int num_ctxs = default_num_ctxs; int num_rcvs = default_num_rcvs; int initial_topic_number = default_initial_topic_number; string topicroot = default_topic_root; int i; int n = args.Length; bool monitor_context = false; int monitor_context_ivl = 0; bool monitor_receiver = false; int monitor_receiver_ivl = 0; string application_id = null; int mon_format = LBMMonitor.FORMAT_CSV; int mon_transport = LBMMonitor.TRANSPORT_LBM; long bufsize = 8; string mon_format_options = null; string mon_transport_options = null; bool error = false; const string OPTION_MONITOR_CTX = "--monitor-ctx"; const string OPTION_MONITOR_RCV = "--monitor-rcv"; const string OPTION_MONITOR_TRANSPORT = "--monitor-transport"; const string OPTION_MONITOR_TRANSPORT_OPTS = "--monitor-transport-opts"; const string OPTION_MONITOR_FORMAT = "--monitor-format"; const string OPTION_MONITOR_FORMAT_OPTS = "--monitor-format-opts"; const string OPTION_MONITOR_APPID = "--monitor-appid"; for (i = 0; i < n; i++) { try { switch (args[i]) { case OPTION_MONITOR_APPID: if (++i >= n) { error = true; break; } application_id = args[i]; break; case OPTION_MONITOR_CTX: if (++i >= n) { error = true; break; } monitor_context = true; monitor_context_ivl = Convert.ToInt32(args[i]); break; case OPTION_MONITOR_RCV: if (++i >= n) { error = true; break; } monitor_receiver = true; monitor_receiver_ivl = Convert.ToInt32(args[i]); break; case OPTION_MONITOR_FORMAT: if (++i >= n) { error = true; break; } if (args[i].ToLower().CompareTo("csv") == 0) { mon_format = LBMMonitor.FORMAT_CSV; } else { error = true; break; } break; case OPTION_MONITOR_TRANSPORT: if (++i >= n) { error = true; break; } if (args[i].ToLower().CompareTo("lbm") == 0) { mon_transport = LBMMonitor.TRANSPORT_LBM; } else if (args[i].ToLower().CompareTo("udp") == 0) { mon_transport = LBMMonitor.TRANSPORT_UDP; } else if (args[i].ToLower().CompareTo("lbmsnmp") == 0) { mon_transport = LBMMonitor.TRANSPORT_LBMSNMP; } else { error = true; break; } break; case OPTION_MONITOR_TRANSPORT_OPTS: if (++i >= n) { error = true; break; } mon_transport_options += args[i]; break; case OPTION_MONITOR_FORMAT_OPTS: if (++i >= n) { error = true; break; } mon_format_options += args[i]; break; case "-B": if (++i >= n) { error = true; break; } bufsize = Convert.ToInt32(args[i]); break; case "-c": if (++i >= n) { error = true; break; } try { LBM.setConfiguration(args[i]); } catch (LBMException Ex) { System.Console.Error.WriteLine("lbmmrcv: " + Ex.Message); error = true; } break; case "-C": if (++i >= n) { error = true; break; } num_ctxs = Convert.ToInt32(args[i]); break; case "-h": print_help_exit(0); break; case "-i": if (++i >= n) { error = true; break; } initial_topic_number = Convert.ToInt32(args[i]); break; case "-M": if (++i >= n) { error = true; break; } msgs = Convert.ToInt32(args[i]); break; case "-r": if (++i >= n) { error = true; break; } topicroot = args[i]; break; case "-R": if (++i >= n) { error = true; break; } num_rcvs = Convert.ToInt32(args[i]); if (num_rcvs > max_num_rcvs) { System.Console.Error.WriteLine("Too many receivers specified. Max number of receivers is " + max_num_rcvs); System.Environment.Exit(1); } break; case "-s": print_stats_flag = true; break; case "-v": verbose = true; break; default: error = true; break; } if (error) { break; } } catch (Exception e) { /* type conversion exception */ System.Console.Error.WriteLine("lbmmrcv: error\n" + e.Message + "\n"); print_help_exit(1); } } if (error) { /* An error occurred processing the command line - print help and exit */ print_help_exit(1); } System.Console.Out.WriteLine("Using " + num_ctxs + " context(s)"); LBMContextAttributes ctx_attr = new LBMContextAttributes(); if (bufsize > 0) { bufsize *= 1024 * 1024; ctx_attr.setValue("transport_tcp_receiver_socket_buffer", "" + bufsize); ctx_attr.setValue("transport_lbtrm_receiver_socket_buffer", "" + bufsize); ctx_attr.setValue("transport_lbtru_receiver_socket_buffer", "" + bufsize); } LBMContext[] ctxs = new LBMContext[num_ctxs]; for (i = 0; i < num_ctxs; i++) { ctxs[i] = new LBMContext(ctx_attr); } LBMMonitorSource lbmmonsrc = null; if (monitor_context || monitor_receiver) { lbmmonsrc = new LBMMonitorSource(mon_format, mon_format_options, mon_transport, mon_transport_options); if (monitor_context) { for (i = 0; i < num_ctxs; i++) { lbmmonsrc.start(ctxs[i], application_id, monitor_context_ivl); } } } LBMMRcvReceiver[] rcvs = new LBMMRcvReceiver[num_rcvs]; System.Console.Out.WriteLine("Creating " + num_rcvs + " receivers"); int ctxidx = 0; for (i = 0; i < num_rcvs; i++) { int topicnum = initial_topic_number + i; string topicname = topicroot + "." + topicnum; LBMTopic topic = ctxs[ctxidx].lookupTopic(topicname); rcvs[i] = new LBMMRcvReceiver(ctxs[ctxidx], topic, verbose); if (i > 1 && (i % 1000) == 0) { System.Console.Out.WriteLine("Created " + i + " receivers"); } if (++ctxidx >= num_ctxs) { ctxidx = 0; } if (monitor_receiver) { lbmmonsrc.start(rcvs[i].rcv, application_id + "(" + i + ")", monitor_receiver_ivl); } } // // Setup just one immediate message receiver to receive topicless // messages. We'll just pick the first context to set it up on. // ctxs[0].enableImmediateMessageReceiver(); ctxs[0].addImmediateMessageReceiver(new LBMImmediateMessageCallback(onReceiveImmediate)); System.Console.Out.WriteLine("Created " + num_rcvs + " receivers. Will start calculating aggregate throughput."); System.Console.Out.Flush(); long start_time; long end_time; long total_msg_count = 0; long last_lost = 0, lost_tmp = 0, lost; while (true) { start_time = System.DateTime.Now.Ticks; System.Threading.Thread.Sleep(1000); end_time = System.DateTime.Now.Ticks; long msg_count = 0; long byte_count = 0; long unrec_count = 0; long burst_loss = 0; long rx_msgs = 0; long otr_msgs = 0; for (i = 0; i < num_rcvs; i++) { msg_count += rcvs[i].msg_count; total_msg_count += rcvs[i].msg_count; byte_count += rcvs[i].byte_count; unrec_count += rcvs[i].unrec_count; burst_loss += rcvs[i].burst_loss; rx_msgs += rcvs[i].rx_msgs; otr_msgs += rcvs[i].otr_msgs; rcvs[i].msg_count = 0; rcvs[i].byte_count = 0; rcvs[i].unrec_count = 0; rcvs[i].burst_loss = 0; rcvs[i].rx_msgs = 0; rcvs[i].otr_msgs = 0; } /* Calculate aggregate transport level loss */ /* Pass 0 for the print flag indicating interested in retrieving loss stats */ lost = get_loss_or_print_stats(ctxs, false); /* Account for loss in previous iteration */ lost_tmp = lost; if (last_lost <= lost) { lost -= last_lost; } else { lost = 0; } last_lost = lost_tmp; print_bw((end_time - start_time) / 10000, msg_count + imsg_count, byte_count + imsg_byte_count, unrec_count, lost, burst_loss, rx_msgs, otr_msgs); imsg_count = 0; imsg_byte_count = 0; if (print_stats_flag) { /* Display transport level statistics */ /* Pass print_stats_flag for the print flag indicating interested in displaying stats */ get_loss_or_print_stats(ctxs, print_stats_flag); } } }
static void Main(string[] args) { if (Environment.GetEnvironmentVariable("LBM_LICENSE_FILENAME") == null && Environment.GetEnvironmentVariable("LBM_LICENSE_INFO") == null) { SetEnvironmentVariable("LBM_LICENSE_FILENAME", "lbm_license.txt"); } LBM lbm = new LBM(); lbm.setLogger(logger); string target = null; int send_rate = 0; // Used for lbmtrm | lbtru transports int retrans_rate = 0; // char protocol = '\0'; // int linger = 5; int msglen = MIN_ALLOC_MSGLEN; int pause_milliseconds = 5; int delay = 1; int i; int n = args.Length; bool error = false; bool done = false; for (i = 0; i < n; i++) { try { switch (args[i]) { case "-c": if (++i >= n) { error = true; break; } try { LBM.setConfiguration(args[i]); } catch (LBMException Ex) { Console.Error.WriteLine("lbmreq error: " + Ex.Message); error = true; } break; case "-d": if (++i >= n) { error = true; break; } delay = Convert.ToInt32(args[i]); break; case "-h": print_help_exit(0); break; case "-i": send_immediate = true; break; case "-q": eventq = true; break; case "-l": if (++i >= n) { error = true; break; } msglen = Convert.ToInt32(args[i]); break; case "-L": if (++i >= n) { error = true; break; } linger = Convert.ToInt32(args[i]); break; case "-P": if (++i >= n) { error = true; break; } pause_milliseconds = Convert.ToInt32(args[i]); break; case "-R": if (++i >= n) { error = true; break; } requests = Convert.ToInt32(args[i]); break; case "-r": if (++i >= n) { error = true; break; } ParseRateVars parseRateVars = lbmExampleUtil.parseRate(args[i]); if (parseRateVars.error) { print_help_exit(1); } send_rate = parseRateVars.rate; retrans_rate = parseRateVars.retrans; protocol = parseRateVars.protocol; break; case "-s": if (++i >= n) { error = true; break; } stats_sec = Convert.ToInt32(args[i]); break; case "-T": if (++i >= n) { error = true; break; } target = args[i]; break; case "-v": verbose++; break; default: if (args[i].StartsWith("-")) { error = true; } else { done = true; } break; } if (error || done) { break; } } catch (Exception e) { /* type conversion exception */ Console.Error.WriteLine("lbmreq: error\n" + e.Message + "\n"); print_help_exit(1); } } if (error || i >= n) { /* An error occurred processing the command line - print help and exit */ print_help_exit(1); } string topic_str = null; if (i >= n) { if (!send_immediate) { print_help_exit(1); } } else { topic_str = args[i]; } byte[] message = null; /* if message buffer is too small, then the enc.GetBytes will cause issues. * Therefore, allocate with a MIN_ALLOC_MSGLEN */ if (msglen < MIN_ALLOC_MSGLEN) { message = new byte[MIN_ALLOC_MSGLEN]; } else { message = new byte[msglen]; } LBMSourceAttributes lbmSourceAttributes = new LBMSourceAttributes(); LBMContextAttributes lbmContextAttributes = new LBMContextAttributes(); /* Check if protocol needs to be set to lbtrm | lbtru */ if (protocol == 'M') { try { lbmSourceAttributes.setValue("transport", "LBTRM"); lbmContextAttributes.setValue("transport_lbtrm_data_rate_limit", send_rate.ToString()); lbmContextAttributes.setValue("transport_lbtrm_retransmit_rate_limit", retrans_rate.ToString()); } catch (LBMException ex) { Console.Error.WriteLine("Error setting LBTRM rate: " + ex.Message); Environment.Exit(1); } } if (protocol == 'U') { try { lbmSourceAttributes.setValue("transport", "LBTRU"); lbmContextAttributes.setValue("transport_lbtru_data_rate_limit", send_rate.ToString()); lbmContextAttributes.setValue("transport_lbtru_retransmit_rate_limit", retrans_rate.ToString()); } catch (LBMException ex) { Console.Error.WriteLine("Error setting LBTRU rate: " + ex.Message); Environment.Exit(1); } } LBMContext ctx = new LBMContext(lbmContextAttributes); LBMreqEventQueue lbmReqEventQueue = null; if (eventq) { lbmReqEventQueue = new LBMreqEventQueue(); Console.Error.WriteLine("Event queue in use."); } else { Console.Error.WriteLine("No event queue\n"); } LBMTopic topic; LBMSource src = null; LBMreqCB lbMreqCallBack = new LBMreqCB(verbose); if (!send_immediate) { topic = ctx.allocTopic(topic_str, lbmSourceAttributes); src = ctx.createSource(topic, lbMreqCallBack.onSourceEvent, null, lbmReqEventQueue); if (delay > 0) { Console.Out.WriteLine("Delaying requests for {0} second{1}...\n", delay, ((delay > 1) ? "s" : "")); Thread.Sleep(delay * 1000); } } ASCIIEncoding enc = new ASCIIEncoding(); if (requests > 0) { Console.Out.WriteLine("Will send {0} request{1}\n", requests, (requests == 1 ? "" : "s")); } Console.Out.Flush(); for (int count = 0; count < requests; count++) { LBMTimer qTimer; StringBuilder sb = new StringBuilder(); sb.AppendFormat("Request data {0}", count); enc.GetBytes(sb.ToString(), 0, sb.ToString().Length, message, 0); LBMRequest req = new LBMRequest(message, msglen); req.addResponseCallback(lbMreqCallBack.onResponse); Console.Out.WriteLine("Sending request " + count); if (send_immediate) { if (target == null) { if (eventq) { ctx.send(topic_str, req, lbmReqEventQueue, 0); } else { ctx.send(topic_str, req, 0); } } else { if (eventq) { ctx.send(target, topic_str, req, lbmReqEventQueue, 0); } else { ctx.send(target, topic_str, req, 0); } } } else { if (eventq) { src.send(req, lbmReqEventQueue, 0); } else { src.send(req, 0); } } if (verbose > 0) { Console.Out.Write("Sent request " + count + ". "); } if (!eventq) { if (verbose > 0) { Console.Out.WriteLine("Pausing " + pause_milliseconds + " seconds."); } Thread.Sleep(pause_milliseconds); } else { if (verbose > 0) { Console.Out.WriteLine("Creating timer for " + pause_milliseconds + " seconds and initiating event pump."); } qTimer = new EQTimer(ctx, pause_milliseconds, lbmReqEventQueue); lbmReqEventQueue.run(LBM.EVENT_QUEUE_BLOCK); } Console.Out.WriteLine("Done waiting for responses, {0} response{1} ({2} total bytes) received. Deleting request.\n", lbMreqCallBack.response_count, (lbMreqCallBack.response_count == 1 ? "" : "s"), lbMreqCallBack.response_byte_count); lbMreqCallBack.response_count = 0; lbMreqCallBack.response_byte_count = 0; req.close(); Console.Out.Flush(); }//end of for if (linger > 0) { Console.Out.WriteLine("\nLingering for {0} second{1}...\n", linger, ((linger > 1) ? "s" : "")); Thread.Sleep(linger * 1000); } Console.Out.WriteLine("Quitting..."); if (src != null) { src.close(); } ctx.close(); }
void Run(string[] args) { string cfgFile = "application.cfg"; string test = "1"; if (args.Length == 2) { cfgFile = args[0]; test = args[1]; } else if (args.Length == 1) { cfgFile = args[0]; } else if (args.Length != 0) { throw new TmonException("TmonExample: bad arg count (" + args.Length + ")"); } LBM lbm = new LBM(); lbm.setLogger(this.Logger); _timeOfDay = new TmonGetTimeOfDay(); LBM.setConfiguration(cfgFile); MyLog("Creating context."); // Context name must be alpha, numeric, underscore, hyphen. LBMContextAttributes ctxAttr = new LBMContextAttributes("tmon_example_ctx"); LBMContext ctx = new LBMContext(ctxAttr); MyLog("Creating topic monitor."); TmonContext tmonContext = new TmonContext(ctx); tmonContext.InitSender(); // I.e. this tmon context is for sending reports. MyLog("Creating wildcard rcv for '^.*2$' (will resolv, no msg)"); TmonReceiver tmonWRcv = tmonContext.ReceiverCreate(ReceiverType.Wildcard, "^.*2$"); LBMReceiverAttributes rcvAttr = new LBMReceiverAttributes("29west_tmon_context", "wc2"); rcvAttr.setSourceNotificationCallbacks(this.OnDeliveryControllerCreate, this.OnDeliveryControllerDelete, tmonWRcv); LBMWildcardReceiver wrcv = new LBMWildcardReceiver(ctx, "^.*2$", rcvAttr, null, this.OnReceive, null); MyLog("Creating rcv for 'src\\1' (will resolv, rcv msg)"); TmonReceiver tmonRcv1 = tmonContext.ReceiverCreate(ReceiverType.Regular, "src\\1"); rcvAttr = new LBMReceiverAttributes("29west_tmon_context", "src\\1"); rcvAttr.setSourceNotificationCallbacks(this.OnDeliveryControllerCreate, this.OnDeliveryControllerDelete, tmonRcv1); LBMReceiver rcv1 = new LBMReceiver(ctx, ctx.lookupTopic("src\\1", rcvAttr), this.OnReceive, null, null); MyLog("Creating rcv for 'src3' (will resolve, no msg)"); TmonReceiver tmonRcv3 = tmonContext.ReceiverCreate(ReceiverType.Regular, "src3"); rcvAttr = new LBMReceiverAttributes("29west_tmon_context", "src3"); rcvAttr.setSourceNotificationCallbacks(this.OnDeliveryControllerCreate, this.OnDeliveryControllerDelete, tmonRcv3); LBMReceiver rcv3 = new LBMReceiver(ctx, ctx.lookupTopic("src3", rcvAttr), this.OnReceive, null, null); MyLog("Creating rcv for 'srcx' (will not resolve)"); TmonReceiver tmonRcvx = tmonContext.ReceiverCreate(ReceiverType.Regular, "srcx"); rcvAttr = new LBMReceiverAttributes("29west_tmon_context", "srcx"); rcvAttr.setSourceNotificationCallbacks(this.OnDeliveryControllerCreate, this.OnDeliveryControllerDelete, tmonRcvx); LBMReceiver rcvx = new LBMReceiver(ctx, ctx.lookupTopic("srcx", rcvAttr), this.OnReceive, null, null); MyLog("Creating src for 'src\\1' (will resolve, send msg)"); TmonSource tmonSrc1 = tmonContext.SourceCreate("src\\1"); LBMSourceAttributes srcAttr = new LBMSourceAttributes("29west_tmon_context", "src\\1"); LBMSource src1 = ctx.createSource(ctx.allocTopic("src\\1", srcAttr)); Thread.Sleep(100); // Let receiver discover. MyLog("Creating src for 'src,2' (wildcard resolve, no msg)"); TmonSource tmonSrc2 = tmonContext.SourceCreate("src,2"); srcAttr = new LBMSourceAttributes("29west_tmon_context", "src,2"); LBMSource src2 = ctx.createSource(ctx.allocTopic("src,2", srcAttr)); Thread.Sleep(100); // Let receiver discover. MyLog("Creating src for 'src3' (will resolve, no msg)"); TmonSource tmonSrc3 = tmonContext.SourceCreate("src3"); srcAttr = new LBMSourceAttributes("29west_tmon_context", "src3"); LBMSource src3 = ctx.createSource(ctx.allocTopic("src3", srcAttr)); Thread.Sleep(100); // Let receiver discover. MyLog("Delete receiver for 'src,2' to get DC delete without BOS or EOS"); wrcv.close(); tmonWRcv.Close(); MyLog("Sleeping 6 for BOS triggered by TSNI for 'src\\1', 'src3'"); Thread.Sleep(6000); MyLog("Deleting rcv for 'src3' while src still up - should get DC delete without EOS"); rcv3.close(); tmonRcv3.Close(); string msg = "Hello!"; if (test.Equals("1")) { MyLog("Sending to 'src\\1'"); src1.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); MyLog("Wait for msg receive or EOS"); while (_messagesReceived == 0) { Thread.Sleep(1000); } } else if (test.Equals("2")) { MyLog("Sending 120 msgs to 'src\\1'"); for (int i = 0; i < 120; i++) { src1.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); } // for MyLog("lingering 10 sec"); Thread.Sleep(10000); } else { throw new TmonException("TmonExample: bad test number (" + test + ")"); } MyLog("Delete sources"); src1.close(); tmonSrc1.Close(); src2.close(); tmonSrc2.Close(); src3.close(); tmonSrc3.Close(); MyLog("Sleeping 6 sec for EOS and DC delete for 'src\\1'."); Thread.Sleep(6000); MyLog("Deleting rcvs for 'src\\1'"); rcv1.close(); tmonRcv1.Close(); MyLog("Generate rolling EOS on srcx"); LBM.setLbtrmSrcLossRate(100); TmonSource tmonSrcx = tmonContext.SourceCreate("srcx"); srcAttr = new LBMSourceAttributes("29west_tmon_context", "srcx"); LBMSource srcx = ctx.createSource(ctx.allocTopic("srcx", srcAttr)); srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Start SMs going. Thread.Sleep(13750); // Wait 2.5 * RM activity timeouts. MyLog("Generate BOS on srcx and msg"); LBM.setLbtrmSrcLossRate(0); msg = "1"; srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Trigger BOS. Thread.Sleep(100); MyLog("Generate unrecoverable loss on srcx"); LBM.setLbtrmSrcLossRate(100); msg = "2"; srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Lost pkt. Thread.Sleep(100); LBM.setLbtrmSrcLossRate(0); msg = "3"; srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // gap. Thread.Sleep(200); // 2*nak gen ivl. msg = "4"; srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // push out loss event. Thread.Sleep(100); MyLog("Generate suppressed unrecoverable loss"); LBM.setLbtrmSrcLossRate(0); msg = "1"; srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Trigger BOS. Thread.Sleep(100); LBM.setLbtrmSrcLossRate(100); msg = "2"; srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Lost pkt. Thread.Sleep(100); LBM.setLbtrmSrcLossRate(0); msg = "3"; srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // gap. Thread.Sleep(200); // 2*nak gen ivl. msg = "4"; srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // push out loss event. Thread.Sleep(100); Thread.Sleep(10100); // Expire tmon's 10-second loss suppression. MyLog("Generate unrecoverable burst loss"); LBM.setLbtrmSrcLossRate(100); msg = "5"; srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Lost pkt. msg = "6"; srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Lost pkt. msg = "7"; srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Lost pkt. msg = "8"; srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Lost pkt. Thread.Sleep(100); LBM.setLbtrmSrcLossRate(0); msg = "9"; srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // gap. Thread.Sleep(200); // Wait for BURST. MyLog("Delete rcvx, srcx."); rcvx.close(); tmonRcvx.Close(); srcx.close(); tmonSrcx.Close(); MyLog("Deleting tmon_ctx."); tmonContext.Close(); MyLog("Deleting context."); ctx.close(); } // Run