Beispiel #1
0
        /// <summary>
        /// runs all simulations for a given rule
        /// </summary>
        /// <returns>simulations that failed</returns>
        public List <Simulation> Run()
        {
            var failedSimulations = new List <Simulation>();

            foreach (var node in network.GetAllWorkstations())
            {
                if (startNode == node)
                {
                    continue;
                }

                var expectedResult = rule.ExpectedResult;
                if (!endNodes.Contains(node))
                {
                    expectedResult = !expectedResult;
                }

                var sim = new Simulation(Guid.NewGuid().ToString(), startNode.Name, node.Name, expectedResult);

                var p = new Packet(startNode, node, rule.Options["TTL"], expectedResult);
                sim.AddPacketSend(p);

                var r = sim.Execute();
                if ((expectedResult && r.ErrorId != 0) || (!expectedResult && r.ErrorId == 0))
                {
                    failedSimulations.Add(sim);
                }
            }

            return(failedSimulations);
        }
Beispiel #2
0
        /// <summary>
        /// runs all simulations for a given rule
        /// </summary>
        /// <returns>simulations that failed</returns>
        public List <Simulation> Run()
        {
            var l   = Guid.NewGuid().ToString();
            var sim = new Simulation(l);
            var passedSimulations = new List <Simulation>();

            foreach (var router in endNodes)
            {
                var p = new Packet(startNode, router, rule.Options["TTL"], rule.ExpectedResult);
                sim.AddPacketSend(p);
                if (sim.Execute().ErrorId == 0)
                {
                    passedSimulations.Add(sim);
                }
                // else break;
            }

            if (passedSimulations.Count == 0)
            {
                passedSimulations.Add(new Simulation(l, startNode.Name, "NoInternetRouter", rule.ExpectedResult)); //potential BUG
            }
            else
            {
                passedSimulations.Clear();
            }

            return(passedSimulations);
        }
Beispiel #3
0
        /// <summary>
        /// Creates and executes a simulation
        /// </summary>
        /// <param name="Source">The name of the sourcenode</param>
        /// <param name="Destination">The name of the destinationnode</param>
        /// <param name="Ttl">Time-To-Life</param>
        /// <param name="ExpectedResult">The expected result</param>
        /// <param name="Broadcast">Indicates if it is a broadcast</param>
        /// <param name="Subnet">The subnetmask of the broadcast</param>
        /// <returns>The result of this simulation</returns>
        public Result CreateAndExecuteSimulation(string Source, string Destination, int Ttl = 255, bool ExpectedResult = true, bool Broadcast = false, string Subnet = "")
        {
            Simulation   sim;
            Hardwarenode start = NetworkManager.Instance.GetHardwarenodeByName(Source);

            if (Broadcast)
            {
                sim = new Simulation(Guid.NewGuid().ToString("N"), Source, "Broadcast", ExpectedResult);
                List <Workstation> allWorkstations = NetworkManager.Instance.GetHardwareNodesForSubnet(Subnet);
                foreach (Workstation w in allWorkstations)
                {
                    if (w.Name.Equals(Source))
                    {
                        continue;
                    }
                    sim.AddPacketSend(new Packet(start, w, Ttl, ExpectedResult));
                }
            }
            else
            {
                sim = new Simulation(Guid.NewGuid().ToString("N"), Source, Destination, ExpectedResult);
                Hardwarenode end = NetworkManager.Instance.GetHardwarenodeByName(Destination);
                sim.AddPacketSend(new Packet(start, end, Ttl, ExpectedResult));
            }
            var res = sim.GetAllPackets().Any() ? sim.Execute() : new Result(Result.Errors.NoPackets, Result.ResultStrings[(int)Result.Errors.NoPackets], null);

            AddSimulationToHistory(sim);
            return(res);
        }
Beispiel #4
0
        /// <summary>
        /// Starts a new simulation with the parameters of one in the history
        /// </summary>
        /// <param name="Id">The ID of the old simulation</param>
        /// <returns>The result of the simulation</returns>
        public Result RunSimulationFromHistory(string Id)
        {
            Simulation sim = null, oldSim = null;

            foreach (Simulation s in Simulations)
            {
                if (s.Id != Id)
                {
                    continue;
                }
                sim    = new Simulation(Guid.NewGuid().ToString("N"), s.Source, s.Destination, s.ExpectedResult);
                oldSim = s;
            }
            if (sim == null)
            {
                return(null);
            }
            foreach (Packet p in oldSim.PacketsSend)
            {
                sim.AddPacketSend(new Packet(p.Source, p.Destination, p.Ttl, p.ExpectedResult));
            }
            Result res = sim.Execute();

            AddSimulationToHistory(sim);
            return(res);
        }
        /// <summary>
        /// runs all simulations for a given rule
        /// </summary>
        /// <returns>simulations that failed</returns>
        public List <Simulation> Run()
        {
            var failedSimulations = new List <Simulation>();

            foreach (var endNode in endNodes)
            {
                var sim = new Simulation(Guid.NewGuid().ToString(), startNode.Name, endNode.Name, rule.ExpectedResult);
                var p   = new Packet(startNode, endNode, rule.Options["TTL"], rule.ExpectedResult);
                sim.AddPacketSend(p);

                var r = sim.Execute();
                if ((rule.ExpectedResult && r.ErrorId != 0) || (!rule.ExpectedResult && r.ErrorId == 0))
                {
                    failedSimulations.Add(sim);
                }
            }

            return(failedSimulations);
        }