OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /*· |
| 3 * Copyright (c) 2012 Michal Paszta |
| 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: Michal Paszta· |
| 19 */ |
| 20 #include "ns3/rns-module.h" |
| 21 #include "ns3/core-module.h" |
| 22 #include "ns3/network-module.h" |
| 23 #include "ns3/mobility-module.h" |
| 24 #include "ns3/config-store-module.h" |
| 25 #include "ns3/wifi-module.h" |
| 26 #include "ns3/internet-module.h" |
| 27 #include "ns3/smecn-module.h" |
| 28 #include "ns3/log.h" |
| 29 |
| 30 using namespace ns3; |
| 31 |
| 32 class RnsSmecnExample |
| 33 { |
| 34 public: |
| 35 |
| 36 RnsSmecnExample() {}; |
| 37 void CaseRun(void); |
| 38 |
| 39 |
| 40 private: |
| 41 |
| 42 NodeContainer * nodes; |
| 43 NetDeviceContainer devices; |
| 44 Ipv4InterfaceContainer interfaces; |
| 45 |
| 46 void SetupDevices(void); |
| 47 void SetupIpv4Stack(void); |
| 48 void SetupMobility(void); |
| 49 void SetupRns(void); |
| 50 |
| 51 void CheckRedundancy(void); |
| 52 }; |
| 53 |
| 54 int main (int argc, char **argv) |
| 55 { |
| 56 // LogComponentEnable ("YansWifiChannel", LOG_LEVEL_DEBUG); |
| 57 // LogComponentEnable ("PropagationLossModel", LOG_LEVEL_DEBUG); |
| 58 RnsSmecnExample example; |
| 59 example = RnsSmecnExample (); |
| 60 example.CaseRun(); |
| 61 return 0; |
| 62 } |
| 63 |
| 64 void RnsSmecnExample::CaseRun(void) |
| 65 { |
| 66 SeedManager::SetSeed (12); |
| 67 nodes->Create(5); |
| 68 SetupMobility(); |
| 69 SetupDevices(); |
| 70 SetupIpv4Stack(); |
| 71 SetupRns(); |
| 72 |
| 73 CheckRedundancy(); |
| 74 |
| 75 Simulator::Stop(Seconds(11)); |
| 76 Simulator::Run(); |
| 77 Simulator::Destroy(); |
| 78 } |
| 79 |
| 80 void RnsSmecnExample::SetupDevices(void) |
| 81 { |
| 82 NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default(); |
| 83 wifiMac.SetType("ns3::AdhocWifiMac"); |
| 84 YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default(); |
| 85 YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();; |
| 86 //Set Propagation Loss model to allow approximately 10m range of nodes. |
| 87 wifiChannel.AddPropagationLoss("ns3::FriisPropagationLossModel", |
| 88 "Lambda",DoubleValue (300000000.0/2.442e9), |
| 89 "SystemLoss",DoubleValue(0.003)); |
| 90 wifiPhy.SetChannel(wifiChannel.Create()); |
| 91 WifiHelper wifi = WifiHelper::Default ();; |
| 92 wifi.SetStandard (WIFI_PHY_STANDARD_80211b); |
| 93 wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", Stri
ngValue ("OfdmRate6Mbps"), "RtsCtsThreshold", |
| 94 StringValue ("2200")); |
| 95 devices = wifi.Install (wifiPhy, wifiMac, *nodes); |
| 96 } |
| 97 |
| 98 void RnsSmecnExample::SetupIpv4Stack(void) |
| 99 { |
| 100 SmecnHelper smecn; |
| 101 smecn.Set ("EnableRns", BooleanValue(true)); |
| 102 InternetStackHelper stack; |
| 103 stack.SetRoutingHelper (smecn); |
| 104 stack.Install (*nodes); |
| 105 Ipv4AddressHelper address; |
| 106 address.SetBase ("10.1.1.0", "255.255.255.0"); |
| 107 interfaces = address.Assign (devices); |
| 108 } |
| 109 |
| 110 void RnsSmecnExample::SetupMobility(void) |
| 111 { |
| 112 MobilityHelper mobility; |
| 113 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
| 114 mobility.Install (*nodes); |
| 115 |
| 116 Ptr<ConstantPositionMobilityModel> m = |
| 117 nodes->Get(0)->GetObject<ConstantPositionMobilityModel>(); |
| 118 m->SetPosition(Vector(10.0,10.0,0.0)); |
| 119 m = nodes->Get(1)->GetObject<ConstantPositionMobilityModel>(); |
| 120 m->SetPosition(Vector(13.0,13.0,0.0)); |
| 121 m = nodes->Get(2)->GetObject<ConstantPositionMobilityModel>(); |
| 122 m->SetPosition(Vector(7.0,13.0,0.0)); |
| 123 m = nodes->Get(3)->GetObject<ConstantPositionMobilityModel>(); |
| 124 m->SetPosition(Vector(7.0,7.0,0.0)); |
| 125 m = nodes->Get(4)->GetObject<ConstantPositionMobilityModel>(); |
| 126 m->SetPosition(Vector(13.0,7.0,0.0)); |
| 127 } |
| 128 |
| 129 void RnsSmecnExample::SetupRns (void) |
| 130 { |
| 131 RnsHelper<Ipv4Address> helper; |
| 132 helper.Set("UpdateInterval",TimeValue(Seconds(2.0))); |
| 133 helper.Set("ConnectivityMaintenanceMode",BooleanValue(true)); |
| 134 helper.Set("UpdateIntervalTimeScatter",DoubleValue(10.0)); |
| 135 helper.Install(*nodes); |
| 136 for (NodeContainer::Iterator n = nodes->Begin();n != nodes->End(); n++) |
| 137 { |
| 138 Ptr<smecn::RoutingProtocol> SmecnRp = (*n)->GetObject<smecn::RoutingProtoc
ol>(); |
| 139 if (SmecnRp != NULL) std::cout << "Smecn found\n"; |
| 140 Ptr<rns::Rns<Ipv4Address> > Rns = (*n)->GetObject<rns::Rns<Ipv4Address> >(
); |
| 141 if (Rns != NULL) std::cout << "Rns found\n"; |
| 142 //SmecnRp->SetRns(Rns); |
| 143 Ptr<Ipv4RoutingProtocol> Rp = (*n)->GetObject<Ipv4RoutingProtocol>(); |
| 144 Rns->SetIpv4Protocol(SmecnRp); |
| 145 } |
| 146 } |
| 147 |
| 148 void RnsSmecnExample::CheckRedundancy(void) |
| 149 { |
| 150 Ptr<OutputStreamWrapper> stream = Create<OutputStreamWrapper> (&std::cout); |
| 151 uint32_t i = 0; |
| 152 *stream->GetStream() << "Time: " << (Simulator::Now()).GetSeconds() << "\n"; |
| 153 for (NodeContainer::Iterator node_iter = nodes->Begin(); |
| 154 node_iter != nodes->End() ;node_iter++) |
| 155 { |
| 156 Ptr<rns::Rns<Ipv4Address> > rns = (*node_iter)->GetObject<rns::Rns<Ipv4Add
ress> >(); |
| 157 *stream->GetStream() << "Node " << i << " is "; |
| 158 if (rns->IsRedundant()) |
| 159 { |
| 160 *stream->GetStream() << "redundant\n"; |
| 161 } |
| 162 else |
| 163 { |
| 164 *stream->GetStream() << "not redundant\n"; |
| 165 } |
| 166 i++; |
| 167 } |
| 168 *stream->GetStream() << "----------\n"; |
| 169 Simulator::Schedule(Seconds (5),&RnsSmecnExample::CheckRedundancy,this); |
| 170 } |
| 171 |
| 172 |
OLD | NEW |