예제 #1
0
        public void CreateFromFibTable(FibTable table)
        {
            Root = new FibTreeNode(null);
            Labels.Clear();

            foreach (FibEntry entry in table)
            {
                FibTreeNode node = Root;
                for (int i = 0; i < entry.BinaryForm.Length; i++)
                {
                    int edgeLabel = entry.BinaryForm[i] - (int)'0';
                    if (node.GetChild(edgeLabel) == null)
                    {
                        node.AddChild(edgeLabel);
                    }
                    node = node.GetChild(edgeLabel);
                }

                FibTreeLabel label = Labels.GetLabelByNextHop(entry.NextHop);
                if (label == null)
                {
                    label = Labels.AddLabelForNextHop(entry.NextHop);
                }
                node.Label = label;
            }

            TreeChanged?.Invoke();
        }
        public static void WriteToFile(this FibTable table, string file)
        {
            List <string> lines = new List <string>();

            foreach (FibEntry fibEntry in table)
            {
                lines.Add(string.Format("{0},{1}", fibEntry.IpForm, fibEntry.NextHop));
            }
            File.WriteAllLines(file, lines.ToArray());
        }
 public static void ReadFromFile(this FibTable table, string file)
 {
     table.ClearEntries();
     string[] lines = File.ReadAllLines(file);
     foreach (string line in lines)
     {
         if (!string.IsNullOrWhiteSpace(line))
         {
             string[] parts = line.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
             if (parts.Length == 2)
             {
                 string prefix  = parts[0].Replace("\"", "");
                 string nextHop = parts[1].Replace("\"", "");
                 table.AddEntry(new FibEntry(prefix, nextHop, null));
             }
         }
     }
 }