Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public void LoadLinks()
        {
            CustomSocket.LogClass.WhiteLog("Loading links in subnetwork:");
            string fileName = Config.getProperty("subnetworkLinks");

            string[] loadedFile       = LoadFile(fileName);
            string[] subnetworkParams = null;
            string   firstNodeAddress = null;
            int      firstNodeCapacity;
            string   secondNodeAddress = null;
            int      secondNodeCapacity;
            SNPP     firstSNPP  = null;
            SNPP     secondSNPP = null;

            foreach (string str in loadedFile)
            {
                subnetworkParams   = str.Split(PARAM_SEPARATOR);
                firstNodeAddress   = subnetworkParams[LINK_NODE_A_POSITION];
                firstNodeCapacity  = Int32.Parse(subnetworkParams[LINK_NODE_A_CAPACITY_POSITION]);
                secondNodeAddress  = subnetworkParams[LINK_NODE_B_POSITION];
                secondNodeCapacity = Int32.Parse(subnetworkParams[LINK_NODE_B_CAPACITY_POSITION]);
                firstSNPP          = new SNPP(firstNodeAddress, firstNodeCapacity);
                secondSNPP         = new SNPP(secondNodeAddress, secondNodeCapacity);
                Links.Add(new Link(firstSNPP, secondSNPP));
                myEdgeSNPPs.Add(firstSNPP);
                myEdgeSNPPs.Add(secondSNPP);
                CustomSocket.LogClass.Log(str);
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        private void AddEdgeSNPP(string[] snppParams)
        {
            String snppAddress  = snppParams[ADDRESS_POSITION];
            int    snppCapacity = Int32.Parse(snppParams[CAPACITY_POSITION]);
            SNPP   edgeSNPP     = new SNPP(snppAddress, snppCapacity);

            SNPsbySNPPaddress.Add(edgeSNPP.Address, new List <SNP>());
            myEdgeSNPPs.Add(edgeSNPP);
            Console.WriteLine(edgeSNPP.ToString());
        }
Esempio n. 5
0
        // % % % % % % % % % % % % % % % % % % % % % % % % % //
        // %%%%%%%%%%%%%%%%% GŁOWNA METODA %%%%%%%%%%%%%%%%% //
        // % % % % % % % % % % % % % % % % % % % % % % % % % //


        public Tuple <SNP, SNP> SNPLinkConnectionRequest(Object pathBegin, Object pathEnd, int capacity)
        {
            Tuple <SNP, SNP> SNPpair = null;

            //LRM dostaje od CC dwa SNPP do stworzenia SNP lub dwa SNP do usuniecia
            if (pathBegin.GetType() == typeof(SNPP) && pathEnd.GetType() == typeof(SNPP))
            {
                SNPP SNPPpathBegin = (SNPP)pathBegin;
                SNPP SNPPpathEnd   = (SNPP)pathEnd;
                SNPpair = AllocateLink(SNPPpathBegin, SNPPpathEnd, capacity);
            }

            //jesli SNPPki są równe to znaczy ze są fejkowe i trzeba znaleźć SNPP o tym adresie
            else if (pathBegin == pathEnd)
            {
                SNPP   fakeSNPP = (SNPP)pathBegin;
                string address  = fakeSNPP.Address;
                SNPP   realSNPP = myEdgeSNPPs.Find(i => i.Address == address);
                if (realSNPP.Capacity > capacity)
                {
                    realSNPP.Capacity -= capacity;
                    //generuje nowy label
                    int potentiallyNewLabel = GimmeNewLabel();

                    //sprawdz, czy wygenerowany label nie wystapil w SNPs - jesli tak, wygeneruj inny label
                    if (!SNPsbySNPPaddress.ContainsKey(realSNPP.Address))
                    {
                        SNPsbySNPPaddress.Add(realSNPP.Address, new List <SNP>());
                    }

                    //tworzenie SNP poczatkowego SNPP
                    SNP createdSNP = new SNP(potentiallyNewLabel, fakeSNPP.Address, capacity); //uses remembered label
                    SNPsbySNPPaddress[fakeSNPP.Address].Add(createdSNP);
                    Topology(createdSNP);

                    SNPpair = new Tuple <SNP, SNP>(createdSNP, createdSNP);
                    return(SNPpair);
                }
            }
            else if (pathBegin.GetType() == typeof(SNP) && pathEnd.GetType() == typeof(SNP))
            {
                SNP SNPpathBegin = (SNP)pathBegin;
                SNP SNPpathEnd   = (SNP)pathEnd;
                RemoveLink(SNPpathBegin, SNPpathEnd);
            }
            return(SNPpair);
        }
Esempio n. 6
0
        private Tuple <SNP, SNP> AllocateLink(SNPP pathBegin, SNPP pathEnd, int capacity)
        {
            List <SNP>       existingSNPs = new List <SNP>();
            Tuple <SNP, SNP> SNPpair;
            SNP SNPpathBegin, SNPpathEnd;

            if (!SNPsbySNPPaddress.ContainsKey(pathBegin.Address))
            {
                SNPsbySNPPaddress.Add(pathBegin.Address, new List <SNP>());
                if (pathBegin != pathEnd)
                {
                    SNPsbySNPPaddress.Add(pathEnd.Address, new List <SNP>());
                }
            }

            //generuje nowy label
            int potentiallyNewLabel = GimmeNewLabel();

            //sprawdz, czy wygenerowany label nie wystapil w SNPs - jesli tak, wygeneruj inny label
            existingSNPs = SNPsbySNPPaddress[pathBegin.Address];
            while (existingSNPs.Find(x => x.Label == potentiallyNewLabel) != null)
            {
                potentiallyNewLabel = GimmeNewLabel();
            }

            //tworzenie SNP poczatkowego SNPP
            SNPpathBegin = new SNP(potentiallyNewLabel, pathBegin.Address, capacity); //uses remembered label
            SNPsbySNPPaddress[pathBegin.Address].Add(SNPpathBegin);
            CustomSocket.LogClass.WhiteLog("[LRM] Sending topology update: allocate " + SNPpathBegin.OccupiedCapacity + "Mbit/s on " + SNPpathBegin.Address);
            Topology(SNPpathBegin);

            if (pathBegin.Address != pathEnd.Address)
            {
                //tworzenie SNP koncowego SNPP
                SNPpathEnd = new SNP(potentiallyNewLabel, pathEnd.Address, capacity); //uses generated label
                SNPsbySNPPaddress[pathEnd.Address].Add(SNPpathEnd);
                CustomSocket.LogClass.WhiteLog("[LRM] Sending topology update: allocate " + SNPpathEnd.OccupiedCapacity + "Mbit/s on " + SNPpathEnd.Address);
                Topology(SNPpathEnd);

                SNPpair = new Tuple <SNP, SNP>(SNPpathBegin, SNPpathEnd);
            }
            else
            {
                SNPpair = new Tuple <SNP, SNP>(SNPpathBegin, SNPpathBegin);
            }
            return(SNPpair);
        }
Esempio n. 7
0
        public SNPP findSNPPbyAddress(IPAddress address)
        {
            SNPP   first  = null;
            SNPP   second = null;
            SNPP   found  = null;
            String toFind = address.ToString();

            foreach (Link link in links)
            {
                first  = link.FirstSNPP;
                second = link.SecondSNPP;
                if (first.Address.Equals(toFind))
                {
                    found = first;
                }
                else if (second.Address.Equals(toFind))
                {
                    found = second;
                }
            }
            return(found);
        }
Esempio n. 8
0
 public void AddEdgeSNPP(SNPP snpp)
 {
     myEdgeSNPPs.Add(snpp);
 }
Esempio n. 9
0
 public Link(SNPP first, SNPP second)
 {
     FirstSNPP  = first;
     SecondSNPP = second;
     ignore     = false;
 }
Esempio n. 10
0
        public static Tuple <SNP, SNP> callLinkConnectionRequestInLRM(SNPP connectionBegin, SNPP connectionEnd, int capacity)
        {
            Tuple <SNP, SNP> SNPpair = linkResourceManager.SNPLinkConnectionRequest(connectionBegin, connectionEnd, capacity);

            return(SNPpair);
        }
Esempio n. 11
0
 private void NetworkTopologyOut(SNPP localTopologyUpdate)
 {
 }
Esempio n. 12
0
 internal void AddSNPP(SNPP snpp)
 {
     throw new NotImplementedException();
 }
Esempio n. 13
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
        }
Esempio n. 14
0
        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
        }
Esempio n. 15
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);
            }
        }
Esempio n. 16
0
        private Tuple <SNP, SNP> LinkConnectionRequest(SNPP connectionBegin, SNPP connectionEnd, int capacity)
        {
            Tuple <SNP, SNP> SNPpair = SubnetworkServer.callLinkConnectionRequestInLRM(connectionBegin, connectionEnd, capacity);

            return(SNPpair);
        }