public void PassToInModule(object oSender, object received, int destPort) { try { InPort inPort; int destinationPort; if (received.GetType() == typeof(Packet)) { Packet receivedPacket = (Packet)received; MPLSPacket packet = SetLabelAndPort(receivedPacket, destPort); destinationPort = GetPortNumber(packet); inPort = GetInPort(destinationPort); //LogClass.WhiteLog("Passing MPLSPacket to inPort " + inPort.GetPortNumber()); MPLSPacket processedPacket = inPort.ProcessPacket(packet); Commutate(processedPacket); } else if (received.GetType() == typeof(MPLSPack)) { MPLSPack receivedPack = (MPLSPack)received; destinationPort = destPort; inPort = GetInPort(destinationPort); //LogClass.WhiteLog("Passing MPLSPack to inPort " + destinationPort); ThreadSafeList <MPLSPacket> processedPackets = inPort.ProcessPack(receivedPack, destPort); foreach (MPLSPacket packet in processedPackets) { Commutate(packet); } } } catch (Exception e) { LogClass.MagentaLog("Connection doesn't exist"); } }
private void ChangeLabel(MPLSPacket packet) { int oldPort = packet.DestinationPort; int oldLabel = packet.GetLabelFromStack(); int[] FIBOutput = fib.GetOutput(oldPort, oldLabel, packet.ipPacket.destinationAddress); int port = FIBOutput[0]; int label = FIBOutput[1]; packet.DestinationPort = port; LogClass.WhiteLog("MPLSPacket from inPort " + oldPort + ": old label = " + oldLabel); if (label != 0) { packet.PutLabelOnStack(label); Console.WriteLine(" | new label = " + label); } else { Console.WriteLine(" | old label removed"); } if (fib.LookForLabelToBeAdded(oldPort, oldLabel) != 0) { int addingLabel = fib.LookForLabelToBeAdded(oldPort, oldLabel); packet.PutLabelOnStack(fib.LookForLabelToBeAdded(oldPort, oldLabel)); LogClass.Log("Starting new tunnel with label " + addingLabel); ChangeLabel(packet); } else if (fib.LookForLabelToBeRemoved(oldPort, oldLabel) != 0) { LogClass.Log("Ending tunnel"); ChangeLabel(packet); } }
public void Start() { ConnectToCableClaud(); while (true) { try { var message = Receive(CSocket); switch (message) { case "OK": ManagementAgent.ReturnLog("Sent message."); break; case "NOTOK": ManagementAgent.ReturnLog("Unable to send message."); break; default: byte[] msg = Encoding.Default.GetBytes(message); MPLSPacket mpls = new MPLSPacket(msg); ManagementAgent.ReturnLog($"Port: {PortNumber}; Received MPLS Packet: " + mpls.MPLSInfo()); SwitchingFabric.SwapLabels(PortNumber, mpls); break; } } catch (Exception e) { } } }
public MPLSPacket ProcessPacket(MPLSPacket mplsPacket) { LogClass.WhiteLog("MPLSPacket added to inPort " + portNumber); Program.count++; ChangeLabel(mplsPacket); return(mplsPacket); }
public void Send(MPLSPacket mplsp) { byte[] byteData = mplsp.GetBytes(); CSocket.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), CSocket); ManagementAgent.ReturnLog($"Port {PortNumber} Trying to send MPLS Packet: " + mplsp.MPLSInfo()); }
private MPLSPacket SetLabel(Packet packet) { int label = fib.ExchangeIpAddressForLabel(packet.destinationAddress); MPLSPacket mplspacket = new MPLSPacket(packet, label); ChangeLabel(mplspacket); return(mplspacket); }
private void ChangeLabel(MPLSPacket packet) { int[] FIBOutput = fib.GetOutput(packet.destinationPort, packet.GetLabelFromStack()); int port = FIBOutput[0]; int label = FIBOutput[1]; packet.destinationPort = port; packet.PutLabelOnStack(label); }
public MPLSPacket(MPLSPacket packet) { ipPacket = new Packet(packet.ipPacket); labelStack = new Stack <int>(); for (int i = 0; i < packet.labelStack.Count; i++) { labelStack.Push(packet.labelStack.ElementAt(i)); } DestinationPort = packet.DestinationPort; }
private MPLSPacket SetLabelAndPort(Packet packet, int destinationPort) { //Console.WriteLine("destination: " + packet.destinationAddress); int label = fib.ExchangeIpAddressForLabel(packet.destinationAddress, destinationPort); LogClass.WhiteLog("Converting IPPacket to MPLSPacket with label " + label); MPLSPacket mplspacket = new MPLSPacket(packet, label); mplspacket.DestinationPort = destinationPort; return(mplspacket); }
public static void SwapLabels(int portNumber, MPLSPacket mplsp) { if (mplsp.TTL > 0) { mplsp.TTL -= 1; int LabelIndex = 1; while (true) { byte LastLabel = mplsp.Labels[mplsp.Labels.Count() - 1]; int mplsListIndex = MPLSFibTable.ReturnIndex(portNumber, LastLabel, LabelIndex); if (mplsListIndex == -1) { ManagementAgent.ReturnLog("Unable to forward packet."); break; } else { List <int> outputLabels = MPLSFibTable.MplsFibTable[mplsListIndex].OutputLabel; if (outputLabels[0] == 0) { LabelIndex++; mplsp.Labels.RemoveAt(mplsp.Labels.Count() - 1); continue; } else { mplsp.Labels.RemoveAt(mplsp.Labels.Count() - 1); foreach (int labels in outputLabels) { mplsp.Labels.Add(Convert.ToByte(labels)); } IOPort exitPort = LabelSwitchingRouter.ReturnPort(MPLSFibTable.MplsFibTable[mplsListIndex].OutputPort); if (exitPort != null) { exitPort.Send(mplsp); } else { ManagementAgent.ReturnLog("Unable to forward packet."); } break; } } } } else { ManagementAgent.ReturnLog("TTL value equals 0. Packet disappeared."); } }
private void Commutate(MPLSPacket packet) { int packetOutPort = packet.destinationPort; int portNumber; foreach (OutPort port in outPorts) { portNumber = port.GetPortNumber; if (packetOutPort == portNumber) { port.addToBuffer(packet); return; } } }
private void Commutate(MPLSPacket packet) { int packetOutPort = packet.DestinationPort; int portNumber; foreach (OutPort port in outPorts) { portNumber = port.GetPortNumber(); if (packetOutPort == portNumber) { LogClass.WhiteLog("Adding MPLSPacket to buffer of OutPort " + portNumber); port.AddToBuffer(packet); return; } } }
public void RouteIncoming(object oSender, object received) //jak to nazwać? { InPort inPort; int destinationPort; if (received.GetType() == typeof(Packet)) { Packet receivedPacket = (Packet)received; destinationPort = GetPortNumber(receivedPacket); inPort = GetInPort(destinationPort); MPLSPacket processedPacket = inPort.processPacket(receivedPacket); } else if (received.GetType() == typeof(MPLSPack)) { MPLSPack receivedPack = (MPLSPack)received; destinationPort = receivedPack.destinationPort; inPort = GetInPort(destinationPort); List <MPLSPacket> processedPackets = inPort.processPack(receivedPack); foreach (MPLSPacket packet in processedPackets) { Commutate(packet); } } }
private int GetPortNumber(MPLSPacket receivedPacket) { int portNumber = receivedPacket.DestinationPort; return(portNumber); }
public void AddToBuffer(MPLSPacket packet) { packetBuffer.Add(packet); }
public MPLSPacket processPacket(Packet packet) { MPLSPacket labeledMPLS = SetLabel(packet); return(labeledMPLS); }