Пример #1
0
        private void RegisterQueryPlacementOnNode(Query q, NodeName n)
        {
            if (!sourceNodesByEventName.ContainsKey(q.name))
            {
                sourceNodesByEventName[q.name] = new HashSet <NodeName>()
                {
                    n
                };
            }
            else
            {
                sourceNodesByEventName[q.name].Add(n);
            }

            if (!queriesByNodeName.ContainsKey(n))
            {
                queriesByNodeName[n] = new HashSet <Query>()
                {
                    q
                };;
            }
            else
            {
                queriesByNodeName[n].Add(q);
            }
        }
Пример #2
0
        /// Parse network plan (which nodes generate which primitive events at what rate)
        private void parseNetworkPlan(string[] inputlines)
        {
            int nodeID = -1;

            numberOfNodes = -1;

            foreach (string line in inputlines)
            {
                if (line.StartsWith("-"))
                {
                    numberOfNodes = nodeID + 1;
                    // finished with parsing the network plan
                    return;
                }

                nodeID++;
                var currentNodeName = new NodeName(nodeID.ToString());

                int[]       rates      = Array.ConvertAll(line.Trim().Split(' '), Int32.Parse);
                EventType[] eventNames = EventNameSequence.Substring(0, rates.Length).Select(c => new EventType(c.ToString())).ToArray();

                if (primitiveEventNames == null)
                {
                    primitiveEventNames = new HashSet <EventType>(eventNames);
                }

                NodeParams nodeParams = new NodeParams(currentNodeName, eventNames, rates);
                networkPlan[currentNodeName] = nodeParams;

                foreach (var e in eventNames.Zip(rates, (e, r) => new { Name = e, Rate = r }))
                {
                    if (e.Rate > 0)
                    {
                        if (!sourceNodesByEventName.ContainsKey(e.Name))
                        {
                            sourceNodesByEventName[e.Name] = new HashSet <NodeName>()
                            {
                                currentNodeName
                            };
                        }
                        else
                        {
                            sourceNodesByEventName[e.Name].Add(currentNodeName);
                        }
                    }
                }
            }

            throw new ArgumentException("Expected ---- separation line after the network plan information was not found.");
        }
Пример #3
0
        public PlacementInfo(string placementstring)
        {
            string remaining = placementstring;

            if (placementstring[0] == '{')
            {
                string specificNodesString = placementstring.Split('/')[0];

                var nodenamestrings = specificNodesString.TrimStart('{').TrimEnd('}').Split(',');

                if (nodenamestrings.Length == 1)
                {
                    singleNode = new NodeName(nodenamestrings[0]);
                }
                else
                {
                    foreach (var nodenamestring in nodenamestrings)
                    {
                        selectedNodes.Add(new NodeName(nodenamestring));

                        // set the first node added to the subset as the forward destination nodes not in the subset
                        if (selectedNodesForwardDestination == null)
                        {
                            selectedNodesForwardDestination = new NodeName(nodenamestring);
                        }
                    }
                }

                remaining = remaining.Substring(remaining.IndexOf("}") + 1);
            }



            if (remaining.StartsWith("/"))
            {
                remaining = TrimStart(remaining, "/");
                Debug.Assert(remaining.StartsWith("n("));
            }

            if (remaining.StartsWith("n("))
            {
                Debug.Assert(remaining.EndsWith(")"));

                remaining = TrimStart(remaining, "n(");
                // remove last ')' character of n()
                var eventNameString = remaining.Remove(remaining.Length - 1);
                allSourcesOfEvent = new EventType(eventNameString);
            }
        }
Пример #4
0
        private void RegisterForwardRequest(EventType e, NodeName target, NodeName source = null)
        {
            if (source == null)
            {
                // add forward rule for all source nodes



                foreach (var sourceNodeName in sourceNodesByEventName[e])
                {
                    if (!sourceNodeName.Equals(target))
                    {
                        var ruleDict = forwardRulesByNodeName[sourceNodeName];
                        if (!ruleDict.ContainsKey(e))
                        {
                            ruleDict[e] = new ForwardRule();
                        }
                        ruleDict[e].addTarget(target);
                    }
                }
            }
            else
            {
                // add forward rule from specific source node only
                if (source.Equals(target))
                {
                    throw new ArgumentException("RegisterForwardRequest: Source equals target." + source.ToString() + " " + target, ToString());
                }

                var ruleDict = forwardRulesByNodeName[source];
                if (!ruleDict.ContainsKey(e))
                {
                    ruleDict[e] = new ForwardRule();
                }
                ruleDict[e].addTarget(target);
            }
        }
Пример #5
0
        private void processSingleQuery(Query q)
        {
            // resolve the list of source nodes for the current query
            if (q.placement.singleNode != null)
            {
                // this query is placed on a single node
                NodeName location = q.placement.singleNode;
                RegisterQueryPlacementOnNode(q, location);

                // all input events need to be forwarded to this node
                foreach (EventType e in q.inputEvents)
                {
                    RegisterForwardRequest(e, location);
                }
            }
            else
            {
                // There exists a locally produced event (LPE) for all nodes of the query.
                Debug.Assert(q.placement.allSourcesOfEvent != null);
                EventType locallyProcessedEvent = q.placement.allSourcesOfEvent;

                IEnumerable <NodeName> locations;
                if (q.placement.selectedNodes.Count == 0)
                {
                    // query is processed at all source nodes of LPE
                    locations = sourceNodesByEventName[q.placement.allSourcesOfEvent];
                }
                else
                {
                    // query is processed at a subset of source nodes of LPE
                    locations = q.placement.selectedNodes;
                }

                foreach (var location in locations)
                {
                    RegisterQueryPlacementOnNode(q, location);

                    // forward all input events except for the LPE
                    foreach (EventType e in q.inputEvents)
                    {
                        if (e.Equals(locallyProcessedEvent))
                        {
                            continue;
                        }

                        RegisterForwardRequest(e, location);
                    }
                }

                if (q.placement.selectedNodes.Count > 0)
                {
                    // forward the LPE from nodes that are not in the subset to
                    // only one (the first) node of the subset, s.t. the LPE instances will be processed exactly once

                    var externalSources = sourceNodesByEventName[locallyProcessedEvent].Except(q.placement.selectedNodes);

                    NodeName selectedDestination = q.placement.selectedNodesForwardDestination;

                    foreach (NodeName sourceNode in externalSources)
                    {
                        RegisterForwardRequest(locallyProcessedEvent, selectedDestination, sourceNode);
                    }
                }
            }
        }
Пример #6
0
 public void addTarget(NodeName n)
 {
     destinations.Add(n);
 }
Пример #7
0
 public NodeParams(NodeName name, EventType[] primitiveEventNames, int[] primitiveEventRates)
 {
     this.name = name;
     this.primitiveEventNames = primitiveEventNames;
     this.primitiveEventRates = primitiveEventRates;
 }