Example #1
0
        private void sendHard(string message, string slot)
        {
            try
            {
                logTextBox.AppendText("DEBISAHFOIS");
                Dictionary <int, VirtualContainer3> vc3List = new Dictionary <int, VirtualContainer3>();
                VirtualContainer3 msg = new VirtualContainer3(adaptation(), message);
                vc3List.Add(int.Parse(slot), msg);
                STM1          frame = new STM1(adaptation(), vc3List);
                List <string> temp  = new List <string>();
                temp.Add(this.virtualIP);
                Signal signal = new Signal(virtualPort, frame, temp);
                string data   = JMessage.Serialize(JMessage.FromValue(signal));
                writer.Write(data);
                foreach (KeyValuePair <int, VirtualContainer3> v in frame.vc4.vc3List)
                {
                    Log1("OUT", virtualIP, virtualPort.ToString(), v.Key, "VC-3", v.Value.POH.ToString(), v.Value.C3);
                }

                sendingTextBox.Clear();
            }
            catch (Exception e)
            {
                Log2("ERR", "Error sending signal");
            }
        }
Example #2
0
        private void sendSwiched(string message)
        {
            try
            {
                Dictionary <int, VirtualContainer3> vc3List = new Dictionary <int, VirtualContainer3>();
                foreach (int slot in slots)
                {
                    //Log2("DEBUG", "sloty od controla: "+slot);
                    VirtualContainer3 vc3 = new VirtualContainer3(adaptation(), "Slot" + slot + " : " + message);
                    vc3List.Add(slot, vc3);
                }
                STM1 frame = new STM1(adaptation(), vc3List);
                //SYGNAL
                List <string> temp = new List <string>();
                temp.Add(this.virtualIP);
                Signal signal = new Signal(virtualPort, frame, temp);
                string data   = JMessage.Serialize(JMessage.FromValue(signal));
                writer.Write(data);
                foreach (KeyValuePair <int, VirtualContainer3> v in frame.vc4.vc3List)
                {
                    Log1("OUT", virtualIP, virtualPort.ToString(), v.Key, "VC-3", v.Value.POH.ToString(), v.Value.C3);
                }

                sendingTextBox.Clear();
            }
            catch (Exception e)
            {
                Log2("ERR", "Error sending signal");
            }
        }
Example #3
0
        private void sendPeriodically(int period, string message)
        {
            Thread myThread = new Thread(async delegate()
            {
                bool isVc3 = false;
                Signal signal;
                STM1 frame;

                string data;
                Dictionary <int, VirtualContainer3> vc3List = new Dictionary <int, VirtualContainer3>();
                foreach (int slot in slots)
                {
                    VirtualContainer3 vc3 = new VirtualContainer3(adaptation(), "Slot" + slot + " :" + message);
                    vc3List.Add(slot, vc3);
                }
                frame = new STM1(adaptation(), vc3List);
                //SYGNAL
                List <string> temp = new List <string>();
                temp.Add(this.virtualIP);
                signal = new Signal(virtualPort, frame, temp);
                data   = JMessage.Serialize(JMessage.FromValue(signal));



                while (cyclic_sending)
                {
                    try
                    {
                        writer.Write(data);
                        foreach (KeyValuePair <int, VirtualContainer3> v in frame.vc4.vc3List)
                        {
                            Log1("OUT", virtualIP, virtualPort.ToString(), v.Key, "VC-3", v.Value.POH.ToString(), v.Value.C3);
                        }

                        await Task.Delay(TimeSpan.FromMilliseconds(period));
                    }
                    catch (Exception e)
                    {
                        Log2("ERR", "Error sending signal: ");
                        break;
                    }
                }
            });

            myThread.Start();
        }
 public Signal(int port, STM1 stm1, List <string> addToPath)
 {
     this.port = port;
     this.stm1 = new STM1(stm1.vc4.POH, stm1.vc4.C4, stm1.vc4.vc3List);
     this.path = addToPath;
 }
 public Signal()
 {
     this.port        = 0;
     this.stm1        = null;
     this.lrmProtocol = null;
 }
Example #6
0
        private void ListenThread(Object client)
        {
            TcpClient    clienttmp = (TcpClient)client;
            BinaryReader reader    = new BinaryReader(clienttmp.GetStream());

            writer = new BinaryWriter(clienttmp.GetStream());
            while (true)
            {
                string   received_data   = reader.ReadString();
                JMessage received_object = JMessage.Deserialize(received_data);
                if (received_object.Type == typeof(Signal))
                {
                    Signal received_signal = received_object.Value.ToObject <Signal>();
                    if (received_signal.stm1 != null)
                    {
                        STM1 received_frame = received_signal.stm1;
                        if (received_frame.vc4.vc3List.Count > 0)
                        {
                            slots.Clear();
                            foreach (KeyValuePair <int, VirtualContainer3> v in received_frame.vc4.vc3List)
                            {
                                receivedTextBox.AppendText(DateTime.Now.ToLongTimeString() + " : " + v.Value.C3);
                                receivedTextBox.AppendText(Environment.NewLine);
                                Log1("IN", virtualIP, received_signal.port.ToString(), v.Key, "VC-3", v.Value.POH.ToString(), v.Value.C3);
                                slots.Add(v.Key);
                            }
                        }
                        else
                        {
                            receivedTextBox.AppendText(DateTime.Now.ToLongTimeString() + " : " + received_frame.vc4.C4);
                            receivedTextBox.AppendText(Environment.NewLine);
                            Log1("IN", virtualIP, received_signal.port.ToString(), 1, "VC-4", received_frame.vc4.POH.ToString(), received_frame.vc4.C4);
                        }

                        logTextBox.AppendText(Environment.NewLine);
                        logTextBox.Paste("Path: \n");
                        foreach (var log in received_signal.path)
                        {
                            logTextBox.Paste(log + " -> ");
                        }
                        logTextBox.Paste(this.virtualIP);
                    }
                    else if (received_signal.lrmProtocol != null)
                    {
                        string   lrmProtocol = received_signal.lrmProtocol;
                        int      port        = received_signal.port;
                        string[] temp        = lrmProtocol.Split(' ');
                        if (temp[0] == "whoyouare")
                        {
                            string message = "iam " + this.virtualIP;
                            Signal signal  = new Signal(port, message);
                            string data    = JMessage.Serialize(JMessage.FromValue(signal));
                            writer.Write(data);
                        }
                    }
                }
                else
                {
                    Log2("ERR", "Received unknown data type from client");
                }
            }

            // reader.Close();
        }