Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // Create the tries
            var binaryRoot     = new BinaryNode("Root");
            var compressedRoot = new CompressedNode("Root");
            var multibitRoot   = new MultibitNode()
            {
                Stride = 3
            };

            // Generate IPs
            var gen = new AddressGenerator().GenerateAddress();
            var db  = gen.Take(10).ToArray();

            // Add children to tries
            foreach (var ip in db)
            {
                binaryRoot.AddChild(ip.MaskedIPv4, ip.BinaryString);
                compressedRoot.AddChild(ip.MaskedIPv4, ip.BinaryString);
                multibitRoot.AddChild(ip.MaskedIPv4, ip.BinaryString);
            }
            compressedRoot.Compress();

            // Perform a lookup
            var tosearch = new Address("132.15.162.33/17");

            Console.WriteLine($"Binary: {binaryRoot.Lookup(tosearch.BinaryString)}");
            Console.WriteLine($"Compressed: {compressedRoot.Lookup(tosearch.BinaryString)}");
            Console.WriteLine($"Multibit: {multibitRoot.Lookup(tosearch.BinaryString, "Root")}");

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        public static void CreateDatabase(IEnumerable <Address> ips)
        {
            BinaryRoot = new BinaryNode()
            {
                NextHop = "Root"
            };
            CompressedRoot = new CompressedNode()
            {
                NextHop = "Root"
            };
            MultibitRoot = new MultibitNode()
            {
                Stride = MultibitStride
            };

            foreach (var ip in ips)
            {
                BinaryRoot.AddChild(ip.MaskedIPv4, ip.BinaryString);
                CompressedRoot.AddChild(ip.MaskedIPv4, ip.BinaryString);
                MultibitRoot.AddChild(ip.MaskedIPv4, ip.BinaryString);
            }

            CompressedRoot.Compress();

            Main.UpdateTreeViews();
        }