inject faults in packages

182 views
Skip to first unread message

Belkneni Maroua

unread,
Jan 29, 2014, 3:43:44 AM1/29/14
to ns-3-...@googlegroups.com
Hello, I am novice in ns3 I want to inject faults in packages sent for example Conversion of the bit (flip), that is to say the value of the Affected bit is inverted.
To see the behavior of the MAC layer in case of faults. help me please. 

Tommaso Pecorella

unread,
Jan 29, 2014, 7:04:46 AM1/29/14
to ns-3-...@googlegroups.com
Hi,

the simplest way is to define a new channel. In the channel model, you can modify the packets being sent.

Check simple channel (src/network/utils/simple-channel.cc) ad other channels in specific network modules for tips.


Hope this helps,

T.

Belkneni Maroua

unread,
Jan 31, 2014, 4:32:11 AM1/31/14
to ns-3-...@googlegroups.com
hi,Thank you for your answer but I want to know how to modify the contained of package sent in  wireless networks.

Tommaso Pecorella

unread,
Jan 31, 2014, 11:49:08 AM1/31/14
to ns-3-...@googlegroups.com
Hi,

my answer was *exactly* about that.
In the channel you'll have a pointer to the packet being sent. That packet is sent to the receives.
In the channel, modify the packet being sent to the receiver and you'll have what you're searching for.

Cheers,

T.

Belkneni Maroua

unread,
Feb 13, 2014, 8:57:47 AM2/13/14
to ns-3-...@googlegroups.com
hi,Thank you for your answer, I defined a new channel,now I want to Invert the bits of the packet, I find the command that allows us to access the contained of packages : 
 p-> CopyData (buffer, p-> GetSize ()); 
and the commande which invert bytes : std :: bitset <6> foo (std :: string ("010101")); 
std :: cout << foo.flip () << '\ n'; 
I don't know  my code is correct or not and I want your help so that I can invert the bytes of packets sent in the channel.
here is my code please healp me :

#include "ns3/core-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/applications-module.h"
#include "ns3/internet-module.h"
#include "ns3/network-module.h"
#include "ns3/config-store-module.h"
#include "ns3/simple-channel.h"
#include "ns3/simple-net-device.h"
#include "ns3/simulator.h"
#include "ns3/packet.h"
#include "ns3/log.h"
#include "ns3/node.h"


#include <iostream>       // std::cout
#include <string>         // std::string
#include <bitset>         // std::bitset
#include <fstream>
#include <vector>

using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("jdidScriptExample");


int main (int argc, char *argv[])
/*Ptr<Packet> pkt1 = Create<Packet> (reinterpret_cast<const uint8_t*> ("010101"), 6);
std::bitset<4> foo (std::string("0001"));
Ptr<Packet> p = pkt1-> ByteTagList.flip();
std::cout << foo.flip() << '\n';  
pkt1->bitset.flip;*/ 


std::bitset<6> foo (std::string("010101"));
std::cout << foo.flip() << '\n';


LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);

NodeContainer wifiNodes;
wifiNodes.Create (3);

YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();


class SimpleChannel : public Channel
{
public:
  static TypeId GetTypeId (void);
  SimpleChannel ();

  void Send (Ptr<Packet> p, uint16_t protocol, Mac48Address to, Mac48Address from, Ptr<SimpleNetDevice> sender);
  

  static std::string GetString (Ptr<Packet> p)
{
  uint8_t *buffer = new uint8_t[p->GetSize()];
  
  p->CopyData (buffer, p->GetSize ());
  return 0;

}
  void Add (Ptr<SimpleNetDevice> device);

  // inherited from ns3::Channel
  virtual uint32_t GetNDevices (void) const;
  virtual Ptr<NetDevice> GetDevice (uint32_t i) const;

private:
  std::vector<Ptr<SimpleNetDevice> > m_devices;
};


wifiPhy.SetChannel (wifiChannel.Create ());
WifiHelper wifi = WifiHelper::Default ();

NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();

wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager");
wifiMac.SetType("ns3::AdhocWifiMac");
NetDeviceContainer wifiDevices = wifi.Install( wifiPhy, wifiMac, wifiNodes );

MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator", 
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (5.0),
"DeltaY", DoubleValue (10.0),
"GridWidth", UintegerValue (3),
"LayoutType", StringValue ("RowFirst"));
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (wifiNodes);

InternetStackHelper internet;
internet.Install (wifiNodes);

Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer wifiInterfaces;
wifiInterfaces = address.Assign( wifiDevices );

UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (wifiNodes.Get( 0 ));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));

UdpEchoClientHelper echoClient (wifiInterfaces.GetAddress (0), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (2));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));

ApplicationContainer clientApps = echoClient.Install ( wifiNodes.Get( 2 ) );
clientApps.Start( Seconds (2.0) );
clientApps.Stop( Seconds (10.0) );

Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

Simulator::Stop (Seconds (5.05));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}


 

Tommaso Pecorella

unread,
Feb 13, 2014, 4:01:44 PM2/13/14
to ns-3-...@googlegroups.com
Hi,

it's a bit hard to read the code in this form- Mind attaching the sources ?

About the code, it seems ok (but then again, it's hard to read). However, from a quick look:
1) you'll need to change the class name. if I do remember correctly, "SimpleChannel" already exist.
2) you'll need to override the proper functions in the channel, I don't think you did it (yet).

Cheers,

T.

Prasad Iyer

unread,
Mar 15, 2017, 8:27:47 PM3/15/17
to ns-3-users
Hi Tommaso Pecorella

As mentioned by you we will have to use the simple channel
But can you please explain how should I use it.
Directly use the code of "src/network/utils/simple-channel.cc"
or call the source code of "simple-channel" from my code?

Regards,
Prasad Iyer

Tommaso Pecorella

unread,
Mar 16, 2017, 6:51:47 PM3/16/17
to ns-3-users
Hi,

please take a look at this example:
src/network/examples/packet-socket-apps.cc


T.
Reply all
Reply to author
Forward
0 new messages