예제 #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);
                }
            }
        }
예제 #2
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);
        }