Example #1
0
 public void AddKeyToDictionary(SubnetworkAddress key)
 {
     if (!OtherDomainSNPPAddressTranslation.ContainsKey(key))
     {
         OtherDomainSNPPAddressTranslation.Add(key, new List <Tuple <IPAddress, IPAddress> >());
     }
 }
Example #2
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);
        }
Example #3
0
        public static CSocket createSocketToOtherDomain(SubnetworkAddress address)
        {
            int     port   = SocketsToAnotherDomains[address];
            CSocket socket = new CSocket(IPAddress.Parse("127.0.0.1"), port, CSocket.CONNECT_FUNCTION);

            return(socket);
        }
Example #4
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);
        }
Example #5
0
        private static object GetSubnetworkInformation()
        {
            Dictionary <string, string> mySubnetworkInformation = new Dictionary <string, string>();
            string            mySubnetworkAddress = Config.getProperty(OPERATED_SUBNETWORK);
            string            mySubnetworkMask    = Config.getProperty(OPERATED_SUBNETWORK_MASK);
            SubnetworkAddress address             = new SubnetworkAddress(mySubnetworkAddress, mySubnetworkMask);

            mySubnetworkInformation.Add(OPERATED_SUBNETWORK, mySubnetworkAddress);
            mySubnetworkInformation.Add(OPERATED_SUBNETWORK_MASK, mySubnetworkMask);
            return(mySubnetworkInformation);
        }
Example #6
0
 public List <Tuple <IPAddress, IPAddress> > GetFromDictionary(SubnetworkAddress address)
 {
     foreach (KeyValuePair <SubnetworkAddress, List <Tuple <IPAddress, IPAddress> > > entry in OtherDomainSNPPAddressTranslation)
     {
         if (entry.Key.subnetAddress.Equals(address.subnetAddress) && entry.Key.subnetMask.Equals(address.subnetMask))
         {
             return(entry.Value);
         }
     }
     return(null);
 }
 public bool Equals(SubnetworkAddress other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(other.subnetAddress.Equals(subnetAddress) && other.subnetMask.Equals(subnetMask));
 }
Example #8
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));
        }
Example #9
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);
        }
Example #10
0
        private static void ProcessConnectInformation(CSocket connectedSocket)
        {
            Tuple <string, object>      received            = connectedSocket.ReceiveObject();
            Dictionary <string, string> receivedInformation = (Dictionary <string, string>)received.Item2;

            if (receivedInformation.Count == 0)
            {
                toNCCSocket = connectedSocket;
            }
            else
            {
                String            operatedSubnetwork     = receivedInformation[OPERATED_SUBNETWORK];
                String            operatedSubnetworkMask = receivedInformation[OPERATED_SUBNETWORK_MASK];
                SubnetworkAddress connectedSubnetAddress = new SubnetworkAddress(operatedSubnetwork, operatedSubnetworkMask);
                SocketsByAddress.Add(connectedSubnetAddress, connectedSocket);
                LogClass.Log("Subnetwork " + operatedSubnetwork + " connected.");
            }
        }
Example #11
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));
        }
Example #12
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);
        }
Example #13
0
        public void translateLinksToEdges()
        {
            List <Vertex>     vertices                = subnetwork.VertexList;
            int               counter                 = 1;
            String            firstSNPPAddress        = null;
            String            secondSNPPAddress       = null;
            SubnetworkAddress firstSubnetworkAddress  = null;
            SubnetworkAddress secondSubnetworkAddress = null;

            foreach (Link link in links)
            {
                linkAndEdgeIdCorrelation.Add(link, counter);
                firstSNPPAddress        = link.FirstSNPP.Address;
                secondSNPPAddress       = link.SecondSNPP.Address;
                firstSubnetworkAddress  = findSubnetworkWhereIsContained(IPAddress.Parse(firstSNPPAddress));
                secondSubnetworkAddress = findSubnetworkWhereIsContained(IPAddress.Parse(secondSNPPAddress));
                int firstVertexId  = subnetworkToVertexId[firstSubnetworkAddress];
                int secondVertexId = subnetworkToVertexId[secondSubnetworkAddress];
                int capacity       = link.FirstSNPP.Capacity;
                subnetwork.addEdge(firstVertexId, secondVertexId, capacity, link.ignore);
                counter++;
            }
        }
Example #14
0
        public static void SendDeleteConnectionRequest(string pathBeginAddress, string pathEndAddress, SubnetworkAddress subnetAddress)
        {
            Tuple <string, string> deleteTuple = new Tuple <string, string>(pathBeginAddress, pathEndAddress);
            CSocket childSubSocket;
            bool    hasValue = SocketsByAddress.TryGetValue(subnetAddress, out childSubSocket);

            if (hasValue)
            {
                childSubSocket.SendObject(DELETE_CONNECTION_REQUEST, deleteTuple);
            }
            else
            {
                LogClass.Log("Can't find subnetwork: " + subnetAddress.ToString());
            }
        }
Example #15
0
        public void AddValueToDictionary(SubnetworkAddress key, Tuple <IPAddress, IPAddress> value)
        {
            List <Tuple <IPAddress, IPAddress> > list = GetFromDictionary(key);

            list.Add(value);
        }