/// <summary> /// IncreasePid=true--> this is a packet. /// IncreasePid=false--> fake packet should not considred as new packet. /// </summary> /// <param name="sourceNode"></param> /// <param name="IncreasePid"></param> /// <returns></returns> private Packet GeneragtePacket(Sensor sourceNode, bool IncreasePid) { if (IncreasePid) { double x = (sourceNode.CenterLocation.X + sourceNode.CenterLocation.Y) / 2; PublicParamerters.NumberofGeneratedPackets += 1; Packet pck = new Packet(); pck.Source = sourceNode; pck.ClosestPointOnTheDiagonal = new Point(x, x); pck.Path = "" + sourceNode.ID; pck.Destination = null; // has no destination. pck.PacketType = PacketType.ObtainSinkPosition; pck.PID = PublicParamerters.NumberofGeneratedPackets; pck.TimeToLive = Convert.ToInt16((Operations.DistanceBetweenTwoPoints(sourceNode.CenterLocation, pck.ClosestPointOnTheDiagonal) / (PublicParamerters.CommunicationRangeRadius / Settings.Default.ComunTTL))); counter.IncreasePacketsCounter(sourceNode, PacketType.ObtainSinkPosition); return(pck); } else { double x = (sourceNode.CenterLocation.X + sourceNode.CenterLocation.Y) / 2; // PublicParamerters.NumberofGeneratedPackets += 1; Packet pck = new Packet(); pck.Source = sourceNode; pck.ClosestPointOnTheDiagonal = new Point(x, x); pck.Path = "" + sourceNode.ID; pck.Destination = null; // has no destination. pck.PacketType = PacketType.ObtainSinkPosition; pck.PID = PublicParamerters.NumberofGeneratedPackets; pck.TimeToLive = Convert.ToInt16((Operations.DistanceBetweenTwoPoints(sourceNode.CenterLocation, pck.ClosestPointOnTheDiagonal) / (PublicParamerters.CommunicationRangeRadius / Settings.Default.ComunTTL))); counter.IncreasePacketsCounter(sourceNode, PacketType.ObtainSinkPosition); return(pck); } }
/// <summary> /// increase the number of packets by one. /// </summary> /// <param name="packet"></param> /// <param name="currentBifSensor"></param> /// <returns></returns> private Packet Duplicate(Packet packet, Sensor currentBifSensor, bool IncreasePid) { Packet pck = packet.Clone() as Packet; if (IncreasePid) { PublicParamerters.NumberofGeneratedPackets += 1; pck.PID = PublicParamerters.NumberofGeneratedPackets; counter.IncreasePacketsCounter(currentBifSensor, PacketType.Data); // } return(pck); }
private Packet GeneragtePacket(Sensor highTierGateWay, SinksAgentsRow reportSinkPositionRow, PacketDirection direction) { // PublicParamerters.NumberofGeneratedPackets += 1; Packet pck = new Packet(); pck.PacketDirection = direction; pck.Source = highTierGateWay; pck.ReportSinkPosition = reportSinkPositionRow; pck.Path = "" + highTierGateWay.ID; if (direction == PacketDirection.Down) { pck.Destination = ClosePointToMe.DownPoint; // point 3 or 4 or medi } else { pck.Destination = ClosePointToMe.TopPoint; // 1 or 2 Operations.DrawPoint(pck.Destination, Brushes.Black, 10); } pck.TimeToLive = 1; // Convert.ToInt16((Operations.DistanceBetweenTwoPoints(highTierGateWay.CenterLocation, pck.Destination) / (PublicParamerters.CommunicationRangeRadius / 3))); pck.PacketType = PacketType.ShareSinkPosition; pck.PID = PublicParamerters.NumberofGeneratedPackets; counter.IncreasePacketsCounter(highTierGateWay, PacketType.ShareSinkPosition); return(pck); }
private Packet GeneragtePacket(Sensor highTierGateWay, SinksAgentsRow reportSinkPositionRow) { PublicParamerters.NumberofGeneratedPackets += 1; Packet pck = new Packet(); pck.Source = highTierGateWay; pck.ReportSinkPosition = reportSinkPositionRow; pck.Path = "" + highTierGateWay.ID; pck.Destination = null; // has no destination. pck.PacketType = PacketType.ShareSinkPosition; pck.PID = PublicParamerters.NumberofGeneratedPackets; counter.IncreasePacketsCounter(highTierGateWay, PacketType.ShareSinkPosition); return(pck); }
/// <summary> /// generate a DiagonalVirtualLineConstruction packet. /// </summary> /// <param name="scr">anchor1</param> /// <param name="des">anchor2</param> /// <returns></returns> private Packet GeneratePacket(Sensor scr, List <Point> rec) { //PublicParamerters.NumberofGeneratedPackets += 1; we will not count this packet for construction. Packet pck = new Packet(); pck.Source = scr; pck.Path = "" + scr.ID; pck.Destination = rec[3]; // we take the point at the bottom as ref. pck.PacketType = PacketType.VirtualLineConstruction; // pck.PID = PublicParamerters.NumberofGeneratedPackets; pck.TimeToLive = System.Convert.ToInt16((Operations.DistanceBetweenTwoPoints(scr.CenterLocation, rec[3]) / (PublicParamerters.CommunicationRangeRadius / 3))); counter.IncreasePacketsCounter(scr, PacketType.VirtualLineConstruction); return(pck); }
/// <summary> /// generate a DiagonalVirtualLineConstruction packet. /// </summary> /// <param name="scr">anchor1</param> /// <param name="des">anchor2</param> /// <returns></returns> private Packet GeneratePacket(Sensor scr, Sensor des) { PublicParamerters.NumberofGeneratedPackets += 1; Packet pck = new Packet(); pck.Source = scr; pck.Path = "" + scr.ID; pck.Destination = des; pck.PacketType = PacketType.DiagonalVirtualLineConstruction; pck.PID = PublicParamerters.NumberofGeneratedPackets; pck.TimeToLive = System.Convert.ToInt16((Operations.DistanceBetweenTwoPoints(scr.CenterLocation, des.CenterLocation) / (PublicParamerters.CommunicationRangeRadius / 3))); counter.IncreasePacketsCounter(scr, PacketType.DiagonalVirtualLineConstruction); return(pck); }
private Packet GeneragtePacket(SinksAgentsRow reportSinkPosition) { PublicParamerters.NumberofGeneratedPackets += 1; Packet pck = new Packet(); pck.Source = reportSinkPosition.AgentNode; pck.Path = "" + reportSinkPosition.AgentNode.ID; pck.Destination = null; // has no destination. pck.PacketType = PacketType.ReportSinkPosition; pck.PID = PublicParamerters.NumberofGeneratedPackets; pck.ReportSinkPosition = reportSinkPosition; pck.TimeToLive = Convert.ToInt16((Operations.DistanceBetweenTwoPoints(reportSinkPosition.AgentNode.CenterLocation, reportSinkPosition.ClosestPointOnTheDiagonal) / (PublicParamerters.CommunicationRangeRadius / Settings.Default.ComunTTL))); counter.IncreasePacketsCounter(reportSinkPosition.AgentNode, PacketType.ReportSinkPosition); return(pck); }
private Packet GeneragtePacket(Sensor sender, Sensor Dist) { PublicParamerters.NumberofGeneratedPackets += 1; Packet pck = new Packet(); pck.Source = sender; pck.Path = "" + sender.ID; pck.Destination = Dist; // has no destination. pck.PacketType = PacketType.Data; pck.Branch = null; pck.PID = PublicParamerters.NumberofGeneratedPackets; pck.TimeToLive = Convert.ToInt16((Operations.DistanceBetweenTwoPoints(sender.CenterLocation, Dist.CenterLocation) / (PublicParamerters.CommunicationRangeRadius / 3))); counter.IncreasePacketsCounter(sender, PacketType.Data); return(pck); }
/// <summary> /// IncreasePid=true--> this is a packet. /// IncreasePid=false--> fake packet should not considred as new packet. /// </summary> /// <param name="sourceNode"></param> /// <param name="IncreasePid"></param> /// <returns></returns> private Packet GeneragtePacket(Sensor sourceNode, bool IncreasePid) { if (IncreasePid) { PublicParamerters.NumberofGeneratedPackets += 1; Packet pck = new Packet(); pck.Source = sourceNode; pck.Destination = ClosePointToMe.PerPendicaularPoint(sourceNode); pck.Path = "" + sourceNode.ID; pck.PacketType = PacketType.ObtainSinkPosition; pck.PID = PublicParamerters.NumberofGeneratedPackets; double dis = Operations.DistanceBetweenTwoPoints(sourceNode.CenterLocation, pck.Destination); pck.TimeToLive = 5 + Convert.ToInt16(dis / (PublicParamerters.CommunicationRangeRadius / 2)); counter.IncreasePacketsCounter(sourceNode, PacketType.ObtainSinkPosition); //Operations.DrawLine(pck.Destination, sourceNode.CenterLocation, 2); return(pck); } else { Packet pck = new Packet(); pck.Source = sourceNode; pck.Path = "" + sourceNode.ID; pck.Destination = ClosePointToMe.PerPendicaularPoint(sourceNode); // has no destination. pck.PacketType = PacketType.ObtainSinkPosition; pck.PID = PublicParamerters.NumberofGeneratedPackets; double dis = Operations.DistanceBetweenTwoPoints(sourceNode.CenterLocation, pck.Destination); pck.TimeToLive = 5 + Convert.ToInt16(dis / (PublicParamerters.CommunicationRangeRadius / 2)); return(pck); } }
public Packet GeneragtePacket(Sensor hightierNode, Sensor lowtiernode, List <int> SinkIDs, bool IncreasePid) { if (IncreasePid) { if (SinkIDs == null) { // normal ResponseSinkPosition: PublicParamerters.NumberofGeneratedPackets += 1; Packet pck = new Packet(); pck.SinkIDsNeedsRecovery = null; pck.Source = hightierNode; pck.Path = "" + hightierNode.ID; pck.Destination = lowtiernode; // has no destination. pck.PacketType = PacketType.ResponseSinkPosition; pck.PID = PublicParamerters.NumberofGeneratedPackets; pck.SinksAgentsList = CopyAllSinks(hightierNode.GetSinksAgentsFromHighTierNode); // normal packet. not recovery packet pck.TimeToLive = Convert.ToInt16((Operations.DistanceBetweenTwoPoints(hightierNode.CenterLocation, lowtiernode.CenterLocation) / (PublicParamerters.CommunicationRangeRadius / Settings.Default.ComunTTL))); counter.IncreasePacketsCounter(hightierNode, PacketType.ResponseSinkPosition); return(pck); } else { // recovery packet: that is to say , only few sinks are reqiured. not need to respnse by all sinks. PublicParamerters.NumberofGeneratedPackets += 1; Packet pck = new Packet(); pck.SinkIDsNeedsRecovery = SinkIDs; pck.Source = hightierNode; pck.Path = "" + hightierNode.ID; pck.Destination = lowtiernode; // has no destination. pck.PacketType = PacketType.ResponseSinkPosition; pck.PID = PublicParamerters.NumberofGeneratedPackets; pck.SinksAgentsList = CopyFewSinks(hightierNode.GetSinksAgentsFromHighTierNode, SinkIDs); // needs recovery pck.TimeToLive = Convert.ToInt16((Operations.DistanceBetweenTwoPoints(hightierNode.CenterLocation, lowtiernode.CenterLocation) / (PublicParamerters.CommunicationRangeRadius / Settings.Default.ComunTTL))); counter.IncreasePacketsCounter(hightierNode, PacketType.ResponseSinkPosition); return(pck); } } else { // fack: if (SinkIDs == null) { // normal ResponseSinkPosition: // PublicParamerters.NumberofGeneratedPackets += 1; Packet pck = new Packet(); pck.SinkIDsNeedsRecovery = null; pck.Source = hightierNode; pck.Path = "" + hightierNode.ID; pck.Destination = lowtiernode; // has no destination. pck.PacketType = PacketType.ResponseSinkPosition; pck.PID = PublicParamerters.NumberofGeneratedPackets; pck.SinksAgentsList = CopyAllSinks(hightierNode.GetSinksAgentsFromHighTierNode); // normal packet. not recovery packet pck.TimeToLive = Convert.ToInt16((Operations.DistanceBetweenTwoPoints(hightierNode.CenterLocation, lowtiernode.CenterLocation) / (PublicParamerters.CommunicationRangeRadius / Settings.Default.ComunTTL))); counter.IncreasePacketsCounter(hightierNode, PacketType.ResponseSinkPosition); return(pck); } else { // recovery packet: that is to say , only few sinks are reqiured. not need to respnse by all sinks. // PublicParamerters.NumberofGeneratedPackets += 1; Packet pck = new Packet(); pck.SinkIDsNeedsRecovery = SinkIDs; pck.Source = hightierNode; pck.Path = "" + hightierNode.ID; pck.Destination = lowtiernode; // has no destination. pck.PacketType = PacketType.ResponseSinkPosition; pck.PID = PublicParamerters.NumberofGeneratedPackets; pck.SinksAgentsList = CopyFewSinks(hightierNode.GetSinksAgentsFromHighTierNode, SinkIDs); // needs recovery pck.TimeToLive = Convert.ToInt16((Operations.DistanceBetweenTwoPoints(hightierNode.CenterLocation, lowtiernode.CenterLocation) / (PublicParamerters.CommunicationRangeRadius / Settings.Default.ComunTTL))); counter.IncreasePacketsCounter(hightierNode, PacketType.ResponseSinkPosition); return(pck); } } }