Hi again,
I've got a simple point-to-point network, and I'm trying to get the
network to route packets across multiple hops from one end of the
network to the other. To do this, I'm using the UDP echo client/server
included with ns-3. Now, I have no expectations that packets will be
correctly routed back to the sender at this point, but I'm not even
seeing my packets getting routed to the right destination node. They
go one hop and then bounce back to the origin.
I'm actually trying to do this with a more complicated TCP app, but I
can't even get it working with a simple echo server. All I want to do
is see my network route packets across the network to their intended
destination. At this point, I don't even care about seeing them echo
back to the client. One complete trip would make me happy. I have been
using NetAnim to visualise what's happening on my network and see what
my packets have been doing. I'd truly appreciate any and all help that
you, the esteemed ns-3 forum, can provide.
At the risk of breaching protocol and making people's lives miserable,
I'm going to copy and paste the source that I'm dealing with, or a
reasonable facsimile:
#include "ns3/core-module.h"
#include "ns3/simulator-module.h"
#include "ns3/node-module.h"
#include "ns3/helper-module.h"
#include "ns3/overlay-module.h"
#include <iostream>
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("SimplePhysicalNetwork");
void setNodeLocation(Ptr<Node> node, double x, double y)
{
Ptr<CanvasLocation> loc = node->GetObject<CanvasLocation>();
if (0 == loc)
{
loc = CreateObject<CanvasLocation>();
node->AggregateObject(loc);
}
Vector locVec(x, y, 0);
loc->SetLocation(locVec);
}
void boundingBox(NodeContainer nodes)
{
setNodeLocation(nodes.Get(0), 3.5, 2.5);
setNodeLocation(nodes.Get(1), 7, 2.5);
setNodeLocation(nodes.Get(2), 2.5, 1);
setNodeLocation(nodes.Get(3), 8, 1);
setNodeLocation(nodes.Get(4), 2.5, 4);
setNodeLocation(nodes.Get(5), 8, 4);
setNodeLocation(nodes.Get(6), 1, 1);
setNodeLocation(nodes.Get(7), 9.5, 1);
setNodeLocation(nodes.Get(8), 1, 4);
setNodeLocation(nodes.Get(9), 9.5, 4);
}
int main(int argc, char *argv[])
{
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
int NUM_NODES = 10;
NodeContainer nodes;
nodes.Create(NUM_NODES);
// We're probably going to want different bandwidth values on
different links
PointToPointHelper p2p;
p2p.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
p2p.SetChannelAttribute("Delay", StringValue("2ms"));
// Again, we may want to have different connection types.
// Different bandwidths, latencies, connection quality, that sort of
thing.
NetDeviceContainer devices;
devices.Add(p2p.Install(nodes.Get(0), nodes.Get(1)));
devices.Add(p2p.Install(nodes.Get(0), nodes.Get(2)));
devices.Add(p2p.Install(nodes.Get(1), nodes.Get(3)));
devices.Add(p2p.Install(nodes.Get(0), nodes.Get(4)));
devices.Add(p2p.Install(nodes.Get(1), nodes.Get(5)));
devices.Add(p2p.Install(nodes.Get(2), nodes.Get(6)));
devices.Add(p2p.Install(nodes.Get(3), nodes.Get(7)));
devices.Add(p2p.Install(nodes.Get(4), nodes.Get(8)));
devices.Add(p2p.Install(nodes.Get(5), nodes.Get(9)));
InternetStackHelper stack;
stack.Install(nodes);
Ipv4AddressHelper address;
address.SetBase("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer interfaces = address.Assign(devices);
UdpEchoServerHelper echoServer(9);
// Create an application container for the echo servers
ApplicationContainer serverApps;
serverApps.Add(echoServer.Install(nodes.Get(9)));
serverApps.Start(Seconds(1.0));
serverApps.Stop(Seconds(10.0));
UdpEchoClientHelper echoClient(interfaces.GetAddress(17), 9);
echoClient.SetAttribute("MaxPackets", UintegerValue(15));
echoClient.SetAttribute("Interval", TimeValue(Seconds(1.0)));
echoClient.SetAttribute("PacketSize", UintegerValue(1024));
// Create an application container for the echo clients
ApplicationContainer clientApps;
clientApps.Add(echoClient.Install(nodes.Get(6)));
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(10.0));
AnimationInterface anim;
anim.SetOutputFile("
simple.tr");
boundingBox(nodes);
anim.StartAnimation();
Ipv4GlobalRoutingHelper::PopulateRoutingTables();
Simulator::Run();
Simulator::Destroy();
anim.StopAnimation();
return 0;
}