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 }
public bool ConnectionRequestFromCC(SNP pathBegin, SNP pathEnd) { List <SNPP> SNPPList = RouteTableQuery(pathBegin.Address, pathEnd.Address, pathBegin.OccupiedCapacity); //Lista SNP dla tworzonego aktualnie polaczenia List <SNP> SNPList = new List <SNP>(); SNPList.Add(pathBegin); SNPList.Add(pathEnd); 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); } //Zapamietaj SNPlist z polaczeniem mdzy takimi adresami existingConnections.Add(new string[] { pathBegin.Address, pathEnd.Address }, SNPList); //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)) { 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)); } SubnetworkServer.callIgnoreLinkInRC(SNPpathBegin); SubnetworkServer.callIgnoreLinkInRC(SNPpathEnd); LogClass.Log("Epic fail."); return(false); } } } } return(true); //Jesli polaczenie zestawiono poprawnie }