OLD | NEW |
(Empty) | |
| 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 * Modified by: Gonçalo AtanĂ¡sio <goncalo.atanasio@tecnico.ulisboa.pt> |
| 20 */ |
| 21 |
| 22 |
| 23 // Network topology |
| 24 // 1 Sink |
| 25 // 19 Nodes |
| 26 //---------------------------Stack------------------- |
| 27 // Nodes |
| 28 // +---------+···· |
| 29 // | APP | UDP_Server (sink)/UDP_Client(all nodes except sink)· |
| 30 // +---------+···· |
| 31 // | UDP |······ |
| 32 // +---------+···· |
| 33 // | DSDVIpv6|···· |
| 34 // +---------+···· |
| 35 // | IPv6 |···· |
| 36 // +---------+···· |
| 37 // | 6LoWPAN |···· |
| 38 // +---------+···· |
| 39 // | LRWPAN |····· |
| 40 // +---------+···· |
| 41 // |
| 42 // - Tracing of queues and packet receptions to file "example-sixlowpan.tr" |
| 43 // Note that the Pcap packet dissection will not be very meaningful. |
| 44 // See the module's documentation for a discussion about this. |
| 45 |
| 46 #include <fstream> |
| 47 #include "ns3/dsdv-helper-ipv6.h" |
| 48 #include "ns3/core-module.h" |
| 49 #include "ns3/internet-module.h" |
| 50 #include "ns3/csma-module.h" |
| 51 #include "ns3/applications-module.h" |
| 52 #include "ns3/ipv6-static-routing-helper.h" |
| 53 #include "ns3/ipv6-routing-table-entry.h" |
| 54 #include "ns3/ping6-helper.h" |
| 55 #include "ns3/sixlowpan-module.h" |
| 56 #include "ns3/lr-wpan-module.h" |
| 57 #include "ns3/mobility-module.h" |
| 58 |
| 59 using namespace ns3; |
| 60 |
| 61 NS_LOG_COMPONENT_DEFINE ("DsdvIpv6_test"); |
| 62 |
| 63 int main (int argc, char** argv) |
| 64 { |
| 65 |
| 66 LogComponentEnable ("UdpClient", LOG_LEVEL_ALL); |
| 67 LogComponentEnable ("UdpServer", LOG_LEVEL_ALL); |
| 68 // LogComponentEnable("Dsdvipv6RoutingProtocol",LOG_LEVEL_ALL); |
| 69 // LogComponentEnable("Ipv6L3Protocol",LOG_LEVEL_ALL); |
| 70 // LogComponentEnable("Ipv6Interface",LOG_LEVEL_ALL); |
| 71 // LogComponentEnable("SixLowPanNetDevice",LOG_LEVEL_ALL); |
| 72 // LogComponentEnable("LrWpanPhy",LOG_LEVEL_ALL); |
| 73 // LogComponentEnable ("LrWpanMac",LOG_LEVEL_ALL); |
| 74 // LogComponentEnable ("LrWpanNetDevice", LOG_LEVEL_ALL); |
| 75 // LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_ALL); |
| 76 // LogComponentEnable ("Icmpv6Header", LOG_LEVEL_ALL); |
| 77 // LogComponentEnable ("UdpSocket", LOG_LEVEL_ALL); |
| 78 NodeContainer n; |
| 79 n.Create (20); |
| 80 |
| 81 //NODES MOBILITY 0 |
| 82 MobilityHelper mobility; |
| 83 ObjectFactory pos; |
| 84 pos.SetTypeId ("ns3::RandomRectanglePositionAllocator"); |
| 85 pos.Set ("X", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=300.0]")); |
| 86 pos.Set ("Y", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=300.0]")); |
| 87 std::ostringstream speedConstantRandomVariableStream; |
| 88 speedConstantRandomVariableStream << "ns3::ConstantRandomVariable[Constant=" |
| 89 << 0 |
| 90 << "]"; |
| 91 Ptr <PositionAllocator> taPositionAlloc = pos.Create ()->GetObject <PositionAl
locator> (); |
| 92 mobility.SetMobilityModel ("ns3::RandomWaypointMobilityModel", "Speed", String
Value (speedConstantRandomVariableStream.str ()), |
| 93 "Pause", StringValue ("ns3::ConstantRandomVariable[
Constant=2.0]"), "PositionAllocator", PointerValue (taPositionAlloc)); |
| 94 mobility.SetPositionAllocator (taPositionAlloc); |
| 95 |
| 96 mobility.Install (n); |
| 97 ·· |
| 98 NS_LOG_INFO ("Create channels."); |
| 99 LrWpanHelper lrWpanHelper; |
| 100 ·· |
| 101 // Add and install the LrWpanNetDevice for each node |
| 102 NetDeviceContainer d = lrWpanHelper.Install(n); |
| 103 |
| 104 //Fake PAN association and short address assignment. |
| 105 lrWpanHelper.AssociateToPan (d, 0); |
| 106 |
| 107 //Create DSDVIpv6 routing |
| 108 Dsdvipv6Helper dsdv; |
| 109 dsdv.Set ("PeriodicUpdateInterval", TimeValue (Seconds (1))); |
| 110 dsdv.Set ("SettlingTime", TimeValue (Seconds (6))); |
| 111 dsdv.Set("GenerateUpdates", BooleanValue (true));//True in sink. Sink sends hi
s table entry to all the other nodes. |
| 112 //Routes output at 21.5s |
| 113 Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> (("routes
_dsdvIpv6.routes"), std::ios::out); |
| 114 dsdv.PrintRoutingTableAllAt (Seconds(21.5), routingStream); //Change to get ro
utes in other time |
| 115 |
| 116 NS_LOG_INFO ("Create IPv6 Internet Stack"); |
| 117 InternetStackHelper internetv6; |
| 118 internetv6.SetRoutingHelper (dsdv); |
| 119 Ptr<Node> node_sink = n.Get(0); |
| 120 internetv6.Install (node_sink); |
| 121 Ptr<Node> node_aux; |
| 122 dsdv.Set("GenerateUpdates", BooleanValue (false));//False in all other nodes.
They propagate the sink entry but not theirs. |
| 123 internetv6.SetRoutingHelper (dsdv); |
| 124 for (uint32_t i=1;i<n.GetN();i++){ |
| 125 node_aux=n.Get(i); |
| 126 internetv6.Install (node_aux); |
| 127 } |
| 128 SixLowPanHelper sixlowpanN; |
| 129 NetDeviceContainer six1 = sixlowpanN.Install (d); |
| 130 |
| 131 |
| 132 NS_LOG_INFO ("Create networks and assign IPv6 Addresses."); |
| 133 Ipv6AddressHelper ipv6; |
| 134 ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64)); |
| 135 Ipv6InterfaceContainer i = ipv6.Assign (six1); |
| 136 |
| 137 uint16_t port = 4000; |
| 138 UdpServerHelper server (port); |
| 139 ApplicationContainer apps = server.Install (n.Get (0)); |
| 140 apps.Start (Seconds (0.0)); |
| 141 apps.Stop (Seconds (40)); |
| 142 |
| 143 uint32_t MaxPacketSize = 50; |
| 144 Time interPacketInterval=Seconds(10); |
| 145 uint32_t maxPacketCount = 10; |
| 146 UdpClientHelper client (i.GetAddress (0,1), port); |
| 147 client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount)); |
| 148 client.SetAttribute ("PacketSize", UintegerValue (MaxPacketSize)); |
| 149 |
| 150 for (uint32_t i=1;i<n.GetN();i++){ |
| 151 interPacketInterval=interPacketInterval+Seconds(0.01);//jitter in send |
| 152 client.SetAttribute ("Interval", TimeValue (interPacketInterval)); |
| 153 apps = client.Install (n.Get (i)); |
| 154 apps.Start (interPacketInterval); |
| 155 apps.Stop (Seconds (40)); |
| 156 } |
| 157 |
| 158 |
| 159 AsciiTraceHelper ascii; |
| 160 lrWpanHelper.EnableAsciiAll (ascii.CreateFileStream ("DsdvIpv6_test.tr")); |
| 161 lrWpanHelper.EnablePcapAll (std::string ("DsdvIpv6_test"), true); |
| 162 |
| 163 Simulator::Stop (Seconds (40)); |
| 164 NS_LOG_INFO ("Run Simulation."); |
| 165 Simulator::Run (); |
| 166 Simulator::Destroy (); |
| 167 NS_LOG_INFO ("Done."); |
| 168 } |
| 169 |
OLD | NEW |