Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(156)

Unified Diff: src/dsdv6/examples/dsdv6-manet.cc

Issue 304640043: IPv6 Support for DSDV in ns-3
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/dsdv6/doc/dsdv6.rst ('k') | src/dsdv6/examples/wscript » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/dsdv6/examples/dsdv6-manet.cc
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/dsdv6/examples/dsdv6-manet.cc
@@ -0,0 +1,337 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2010 Hemanth Narra
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Hemanth Narra <hemanth@ittc.ku.com>
+ *
+ * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
+ * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
+ * Information and Telecommunication Technology Center (ITTC)
+ * and Department of Electrical Engineering and Computer Science
+ * The University of Kansas Lawrence, KS USA.
+ *
+ * Work supported in part by NSF FIND (Future Internet Design) Program
+ * under grant CNS-0626918 (Postmodern Internet Architecture),
+ * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
+ * US Department of Defense (DoD), and ITTC at The University of Kansas.
+ */
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/applications-module.h"
+#include "ns3/mobility-module.h"
+#include "ns3/config-store-module.h"
+#include "ns3/wifi-module.h"
+#include "ns3/internet-module.h"
+#include "ns3/dsdv6-helper.h"
+#include <iostream>
+#include <cmath>
+
+using namespace ns3;
+
+uint16_t port = 9;
+
+NS_LOG_COMPONENT_DEFINE ("dsdv6ManetExample");
+
+class Dsdv6ManetExample
+{
+public:
+ Dsdv6ManetExample ();
+ void CaseRun (uint32_t nWifis,
+ uint32_t nSinks,
+ double totalTime,
+ std::string rate,
+ std::string phyMode,
+ uint32_t nodeSpeed,
+ uint32_t periodicUpdateInterval,
+ uint32_t settlingTime,
+ double dataStart,
+ bool printRoutes,
+ std::string CSVfileName);
+
+private:
+ uint32_t m_nWifis;
+ uint32_t m_nSinks;
+ double m_totalTime;
+ std::string m_rate;
+ std::string m_phyMode;
+ uint32_t m_nodeSpeed;
+ uint32_t m_periodicUpdateInterval;
+ uint32_t m_settlingTime;
+ double m_dataStart;
+ uint32_t bytesTotal;
+ uint32_t packetsReceived;
+ bool m_printRoutes;
+ std::string m_CSVfileName;
+
+ NodeContainer nodes;
+ NetDeviceContainer devices;
+ Ipv6InterfaceContainer interfaces;
+
+private:
+ void CreateNodes ();
+ void CreateDevices (std::string tr_name);
+ void InstallInternetStack (std::string tr_name);
+ void InstallApplications ();
+ void SetupMobility ();
+ void ReceivePacket (Ptr <Socket> );
+ Ptr <Socket> SetupPacketReceive (Ipv6Address, Ptr <Node> );
+ void CheckThroughput ();
+
+};
+
+int main (int argc, char **argv)
+{
+ Dsdv6ManetExample test;
+ uint32_t nWifis = 30;
+ uint32_t nSinks = 10;
+ double totalTime = 100.0;
+ std::string rate ("8kbps");
+ std::string phyMode ("DsssRate11Mbps");
+ uint32_t nodeSpeed = 10; // in m/s
+ std::string appl = "all";
+ uint32_t periodicUpdateInterval = 15;
+ uint32_t settlingTime = 6;
+ double dataStart = 50.0;
+ bool printRoutingTable = true;
+ std::string CSVfileName = "Dsdv6ManetExample.csv";
+
+ CommandLine cmd;
+ cmd.AddValue ("nWifis", "Number of wifi nodes[Default:30]", nWifis);
+ cmd.AddValue ("nSinks", "Number of wifi sink nodes[Default:10]", nSinks);
+ cmd.AddValue ("totalTime", "Total Simulation time[Default:100]", totalTime);
+ cmd.AddValue ("phyMode", "Wifi Phy mode[Default:DsssRate11Mbps]", phyMode);
+ cmd.AddValue ("rate", "CBR traffic rate[Default:8kbps]", rate);
+ cmd.AddValue ("nodeSpeed", "Node speed in RandomWayPoint model[Default:10]", nodeSpeed);
+ cmd.AddValue ("periodicUpdateInterval", "Periodic Interval Time[Default=15]", periodicUpdateInterval);
+ cmd.AddValue ("settlingTime", "Settling Time before sending out an update for changed metric[Default=6]", settlingTime);
+ cmd.AddValue ("dataStart", "Time at which nodes start to transmit data[Default=50.0]", dataStart);
+ cmd.AddValue ("printRoutingTable", "print routing table for nodes[Default:1]", printRoutingTable);
+ cmd.AddValue ("CSVfileName", "The name of the CSV output file name[Default:Dsdv6ManetExample.csv]", CSVfileName);
+ cmd.Parse (argc, argv);
+
+ std::ofstream out (CSVfileName.c_str ());
+ out << "SimulationSecond," <<
+ "ReceiveRate," <<
+ "PacketsReceived," <<
+ "NumberOfSinks," <<
+ std::endl;
+ out.close ();
+
+ SeedManager::SetSeed (12345);
+ //LogComponentEnable ("Dsdv6RoutingProtocol", LOG_LEVEL_ALL);
+ //LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_ALL);
+ Config::SetDefault ("ns3::OnOffApplication::PacketSize", StringValue ("1000"));
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue (rate));
+ Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (phyMode));
+ Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2000"));
+
+ test = Dsdv6ManetExample ();
+ test.CaseRun (nWifis, nSinks, totalTime, rate, phyMode, nodeSpeed, periodicUpdateInterval,
+ settlingTime, dataStart, printRoutingTable, CSVfileName);
+
+ return 0;
+}
+
+Dsdv6ManetExample::Dsdv6ManetExample ()
+ : bytesTotal (0),
+ packetsReceived (0)
+{
+}
+
+void
+Dsdv6ManetExample::ReceivePacket (Ptr <Socket> socket)
+{
+ NS_LOG_UNCOND (Simulator::Now ().GetSeconds () << " Received one packet!");
+ Ptr <Packet> packet;
+ while ((packet = socket->Recv ()))
+ {
+ bytesTotal += packet->GetSize ();
+ packetsReceived += 1;
+ }
+}
+
+void
+Dsdv6ManetExample::CheckThroughput ()
+{
+ double kbs = (bytesTotal * 8.0) / 1000;
+ bytesTotal = 0;
+
+ std::ofstream out (m_CSVfileName.c_str (), std::ios::app);
+
+ out << (Simulator::Now ()).GetSeconds () << "," << kbs << "," << packetsReceived << "," << m_nSinks << std::endl;
+
+ out.close ();
+ packetsReceived = 0;
+ Simulator::Schedule (Seconds (1.0), &Dsdv6ManetExample::CheckThroughput, this);
+}
+
+Ptr <Socket>
+Dsdv6ManetExample::SetupPacketReceive (Ipv6Address addr, Ptr <Node> node)
+{
+
+ TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
+ Ptr <Socket> sink = Socket::CreateSocket (node, tid);
+ Inet6SocketAddress local = Inet6SocketAddress (addr, port);
+ sink->Bind (local);
+ sink->SetRecvCallback (MakeCallback ( &Dsdv6ManetExample::ReceivePacket, this));
+
+ return sink;
+}
+
+void
+Dsdv6ManetExample::CaseRun (uint32_t nWifis, uint32_t nSinks, double totalTime, std::string rate,
+ std::string phyMode, uint32_t nodeSpeed, uint32_t periodicUpdateInterval, uint32_t settlingTime,
+ double dataStart, bool printRoutes, std::string CSVfileName)
+{
+ m_nWifis = nWifis;
+ m_nSinks = nSinks;
+ m_totalTime = totalTime;
+ m_rate = rate;
+ m_phyMode = phyMode;
+ m_nodeSpeed = nodeSpeed;
+ m_periodicUpdateInterval = periodicUpdateInterval;
+ m_settlingTime = settlingTime;
+ m_dataStart = dataStart;
+ m_printRoutes = printRoutes;
+ m_CSVfileName = CSVfileName;
+
+ std::stringstream ss;
+ ss << m_nWifis;
+ std::string t_nodes = ss.str ();
+
+ std::stringstream ss3;
+ ss3 << m_totalTime;
+ std::string sTotalTime = ss3.str ();
+
+ std::string tr_name = "Dsdv6_Manet_" + t_nodes + "Nodes_" + sTotalTime + "SimTime";
+ std::cout << "Trace file generated is " << tr_name << ".tr\n";
+
+ CreateNodes ();
+ CreateDevices (tr_name);
+ SetupMobility ();
+ InstallInternetStack (tr_name);
+ InstallApplications ();
+
+ std::cout << "\nStarting simulation for " << m_totalTime << " s ...\n";
+
+ CheckThroughput ();
+
+ Simulator::Stop (Seconds (m_totalTime));
+ Simulator::Run ();
+ Simulator::Destroy ();
+}
+
+void
+Dsdv6ManetExample::CreateNodes ()
+{
+ std::cout << "Creating " << (unsigned) m_nWifis << " nodes.\n";
+ nodes.Create (m_nWifis);
+ NS_ASSERT_MSG (m_nWifis > m_nSinks, "Sinks must be less or equal to the number of nodes in network");
+}
+
+void
+Dsdv6ManetExample::SetupMobility ()
+{
+ MobilityHelper mobility;
+ ObjectFactory pos;
+ pos.SetTypeId ("ns3::RandomRectanglePositionAllocator");
+ pos.Set ("X", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=1000.0]"));
+ pos.Set ("Y", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=1000.0]"));
+
+ std::ostringstream speedConstantRandomVariableStream;
+ speedConstantRandomVariableStream << "ns3::ConstantRandomVariable[Constant="
+ << m_nodeSpeed
+ << "]";
+
+ Ptr <PositionAllocator> taPositionAlloc = pos.Create ()->GetObject <PositionAllocator> ();
+ mobility.SetMobilityModel ("ns3::RandomWaypointMobilityModel", "Speed", StringValue (speedConstantRandomVariableStream.str ()),
+ "Pause", StringValue ("ns3::ConstantRandomVariable[Constant=2.0]"), "PositionAllocator", PointerValue (taPositionAlloc));
+ mobility.SetPositionAllocator (taPositionAlloc);
+ mobility.Install (nodes);
+}
+
+void
+Dsdv6ManetExample::CreateDevices (std::string tr_name)
+{
+ WifiMacHelper wifiMac;
+ wifiMac.SetType ("ns3::AdhocWifiMac");
+ YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
+ YansWifiChannelHelper wifiChannel;
+ wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
+ wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel");
+ wifiPhy.SetChannel (wifiChannel.Create ());
+ WifiHelper wifi;
+ wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
+ wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue (m_phyMode), "ControlMode",
+ StringValue (m_phyMode));
+ devices = wifi.Install (wifiPhy, wifiMac, nodes);
+
+ AsciiTraceHelper ascii;
+ wifiPhy.EnableAsciiAll (ascii.CreateFileStream (tr_name + ".tr"));
+ wifiPhy.EnablePcapAll (tr_name);
+}
+
+void
+Dsdv6ManetExample::InstallInternetStack (std::string tr_name)
+{
+ Dsdv6Helper Dsdv6;
+ Dsdv6.Set ("PeriodicUpdateInterval", TimeValue (Seconds (m_periodicUpdateInterval)));
+ Dsdv6.Set ("SettlingTime", TimeValue (Seconds (m_settlingTime)));
+ InternetStackHelper stack;
+ stack.SetRoutingHelper (Dsdv6); // has effect on the next Install ()
+ stack.Install (nodes);
+ Ipv6AddressHelper address;
+ address.SetBase ("2001:1::", Ipv6Prefix (64));
+ interfaces = address.Assign (devices);
+ if (m_printRoutes)
+ {
+ Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ((tr_name + ".routes"), std::ios::out);
+ Dsdv6.PrintRoutingTableAllAt (Seconds (m_periodicUpdateInterval), routingStream);
+ Dsdv6.PrintRoutingTableAllAt (Seconds (m_periodicUpdateInterval * 2), routingStream);
+ Dsdv6.PrintRoutingTableAllAt (Seconds (m_periodicUpdateInterval * 3), routingStream);
+ Dsdv6.PrintRoutingTableAllAt (Seconds (m_periodicUpdateInterval * 4), routingStream);
+ }
+}
+
+void
+Dsdv6ManetExample::InstallApplications ()
+{
+ for (uint32_t i = 0; i <= m_nSinks - 1; i++ )
+ {
+ Ptr<Node> node = NodeList::GetNode (i);
+ Ipv6Address nodeAddress = node->GetObject<Ipv6> ()->GetAddress (1, 1).GetAddress ();
+ Ptr<Socket> sink = SetupPacketReceive (nodeAddress, node);
+ }
+
+ for (uint32_t clientNode = 0; clientNode <= m_nWifis - 1; clientNode++ )
+ {
+ for (uint32_t j = 0; j <= m_nSinks - 1; j++ )
+ {
+ OnOffHelper onoff1 ("ns3::UdpSocketFactory", Address (Inet6SocketAddress (interfaces.GetAddress (j,1), port)));
+ onoff1.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"));
+ onoff1.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"));
+
+ if (j != clientNode)
+ {
+ ApplicationContainer apps1 = onoff1.Install (nodes.Get (clientNode));
+ Ptr<UniformRandomVariable> var = CreateObject<UniformRandomVariable> ();
+ apps1.Start (Seconds (var->GetValue (m_dataStart, m_dataStart + 1)));
+ apps1.Stop (Seconds (m_totalTime));
+ }
+ }
+ }
+}
+
« no previous file with comments | « src/dsdv6/doc/dsdv6.rst ('k') | src/dsdv6/examples/wscript » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b