public ReportSinkPositionMessage(SinksAgentsRow reportSinkPosition) { // node should not be a hightier if (!reportSinkPosition.AgentNode.IsHightierNode) { counter = new NetworkOverheadCounter(); reportSinkPosition.ClosestPointOnTheDiagonal = ClosePointToMe.PerPendicaularPoint(reportSinkPosition.AgentNode); Packet packet = GeneragtePacket(reportSinkPosition); SendPacket(reportSinkPosition.AgentNode, packet); // check if the node isself is hightier node. here no need to generate ReportSinkPosition. } else { // node just generate sharesinkposition packet. // no need to report. ShareSinkPositionIntheHighTier xma = new ShareSinkPositionIntheHighTier(reportSinkPosition.AgentNode, reportSinkPosition); } }
/// <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); } }