Ejemplo n.º 1
0
 private bool BelongsToSubnetwork(SNP SNPstart, SNP SNPend)
 {
     //sprawdza, czy ma taka pare na liscie
     foreach (SubnetworkAddress subAddress in ContainedSubnetworksAddresses)
     {
         if (IPAddressExtensions.IsInSameSubnet(IPAddress.Parse(SNPstart.Address), IPAddress.Parse(SNPend.Address), subAddress.subnetMask))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 2
0
        public static CSocket GetSocketToDomain(string address)
        {
            IPAddress         ipAddress = IPAddress.Parse(address);
            SubnetworkAddress found     = null;

            foreach (SubnetworkAddress domainAddress in SocketsToAnotherDomains.Keys)
            {
                if (IPAddressExtensions.IsInSameSubnet(ipAddress, domainAddress.subnetAddress, domainAddress.subnetMask))
                {
                    found = domainAddress;
                }
            }
            return(createSocketToOtherDomain(found));
        }
Ejemplo n.º 3
0
        private SubnetworkAddress findSubnetworkWhereIsContained(IPAddress isContained)
        {
            IPAddress         subnetAddress = null;
            IPAddress         subnetMask    = null;
            SubnetworkAddress subnetworkAddressWhereIsContained = null;

            foreach (SubnetworkAddress address in subnetworks)
            {
                subnetAddress = address.subnetAddress;
                subnetMask    = address.subnetMask;
                if (IPAddressExtensions.IsInSameSubnet(subnetAddress, isContained, subnetMask))
                {
                    subnetworkAddressWhereIsContained = address;
                }
            }
            return(subnetworkAddressWhereIsContained);
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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
        }
Ejemplo n.º 7
0
        public bool DeleteConnection(string pathBegin, string pathEnd)
        {
            List <SNP> SNPList = null;

            LogClass.Log("[DEBUG] deleting connection between" + pathBegin + " to " + pathEnd);
            //new string[] { pathBegin, pathEnd }
            foreach (string[] key in existingConnections.Keys)
            {
                if ((key[0] == pathBegin && key[1] == pathEnd) || (key[1] == pathBegin && key[0] == pathEnd))
                {
                    SNPList = existingConnections[key];
                }
            }

            //w kazdym SNP ustaw "deleting" na true
            SNPList.ForEach(x => x.Deleting = true);

            string PathEndAddressFromDifferentDomain = null;

            //usuniecie alokacji w LRM
            for (int index = 0; index < SNPList.Count; index += 2)
            {
                SNP SNPpathBegin = SNPList[index];
                SNP SNPpathEnd   = SNPList[index + 1];
                DeleteLinkConnectionRequest(SNPpathBegin, SNPpathEnd);
            }

            //Wysłanie DeleteConnectionRequesta do podsieci, jeżeli na liscie SNP znajdą 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("Deleting " + SNPpathBegin.Address + " - " + SNPpathEnd.Address + " successful.");
                        }
                        else
                        {
                            LogClass.Log("Epic fail xD");
                            return(false);
                        }
                    }
                }
            }

            //sprawdzamy, czy adres koncowy jest w naszej domenie
            if (!IPAddressExtensions.IsInSameSubnet(IPAddress.Parse(pathEnd), IPAddress.Parse(SubnetworkAddress), IPAddress.Parse(SubnetworkMask)))
            {
                PathEndAddressFromDifferentDomain = pathEnd;

                //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;
                            }
                        }
                    }
                }

                if (DeletePeerCoordinationOut(lastSNPinThisDomain, PathEndAddressFromDifferentDomain))
                {
                    LogClass.Log("DeletePeerCoordination OK.");
                }
                else
                {
                    LogClass.Log("PeerCoordination FAIL.");
                };
            }
            return(true);  //Jesli polaczenie zestawiono poprawnie
        }
Ejemplo n.º 8
0
        // % % % % % % % % % % % % % % % % % % % % % % % % % //
        // %%%%%%%%%%%%%%%%% 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);
            }
        }