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 :
and the commande which invert bytes : std :: bitset <6> foo (std :: string ("010101"));
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.
#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;
}