A Discrete-Event Network Simulator
API
example-ping-lr-wpan.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Universita' di Firenze, Italy
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
19  */
20 
21 
22 #include <fstream>
23 #include "ns3/core-module.h"
24 #include "ns3/internet-module.h"
25 #include "ns3/applications-module.h"
26 #include "ns3/ipv6-static-routing-helper.h"
27 #include "ns3/mobility-module.h"
28 #include "ns3/spectrum-module.h"
29 #include "ns3/propagation-loss-model.h"
30 #include "ns3/log.h"
31 #include "ns3/ipv6-routing-table-entry.h"
32 #include "ns3/sixlowpan-module.h"
33 #include "ns3/lr-wpan-module.h"
34 
35 using namespace ns3;
36 
37 
38 
39 int main (int argc, char** argv)
40 {
41 #if 0
42  LogComponentEnable ("Ping6Application", LOG_LEVEL_ALL);
43  LogComponentEnable ("LrWpanMac",LOG_LEVEL_ALL);
44  LogComponentEnable ("LrWpanPhy",LOG_LEVEL_ALL);
45  LogComponentEnable ("LrWpanNetDevice", LOG_LEVEL_ALL);
46  LogComponentEnable ("SixLowPanNetDevice", LOG_LEVEL_ALL);
47 #endif
48 
50  nodes.Create(2);
51 
53  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
54  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
55  "MinX", DoubleValue (0.0),
56  "MinY", DoubleValue (0.0),
57  "DeltaX", DoubleValue (20),
58  "DeltaY", DoubleValue (20),
59  "GridWidth", UintegerValue (3),
60  "LayoutType", StringValue ("RowFirst"));
61  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
62  mobility.Install (nodes);
63 
64  LrWpanHelper lrWpanHelper;
65  // Add and install the LrWpanNetDevice for each node
66  NetDeviceContainer lrwpanDevices = lrWpanHelper.Install(nodes);
67 
68  // Fake PAN association and short address assignment.
69  lrWpanHelper.AssociateToPan (lrwpanDevices, 0);
70 
71  InternetStackHelper internetv6;
72  internetv6.Install (nodes);
73 
74  SixLowPanHelper sixlowpan;
75  NetDeviceContainer devices = sixlowpan.Install (lrwpanDevices);
76 
77  Ipv6AddressHelper ipv6;
78  ipv6.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64));
79  Ipv6InterfaceContainer deviceInterfaces;
80  deviceInterfaces = ipv6.Assign (devices);
81  // check if adresses are assigned
82  //std::cout<< deviceInterfaces.GetAddress(0,1)<<std::endl;
83  //std::cout<< deviceInterfaces.GetAddress(1,1)<<std::endl;
84 
85 
86 
87  uint32_t packetSize = 10;
88  uint32_t maxPacketCount = 5;
89  Time interPacketInterval = Seconds (1.);
90  Ping6Helper ping6;
91 
92  ping6.SetLocal (deviceInterfaces.GetAddress (0, 1));
93  ping6.SetRemote (deviceInterfaces.GetAddress (1, 1));
94 
95  ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
96  ping6.SetAttribute ("Interval", TimeValue (interPacketInterval));
97  ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
98  ApplicationContainer apps = ping6.Install (nodes.Get (0));
99 
100  apps.Start (Seconds (1.0));
101  apps.Stop (Seconds (10.0));
102 
103  AsciiTraceHelper ascii;
104  lrWpanHelper.EnableAsciiAll (ascii.CreateFileStream ("Ping-6LoW-lr-wpan.tr"));
105  lrWpanHelper.EnablePcapAll (std::string ("Ping-6LoW-lr-wpan"), true);
106 
107  Simulator::Stop (Seconds (10));
108 
109  Simulator::Run ();
111 
112 }
113 
holds a vector of ns3::Application pointers.
NetDeviceContainer Install(NodeContainer c)
Install a LrWpanNetDevice and the associated structures (e.g., channel) in the nodes.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Manage ASCII trace files for device models.
Definition: trace-helper.h:155
tuple devices
Definition: first.py:32
Keep track of a set of IPv6 interfaces.
Hold variables of type string.
Definition: string.h:41
ApplicationContainer Install(NodeContainer c)
Install the application in Nodes.
Definition: ping6-helper.cc:50
static void Run(void)
Run the simulation.
Definition: simulator.cc:200
aggregate IP/TCP/UDP functionality to existing Nodes.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
void AssociateToPan(NetDeviceContainer c, uint16_t panId)
Associate the nodes to the same PAN.
void SetAttribute(std::string name, const AttributeValue &value)
Set some attributes.
Definition: ping6-helper.cc:45
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits. ...
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
tuple nodes
Definition: first.py:25
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:351
tuple mobility
Definition: third.py:101
void EnablePcapAll(std::string prefix, bool promiscuous=false)
Enable pcap output on each device (which is of the appropriate type) in the set of all nodes created ...
void SetLocal(Ipv6Address ip)
Set the local IPv6 address.
Definition: ping6-helper.cc:35
AttributeValue implementation for Time.
Definition: nstime.h:957
Hold an unsigned integer type.
Definition: uinteger.h:44
holds a vector of ns3::NetDevice pointers
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:164
NetDeviceContainer Install(NetDeviceContainer c)
Install the SixLoWPAN stack on top of an existing NetDevice.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
void SetRemote(Ipv6Address ip)
Set the remote IPv6 address.
Definition: ping6-helper.cc:40
Helper class to auto-assign global IPv6 unicast addresses.
Helper class used to assign positions and mobility models to nodes.
Describes an IPv6 address.
Definition: ipv6-address.h:47
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:208
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
Describes an IPv6 prefix.
Definition: ipv6-address.h:389
Print everything.
Definition: log.h:112
void EnableAsciiAll(std::string prefix)
Enable ascii trace output on each device (which is of the appropriate type) in the set of all nodes c...
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
static const uint32_t packetSize
helps to manage and create IEEE 802.15.4 NetDevice objects
Setup a sixlowpan stack to be used as a shim between IPv6 and a generic NetDevice.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
Ping6 application helper.
Definition: ping6-helper.h:39
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.