示例#1
0
        /// <summary>
        /// Builds the frame from JSON text
        /// </summary>
        /// <param name="textFrame">The text of JSON frame.</param>
        /// <returns></returns>
        public IFrame BuildFrame(String textFrame)
        {
            metadata = JObject.Parse(textFrame);
            StmLevel frameLevel = StmLevel.STM1;

            if (metadata["Level"] != null)
            {
                frameLevel = FrameBuilder.getStmLevel(metadata["Level"]);
            }
            Frame returnFrame = new Frame(frameLevel);

            if (metadata["Msoh"].HasValues)
            {
                returnFrame.Msoh = (Header)FrameBuilder.EvaluateContent((JObject)metadata["Msoh"]);
            }
            if (metadata["Rsoh"].HasValues)
            {
                returnFrame.Rsoh = (Header)FrameBuilder.EvaluateContent((JObject)metadata["Rsoh"]);
            }
            if (FrameBuilder.isJArray(metadata["Content"]))
            {
                returnFrame.Content = FrameBuilder.evaluateContents((JArray)metadata["Content"]);
            }
            else
            {
                return(null);
            }
            return(returnFrame);
        }
示例#2
0
 /// <summary>
 /// Evaluates the content. Read JSON object create IContent
 /// </summary>
 /// <param name="content">The content.</param>
 /// <returns></returns>
 private static IContent EvaluateContent(JObject content)
 {
     try
     {
         if (FrameBuilder.isVirtualContainer(content["Type"])) //VirtualContainer
         {
             //Create new VC with level from JSON file
             VirtualContainer newVC = new VirtualContainer(FrameBuilder.getVCLevel(content["Level"]));
             newVC.Pointer = content["Pointer"].ToString();
             newVC.POH     = (POH)FrameBuilder.EvaluateContent((JObject)content["POH"]);
             if (FrameBuilder.isJArray(content["Content"]))
             {
                 newVC.Content = FrameBuilder.evaluateContents((JArray)content["Content"]);
             }
             else //There is no value Content of VC is null
             {
                 newVC.Content = null;
             }
             return(newVC);
         }
         else if (FrameBuilder.isContainer(content["Type"]))
         {
             Container newContainer = new Container(content["Content"].ToString());
             return(newContainer);
         }
         else if (FrameBuilder.isHeader(content["Type"]))
         {
             string checksum  = content["Checksum"].ToString();
             string eow       = content["EOW"].ToString();
             string dcc       = content["DCC"].ToString();
             Header newHeader = new Header(checksum, eow, dcc);
             return(newHeader);
         }
         else if (FrameBuilder.isPOH(content["Type"]))
         {
             SignalLabelType signalType = FrameBuilder.getSignalType(content["SignalLabel"]);
             POH             poh        = new POH(signalType);
             return(poh);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(null);
     }
 }
        public AdaptationFunction(TransportTerminalFunction ttf)
        {
            Ttf = ttf;
            Builder = new FrameBuilder();
            Ttf.HandleInputFrame += new HandleInputFrame(GetDataFromFrame);

            this.Streams = new List<StreamData>();

            Dictionary<int, StmLevel> portsLevels = Ttf.GetPorts();
            OutputCredentials = new Dictionary<int, IFrame>();

            foreach (int portNumber in portsLevels.Keys)
            {
                OutputCredentials.Add(portNumber, new Frame(portsLevels[portNumber]));
            }
        }
示例#4
0
        /// <summary>
        /// Evaluates the contents. Iterate through the JArray to create IContent
        /// </summary>
        /// <param name="content">The content.</param>
        /// <returns></returns>
        private static List <IContent> evaluateContents(JArray content)
        {
            List <IContent> returnList = new List <IContent>();

            foreach (var item in content)
            {
                if (item.HasValues)
                {
                    returnList.Add(FrameBuilder.EvaluateContent((JObject)item));
                }
                else //Index in Frame.Content is free or occupied by larger VC then VC12
                {
                    returnList.Add(null);
                }
            }
            return(returnList);
        }
 /// <summary>
 /// Generates the BIP checksum
 /// </summary>
 /// <param name="sdhFrame">The SDH frame.</param>
 /// <param name="block">The block.</param>
 /// <returns></returns>
 public static string GenerateBIP(IFrame sdhFrame, int blockCount)
 {
     FrameBuilder fmb = new FrameBuilder();
     String checksum = String.Empty;
     byte[] bitFrame = BinaryInterleavedParity.ObjectToByteArray(fmb.BuildLiteral(sdhFrame));
     int hopSize = bitFrame.Length / blockCount;
     for (int z = 0; z < blockCount; z++)
     {
         byte block = 0;
         for (int x = z; x < z * hopSize && x < bitFrame.Length; x++)
         {
             block = (byte)(block + bitFrame[x]);
         }
         block = (byte)(block % 2);
         checksum += block.ToString();
     }
     return checksum;
 }