public void deleteConnection(NodeConnection con)
        {
            ConnectionProperties conProp = con.Prop;
            int tempVPortTo = conProp.VirtualPortTo;
            int tempLPortTo = conProp.LocalPortTo;

            conProp.VirtualPortTo = 0;
            conProp.LocalPortTo   = 0;
            String data = JSON.Serialize(JSON.FromValue(conProp));

            try
            {
                writerCableCloud.Write(data);
                conProp = con.Prop;
                conProp.VirtualPortFrom = tempVPortTo;
                conProp.LocalPortFrom   = tempLPortTo;
                data = JSON.Serialize(JSON.FromValue(conProp));
                writerCableCloud.Write(data);
            }
            catch (SocketException e)
            {
                Console.WriteLine(e.StackTrace);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.StackTrace);
            }
            Console.WriteLine("Conn send" + DateTime.Now.ToLongTimeString());
        }
        public void updateConnections(List <NodeConnection> connections)
        {
            String data = JSON.Serialize(JSON.FromValue(connections.Select(n => n.Prop).ToList()));

            try
            {
                writerCableCloud.Write(data);
            }
            catch (SocketException e)
            {
                Console.WriteLine(e.StackTrace);
            }
            //connectionList.Add(new NodeConnection(from, portFrom, to, portTo, from.Name + "-" + to.Name));
            //for (int i = 0; i < connections.Count; i++)
            //{
            //    String data = JSON.Serialize(JSON.FromValue(connections[i].Prop));
            //    try
            //    {
            //        writerCableCloud.Write(data);
            //    }
            //    catch (SocketException e)
            //    {
            //        Console.WriteLine(e.StackTrace);
            //    }
            //}
        }
Exemplo n.º 3
0
 public void killManagement()
 {
     if (clientManagement != null)
     {
         ApplicationProtocol toSend = new ApplicationProtocol();
         toSend.State = ApplicationProtocol.KILL;
         string data = JSON.Serialize(JSON.FromValue(toSend));
         writerManagement.Write(data);
     }
 }
Exemplo n.º 4
0
        public void sandInfoToOtherNcc(List <int> nccPorts)
        {
            ApplicationProtocol toSend = new ApplicationProtocol();

            toSend.State = ApplicationProtocol.TOOTHERNCC;
            toSend.ConnectionToOtherNcc = nccPorts;
            string data = JSON.Serialize(JSON.FromValue(toSend));

            threadManagement = new Thread(new ParameterizedThreadStart(tryToSendData));
            threadManagement.Start(data);
        }
Exemplo n.º 5
0
 public void sendConnectClientNcc(List <String> nodeNames)
 {
     if (clientManagement != null)
     {
         ApplicationProtocol toSend = new ApplicationProtocol();
         toSend.State           = ApplicationProtocol.CONNECTIONTONCC;
         toSend.ConnectionToNcc = nodeNames;
         string data = JSON.Serialize(JSON.FromValue(toSend));
         writerManagement.Write(data);
     }
 }
Exemplo n.º 6
0
        internal void sendAllClients(List <string> clientList)
        {
            ApplicationProtocol toSend = new ApplicationProtocol();

            toSend.State      = ApplicationProtocol.ALLCLIENTS;
            toSend.AllClients = clientList;
            string data = JSON.Serialize(JSON.FromValue(toSend));

            threadManagement = new Thread(new ParameterizedThreadStart(tryToSendData));
            threadManagement.Start(data);
        }
        public void updateOneConnection()
        {
            String data = JSON.Serialize(JSON.FromValue(allConnections.Last().Prop));

            try
            {
                writerCableCloud.Write(data);
            }
            catch (SocketException e)
            {
                Console.WriteLine(e.StackTrace);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.StackTrace);
            }
            Console.WriteLine("Conn send" + DateTime.Now.ToLongTimeString());
        }
Exemplo n.º 8
0
        private static void ListenThread(Object threadPasser)
        {
            ThreadPasser tp        = (ThreadPasser)threadPasser;
            TcpClient    clienttmp = tp.client;
            BinaryWriter writer    = new BinaryWriter(clienttmp.GetStream());

            ManagmentProtocol toSend = new ManagmentProtocol();

            toSend.State = ManagmentProtocol.WHOIS;
            string data = JSON.Serialize(JSON.FromValue(toSend));

            writer.Write(data);

            BinaryReader      reader            = new BinaryReader(clienttmp.GetStream());
            string            received_data     = reader.ReadString();
            JSON              received_object   = JSON.Deserialize(received_data);
            ManagmentProtocol received_Protocol = received_object.Value.ToObject <ManagmentProtocol>();
            String            nodeName          = received_Protocol.Name;

            tp.control.allocateNode(nodeName, clienttmp, Thread.CurrentThread, writer);
        }
Exemplo n.º 9
0
        public void sendOutInformation(bool clearAutoTrails = true)
        {
            if (clearAutoTrails)
            {
                List <Trail> copyTrailList = new List <Trail>(trailList);
                foreach (Trail trail in copyTrailList)
                {
                    if (!trail.isCreadetByUser())
                    {
                        trail.clearTrail(trail);
                        trailList.Remove(trail);
                    }
                }
            }

            Dictionary <Dictionary <String, int>, String> possibleDestinations = new Dictionary <Dictionary <string, int>, String>();
            Dictionary <Dictionary <string, int>, string> listDestinations     = new Dictionary <Dictionary <string, int>, string>();

            foreach (Trail trail in trailList)
            {
                if (trail.From != null && trail.To != null)
                {
                    Dictionary <string, int> temp = new Dictionary <string, int>();
                    temp.Add(trail.To.Name, trail.StartingSlot);
                    listDestinations.Add(temp, (trail.From.Name));
                }
            }

            foreach (Trail trail in trailList)
            {
                if (trail.From == null)
                {
                    continue;
                }
                BinaryWriter      writer   = new BinaryWriter(trail.From.TcpClient.GetStream());
                ManagmentProtocol protocol = new ManagmentProtocol();
                protocol.State = ManagmentProtocol.POSSIBLEDESITATIONS;
                protocol.possibleDestinations = new Dictionary <string, int>();

                foreach (var dest in listDestinations)
                {
                    if (dest.Value == trail.From.Name)
                    {
                        foreach (var temp in dest.Key)
                        {
                            protocol.possibleDestinations.Add(temp.Key, temp.Value);
                        }
                    }
                }

                //protocol.possibleDestinations.Add(trail.To.Name, trail.StartingSlot);
                protocol.Port = trail.PortFrom;
                mainWindow.errorMessage(trail.From.Name + "<->" + protocol.Port);
                String send_object = JSON.Serialize(JSON.FromValue(protocol));
                writer.Write(send_object);

                foreach (KeyValuePair <Node, FIB> fib in trail.ComponentFIBs)
                {
                    //continue;
                    writer         = fib.Key.SocketWriter;//new BinaryWriter(fib.Key.TcpClient.GetStream());
                    protocol       = new ManagmentProtocol();
                    protocol.State = ManagmentProtocol.ROUTINGENTRY;
                    Console.WriteLine("routingentry");
                    protocol.RoutingEntry = fib.Value;

                    send_object = JSON.Serialize(JSON.FromValue(protocol));
                    writer.Write(send_object);
                }
            }
        }