Point-to-Point multicast (with code!)

237 views
Skip to first unread message

Steve Marotta

unread,
Jun 23, 2011, 4:35:27 PM6/23/11
to ns-3-users
I'm trying to set up multicast on a point-to-point network. I'm
starting with the code in csma-multicast.cc and I'm adapting it to
meet my needs. I'm using NetAnim to visualize packet traffic, and I'm
not seeing any. So I'm wondering if I've got my network configured
correctly. I'm guessing that I don't, so if any if you have a spare
moment, I'd appreciate it if you could take a look at my code and let
me know what I'm doing wrong.

#include "ns3/core-module.h"
#include "ns3/simulator-module.h"
#include "ns3/node-module.h"
#include "ns3/helper-module.h"
#include <iostream>

using namespace ns3;

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);
setNodeLocation(nodes.Get(10), 8, 2.5);
setNodeLocation(nodes.Get(11), 9.5, 2.5);
}

void buildNetwork(NodeContainer nodes)
{

PointToPointHelper p2p;
p2p.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
p2p.SetChannelAttribute("Delay", StringValue("2ms"));

NodeContainer n0n1 = NodeContainer(nodes.Get(0), nodes.Get(1));
NodeContainer n0n2 = NodeContainer(nodes.Get(0), nodes.Get(2));
NodeContainer n1n3 = NodeContainer(nodes.Get(1), nodes.Get(3));
NodeContainer n0n4 = NodeContainer(nodes.Get(0), nodes.Get(4));
NodeContainer n1n5 = NodeContainer(nodes.Get(1), nodes.Get(5));
NodeContainer n2n6 = NodeContainer(nodes.Get(2), nodes.Get(6));
NodeContainer n3n7 = NodeContainer(nodes.Get(3), nodes.Get(7));
NodeContainer n4n8 = NodeContainer(nodes.Get(4), nodes.Get(8));
NodeContainer n5n9 = NodeContainer(nodes.Get(5), nodes.Get(9));
NodeContainer n1n10 = NodeContainer(nodes.Get(1), nodes.Get(10));
NodeContainer n10n11 = NodeContainer(nodes.Get(10), nodes.Get(11));

NetDeviceContainer d0d1 = p2p.Install(n0n1);
NetDeviceContainer d0d2 = p2p.Install(n0n2);
NetDeviceContainer d1d3 = p2p.Install(n1n3);
NetDeviceContainer d0d4 = p2p.Install(n0n4);
NetDeviceContainer d1d5 = p2p.Install(n1n5);
NetDeviceContainer d2d6 = p2p.Install(n2n6);
NetDeviceContainer d3d7 = p2p.Install(n3n7);
NetDeviceContainer d4d8 = p2p.Install(n4n8);
NetDeviceContainer d5d9 = p2p.Install(n5n9);
NetDeviceContainer d1d10 = p2p.Install(n1n10);
NetDeviceContainer d10d11 = p2p.Install(n10n11);

Ipv4AddressHelper address;

address.SetBase("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer i0i1 = address.Assign(d0d1);
address.SetBase("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer i0i2 = address.Assign(d0d2);
address.SetBase("10.1.3.0", "255.255.255.0");
Ipv4InterfaceContainer i1i3 = address.Assign(d1d3);
address.SetBase("10.1.4.0", "255.255.255.0");
Ipv4InterfaceContainer i0i4 = address.Assign(d0d4);
address.SetBase("10.1.5.0", "255.255.255.0");
Ipv4InterfaceContainer i1i5 = address.Assign(d1d5);
address.SetBase("10.1.6.0", "255.255.255.0");
Ipv4InterfaceContainer i2i6 = address.Assign(d2d6);
address.SetBase("10.1.7.0", "255.255.255.0");
Ipv4InterfaceContainer i3i7 = address.Assign(d3d7);
address.SetBase("10.1.8.0", "255.255.255.0");
Ipv4InterfaceContainer i4i8 = address.Assign(d4d8);
address.SetBase("10.1.9.0", "255.255.255.0");
Ipv4InterfaceContainer i5i9 = address.Assign(d5d9);
address.SetBase("10.1.10.0", "255.255.255.0");
Ipv4InterfaceContainer i1i10 = address.Assign(d1d10);
address.SetBase("10.1.11.0", "255.255.255.0");
Ipv4InterfaceContainer i10i11 = address.Assign(d10d11);

// Configure multicasting
Ipv4Address multicastSource("10.1.6.2");
Ipv4Address multicastGroup("226.10.28.80");

Ipv4StaticRoutingHelper multicast;

// Configure sender node for multicast
Ptr<Node> sender = nodes.Get(6);
Ptr<NetDevice> senderIf = d2d6.Get(1);
multicast.SetDefaultMulticastRoute(sender, senderIf);

// Configure intermediate nodes for multicast
NetDeviceContainer out0;
out0.Add(d0d1.Get(0));
multicast.AddMulticastRoute(nodes.Get(0), multicastSource,
multicastGroup, d0d2.Get(0), out0);

NetDeviceContainer out1;
out1.Add(d1d3.Get(0));
out1.Add(d1d10.Get(0));
out1.Add(d1d5.Get(0));
multicast.AddMulticastRoute(nodes.Get(1), multicastSource,
multicastGroup, d0d1.Get(1), out1);

NetDeviceContainer out2;
out2.Add(d0d2.Get(1));
multicast.AddMulticastRoute(nodes.Get(2), multicastSource,
multicastGroup, d2d6.Get(0), out2);

NetDeviceContainer out3;
out3.Add(d3d7.Get(0));
multicast.AddMulticastRoute(nodes.Get(3), multicastSource,
multicastGroup, d1d3.Get(1), out3);

NetDeviceContainer out4;
out4.Add(d4d8.Get(0));
multicast.AddMulticastRoute(nodes.Get(4), multicastSource,
multicastGroup, d0d4.Get(1), out4);

NetDeviceContainer out5;
out5.Add(d5d9.Get(0));
multicast.AddMulticastRoute(nodes.Get(5), multicastSource,
multicastGroup, d1d5.Get(1), out5);

NetDeviceContainer out10;
out10.Add(d10d11.Get(0));
multicast.AddMulticastRoute(nodes.Get(10), multicastSource,
multicastGroup, d1d10.Get(1), out10);
}

int main(int argc, char *argv[])
{
int NUM_NODES = 12;

NodeContainer nodes;
nodes.Create(NUM_NODES);

InternetStackHelper stack;
stack.Install(nodes);

buildNetwork(nodes);

ApplicationContainer clientApps;
ApplicationContainer replicaApps;

PacketSinkHelper sink ("ns3::UdpSocketFactory",
InetSocketAddress(Ipv4Address::GetAny(), 9));
replicaApps.Add(sink.Install(nodes.Get(9)));
replicaApps.Add(sink.Install(nodes.Get(8)));
replicaApps.Add(sink.Install(nodes.Get(7)));
replicaApps.Add(sink.Install(nodes.Get(11)));
replicaApps.Start(Seconds(0.0));
replicaApps.Stop(Seconds(10.0));

OnOffHelper onoff ("ns3::UdpSocketFactory",
Address (InetSocketAddress ("226.10.28.80", 9)));
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable
(1)));
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable
(0)));
onoff.SetAttribute ("DataRate", DataRateValue (DataRate ("255b/
s")));
onoff.SetAttribute ("PacketSize", UintegerValue (128));
clientApps.Add(onoff.Install(nodes.Get(6)));
clientApps.Start(Seconds(0.0));
clientApps.Stop(Seconds(9.5));

AnimationInterface anim;
anim.SetOutputFile("p2p-multicast.tr");

boundingBox(nodes);

anim.StartAnimation();

Ipv4GlobalRoutingHelper::PopulateRoutingTables();

Simulator::Run();
Simulator::Destroy();
anim.StopAnimation();
return 0;
}

John Abraham

unread,
Jun 23, 2011, 5:12:07 PM6/23/11
to ns-3-users
Can you paste the output of the "*.tr" file in say "pastebin.com"? or
something similar?

Steve Marotta

unread,
Jun 23, 2011, 5:17:43 PM6/23/11
to ns-3-users
I can paste it right here -

0.0 N 0 3.5 2.5
0.0 N 1 7 2.5
0.0 N 2 2.5 1
0.0 N 3 8 1
0.0 N 4 2.5 4
0.0 N 5 8 4
0.0 N 6 1 1
0.0 N 7 9.5 1
0.0 N 8 1 4
0.0 N 9 9.5 4
0.0 N 10 8 2.5
0.0 N 11 9.5 2.5
0.0 L 0 1
0.0 L 0 2
0.0 L 0 4
0.0 L 1 3
0.0 L 1 5
0.0 L 1 10
0.0 L 2 6
0.0 L 3 7
0.0 L 4 8
0.0 L 5 9
0.0 L 10 11
4.01569 P 6 2 4.01594 4.01769 4.01794
4.01794 P 2 0 4.01819 4.01994 4.02019
4.02019 P 0 1 4.02044 4.02219 4.02244
4.02244 P 1 3 4.0227 4.02444 4.0247
4.02244 P 1 5 4.0227 4.02444 4.0247
4.02244 P 1 10 4.0227 4.02444 4.0247
4.0247 P 3 7 4.02495 4.0267 4.02695
4.0247 P 5 9 4.02495 4.0267 4.02695
4.0247 P 10 11 4.02495 4.0267 4.02695
8.03137 P 6 2 8.03163 8.03337 8.03363
8.03363 P 2 0 8.03388 8.03563 8.03588
8.03588 P 0 1 8.03613 8.03788 8.03813
8.03813 P 1 3 8.03838 8.04013 8.04038
8.03813 P 1 5 8.03838 8.04013 8.04038
8.03813 P 1 10 8.03838 8.04013 8.04038
8.04038 P 3 7 8.04064 8.04238 8.04264
8.04038 P 5 9 8.04064 8.04238 8.04264
8.04038 P 10 11 8.04064 8.04238 8.04264

John Abraham

unread,
Jun 23, 2011, 5:35:39 PM6/23/11
to ns-3-users
All the lines with P indicate Packets.

4.01569 P 6 2 4.01594 4.01769 4.01794
indicates, at 4.015 second of simulation time
node 6 scheduled a packet for node 2

So if you set NetAnim sliders just about right (slow enough) you could
see the ~ 30 packets sent.

-john

Steve Marotta

unread,
Jun 23, 2011, 5:47:46 PM6/23/11
to ns-3-users
Hey, look at that! You're right! I just wasn't looking far enough into
the scenario. Thanks for that. I feel mildly stupid, but grateful for
the help and for the working code staring back at me.

~ Steve

John Abraham

unread,
Jun 23, 2011, 5:50:16 PM6/23/11
to ns-3-users
There is a new version of NetAnim going through reviews, which
supports xml, so it will make the animation trace files will be more
intuitive.
> > > > >   onoff.SetAttribute ("OffTime",...
>
> read more »

Nasimul Hyder Maruf Bhuyan

unread,
Sep 23, 2012, 10:32:55 AM9/23/12
to ns-3-...@googlegroups.com
Hi,
thank you for your code ! I am a new user in ns3 ! I saw the example third.cc ( http://code.google.com/p/ns-3/source/browse/examples/third.cc?spec=svna84f60b6cd122c17c8955a94971bc571aff62b4d&r=a84f60b6cd122c17c8955a94971bc571aff62b4d ) !
this program is related with UdpEchoClientHelper ! I want to replace it into multicast ! can you help me how I can do this in multicast !

BR,
N H Maruf Bhuyan

tomas.h...@gmail.com

unread,
Oct 9, 2014, 7:19:45 AM10/9/14
to ns-3-...@googlegroups.com
Your code has a mistake. You have link for destination 8 node, but link does not exist. I have correct code for NS-3 3.19.
Reply all
Reply to author
Forward
0 new messages