private void IP_FIB_AddButton_Click(object sender, RoutedEventArgs e) { var routerName = IP_FIB_RouterName.Text; var destAddress = IP_FIB_DestAddress.Text; var outPort = IP_FIB_OutPort.Text; if (routerName.Length == 0 || destAddress.Length == 0 || outPort.Length == 0) { return; } var isProperRule = CheckIfIsProperIP_FIB_Entry(destAddress, outPort); if (!isProperRule || !Manager.RouterNameToIP_FIB_Table.ContainsKey(routerName)) { AddLog("You are trying to add an incorrect rule!", LogType.Error); return; } var foundRow = IP_FIB_Rows.Find(x => x.RouterName.Equals(routerName) && x.DestAddress.Equals(IPAddress.Parse(destAddress))); if (foundRow != null) { AddLog("Output port for such destination address already exists!", LogType.Error); return; } var rule = new IpFibTableRow(destAddress + " " + outPort); rule.RouterName = routerName; Manager.RouterNameToIP_FIB_Table[routerName].Add(rule); IP_FIB_Rows.Add(rule); Manager.SendRow(routerName, rule, ManagementActions.ADD_IP_FIB_ENTRY); SortIpFibRows(); IP_FIB_Table.Items.Refresh(); IP_FIB_RouterName.Clear(); IP_FIB_DestAddress.Clear(); IP_FIB_OutPort.Clear(); IP_FIB_RouterName.Focus(); }
private void IP_FIB_DeleteButton_Click(object sender, RoutedEventArgs e) { int index = IP_FIB_Table.SelectedIndex; if (index == -1) // selected empty entry { return; } var selectedEntry = IP_FIB_Table.SelectedItems[0] as IpFibTableRow; var routerName = selectedEntry.RouterName; var destAddress = selectedEntry.DestAddress; var outPort = selectedEntry.OutPort; if (Manager.RouterNameToIP_FIB_Table.ContainsKey(routerName)) { try { // remove item from the list that is binded to GUI's listView var foundRow = IP_FIB_Rows.Find(x => x.RouterName.Equals(routerName) && x.DestAddress.Equals(destAddress) && x.OutPort.Equals(outPort)); Manager.SendRow(routerName, foundRow, ManagementActions.REMOVE_IP_FIB_ENTRY); IP_FIB_Rows.Remove(foundRow); // remove item from the list that is in dictionary var item = Manager.RouterNameToIP_FIB_Table[routerName].Find(x => x.RouterName.Equals(routerName) && x.DestAddress.Equals(destAddress) && x.OutPort.Equals(outPort)); Manager.RouterNameToIP_FIB_Table[routerName].Remove(item); IP_FIB_Table.Items.Refresh(); } catch (Exception) { AddLog($"Router {routerName} is not connected to MS!\n", LogType.Error); } } else { AddLog("Network topology does not contain such router!\n", LogType.Error); } }