Esempio n. 1
0
        public RoutingTable CalculateRoutingTableForDevice(string deviceName)
        {
            RoutingTable rt = new RoutingTable(deviceName);

            List <Device> associatedDevices = devices.Where(x => GetParent(x.name) == deviceName).ToList();

            if (associatedDevices.Count == 0)
            {
                throw new ApplicationException("no devices are associated to routing table!");
            }

            List <Connection> associatedConnections = connections.Where(
                x => associatedDevices.Contains(x.source) && associatedDevices.Contains(x.destination)).ToList();

            foreach (Connection conn in associatedConnections)
            {
                if (conn.slots == null)
                {
                    continue;
                }

                List <Connection> inputConnections =
                    conn.source.incomingConnections.FindAll(x => !associatedConnections.Contains(x));
                if (inputConnections.Count != 1)
                {
                    throw new ApplicationException("topology is broken!");
                }
                Connection inputConnection = inputConnections[0];

                List <Connection> outputConnections =
                    conn.destination.outgoingConnections.FindAll(x => !associatedConnections.Contains(x));
                if (outputConnections.Count != 1)
                {
                    throw new ApplicationException("topology is broken!");
                }
                Connection outputConnection = outputConnections[0];

                //TODO:make set
                List <Link> linkAllocatedOnCurrConnection = new List <Link>();

                foreach (Slot takenSlot in conn.slots.Where(x => x.state == Slot.State.TAKEN))
                {
                    if (!linkAllocatedOnCurrConnection.Contains(takenSlot.slotOWner))
                    {
                        linkAllocatedOnCurrConnection.Add(takenSlot.slotOWner);
                    }
                }

                foreach (Link link in linkAllocatedOnCurrConnection)
                {
                    RoutingEntity re = new RoutingEntity();
                    re.linkName = link.name;
                    re.deviceConnectedOnOutput = outputConnection.destination.name;
                    re.inputDevice             = conn.source.name;
                    re.outputDevice            = conn.destination.name;

                    int firstIndexOnInput          = inputConnection.slots.FindIndex(x => x.slotOWner == link);
                    int allocatedSlotsCountOnInput = inputConnection.slots.Count(x => x.slotOWner == link);
                    re.inputIndex  = firstIndexOnInput;
                    re.inputModulo = inputConnection.slots.Count / allocatedSlotsCountOnInput;
                    if (re.inputIndex >= re.inputModulo)
                    {
                        throw new ApplicationException("index should be lower than modulo!");
                    }

                    int firstIndexOnOutput         = outputConnection.slots.FindIndex(x => x.slotOWner == link);
                    int allocatedSlotsCountOnOuput = outputConnection.slots.Count(x => x.slotOWner == link);
                    re.outputIndex  = firstIndexOnOutput;
                    re.outputModulo = outputConnection.slots.Count / allocatedSlotsCountOnOuput;
                    if (re.outputIndex >= re.outputModulo)
                    {
                        throw new ApplicationException("index should be lower than modulo!");
                    }

                    rt.routingEntities.Add(re);
                }
            }

            return(rt);
        }
Esempio n. 2
0
        public RoutingTable CalculateRoutingTableForDevice(string deviceName)
        {
            RoutingTable rt = new RoutingTable(deviceName);

            List<Device> associatedDevices = devices.Where(x => GetParent(x.name) == deviceName).ToList();
            if (associatedDevices.Count == 0)
                throw new ApplicationException("no devices are associated to routing table!");

            List<Connection> associatedConnections = connections.Where(
                x => associatedDevices.Contains(x.source) && associatedDevices.Contains(x.destination)).ToList();

            foreach (Connection conn in associatedConnections)
            {
                if (conn.slots == null) continue;

                List<Connection> inputConnections =
                    conn.source.incomingConnections.FindAll(x => !associatedConnections.Contains(x));
                if (inputConnections.Count != 1)
                    throw new ApplicationException("topology is broken!");
                Connection inputConnection = inputConnections[0];

                List<Connection> outputConnections =
                    conn.destination.outgoingConnections.FindAll(x => !associatedConnections.Contains(x));
                if (outputConnections.Count != 1)
                    throw new ApplicationException("topology is broken!");
                Connection outputConnection = outputConnections[0];

                //TODO:make set
                List<Link> linkAllocatedOnCurrConnection = new List<Link>();

                foreach (Slot takenSlot in conn.slots.Where(x => x.state == Slot.State.TAKEN))
                {
                    if (!linkAllocatedOnCurrConnection.Contains(takenSlot.slotOWner))
                        linkAllocatedOnCurrConnection.Add(takenSlot.slotOWner);
                }

                foreach (Link link in linkAllocatedOnCurrConnection)
                {
                    RoutingEntity re = new RoutingEntity();
                    re.linkName = link.name;
                    re.deviceConnectedOnOutput = outputConnection.destination.name;
                    re.inputDevice = conn.source.name;
                    re.outputDevice = conn.destination.name;

                    int firstIndexOnInput = inputConnection.slots.FindIndex(x => x.slotOWner == link);
                    int allocatedSlotsCountOnInput = inputConnection.slots.Count(x => x.slotOWner == link);
                    re.inputIndex = firstIndexOnInput;
                    re.inputModulo = inputConnection.slots.Count / allocatedSlotsCountOnInput;
                    if (re.inputIndex >= re.inputModulo)
                        throw new ApplicationException("index should be lower than modulo!");

                    int firstIndexOnOutput = outputConnection.slots.FindIndex(x => x.slotOWner == link);
                    int allocatedSlotsCountOnOuput = outputConnection.slots.Count(x => x.slotOWner == link);
                    re.outputIndex = firstIndexOnOutput;
                    re.outputModulo = outputConnection.slots.Count / allocatedSlotsCountOnOuput;
                    if (re.outputIndex >= re.outputModulo)
                        throw new ApplicationException("index should be lower than modulo!");

                    rt.routingEntities.Add(re);
                }

            }

            return rt;
        }