/// <summary> /// Permet d'envoyer le graph à un router specifique /// </summary> /// <param name="router"></param> private void SendGraphTo(Router destRouter, Link link) { //TODO //Dans la réception du graph il faut comparer les graph et si ils sont identiques //on met le graph.isupdated a true, sinon à false //Lorsque tous les graphs seront updated, ça veut dire que tous les routers ont le mm graph string str = "Poke"; try { //var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //socket.Connect(destRouter.Gateway, destRouter.GetPort(link)); //socket.Send(Encoding.UTF8.GetBytes(str), 0, str.Length, SocketFlags.None); TcpClient client = new TcpClient(destRouter.Gateway.ToString(), destRouter.portNumber); // Translate the passed message into ASCII and store it as a Byte array. Byte[] data = System.Text.Encoding.ASCII.GetBytes(str); // Get a client stream for reading and writing. // Stream stream = client.GetStream(); NetworkStream stream = client.GetStream(); // Send the message to the connected TcpServer. stream.Write(data, 0, data.Length); Console.WriteLine("Sent: {0}", str); // Receive the TcpServer.response. // Buffer to store the response bytes. data = new Byte[256]; // String to store the response ASCII representation. String responseData = String.Empty; // Read the first batch of the TcpServer response bytes. Int32 bytes = stream.Read(data, 0, data.Length); responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes); Console.WriteLine("Received: {0}", responseData); // Close everything. stream.Close(); client.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
static void Main(string[] args) { //Choix de l'algo int choiceAlgorithm; bool parsed; do { Console.WriteLine("Quel algorithme souhaitez-vous utiliser?\n1) LS\n2) DV"); parsed = Int32.TryParse(Console.ReadLine(), out choiceAlgorithm); } while (!parsed || (choiceAlgorithm != 1 && choiceAlgorithm != 2)); if (choiceAlgorithm == 1) { Router.RouterMode = ModeEnum.LS; } else { Router.RouterMode = ModeEnum.DV; } Router RouterA = new Router("RouterA", 50001); Router RouterB = new Router("RouterB", 50002); Router RouterC = new Router("RouterC", 50003); Router RouterD = new Router("RouterD", 50004); Router RouterE = new Router("RouterE", 50005); Router RouterF = new Router("RouterF", 50006); Link linkAB = new Link(RouterA, RouterB, 5); Link linkAD = new Link(RouterA, RouterD, 45); Link linkBC = new Link(RouterB, RouterC, 70); Link linkBE = new Link(RouterB, RouterE, 3); Link linkDC = new Link(RouterD, RouterC, 50); Link linkDE = new Link(RouterD, RouterE, 8); Link linkCF = new Link(RouterC, RouterF, 78); Link linkEF = new Link(RouterE, RouterF, 7); RouterA.NeighboursLink = new List<Link>() { linkAB, linkAD }; RouterB.NeighboursLink = new List<Link>() { linkAB, linkBE, linkBC }; RouterC.NeighboursLink = new List<Link>() { linkBC, linkDC, linkCF }; RouterD.NeighboursLink = new List<Link>() { linkAD, linkDC, linkDE }; RouterE.NeighboursLink = new List<Link>() { linkDE, linkBE, linkEF }; RouterF.NeighboursLink = new List<Link>() { linkCF, linkEF }; Thread ThreadRouterA = new Thread(RouterA.StartListening); Thread ThreadRouterB = new Thread(RouterB.StartListening); Thread ThreadRouterC = new Thread(RouterC.StartListening); Thread ThreadRouterD = new Thread(RouterD.StartListening); Thread ThreadRouterE = new Thread(RouterE.StartListening); Thread ThreadRouterF = new Thread(RouterF.StartListening); ThreadRouterA.Start(); ThreadRouterB.Start(); ThreadRouterC.Start(); ThreadRouterD.Start(); ThreadRouterE.Start(); ThreadRouterF.Start(); RouterA.UpdateNeighborhood(); RouterB.UpdateNeighborhood(); RouterC.UpdateNeighborhood(); RouterD.UpdateNeighborhood(); RouterE.UpdateNeighborhood(); RouterF.UpdateNeighborhood(); Console.ReadLine(); }
/// <summary> /// Constructeur paramétré /// </summary> public Link(Router r1, Router r2, int cost) { R1 = r1; R2 = r2; Cost = cost; }