Beispiel #1
0
		public NSEventBlock ReadNextEventBlock()
		{
			double time = 0;
			double startTime = 0;
			string traceLine;
			var eventBlock = new NSEventBlock();

			// read the first event to adjust the start time
			while (true)
			{
				traceLine = file.ReadLine();
				if (traceLine != null)
				{
					// map the trace line to analogous event object
					var nsEvent = otMapper.Map(traceLine);
					if (nsEvent != null)
					{
						eventBlock.Add(nsEvent);
						time = startTime = nsEvent.Time;
					}
					break;
				}
			}

			while (time - startTime < blockDuration && !file.EndOfStream)
			{
				string traceLine2 = file.ReadLine();
				if (traceLine2 != null)
				{
					// map the trace line to analogous event object
					var nsEvent = otMapper.Map(traceLine2);
					if (nsEvent != null)
					{
						eventBlock.Add(nsEvent);
						time = nsEvent.Time;
					}
				}
			}
			return eventBlock;
		}
Beispiel #2
0
        public static double Compute(Metric metric, NSEventBlock nodeEvents)
        {
            double M = -1;

            switch (metric)
            {
            // OK
            case Metric.ResponseTime:
                var rt = nodeEvents.Where(ne => ne.IsLastHop &&
                                          ne.InnerMessageType == NSMessageType.Data);

                if (rt.Any())
                {
                    M = rt.Average(ne => ne.TotalDelay);
                }
                break;

            // OK
            case Metric.OneHopDelay:
                var ohd = nodeEvents.Where(ne => ne.IsNetReceive);
                if (ohd.Any())
                {
                    M = nodeEvents.Average(ne => ne.OneHopDelay);
                }
                break;

            // OK
            case Metric.DataThroughput:
                M = nodeEvents.Count(ne => ne.IsNetReceive &&
                                     (ne.InnerMessageType == NSMessageType.Data ||
                                      ne.InnerMessageType == NSMessageType.ExploratoryData));
                break;

            case Metric.ExpectedDataThroughput:
                var edtps = nodeEvents.Where(ne => ne.Type == NSEventType.Send &&
                                             ne.TraceLevel == NSTraceLevel.AGT &&
                                             ne.OuterMessageType == NSMessageType.Control &&
                                             ne.InnerMessageType != NSMessageType.Unknown &&
                                             ne.ExpectedDataRate > 0);

                if (edtps.Any())
                {
                    M = edtps.Average(ne => ne.ExpectedDataRate);
                }
                break;

            case Metric.RoutingListSize:
                var rls = nodeEvents.Where(ne => ne.Type == NSEventType.Send &&
                                           ne.TraceLevel == NSTraceLevel.AGT &&
                                           ne.OuterMessageType == NSMessageType.Control &&
                                           ne.InnerMessageType != NSMessageType.Unknown &&
                                           ne.RoutingListSize > 0);

                if (rls.Any())
                {
                    M = rls.Average(ne => ne.RoutingListSize);
                }
                break;

            // OK
            case Metric.MyInterestSendRate:
                M = nodeEvents.Count(ne => ne.Type == NSEventType.Send &&
                                     ne.TraceLevel == NSTraceLevel.AGT &&
                                     ne.InnerMessageType == NSMessageType.Interest &&
                                     ne.OuterMessageType == NSMessageType.Interest);
                break;

            // OK
            case Metric.InterestThroughput:
                M = nodeEvents.Count(ne => ne.IsNetReceive &&
                                     (ne.InnerMessageType == NSMessageType.Interest));
                break;

            // OK
            case Metric.PassedHops:
                var ph = nodeEvents.Where(ne => ne.IsLastHop &&
                                          ne.InnerMessageType == NSMessageType.Data);

                if (ph.Any())
                {
                    M = ph.Average(ne => ne.NumPassedHops);
                }
                break;

            // OK (but needs threshold)
            case Metric.DelayedPackets:
                var responseTimeThresh = 10.0;                          // TODO: should be a realistic time
                var lastHops           = nodeEvents.Where(ne => ne.IsLastHop);
                if (lastHops.Any())
                {
                    M = (double)lastHops.Count(ne => ne.TotalDelay > responseTimeThresh) / lastHops.Count();
                }
                break;

            // OK (but needs threshold)
            case Metric.LongBufferProbability:
                var longBufferThresh = 40;                                      // value set by experiment
                var ifqs             = nodeEvents.Where(ne =>
                                                        ne.TraceLevel == NSTraceLevel.IFQ &&
                                                        ne.PacketType == NSPacketType.Diffusion &&
                                                        ne.Reason == "");
                if (ifqs.Any())
                {
                    M = (double)ifqs.Count(ne => ne.IFQLength > longBufferThresh) / ifqs.Count();
                }
                break;

            // OK
            case Metric.DataDrop:
                M = nodeEvents.Count(ne => ne.Type == NSEventType.Drop &&
                                     ne.TraceLevel == NSTraceLevel.AGT &&
                                     (ne.InnerMessageType == NSMessageType.Data ||
                                      ne.InnerMessageType == NSMessageType.ExploratoryData) &&
                                     ne.Reason.ToUpper() == "NMS");
                break;

            // OK
            case Metric.BufferOverflow:
                M = nodeEvents.Count(ne => ne.Type == NSEventType.Drop &&
                                     ne.TraceLevel == NSTraceLevel.IFQ && ne.Reason.ToUpper() == "IFQ");
                break;

            // did not OK Mahenush changed it(but needs threshold)
            case Metric.LowEnergy:
                var energyThresh = 1.5;                                 // TODO: should be a realistic value
                if (nodeEvents.Any())
                {
                    /*var x = nodeEvents.Where(ne => ne.Energy < energyThresh);
                     * if (x.Any())
                     * {
                     *      M = x.Average(ne2 => ne2.Time);
                     * }*/
                    M = nodeEvents.Average(ne => ne.Energy);
                }
                break;

            default: throw new Exception("Invalid metric type!"); break;
            }
            return(M);
        }
Beispiel #3
0
		public static double Compute(Metric metric, NSEventBlock nodeEvents)
		{
			double M = -1;
			switch (metric)
			{
				// OK
				case Metric.ResponseTime:
					var rt = nodeEvents.Where(ne => ne.IsLastHop &&
						ne.InnerMessageType == NSMessageType.Data);

					if (rt.Any())
					{
						M = rt.Average(ne => ne.TotalDelay);
					}
					break;

				// OK
				case Metric.OneHopDelay:
					var ohd = nodeEvents.Where(ne => ne.IsNetReceive);
					if (ohd.Any())
					{
						M = nodeEvents.Average(ne => ne.OneHopDelay);
					}
					break;

				// OK
				case Metric.DataThroughput:
					M = nodeEvents.Count(ne => ne.IsNetReceive &&
						(ne.InnerMessageType == NSMessageType.Data || 
						ne.InnerMessageType == NSMessageType.ExploratoryData));
					break;

				case Metric.ExpectedDataThroughput:
					var edtps = nodeEvents.Where(ne => ne.Type == NSEventType.Send &&
						ne.TraceLevel == NSTraceLevel.AGT &&
						ne.OuterMessageType == NSMessageType.Control &&
						ne.InnerMessageType != NSMessageType.Unknown
						&& ne.ExpectedDataRate > 0);

					if (edtps.Any())
					{
						M = edtps.Average(ne => ne.ExpectedDataRate);
					}
					break;

				case Metric.RoutingListSize:
					var rls = nodeEvents.Where(ne => ne.Type == NSEventType.Send &&
						ne.TraceLevel == NSTraceLevel.AGT &&
						ne.OuterMessageType == NSMessageType.Control &&
						ne.InnerMessageType != NSMessageType.Unknown
						&& ne.RoutingListSize > 0);

					if (rls.Any())
					{
						M = rls.Average(ne => ne.RoutingListSize);
					}
					break;

				// OK
				case Metric.MyInterestSendRate:
					M = nodeEvents.Count(ne => ne.Type == NSEventType.Send &&
						ne.TraceLevel == NSTraceLevel.AGT &&
						ne.InnerMessageType == NSMessageType.Interest &&
						ne.OuterMessageType == NSMessageType.Interest);
					break;

				// OK
				case Metric.InterestThroughput:
					M = nodeEvents.Count(ne => ne.IsNetReceive &&
						(ne.InnerMessageType == NSMessageType.Interest));
					break;

				// OK
				case Metric.PassedHops:
					var ph = nodeEvents.Where(ne => ne.IsLastHop &&
						ne.InnerMessageType == NSMessageType.Data);

					if (ph.Any())
					{
						M = ph.Average(ne => ne.NumPassedHops);
					}
					break;

				// OK (but needs threshold)
				case Metric.DelayedPackets:
					var responseTimeThresh = 10.0;	// TODO: should be a realistic time
					var lastHops = nodeEvents.Where(ne => ne.IsLastHop);
					if (lastHops.Any())
					{
						M = (double)lastHops.Count(ne => ne.TotalDelay > responseTimeThresh) / lastHops.Count();
					}
					break;

				// OK (but needs threshold)
				case Metric.LongBufferProbability:
					var longBufferThresh = 40;		// value set by experiment
					var ifqs = nodeEvents.Where(ne => 
							ne.TraceLevel == NSTraceLevel.IFQ &&
							ne.PacketType == NSPacketType.Diffusion &&
							ne.Reason == "");
					if (ifqs.Any())
					{
						M = (double)ifqs.Count(ne => ne.IFQLength > longBufferThresh) / ifqs.Count();
					}
					break;

				// OK
				case Metric.DataDrop:
					M = nodeEvents.Count(ne => ne.Type == NSEventType.Drop && 
						ne.TraceLevel == NSTraceLevel.AGT && 
						(ne.InnerMessageType == NSMessageType.Data ||
						ne.InnerMessageType == NSMessageType.ExploratoryData) &&
						ne.Reason.ToUpper() == "NMS");
					break;

				// OK
				case Metric.BufferOverflow:
					M = nodeEvents.Count(ne => ne.Type == NSEventType.Drop &&
						ne.TraceLevel == NSTraceLevel.IFQ && ne.Reason.ToUpper() == "IFQ");
					break;

				// did not OK Mahenush changed it(but needs threshold)
				case Metric.LowEnergy:
					var energyThresh = 1.5;		// TODO: should be a realistic value
					if (nodeEvents.Any())
					{
						/*var x = nodeEvents.Where(ne => ne.Energy < energyThresh);
						if (x.Any())
						{
							M = x.Average(ne2 => ne2.Time);
						}*/
						M = nodeEvents.Average(ne => ne.Energy);
					}
					break;

				default: throw new Exception("Invalid metric type!"); break;
			}
			return M;
		}