|
|
| 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 |
/* |
| 3 |
* This program is free software; you can redistribute it and/or modify |
| 4 |
* it under the terms of the GNU General Public License version 2 as |
| 5 |
* published by the Free Software Foundation; |
| 6 |
* |
| 7 |
* This program is distributed in the hope that it will be useful, |
| 8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 |
* GNU General Public License for more details. |
| 11 |
* |
| 12 |
* You should have received a copy of the GNU General Public License |
| 13 |
* along with this program; if not, write to the Free Software |
| 14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 15 |
* |
| 16 |
*/ |
| 17 |
|
| 18 |
// |
| 19 |
// Network topology |
| 20 |
// |
| 21 |
// 5Mb/s, 2ms |
| 22 |
// n0 -------------------------n1 |
| 23 |
// |
| 24 |
// |
| 25 |
// |
| 26 |
// |
| 27 |
// - all links are point-to-point links with indicated one-way BW/delay |
| 28 |
// - HTTP requests from n1 to n0 via TCP |
| 29 |
// - DropTail queues |
| 30 |
// - Tracing of queues and packet receptions to file "http-traffic.tr" |
| 31 |
|
| 32 |
#include <iostream> |
| 33 |
#include <fstream> |
| 34 |
#include <string> |
| 35 |
#include <cassert> |
| 36 |
|
| 37 |
#include "ns3/core-module.h" |
| 38 |
#include "ns3/simulator-module.h" |
| 39 |
#include "ns3/node-module.h" |
| 40 |
#include "ns3/helper-module.h" |
| 41 |
#include "ns3/http-module.h" |
| 42 |
|
| 43 |
#include "ns3/global-route-manager.h" |
| 44 |
|
| 45 |
using namespace ns3; |
| 46 |
|
| 47 |
NS_LOG_COMPONENT_DEFINE ("SimpleGlobalRoutingExample"); |
| 48 |
|
| 49 |
int |
| 50 |
main (int argc, char *argv[]) |
| 51 |
{ |
| 52 |
// Users may find it convenient to turn on explicit debugging |
| 53 |
// for selected modules; the below lines suggest how to do this |
| 54 |
#if 0 |
| 55 |
LogComponentEnable ("SimpleGlobalRoutingExample", LOG_LEVEL_INFO); |
| 56 |
#endif |
| 57 |
|
| 58 |
// |
| 59 |
// Make the random number generators generate reproducible results. |
| 60 |
// |
| 61 |
RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8); |
| 62 |
|
| 63 |
// Set up some default values for the simulation. Use the |
| 64 |
|
| 65 |
//DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30); |
| 66 |
|
| 67 |
// Allow the user to override any of the defaults and the above |
| 68 |
// DefaultValue::Bind ()s at run-time, via command-line arguments |
| 69 |
CommandLine cmd; |
| 70 |
cmd.Parse (argc, argv); |
| 71 |
|
| 72 |
// Here, we will explicitly create two nodes. In more sophisticated |
| 73 |
// topologies, we could configure a node factory. |
| 74 |
NS_LOG_INFO ("Create nodes."); |
| 75 |
NodeContainer c; |
| 76 |
c.Create (2); |
| 77 |
|
| 78 |
InternetStackHelper internet; |
| 79 |
internet.Install (c); |
| 80 |
|
| 81 |
// We create the channels first without any IP addressing information |
| 82 |
NS_LOG_INFO ("Create channels."); |
| 83 |
PointToPointHelper p2p; |
| 84 |
p2p.SetDeviceParameter ("DataRate", StringValue ("5Mbps")); |
| 85 |
p2p.SetChannelParameter ("Delay", StringValue ("2ms")); |
| 86 |
NetDeviceContainer devices = p2p.Install (c); |
| 87 |
|
| 88 |
// Later, we add IP addresses. |
| 89 |
NS_LOG_INFO ("Assign IP Addresses."); |
| 90 |
Ipv4AddressHelper ipv4; |
| 91 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
| 92 |
Ipv4InterfaceContainer ipInterfaces = ipv4.Assign (devices); |
| 93 |
|
| 94 |
//Use "god" BFS static routing |
| 95 |
GlobalRouteManager::PopulateRoutingTables (); |
| 96 |
|
| 97 |
// ...instead of OLSR |
| 98 |
//NS_LOG_INFO ("Enabling OLSR Routing."); |
| 99 |
//OlsrHelper olsr; |
| 100 |
//olsr.InstallAll (); |
| 101 |
|
| 102 |
// Create the HTTP applications |
| 103 |
|
| 104 |
NS_LOG_INFO ("Create Applications."); |
| 105 |
|
| 106 |
//have to use low level/internal APIs here since I didn't make a helper |
| 107 |
|
| 108 |
//add the server to node0 |
| 109 |
ObjectFactory webServerFactory; |
| 110 |
webServerFactory.SetTypeId ("ns3::WebServer"); |
| 111 |
//these can be used to configure the parameters of the connection |
| 112 |
//webServerFactory.Set ("Protocol", TypeIdValue (TcpSocketFactory::GetTypeId ())); |
| 113 |
//webServerFactory.Set ("Local", AddressValue (InetSocketAddress (Ipv4Address::GetAny (), 80))); |
| 114 |
Ptr<Application> serverApplication = webServerFactory.Create<Application> (); |
| 115 |
c.Get(0)->AddApplication(serverApplication); |
| 116 |
serverApplication->Start(Seconds (0.0)); |
| 117 |
|
| 118 |
//add the client to node1 |
| 119 |
ObjectFactory webClientFactory; |
| 120 |
webClientFactory.SetTypeId("ns3::WebClient"); |
| 121 |
webClientFactory.Set("Remote", AddressValue (InetSocketAddress(ipInterfaces.GetAddress(0), 80))); |
| 122 |
Ptr<Application> clientApplication = webClientFactory.Create<Application> (); |
| 123 |
c.Get(1)->AddApplication(clientApplication); |
| 124 |
clientApplication->Start(Seconds(0.0)); |
| 125 |
|
| 126 |
std::ofstream ascii; |
| 127 |
ascii.open ("simple-http.tr"); |
| 128 |
PointToPointHelper::EnablePcapAll ("simple-http"); |
| 129 |
PointToPointHelper::EnableAsciiAll (ascii); |
| 130 |
|
| 131 |
Simulator::Stop (Seconds (30)); |
| 132 |
|
| 133 |
NS_LOG_INFO ("Run Simulation."); |
| 134 |
Simulator::Run (); |
| 135 |
Simulator::Destroy (); |
| 136 |
NS_LOG_INFO ("Done."); |
| 137 |
|
| 138 |
return 0; |
| 139 |
} |