public void TestRemoveAll(string s, char c, string expected) { var f = new ZenFunction <FiniteString, FiniteString>(fs => fs.RemoveAll(c)); var actual = f.Evaluate(s).ToString(); Assert.AreEqual(expected, actual); }
public void TestConcat(string s1, string s2, string expected) { var f = new ZenFunction <FiniteString, FiniteString>(fs => fs.Concat(new FiniteString(s2))); var actual = f.Evaluate(s1).ToString(); Assert.AreEqual(expected, actual); }
public void TestAt(string s, int idx, string expected) { var f = new ZenFunction <FiniteString, FiniteString>(fs => fs.At((ushort)idx)); var actual = f.Evaluate(s).ToString(); Assert.AreEqual(expected, actual); }
public void TestSubstring(string s, int offset, int len, string expected) { var f = new ZenFunction <FiniteString, FiniteString>(fs => fs.SubString((ushort)offset, (ushort)len)); var actual = f.Evaluate(s).ToString(); Assert.AreEqual(expected, actual); }
public void TestServiceMesh() { var network = ExampleNetwork(); var d1 = network.Devices["R1"]; var d2 = network.Devices["R2"]; var d3 = network.Devices["R3"]; // encoding along a single path approach var f = new ZenFunction <Packet, bool>(p => { var pencap = d1.Interfaces[0].Encapsulate(p); var fwd1 = d1.Table.Forward(pencap, 0) == 1; var fwd2 = d2.Table.Forward(pencap, 0) == 2; var pdecap = d3.Interfaces[0].Decapsulate(pencap); var acl = d3.Interfaces[0].InboundAcl.Process(pdecap.GetOverlayHeader(), 0); return(And(fwd1, fwd2, acl)); }); // build transformers var tfwd1 = new ZenFunction <Packet, bool>(p => d1.Table.Forward(p, 0) == 1).Transformer(); var tfwd2 = new ZenFunction <Packet, bool>(p => d2.Table.Forward(p, 0) == 2).Transformer(); var tencap = new ZenFunction <Packet, Packet>(d1.Interfaces[0].Encapsulate).Transformer(); var tdecap = new ZenFunction <Packet, Packet>(d3.Interfaces[0].Decapsulate).Transformer(); var tacl = new ZenFunction <Packet, bool>(p => d3.Interfaces[0].InboundAcl.Process(p.GetOverlayHeader(), 0)).Transformer(); }
/// <summary> /// Check that a field is set correctly. /// </summary> /// <typeparam name="T">The object type.</typeparam> /// <param name="field">The field name.</param> private void CheckWithIsSet <T>(string field) { var f = new ZenFunction <T, T>(o => o.WithField(field, Constant(1))); var r = f.Find((i, o) => o.GetField <T, int>(field) == Constant(0)); Assert.IsFalse(r.HasValue); }
public void VerifyAclProvenance() { var f = new ZenFunction <IpHeader, Pair <bool, ushort> >(h => this.acl.ProcessProvenance(h)); var packet = f.Find((p, o) => o.Item2() == (ushort)(this.acl.Lines.Length + 1), backend: this.Backend); f.Evaluate(packet.Value); }
public void TestNegatives() { var f = new ZenFunction <short, bool>(x => - 2 > -1); var result = f.Find((i, o) => o, backend: Backend.DecisionDiagrams); Assert.IsFalse(result.HasValue); }
public void TestTransformerSetIsEmpty() { var t = new ZenFunction <bool, bool>(b => true).Transformer(); var set = t.InputSet().Complement(); Assert.IsTrue(set.IsEmpty()); }
public void TestTransformerFixedWidthInteger() { var t = new ZenFunction <Int5, bool>(i => i <= new Int5(0)).Transformer(); var set = t.InputSet((x, y) => y); Assert.IsTrue(set.Element() <= new Int5(0)); }
public void TestConstructingOptions() { var f = new ZenFunction <Option <Int5>, Option <Int5> >(x => Null <Int5>()); var input = f.Find((x, y) => true); Assert.IsTrue(input.HasValue); }
public void TestSymbolicExecutionAcl() { var random = new Random(1); var lines = new List <AclLine>(); bool parity = false; for (int i = 0; i < 19; i++) { parity = !parity; var dlow = (uint)random.Next(); var dhigh = (uint)random.Next((int)dlow, int.MaxValue); var slow = (uint)random.Next(); var shigh = (uint)random.Next((int)slow, int.MaxValue); var line = new AclLine { DstIp = Prefix.Random(24, 32), SrcIp = Prefix.Random(24, 32), Permitted = parity, }; Console.WriteLine($"{line.DstIp}, {line.SrcIp}, {line.Permitted}"); lines.Add(line); } var acl = new Acl { Lines = lines.ToArray() }; var function = new ZenFunction <IpHeader, bool>(p => acl.Process(p, 0)); Assert.AreEqual(20, function.GenerateInputs().Count()); }
public void TestSymbolicExecutionPrecondition() { var f = new ZenFunction <IList <byte>, bool>(l => l.IsSorted()); var f1 = new ZenFunction <IList <byte>, bool>(l1 => l1.Contains(2)); Assert.IsTrue(f1.GenerateInputs(precondition: l => l.IsSorted()).All(i => f.Evaluate(i))); }
public void TestSymbolicExecutionPacketAcl() { var p1 = new Prefix { Length = 24, Address = Ip.Parse("72.1.2.0").Value }; var p2 = new Prefix { Length = 24, Address = Ip.Parse("1.2.3.0").Value }; var p3 = new Prefix { Length = 32, Address = Ip.Parse("8.8.8.8").Value }; var p4 = new Prefix { Length = 32, Address = Ip.Parse("9.9.9.9").Value }; var aclLine1 = new AclLine { DstIp = p1, SrcIp = p2, Permitted = true }; var aclLine2 = new AclLine { DstIp = p3, SrcIp = p4, Permitted = true }; var lines = new AclLine[2] { aclLine1, aclLine2 }; var acl = new Acl { Lines = lines }; var f = new ZenFunction <IpHeader, bool>(h => acl.Process(h, 0)); Assert.AreEqual(3, f.GenerateInputs().Count()); }
public void TestLength(string s, int expected) { var f = new ZenFunction <FiniteString, ushort>(fs => fs.Length()); var actual = f.Evaluate(s); Assert.AreEqual(expected, (int)actual); }
static void oneHopReachability(DVP dvp) { // 1. Evaluate Ip srcAddr = new Ip { Value = 1 }; Ip dstAddr = new Ip { Value = 2 }; ZenFunction <Ip, Ip, bool> f = Function <Ip, Ip, bool>(dvp.OneHopForward); var output = f.Evaluate(srcAddr, dstAddr); Console.WriteLine(output); // 2. Find var input = f.Find((src, dst, result) => And(And(And(src.GetField <Ip, uint>("Value") < 7, dst.GetField <Ip, uint>("Value") < 7), result == False()), src != dst)); Console.WriteLine("Using powerful Zen Find!!!"); Console.WriteLine(input); Console.WriteLine("printing single value"); Console.WriteLine(input.Value); }
public void TestContains(string s, string sub, bool expected) { var f = new ZenFunction <FiniteString, bool>(fs => fs.Contains(new FiniteString(sub))); var actual = f.Evaluate(s); Assert.AreEqual(expected, actual); }
public void TestMultiplySolve() { var f = new ZenFunction <BigInteger, BigInteger, bool>((x, y) => x * y == new BigInteger(4)); var inputs = f.Find((x, y, result) => result); Assert.AreEqual(4, inputs.Value.Item1 * inputs.Value.Item2); }
public void TestSuffixOf(string s, string sub, bool expected) { var f = new ZenFunction <FiniteString, bool>(fs => Language.EndsWith(fs, new FiniteString(sub))); var actual = f.Evaluate(s); Assert.AreEqual(expected, actual); }
public void TestMatrixAdd() { var function = new ZenFunction <Matrix3x3, Matrix3x3, Matrix3x3>(Matrix3x3.Add); var input = function.Find((x, y, result) => result.GetField <Matrix3x3, int>("v22") == 10); var x = input.Value.Item1; var y = input.Value.Item2; Assert.AreEqual(x.v22 + y.v22, 10); x.v11 = 1; x.v12 = 2; x.v13 = 3; x.v21 = 4; x.v22 = 5; x.v23 = 6; x.v31 = 7; x.v32 = 8; x.v33 = 9; y.v11 = 1; y.v12 = 2; y.v13 = 3; y.v21 = 4; y.v22 = 5; y.v23 = 6; y.v31 = 7; y.v32 = 8; y.v33 = 9; Assert.AreEqual(2, function.Evaluate(x, y).v11); Assert.AreEqual(4, function.Evaluate(x, y).v12); Assert.AreEqual(6, function.Evaluate(x, y).v13); Assert.AreEqual(8, function.Evaluate(x, y).v21); Assert.AreEqual(10, function.Evaluate(x, y).v22); Assert.AreEqual(12, function.Evaluate(x, y).v23); Assert.AreEqual(14, function.Evaluate(x, y).v31); Assert.AreEqual(16, function.Evaluate(x, y).v32); Assert.AreEqual(18, function.Evaluate(x, y).v33); }
public void TestConstants(string s) { var fs = FiniteString(s); var f = new ZenFunction <FiniteString>(() => fs); Assert.IsTrue(f.Assert(x => x == fs)); }
public void TestIndexOfFind() { var f = new ZenFunction <string, BigInteger>(s => s.IndexOf("a", new BigInteger(0))); var input = f.Find((s, o) => o == new BigInteger(5)); Assert.AreEqual((short)5, f.Evaluate(input.Value)); }
public void TestAddMultipleValues() { var f1 = new ZenFunction <byte, byte, bool>((w, x) => w + x == 7); var f2 = new ZenFunction <byte, byte, byte, bool>((w, x, y) => w + x + y == 7); var f3 = new ZenFunction <byte, byte, byte, byte, bool>((w, x, y, z) => w + x + y + z == 7); var r1 = f1.Find((i1, i2, o) => o); var r2 = f2.Find((i1, i2, i3, o) => o); var r3 = f3.Find((i1, i2, i3, i4, o) => o); Assert.IsTrue(r1.HasValue); Assert.IsTrue(r2.HasValue); Assert.IsTrue(r3.HasValue); Assert.AreEqual(7, (byte)(r1.Value.Item1 + r1.Value.Item2)); Assert.AreEqual((byte)7, (byte)(r2.Value.Item1 + r2.Value.Item2 + r2.Value.Item3)); Assert.AreEqual(7, (byte)(r3.Value.Item1 + r3.Value.Item2 + r3.Value.Item3 + r3.Value.Item4)); Assert.IsTrue(f1.Evaluate(2, 5)); Assert.IsFalse(f1.Evaluate(2, 6)); Assert.IsTrue(f2.Evaluate(2, 1, 4)); Assert.IsFalse(f2.Evaluate(5, 5, 0)); Assert.IsTrue(f3.Evaluate(1, 1, 2, 3)); Assert.IsFalse(f3.Evaluate(3, 0, 1, 1)); }
public void TestConcatMultipleValues() { var f1 = new ZenFunction <string, string, bool>((w, x) => w + x == "hello"); var f2 = new ZenFunction <string, string, string, bool>((w, x, y) => w + x + y == "hello"); var f3 = new ZenFunction <string, string, string, string, bool>((w, x, y, z) => w + x + y + z == "hello"); var r1 = f1.Find((i1, i2, o) => o); var r2 = f2.Find((i1, i2, i3, o) => o); var r3 = f3.Find((i1, i2, i3, i4, o) => o); Assert.IsTrue(r1.HasValue); Assert.IsTrue(r2.HasValue); Assert.IsTrue(r3.HasValue); string s1 = r1.Value.Item1 + r1.Value.Item2; string s2 = r2.Value.Item1 + r2.Value.Item2 + r2.Value.Item3; string s3 = r3.Value.Item1 + r3.Value.Item2 + r3.Value.Item3 + r3.Value.Item4; Assert.AreEqual("hello", s1); Assert.AreEqual("hello", s2); Assert.AreEqual("hello", s3); Assert.IsTrue(f1.Evaluate("he", "llo")); Assert.IsFalse(f1.Evaluate("he", "ello")); Assert.IsTrue(f2.Evaluate("h", "e", "llo")); Assert.IsFalse(f2.Evaluate("hell", "l", "o")); Assert.IsTrue(f3.Evaluate("h", "e", "ll", "o")); Assert.IsFalse(f3.Evaluate("hel", "l", "l", "o")); }
public void TestIndexOfEvaluation(string s, string sub, int offset, int expected) { var f = new ZenFunction <string, BigInteger>(s => s.IndexOf(sub, new BigInteger(offset))); Assert.AreEqual((short)expected, f.Evaluate(s)); f.Compile(); Assert.AreEqual((short)expected, f.Evaluate(s)); }
public void TestLengthEvaluation(string s, int expected) { var f = new ZenFunction <string, BigInteger>(s => s.Length()); Assert.AreEqual(new BigInteger(expected), f.Evaluate(s)); f.Compile(); Assert.AreEqual(new BigInteger(expected), f.Evaluate(s)); }
public void TestSubstringEvaluation(string s, int offset, int length, string expected) { var f = new ZenFunction <string, string>(s => s.Substring(new BigInteger(offset), new BigInteger(length))); Assert.AreEqual(expected, f.Evaluate(s)); f.Compile(); Assert.AreEqual(expected, f.Evaluate(s)); }
public void TestReplaceEvaluation(string s, string sub, string replace, string expected) { var f = new ZenFunction <string, string>(s => s.ReplaceFirst(sub, replace)); Assert.AreEqual(expected, f.Evaluate(s)); f.Compile(); Assert.AreEqual(expected, f.Evaluate(s)); }
public void TestContainsEvaluation(string s, string sub, bool expected) { var f = new ZenFunction <string, string, bool>((s1, s2) => s1.Contains(s2)); Assert.AreEqual(expected, f.Evaluate(s, sub)); f.Compile(); Assert.AreEqual(expected, f.Evaluate(s, sub)); }
public void TestDictionaryEvaluation() { var f = new ZenFunction <Dict <int, int>, Dict <int, int> >(d => d.Add(1, 1).Add(2, 2)); var result = f.Evaluate(new Dict <int, int>()); Assert.AreEqual(result.Get(1), 1); Assert.AreEqual(result.Get(2), 2); }