コード例 #1
0
        public SessionData RunSimulation(int delay, int tabIndex)
        {
            SessionData sessionData = new SessionData(tabIndex);

            sessionData.SetStartingBatteryLevels(mobileNodes);              // Save starting battery levels
            sessionData.SetNumberOfAttemptedTransmissions(messages.Count);  // Save number of attempted transmissions

            string tag = "";

            if (tabIndex == PROTOCOL_INDEX_DSR)
            {
                tag = OutputTag.TAG_DSR;
            }
            else if (tabIndex == PROTOCOL_INDEX_SADSR)
            {
                tag = OutputTag.TAG_SADSR;
            }
            else if (tabIndex == PROTOCOL_INDEX_MSADSR)
            {
                tag = OutputTag.TAG_MSADSR;
            }

            /* Send all messages */
            foreach (Message message in messages)
            {
                controller.PrintToOutputPane(OutputTag.TAG_NOTE, "Message: " + message.GetMessageID());
                if (tabIndex == PROTOCOL_INDEX_DSR)
                {
                    controller.PrintToOutputPane(OutputTag.TAG_DSR, "Running DSR Simulation.");
                    SendMessageDSR(message, sessionData, delay);
                }
                else if (tabIndex == PROTOCOL_INDEX_SADSR)
                {
                    controller.PrintToOutputPane(OutputTag.TAG_SADSR, "Running SA-DSR Simulation.");
                    SendMessageSADSR(message, sessionData, delay);
                }
                else if (tabIndex == PROTOCOL_INDEX_MSADSR)
                {
                    controller.PrintToOutputPane(OutputTag.TAG_MSADSR, "Running MSA-DSR Simulation.");
                    SendMessageMSADSR(message, sessionData, delay);
                }
            }

            sessionData.SetEndingBatteryLevels(mobileNodes); // Save ending battery levels
            sessionData.PrintResults();                      // Print collected metrics
            sessions.Add(sessionData);                       // Add collected data to recorded sessions
            controller.PrintToOutputPane(tag, sessionData.GetNumberOfAttemptedTransmissions() + " attempted transmissions.");
            controller.PrintToOutputPane(tag, sessionData.GetNumberOfSuccessfulTranmissions() + " successful transmissions.");
            controller.PrintToOutputPane(tag, "Finished Transmitting Messages.");
            controller.MarkTransferAsComplete(tabIndex);

            return(sessionData);
        }