Sending Custom Packets using sockets

1,095 views
Skip to first unread message

srinivas poram

unread,
Oct 30, 2012, 6:29:37 AM10/30/12
to ns-3-...@googlegroups.com
Hi,
I want to send my custom packet like hello among the simulated nodes. for this i have created a packet like below

Ptr<Packet>pkt=Create<Packet>(reinterpret_cast<uint8_t *>("hello"),5);
 i can able to check the payload by
cout<<*pkt<<endl; and contents of the packet by
cout<<pkt->PeekData()<<endl;
I came to know that i can able to send these packets among simulated nodes by using sockets.So i created socket by
Ptr<Socket>socket;
why is it giving error when i use
socket->Bind(InetSocketAddress(80));

and error is being displayed when i'm using udpFactory if i want to create a socket as below

Ptr<Socket>socket=udpFactory->CreateSocket();

any help ..please

srinivas poram

unread,
Nov 7, 2012, 2:46:18 AM11/7/12
to ns-3-...@googlegroups.com
Hi,
 I could able tomake a packet and socket also. And i couldable to send the packet the packet particular destination node by using socket->SendTo(pkt,0,InetSocketAddress("Destination Address",destination port). But when i'm reading the pcap file generated by simulator it is showing that packet is sent only once. How can i make my simulator to take my packet(created by me) and send it regularly with some interval. also how can i send it in multicast and broadcast mode.

William Bellia

unread,
Nov 7, 2012, 2:51:27 AM11/7/12
to ns-3-...@googlegroups.com
Hey,

In order to schedule re transmission of packets, you can use the following code:
  if (m_running)
    {
      Time tNext (Seconds (m_packetSize * 8 / static_cast<double> (m_dataRate.GetBitRate ())));
      m_sendEvent = Simulator::Schedule (tNext, &MyApp::SendPacket, this);
    }

where the variant on how fast the transmission takes place is the bit rate.

This code was taken from the example section in ns3 source.

Will

--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ns-3-users/-/QbxlV7VQqrYJ.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.



--
William Bellia


srinivas poram

unread,
Nov 8, 2012, 6:41:08 AM11/8/12
to ns-3-...@googlegroups.com
How can i make simulator to consider my packet/custom packet instead of generalized packets created by:
 
OnOffHelper onoff("ns3::UdpSocketFactory",Address(InetSocketAddress(Ipv4Address("10. . ."),port)));
 
 
Thanks

On Tuesday, 30 October 2012 15:59:37 UTC+5:30, srinivas poram wrote:
Message has been deleted

Munde Pravin

unread,
Feb 3, 2018, 8:12:57 AM2/3/18
to ns-3-users
Greetings Sir,
I tried :

Ptr<Packet>pkt=Create<Packet>(reinterpret_cast<uint8_t *>("hello"),5);
socket->SendTo(pkt,0,InetSocketAddress(Ipv4Address ("10.1.1.1"), 80));

and ended up with following error :

error: reinterpret_cast from type ‘const char*’ to type ‘uint8_t* {aka unsigned char*}’ casts away qualifiers

for the first line.
How to resolve this ?
HOW to send any kind of data such as int ,char,string,variable value,array,list etc. ?
please help.Thank you

Tommaso Pecorella

unread,
Feb 4, 2018, 1:14:05 AM2/4/18
to ns-3-users
Hi,

please read the posting guidelines.

T
Reply all
Reply to author
Forward
0 new messages