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); }
/// <summary> /// hand the packet to my sink. /// </summary> /// <param name="agent"></param> /// <param name="packt"></param> public void HandOffToTheSinkOrRecovry(Sensor agent, Packet packt) { // check how many sinks are there in my record if (agent != null) { if (packt.SinksAgentsList != null) { // my sinks recored in the packet: List <SinksAgentsRow> MysinksInPpaket = GetMySinksFromPacket(agent.ID, packt.SinksAgentsList); // my sinks in the packet. List <SinksAgentsRow> MyCurrentSinks = agent.GetSinksAgentsList; //my sinks that currently within my range. List <int> SinksIDsRequiredRecovery = new List <int>(); // sinks that required recovery. those sinks which are in the packet but not within my range anymore. for (int i = 0; i < MysinksInPpaket.Count; i++) { SinksAgentsRow sinkInPacket = MysinksInPpaket[i]; // check if sink still within the range of the agent bool stillWithinMyRange = StillWithinMyRange(sinkInPacket, MyCurrentSinks); // check if sink x still within my range if (stillWithinMyRange) { // I am an agent for more than one sink // here we should increase the PID, otherwise the number of delivered packets will be more than the generated packets. Packet pck = Duplicate(packt, agent, false); // duplicate and increase the PID Sink sink = sinkInPacket.Sink; pck.Path += "> Sink: " + sink.ID; counter.SuccessedDeliverdPacket(pck); counter.DisplayRefreshAtReceivingPacket(agent); } else { // sinkInPacket.Sink is out of agent range. SinksIDsRequiredRecovery.Add(sinkInPacket.Sink.ID); } } // recovery: SinksIDsRequiredRecovery if (SinksIDsRequiredRecovery.Count > 0) { packt.SinkIDsNeedsRecovery = SinksIDsRequiredRecovery; new RecoveryMessage(agent, packt); } } else { // drop the packet. // i dont know when it should be null. Console.Write(">>>>No agents. MergedPathsMessages->HandOffToTheSinkOrRecovry->packt.SinksAgentsList==null"); counter.DropPacket(packt, agent, PacketDropedReasons.Unknow); } } else { // drop the packet Console.Write(">>>>HandOffToTheSinkOrRecovry->agent = null"); counter.DropPacket(packt, agent, PacketDropedReasons.Unknow); } }
/// <summary> /// find x in inlist /// /// </summary> /// <param name="x"></param> /// <param name="inlist"></param> /// <returns></returns> private bool StillWithinMyRange(SinksAgentsRow x, List <SinksAgentsRow> inlist) { foreach (SinksAgentsRow rec in inlist) { if (rec.Sink.ID == x.Sink.ID) { return(true); } } return(false); }
/// <summary> /// due to duplication, we dont count the generated packets here. we count it when it recived. /// </summary> /// <param name="sender"></param> /// <param name="branch"></param> /// <returns></returns> private Packet GeneragtePacket(Sensor sender, SinksAgentsRow row) { PublicParamerters.NumberofGeneratedPackets += 1; Packet pck = new Packet(); pck.Source = sender; pck.Path = "" + sender.ID; pck.Destination = row.AgentNode.CenterLocation; pck.PacketType = PacketType.Data; pck.PID = PublicParamerters.NumberofGeneratedPackets; pck.TimeToLive = Convert.ToInt16((Operations.DistanceBetweenTwoPoints(sender.CenterLocation, pck.Destination) / (PublicParamerters.CommunicationRangeRadius / 3))); counter.IncreasePacketsCounter(sender, PacketType.Data); // 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 = reportSinkPosition.ClosestPointOnTheDiagonal; // 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); }
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); } }
public ShareSinkPositionIntheHighTier(Sensor highTierGateWay, SinksAgentsRow reportSinkPositionRow) { if (highTierGateWay.IsHightierNode) { counter = new NetworkOverheadCounter(); Packet upPlacket = GeneragtePacket(highTierGateWay, reportSinkPositionRow, PacketDirection.Up); Packet downpacket = GeneragtePacket(highTierGateWay, reportSinkPositionRow, PacketDirection.Down); SendPacket(highTierGateWay, upPlacket); SendPacket(highTierGateWay, downpacket); // floood: //: SAVE Sink positions.// this is not agent record. becarful here highTierGateWay.AddSinkRecordInHighTierNode(reportSinkPositionRow); } }