Example #1
0
        /*
         * function to retrieve transport level loss or display transport level stats
         * @ctxs -- contexts to retrieve transport stats for
         * @print_flag -- if 1, display stats, retrieve loss otherwise
         */
        private static long get_loss_or_print_stats(LBMContext[] ctxs, bool print_flag)
        {
            long lost = 0;
            LBMReceiverStatistics stats = null;
            bool have_stats;

            for (int ctx = 0; ctx < ctxs.Length; ctx++)
            {
                have_stats = false;
                while (!have_stats)
                {
                    try
                    {
                        stats      = ctxs[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 */
                    }
                }

                /* If we get here, we have the stats */
                if (print_flag)
                {
                    /* Display transport level stats */
                    print_stats(stats);
                }
                else
                {
                    /* Accumlate transport level loss */
                    for (int stat = 0; stat < stats.size(); stat++)
                    {
                        switch (stats.type(stat))
                        {
                        case LBM.TRANSPORT_STAT_LBTRU:
                        case LBM.TRANSPORT_STAT_LBTRM:
                            lost += stats.lost(stat);
                            break;
                        }
                    }
                }
            }
            return(lost);
        }
Example #2
0
        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);
        }
Example #3
0
        private static void print_stats(LBMReceiverStatistics stats, LBMEventQueue evq)
        {
            if (evq != null)
            {
                if (Convert.ToInt32(evq.getAttributeValue("queue_size_warning")) > 0)
                {
                    System.Console.Out.WriteLine("Event queue size: " + evq.size());
                }
            }
            for (int i = 0; i < stats.size(); i++)
            {
                switch (stats.type(i))
                {
                case LBM.TRANSPORT_STAT_TCP:
                    System.Console.Out.WriteLine("TCP, source " + stats.source(i)
                                                 + ", received "
                                                 + stats.messagesReceived(i)
                                                 + "/"
                                                 + stats.bytesReceived(i)
                                                 + ", no topics "
                                                 + stats.noTopicMessagesReceived(i)
                                                 + ", requests "
                                                 + stats.lbmRequestsReceived(i));
                    break;

                case LBM.TRANSPORT_STAT_LBTRU:
                case LBM.TRANSPORT_STAT_LBTRM:
                    if (stats.type() == LBM.TRANSPORT_STAT_LBTRU)
                    {
                        System.Console.Out.Write("LBT-RU");
                    }
                    else
                    {
                        System.Console.Out.Write("LBT-RM");
                    }
                    System.Console.Out.WriteLine(", source " + stats.source(i)
                                                 + ", received "
                                                 + stats.messagesReceived(i)
                                                 + "/"
                                                 + stats.bytesReceived(i)
                                                 + ", naks "
                                                 + stats.nakPacketsSent(i)
                                                 + "/"
                                                 + stats.naksSent(i)
                                                 + ", lost "
                                                 + stats.lost(i)
                                                 + ", ncfs "
                                                 + stats.ncfsIgnored(i)
                                                 + "/"
                                                 + stats.ncfsShed(i)
                                                 + "/"
                                                 + stats.ncfsRetransmissionDelay(i)
                                                 + "/"
                                                 + stats.ncfsUnknown(i)
                                                 + ", recovery "
                                                 + stats.minimumRecoveryTime(i)
                                                 + "/"
                                                 + stats.meanRecoveryTime(i)
                                                 + "/"
                                                 + stats.maximumRecoveryTime(i)
                                                 + ", nak tx "
                                                 + stats.minimumNakTransmissions(i)
                                                 + "/"
                                                 + stats.minimumNakTransmissions(i)
                                                 + "/"
                                                 + stats.maximumNakTransmissions(i)
                                                 + ", dup "
                                                 + stats.duplicateMessages(i)
                                                 + ", unrecovered "
                                                 + stats.unrecoveredMessagesWindowAdvance(i)
                                                 + "/"
                                                 + stats.unrecoveredMessagesNakGenerationTimeout(i)
                                                 + ", LBM msgs " + stats.lbmMessagesReceived(i)
                                                 + ", no topics "
                                                 + stats.noTopicMessagesReceived(i)
                                                 + ", requests "
                                                 + stats.lbmRequestsReceived(i));
                    break;

                case LBM.TRANSPORT_STAT_LBTIPC:
                    System.Console.Out.WriteLine("LBT-IPC, source "
                                                 + stats.source(i)
                                                 + ", received "
                                                 + stats.messagesReceived(i)
                                                 + "/"
                                                 + stats.bytesReceived(i)
                                                 + ", LBM msgs "
                                                 + stats.lbmMessagesReceived(i)
                                                 + ", no topics "
                                                 + stats.noTopicMessagesReceived(i)
                                                 + ", requests "
                                                 + stats.lbmRequestsReceived(i));
                    break;

                case LBM.TRANSPORT_STAT_LBTRDMA:
                    System.Console.Out.WriteLine("LBT-RDMA, source "
                                                 + stats.source(i)
                                                 + ", received "
                                                 + stats.messagesReceived(i)
                                                 + "/"
                                                 + stats.bytesReceived(i)
                                                 + ", LBM msgs "
                                                 + stats.lbmMessagesReceived(i)
                                                 + ", no topics "
                                                 + stats.noTopicMessagesReceived(i)
                                                 + ", requests "
                                                 + stats.lbmRequestsReceived(i));
                    break;
                }
            }
            System.Console.Out.Flush();
        }
Example #4
0
        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();
            }
        }
Example #5
0
        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();
        }
Example #6
0
        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();
            }
        }
Example #7
0
    public virtual void  onReceive(LBMReceiverStatistics stats)
    {
        System.Console.Error.Write("\nReceiver statistics received");
        System.Console.Error.Write(" from " + stats.getApplicationSourceId());
        System.Console.Error.Write(" at " + stats.getSender().ToString());
        System.Console.Error.WriteLine(", sent " + stats.getTimestamp().ToLocalTime().ToString());
        System.Console.Error.WriteLine("Source: " + stats.source());
        System.Console.Error.WriteLine("Transport: " + stats.typeName());
        switch (stats.type())
        {
        case LBM.TRANSPORT_STAT_TCP:
            System.Console.Error.WriteLine("\tLBT-TCP bytes received                                    : " + stats.bytesReceived());
            System.Console.Error.WriteLine("\tLBM messages received                                     : " + stats.lbmMessagesReceived());
            System.Console.Error.WriteLine("\tLBM messages received with uninteresting topic            : " + stats.noTopicMessagesReceived());
            System.Console.Error.WriteLine("\tLBM requests received                                     : " + stats.lbmRequestsReceived());
            break;

        case LBM.TRANSPORT_STAT_LBTRM:
            System.Console.Error.WriteLine("\tLBT-RM datagrams received                                 : " + stats.messagesReceived());
            System.Console.Error.WriteLine("\tLBT-RM datagram bytes received                            : " + stats.bytesReceived());
            System.Console.Error.WriteLine("\tLBT-RM NAK packets sent                                   : " + stats.nakPacketsSent());
            System.Console.Error.WriteLine("\tLBT-RM NAKs sent                                          : " + stats.naksSent());
            System.Console.Error.WriteLine("\tLost LBT-RM datagrams detected                            : " + stats.lost());
            System.Console.Error.WriteLine("\tNCFs received (ignored)                                   : " + stats.ncfsIgnored());
            System.Console.Error.WriteLine("\tNCFs received (shed)                                      : " + stats.ncfsShed());
            System.Console.Error.WriteLine("\tNCFs received (retransmit delay)                          : " + stats.ncfsRetransmissionDelay());
            System.Console.Error.WriteLine("\tNCFs received (unknown)                                   : " + stats.ncfsUnknown());
            System.Console.Error.WriteLine("\tLoss recovery minimum time                                : " + stats.minimumRecoveryTime() + "ms");
            System.Console.Error.WriteLine("\tLoss recovery mean time                                   : " + stats.meanRecoveryTime() + "ms");
            System.Console.Error.WriteLine("\tLoss recovery maximum time                                : " + stats.maximumRecoveryTime() + "ms");
            System.Console.Error.WriteLine("\tMinimum transmissions per individual NAK                  : " + stats.minimumNakTransmissions());
            System.Console.Error.WriteLine("\tMean transmissions per individual NAK                     : " + stats.meanNakTransmissions());
            System.Console.Error.WriteLine("\tMaximum transmissions per individual NAK                  : " + stats.maximumNakTransmissions());
            System.Console.Error.WriteLine("\tDuplicate LBT-RM datagrams received                       : " + stats.duplicateMessages());
            System.Console.Error.WriteLine("\tLBT-RM datagrams unrecoverable (window advance)           : " + stats.unrecoveredMessagesWindowAdvance());
            System.Console.Error.WriteLine("\tLBT-RM datagrams unrecoverable (NAK generation expiration): " + stats.unrecoveredMessagesNakGenerationTimeout());
            System.Console.Error.WriteLine("\tLBT-RM LBM messages received                              : " + stats.lbmMessagesReceived());
            System.Console.Error.WriteLine("\tLBT-RM LBM messages received with uninteresting topic     : " + stats.noTopicMessagesReceived());
            System.Console.Error.WriteLine("\tLBT-RM LBM requests received                              : " + stats.lbmRequestsReceived());
            System.Console.Error.WriteLine("\tLBT-RM datagrams dropped (size)                           : " + stats.datagramsDroppedIncorrectSize());
            System.Console.Error.WriteLine("\tLBT-RM datagrams dropped (type)                           : " + stats.datagramsDroppedType());
            System.Console.Error.WriteLine("\tLBT-RM datagrams dropped (version)                        : " + stats.datagramsDroppedVersion());
            System.Console.Error.WriteLine("\tLBT-RM datagrams dropped (header)                         : " + stats.datagramsDroppedHeader());
            System.Console.Error.WriteLine("\tLBT-RM datagrams dropped (other)                          : " + stats.datagramsDroppedOther());
            System.Console.Error.WriteLine("\tLBT-RM datagrams received out of order                    : " + stats.outOfOrder());
            break;

        case LBM.TRANSPORT_STAT_LBTRU:
            System.Console.Error.WriteLine("\tLBT-RU datagrams received                                 : " + stats.messagesReceived());
            System.Console.Error.WriteLine("\tLBT-RU datagram bytes received                            : " + stats.bytesReceived());
            System.Console.Error.WriteLine("\tLBT-RU NAK packets sent                                   : " + stats.nakPacketsSent());
            System.Console.Error.WriteLine("\tLBT-RU NAKs sent                                          : " + stats.naksSent());
            System.Console.Error.WriteLine("\tLost LBT-RU datagrams detected                            : " + stats.lost());
            System.Console.Error.WriteLine("\tNCFs received (ignored)                                   : " + stats.ncfsIgnored());
            System.Console.Error.WriteLine("\tNCFs received (shed)                                      : " + stats.ncfsShed());
            System.Console.Error.WriteLine("\tNCFs received (retransmit delay)                          : " + stats.ncfsRetransmissionDelay());
            System.Console.Error.WriteLine("\tNCFs received (unknown)                                   : " + stats.ncfsUnknown());
            System.Console.Error.WriteLine("\tLoss recovery minimum time                                : " + stats.minimumRecoveryTime() + "ms");
            System.Console.Error.WriteLine("\tLoss recovery mean time                                   : " + stats.meanRecoveryTime() + "ms");
            System.Console.Error.WriteLine("\tLoss recovery maximum time                                : " + stats.maximumRecoveryTime() + "ms");
            System.Console.Error.WriteLine("\tMinimum transmissions per individual NAK                  : " + stats.minimumNakTransmissions());
            System.Console.Error.WriteLine("\tMean transmissions per individual NAK                     : " + stats.meanNakTransmissions());
            System.Console.Error.WriteLine("\tMaximum transmissions per individual NAK                  : " + stats.maximumNakTransmissions());
            System.Console.Error.WriteLine("\tDuplicate LBT-RU datagrams received                       : " + stats.duplicateMessages());
            System.Console.Error.WriteLine("\tLBT-RU datagrams unrecoverable (window advance)           : " + stats.unrecoveredMessagesWindowAdvance());
            System.Console.Error.WriteLine("\tLBT-RU datagrams unrecoverable (NAK generation expiration): " + stats.unrecoveredMessagesNakGenerationTimeout());
            System.Console.Error.WriteLine("\tLBT-RU LBM messages received                              : " + stats.lbmMessagesReceived());
            System.Console.Error.WriteLine("\tLBT-RU LBM messages received with uninteresting topic     : " + stats.noTopicMessagesReceived());
            System.Console.Error.WriteLine("\tLBT-RU LBM requests received                              : " + stats.lbmRequestsReceived());
            System.Console.Error.WriteLine("\tLBT-RU datagrams dropped (size)                           : " + stats.datagramsDroppedIncorrectSize());
            System.Console.Error.WriteLine("\tLBT-RU datagrams dropped (type)                           : " + stats.datagramsDroppedType());
            System.Console.Error.WriteLine("\tLBT-RU datagrams dropped (version)                        : " + stats.datagramsDroppedVersion());
            System.Console.Error.WriteLine("\tLBT-RU datagrams dropped (header)                         : " + stats.datagramsDroppedHeader());
            System.Console.Error.WriteLine("\tLBT-RU datagrams dropped (SID)                            : " + stats.datagramsDroppedSID());
            System.Console.Error.WriteLine("\tLBT-RU datagrams dropped (other)                          : " + stats.datagramsDroppedOther());
            break;

        case LBM.TRANSPORT_STAT_LBTIPC:
            System.Console.Error.WriteLine("\tLBT-IPC datagrams received                                :" + stats.messagesReceived());
            System.Console.Error.WriteLine("\tLBT-IPC datagram bytes received                           :" + stats.bytesReceived());
            System.Console.Error.WriteLine("\tLBT-IPC LBM messages received                             :" + stats.lbmMessagesReceived());
            System.Console.Error.WriteLine("\tLBT-IPC LBM messages received with uninteresting topic    :" + stats.noTopicMessagesReceived());
            System.Console.Error.WriteLine("\tLBT-IPC LBM requests received                             :" + stats.lbmRequestsReceived());
            break;

        case LBM.TRANSPORT_STAT_LBTSMX:
            System.Console.Error.WriteLine("\tLBT-SMX datagrams received                                :" + stats.messagesReceived());
            System.Console.Error.WriteLine("\tLBT-SMX datagram bytes received                           :" + stats.bytesReceived());
            System.Console.Error.WriteLine("\tLBT-SMX LBM messages received                             :" + stats.lbmMessagesReceived());
            System.Console.Error.WriteLine("\tLBT-SMX LBM messages received with uninteresting topic    :" + stats.noTopicMessagesReceived());
            System.Console.Error.WriteLine("\tLBT-SMX LBM requests received                             :" + stats.lbmRequestsReceived());
            break;

        case LBM.TRANSPORT_STAT_LBTRDMA:
            System.Console.Error.WriteLine("\tLBT-RDMA datagrams received                                :" + stats.messagesReceived());
            System.Console.Error.WriteLine("\tLBT-RDMA datagram bytes received                           :" + stats.bytesReceived());
            System.Console.Error.WriteLine("\tLBT-RDMA LBM messages received                             :" + stats.lbmMessagesReceived());
            System.Console.Error.WriteLine("\tLBT-RDMA LBM messages received with uninteresting topic    :" + stats.noTopicMessagesReceived());
            System.Console.Error.WriteLine("\tLBT-RDMA LBM requests received                             :" + stats.lbmRequestsReceived());
            break;

        case LBM.TRANSPORT_STAT_BROKER:
            System.Console.Error.WriteLine("\tBROKER messages received                                  : " + stats.messagesReceived());
            System.Console.Error.WriteLine("\tBROKER message bytes received                             : " + stats.bytesReceived());
            break;

        default:
            System.Console.Error.WriteLine("Error: Unknown transport type received:" + stats.type());
            break;
        }
        _recycler.doneWithReceiverStatistics(stats);
    }
Example #8
0
        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();
            }
        }
Example #9
0
        private int print_stats()
        {
            LBMReceiverStatistics rcv_stats = null;
            LBMSourceStatistics   src_stats = null;
            string source_type = "";
            int    nstats      = 1;
            int    stat_index  = 0;

            // Get receiver stats
            try {
                rcv_stats = _rcv.getStatistics(nstats);
            } catch (LBMException ex) {
                System.Console.Error.WriteLine("Error getting receiver statistics: " + ex.Message);
                return(-1);
            }

            if (rcv_stats == null)
            {
                System.Console.Error.WriteLine("Cannot print stats, because receiver stats are null");
                return(-1);
            }

            // Get source stats
            try {
                src_stats = _src.getStatistics();
            } catch (LBMException ex) {
                System.Console.Error.WriteLine("Error getting source statistics: " + ex.Message);
                return(-1);
            }

            if (src_stats == null)
            {
                System.Console.Error.WriteLine("Cannot print stats, because source stats are null");
                return(-1);
            }

            // Print transport stats
            switch (src_stats.type(stat_index))
            {
            case LBM.TRANSPORT_STAT_TCP:
                break;

            case LBM.TRANSPORT_STAT_LBTRU:
            case LBM.TRANSPORT_STAT_LBTRM:
                if (rcv_stats.lost() != 0 || src_stats.retransmissionsSent() != 0)
                {
                    source_type = (src_stats.type() == LBM.TRANSPORT_STAT_LBTRM) ? "LBT-RM" : "LBT-RU";
                    System.Console.Out.WriteLine("The latency for this " + source_type
                                                 + " session of lbmpong might be skewed by loss");
                    System.Console.Out.WriteLine("Source loss: " + src_stats.retransmissionsSent()
                                                 + "    " + "Receiver loss: " + rcv_stats.lost());
                }
                break;

            case LBM.TRANSPORT_STAT_LBTIPC:
                break;

            case LBM.TRANSPORT_STAT_LBTSMX:
                break;

            case LBM.TRANSPORT_STAT_LBTRDMA:
                break;
            }

            src_stats.dispose();
            rcv_stats.dispose();
            System.Console.Out.Flush();
            return(0);
        }