8#include "ns3/acoustic-modem-energy-model-helper.h"
9#include "ns3/basic-energy-source-helper.h"
10#include "ns3/core-module.h"
11#include "ns3/energy-source-container.h"
12#include "ns3/internet-module.h"
13#include "ns3/mobility-helper.h"
14#include "ns3/mobility-model.h"
15#include "ns3/node-container.h"
16#include "ns3/uan-channel.h"
17#include "ns3/uan-helper.h"
100 MobilityHelper mobilityHelper;
103 m_nodes.Get(0)->GetObject<MobilityModel>()->SetPosition(Vector(0, 0, 0));
104 m_nodes.Get(1)->GetObject<MobilityModel>()->SetPosition(Vector(100, 0, 0));
105 m_nodes.Get(2)->GetObject<MobilityModel>()->SetPosition(Vector(-100, 0, 0));
111 BasicEnergySourceHelper energySourceHelper;
112 energySourceHelper.
Set(
"BasicEnergySourceInitialEnergyJ", DoubleValue(900000));
121 NetDeviceContainer netDeviceContainer = uanHelper.
Install(
m_nodes, channel);
122 EnergySourceContainer energySourceContainer;
126 energySourceContainer.
Add((*node)->GetObject<EnergySourceContainer>()->Get(0));
129 AcousticModemEnergyModelHelper acousticModemEnergyModelHelper;
130 acousticModemEnergyModelHelper.
Install(netDeviceContainer, energySourceContainer);
132 InternetStackHelper internetStackHelper;
135 Ipv6AddressHelper ipv6AddressHelper;
136 ipv6AddressHelper.
SetBase(Ipv6Address(
"2002::"), Ipv6Prefix(64));
137 ipv6AddressHelper.
Assign(netDeviceContainer);
142 (*node)->GetObject<Icmpv6L4Protocol>()->SetAttribute(
"DAD", BooleanValue(
false));
143 (*node)->GetObject<Icmpv6L4Protocol>()->SetAttribute(
"ReachableTime",
145 (*node)->GetObject<Icmpv6L4Protocol>()->SetAttribute(
"RetransmissionTime",
155 while (socket->GetRxAvailable() > 0)
157 Ptr<Packet> packet = socket->RecvFrom(srcAddress);
158 uint8_t energyReading;
159 packet->CopyData(&energyReading, 1);
166 <<
" | Energy: " << +energyReading <<
"%");
179 if ((*node)->GetObject<Ipv6>())
197 (*node)->GetObject<Ipv6L3Protocol>()->GetInterface(1)->GetAddress(1).GetAddress();
202 ((*node)->GetObject<EnergySourceContainer>()->Get(0)->GetEnergyFraction()) * 100;
206 double time = uniformRandomVariable->GetValue(0, 60);
218 m_sockets[node]->SendTo(pkt, 0, ipv6_destination);
237 socket->second->Close();
242main(
int argc,
char* argv[])
245 cmd.Parse(argc, argv);
This example shows the usage of UDP over 6LoWPAN to transfer data.
void Teardown()
Teardown the experiment.
void PrintReceivedPacket(Ptr< Socket > socket)
Print the received packet.
NodeContainer m_nodes
UAN nodes.
void Prepare()
Prepare the experiment.
void SendSinglePacket(Ptr< Node > node, Ptr< Packet > pkt, Ipv6Address dst)
Send a packet from one of the nodes.
void SendPackets()
Send a packet from all the nodes.
void SetupCommunications()
Set the UAN nodes communication channels.
void SetupPositions()
Set the UAN nodes position.
std::map< Ptr< Node >, Ptr< Socket > > m_sockets
send and receive sockets
void SetupApplications()
Set the UAN nodes communication channels.
void SetupEnergy()
Set the UAN nodes energy.
void Set(std::string name, const AttributeValue &v) override
Parse command-line arguments.
energy::DeviceEnergyModelContainer Install(Ptr< NetDevice > device, Ptr< energy::EnergySource > source) const
energy::EnergySourceContainer Install(Ptr< Node > node) const
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
static bool IsMatchingType(const Address &addr)
If the address match.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
Describes an IPv6 address.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void SetMobilityModel(std::string type, Ts &&... args)
keep track of a set of node pointers.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static Time Now()
Return the current simulation virtual time.
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
static TypeId LookupByName(std::string name)
Get a TypeId by name.
NetDeviceContainer Install(NodeContainer c) const
This method creates a simple ns3::UanChannel (with a default ns3::UanNoiseModelDefault and ns3::UanPr...
void Add(EnergySourceContainer container)
void experiment(std::string queue_disc_type)
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time Days(double value)
Construct a Time in the indicated unit.
Time Hours(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...