Exemplo n.º 1
0
        private void Send_CSMA_CD(string TypeDataSend, string IPSource, string IPDest)
        {
            ProcessSending ps          = ProcessSends.Find(p => p.IPSource == IPSource && p.IPDest == IPDest && p.Status == "Sending");
            Computer       Com_Send    = ListComputers.Find(c => c.MAC == IPSource);
            Computer       Com_Receive = ListComputers.Find(c => c.MAC == IPDest);

            Com_Receive.RemoveData();

            PaintLine(Pens.Red, Com_Send.GetPoint, Com_Send.GetButton);
            PaintLine(Pens.Red, Com_Receive.GetPoint, Com_Receive.GetButton);
            PaintLine(Pens.Red, Com_Send.GetPoint, Com_Receive.GetPoint);
            Com_Send.GetButton.BackColor    = Color.Red;
            Com_Receive.GetButton.BackColor = Color.Red;

            DataChannel = ps.Data;
            int length = CountPacket(DataChannel);
            int size   = ConstantFrame.SizePacket;

            Soluong = length;

            bool CheckCollision = false;

            // Create frames -> send
            for (int i = 0; i < length; i++)
            {
                if (i == length - 1)
                {
                    List <byte> dataEnd = new List <byte>();
                    dataEnd.AddRange(DataChannel.GetRange(i * size, DataChannel.Count - i * size));
                    dataEnd.AddRange(Encoding.UTF8.GetBytes(ConstantFrame.EndData));
                    Send_CSMA_CD(DataSend(dataEnd, TypeDataSend, IPSource, IPDest), Com_Receive);
                }
                else
                {
                    Send_CSMA_CD(DataSend(DataChannel.GetRange(i * size, size), TypeDataSend, IPSource, IPDest), Com_Receive);
                }

                if (Collision_CSMA_CD)
                {
                    CheckCollision = true;
                    break;
                }
            }

            if (!CheckCollision)
            {
                ProcessSends.Find(p => p.IPSource == IPSource && p.IPDest == IPDest).Status = "Complete";
                //UpdateDataGridView(dgvView);

                // Remove DataChannel

                PaintLine(Pens.Black, Com_Send.GetPoint, Com_Send.GetButton);
                PaintLine(Pens.Black, Com_Receive.GetPoint, Com_Receive.GetButton);
                PaintLine(Pens.Black, Com_Send.GetPoint, Com_Receive.GetPoint);
                Com_Send.GetButton.BackColor    = Control.DefaultBackColor;
                Com_Receive.GetButton.BackColor = Control.DefaultBackColor;

                DataChannel.RemoveRange(0, DataChannel.Count);
                TestChannel = true;

                // Show
                ConverDataReceive(Com_Receive);
            }
            else
            {
                PaintLine(Pens.Yellow, Com_Send.GetPoint, Com_Send.GetButton);
                PaintLine(Pens.Black, Com_Receive.GetPoint, Com_Receive.GetButton);
                PaintLine(Pens.Black, Com_Send.GetPoint, Com_Receive.GetPoint);
                Com_Send.GetButton.BackColor    = Color.Yellow;
                Com_Receive.GetButton.BackColor = Control.DefaultBackColor;

                ProcessSends.Find(p => p.IPSource == IPSource && p.IPDest == IPDest && p.Status == "Sending").Status = "Waitting";
                TestChannel = true;

                if (Congestion_CSMA_CD == "Continue")
                {
                    Congestion_CSMA_CD = IPSource;
                    k_CD = Math.Pow(2, k_CD);

                    Thread.Sleep((int)k_CD * 10 /*ConstantFrame.MiniSlot*/);
                    CSMA_CD(TypeDataSend, IPSource, IPDest);
                }
                else // lbCongestion.Text != IPSource
                {
                    CSMA_CD(TypeDataSend, IPSource, IPDest);
                }
            }
        }
Exemplo n.º 2
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            ProcessSending process = new ProcessSending(cbComputerSend.Text, cbComputerReceive.Text, btnTypeData.Text);

            if (btnTypeData.Text == "MM")
            {
                process.Data.AddRange(Encoding.UTF8.GetBytes(txbData.Text));
            }
            else //"FF"
            {
                process.Data.AddRange(Encoding.UTF8.GetBytes(txbData.Text));
                process.Data.AddRange(FileBuffer.DataFile);
            }

            ProcessSends.Add(process);

            Computer comSend = ListComputers.Find(c => c.MAC == process.IPSource);

            comSend.GetButton.BackColor = Color.Yellow;
            PaintLine(Pens.Yellow, comSend.GetPoint, comSend.GetButton);

            switch (cbTypeCSMA.Text)
            {
            case "1 Persistent":
                Thread Thread_1Persistent = new Thread(CSMA_1Persistent);
                Thread_1Persistent.Priority     = ThreadPriority.Lowest;
                Thread_1Persistent.IsBackground = true;
                Thread_1Persistent.Start();

                //CSMA_1Persistent();
                break;

            case "P Persistent":
                Thread Thread_pPersistent = new Thread(CSMA_pPersistent);
                Thread_pPersistent.IsBackground = true;
                Thread_pPersistent.Start();

                //CSMA_pPersistent();
                break;

            case "None Persistent":
                Thread Thread_NonePersistent = new Thread(CSMA_NonePersistent);
                Thread_NonePersistent.IsBackground = true;
                Thread_NonePersistent.Start();
                break;

            case "CSMA/CD":
                Thread Thread_CSMACD = new Thread(CSMA_CD);
                Thread_CSMACD.IsBackground = true;
                Thread_CSMACD.Start();

                //CSMA_CD();
                break;

            case "CSMA/CA": break;

            default:
                break;
            }

            btnViewProcess_Click(this, new EventArgs());
        }
Exemplo n.º 3
0
        // Send frame
        private void Send(string TypeDataSend, string IPSource, string IPDest)
        {
            ProcessSending ps          = ProcessSends.Find(p => p.IPSource == IPSource && p.IPDest == IPDest && p.Status == "Sending");
            Computer       Com_Send    = ListComputers.Find(c => c.MAC == IPSource);
            Computer       Com_Receive = ListComputers.Find(c => c.MAC == IPDest);

            Com_Receive.RemoveData();

            PaintLine(Pens.Red, Com_Send.GetPoint, Com_Send.GetButton);
            PaintLine(Pens.Red, Com_Receive.GetPoint, Com_Receive.GetButton);
            PaintLine(Pens.Red, Com_Send.GetPoint, Com_Receive.GetPoint);
            Com_Send.GetButton.BackColor    = Color.Red;
            Com_Receive.GetButton.BackColor = Color.Red;

            //if (TypeDataSend == "MM")
            //{
            //    Com_Send.Data = Encoding.UTF8.GetBytes(txbData.Text).ToList();
            //}
            //if(TypeDataSend == "FF")
            //{

            //}
            DataChannel = ps.Data;
            int length = CountPacket(DataChannel);
            int size   = ConstantFrame.SizePacket;

            Soluong = length;
            // Create frames -> send
            for (int i = 0; i < length; i++)
            {
                if (i == length - 1)
                {
                    List <byte> dataEnd = new List <byte>();
                    dataEnd.AddRange(DataChannel.GetRange(i * size, DataChannel.Count - i * size));
                    dataEnd.AddRange(Encoding.UTF8.GetBytes(ConstantFrame.EndData));
                    Send(DataSend(dataEnd, TypeDataSend, IPSource, IPDest), Com_Receive);
                }
                else
                {
                    Send(DataSend(DataChannel.GetRange(i * size, size), TypeDataSend, IPSource, IPDest), Com_Receive);
                }
            }

            ProcessSends.Find(p => p.IPSource == IPSource && p.IPDest == IPDest).Status = "Complete";
            //UpdateDataGridView(dgvView);

            // Remove DataChannel
            PaintLine(Pens.Black, Com_Send.GetPoint, Com_Send.GetButton);
            PaintLine(Pens.Black, Com_Receive.GetPoint, Com_Receive.GetButton);
            PaintLine(Pens.Black, Com_Send.GetPoint, Com_Receive.GetPoint);
            Com_Send.GetButton.BackColor    = Control.DefaultBackColor;
            Com_Receive.GetButton.BackColor = Control.DefaultBackColor;

            DataChannel.RemoveRange(0, DataChannel.Count);
            TestChannel = true;



            // Show
            ConverDataReceive(Com_Receive);
        }