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

Unified Diff: src/rns/examples/rns-dsdv-example.cc

Issue 7304093: SMECN protocol and RNS algorithm
Patch Set: Created 11 years, 1 month 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/rns/doc/source/rns-user.rst ('k') | src/rns/examples/rns-smecn-example.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/rns/examples/rns-dsdv-example.cc
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/rns/examples/rns-dsdv-example.cc
@@ -0,0 +1,175 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2012 Michal Paszta
+ *
+ * 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: Michal Paszta
+ */
+#include "ns3/rns-module.h"
+#include "ns3/core-module.h"
+#include "ns3/network-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/dsdv-module.h"
+#include "ns3/log.h"
+
+using namespace ns3;
+
+class RnsDsdvExample
+{
+public:
+
+ RnsDsdvExample() {};
+ void CaseRun(void);
+
+
+private:
+
+ NodeContainer * nodes;
+ NetDeviceContainer devices;
+ Ipv4InterfaceContainer interfaces;
+
+ void SetupDevices(void);
+ void SetupIpv4Stack(void);
+ void SetupMobility(void);
+ void SetupRns(void);
+
+ void CheckRedundancy(void);
+};
+
+int main (int argc, char **argv)
+{
+// LogComponentEnable ("YansWifiChannel", LOG_LEVEL_DEBUG);
+// LogComponentEnable ("PropagationLossModel", LOG_LEVEL_DEBUG);
+ RnsDsdvExample example;
+ example = RnsDsdvExample ();
+ example.CaseRun();
+ return 0;
+}
+
+void RnsDsdvExample::CaseRun(void)
+{
+ SeedManager::SetSeed (12);
+ nodes->Create(5);
+ SetupMobility();
+ SetupDevices();
+ SetupIpv4Stack();
+ SetupRns();
+
+ CheckRedundancy();
+
+ Simulator::Stop(Seconds(11));
+ Simulator::Run();
+ Simulator::Destroy();
+}
+
+void RnsDsdvExample::SetupDevices(void)
+{
+ NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default();
+ wifiMac.SetType("ns3::AdhocWifiMac");
+ YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
+ YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();;
+ //Set Propagation Loss model to allow approximately 10m range of nodes.
+ wifiChannel.AddPropagationLoss("ns3::FriisPropagationLossModel",
+ "Lambda",DoubleValue (300000000.0/2.442e9),
+ "SystemLoss",DoubleValue(0.003));
+ wifiPhy.SetChannel(wifiChannel.Create());
+ WifiHelper wifi = WifiHelper::Default ();;
+ wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
+ wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("OfdmRate6Mbps"), "RtsCtsThreshold",
+ StringValue ("2200"));
+ devices = wifi.Install (wifiPhy, wifiMac, *nodes);
+}
+
+void RnsDsdvExample::SetupIpv4Stack(void)
+{
+ DsdvHelper dsdv;
+ dsdv.Set ("PeriodicUpdateInterval", TimeValue (Seconds (3)));
+ dsdv.Set ("SettlingTime", TimeValue (Seconds (2)));
+ dsdv.Set ("EnableRns", BooleanValue(true));
+ InternetStackHelper stack;
+ stack.SetRoutingHelper (dsdv);
+ stack.Install (*nodes);
+ Ipv4AddressHelper address;
+ address.SetBase ("10.1.1.0", "255.255.255.0");
+ interfaces = address.Assign (devices);
+}
+
+void RnsDsdvExample::SetupMobility(void)
+{
+ MobilityHelper mobility;
+ mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+ mobility.Install (*nodes);
+
+ Ptr<ConstantPositionMobilityModel> m =
+ nodes->Get(0)->GetObject<ConstantPositionMobilityModel>();
+ m->SetPosition(Vector(10.0,10.0,0.0));
+ m = nodes->Get(1)->GetObject<ConstantPositionMobilityModel>();
+ m->SetPosition(Vector(13.0,13.0,0.0));
+ m = nodes->Get(2)->GetObject<ConstantPositionMobilityModel>();
+ m->SetPosition(Vector(7.0,13.0,0.0));
+ m = nodes->Get(3)->GetObject<ConstantPositionMobilityModel>();
+ m->SetPosition(Vector(7.0,7.0,0.0));
+ m = nodes->Get(4)->GetObject<ConstantPositionMobilityModel>();
+ m->SetPosition(Vector(13.0,7.0,0.0));
+}
+
+void RnsDsdvExample::SetupRns (void)
+{
+ RnsHelper<Ipv4Address> helper;
+ helper.Set("UpdateInterval",TimeValue(Seconds(2.0)));
+ helper.Set("ConnectivityMaintenanceMode",BooleanValue(true));
+ helper.Set("UpdateIntervalTimeScatter",DoubleValue(100.0));
+ helper.Set("ProtocolPeriodicUpdate",BooleanValue(false));
+ helper.Set("PositionInRnsHeader",BooleanValue(true));
+ helper.Set("EventTriggerredBroadcast",BooleanValue(false));
+ helper.Install(*nodes);
+ for (NodeContainer::Iterator n = nodes->Begin();n != nodes->End(); n++)
+ {
+ Ptr<dsdv::RoutingProtocol> DsdvRp = (*n)->GetObject<dsdv::RoutingProtocol>();
+ Ptr<rns::Rns<Ipv4Address> > Rns = (*n)->GetObject<rns::Rns<Ipv4Address> >();
+ DsdvRp->SetRns(Rns);
+ Ptr<Ipv4RoutingProtocol> Rp = (*n)->GetObject<Ipv4RoutingProtocol>();
+ Rns->SetIpv4Protocol(DsdvRp);
+ }
+}
+
+void RnsDsdvExample::CheckRedundancy(void)
+{
+ Ptr<OutputStreamWrapper> stream = Create<OutputStreamWrapper> (&std::cout);
+ uint32_t i = 0;
+ *stream->GetStream() << "Time: " << (Simulator::Now()).GetSeconds() << "\n";
+ for (NodeContainer::Iterator node_iter = nodes->Begin();
+ node_iter != nodes->End() ;node_iter++)
+ {
+ Ptr<rns::Rns<Ipv4Address> > rns = (*node_iter)->GetObject<rns::Rns<Ipv4Address> >();
+ *stream->GetStream() << "Node " << (*node_iter)->GetId() << " is ";
+ if (rns->IsRedundant())
+ {
+ *stream->GetStream() << "redundant\n";
+ }
+ else
+ {
+ *stream->GetStream() << "not redundant\n";
+ }
+ i++;
+ }
+ *stream->GetStream() << "----------\n";
+ Simulator::Schedule(Seconds (5),&RnsDsdvExample::CheckRedundancy,this);
+}
+
+
« no previous file with comments | « src/rns/doc/source/rns-user.rst ('k') | src/rns/examples/rns-smecn-example.cc » ('j') | no next file with comments »

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