示例#1
0
        public void AddLink(string ip1, string ip2)
        {
            NetworkNode selected1 = FindNode(ip1);
            NetworkNode selected2 = FindNode(ip2);

            if (selected1 == null || selected2 == null)
            {
                Console.WriteLine("One or both routers are not found!");
                return;
            }
            Edge e = new Edge(selected1, selected2);

            selected1.AddEdge(e);
            selected2.AddEdge(e);
            Console.WriteLine("Link added!");
        }
示例#2
0
        public void Generate(int Networks)
        {
            if (Networks <= 1)
            {
                throw new ArgumentException("Cannot create a network with less than two networks!");
            }

            NetworkNodes.Clear();

            //Generate network point nodes
            List <string> uniqueIPs = GenerateUniqueIPs(Networks);

            Console.WriteLine("Generated IP Addresses: ");
            foreach (string ip in uniqueIPs)
            {
                Console.WriteLine(ip);
                NetworkNodes.Add(new NetworkNode(ip, this));
            }

            Console.WriteLine("Generated connections: ");
            //Generate a randomly connected network graph
            for (int i = 0; i < Networks; i++)
            {
                //Generate a random network to target
                int r = RandomGenerator.Next(Networks);
                while (r == i)
                {
                    r = RandomGenerator.Next(Networks);
                }

                NetworkNode currentNetwork = NetworkNodes[i];
                NetworkNode targetNetwork  = NetworkNodes[r];

                Edge e = new Edge(currentNetwork, targetNetwork);
                currentNetwork.AddEdge(e);
                targetNetwork.AddEdge(e);

                Console.WriteLine("{0} -- {1}", currentNetwork.GetIP(), targetNetwork.GetIP());
            }
        }