Hello!I'm sorry about disturbing I have a basic question, I hope someone can answer me. I'm working on a custom application using UDP sockets in ns-3. I wrote a simple two classes (Source application and sink application), the Logic is easy. Source sends 1000 packets using udp socket and on sink application using SetRecvCallback () the sink reads these packets and performs some reordering mechanism. By creating 2 nodes and setup 1 of them as source node and the second as destination. when I send 1000 packet all the packets are sent (NS_LOG_INFO working fine for source node), but on the sink node I get only 3 packets (NS_LOG_INFO shows me only 3 first packets). What may be the problem?
1) Sending the code for source application
2) The code of sink application
2) The main classe
-----------------------------------------------------------------------------------
void SourceApplication::StartApplication()
{
Ptr<UniformRandomVariable> rand = CreateObject<UniformRandomVariable> ();
m_random_offset = MicroSeconds (rand->GetValue(2,10));
NS_LOG_FUNCTION("Start application ... " << m_my_addr);
TypeId tid = TypeId::LookupByName("ns3::UdpSocketFactory");
m_recv_socket1 = Socket::CreateSocket(GetNode(), tid);
m_recv_socket2 = Socket::CreateSocket(GetNode(), tid);
SetupReceiveSocket(m_recv_socket1, m_my_addr, m_port1);
SetupReceiveSocket(m_recv_socket2, m_my_addr, m_port2);
//Send Socket
m_send_socket = Socket::CreateSocket(GetNode(), tid);
m_recv_socket1->SetRecvCallback(MakeCallback(&SourceApplication::HandleReadTwo, this));
this->check_udp_socket ();
}
int SourceApplication::check_udp_socket ()
{
if(isStarted == false)
{
if (starttime == 0)
{
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);
starttime = tp.tv_nsec;
}
isStarted = true;
}
for (int i = 0; i< m_number_of_packets_to_send; i++)
{
Ptr<Packet> packet = Create<Packet>(MTU_SIZE);
PacketDataTag tag;
tag.SetNumberOfRepeat (0);
if(gal_pn == MAX_PN) gal_pn = 0; else gal_pn++;
tag.SetSeqNumber (gal_pn);
tag.SetNodeId (GetNode ()->GetId ());
tag.SetPacketId (IDM_UDP_ARQ_VIDEO);
tag.SetTimestamp (Simulator::Now ());
tag.SetTreeNumber (0);
packet->AddPacketTag (tag);
pbb.new_packet_tag.number_of_repeat = tag.GetNumberOfRepeat ();
pbb.new_packet_tag.seq_number = tag.GetSeqNumber ();
pbb.new_packet_tag.nodeId = tag.GetNodeId ();
pbb.new_packet_tag.packet_id = tag.GetpacketId ();
pbb.new_packet_tag.timestamp = tag.GetTimestamp ();
pbb.new_packet_tag.nt = tag.GetTreeNumber ();
pbb.new_packet_tag.next = NULL;
pbb.shift_buffer ();
if (g.getState ())
{
if(this->SendPacket (packet) == EXIT_SUCCESS)
{
packetsSend++;
//printf (".");
printf (PURPLE_CODE);
printf (" %" PRIu32, tag.GetSeqNumber ());
printf (END_CODE);
}
}
else
{
printf (" l");
}
}
return EXIT_SUCCESS;
}
____________________________________________________
SINK APPLICATION
__________________________________________________
void SinkApplication::StartApplication()
{
NS_LOG_FUNCTION("Start application ... " << m_my_addr);
TypeId tid = TypeId::LookupByName("ns3::UdpSocketFactory");
m_recv_socket1 = Socket::CreateSocket(GetNode(), tid);
m_recv_socket2 = Socket::CreateSocket(GetNode(), tid);
SetupReceiveSocket(m_recv_socket1, m_my_addr, m_port1);
SetupReceiveSocket(m_recv_socket2, m_my_addr, m_port2);
m_send_socket = Socket::CreateSocket(GetNode(), tid);
m_recv_socket1->SetRecvCallback(MakeCallback(&SinkApplication::HandleReadOne, this));
}
_____________________________________________________
THE PART OF MAIN CLASS WHERE THE APPLICATIONS ARE CREATED
_____________________________________________________
Ptr <SinkApplication> appSink = CreateObject <SinkApplication> ();
Ptr <SourceApplication> appSource = CreateObject <SourceApplication> ();
//Set up sink application
appSink->SetStartTime (Seconds(1));
appSink->SetStopTime (Seconds (simTime));
Ipv4Address dest_ip ("10.1.1.2");
Ipv4Address my_ip("10.1.1.1");
appSink->SetDestinationAddr (dest_ip);
appSink->SetMyAddr (my_ip);
// Set up source application
appSource->SetStartTime (Seconds(2));
appSource->SetStopTime (Seconds (simTime));
Ipv4Address dest_ip2 ("10.1.1.1");
appSource->SetDestinationAddr (dest_ip2);
Ipv4Address my_addr2 ("10.1.1.2");
appSource->SetMyAddr (my_addr2);
nodes.Get(0)->AddApplication (appSink);
nodes.Get(1)->AddApplication (appSource);
LogComponentEnable ("SourceApplication", LOG_LEVEL_ALL);
LogComponentEnable ("SinkApplication", LOG_LEVEL_ALL);
Simulator::Stop (Seconds (simTime));
Simulator::Run ();
appSource->print_results ();
appSink->print_results ();
Simulator::Destroy ();