/// <summary>
        /// Raised when the Flooder object updates one of its own properties.
        /// </summary>
        /// <param name="sender">Flooder object sending the message</param>
        /// <param name="e">Object containing name of the property that changed</param>
        void flooder_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            Flooder f        = (Flooder)sender;
            int     L2Octets = 0;

            if (UseWANFrameBwCalc)
            {
                L2Octets = SelectedWANFrameType.Size;
            }
            if (e.PropertyName == "IsRunning")
            {
                if (f.IsRunning)
                {
                    FlooderIsRunning = Visibility.Visible;
                }
                else
                {
                    FlooderIsRunning = Visibility.Hidden;
                }
            }
            if (e.PropertyName == "LatestResult")
            {
                LatestResult = new FlooderResultVM(f.LatestResult, L2Octets);
                //ComputeImmediateResult(f.LatestResult);
            }
            if (e.PropertyName == "HistoryResult")
            {
                HistoryResult = new FlooderResultVM(f.HistoryResult, L2Octets);
                //ComputeHistoricalResult(f.HistoryResult);
            }
        }
        public string Solve(string[] input)
        {
            var waitingRoom    = new Cubicle(1, 1);
            var favoriteNumber = int.Parse(input[0]);
            var maze           = new Maze(favoriteNumber);
            var flooder        = new Flooder();
            var flooded        = flooder.Flood(maze, waitingRoom, 50);

            return(flooded.Count.ToString());
        }
        public MainWindowVM()
        {
            _flooder = new Flooder();
            _flooder.PropertyChanged += flooder_PropertyChanged;
            FlooderIsRunning          = Visibility.Hidden;
            LatestResult              = null;
            HistoryResult             = null;
            Target              = "<enter hostname here>";
            PacketSizeOctets    = 1250;
            BandwidthOctets     = 125000;
            DestPort            = 7;
            TargetIP            = null;
            ReadyToRun          = false;
            TargetResolveResult = "";
            TargetPingResult    = "";
            GoCommand           = new GoCommand(() => {
                if (IsRunning)
                {
                    _flooder.Stop();
                }
                else
                {
                    _flooder.Start();
                }
                IsRunning = !IsRunning;
            }, true);
            SelectedWANFrameType = new WANFrameType("Ethernet", 26);
            UseWANFrameBwCalc    = false;

            FindMaxMTU();

            DoubleCollection BandwidthTicksBits = new DoubleCollection();

            BandwidthTicksBits.Add(1000000);
            BandwidthTicksBits.Add(1536000);
            BandwidthTicksBits.Add(1536000 * 2);
            BandwidthTicksBits.Add(5000000);
            BandwidthTicksBits.Add(1536000 * 3);
            BandwidthTicksBits.Add(1536000 * 4);
            BandwidthTicksBits.Add(10000000);
            BandwidthTicksBits.Add(20000000);
            BandwidthTicksBits.Add(50000000);
            BandwidthTicksBits.Add(100000000);
            BandwidthTicksBits.Add(200000000);
            BandwidthTicksBits.Add(500000000);
            BandwidthTicksBits.Add(1000000000);

            /* The below math formula causes the following to happen on the slider control:
             *   From 0 to 1 megabit/sec (1000000 bits/sec), the scale is linear.
             *   From 1 megabit/sec to 1 gigabit/sec, the scale is logarithmic.
             * The formula first converts the above numbers from bits/sec to octets/sec.
             * Then it takes the Log base 10 of that octets/sec number.
             * Finally, it aligns the start of the log scale with the linear scale, by subtracting Log base 10 of 1 megabit/sec (125,000 octets/sec), minus 1.
             */

            BandwidthTicks = new DoubleCollection(BandwidthTicksBits.Select(x => { return(Math.Log10(x / 8) - (Math.Log10(125000) - 1)); }));

            PacketSizeTicks = new DoubleCollection();
            PacketSizeTicks.Add(64);
            PacketSizeTicks.Add(576);
            PacketSizeTicks.Add(1250);
            PacketSizeTicks.Add(1500);
            PacketSizeTicks.Add(9000);
        }
Example #4
0
	public static void Main(String[] args) {
		String user = "******";
		int numMessages = 10000;
		int numBytes = 1000;
		String address = null;
		int port = 0;
		bool readOnly = false;
		bool writeOnly = false;
		
		for(int i = 0 ; i < args.Length ; i++) {
			// Check for user.
			//////////////////
			if((args[i].CompareTo("-u") == 0) && (args.Length > (i + 1))) {
				// Set user.
				////////////
				i++;
				user = args[i];
			}
				// Check for numMessages.
				/////////////////////////
			else if((args[i].CompareTo("-m") == 0) && (args.Length > (i + 1))) {
				// Set numMessages.
				///////////////////
				i++;
				numMessages = int.Parse(args[i]);
			}
				// Check for numBytes.
				//////////////////////
			else if((args[i].CompareTo("-b") == 0) && (args.Length > (i + 1))) {
				// Set numBytes.
				////////////////
				i++;
				numBytes = int.Parse(args[i]);
			}
				// Check for address.
				/////////////////////
			else if((args[i].CompareTo("-s") == 0) && (args.Length > (i + 1))) {
				// Set address.
				///////////////
				i++;
				address = args[i];
			}
				// Check for port.
				//////////////////
			else if((args[i].CompareTo("-p") == 0) && (args.Length > (i + 1))) {
				// Set port.
				////////////
				i++;
				port = int.Parse(args[i]);
			}
				// Check for readOnly.
				//////////////////////
			else if(args[i].CompareTo("-ro") == 0) {
				// Set readOnly.
				////////////////
				readOnly = true;
				writeOnly = false;
			}
				// Check for writeOnly.
				///////////////////////
			else if(args[i].CompareTo("-wo") == 0) {
				// Set writeOnly.
				/////////////////
				writeOnly = true;
				readOnly = false;
			}
			else {
				Console.Write("Usage: flooder\n" + 
						   "\t[-u <user name>]     : unique user name\n" + 
						   "\t[-m <num messages>]  : number of messages\n" + 
						   "\t[-b <num bytes>]     : number of bytes per message\n" + 
						   "\t[-s <address>]       : the name or IP for the daemon\n" + 
						   "\t[-p <port>]          : the port for the daemon\n" + 
						   "\t[-ro]                : read  only (no multicast)\n" + 
						   "\t[-wo]                : write only (no receive)\n");
				Environment.Exit(0);
			}
		}
		
		Flooder f = new Flooder(user, numMessages, numBytes, address, port, readOnly, writeOnly);
	}
        //private bool StartFlooder(IPAddress ipAddress, int portNo, int timeInterval)
        //private bool StartFlooder(IPAddress sourceIpAddress, int sourcePortNo, IPAddress destIpAddress, int destPortNo, int timeInterval)
        //private bool StartFlooder(IPAddress connectionIpAddress, int connectionPortNo, string sourceIpAddress, int sourcePortNumber, string destIpAddress, int destPortNumber, int timeInterval)
        //private bool OpenFlooderConnection(bool isStarting, IPAddress connectionIpAddress, int connectionPortNo, string sourceIpAddress, int sourcePortNumber, string destIpAddress, int destPortNumber, int timeInterval)
        private bool OpenFlooderConnection(bool isStarting, Flooder flooder, int timeInterval)
        {
            bool success = false;

            // Data buffer for incoming data.
            byte[] bytes = new byte[1024];

            // Create a TCP socket
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            // Connect to a remote flooder
            try
            {
                //IPEndPoint remoteEP = new IPEndPoint(ipAddress, portNo);
                IPEndPoint remoteEP = new IPEndPoint(flooder.ConnectionIpAddress, flooder.ConnectionPortNumber);

                //// Create a TCP/IP  socket.
                //Socket s = new Socket(AddressFamily.InterNetwork,
                //SocketType.Stream, ProtocolType.Tcp);

                s.Connect(remoteEP);

                //string strSocketMessage = "";

                // Get the demographic data

                //strSocketMessage = "Socket connected to GTC:" + s.RemoteEndPoint.ToString() + "\r\n";

                //strRtbMessage = strRtbMessage + strSocketMessage + "\r\n";
                //rtbMessages.Text = strRtbMessage;
                //rtbMessages.Refresh();

                string response = string.Empty;

                // Send message to flooder with time increment to run
                string msgStart = string.Empty;
                string msgStartFile = string.Empty;
                //string msgRunTime = timeInterval.ToString();
                string msgEnd = "end";

                if (isStarting)
                {
                    msgStart = "start";

                    // Construct the 'start' file string
                    msgStartFile = flooder.SourceIpAddress + "|" + flooder.DestinationIpAddress + "|" + flooder.SourcePortNumber.ToString() + "|" + flooder.ConnectionPortNumber.ToString() + "|" + timeInterval.ToString() + "|" + "\\0";
                }
                else
                {
                    msgStart = "stop";
                }

                // Encode the data string into a byte array.
                byte[] msg = Encoding.ASCII.GetBytes(msgStart + "\r\n");

                // Send the data through the socket.
                int bytesSent = s.Send(msg);
                int bytesRecvd = s.Receive(bytes);
                response = Encoding.ASCII.GetString(bytes, 0, bytesRecvd);
                if(response.Trim().Substring(0,12) == "ACK-Received")
                {
                    success = true;
                }
                else
                {
                    MessageBox.Show("Error sending message - start token not acknowledged", "Send Start Token", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return false;
                }

                if (isStarting)
                {
                    //msg = Encoding.ASCII.GetBytes(msgRunTime + "\r\n");
                    msg = Encoding.ASCII.GetBytes(msgStartFile + "\r\n");
                    bytesSent = s.Send(msg);
                    bytesRecvd = s.Receive(bytes);
                    response = Encoding.ASCII.GetString(bytes, 0, bytesRecvd);
                    if (response.Trim().Substring(0, 12) == "ACK-Received")
                    {
                        success = true;
                    }
                    else
                    {
                        MessageBox.Show("Error sending message - start file not acknowledged", "Send Start File", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return false;
                    }
                }

                msg = Encoding.ASCII.GetBytes(msgEnd + "\r\n");
                bytesSent = s.Send(msg);
                bytesRecvd = s.Receive(bytes);
                response = Encoding.ASCII.GetString(bytes, 0, bytesRecvd);
                if (response.Trim().Substring(0, 12) == "ACK-Received")
                {
                    success = true;
                }
                else
                {
                    MessageBox.Show("Error sending message - end token not acknowledged", "Send End Token", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return false;
                }

                //// Receive the response from the remote device.
                //bytesRecvd = s.Receive(bytes);
                //response = Encoding.ASCII.GetString(bytes, 0, bytesRecvd);

                //strSocketMessage = "Sending BKARR (CLOSE) message..." + "\r\n" + "\r\n" +
                //                   "GTC Acknowledgement: " + "\r\n" + Encoding.ASCII.GetString(bytes, 0, bytesRec);

                //strRtbMessage = strRtbMessage + strSocketMessage;
                //rtbMessages.Text = strRtbMessage;
                //rtbMessages.Refresh();

                return success;

            }
            catch (ArgumentNullException ane)
            {
                MessageBox.Show("ArgumentNullException for " + flooder.SourceIpAddress.ToString() + ": " + ane.ToString(),
                    "Argument Null Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            catch (SocketException se)
            {
                MessageBox.Show("SocketException for " + flooder.SourceIpAddress.ToString() + ": " + se.ToString(),
                    "Socket Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unexpected exception for " + flooder.SourceIpAddress.ToString() + ": " + ex.ToString(),
                    "Socket Connection - General Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }

            finally
            {
                // Release the socket.
                if (s.Connected == true)
                    s.Shutdown(SocketShutdown.Both);
                s.Close();
            }
        }