Esempio n. 1
0
        public static int Main(string[] args)
        {
            lbmlatpong latpong = null;

            LBMContext           ctx      = null;
            LBMContextAttributes ctx_attr = null;

            LBMTopic            pong_src_topic      = null;
            LBMSourceAttributes pong_src_topic_attr = null;
            LBMSource           pong_src            = null;

            LBMTopic ping_rcv_topic = null;
            LBMReceiverAttributes ping_rcv_topic_attr = null;
            lbmlatpongreceiver    ping_rcv            = null;

            latpong = new lbmlatpong(args);
            if (latpong.cpu >= 0)
            {
                Process.GetCurrentProcess().ProcessorAffinity = new IntPtr(latpong.cpu);
            }

            /* Create the context. */
            ctx_attr = new LBMContextAttributes();
            ctx_attr.setValue("resolver_cache", "0");
            ctx_attr.setValue("operational_mode", "sequential");
            ctx_attr.setValue("request_tcp_port_high", "50000");
            ctx_attr.setValue("transport_lbtipc_receiver_thread_behavior", "busy_wait");
            ctx = new LBMContext(ctx_attr);
            ctx_attr.dispose();

            /* Create the pong source. */
            pong_src_topic_attr = new LBMSourceAttributes();
            pong_src_topic_attr.setValue("resolver_advertisement_sustain_interval", "0");
            pong_src_topic_attr.setValue("transport", "lbtsmx");
            pong_src_topic = new LBMTopic(ctx, "lbmlat-pong", pong_src_topic_attr);
            pong_src_topic_attr.dispose();
            pong_src         = new LBMSource(ctx, pong_src_topic);
            latpong.pong_src = pong_src;

            /* Create the ping receiver. */
            ping_rcv_topic_attr = new LBMReceiverAttributes();
            ping_rcv_topic_attr.enableSingleReceiverCallback(true);
            ping_rcv_topic_attr.setSourceNotificationCallbacks(
                new LBMSourceCreationCallback(latpong.onNewSource),
                new LBMSourceDeletionCallback(latpong.onSourceDelete),
                null);
            ping_rcv_topic = new LBMTopic(ctx, "lbmlat-ping", ping_rcv_topic_attr);
            ping_rcv_topic_attr.dispose();
            ping_rcv = new lbmlatpongreceiver(ctx, ping_rcv_topic, latpong, pong_src);

            /* Wait a bit for things to get set up. */
            System.Threading.Thread.Sleep(1000);

            /* Run the context until we've discovered the pinger's source. */
            while (!latpong.found_pinger)
            {
                ctx.processEvents(1000);
            }

            /* Wait a bit for things to get set up. */
            System.Threading.Thread.Sleep(1000);

            /* Send in a dummy pong message to kick things off. */
            IntPtr writeBuff;

            if (pong_src.buffAcquire(out writeBuff, (uint)16, 0) == 0)
            {
                Marshal.WriteInt64(writeBuff, 0, 1234567890);
                pong_src.buffsComplete();
            }

            /* Wait forever. */
            while (true)
            {
                System.Threading.Thread.Sleep(1000000);
                // ctx.processEvents(1000000);
            }
        }
Esempio n. 2
0
        void Run(string[] args)
        {
            string cfgFile = "application.cfg";
            string test    = "1";

            if (args.Length == 2)
            {
                cfgFile = args[0];
                test    = args[1];
            }
            else if (args.Length == 1)
            {
                cfgFile = args[0];
            }
            else if (args.Length != 0)
            {
                throw new TmonException("TmonExample: bad arg count (" + args.Length + ")");
            }

            LBM lbm = new LBM();

            lbm.setLogger(this.Logger);

            _timeOfDay = new TmonGetTimeOfDay();

            LBM.setConfiguration(cfgFile);

            MyLog("Creating context.");
            // Context name must be alpha, numeric, underscore, hyphen.
            LBMContextAttributes ctxAttr = new LBMContextAttributes("tmon_example_ctx");
            LBMContext           ctx     = new LBMContext(ctxAttr);

            MyLog("Creating topic monitor.");
            TmonContext tmonContext = new TmonContext(ctx);

            tmonContext.InitSender(); // I.e. this tmon context is for sending reports.

            MyLog("Creating wildcard rcv for '^.*2$' (will resolv, no msg)");
            TmonReceiver          tmonWRcv = tmonContext.ReceiverCreate(ReceiverType.Wildcard, "^.*2$");
            LBMReceiverAttributes rcvAttr  = new LBMReceiverAttributes("29west_tmon_context", "wc2");

            rcvAttr.setSourceNotificationCallbacks(this.OnDeliveryControllerCreate,
                                                   this.OnDeliveryControllerDelete, tmonWRcv);
            LBMWildcardReceiver wrcv = new LBMWildcardReceiver(ctx, "^.*2$", rcvAttr,
                                                               null, this.OnReceive, null);

            MyLog("Creating rcv for 'src\\1' (will resolv, rcv msg)");
            TmonReceiver tmonRcv1 = tmonContext.ReceiverCreate(ReceiverType.Regular, "src\\1");

            rcvAttr = new LBMReceiverAttributes("29west_tmon_context", "src\\1");
            rcvAttr.setSourceNotificationCallbacks(this.OnDeliveryControllerCreate,
                                                   this.OnDeliveryControllerDelete, tmonRcv1);
            LBMReceiver rcv1 = new LBMReceiver(ctx, ctx.lookupTopic("src\\1", rcvAttr),
                                               this.OnReceive, null, null);

            MyLog("Creating rcv for 'src3' (will resolve, no msg)");
            TmonReceiver tmonRcv3 = tmonContext.ReceiverCreate(ReceiverType.Regular, "src3");

            rcvAttr = new LBMReceiverAttributes("29west_tmon_context", "src3");
            rcvAttr.setSourceNotificationCallbacks(this.OnDeliveryControllerCreate,
                                                   this.OnDeliveryControllerDelete, tmonRcv3);
            LBMReceiver rcv3 = new LBMReceiver(ctx, ctx.lookupTopic("src3", rcvAttr),
                                               this.OnReceive, null, null);

            MyLog("Creating rcv for 'srcx' (will not resolve)");
            TmonReceiver tmonRcvx = tmonContext.ReceiverCreate(ReceiverType.Regular, "srcx");

            rcvAttr = new LBMReceiverAttributes("29west_tmon_context", "srcx");
            rcvAttr.setSourceNotificationCallbacks(this.OnDeliveryControllerCreate,
                                                   this.OnDeliveryControllerDelete, tmonRcvx);
            LBMReceiver rcvx = new LBMReceiver(ctx, ctx.lookupTopic("srcx", rcvAttr),
                                               this.OnReceive, null, null);

            MyLog("Creating src for 'src\\1' (will resolve, send msg)");
            TmonSource          tmonSrc1 = tmonContext.SourceCreate("src\\1");
            LBMSourceAttributes srcAttr  = new LBMSourceAttributes("29west_tmon_context", "src\\1");
            LBMSource           src1     = ctx.createSource(ctx.allocTopic("src\\1", srcAttr));

            Thread.Sleep(100); // Let receiver discover.

            MyLog("Creating src for 'src,2' (wildcard resolve, no msg)");
            TmonSource tmonSrc2 = tmonContext.SourceCreate("src,2");

            srcAttr = new LBMSourceAttributes("29west_tmon_context", "src,2");
            LBMSource src2 = ctx.createSource(ctx.allocTopic("src,2", srcAttr));

            Thread.Sleep(100); // Let receiver discover.

            MyLog("Creating src for 'src3' (will resolve, no msg)");
            TmonSource tmonSrc3 = tmonContext.SourceCreate("src3");

            srcAttr = new LBMSourceAttributes("29west_tmon_context", "src3");
            LBMSource src3 = ctx.createSource(ctx.allocTopic("src3", srcAttr));

            Thread.Sleep(100); // Let receiver discover.

            MyLog("Delete receiver for 'src,2' to get DC delete without BOS or EOS");
            wrcv.close();
            tmonWRcv.Close();

            MyLog("Sleeping 6 for BOS triggered by TSNI for 'src\\1', 'src3'");
            Thread.Sleep(6000);

            MyLog("Deleting rcv for 'src3' while src still up - should get DC delete without EOS");
            rcv3.close();
            tmonRcv3.Close();

            string msg = "Hello!";

            if (test.Equals("1"))
            {
                MyLog("Sending to 'src\\1'");
                src1.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0);

                MyLog("Wait for msg receive or EOS");
                while (_messagesReceived == 0)
                {
                    Thread.Sleep(1000);
                }
            }
            else if (test.Equals("2"))
            {
                MyLog("Sending 120 msgs to 'src\\1'");
                for (int i = 0; i < 120; i++)
                {
                    src1.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0);
                } // for
                MyLog("lingering 10 sec");
                Thread.Sleep(10000);
            }
            else
            {
                throw new TmonException("TmonExample: bad test number (" + test + ")");
            }

            MyLog("Delete sources");
            src1.close();
            tmonSrc1.Close();
            src2.close();
            tmonSrc2.Close();
            src3.close();
            tmonSrc3.Close();

            MyLog("Sleeping 6 sec for EOS and DC delete for 'src\\1'.");
            Thread.Sleep(6000);

            MyLog("Deleting rcvs for 'src\\1'");
            rcv1.close();
            tmonRcv1.Close();

            MyLog("Generate rolling EOS on srcx");
            LBM.setLbtrmSrcLossRate(100);
            TmonSource tmonSrcx = tmonContext.SourceCreate("srcx");

            srcAttr = new LBMSourceAttributes("29west_tmon_context", "srcx");
            LBMSource srcx = ctx.createSource(ctx.allocTopic("srcx", srcAttr));

            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Start SMs going.
            Thread.Sleep(13750);                                    // Wait 2.5 * RM activity timeouts.

            MyLog("Generate BOS on srcx and msg");
            LBM.setLbtrmSrcLossRate(0);
            msg = "1";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Trigger BOS.
            Thread.Sleep(100);

            MyLog("Generate unrecoverable loss on srcx");
            LBM.setLbtrmSrcLossRate(100);
            msg = "2";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Lost pkt.
            Thread.Sleep(100);
            LBM.setLbtrmSrcLossRate(0);
            msg = "3";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // gap.
            Thread.Sleep(200);                                      // 2*nak gen ivl.
            msg = "4";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // push out loss event.
            Thread.Sleep(100);

            MyLog("Generate suppressed unrecoverable loss");
            LBM.setLbtrmSrcLossRate(0);
            msg = "1";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Trigger BOS.
            Thread.Sleep(100);
            LBM.setLbtrmSrcLossRate(100);
            msg = "2";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Lost pkt.
            Thread.Sleep(100);
            LBM.setLbtrmSrcLossRate(0);
            msg = "3";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // gap.
            Thread.Sleep(200);                                      // 2*nak gen ivl.
            msg = "4";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // push out loss event.
            Thread.Sleep(100);

            Thread.Sleep(10100); // Expire tmon's 10-second loss suppression.

            MyLog("Generate unrecoverable burst loss");
            LBM.setLbtrmSrcLossRate(100);
            msg = "5";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Lost pkt.
            msg = "6";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Lost pkt.
            msg = "7";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Lost pkt.
            msg = "8";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // Lost pkt.
            Thread.Sleep(100);
            LBM.setLbtrmSrcLossRate(0);
            msg = "9";
            srcx.send(Encoding.ASCII.GetBytes(msg), msg.Length, 0); // gap.
            Thread.Sleep(200);                                      // Wait for BURST.

            MyLog("Delete rcvx, srcx.");
            rcvx.close();
            tmonRcvx.Close();
            srcx.close();
            tmonSrcx.Close();

            MyLog("Deleting tmon_ctx.");
            tmonContext.Close();

            MyLog("Deleting context.");
            ctx.close();
        } // Run