private void PerformLabelAction(MPLSPackage package, NHLFETableRow NHLFE, byte TTL, ref string poppedLabelStack) { if (NHLFE.OutPort != null) { package.Port = (ushort)NHLFE.OutPort; } switch (NHLFE.Action) { case LabelActions.POP: if (poppedLabelStack.Equals("-")) { poppedLabelStack = package.PeekTopLabel().Number.ToString(); } else { poppedLabelStack += "," + package.PeekTopLabel().Number.ToString(); } AddLog($"Popped top label: {package.PeekTopLabel().Number}", LogType.Information, Window.ShowDetailedRoutingLogs); package.PopTopLabel(); if (package.LabelStack.IsEmpty()) { AddLog("[MPLS->IP] Copying TTL from MPLS level 1 label to IP header", LogType.Information, Window.ShowDetailedTTLLogs); package.TTL = TTL; } else { AddLog("[MPLS] Copying TTL from the previous outermost label to the new [lower level] outermost one", LogType.Information, Window.ShowDetailedTTLLogs); package.PeekTopLabel().TTL = TTL; } break; case LabelActions.SWAP: AddLog($"Swapped top label: {package.PeekTopLabel().Number} to {(short)NHLFE.OutLabel}", LogType.Information, Window.ShowDetailedRoutingLogs); package.PopTopLabel(); package.PushLabel(new Label((short)NHLFE.OutLabel)); package.PeekTopLabel().TTL = TTL; break; case LabelActions.PUSH: AddLog($"Pushed new label: {(short)NHLFE.OutLabel}", LogType.Information, Window.ShowDetailedRoutingLogs); package.PushLabel(new Label((short)NHLFE.OutLabel)); if (poppedLabelStack.Equals("Push first label on IP package")) { AddLog("[MPLS] Copying TTL from IP header", LogType.Information, Window.ShowDetailedTTLLogs); poppedLabelStack = "-"; } else { AddLog("[MPLS] Copying TTL from the previous outermost label to the new [higher level] outermost one", LogType.Information, Window.ShowDetailedTTLLogs); } package.PeekTopLabel().TTL = TTL; break; default: break; } }
private void NHLFE_AddButton_Click(object sender, RoutedEventArgs e) { var routerName = NHLFE_RouterName.Text; var NHLFE_ID = NHLFE_NHLFE_ID.Text; var action = NHLFE_Action.Text; var outLabel = NHLFE_OutLabel.Text; var outPort = NHLFE_OutPort.Text; var nextID = NHLFE_NextID.Text; if (routerName.Length == 0 || NHLFE_ID.Length == 0 || action.Length == 0 || outLabel.Length == 0 || outPort.Length == 0 || nextID.Length == 0) { return; } var isProperRule = CheckIfIsProperNHLFE_Entry(routerName, NHLFE_ID, action, outLabel, outPort, nextID); if (!isProperRule || !Manager.RouterNameToNHLFE_Table.ContainsKey(routerName)) { AddLog("You are trying to add an incorrect rule!", LogType.Error); return; } var foundRow = NHLFE_Rows.Find(x => x.RouterName.Equals(routerName) && x.ID.Equals(int.Parse(NHLFE_ID))); if (foundRow != null) { AddLog("NHLFE with given ID already exists!", LogType.Error); return; } var rule = new NHLFETableRow(NHLFE_ID + " " + action + " " + outLabel + " " + outPort + " " + nextID); rule.RouterName = routerName; Manager.RouterNameToNHLFE_Table[routerName].Add(rule); NHLFE_Rows.Add(rule); Manager.SendRow(routerName, rule, ManagementActions.ADD_NHLFE_ENTRY); SortNhlfeRows(); NHLFE_Table.Items.Refresh(); NHLFE_RouterName.Clear(); NHLFE_NHLFE_ID.Clear(); NHLFE_Action.Clear(); NHLFE_OutLabel.Clear(); NHLFE_OutPort.Clear(); NHLFE_NextID.Clear(); NHLFE_RouterName.Focus(); }
/// <summary> /// Checks if two NHLFE entries are equal. /// </summary> /// <param name="other">An NHLFE entry we are comparing our entry to.</param> /// <returns>True, if entries are equal; false - otherwise.</returns> protected bool Equals(NHLFETableRow other) { return(ID == other.ID && Action == other.Action && OutLabel == other.OutLabel && OutPort == other.OutPort && NextID == other.NextID); }