static void Main(string[] args) { string[] arguments = Environment.GetCommandLineArgs(); try { SubnetworkConfig.LoadConfig(arguments[1]); } catch (Exception e) { Console.WriteLine(e.Message); Console.ReadLine(); Environment.ExitCode = 0; } SubnetworkServer subnetworkServer = new SubnetworkServer(); subnetworkServer.ExternalAddress = SubnetworkConfig.externalAddress; subnetworkServer.StartListener(arguments[2], arguments[3], arguments[4]); Console.ReadLine(); }
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 bool DeleteConnectionRequestOut(SNP pathBegin, SNP pathEnd) { LogClass.Log("[DEBUG] sending delete connection request out between " + pathBegin.Address + " and " + pathEnd.Address); //wysyla do cc poziom niżej wiadomosc usuwaj jak szalony konik 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()); SubnetworkServer.SendConnectionRequest(pathBegin, pathEnd, subnetAddress); return(true); }
static void Main(string[] args) { Console.Title = "Subnetwork " + CustomSocket.Config.getProperty("SubnetworkAddress"); ConnectionController CC = new ConnectionController(); LinkResourceManager LRM = new LinkResourceManager(); RoutingController RC = new RoutingController(CC.ContainedSubnetworksAddresses, LRM.Links); SubnetworkServer.init(CC, RC, LRM); LoadEdgeSNPPs(CC, LRM); string decision; do { decision = Console.ReadLine().Trim(); if (decision.StartsWith("kill")) { string[] killParams = decision.Split(' '); string firstSNPaddress = killParams[1]; string secondSNPaddress = killParams[2]; CustomSocket.LogClass.MagentaLog("Removing link: " + firstSNPaddress + " - " + secondSNPaddress); List <Tuple <string, string, int> > pathsToReroute = CC.GetPathsContainingThisSNP(firstSNPaddress); foreach (var path in pathsToReroute) { CC.DeleteConnection(path.Item1, path.Item2); RC.DeleteLink(firstSNPaddress, secondSNPaddress); CC.ConnectionRequestFromNCC(path.Item1, path.Item2, path.Item3); } } else if (decision.StartsWith("restore")) { string[] restoreParams = decision.Split(' '); string firstSNPPaddress = restoreParams[1]; string secondSNPPaddress = restoreParams[2]; RC.RestoreLink(firstSNPPaddress, secondSNPPaddress); } }while (decision != "exit"); }
private void Topology(SNP localTopologyUpdate) { //wysyła SNP, które zostało uaktualnione do RC //Wywołanie metody serwera, która jeszcze nie jest zrobiona SubnetworkServer.SendTopologyUpdateToRC(localTopologyUpdate.Deleting, localTopologyUpdate); }
private bool DeletePeerCoordinationOut(SNP lastSNPinThisDomain, string pathEndAddressFromDifferentDomain) { LogClass.WhiteLog("[CC] Sending deletePeerCoordination: " + lastSNPinThisDomain.Address + " to " + pathEndAddressFromDifferentDomain); return(SubnetworkServer.SendPeerCoordination(lastSNPinThisDomain, pathEndAddressFromDifferentDomain, 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 }
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 }
private void DeleteLinkConnectionRequest(SNP SNPpathBegin, SNP SNPpathEnd) { SubnetworkServer.CallDeleteLinkConnectionRequestInLRM(SNPpathBegin, SNPpathEnd, 0); }
private Tuple <SNP, SNP> LinkConnectionRequest(SNPP connectionBegin, SNPP connectionEnd, int capacity) { Tuple <SNP, SNP> SNPpair = SubnetworkServer.callLinkConnectionRequestInLRM(connectionBegin, connectionEnd, capacity); return(SNPpair); }
private List <SNPP> RouteTableQuery(string pathBegin, string pathEnd, int capacity) { List <SNPP> SNPPlist = SubnetworkServer.callRouteTableQueryInRC(pathBegin, pathEnd, capacity); return(SNPPlist); }