Exemple #1
0
        public static bool SendPeerCoordination(SNP SNPpathBegin, string AddressPathEnd, bool val)

        {
            Tuple <SNP, string> peerTuple         = new Tuple <SNP, string>(SNPpathBegin, AddressPathEnd);
            CSocket             otherDomainSocket = GetSocketToDomain(AddressPathEnd);

            if (val)
            {
                otherDomainSocket.SendObject(null, new Dictionary <string, string>());
                otherDomainSocket.SendObject(PEER_COORDINATION, peerTuple);
            }
            else
            {
                otherDomainSocket.SendObject(null, new Dictionary <string, string>());
                otherDomainSocket.SendObject(DELETE_PEER_COORDINATION, peerTuple);
            }
            string response = otherDomainSocket.ReceiveObject().Item1;

            //otherDomainSocket.Close();
            if (response.Equals(CSocket.ACK_FUNCTION))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
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);
        }
Exemple #3
0
        public static bool SendConnectionRequest(SNP pathBegin, SNP pathEnd, SubnetworkAddress subnetworkAddress)
        {
            Tuple <SNP, SNP> connTuple = new Tuple <SNP, SNP>(pathBegin, pathEnd);
            bool             hasValue  = SocketsByAddress.TryGetValue(subnetworkAddress, out childSubSocket);

            if (hasValue)
            {
                if (pathBegin.Deleting)
                {
                    childSubSocket.SendObject(DELETE_CONNECTION_REQUEST, connTuple);
                }
                else
                {
                    childSubSocket.SendObject(CONNECTION_REQUEST_FROM_CC, connTuple);
                }

                while (!(acked || nacked))
                {
                    Thread.Sleep(30);
                }

                if (acked)
                {
                    if (pathBegin.Deleting)
                    {
                        LogClass.MagentaLog("Subnetwork " + subnetworkAddress.subnetAddress + " deleted connection between: " + pathBegin.Address + " and " + pathEnd.Address);
                    }
                    else
                    {
                        LogClass.GreenLog("Subnetwork " + subnetworkAddress.subnetAddress + " set connection between: " + pathBegin.Address + " and " + pathEnd.Address);
                    }
                    acked = false;
                    return(true);
                }
                else if (nacked)
                {
                    if (pathBegin.Deleting)
                    {
                        LogClass.Log("Subnetwork " + subnetworkAddress.subnetAddress + " can't delete the connection between: " + pathBegin.Address + " and " + pathEnd.Address);
                    }
                    else
                    {
                        LogClass.Log("Subnetwork " + subnetworkAddress.subnetAddress + " can't set up the connection between: " + pathBegin.Address + " and " + pathEnd.Address);
                    }
                    nacked = false;
                    return(false);
                }
            }
            else
            {
                LogClass.Log("Can't find subnetwork: " + subnetworkAddress.ToString());
            }
            return(false);
        }
Exemple #4
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);
 }
Exemple #5
0
        public bool DeletePeerCoordinationIn(SNP pathBegin, string pathEnd)
        {
            LogClass.Log("[DEBUG] incoming deletepeercoordination from" + pathBegin.Address + " to " + pathEnd);
            List <SNP> SNPList = null;

            foreach (string[] key in existingConnections.Keys)
            {
                if ((key[0] == pathBegin.Address && key[1] == pathEnd) || (key[1] == pathBegin.Address && key[0] == pathEnd))
                {
                    SNPList = existingConnections[key];
                }
            }

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

            //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 (DeleteConnectionRequestOut(SNPpathBegin, SNPpathEnd))
                        {
                            LogClass.Log("Deleting " + SNPpathBegin.Address + " - " + SNPpathEnd.Address + " successful.");
                        }
                        else
                        {
                            LogClass.Log("Epic fail xD");
                            return(false);
                        }
                    }
                }
            }


            return(true);  //Jesli polaczenie zestawiono poprawnie
        }
Exemple #6
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);
        }
Exemple #7
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);
        }
Exemple #8
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));
        }
Exemple #9
0
        private void RemoveLink(SNP SNPpathBegin, SNP SNPpathEnd)
        {
            List <SNP> existingSNPs = new List <SNP>();

            if (SNPsbySNPPaddress.ContainsKey(SNPpathBegin.Address))
            {
                SNP BeginToBeDeleted = SNPsbySNPPaddress[SNPpathBegin.Address].Find(x => x.Address == SNPpathBegin.Address);
                SNPsbySNPPaddress[SNPpathBegin.Address].Remove(BeginToBeDeleted);
                Topology(SNPpathBegin);
                CustomSocket.LogClass.WhiteLog("[LRM] Sending topology update: deallocate " + SNPpathBegin.OccupiedCapacity + "Mbit/s on " + SNPpathBegin.Address);
            }

            if (SNPsbySNPPaddress.ContainsKey(SNPpathEnd.Address))
            {
                SNP EndToBeDeleted = SNPsbySNPPaddress[SNPpathEnd.Address].Find(x => x.Address == SNPpathEnd.Address);
                SNPsbySNPPaddress[SNPpathEnd.Address].Remove(EndToBeDeleted);
                Topology(SNPpathEnd);
                CustomSocket.LogClass.WhiteLog("[LRM] Sending topology update: deallocate " + SNPpathEnd.OccupiedCapacity + "Mbit/s on " + SNPpathEnd.Address);
            }
        }
Exemple #10
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);
        }
Exemple #11
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
        }
Exemple #12
0
 internal static void callIgnoreLinkInRC(SNP snpPathBegin)
 {
     routingController.IgnoreLink(snpPathBegin);
 }
Exemple #13
0
 public static void SendTopologyUpdateToRC(bool delete, SNP localTopologyUpdate)
 {
     routingController.LocalTopologyIn(delete, localTopologyUpdate);
 }
Exemple #14
0
 private static void WaitForInput(CSocket connected)
 {
     if (!connected.Equals(toParentSocket))
     {
         ProcessConnectInformation(connected);
     }
     while (true)
     {
         Tuple <String, Object> received = connected.ReceiveObject();
         String parameter      = received.Item1;
         Object receivedObject = received.Item2;
         if (parameter.Equals(SNPP_SUBNETWORK_INFORMATION))
         {
             InsertSNPPSToRC((List <SNPP>)receivedObject);
         }
         else if (parameter.Equals(CONNECTION_REQUEST_FROM_NCC))
         {
             MessageParameters parameters    = (MessageParameters)receivedObject;
             String            sourceIP      = parameters.getFirstParameter();
             String            destinationIP = parameters.getSecondParameter();
             int capacity = parameters.getCapacity();
             LogClass.CyanLog("Received CONNECTION REQUEST from NCC.");
             bool    success = connectionController.ConnectionRequestFromNCC(sourceIP, destinationIP, capacity);
             String  parentSubnetworkAddress = "127.0.0.1";
             CSocket c = new CSocket(IPAddress.Parse(parentSubnetworkAddress), 40000, CSocket.CONNECT_FUNCTION);
             SendACKorNACK(success, c);
         }
         else if (parameter.Equals(PEER_COORDINATION))
         {
             Tuple <SNP, string> receivedPair = (Tuple <SNP, string>)receivedObject;
             LogClass.CyanLog("Received PEER COORDINATION from AS 1");
             bool success = connectionController.PeerCoordinationIn(receivedPair.Item1, receivedPair.Item2);
             SendACKorNACK(success, connected);
         }
         else if (parameter.Equals(DELETE_PEER_COORDINATION))
         {
             Tuple <SNP, string> receivedPair = (Tuple <SNP, string>)receivedObject;
             LogClass.CyanLog("Received DELETE PEER COORDINATION from AS 1");
             bool success = connectionController.DeletePeerCoordinationIn(receivedPair.Item1, receivedPair.Item2);
             SendACKorNACK(success, connected);
         }
         else if (parameter.Equals(NETWORK_TOPOLOGY))
         {
         }
         else if (parameter.Equals(CONNECTION_REQUEST_FROM_CC))
         {
             Tuple <SNP, SNP> pathToAssign = (Tuple <SNP, SNP>)received.Item2;
             SNP first  = pathToAssign.Item1;
             SNP second = pathToAssign.Item2;
             LogClass.CyanLog("Received CONNECTION REQUEST to set connection between " + first.Address + " and " + second.Address);
             bool response = callConnectionRequest(pathToAssign.Item1, pathToAssign.Item2);
             SendACKorNACK(response, connected);
         }
         else if (parameter.Equals(CALL_TEARDOWN))
         {
             MessageParameters parameters    = (MessageParameters)receivedObject;
             String            sourceIP      = parameters.getFirstParameter();
             String            destinationIP = parameters.getSecondParameter();
             LogClass.CyanLog("Received TEARDOWN to deallocate connection between " + sourceIP + " and " + destinationIP);
             bool    success = connectionController.DeleteConnection(sourceIP, destinationIP);
             String  parentSubnetworkAddress = "127.0.0.1";
             CSocket c = new CSocket(IPAddress.Parse(parentSubnetworkAddress), 40000, CSocket.CONNECT_FUNCTION);
             SendACKorNACK(success, c);
         }
         else if (parameter.Equals(DELETE_CONNECTION_REQUEST))
         {
             Tuple <SNP, SNP> pathToDelete = (Tuple <SNP, SNP>)received.Item2;
             string           pathBegin    = pathToDelete.Item1.Address;
             string           pathEnd      = pathToDelete.Item2.Address;
             LogClass.CyanLog("Received DELETE CONNECTION REQUEST to delete connection between " + pathBegin + " and " + pathEnd);
             bool success = connectionController.DeleteConnection(pathBegin, pathEnd);
             SendACKorNACK(success, connected);
         }
         else if (parameter.Equals(CSocket.ACK_FUNCTION))
         {
             LogClass.CyanLog("Received ACK");
             acked = true;
         }
         else if (parameter.Equals(CSocket.NACK_FUNCTION))
         {
             LogClass.CyanLog("Received NACK");
             nacked = true;
         }
     }
 }
Exemple #15
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
        }
Exemple #16
0
 public static void CallDeleteLinkConnectionRequestInLRM(SNP SNPpathBegin, SNP SNPpathEnd, int capacity)
 {
     linkResourceManager.SNPLinkConnectionRequest(SNPpathBegin, SNPpathEnd, capacity);
 }
Exemple #17
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);
            }
        }
Exemple #18
0
        internal void IgnoreLink(SNP snp)
        {
            Link link = links.Find(x => (x.FirstSNPP.Address.Equals(snp.Address) || x.SecondSNPP.Address.Equals(snp.Address)));

            link.ignore = true;
        }
Exemple #19
0
 private bool DeletePeerCoordinationOut(SNP lastSNPinThisDomain, string pathEndAddressFromDifferentDomain)
 {
     LogClass.WhiteLog("[CC] Sending deletePeerCoordination: " + lastSNPinThisDomain.Address + " to " + pathEndAddressFromDifferentDomain);
     return(SubnetworkServer.SendPeerCoordination(lastSNPinThisDomain, pathEndAddressFromDifferentDomain, false));
 }
Exemple #20
0
 private bool PeerCoordinationOut(SNP SNPpathBegin, string AddressPathEnd)
 {
     LogClass.WhiteLog("[CC] Sending peerCoordination: " + SNPpathBegin.Address + " to " + AddressPathEnd);
     return(SubnetworkServer.SendPeerCoordination(SNPpathBegin, AddressPathEnd, true));
 }
Exemple #21
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
        }
Exemple #22
0
 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);
 }
Exemple #23
0
 private void DeleteLinkConnectionRequest(SNP SNPpathBegin, SNP SNPpathEnd)
 {
     SubnetworkServer.CallDeleteLinkConnectionRequestInLRM(SNPpathBegin, SNPpathEnd, 0);
 }
Exemple #24
0
 private static bool callConnectionRequest(SNP pathBegin, SNP pathEnd)
 {
     return(connectionController.ConnectionRequestFromCC(pathBegin, pathEnd));
 }