Update OLSR example.

This commit is contained in:
Gustavo J. A. M. Carneiro
2007-09-21 14:28:05 +01:00
parent 0826d6de53
commit 1f6d0347cc

View File

@@ -38,11 +38,7 @@
// - Tracing of queues and packet receptions to file
// "simple-point-to-point.tr"
#include <iostream>
#include <fstream>
#include <string>
#include <cassert>
#include "ns3/log.h"
#include "ns3/command-line.h"
#include "ns3/default-value.h"
#include "ns3/ptr.h"
@@ -65,24 +61,41 @@
#include "ns3/point-to-point-topology.h"
#include "ns3/onoff-application.h"
#include "ns3/packet-sink.h"
#include "ns3/olsr.h"
using namespace ns3;
int main (int argc, char *argv[])
{
NS_LOG_COMPONENT_DEFINE ("SimplePointToPointExample");
int
main (int argc, char *argv[])
{
// Users may find it convenient to turn on explicit debugging
// for selected modules; the below lines suggest how to do this
// remember to add #include "ns3/debug.h" before enabling these
#if 0
DebugComponentEnable("Object");
DebugComponentEnable("Queue");
DebugComponentEnable("DropTailQueue");
DebugComponentEnable("Channel");
DebugComponentEnable("PointToPointChannel");
DebugComponentEnable("PointToPointNetDevice");
LogComponentEnable ("SimplePointToPointExample", LOG_LEVEL_INFO);
LogComponentEnable("Object", LOG_LEVEL_ALL);
LogComponentEnable("Queue", LOG_LEVEL_ALL);
LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
LogComponentEnable("Channel", LOG_LEVEL_ALL);
LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
LogComponentEnable("Socket", LOG_LEVEL_ALL);
LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
#endif
// Set up some default values for the simulation. Use the Bind()
@@ -104,12 +117,14 @@ int main (int argc, char *argv[])
// Here, we will explicitly create four nodes. In more sophisticated
// topologies, we could configure a node factory.
NS_LOG_INFO ("Create nodes.");
Ptr<Node> n0 = Create<InternetNode> ();
Ptr<Node> n1 = Create<InternetNode> ();
Ptr<Node> n2 = Create<InternetNode> ();
Ptr<Node> n3 = Create<InternetNode> ();
// We create the channels first without any IP addressing information
NS_LOG_INFO ("Create channels.");
Ptr<PointToPointChannel> channel0 =
PointToPointTopology::AddPointToPointLink (
n0, n2, DataRate(5000000), MilliSeconds(2));
@@ -123,6 +138,7 @@ int main (int argc, char *argv[])
n2, n3, DataRate(1500000), MilliSeconds(10));
// Later, we add IP addresses.
NS_LOG_INFO ("Assign IP Addresses.");
PointToPointTopology::AddIpv4Addresses (
channel0, n0, Ipv4Address("10.1.1.1"),
n2, Ipv4Address("10.1.1.2"));
@@ -139,16 +155,16 @@ int main (int argc, char *argv[])
// NetDevice creation, IP Address assignment, and routing) are
// separated because there may be a need to postpone IP Address
// assignment (emulation) or modify to use dynamic routing
PointToPointTopology::AddIpv4Routes(n0, n2, channel0);
PointToPointTopology::AddIpv4Routes(n1, n2, channel1);
PointToPointTopology::AddIpv4Routes(n2, n3, channel2);
NS_LOG_INFO ("Enabling OLSR Routing.");
olsr::EnableAllNodes ();
// Create the OnOff application to send UDP datagrams of size
// 210 bytes at a rate of 448 Kb/s
NS_LOG_INFO ("Create Applications.");
uint16_t port = 9; // Discard port (RFC 863)
Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
n0,
InetSocketAddress ("10.1.3.2", 80),
InetSocketAddress ("10.1.3.2", port),
"Udp",
ConstantVariable(1),
ConstantVariable(0));
@@ -159,7 +175,7 @@ int main (int argc, char *argv[])
// Create an optional packet sink to receive these packets
Ptr<PacketSink> sink = Create<PacketSink> (
n3,
InetSocketAddress (Ipv4Address::GetAny (), 80),
InetSocketAddress (Ipv4Address::GetAny (), port),
"Udp");
// Start the sink
sink->Start (Seconds (1.0));
@@ -168,7 +184,7 @@ int main (int argc, char *argv[])
// Create a similar flow from n3 to n1, starting at time 1.1 seconds
ooff = Create<OnOffApplication> (
n3,
InetSocketAddress ("10.1.2.1", 80),
InetSocketAddress ("10.1.2.1", port),
"Udp",
ConstantVariable(1),
ConstantVariable(0));
@@ -179,7 +195,7 @@ int main (int argc, char *argv[])
// Create a packet sink to receive these packets
sink = Create<PacketSink> (
n1,
InetSocketAddress (Ipv4Address::GetAny (), 80),
InetSocketAddress (Ipv4Address::GetAny (), port),
"Udp");
// Start the sink
sink->Start (Seconds (1.1));
@@ -187,6 +203,7 @@ int main (int argc, char *argv[])
// Here, finish off packet routing configuration
// This will likely set by some global StaticRouting object in the future
NS_LOG_INFO ("Set Default Routes.");
Ptr<Ipv4> ipv4;
ipv4 = n0->QueryInterface<Ipv4> (Ipv4::iid);
ipv4->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1);
@@ -195,9 +212,12 @@ int main (int argc, char *argv[])
// Configure tracing of all enqueue, dequeue, and NetDevice receive events
// Trace output will be sent to the simple-point-to-point.tr file
// AsciiTrace asciitrace ("simple-point-to-point.tr");
// asciitrace.TraceAllQueues ();
// asciitrace.TraceAllNetDeviceRx ();
#if 0 // causes: assert failed. file=../src/common/packet-metadata.cc, line=1043, cond="GetTotalSize () == data.GetSize ()"
NS_LOG_INFO ("Configure Tracing.");
AsciiTrace asciitrace ("simple-point-to-point-olsr.tr");
asciitrace.TraceAllQueues ();
asciitrace.TraceAllNetDeviceRx ();
#endif
// Also configure some tcpdump traces; each interface will be traced
// The output files will be named
@@ -207,9 +227,9 @@ int main (int argc, char *argv[])
PcapTrace pcaptrace ("simple-point-to-point-olsr.pcap");
pcaptrace.TraceAllIp ();
NS_LOG_INFO ("Run Simulation.");
Simulator::StopAt (Seconds (10));
Simulator::Run ();
Simulator::Run ();
Simulator::Destroy ();
NS_LOG_INFO ("Done.");
}