Sending Pakets via UDP Sockets in Parallel

89 views
Skip to first unread message

Richard Dworschak

unread,
May 25, 2020, 2:46:50 AM5/25/20
to ns-3-users
Greetings

I have Problems understanding if it is possible to send packets in parallel. The basic idea is, that every node i create runs on a thread to simulate a node in an IoT Network. These nodes do some work and periodically need to send some date through the simulated network (See in Sim_Start.cc on how i set it up, but its a standard adhoc Wifi network with static positioning). The thread within the node loops until it gets destroyed at the end of the simulation by a ns3 scheduled event. The provided function intents to send the data from one node to the other. It also creates the socket for each sending (That is just for testing)

   
void test_send_single(int send_to_id, std::string msg){
       
const std::shared_ptr<BNode> dest_node = all_nodes->at(send_to_id); //All Nodes are saved in a vector to retrieve their data
       
int port = dest_node->get_next_port(); // Get the next port to use with the new Socket

        shared_mutex
->lock();


       
Ptr<Socket> skt = Socket::CreateSocket(this->ns3_node, TypeId::LookupByName("ns3::UdpSocketFactory"));
        skt
->Bind();

       
Ptr<Socket> dst = Socket::CreateSocket(dest_node->getNs3Node(), TypeId::LookupByName("ns3::UdpSocketFactory"));
       
InetSocketAddress addr = InetSocketAddress(dest_node->getLocalAddress(), port);
        dst
->Bind(addr);
        dst
->SetRecvCallback(MakeCallback(&BNode::recv_pkg, dest_node.get()));

        NS_LOG_UNCOND
(port);

        uint8_t buf
[4] = {'a','b','c','\0'};
       
Ptr<Packet> pkt = Create<Packet> (buf,4); // Creating a dummy Paket with some data and a null termination.

        shared_mutex
->unlock();

        NS_LOG_UNCOND
("Sending Packet Number: " << pkt->GetUid() );
        skt
->SendTo(pkt, 0, addr);
    }

I included the code snipped on how i try to send a packet with a buffer to another node within the network. The problem is, if two nodes send at the same time, i get a Segmentation Fault:

Thread 1 "IoTSim_Wifi_Sca" received signal SIGSEGV, Segmentation fault.
0x00007fffef567c73 in ns3::Buffer::Create (dataSize=0)
    at ../src/network/model/buffer.cc:133
133              if (data->m_size >= dataSize)
(gdb) where

#0  0x00007fffef567c73 in ns3::Buffer::Create (dataSize=0) at ../src/network/model/buffer.cc:133
#1  0x00007fffef568a0a in ns3::Buffer::Initialize (this=0x5555558c3bc8, zeroSize=0) at ../src/network/model/buffer.cc:247
#2  0x00007fffef568384 in ns3::Buffer::Buffer (this=0x5555558c3bc8) at ../src/network/model/buffer.cc:191
#3  0x00007fffef59861d in ns3::Packet::Packet (this=0x5555558c3bc0) at ../src/network/model/packet.cc:140
#4  0x00007ffff7ba4fc8 in ns3::Create<ns3::Packet> () at ./ns3/ptr.h:518
#5  0x00007ffff216d21d in ns3::ArpL3Protocol::SendArpRequest (this=0x555555814740, cache=..., to=...) at ../src/internet/model/arp-l3-protocol.cc:375
#6  0x00007ffff2170174 in ns3::EventImpl* ns3::MakeEvent<void (ns3::ArpL3Protocol::*)(ns3::Ptr<ns3::ArpCache const>, ns3::Ipv4Address), ns3::ArpL3Protocol*, ns3::Ptr<ns3::ArpCache>, ns3::Ipv4Address>(void (ns3::ArpL3Protocol::*)(ns3::Ptr<ns3::ArpCache const>, ns3::Ipv4Address), ns3::ArpL3Protocol*, ns3::Ptr<ns3::ArpCache>, ns3::Ipv4Address)::EventMemberImpl2::Notify() (this=0x7fffd4001ab0) at ./ns3/make-event.h:437
#7  0x00007fffeee0c03f in ns3::EventImpl::Invoke (this=0x7fffd4001ab0) at ../src/core/model/event-impl.cc:51
#8  0x00007fffeeec5506 in ns3::RealtimeSimulatorImpl::ProcessOneEvent (this=0x5555558355e0) at ../src/core/model/realtime-simulator-impl.cc:391
#9  0x00007fffeeec5b21 in ns3::RealtimeSimulatorImpl::Run (this=0x5555558355e0) at ../src/core/model/realtime-simulator-impl.cc:465
#10 0x00007fffeee0d26b in ns3::Simulator::Run () at ../src/core/model/simulator.cc:230
#11 0x00005555555658c7 in main (argc=1, argv=0x7fffffffdc08) at ../scratch/IoTSim_Wifi_Scale/Sim_Start.cc:113

My guess is, that the buffer is deleted within the Buffer class from one node while the other wants to access it. On Line 133 the data field is nothing so the programm cant read the m_size property. I have no problems creating an emtpy Packet with a certain size. I tried to lock it with a mutex but that didnt help. I think my problem is the missing understanding on how ns3 works under the hood and with the vast amount of doc i am a little lost.

Kind regards
Richard Dworschak

Sim_Start.cc
Reply all
Reply to author
Forward
0 new messages