public static int Generate(UdpTestParameters parms)
        {
            var hostName = System.Environment.MachineName + "." +
               Microsoft.Win32.Registry.LocalMachine.OpenSubKey(
                   "SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters").GetValue("Domain", "").ToString();

            IPAddress broadcast;
            if (!IPAddress.TryParse(parms.Host, out broadcast))
                broadcast = Dns.GetHostEntry(parms.Host).AddressList[0];

            Socket s = new Socket(broadcast.AddressFamily, SocketType.Dgram, ProtocolType.Udp);

            LogManager.GetCurrentClassLogger().Info("Start UDP Generation");

            for (int i = 0; i < parms.NumMessages; i++)
            {
                JObject o = new JObject
                {
                    {"Application", "udp-generator"},
                    {"Executable", "VP.Common.SvcFrm.Services.Host, Version=29.7.0.0, Culture=neutral, PublicKeyToken=null"},
                    {"RenderedMessage", "Responding to RequestSchedule message from 10.1.230.36 with Ack because: PRJ byte array is null."},
                    {"Team", "Manufacturing Software"},
                    {"RecordNumber", i},
                    {"Host", hostName},
                    {"UtcTimestamp", DateTime.UtcNow.ToString("o")},
                    {"Type", "VP.Fulfillment.Direct.Initialization.LogWrapper"},
                    {"Message", "Testgenerator udp message " + DateTime.UtcNow.ToString("o")},
                    {"Index", "logstash"}
                };

                string hashedString = "";
                foreach(var key in o)
                {
                    hashedString += key.ToString();
                }

                var source = ASCIIEncoding.ASCII.GetBytes(hashedString);
                var md5 = new MD5CryptoServiceProvider().ComputeHash(source);
                var hash = string.Concat(md5.Select(x => x.ToString("X2")));

                o["md5"] = hash;

                byte[] sendbuf = Encoding.UTF8.GetBytes(o.ToString(Formatting.None));
                IPEndPoint ep = new IPEndPoint(broadcast, parms.Port);
                s.SendTo(sendbuf, ep);

                if (i % 1000 == 0)
                    LogManager.GetCurrentClassLogger().Info("Sent {0} of {1} messages", i, parms.NumMessages);

                Thread.Sleep(parms.SleepTimeMilliseconds);
            }

            LogManager.GetCurrentClassLogger().Info("Finished UDP Generation");

            return parms.NumMessages;
        }
Esempio n. 2
0
        static void StartUdp(CommandLineOptions options)
        {
            if (options.Udp > 0)
            {
                if (options.Verbose)
                {
                    LogManager.GetCurrentClassLogger()
                    .Info("Starting UDP Generator for {0}:{1}", options.UdpHost, options.Udp);
                }

                _tasks.Add(Task.Factory.StartNew(() =>
                {
                    var p = new UdpTestParameters()
                    {
                        Port                  = options.Udp,
                        Host                  = options.UdpHost,
                        NumMessages           = options.NumMessages,
                        SleepTimeMilliseconds = options.UdpRate
                    };
                    _totalMessagesToSend += UdpTestGenerator.Generate(p);
                }));
            }
        }
Esempio n. 3
0
        public static int Generate(UdpTestParameters parms)
        {
            var hostName = System.Environment.MachineName + "." +
                           Microsoft.Win32.Registry.LocalMachine.OpenSubKey(
                "SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters").GetValue("Domain", "").ToString();

            IPAddress broadcast;

            if (!IPAddress.TryParse(parms.Host, out broadcast))
            {
                broadcast = Dns.GetHostEntry(parms.Host).AddressList[0];
            }

            Socket s = new Socket(broadcast.AddressFamily, SocketType.Dgram, ProtocolType.Udp);

            LogManager.GetCurrentClassLogger().Info("Start UDP Generation");

            for (int i = 0; i < parms.NumMessages; i++)
            {
                JObject o = new JObject
                {
                    { "Application", "udp-generator" },
                    { "Executable", "VP.Common.SvcFrm.Services.Host, Version=29.7.0.0, Culture=neutral, PublicKeyToken=null" },
                    { "RenderedMessage", "Responding to RequestSchedule message from 10.1.230.36 with Ack because: PRJ byte array is null." },
                    { "Team", "Manufacturing Software" },
                    { "RecordNumber", i },
                    { "Host", hostName },
                    { "UtcTimestamp", DateTime.UtcNow.ToString("o") },
                    { "Type", "VP.Fulfillment.Direct.Initialization.LogWrapper" },
                    { "Message", "Testgenerator udp message " + DateTime.UtcNow.ToString("o") },
                    { "Index", "logstash" }
                };

                string hashedString = "";
                foreach (var key in o)
                {
                    hashedString += key.ToString();
                }

                var source = ASCIIEncoding.ASCII.GetBytes(hashedString);
                var md5    = new MD5CryptoServiceProvider().ComputeHash(source);
                var hash   = string.Concat(md5.Select(x => x.ToString("X2")));

                o["md5"] = hash;

                byte[]     sendbuf = Encoding.UTF8.GetBytes(o.ToString(Formatting.None));
                IPEndPoint ep      = new IPEndPoint(broadcast, parms.Port);
                s.SendTo(sendbuf, ep);

                if (i % 1000 == 0)
                {
                    LogManager.GetCurrentClassLogger().Info("Sent {0} of {1} messages", i, parms.NumMessages);
                }

                Thread.Sleep(parms.SleepTimeMilliseconds);
            }

            LogManager.GetCurrentClassLogger().Info("Finished UDP Generation");

            return(parms.NumMessages);
        }
Esempio n. 4
0
        static void StartUdp(CommandLineOptions options)
        {
            if (options.Udp > 0)
            {
                if (options.Verbose)
                    LogManager.GetCurrentClassLogger()
                        .Info("Starting UDP Generator for {0}:{1}", options.UdpHost, options.Udp);

                _tasks.Add(Task.Factory.StartNew(() =>
                {
                    var p = new UdpTestParameters()
                    {
                        Port = options.Udp,
                        Host = options.UdpHost,
                        NumMessages = options.NumMessages,
                        SleepTimeMilliseconds = options.UdpRate
                    };
                    _totalMessagesToSend += UdpTestGenerator.Generate(p);
                }));
            }
        }