Lucas | 64b8536 | 2012-01-30 16:28:37 -0800 | [diff] [blame^] | 1 | #include "ns3/core-module.h" |
| 2 | #include "ns3/network-module.h" |
| 3 | #include "ns3/applications-module.h" |
| 4 | #include "ns3/wifi-module.h" |
| 5 | #include "ns3/mobility-module.h" |
| 6 | #include "ns3/internet-module.h" |
| 7 | #include "ns3/NDNabstraction-module.h" |
| 8 | |
| 9 | using namespace ns3; |
| 10 | |
| 11 | NS_LOG_COMPONENT_DEFINE ("ThirdScriptExample"); |
| 12 | |
| 13 | int |
| 14 | main (int argc, char *argv[]) |
| 15 | { |
| 16 | CommandLine cmd; |
| 17 | cmd.Parse (argc,argv); |
| 18 | NodeContainer producerNode; |
| 19 | producerNode.Create (1); |
| 20 | NodeContainer consumerNode; |
| 21 | consumerNode.Create(1); |
| 22 | YansWifiChannelHelper channel = YansWifiChannelHelper::Default (); |
| 23 | YansWifiPhyHelper phy = YansWifiPhyHelper::Default (); |
| 24 | phy.SetChannel (channel.Create ()); |
| 25 | WifiHelper wifi = WifiHelper::Default (); |
| 26 | wifi.SetRemoteStationManager ("ns3::AarfWifiManager"); |
| 27 | NqosWifiMacHelper mac = NqosWifiMacHelper::Default (); |
| 28 | /*Ssid ssid = Ssid ("ns-3-ssid"); |
| 29 | mac.SetType ("ns3::StaWifiMac", |
| 30 | "Ssid", SsidValue (ssid), |
| 31 | "ActiveProbing", BooleanValue (false));*/ |
| 32 | mac.SetType("ns3::AdhocWifiMac"); |
| 33 | NetDeviceContainer producerDevices; |
| 34 | producerDevices = wifi.Install (phy, mac, producerNode); |
| 35 | /*mac.SetType ("ns3::ApWifiMac", |
| 36 | "Ssid", SsidValue (ssid)); |
| 37 | */ |
| 38 | NetDeviceContainer consumerDevices; |
| 39 | consumerDevices = wifi.Install (phy, mac, consumerNode); |
| 40 | |
| 41 | MobilityHelper mobility; |
| 42 | mobility.SetPositionAllocator ("ns3::GridPositionAllocator", |
| 43 | "MinX", DoubleValue (0.0), |
| 44 | "MinY", DoubleValue (0.0), |
| 45 | "DeltaX", DoubleValue (300.0), |
| 46 | "DeltaY", DoubleValue (10.0), |
| 47 | "GridWidth", UintegerValue (3), |
| 48 | "LayoutType", StringValue ("RowFirst")); |
| 49 | mobility.SetMobilityModel("ns3::ConstantVelocityMobilityModel", |
| 50 | "ConstantVelocity", VectorValue(Vector(26.8224, 0, 0))); |
| 51 | mobility.Install (producerNode); |
| 52 | |
| 53 | mobility.SetMobilityModel("ns3::ConstantVelocityMobilityModel", |
| 54 | "ConstantVelocity", VectorValue(Vector(-26.8224, 0, 0))); |
| 55 | mobility.Install (consumerNode); |
| 56 | |
| 57 | |
| 58 | // 1. Set RoutingHelper to support prefix |
| 59 | //InternetStackHelper stack; |
| 60 | //Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops"); |
| 61 | //stack.SetRoutingHelper (ipv4RoutingHelper); |
| 62 | |
| 63 | // 2. Install CCNx stack |
| 64 | NS_LOG_INFO ("Installing CCNx stack"); |
| 65 | CcnxStackHelper ccnxHelper; |
| 66 | std::string strategy = "ns3::CcnxFloodingStrategy"; |
| 67 | ccnxHelper.SetForwardingStrategy (strategy); |
| 68 | ccnxHelper.SetDefaultRoutes(true); |
| 69 | //ccnxHelper.EnableLimits (false, Seconds(0.1)); |
| 70 | ccnxHelper.InstallAll (); |
| 71 | |
| 72 | // 3. Install IP stack |
| 73 | //stack.Install (consumerNode); |
| 74 | //stack.Install (producerNode); |
| 75 | |
| 76 | // 4. Assign Addresses |
| 77 | //Ipv4AddressHelper address; |
| 78 | //address.SetBase ("10.1.3.0", "255.255.255.0"); |
| 79 | //address.Assign (consumerDevices); |
| 80 | //Ipv4InterfaceContainer producerInterface = address.Assign (producerDevices); |
| 81 | |
| 82 | // 5. Populate FIB based on IPv4 global routing controller |
| 83 | //ccnxHelper.InstallFakeGlobalRoutes (); |
| 84 | //ccnxHelper.InstallRouteTo (producerNode.Get(0)); |
| 85 | |
| 86 | // 6. Set up applications |
| 87 | NS_LOG_INFO ("Installing Applications"); |
| 88 | std::ostringstream prefix; |
| 89 | prefix << "/" << producerNode.Get(0)->GetId (); |
| 90 | |
| 91 | CcnxAppHelper consumerHelper ("ns3::CcnxConsumer"); |
| 92 | consumerHelper.SetPrefix (prefix.str ()); |
| 93 | consumerHelper.SetAttribute ("MeanRate", StringValue ("1Mbps")); |
| 94 | ApplicationContainer consumers = consumerHelper.Install (consumerNode); |
| 95 | |
| 96 | // consumers.Start (Seconds (0.0)); |
| 97 | // consumers.Stop (finishTime); |
| 98 | |
| 99 | CcnxAppHelper producerHelper ("ns3::CcnxProducer"); |
| 100 | producerHelper.SetPrefix (prefix.str ()); |
| 101 | producerHelper.SetAttribute ("PayloadSize", StringValue("1024")); |
| 102 | ApplicationContainer producers = producerHelper.Install (producerNode); |
| 103 | |
| 104 | Simulator::Stop (Seconds (10.0)); |
| 105 | Simulator::Run (); |
| 106 | Simulator::Destroy (); |
| 107 | return 0; |
| 108 | } |