public static void addToSwitch(FIB row) { int counter = 0; if (fib.Count == 0) { fib.Add(row); Console.WriteLine("New fib entry added"); } else { foreach (var fibrow in fib) { if (fibrow.iport == row.iport && fibrow.in_cont == row.in_cont)// && fibrow.oport == row.oport && fibrow.out_cont == row.out_cont) { Console.WriteLine("Updating already stored"); fib.Remove(fibrow); fib.Add(row); break; } counter++; } if (counter == fib.Count) { fib.Add(row); Console.WriteLine("New fib entry added"); } } }
private void insertFib() { FIB fib = new FIB(0, 0, 0, 0); Console.WriteLine("Insert input port:"); Int32.TryParse(Console.ReadLine(), out fib.iport); Console.WriteLine("Insert input container position:"); Int32.TryParse(Console.ReadLine(), out fib.in_cont); Console.WriteLine("Insert output port:"); Int32.TryParse(Console.ReadLine(), out fib.oport); Console.WriteLine("Insert output container position:"); Int32.TryParse(Console.ReadLine(), out fib.out_cont); SwitchingField.addToSwitch(fib); //adding fib for two-way communication SwitchingField.addToSwitch(new FIB(fib.oport, fib.out_cont, fib.iport, fib.in_cont)); }
public static void clearFib(FIB row) { Console.WriteLine("Removing fib: " + row.toString()); int id = 0; foreach (var temp in fib) { if (row.iport == temp.iport) { if (row.in_cont == temp.in_cont) { if (row.oport == temp.oport) { if (row.out_cont == temp.out_cont) { id = fib.IndexOf(temp); } } } } } fib.RemoveAt(id); }