public PongLBMReceiver(LBMContext ctx, LBMTopic topic, LBMEventQueue evq, LBMSource src, bool ping, int msecpause, int msgs, bool verbose, bool end_on_eos, bool rtt_collect, int ignore, bool mim) { _ctx = ctx; _rcv = new LBMReceiver(ctx, topic, new LBMReceiverCallback(onReceive), null, evq); _msgs = msgs; _verbose = verbose; _msecpause = msecpause; _ping = ping; _evq = evq; _end_on_eos = end_on_eos; _src = src; if (rtt_collect) { rtt_data = new double[msgs]; } rtt_ignore = ignore; use_mim = mim; use_smx = src.getAttributeValue("transport").ToLower().Contains("smx"); }
public static int Main(string[] args) { lbmlatping latping = null; LBMContext ctx = null; LBMContextAttributes ctx_attr = null; LBMTopic ping_src_topic = null; LBMSourceAttributes ping_src_topic_attr = null; LBMSource ping_src = null; LBMTopic pong_rcv_topic = null; LBMReceiverAttributes pong_rcv_topic_attr = null; lbmlatpingreceiver pong_rcv = null; latping = new lbmlatping(args); if (latping.cpu >= 0) { Process.GetCurrentProcess().ProcessorAffinity = new IntPtr(latping.cpu); } try { /* Create the context. */ ctx_attr = new LBMContextAttributes(); ctx_attr.setValue("resolver_cache", "0"); ctx_attr.setValue("operational_mode", "sequential"); ctx_attr.setValue("request_tcp_port_high", "50000"); ctx = new LBMContext(ctx_attr); ctx_attr.dispose(); /* Create the ping source. */ ping_src_topic_attr = new LBMSourceAttributes(); ping_src_topic_attr.setValue("resolver_advertisement_sustain_interval", "0"); ping_src_topic_attr.setValue("transport", "lbtsmx"); ping_src_topic = new LBMTopic(ctx, "lbmlat-ping", ping_src_topic_attr); ping_src_topic_attr.dispose(); ping_src = new LBMSource(ctx, ping_src_topic); latping.ping_src = ping_src; /* Perform some configuration validation */ const int smx_header_size = 16; int max_payload_size = Convert.ToInt32(ping_src.getAttributeValue("transport_lbtsmx_datagram_max_size")) + smx_header_size; if (latping.msgbuf.Length > 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); } /* Create the pong receiver. */ pong_rcv_topic_attr = new LBMReceiverAttributes(); pong_rcv_topic_attr.enableSingleReceiverCallback(true); pong_rcv_topic = new LBMTopic(ctx, "lbmlat-pong", pong_rcv_topic_attr); pong_rcv_topic_attr.dispose(); pong_rcv = new lbmlatpingreceiver(ctx, pong_rcv_topic, latping); /* Run the context just long enough to advertise. */ ctx.processEvents(1000); /* The ponger kicks things off as soon as he's discovered our ping source. */ while (true) { System.Threading.Thread.Sleep(1000000); //ctx.processEvents(1000000); } } catch (Exception e) { System.Console.Out.WriteLine(e.ToString()); } return(0); }
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(); } }