static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval )
Hi Ahmed,Sending periodically packets every "X" is already implemented in your code. If you do not understand it, perhaps you need to study your code more carefully.Your method GenerateTraffic gives a clue on how to do that:
static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval )Yes, you can see the ID of the nodes. You need to get that information from the socket and the received packet.See for example how the PacketSink application handles received packets. The HandleRead method is in principle the same as your ReceivePacket.Regards,K.
Check again the GenerateTraffic to understand what is the meaning of packetCount (numPackets).
uint32_t numPackets = 1;
Yes this is what I meant when I first asked the question but I guess you made things clear to me now I was looking at the wrong place . correct me if I'm wrong please:
uint32_t numPackets = 1;
double interval = 10;
static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval )
{ if (pktCount > 0) { socket->Send (Create<Packet> (pktSize)); Simulator::Schedule (pktInterval, &GenerateTraffic, socket, pktSize,pktCount, pktInterval);
} else { socket->Close (); }}
pktcount-1
Hello Again Mr.K
void ReceivePacket (Ptr<Socket> socket)
{
Ptr<Packet> packet; Address from; while(socket->RecvFrom(from)){
NS_LOG_UNCOND ("Received one packet! \t" << "At \t " << Simulator::Now ().GetSeconds () << " from " << InetSocketAddress::ConvertFrom(from).GetIpv4 () << endl); }}
Hello Konstantinos ,
void ReceivePacket (Ptr<Socket> socket){
Ptr<Packet> packet; Address from; while(socket->RecvFrom(from)){
NS_LOG_UNCOND ("Received one packet! \t" << "At \t " << Simulator::Now ().GetSeconds () << " from " << InetSocketAddress::ConvertFrom(from).GetIpv4 () << endl );
}}
Simulator::ScheduleWithContext (source->GetNode ()->GetId (), Seconds (1.0, &GenerateTraffic, source, packetSize, numPackets, interPacketInterval);
for (int n=0; n<10 ; n++) { Ptr<Socket> recvSink = Socket::CreateSocket (wifiStaNodes.Get (n), tid); InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80); recvSink->Bind (local); recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));
Ptr<Socket> source = Socket::CreateSocket (wifiStaNodes.Get (n), tid); InetSocketAddress remote = InetSocketAddress (Ipv4Address ("255.255.255.255"), 80); source->SetAllowBroadcast (true); source->Connect (remote);
Simulator::ScheduleWithContext (source->GetNode ()->GetId (), Seconds (1.0), &GenerateTraffic, source, packetSize, numPackets, interPacketInterval);
Simulator::ScheduleWithContext (source->GetNode ()->GetId (), Seconds (1.0), &GenerateTraffic, source, packetSize, numPackets, interPacketInterval);
}
for (int n=0; n<10 ; n++) { Ptr<Socket> recvSink = Socket::CreateSocket (wifiStaNodes.Get (n), tid); InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80); recvSink->Bind (local); recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));
Ptr<Socket> source = Socket::CreateSocket (wifiStaNodes.Get (n), tid); InetSocketAddress remote = InetSocketAddress (Ipv4Address ("255.255.255.255"), 80); source->SetAllowBroadcast (true); source->Connect (remote);
Simulator::ScheduleWithContext (source->GetNode ()->GetId (), Seconds (1.0), &GenerateTraffic, source, packetSize, numPackets, interPacketInterval);
}