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

Unified Diff: src/smecn/examples/smecn-static.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/smecn/examples/smecn-mobile.cc ('k') | src/smecn/examples/wscript » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/smecn/examples/smecn-static.cc
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/smecn/examples/smecn-static.cc
@@ -0,0 +1,266 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) YEAR COPYRIGHTHOLDER
+ *
+ * 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/smecn-module.h"
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/internet-module.h"
+#include "ns3/mobility-module.h"
+#include "ns3/point-to-point-module.h"
+#include "ns3/wifi-module.h"
+#include "ns3/v4ping-helper.h"
+#include "ns3/netanim-module.h"
+#include <iostream>
+#include <cmath>
+
+using namespace ns3;
+
+class SmecnStaticExample
+{
+public:
+ SmecnStaticExample();
+ /// Configure script parameters, \return true on successful configuration
+ bool Configure (int argc, char **argv);
+ /// Run simulation
+ void Run (void);
+ /// Report results
+ void Report (std::ostream & os);
+
+private:
+ void CreateDevices (void);
+ void CreateNodes (void);
+ void PrintRoutingTables(void);
+ void SetupSituation1(void);
+
+ void TurnLogsOn (void);
+ void TurnLogsOff(void);
+ NodeContainer * m_nodes;
+ Time m_time;
+ ///\name parameters
+ //\{
+ uint32_t m_nodesNumber;
+ double simulationTime;
+ bool printRoutingTables;
+ //\}
+};
+
+SmecnStaticExample::SmecnStaticExample ()
+: m_nodesNumber(13),
+ simulationTime(4),
+ printRoutingTables(true)
+{}
+
+int main (int argc, char **argv)
+{
+ SmecnStaticExample mecnExample;
+ if (!mecnExample.Configure(argc, argv))
+ {
+ NS_FATAL_ERROR("Configuration failed. Aborted.");
+ }
+
+ mecnExample.Run();
+ mecnExample.Report(std::cout);
+ return 0;
+}
+
+bool SmecnStaticExample::Configure(int argc, char** argv)
+{
+ SeedManager::SetSeed (12345);
+
+ CommandLine cmd;
+ cmd.AddValue ("nodes", "Number of nodes.", m_nodesNumber);
+ cmd.AddValue ("time", "Simulation time [s].", simulationTime);
+ cmd.AddValue ("printRT", "print Routing Tables.", printRoutingTables);
+ cmd.Parse(argc,argv);
+
+ return true;
+}
+
+void SmecnStaticExample::Run(void)
+{
+ m_time = Seconds(simulationTime);
+
+ CreateNodes();
+ CreateDevices();
+
+ Simulator::Schedule(Seconds(0.001),&SmecnStaticExample::SetupSituation1,this);
+
+
+ if (printRoutingTables)
+ {
+ Simulator::Schedule(Seconds(1.8),&SmecnStaticExample::PrintRoutingTables,this);
+ }
+
+ Simulator::Stop(m_time);
+
+ Simulator::Run();
+ Simulator::Destroy();
+}
+
+void SmecnStaticExample::Report (std::ostream & os)
+{}
+
+void SmecnStaticExample::SetupSituation1(void)
+{
+ //Browse through all nodes and set their initial positions
+ Ptr<ConstantPositionMobilityModel> m;
+
+ Ptr<Node> n = m_nodes->Get(0);
+ Vector v = Vector(10,10,0);//0,0
+ m = n->GetObject<ConstantPositionMobilityModel>();
+ m->SetPosition(v);
+
+ n = m_nodes->Get(1);
+ v = Vector(13,10,0);//3,0
+ m = n->GetObject<ConstantPositionMobilityModel>();
+ m->SetPosition(v);
+
+ n = m_nodes->Get(2);
+ v = Vector(11,12,0);//1,2
+ m = n->GetObject<ConstantPositionMobilityModel>();
+ m->SetPosition(v);
+
+ n = m_nodes->Get(3);
+ v = Vector(9,12,0);//-1,2
+ m = n->GetObject<ConstantPositionMobilityModel>();
+ m->SetPosition(v);
+
+ n = m_nodes->Get(4);
+ v = Vector(7,10,0);//-3,0
+ m = n->GetObject<ConstantPositionMobilityModel>();
+ m->SetPosition(v);
+
+ n = m_nodes->Get(5);
+ v = Vector(9,8,0);//-1,-2
+ m = n->GetObject<ConstantPositionMobilityModel>();
+ m->SetPosition(v);
+
+ n = m_nodes->Get(6);
+ v = Vector(11,8,0);//1,-2
+ m = n->GetObject<ConstantPositionMobilityModel>();
+ m->SetPosition(v);
+
+ n = m_nodes->Get(7);
+ v = Vector(6,7,0);//-4,-3
+ m = n->GetObject<ConstantPositionMobilityModel>();
+ m->SetPosition(v);
+
+ n = m_nodes->Get(8);
+ v = Vector(10,6,0);//0,-4
+ m = n->GetObject<ConstantPositionMobilityModel>();
+ m->SetPosition(v);
+
+ n = m_nodes->Get(9);
+ v = Vector(14,8,0);//4,-2
+ m = n->GetObject<ConstantPositionMobilityModel>();
+ m->SetPosition(v);
+
+ n = m_nodes->Get(10);
+ v = Vector(15,10,0);//5,0
+ m = n->GetObject<ConstantPositionMobilityModel>();
+ m->SetPosition(v);
+
+ n = m_nodes->Get(11);
+ v = Vector(14,13,0);//4,3
+ m = n->GetObject<ConstantPositionMobilityModel>();
+ m->SetPosition(v);
+
+ n = m_nodes->Get(12);
+ v = Vector(17,7,0);//7,-3
+ m = n->GetObject<ConstantPositionMobilityModel>();
+ m->SetPosition(v);
+}
+
+void SmecnStaticExample::CreateNodes(void)
+{
+ m_nodes = new NodeContainer;
+ m_nodes->Create (m_nodesNumber);
+
+ MobilityHelper mobility;
+ mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
+ mobility.Install(*m_nodes);
+
+ m_nodes->Get(0)->GetObject<ConstantPositionMobilityModel>();
+}
+
+void SmecnStaticExample::CreateDevices()
+{
+ // Setup wifi
+ NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
+ wifiMac.SetType ("ns3::AdhocWifiMac");
+ YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
+ YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
+ //Set Propagation Loss model to allow approximately 5m range of nodes.
+ wifiChannel.AddPropagationLoss("ns3::FriisPropagationLossModel",
+ "Lambda",DoubleValue (300000000.0/2.442e9),
+ "SystemLoss",DoubleValue(0.007));
+ wifiPhy.SetChannel (wifiChannel.Create ());
+ // This test suite output was originally based on YansErrorRateModel
+ wifiPhy.SetErrorRateModel ("ns3::YansErrorRateModel");
+
+ //configure power mangement
+ wifiPhy.Set("TxPowerLevels",UintegerValue(2));
+ wifiPhy.Set("TxPowerStart",DoubleValue(8.0206));
+ wifiPhy.Set("TxPowerEnd",DoubleValue(20.0206));
+
+ WifiHelper wifi = WifiHelper::Default ();
+ wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("OfdmRate6Mbps"), "RtsCtsThreshold", StringValue ("2200"));
+ NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, *m_nodes);
+
+
+ // Setup TCP/IP & MECN
+ InternetStackHelper internetStack;
+ SmecnHelper smecnHelper;
+ smecnHelper.Set("UpdateFromBroadcastPeriod",TimeValue(MilliSeconds(500)));
+ smecnHelper.Set("ReconfigurationInterval",TimeValue(Seconds(1)));
+ internetStack.SetRoutingHelper(smecnHelper);
+ internetStack.Install(*m_nodes);
+ Ipv4AddressHelper address;
+ address.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer interfaces = address.Assign (devices);
+}
+
+void SmecnStaticExample::PrintRoutingTables(void)
+{
+ Ptr<OutputStreamWrapper> stream = Create<OutputStreamWrapper> (&std::cout);
+
+ Ptr<Node> node = m_nodes->Get(0);
+ Ptr<Ipv4RoutingProtocol> rp = node->GetObject<Ipv4RoutingProtocol>();
+ rp->PrintRoutingTable(stream);
+
+ Simulator::Schedule(Seconds(1),&SmecnStaticExample::PrintRoutingTables,this);
+
+ std::cout << "--------------------------------------------\n";
+}
+
+void SmecnStaticExample::TurnLogsOn(void)
+{
+ LogComponentEnable("SmecnRoutingProtocol",LOG_DEBUG);
+ LogComponentEnable("SmecnRoutingProtocol",LOG_ERROR);
+ LogComponentEnable("SmecnRoutingProtocol",LOG_LOGIC);
+ LogComponentEnable("V4Ping",LOG_ALL);
+ LogComponentEnable("Ipv4RawSocketImpl",LOG_ALL);
+ LogComponentEnable("SmecnRoutingProtocol",LOG_ALL);
+ LogComponentEnable("SmecnRoutingTable",LOG_ALL);
+}
+
+void SmecnStaticExample::TurnLogsOff(void)
+{
+ LogComponentDisableAll(LOG_ALL);
+}
« no previous file with comments | « src/smecn/examples/smecn-mobile.cc ('k') | src/smecn/examples/wscript » ('j') | no next file with comments »

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