Exemple #1
0
        public void TestSolvingGeq()
        {
            foreach (var backend in new List <Backend>()
            {
                Backend.Z3, Backend.DecisionDiagrams
            })
            {
                var f      = new ZenFunction <Int5, Int5, bool>((x, y) => x >= y);
                var inputs = f.FindAll((x, y, z) => z).Take(5);

                foreach (var input in inputs)
                {
                    Assert.AreEqual(true, input.Item1 >= input.Item2);
                }
            }
        }
Exemple #2
0
        public void TestSolvingBitwiseXor()
        {
            foreach (var backend in new List <Backend>()
            {
                Backend.Z3, Backend.DecisionDiagrams
            })
            {
                var f      = new ZenFunction <Int5, Int5, Int5>((x, y) => x ^ y);
                var inputs = f.FindAll((x, y, z) => z == new Int5(4)).Take(5);

                foreach (var input in inputs)
                {
                    Assert.AreEqual(new Int5(4), input.Item1.BitwiseXor(input.Item2));
                }
            }
        }
Exemple #3
0
        static void findLinks(DVP dvp, bool desired_result, SimplePacket packet)
        {
            Console.WriteLine("findLinks");

            ZenFunction <SimplePacket, IList <Tuple <int, int> >, bool> f = Function <SimplePacket, IList <Tuple <int, int> >, bool>(dvp.Forward);

            f.Compile();

            // Console.WriteLine("Using FindAll");
            // Console.WriteLine("Number of packets that cannot be delivered in the network:");
            var input = f.FindAll((pkt, failed_links, result) => And(
                                      And(
                                          And(
                                              And(
                                                  pkt.GetDstIp().GetField <Ip, uint>("Value") == packet.DstIp.Value,
                                                  pkt.GetSrcIp().GetField <Ip, uint>("Value") == packet.SrcIp.Value
                                                  ),
                                              pkt.GetDstIp() != pkt.GetSrcIp()),
                                          result == desired_result),
                                      // For DVP, no route requires more then two links to fail (no multiple path routing)
                                      // Therefore, we limit length to 1 here
                                      failed_links.Length() == 1));

            Console.WriteLine("\tCount:\t" + input.Count());
            //Console.WriteLine();
            //Console.WriteLine(input);

            if (input.Count() != 0)
            {
                Console.WriteLine("\tPrinting inputs:");
                foreach (var x in input)
                {
                    Console.Write("\t\t" + x.Item1 + " with List [");
                    foreach (var i in x.Item2)
                    {
                        Console.Write(i + ", ");
                    }
                    Console.WriteLine("]");
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Given an Acl ruleset and a stragey, computes and finds any possible solutions.
        /// </summary>
        /// <param name="ruleSet">The Acl ruleset to verify.</param>
        /// <param name="strategy">The Strategy representing the test invariant.</param>
        /// <returns>A list of solution (if any) that satisfy the provided strategy.</returns>
        public Task <IEnumerable <Packet> > FindSolutions(Acl ruleSet, Strategy strategy)
        {
            // Create Zen func and run input evaluation
            Stopwatch sw = new Stopwatch();
            ZenFunction <Packet, bool> func = Function <Packet, bool>(p => ruleSet.Allowed(p));

            _logger.Write("Starting model evaluation");
            _logger.Write($"Using the \"{strategy.Name}\" strategy");

            sw.Start();

            IEnumerable <Packet> solutions = func.FindAll(strategy.Invariant,
                                                          backend: ZenLib.ModelChecking.Backend.Z3)
                                             .Take(_config.MaxReportedResults)
                                             .ToList(); // Force evaluation

            sw.Stop();

            _logger.Write($"Model evaluation finished ({sw.ElapsedMilliseconds} msec)");
            return(Task.FromResult(solutions));
        }
Exemple #5
0
        static void findPackets(DVP dvp, bool desired_result, List <Tuple <int, int> > failedLinks = null)
        {
            if (failedLinks == null)
            {
                failedLinks = new List <Tuple <int, int> >();
            }

            Console.WriteLine("findPackets");

            ZenFunction <SimplePacket, IList <Tuple <int, int> >, bool> f = Function <SimplePacket, IList <Tuple <int, int> >, bool>(dvp.Forward);

            f.Compile();

            // Console.WriteLine("Using FindAll");
            // Console.WriteLine("Number of packets that cannot be delivered in the network:");
            Console.WriteLine(failedLinks);
            var input = f.FindAll((pkt, failed_links, result) => And(
                                      And(
                                          And(
                                              And(
                                                  pkt.GetDstIp().GetField <Ip, uint>("Value") < 7,
                                                  pkt.GetSrcIp().GetField <Ip, uint>("Value") < 7
                                                  ),
                                              pkt.GetDstIp() != pkt.GetSrcIp()),
                                          result == desired_result),
                                      failed_links == failedLinks));

            Console.WriteLine("\tCount:\t" + input.Count());
            //Console.WriteLine();
            //Console.WriteLine(input);

            if (input.Count() != 0)
            {
                Console.WriteLine("\tPrinting inputs:");
                foreach (var x in input)
                {
                    Console.WriteLine("\t\t" + x);
                }
            }
        }