Exemplo n.º 1
0
 public void addToTempQueue(VirtualContainer3 container, int pos)
 {
     if (this.currentFrame.vc4 == null)
     {
         this.currentFrame.vc4 = new VirtualContainer4();
     }
     if (pos != 0)
     {
         this.currentFrame.vc4.vc3List.Add(pos, container);
     }
 }
Exemplo n.º 2
0
 public int[] commutateContainer(VirtualContainer3 container, int iport, int pos)
 {
     int[] out_pos = { -1, -1 };
     if (container != null)
     {
         //mamy do czynienia z vc3
         foreach (var row in fib)
         {
             if (row.iport == iport && row.in_cont == pos)
             {
                 out_pos[0] = row.oport;
                 out_pos[1] = row.out_cont;
                 NetNode.log("Commutating vc3 container from:" + row.iport + " " + row.in_cont + "to " + row.oport + " " + row.out_cont, ConsoleColor.Green);
                 return(out_pos);
             }
         }
     }
     return(out_pos);
 }
Exemplo n.º 3
0
        private void commutation()
        {
            while (flag)
            {
                int opt = commOption();

                foreach (IPort iport in this.ports.iports)
                {
                    //check if there is frame in queue and try to process it
                    if (iport.input.Count > 0)
                    {
                        STM1 frame = iport.input.Dequeue();

                        //if (frame.vc4 != null)
                        if (opt != 1)
                        {
                            Console.WriteLine("vc4");
                            int out_pos           = -1;
                            VirtualContainer4 vc4 = frame.vc4;
                            out_pos = switchField.commutateContainer(vc4, iport.port);
                            if (out_pos != -1)
                            {
                                log("ok", ConsoleColor.Green);
                                this.ports.oports[out_pos].addToOutQueue(vc4);
                            }
                        }
                        //else if (frame.vc4.vc3List.Count > 0)
                        else
                        {
                            Console.WriteLine("vc3->vc4");
                            Console.WriteLine("unpacking container");
                            foreach (var vc in frame.vc4.vc3List)
                            {
                                VirtualContainer3 vc3 = vc.Value;
                                if (vc3 != null)
                                {
                                    int[] out_pos = { -1, -1 };
                                    out_pos = switchField.commutateContainer(vc3, iport.port, vc.Key);
                                    if (out_pos[0] != -1)
                                    {
                                        log("ok", ConsoleColor.Green);
                                        this.ports.oports[out_pos[0]].addToTempQueue(vc3, out_pos[1]);
                                    }
                                }
                            }
                        }
                        //else
                        //{
                        //Console.WriteLine("smth wrong with stm1");
                        //}
                    }
                }
                foreach (OPort oport in this.ports.oports)
                {
                    //packing STM from tempQueue to outqueue
                    oport.addToOutQueue();
                }

                foreach (OPort oport in this.ports.oports)
                {
                    //check if there is frame in queue and try to send it
                    if (oport.output.Count > 0)
                    {
                        STM1 frame = oport.output.Dequeue();
                        if (frame.vc4 != null || frame.vc4.vc3List.Count > 0)
                        {
                            try
                            {
                                pathList.Add(this.virtualIp);
                                Signal signal = new Signal(oport.port, frame, pathList);
                                consoleWriter("sending signal port: " + signal.port);
                                string data = JMessage.Serialize(JMessage.FromValue(signal));
                                Console.WriteLine(data);
                                writer.Write(data);
                            }
                            catch (Exception e)
                            {
                                log("\nError sending signal: " + e.Message, ConsoleColor.Red);
                                Thread.Sleep(2000);
                                Environment.Exit(1);
                            }
                        }
                    }
                }
                Thread.Sleep(125);
            }
        }