How can i get the contents of packet

2,313 views
Skip to first unread message

Farrukh

unread,
Apr 20, 2010, 9:15:16 AM4/20/10
to ns-3-users
Hi,
i want to access the contents of Packets to implement desired
modulation scheme. How can i get the contents of the Packet,

Regards,

--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
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.

Mathieu Lacage

unread,
Apr 20, 2010, 10:09:40 AM4/20/10
to ns-3-...@googlegroups.com
uint8_t *buffer = new uint8_t () [packet->GetSize ()];
packet->CopyData (buffer, packet->GetSize ());
--
Mathieu Lacage <mathieu...@gmail.com>

Mathieu Lacage

unread,
Apr 20, 2010, 2:44:04 PM4/20/10
to ns-3-...@googlegroups.com
On Tue, Apr 20, 2010 at 7:54 PM, Farrukh <mir....@gmail.com> wrote:
> Command ['/home/muhr/Documents/cplus-ns3-workspace/MIMO_MESH_204/build/
> debug/scratch/MIMO_MESH/MIMO_MESH'] exited with code -11

This is a segfault. Use a debugger.

Mathieu

Farrukh

unread,
Apr 20, 2010, 1:54:44 PM4/20/10
to ns-3-users
@ Mathieu, THANKS ALOT..... it workes

I want to implement another PHY layer instead of YANS, i did change
in given example of mesh.cc
i.e

-----------------------------
#include <sstream>
#include <string>
#include "MeshTest.h"
using namespace ns3;

MM_Node mnode;
MeshTest::MeshTest () :
m_xSize (3),
m_ySize (3),
m_step (100.0),
m_randomStart (0.1),
m_totalTime (10.0),
m_packetInterval (5.0),
m_packetSize (1024),
m_nIfaces (1),
m_chan (true),
m_pcap (false),
m_stack ("ns3::Dot11sStack"),
m_root ("ff:ff:ff:ff:ff:ff")
{
}

void
MeshTest::CreateNodes ()
{

/*
* Create m_ySize*m_xSize stations to form a grid topology
*/
nodes.Create (m_ySize*m_xSize);

mesh = MeshHelper::Default ();
if (!Mac48Address (m_root.c_str ()).IsBroadcast ())
{
mesh.SetStackInstaller (m_stack, "Root", Mac48AddressValue
(Mac48Address (m_root.c_str ())));
}
else
{
//If root is not set, we do not use "Root" attribute, because it
//is specified only for 11s
mesh.SetStackInstaller (m_stack);
}
/* if (m_chan)
{
mesh.SetSpreadInterfaceChannels (MeshHelper::SPREAD_CHANNELS);
}
else
{
mesh.SetSpreadInterfaceChannels (MeshHelper::ZERO_CHANNEL);
}*/

mesh.SetMacType ("RandomStart", TimeValue (Seconds(m_randomStart)));
// Set number of interfaces - default is single-interface mesh point
mesh.SetNumberOfInterfaces (m_nIfaces);
// Install protocols and return container if MeshPointDevices



meshDevices = mesh.Install (nodes);


}
void
MeshTest::InstallInternetStack ()
{
InternetStackHelper internetStack;
internetStack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
interfaces = address.Assign (meshDevices);
}

int
MeshTest::Run ()
{
CreateNodes ();
InstallInternetStack ();
//InstallApplication ();
return 0;
}

int
main (int argc, char *argv[])
{
MeshTest t;

return t.Run();
}
-----------------------------------------------
For this i changed the method of mesh helper as well
----------------------------------------------------

NetDeviceContainer
MeshHelper::Install (NodeContainer c) const
{
NetDeviceContainer devices;
NS_ASSERT (m_stack != 0);
for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
{
Ptr<Node> node = *i;
// Create a mesh point device
Ptr<MeshPointDevice> mp = CreateObject<MeshPointDevice> ();
node->AddDevice (mp);
// Create wifi interfaces (single interface by default)
for (uint32_t i = 0; i < m_nInterfaces; ++i)
{
uint32_t channel = 0;
if (m_spreadChannelPolicy == ZERO_CHANNEL)
{
channel = 0;
}
if (m_spreadChannelPolicy == SPREAD_CHANNELS)
{
channel = i * 5;
}
Ptr<WifiNetDevice> iface = CreateInterface (node, channel);
mp->AddInterface (iface);
}
if (!m_stack->InstallStack (mp))
{
NS_FATAL_ERROR ("Stack is not installed!");
}
devices.Add (mp);
}
return devices;
}


Ptr<WifiNetDevice>
MeshHelper::CreateInterface (Ptr<Node> node, uint16_t channelId) const
{
Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice> ();

Ptr<MeshWifiInterfaceMac> mac = m_mac.Create<MeshWifiInterfaceMac>
();
NS_ASSERT (mac != 0);
mac->SetSsid (Ssid ());
Ptr<WifiRemoteStationManager> manager =
m_stationManager.Create<WifiRemoteStationManager> ();
NS_ASSERT (manager != 0);
//Ptr<WifiPhy> phy = phyHelper.Create (node, device);
mac->SetAddress (Mac48Address::Allocate ());
mac->ConfigureStandard (m_standard);
//phy->ConfigureStandard (m_standard);
device->SetMac (mac);
//device->SetPhy (phy);
device->SetRemoteStationManager (manager);
node->AddDevice (device);
///////////////////////////////////////////
//mac->SwitchFrequencyChannel (channelId);
/////////////////////////////////////////
return device;
}

-----------------------------------------------

it builds successfully but also following message

Command ['/home/muhr/Documents/cplus-ns3-workspace/MIMO_MESH_204/build/
debug/scratch/MIMO_MESH/MIMO_MESH'] exited with code -11

please help me to sort out this issue,

regards,





On Apr 20, 4:09 pm, Mathieu Lacage <mathieu.lac...@gmail.com> wrote:
> uint8_t *buffer = new uint8_t () [packet->GetSize ()];
> packet->CopyData (buffer, packet->GetSize ());
>
> On Tue, Apr 20, 2010 at 3:15 PM, Farrukh <mir.k...@gmail.com> wrote:
> > Hi,
> > i want to access the contents of Packets to implement desired
> > modulation scheme. How can i get the contents of the Packet,

Karl77

unread,
Apr 21, 2010, 9:43:39 AM4/21/10
to ns-3-users
Hello Mathieu, Farrukh,...

i inserted ur suggested code to get the contents of the packet in wifi-
simple-adhoc.cc example,
i did like (the amendmented part is in ****, other is same as in
origional )
+++++++++++++++++++++++++++++++++++++++++++++++++++

#include "ns3/core-module.h"
#include "ns3/common-module.h"
#include "ns3/node-module.h"
#include "ns3/helper-module.h"
#include "ns3/mobility-module.h"
#include "ns3/contrib-module.h"
#include "ns3/wifi-module.h"

#include <iostream>
#include <fstream>
#include <vector>
#include <string>

NS_LOG_COMPONENT_DEFINE ("WifiSimpleAdhoc");

using namespace ns3;
*************************************
Packet *p = new Packet(1000);
uint32_t D;
***********************************
void ReceivePacket (Ptr<Socket> socket)
{

NS_LOG_UNCOND ("Received one packet!");
}

static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
uint32_t pktCount, Time pktInterval )
{
if (pktCount > 0)
{
socket->Send (p);
*********************************
uint8_t *buffer = new uint8_t(p->GetSize ());
cout<<"Packet Size"<<p->GetSize ()<<endl;
D= p->CopyData (buffer, p->GetSize ());
cout<<"D"<< D <<endl;
**************************************

Simulator::Schedule (pktInterval, &GenerateTraffic,
socket, pktSize,pktCount-1,
pktInterval);
}
else
{
socket->Close();
}
}


int main (int argc, char *argv[])
{
std::string phyMode ("wifib-1mbs");
double rss = -80; // -dBm
uint32_t packetSize = 1000; // bytes
uint32_t numPackets = 1;
double interval = 1.0; // seconds
bool verbose = false;

CommandLine cmd;

cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
cmd.AddValue ("rss", "received signal strength", rss);
cmd.AddValue ("packetSize", "size of application packet sent",
packetSize);
cmd.AddValue ("numPackets", "number of packets generated",
numPackets);
cmd.AddValue ("interval", "interval (seconds) between packets",
interval);
cmd.AddValue ("verbose", "turn on all WifiNetDevice log components",
verbose);

cmd.Parse (argc, argv);
// Convert to time object
Time interPacketInterval = Seconds (interval);

// disable fragmentation for frames below 2200 bytes
Config::SetDefault
("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue
("2200"));
// turn off RTS/CTS for frames below 2200 bytes
Config::SetDefault
("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue
("2200"));
// Fix non-unicast data rate to be the same as that of unicast
Config::SetDefault
("ns3::WifiRemoteStationManager::NonUnicastMode",
StringValue (phyMode));

NodeContainer c;
c.Create (2);

// The below set of helpers will help us to put together the wifi
NICs we want
WifiHelper wifi;
if (verbose)
{
wifi.EnableLogComponents (); // Turn on all Wifi logging
}
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);

YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
// This is one parameter that matters when using FixedRssLossModel
// set it to zero; otherwise, gain will be added
wifiPhy.Set ("RxGain", DoubleValue (0) );
// ns-3 supports RadioTap and Prism tracing extensions for 802.11b
wifiPhy.SetPcapDataLinkType
(YansWifiPhyHelper::DLT_IEEE802_11_RADIO);

YansWifiChannelHelper wifiChannel ;
wifiChannel.SetPropagationDelay
("ns3::ConstantSpeedPropagationDelayModel");
// The below FixedRssLossModel will cause the rss to be fixed
regardless
// of the distance between the two stations, and the transmit power
wifiChannel.AddPropagationLoss
("ns3::FixedRssLossModel","Rss",DoubleValue(rss));
wifiPhy.SetChannel (wifiChannel.Create ());

// Add a non-QoS upper mac, and disable rate control
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode",StringValue(phyMode),

"ControlMode",StringValue(phyMode));
// Set it to adhoc mode
wifiMac.SetType ("ns3::AdhocWifiMac");
NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c);

// Note that with FixedRssLossModel, the positions below are not
// used for received signal strength.
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc =
CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (0.0, 0.0, 0.0));
positionAlloc->Add (Vector (5.0, 0.0, 0.0));
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (c);

InternetStackHelper internet;
internet.Install (c);

Ipv4AddressHelper ipv4;
NS_LOG_INFO ("Assign IP Addresses.");
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer i = ipv4.Assign (devices);

TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (0), tid);
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (),
80);
recvSink->Bind (local);
recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));

Ptr<Socket> source = Socket::CreateSocket (c.Get (1), tid);
InetSocketAddress remote = InetSocketAddress (Ipv4Address
("255.255.255.255"), 80);
source->Connect (remote);

// Tracing
wifiPhy.EnablePcap ("wifi-simple-adhoc", devices);

// Output what we are doing
NS_LOG_UNCOND ("Testing " << numPackets << " packets sent with
receiver rss " << rss );

Simulator::ScheduleWithContext (source->GetNode ()->GetId (),
Seconds (1.0), &GenerateTraffic,
source, packetSize, numPackets,
interPacketInterval);

Simulator::Run ();
Simulator::Destroy ();

return 0;
}

++++++++++++++++++++++++++++++++++++++++++++++++++++++++

when i run this, i got following
""""
'build' finished successfully (6.934s)
Testing 1 packets sent with receiver rss -80
Packet Size1000
D0
Command ['/home/karl/Documents/NS3/build/debug/examples/wireless/wifi-
simple-adhoc'] exited with code -11
"""

Plz Help to sort out this
regards,
Karl


On Apr 20, 4:09 pm, Mathieu Lacage <mathieu.lac...@gmail.com> wrote:
> uint8_t *buffer = new uint8_t () [packet->GetSize ()];
> packet->CopyData (buffer, packet->GetSize ());
>

Mathieu Lacage

unread,
Apr 22, 2010, 2:32:31 AM4/22/10
to ns-3-...@googlegroups.com
On Wed, Apr 21, 2010 at 3:43 PM, Karl77 <mathew...@googlemail.com> wrote:

> when i run this, i got following
> """"
> 'build' finished successfully (6.934s)
> Testing 1 packets sent with receiver rss -80
> Packet Size1000
> D0
> Command ['/home/karl/Documents/NS3/build/debug/examples/wireless/wifi-
> simple-adhoc'] exited with code -11
> """

I am getting a bit "tired" of getting this development question which
has nothing to do with ns-3 so, here is my answer, one more time. This
is a segfault, use a debugger.

./waf shell
gdb build/debug/examples/wireless/wifi-simple-adhoc

RTFM gdb

Mathieu
--
Mathieu Lacage <mathieu...@gmail.com>

Reply all
Reply to author
Forward
0 new messages