Beispiel #1
0
        /// <summary>
        /// This method checks for all the flow comming in and process it
        /// accordingly. If flow is for node itself, it pass it to comsume
        /// method otherwise it is pass to forward method. After checking
        /// is done, it call the method to sent its own flow.
        /// </summary>
        private void _FlowReciever()
        {
            this._SourceNum = this.Sources.Count;
            int i = 0;

            for (int j = 0; j < this._SourceNum; j++) //check for all flows came in from all sources
            {
                i = this.Sources.ElementAt(j);
                foreach (string key in this.InFlow[i].Keys)
                {
                    if (this.InFlow[i][key] != null)
                    {
                        if (this.InFlow[i][key].DestinationID == this.ID)
                        {
                            this._ConsumeFlow(this.InFlow[i][key].OriginID, this.InFlow[i][key].CurrFlow, i);
                        }
                        else
                        {
                            AdHocFlow flow = this.InFlow[i][key].Clone();
                            this._ForwardFlow(flow, i);
                        }
                        this.InFlow[i][key] = null;
                    }
                }
            }
            this._SendMyOwnFlow(); //send my own flow
        }
        //clone method creates new flow package with same information
        public AdHocFlow Clone()
        {
            AdHocFlow flow = new AdHocFlow();
            flow.OriginID = this.OriginID;
            flow.DestinationID = this.DestinationID;
            flow.OriginalFlow = this.OriginalFlow;
            flow.CurrFlow = this.CurrFlow;
            flow.FlowCameFrom = this.FlowCameFrom;
            flow.FlowBlockedByPrevNode = this.FlowBlockedByPrevNode;

            return flow;
        }
        //clone method creates new flow package with same information
        public AdHocFlow Clone()
        {
            AdHocFlow flow = new AdHocFlow();

            flow.OriginID              = this.OriginID;
            flow.DestinationID         = this.DestinationID;
            flow.OriginalFlow          = this.OriginalFlow;
            flow.CurrFlow              = this.CurrFlow;
            flow.FlowCameFrom          = this.FlowCameFrom;
            flow.FlowBlockedByPrevNode = this.FlowBlockedByPrevNode;

            return(flow);
        }
Beispiel #4
0
        /// <summary>
        /// this method sends its own flow to all of its destinations
        /// according to the current flow that is reaching to destinations
        /// </summary>
        private void _SendMyOwnFlow()
        {
            int   destID = 0;
            float Currdemand;

            this._DestNum = this.MyDestinationsAndDemands.Count;
            try
            {
                for (int j = 0; j < this._DestNum; j++)
                {
                    destID = MyDestinationsAndDemands.ElementAt(j).Key;

                    Currdemand = MyDestinationsAndCurrentDemands.ElementAt(j).Value;
                    AdHocFlow myFlow = new AdHocFlow();
                    myFlow.FlowCameFrom  = this.ID;
                    myFlow.OriginID      = this.ID;
                    myFlow.DestinationID = destID;
                    myFlow.OriginalFlow  = Currdemand;
                    myFlow.CurrFlow      = Currdemand;
                    myFlow.FlowCameFrom  = this.ID;
                    string key = this.ID + ":" + destID;
                    if (Targets[ForwardingTable[destID]])
                    {
                        if (NodeList.Nodes[ForwardingTable[destID]].InFlow[this.ID].ContainsKey(key))
                        {
                            NodeList.Nodes[ForwardingTable[destID]].InFlow[this.ID][key] = myFlow;
                        }
                        else
                        {
                            NodeList.Nodes[ForwardingTable[destID]].InFlow[this.ID].GetOrAdd(key, myFlow);
                        }
                    }
                    if (TargetsAndMyFlowSent[ForwardingTable[destID]].ContainsKey(destID))
                    {
                        TargetsAndMyFlowSent[ForwardingTable[destID]][destID] = Currdemand;
                    }
                    else
                    {
                        TargetsAndMyFlowSent[ForwardingTable[destID]].GetOrAdd(destID, Currdemand);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Node: " + this.ID + "was trying to send its own  flow to: " + ForwardingTable[destID] + "\n" + ex.ToString());
            }
        }
        /// <summary>
        /// this method sends its own flow to all of its destinations 
        /// according to the current flow that is reaching to destinations
        /// </summary>
        private void _SendMyOwnFlow()
        {
            int destID = 0;
            float Currdemand;

            this._DestNum = this.MyDestinationsAndDemands.Count;
            try
            {
                for (int j = 0; j < this._DestNum; j++)
                {
                    destID = MyDestinationsAndDemands.ElementAt(j).Key;

                    Currdemand = MyDestinationsAndCurrentDemands.ElementAt(j).Value;
                    AdHocFlow myFlow = new AdHocFlow();
                    myFlow.FlowCameFrom = this.ID;
                    myFlow.OriginID = this.ID;
                    myFlow.DestinationID = destID;
                    myFlow.OriginalFlow = Currdemand;
                    myFlow.CurrFlow = Currdemand;
                    myFlow.FlowCameFrom = this.ID;
                    string key = this.ID + ":" + destID;
                    if (Targets[ForwardingTable[destID]])
                    {
                        if (NodeList.Nodes[ForwardingTable[destID]].InFlow[this.ID].ContainsKey(key))
                        {
                            NodeList.Nodes[ForwardingTable[destID]].InFlow[this.ID][key] = myFlow;
                        }
                        else
                        {
                            NodeList.Nodes[ForwardingTable[destID]].InFlow[this.ID].GetOrAdd(key, myFlow);
                        }
                    }
                    if (TargetsAndMyFlowSent[ForwardingTable[destID]].ContainsKey(destID))
                    {
                        TargetsAndMyFlowSent[ForwardingTable[destID]][destID] = Currdemand;
                    }
                    else
                    {
                        TargetsAndMyFlowSent[ForwardingTable[destID]].GetOrAdd(destID, Currdemand);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Node: " + this.ID + "was trying to send its own  flow to: " + ForwardingTable[destID] + "\n" + ex.ToString());
            }
        }
        /// <summary>
        /// This method block the flow according to the source it came 
        /// from and forward rest of the flow and update its data accordingly
        /// </summary>
        /// <param name="flow">flow to send</param>
        /// <param name="sourceID">source node it came from</param>
        private void _ForwardFlow(AdHocFlow flow, int sourceID)
        {
            int target = ForwardingTable[flow.DestinationID];
            float blockRate = 0;
            float amount = flow.CurrFlow;
            float flowCame = flow.CurrFlow;
            float amountblocked = 0;
            string key = flow.OriginID + ":" + flow.DestinationID;

            blockRate = this.GetBlockRate(sourceID);
            try
            {
                if (Targets[target])
                {
                    if (flow.CurrFlow != 0)
                    {
                        amountblocked = (amount * blockRate);
                        amount = amount - amountblocked;
                        flow.CurrFlow = amount;
                        flow.FlowBlockedByPrevNode = amountblocked;
                    }
                    flow.FlowCameFrom = this.ID;

                    if (NodeList.Nodes[target].InFlow[this.ID].ContainsKey(key))
                    {
                        NodeList.Nodes[target].InFlow[this.ID][key] = flow;
                    }
                    else
                    {
                        NodeList.Nodes[target].InFlow[this.ID].GetOrAdd(key, flow);
                    }

                }
                else
                {
                    NodeList.Nodes[flow.OriginID].FlowReached[flow.DestinationID] = 0;
                }

                float[] flowVals = new float[2];
                flowVals[0] = flow.CurrFlow;
                flowVals[1] = flowCame;
                if (this.SourcesAndFlowForwarded[sourceID].ContainsKey(key))
                {
                    this.SourcesAndFlowForwarded[sourceID][key] = flowVals;
                }
                else
                {
                    this.SourcesAndFlowForwarded[sourceID].GetOrAdd(key, flowVals);
                }
                if (this.TargetsAndFlowForwarded[target].ContainsKey(key))
                {
                    this.TargetsAndFlowForwarded[target][key] = flowVals[0];
                }
                else
                {
                    this.TargetsAndFlowForwarded[target].GetOrAdd(key, flowVals[0]);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Node: " + this.ID + "was trying to forward  flow to: " + target + "\n" + ex.ToString());
            }
        }
Beispiel #7
0
        /// <summary>
        /// This method block the flow according to the source it came
        /// from and forward rest of the flow and update its data accordingly
        /// </summary>
        /// <param name="flow">flow to send</param>
        /// <param name="sourceID">source node it came from</param>
        private void _ForwardFlow(AdHocFlow flow, int sourceID)
        {
            int    target        = ForwardingTable[flow.DestinationID];
            float  blockRate     = 0;
            float  amount        = flow.CurrFlow;
            float  flowCame      = flow.CurrFlow;
            float  amountblocked = 0;
            string key           = flow.OriginID + ":" + flow.DestinationID;

            blockRate = this.GetBlockRate(sourceID);
            try
            {
                if (Targets[target])
                {
                    if (flow.CurrFlow != 0)
                    {
                        amountblocked = (amount * blockRate);
                        amount        = amount - amountblocked;
                        flow.CurrFlow = amount;
                        flow.FlowBlockedByPrevNode = amountblocked;
                    }
                    flow.FlowCameFrom = this.ID;

                    if (NodeList.Nodes[target].InFlow[this.ID].ContainsKey(key))
                    {
                        NodeList.Nodes[target].InFlow[this.ID][key] = flow;
                    }
                    else
                    {
                        NodeList.Nodes[target].InFlow[this.ID].GetOrAdd(key, flow);
                    }
                }
                else
                {
                    NodeList.Nodes[flow.OriginID].FlowReached[flow.DestinationID] = 0;
                }

                float[] flowVals = new float[2];
                flowVals[0] = flow.CurrFlow;
                flowVals[1] = flowCame;
                if (this.SourcesAndFlowForwarded[sourceID].ContainsKey(key))
                {
                    this.SourcesAndFlowForwarded[sourceID][key] = flowVals;
                }
                else
                {
                    this.SourcesAndFlowForwarded[sourceID].GetOrAdd(key, flowVals);
                }
                if (this.TargetsAndFlowForwarded[target].ContainsKey(key))
                {
                    this.TargetsAndFlowForwarded[target][key] = flowVals[0];
                }
                else
                {
                    this.TargetsAndFlowForwarded[target].GetOrAdd(key, flowVals[0]);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Node: " + this.ID + "was trying to forward  flow to: " + target + "\n" + ex.ToString());
            }
        }