private void ILM_AddButton_Click(object sender, RoutedEventArgs e) { var routerName = ILM_RouterName.Text; var incPort = ILM_IncPort.Text; var incLabel = ILM_IncLabel.Text; var poppedLabels = ILM_PoppedLabels.Text; var NHLFE_ID = ILM_NHLFE_ID.Text; if (routerName.Length == 0 || incPort.Length == 0 || incLabel.Length == 0 || poppedLabels.Length == 0 || NHLFE_ID.Length == 0) { return; } var isProperRule = CheckIfIsProperILM_Entry(incPort, incLabel, poppedLabels, NHLFE_ID); if (!isProperRule || !Manager.RouterNameToILMTable.ContainsKey(routerName)) { AddLog("You are trying to add an incorrect rule!", LogType.Error); return; } var foundRow = ILM_Rows.Find(x => x.RouterName.Equals(routerName) && x.IncLabel.Equals(int.Parse(incLabel)) && x.IncPort.Equals(ushort.Parse(incPort)) && x.PoppedLabelStack.Equals(poppedLabels)); if (foundRow != null) { AddLog("NHLFE ID for such parameters already exists!", LogType.Error); return; } var rule = new IlmTableRow(incPort + " " + incLabel + " " + poppedLabels + " " + NHLFE_ID); rule.RouterName = routerName; Manager.RouterNameToILMTable[routerName].Add(rule); ILM_Rows.Add(rule); Manager.SendRow(routerName, rule, ManagementActions.ADD_ILM_ENTRY); SortIlmRows(); ILM_Table.Items.Refresh(); ILM_RouterName.Clear(); ILM_IncPort.Clear(); ILM_IncLabel.Clear(); ILM_PoppedLabels.Clear(); ILM_NHLFE_ID.Clear(); ILM_RouterName.Focus(); }
private void ILM_DeleteButton_Click(object sender, RoutedEventArgs e) { int index = ILM_Table.SelectedIndex; if (index == -1) // selected empty entry { return; } var selectedEntry = ILM_Table.SelectedItems[0] as IlmTableRow; var routerName = selectedEntry.RouterName; var incLabel = selectedEntry.IncLabel; var incPort = selectedEntry.IncPort; var poppedLabelStack = selectedEntry.PoppedLabelStack; var NHLFE_ID = selectedEntry.NHLFE_ID; if (Manager.RouterNameToILMTable.ContainsKey(routerName)) { try { // remove item from the list that is binded to GUI's listView var foundRow = ILM_Rows.Find(x => x.RouterName.Equals(routerName) && x.IncLabel.Equals(incLabel) && x.IncPort.Equals(incPort) && x.PoppedLabelStack.Equals(poppedLabelStack) && x.NHLFE_ID.Equals(NHLFE_ID)); Manager.SendRow(routerName, foundRow, ManagementActions.REMOVE_ILM_ENTRY); ILM_Rows.Remove(foundRow); // remove item from the list that is in dictionary var row = Manager.RouterNameToILMTable[routerName].Find(x => x.RouterName.Equals(routerName) && x.IncLabel.Equals(incLabel) && x.IncPort.Equals(incPort) && x.PoppedLabelStack.Equals(poppedLabelStack) && x.NHLFE_ID.Equals(NHLFE_ID)); Manager.RouterNameToILMTable[routerName].Remove(row); ILM_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); } }