Alexander Afanasyev | 18750bb | 2012-02-02 23:11:30 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2005-2009 Old Dominion University [ARBABI] |
| 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: Hadi Arbabi <marbabi@cs.odu.edu> |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | This the starting point of the simulation and experiments. |
| 23 | The main function will parse the input and parameter settings. |
| 24 | Creates a highway and set the highway parameters. then bind the events (callbacks) |
| 25 | to the created controller and designed handlers. Sets the highway start and end time, |
| 26 | and eventually runs the simulation which is basically running a highway with a controller. |
| 27 | You can add your functions to controller to create various scenarios. |
| 28 | */ |
| 29 | |
| 30 | #include <fstream> |
| 31 | #include <iostream> |
| 32 | #include <iomanip> |
| 33 | #include "ns3/core-module.h" |
| 34 | #include "ns3/network-module.h" |
| 35 | #include "ns3/mobility-module.h" |
| 36 | #include "ns3/wifi-module.h" |
| 37 | |
| 38 | #include "math.h" |
| 39 | |
| 40 | #include "ns3/model.h" |
| 41 | #include "ns3/highway.h" |
| 42 | #include "ns3/vehicle-generator.h" |
| 43 | #include "ns3/tinyxml.h" |
| 44 | #include "ns3/highway-project-xml.h" |
| 45 | #include "ns3/highway-xml.h" |
| 46 | #include "ns3/wifi-configuration-xml.h" |
| 47 | #include "ns3/highway-project.h" |
| 48 | |
| 49 | #include "ns3/ccnx-stack-helper.h" |
| 50 | #include "ns3/ccnx-face-container.h" |
| 51 | #include "ns3/ccnx-app-helper.h" |
| 52 | |
| 53 | NS_LOG_COMPONENT_DEFINE ("VanetCcnx"); |
| 54 | |
| 55 | using namespace ns3; |
| 56 | using namespace std; |
| 57 | |
| 58 | void |
| 59 | EquipVehicle (Ptr<Vehicle> vehicle, Ptr<Highway> highway, double probability) |
| 60 | { |
| 61 | NS_LOG_FUNCTION (vehicle->GetNode ()->GetId () << highway << probability); |
| 62 | |
| 63 | CcnxStackHelper ccnxHelper; |
| 64 | ccnxHelper.SetDefaultRoutes (true); |
| 65 | Ptr<CcnxFaceContainer> faces = ccnxHelper.Install (vehicle->GetNode ()); |
| 66 | NS_LOG_DEBUG ("Install CCNx stack. " << faces->GetN () << " faces available"); |
| 67 | |
| 68 | |
| 69 | if (probability < 30) |
| 70 | { |
| 71 | CcnxAppHelper producerHelper ("ns3::CcnxProducer"); |
| 72 | producerHelper.SetPrefix ("/"); |
| 73 | producerHelper.Install (vehicle->GetNode ()); |
| 74 | } |
| 75 | else |
| 76 | { |
| 77 | CcnxAppHelper consumerHelper ("ns3::CcnxConsumerCbr"); |
| 78 | consumerHelper.SetAttribute ("LifeTime", StringValue("100s")); |
| 79 | consumerHelper.SetAttribute ("Frequency", StringValue("10")); |
| 80 | consumerHelper.SetPrefix ("/"); |
| 81 | consumerHelper.Install (vehicle->GetNode ()); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | int |
| 86 | main (int argc, char *argv[]) |
| 87 | { |
| 88 | string projectXmlFile = ""; |
| 89 | |
| 90 | CommandLine cmd; |
| 91 | cmd.AddValue ("project", "highway xml description", projectXmlFile); |
| 92 | cmd.Parse (argc, argv); |
| 93 | if (projectXmlFile == "") |
| 94 | { |
| 95 | std::cerr << "ERROR: --project option MUST be specified\n"; |
| 96 | return 1; |
| 97 | } |
| 98 | |
| 99 | std::ifstream testProjectFile (projectXmlFile.c_str ()); |
| 100 | if (testProjectFile.bad ()) |
| 101 | { |
| 102 | std::cerr << "ERROR: Cannot open project file\n"; |
| 103 | return 2; |
| 104 | } |
| 105 | testProjectFile.close (); |
| 106 | |
| 107 | TiXmlDocument doc (projectXmlFile.c_str ()); |
| 108 | doc.LoadFile (); |
| 109 | TiXmlHandle hDoc (&doc); |
| 110 | TiXmlElement* root = hDoc.FirstChildElement ().Element (); |
| 111 | TiXmlHandle hroot = TiXmlHandle (root); |
| 112 | HighwayProjectXml xml; |
| 113 | xml.LoadFromXml (hroot); |
| 114 | |
| 115 | ns3::PacketMetadata::Enable (); |
| 116 | Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200")); |
| 117 | Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200")); |
| 118 | |
| 119 | HighwayProject project (xml); |
| 120 | // project.SetVehTraceFile (vehicleTraceFile); |
| 121 | // project.SetNetTraceFile (networkTraceFile); |
| 122 | |
| 123 | for (std::list<ns3::Ptr<ns3::VehicleGenerator> >::iterator generator = project.GetVehicleGenerators ().begin (); |
| 124 | generator != project.GetVehicleGenerators ().end (); |
| 125 | generator++) |
| 126 | { |
| 127 | (*generator)->TraceConnectWithoutContext ("NewVehicle", MakeCallback (EquipVehicle)); |
| 128 | } |
| 129 | |
| 130 | project.Start (); |
| 131 | |
| 132 | Simulator::Run (); |
| 133 | Simulator::Destroy (); |
| 134 | |
| 135 | // Ptr<Highway> highway = project.getHighways ()[0]; |
| 136 | // Simulator::Schedule (Seconds (10), &addCustomVehicle, highway); |
| 137 | // project.SetVehicleControlCallback (MakeCallback (&controlVehicle)); |
| 138 | |
| 139 | return 0; |
| 140 | } |