public void LocalTopologyIn(bool delete, SNP localTopologyUpdate) { Link link = links.Find(x => x.FirstSNPP.Address == localTopologyUpdate.Address || x.SecondSNPP.Address == localTopologyUpdate.Address); SNPP snpp = null; if (link.FirstSNPP.Address == localTopologyUpdate.Address) { snpp = link.FirstSNPP; } else { snpp = link.SecondSNPP; } if (delete) { snpp.Capacity += localTopologyUpdate.OccupiedCapacity; LogClass.GreenLog("[RC]Received Topology: Added " + localTopologyUpdate.OccupiedCapacity + "Mbit/s to SNPP " + localTopologyUpdate.Address + "."); } else { snpp.Capacity -= localTopologyUpdate.OccupiedCapacity; LogClass.MagentaLog("[RC]Received Topology: Removed " + localTopologyUpdate.OccupiedCapacity + "Mbit/s from SNPP " + localTopologyUpdate.Address + "."); } LogClass.WhiteLog("[RC] " + snpp.Capacity + "Mbit/s left on " + snpp.Address); }
public MPLSPacket ProcessPacket(MPLSPacket mplsPacket) { LogClass.WhiteLog("MPLSPacket added to inPort " + portNumber); Program.count++; ChangeLabel(mplsPacket); return(mplsPacket); }
public void DisplayFIB(int inPortNumber) { foreach (Entry entry in routingTable) { LogClass.WhiteLog("[FIB] InPort " + entry.InPort + " InLabel " + entry.InLabel + " OutPort " + entry.OutPort + " OutLabel " + entry.OutLabel + " DestinationAddress " + entry.IPAddress); } }
public void createStringBasedPath(string path) //dodaje sciezke do listy scieżek na podstawie stringa z ciągiem wierzchołków { Path createdPath = null; try { if (!String.IsNullOrEmpty(path)) { int b = 0; string[] nbsVertices = path.Split(' '); createdPath = new Path(Int32.Parse(nbsVertices[0]) + 1, Int32.Parse(nbsVertices[nbsVertices.GetLength(0) - 1]) + 1); PathList.Add(createdPath); for (int a = 0; a < nbsVertices.GetLength(0) - 1; a++) { b = a + 1; PathList[PathList.Count - 1].edgesInPath.Add(getEdge(Int32.Parse(nbsVertices[a]) + 1, Int32.Parse(nbsVertices[b]) + 1, EdgeList)); } } } catch (System.FormatException e) { LogClass.WhiteLog("[RC] Can't find path with this capacity"); PathList.Remove(createdPath); } }
private void OnTimedEvent(object source, ElapsedEventArgs e) { int portNumber; sendingTimer.Stop(); foreach (OutPort outPort in outPorts) { if (outPort.GetBufferLength() > 0) { portNumber = outPort.GetPortNumber(); if (outPort.SendingToClient()) { while (outPort.GetBufferLength() > 0) { Packet bufferObject = outPort.PrepareIPPacketFromBuffer(0); OutputManager.sendIPPacket(bufferObject, outPort, portNumber); LogClass.WhiteLog("Sending IPPacket from outPort " + portNumber); } } else { MPLSPack bufferContent = outPort.PrepareMPLSPackFromBuffer(); OutputManager.sendMPLSPack(bufferContent, portNumber, outPort); LogClass.WhiteLog("Sending MPLSPack from outPort " + portNumber); } } } sendingTimer.Start(); }
public List <SNPP> route(IPAddress sourceAddress, IPAddress destinationAddress, int capacity) { TranslateSubnetworkData(); refreshSubnetwork(capacity); List <SNPP> path = new List <SNPP>(); List <Edge> edges = new List <Edge>(); List <SNPP> translated = new List <SNPP>(); SNPP sourceSNPP = findSNPPbyAddress(sourceAddress); SNPP destinationSNPP = findSNPPbyAddress(destinationAddress); subnetwork.algFloyda(); SubnetworkAddress source = findSubnetworkWhereIsContained(sourceAddress); SubnetworkAddress destination = findSubnetworkWhereIsContained(destinationAddress); int sourceVertexId = subnetworkToVertexId[source]; int destinationVertexId = subnetworkToVertexId[destination]; try { if (!(sourceVertexId == destinationVertexId)) { edges = subnetwork.getPath(sourceVertexId, destinationVertexId); translated = translateEdgesToSNPPs(edges); } } catch (FormatException e) { LogClass.WhiteLog("[RC] Can't find path with this capacity"); return(new List <SNPP>()); } return(translated); }
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); } }
private static Thread InitListenThread() { LogClass.WhiteLog("LISTENING FOR SUBNETWORKS"); var t = new Thread(() => RealStart()); t.IsBackground = true; t.Start(); return(t); }
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 void AddEntry(int inport, int inlabel, int outport, int outlabel, int newlabel, int removelabel, String address) { if (!routingTable.Contains(FindInputDestination(inport, inlabel, address))) { routingTable.Add(new Entry(inport, inlabel, outport, outlabel, newlabel, removelabel, address)); LogClass.GreenLog("Added new entry in FIB: inport " + inport + " inlabel " + inlabel + " outport " + outport + " outlabel " + outlabel + " | destinationAddress: " + address); } else { LogClass.WhiteLog("Entry with such input parameters already exists. Delete it before adding new one."); } }
public ConnectionController() { NetworkAddress = Config.getProperty("NetworkAddress"); ParentNetworkAddress = Config.getProperty("ParentNetworkAddress"); SubnetworkAddress = Config.getProperty("SubnetworkAddress"); SubnetworkMask = Config.getProperty("SubnetworkMask"); LogClass.WhiteLog("INITIALIZATION"); OtherDomainSNPPAddressTranslation = new Dictionary <SubnetworkAddress, List <Tuple <IPAddress, IPAddress> > >(); existingConnections = new Dictionary <string[], List <SNP> >(); ContainedSubnetworksAddresses = new List <SubnetworkAddress>(); LoadContainedSubnetworks(); }
public void LoadContainedSubnetworks() { LogClass.WhiteLog("Loading contained subnetworks:"); string fileName = Config.getProperty("ContainedSubnetworks"); string[] loadedFile = LoadFile(fileName); string[] subnetworkParams = null; foreach (string str in loadedFile) { subnetworkParams = str.Split(PARAM_SEPARATOR); ContainedSubnetworksAddresses.Add(new SubnetworkAddress(subnetworkParams[ADDRESS_POSITION], subnetworkParams[MASK_POSITION])); Console.WriteLine(str); } }
public void RemoveEntry(int inport, int inlabel, int outport, int outlabel) { Entry entryToBeDeleted = FindToDelete(inport, inlabel, outport, outlabel); if (entryToBeDeleted != null) { routingTable.Remove(entryToBeDeleted); LogClass.MagentaLog("Deleted entry from FIB: inport " + entryToBeDeleted.InPort + " inlabel " + entryToBeDeleted.InLabel + " outport " + entryToBeDeleted.OutPort + " outlabel " + entryToBeDeleted.OutLabel + " removed from FIB."); } else { LogClass.WhiteLog("Entry with such input parameters doesn't exist in this FIB."); } }
public ThreadSafeList <MPLSPacket> ProcessPack(MPLSPack mplsPack, int destPort) { LogClass.WhiteLog("MPLSPack added to inPort " + destPort); ThreadSafeList <MPLSPacket> packets = UnpackPack(mplsPack); LogClass.WhiteLog("MPLSPack unpacked, comutating MPLSPackets"); foreach (MPLSPacket packet in packets) { Program.count++; packet.DestinationPort = destPort; } packets.ForEach(ChangeLabel); return(packets); }
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; } } }
private static void LoadPortsToAnotherDomains() { string fileName = Config.getProperty("realPortsToDomains"); string[] loadedFile = LoadFile(fileName); string[] parameters = null; LogClass.WhiteLog("Loaded ports to another domains."); foreach (string str in loadedFile) { if (str[0] != '#') { parameters = str.Split(PARAM_SEPARATOR); SocketsToAnotherDomains.Add(new SubnetworkAddress(parameters[SUBNETWORK_ADDRESS_POSITION], parameters[SUBNETWORK_MASK_POSITION]), Int32.Parse(parameters[PORT_POSITION])); } } }
public LabelSwitchingRouter() { fib = new FIB(); numberOfInputModules = GetInputModulesNumber(); numberOfOutputModules = GetOutputModulesNumber(); inPorts = new List <InPort>(); outPorts = new List <OutPort>(); sendingTimer = new Timer(); sendingTimer.Interval = Config.getIntegerProperty("SendingInterval"); sendingTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); sendingTimer.Enabled = true; //agent = new RouterAgent(fib, inPorts); //łączność z NMSem, teraz niepotrzebna CC = new ConnectionController(fib, inPorts); CreateInPorts(numberOfInputModules); CreateOutPorts(numberOfOutputModules); LogClass.WhiteLog("Created LSR"); ParentSubnetworkConnector.Init(CC); }
private bool ConnectionRequestOut(SNP pathBegin, SNP pathEnd) { LogClass.WhiteLog("[CC] Sending ConnectionRequestOut between ports: " + pathBegin.Address + " and " + pathEnd.Address); //wysyla do cc poziom niżej wiadomosc connection request IPAddress subnetworkAddress = null; IPAddress subnetworkAddressMask = null; foreach (SubnetworkAddress sub in ContainedSubnetworksAddresses) { if (IPAddressExtensions.IsInSameSubnet(sub.subnetAddress, IPAddress.Parse(pathBegin.Address), sub.subnetMask)) { subnetworkAddress = sub.subnetAddress; subnetworkAddressMask = sub.subnetMask; } } SubnetworkAddress subnetAddress = new SubnetworkAddress(subnetworkAddress.ToString(), subnetworkAddressMask.ToString()); return(SubnetworkServer.SendConnectionRequest(pathBegin, pathEnd, subnetAddress)); }
public RouterAgent(FIB fib, List <InPort> inPorts) { this.fib = fib; inCommand = new Command(); outCommand = new Command(); this.inPorts = inPorts; _interface = Config.getProperty("NMSInterface"); outport = Config.getIntegerProperty("NMSListenPort"); init(); LogClass.WhiteLog("Established connection with NMS"); SendSingleCommand(_interface, outport); LogClass.WhiteLog("Sent hello message"); inputSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress ipAdd = IPAddress.Parse("127.0.0.1"); IPEndPoint remoteEP = new IPEndPoint(ipAdd, outport); inputSocket.Bind(remoteEP); Listen(); }
// % % % % % % % % % % % % % % % % % % % % % % % % % // // %%%%%%%%%%%%%%%%% GŁOWNA METODA %%%%%%%%%%%%%%%%% // // % % % % % % % % % % % % % % % % % % % % % % % % % // public bool ConnectionRequestFromNCC(string pathBegin, string pathEnd, int capacity) { string PathEndAddressFromDifferentDomain = null; string[] existingConnKey = new string[] { pathBegin, pathEnd }; //Lista SNP dla tworzonego aktualnie polaczenia List <SNP> SNPList = new List <SNP>(); //zakladamy, ze adres poczatkowy zawsze jest w naszej domenie, jezeli dostalismy requesta od NCC //dodaj SNP z labelem 0 dla poczatku sciezki SNPList.Add(new SNP(0, pathBegin, capacity, pathBegin, pathEnd)); //sprawdzamy, czy adres koncowy jest w naszej domenie if (!IPAddressExtensions.IsInSameSubnet(IPAddress.Parse(pathEnd), IPAddress.Parse(SubnetworkAddress), IPAddress.Parse(SubnetworkMask))) { PathEndAddressFromDifferentDomain = pathEnd; //sprawdza, czy adres docelowy jest w innej podsieci i podmienia foreach (SubnetworkAddress domainAddress in OtherDomainSNPPAddressTranslation.Keys) { if (!IPAddressExtensions.IsInSameSubnet(IPAddress.Parse(pathEnd), domainAddress.subnetAddress, domainAddress.subnetMask)) { Random random = new Random(); List <Tuple <IPAddress, IPAddress> > translationsList = OtherDomainSNPPAddressTranslation[domainAddress]; Tuple <IPAddress, IPAddress> foundTranslation = translationsList[random.Next(translationsList.Count)]; IPAddress translatedAddress = foundTranslation.Item1; pathEnd = translatedAddress.ToString(); } } } LogClass.WhiteLog("[CC] RouteTableQuery called between: " + pathBegin + " and: " + pathEnd); List <SNPP> SNPPList = RouteTableQuery(pathBegin, pathEnd, capacity); if (SNPPList.Count > 0) { //dodaj SNP z labelem 0 dla konca sciezki if (PathEndAddressFromDifferentDomain == null) { SNPList.Add(new SNP(0, pathEnd, capacity, pathBegin, pathEnd)); } else { SNPP fakeSNPP = new SNPP(pathEnd, 0); SNPPList.Add(fakeSNPP); SNPPList.Add(fakeSNPP); } for (int index = 0; index < SNPPList.Count; index += 2) { SNPP SNPPpathBegin = SNPPList[index]; SNPP SNPPpathEnd = SNPPList[index + 1]; Tuple <SNP, SNP> SNPpair = LinkConnectionRequest(SNPPpathBegin, SNPPpathEnd, capacity); if (SNPpair.Item1 != SNPpair.Item2) { SNPList.Add(SNPpair.Item1); SNPList.Add(SNPpair.Item2); } else { SNPList.Add(SNPpair.Item1); } } //Zapamietaj SNPlist z polaczeniem mdzy takimi adresami existingConnections.Add(existingConnKey, SNPList); //Wysłanie ConnectionRequesta do podsieci, jeżeli na liscie SNP zajdą się 2 adresy brzegowe tej podsieci for (int index = 0; index < SNPList.Count - 1; index++) { SNP SNPpathBegin = SNPList[index]; for (int jndex = index + 1; jndex < SNPList.Count; jndex++) { SNP SNPpathEnd = SNPList[jndex]; if (BelongsToSubnetwork(SNPpathBegin, SNPpathEnd)) { if (ConnectionRequestOut(SNPpathBegin, SNPpathEnd)) { LogClass.Log("Subnetwork Connection set properly."); } else { LogClass.Log("Epic fail."); return(false); } } } } //Wyslanie PeerCoordination jezeli zestawiane polaczenie przebiega przez 2 domeny if (PathEndAddressFromDifferentDomain != null) { //TODO: sprawdz, czy ktorys z SNP ma adres SNPP brzegowego tej domeny SNP lastSNPinThisDomain = null; foreach (SNP snp in SNPList) { foreach (List <Tuple <IPAddress, IPAddress> > list in OtherDomainSNPPAddressTranslation.Values) { foreach (Tuple <IPAddress, IPAddress> tuple in list) { if (tuple.Item1.ToString() == snp.Address) { lastSNPinThisDomain = snp; lastSNPinThisDomain.PathBegin = pathBegin; lastSNPinThisDomain.PathEnd = PathEndAddressFromDifferentDomain; } } } } if (PeerCoordinationOut(lastSNPinThisDomain, PathEndAddressFromDifferentDomain)) { LogClass.Log("PeerCoordination OK."); } else { LogClass.Log("PeerCoordination FAIL."); }; } } if (SNPPList.Count > 0) { return(true); //Jesli polaczenie zestawiono poprawnie } else { return(false); } }
private bool PeerCoordinationOut(SNP SNPpathBegin, string AddressPathEnd) { LogClass.WhiteLog("[CC] Sending peerCoordination: " + SNPpathBegin.Address + " to " + AddressPathEnd); return(SubnetworkServer.SendPeerCoordination(SNPpathBegin, AddressPathEnd, true)); }
public bool PeerCoordinationIn(SNP pathBegin, string pathEnd) { LogClass.Log("[DEBUG] incoming peercoordination from" + pathBegin.Address + " to " + pathEnd); string[] existingConnKey = new string[] { pathBegin.Address, pathEnd }; string beginAddressForDict = pathBegin.Address; //Lista SNP dla tworzonego aktualnie polaczenia List <SNP> SNPList = new List <SNP>(); //sprawdza, z ktorej domeny przyszedl SNP i podmienia jego adres na adres swojego SNPP brzegowego foreach (SubnetworkAddress domainAddress in OtherDomainSNPPAddressTranslation.Keys) { if (IPAddressExtensions.IsInSameSubnet(IPAddress.Parse(pathBegin.Address), domainAddress.subnetAddress, domainAddress.subnetMask)) { Tuple <IPAddress, IPAddress> foundTranslation = OtherDomainSNPPAddressTranslation[domainAddress].Find(x => x.Item1.ToString() == pathBegin.Address); IPAddress translatedAddress = foundTranslation.Item2; Console.WriteLine("TRANSALATED FROM" + pathBegin.Address + " TO " + translatedAddress.ToString()); pathBegin.Address = translatedAddress.ToString(); } } Console.WriteLine("DEFENITELY TRANSALATED TO " + pathBegin.Address); //przepustowosc bierzemy z przekazanego SNP SNPList.Add(new SNP(pathBegin.Label, pathBegin.Address, pathBegin.OccupiedCapacity, null, null)); SNPList.Add(new SNP(0, pathEnd, pathBegin.OccupiedCapacity, pathBegin.PathBegin, pathBegin.PathEnd)); //Zapamietaj SNPlist z polaczeniem mdzy takimi adresami existingConnections.Add(existingConnKey, SNPList); List <SNPP> SNPPList = RouteTableQuery(pathBegin.Address, pathEnd, pathBegin.OccupiedCapacity); for (int index = 0; index < SNPPList.Count; index += 2) { SNPP SNPPpathBegin = SNPPList[index]; SNPP SNPPpathEnd = SNPPList[index + 1]; Tuple <SNP, SNP> SNPpair = LinkConnectionRequest(SNPPpathBegin, SNPPpathEnd, pathBegin.OccupiedCapacity); SNPList.Add(SNPpair.Item1); SNPList.Add(SNPpair.Item2); } //Wysłanie ConnectionRequesta do podsieci, jeżeli na liscie SNP zajdą się 2 adresy brzegowe tej podsieci List <SNP> connected = new List <SNP>(); for (int index = 0; index < SNPList.Count - 1; index++) { SNP SNPpathBegin = SNPList[index]; for (int jndex = index + 1; jndex < SNPList.Count; jndex++) { SNP SNPpathEnd = SNPList[jndex]; if (BelongsToSubnetwork(SNPpathBegin, SNPpathEnd)) { LogClass.WhiteLog("[DEBUG] Sending ConnectionRequest between" + SNPpathBegin.Address + SNPpathEnd.Deleting + "and" + SNPpathEnd.Address + SNPpathBegin.Deleting); if (ConnectionRequestOut(SNPpathBegin, SNPpathEnd)) { connected.Add(SNPpathBegin); connected.Add(SNPpathEnd); LogClass.Log("Subnetwork Connection set properly."); } else { connected.ForEach(x => x.Deleting = true); for (int i = 0; i < connected.Count; i += 2) { DeleteLinkConnectionRequest(connected.ElementAt(i), connected.ElementAt(i + 1)); } for (int i = 0; i < connected.Count; i += 2) { ConnectionRequestOut(connected.ElementAt(i), connected.ElementAt(i + 1)); LogClass.WhiteLog("[DEBUG] Sending DeleteConnectionRequest between" + SNPpathBegin.Address + SNPpathEnd.Deleting + "and" + SNPpathEnd.Address + SNPpathBegin.Deleting); } SubnetworkServer.callIgnoreLinkInRC(SNPpathBegin); SubnetworkServer.callIgnoreLinkInRC(SNPpathEnd); LogClass.Log("Epic fail."); return(false); } } } } return(true); //Jesli polaczenie zestawiono poprawnie }
private bool DeletePeerCoordinationOut(SNP lastSNPinThisDomain, string pathEndAddressFromDifferentDomain) { LogClass.WhiteLog("[CC] Sending deletePeerCoordination: " + lastSNPinThisDomain.Address + " to " + pathEndAddressFromDifferentDomain); return(SubnetworkServer.SendPeerCoordination(lastSNPinThisDomain, pathEndAddressFromDifferentDomain, false)); }