specify a device for an application

52 views
Skip to first unread message

Michael

unread,
Dec 3, 2009, 12:53:02 AM12/3/09
to ns-3-users
How do you specify which device you want an application to use?

I have multiple WifiNetDevices installed in a node, and I have
multiple applications installed on the same node. How do I specify
which device to use for each application?

For example, I have OnOffApplication and UdpEchoClient applications
installed on a node with two devices. I want OnOffApplication to only
run on device 0, and UdpEchoClient to only run on device 1.

Thanks!
Michael

Antti Mäkelä

unread,
Dec 3, 2009, 4:03:54 AM12/3/09
to ns-3-users
On Dec 3, 7:53 am, Michael <nowat...@gmail.com> wrote:
> How do you specify which device you want an application to use?

At the moment, you don't directly. You can work around it a bit if
the applications have separate destinations - then you can just set
the routes destination via appropriate devices.

For specific device-applicability, I'm working on it -
http://www.nsnam.org/bugzilla/show_bug.cgi?id=742 :).

Michael

unread,
Dec 3, 2009, 4:42:50 PM12/3/09
to ns-3-users
Thanks! It looks like your patch will work great for what I'm trying
to do!

Michael

Michael

unread,
Dec 30, 2009, 9:18:19 PM12/30/09
to ns-3-users
I'm using BindToNetDevice(<Ptr>(NetDevice)) in OnOffApplication to try
to send packets over a specific NetDevice. Should I see the packets
on the pcap trace for that device? It still looks like all the
packets are going out on the same device according to the pcap trace.
Or is there something else I need to do to send the packets out only
the device I specify? I installed two wifi net devices on a node.

m_socket = Socket::CreateSocket (GetNode(), m_tid);
m_socket->BindToNetDevice(GetNode()->GetDevice(m_devNum)); //
added this line
m_socket->Bind ();
m_socket->Connect (m_peer);

Thanks!
Michael

Antti Mäkelä

unread,
Dec 31, 2009, 3:42:57 AM12/31/09
to ns-3-users
On Dec 31, 4:18 am, Michael <nowat...@gmail.com> wrote:
> I'm using BindToNetDevice(<Ptr>(NetDevice)) in OnOffApplication to try
> to send packets over a specific NetDevice.  Should I see the packets
> on the pcap trace for that device?  It still looks like all the
> packets are going out on the same device according to the pcap trace.
> Or is there something else I need to do to send the packets out only
> the device I specify?  I installed two wifi net devices on a node.
>
>       m_socket = Socket::CreateSocket (GetNode(), m_tid);
>       m_socket->BindToNetDevice(GetNode()->GetDevice(m_devNum)); //
> added this line
>       m_socket->Bind ();
>       m_socket->Connect (m_peer);

There should be a viable route via both of these devices to your
destination for it to work. See examples/socket/socket-bound* for an
example.

Michael

unread,
Dec 31, 2009, 8:21:05 AM12/31/09
to ns-3-users
I am using wifi nodes all on the same wifi channel. The devices are
on different frequencies (channel numbers), but all of the packets
seem to send from only one device (device 0).

Antti Mäkelä

unread,
Dec 31, 2009, 9:16:28 AM12/31/09
to ns-3-users
On Dec 31, 3:21 pm, Michael <nowat...@gmail.com> wrote:
> I am using wifi nodes all on the same wifi channel.  The devices are
> on different frequencies (channel numbers), but all of the packets
> seem to send from only one device (device 0).

Hmm - I didn't actually test this configuration where multiple
interfaces are connected to *same* subnet. Any chance you could post
some sort of abridged source code where the issue appears (preferably
not your full simulation, but some simple case that demonstrates the
issue)?

Also, are you using latest ns-dev (the patch has been merged and
there were a few revisions since my original post)?

Michael

unread,
Jan 1, 2010, 4:25:13 PM1/1/10
to ns-3-users
I uploaded a file "testBindTo.cc" It is a modified /examples/wifi-
simple-adhoc.cc. It doesn't work quite right though.

Packets are only sent from the highest numbered device on the node
with multiple devices.

When the "source[chan]->BindToNetDevice(dev);" line is active, only
numPackets are sent. When the line is commented out, all of the
packets (numPackets*numChannels) are sent out over a single device
with different socket values.

I am using the latest dev package, I did an hg pull just before
starting this earlier today.

Thanks for your assistance!
Michael

Antti Mäkelä

unread,
Jan 2, 2010, 6:22:23 AM1/2/10
to ns-3-users
On Jan 1, 11:25 pm, Michael <nowat...@gmail.com> wrote:
> I uploaded a file "testBindTo.cc"  It is a modified /examples/wifi-
> simple-adhoc.cc.  It doesn't work quite right though.

Ok,

Key information seems to be that your remote address is broadcast,

InetSocketAddress remote = InetSocketAddress (Ipv4Address
("255.255.255.255"), 80);

so this case is something I definitely didn't test. There *is* a
check in place though.

Right now I would probably simply run this with gdb with a
breakpoint at udp-socket-impl.cc and line 371 and see what happens
there. Since it seems that you are having issues even *without* device
binding in place (all packets going out of a single interface anyway)?
So there may be something there..

I can get back onto this on next week if you wish to try your own
debugs in the meantime. I'd also suggest filing a bug report.

Tom Henderson

unread,
Jan 4, 2010, 12:52:44 AM1/4/10
to ns-3-...@googlegroups.com
On 1/1/10 1:25 PM, Michael wrote:
> I uploaded a file "testBindTo.cc" It is a modified /examples/wifi-
> simple-adhoc.cc. It doesn't work quite right though.
>
> Packets are only sent from the highest numbered device on the node
> with multiple devices.
>
> When the "source[chan]->BindToNetDevice(dev);" line is active, only
> numPackets are sent. When the line is commented out, all of the
> packets (numPackets*numChannels) are sent out over a single device
> with different socket values.
>
> I am using the latest dev package, I did an hg pull just before
> starting this earlier today.

Michael,
I did not know where to look for your uploaded file, but is it possible
you are running OLSR (or AODV) and are encountering this bug?
http://www.nsnam.org/bugzilla/show_bug.cgi?id=778

If you are not running static routing, then most likely the routing
protocol will not honor the request to bind to the device until these
bugs are fixed.

- Tom

Antti Mäkelä

unread,
Jan 4, 2010, 3:56:39 AM1/4/10
to ns-3-users
On Jan 4, 7:52 am, Tom Henderson <t...@tomh.org> wrote:
el,
> I did not know where to look for your uploaded file, but is it possible
> you are running OLSR (or AODV) and are encountering this bug?http://www.nsnam.org/bugzilla/show_bug.cgi?id=778

http://ns-3-users.googlegroups.com/web/testBindTo.cc?gda=dsFdDD8AAADbpj5ltU5plboFYd9CaUiLt3zeAZNtpHhfjSlSX4E-OV05kApfN1Dp5BLlGj2CGlmccyFKn-rNKC-d1pM_IdV0
is the file (visible in group view of google groups web interface).

Just reading the source doesn't have any references to OLSR, unless
mobility models automagically install it.

Message has been deleted

Antti Mäkelä

unread,
Jan 4, 2010, 6:19:43 AM1/4/10
to ns-3-users
Ok,

I think I have found something. This is in fact NOT a problem with
BindToNetDevice(), but looks like in the handling of broadcasts in
general in ipv4-l3-protocol.cc.

Lines 555-> handle subnet-directed broadcasts. Note that the choice
of output device is based *solely* on the destination mask matching
and, on line 575 there's a "return" statement. So whenever sending
limited broadcasts, the interface that is iterated first and matches
the mask sends stuff out.

I added

LogComponentEnable("UdpSocketImpl", LOG_LEVEL_LOGIC);
LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_LOGIC);

to your code and and commented bindtonetdevice out, and got this:
Testing 3 packets sent with receiver rss
-80
dev[0]=
0
source[0]=
0x8f19688
dev[1]=
0
source[1]=
0x8f19b68
called by 0x8f19688 pktCount=
3
UdpSocketImpl:Send(0x8f19688, 0x8f1f748,
0)
UdpSocketImpl:DoSend(0x8f19688,
0x8f1f748)
UdpSocketImpl:Bind
()
UdpSocketImpl:FinishBind
()
UdpSocketImpl:DoSendTo(0x8f19688, 0x8f1f748, 255.255.255.255,
80)
UdpSocketImpl:GetTxAvailable
()
Limited broadcast
start.
Ipv4L3Protocol:GetNInterfaces
()
Ipv4L3Protocol:GetAddress(0x8f16670, 0,
0)
Ipv4L3Protocol:GetInterface(0x8f16670,
0)
Ipv4L3Protocol:GetNInterfaces
()
Ipv4L3Protocol:GetAddress(0x8f16670, 1,
0)
Ipv4L3Protocol:GetInterface(0x8f16670,
1)
Sending one copy from 10.1.1.1 to 10.1.1.255 (mask is
255.255.255.0)
Ipv4L3Protocol:Send(0x8f16670, 0x8f217d8, 10.1.1.1, 10.1.1.255, 17,
0)
Ipv4L3Protocol:GetNAddresses(0x8f16670,
0)
Ipv4L3Protocol:GetInterface(0x8f16670,
0)
Ipv4L3Protocol:GetAddress(0x8f16670, 0,
0)
Ipv4L3Protocol:GetInterface(0x8f16670,
0)
Testing address 127.0.0.1 with mask
255.0.0.0
Ipv4L3Protocol:GetNAddresses(0x8f16670,
0)
Ipv4L3Protocol:GetInterface(0x8f16670,
0)
Ipv4L3Protocol:GetNAddresses(0x8f16670,
1)
Ipv4L3Protocol:GetInterface(0x8f16670,
1)
Ipv4L3Protocol:GetAddress(0x8f16670, 1,
0)
Ipv4L3Protocol:GetInterface(0x8f16670,
1)
Testing address 10.1.1.1 with mask
255.255.255.0
Ipv4L3Protocol::Send case 2: subnet directed bcast to
10.1.1.1
Ipv4L3Protocol:BuildHeader
()
UdpSocketImpl:GetTxAvailable
()
Ipv4L3Protocol:GetNInterfaces
()
Limited broadcast
end.
called by 0x8f19b68 pktCount=
3
UdpSocketImpl:Send(0x8f19b68, 0x8f1a4f8,
0)
UdpSocketImpl:DoSend(0x8f19b68,
0x8f1a4f8)
UdpSocketImpl:Bind
()
UdpSocketImpl:FinishBind
()
UdpSocketImpl:DoSendTo(0x8f19b68, 0x8f1a4f8, 255.255.255.255,
80)
UdpSocketImpl:GetTxAvailable
()
Limited broadcast
start.
Ipv4L3Protocol:GetNInterfaces
()
Ipv4L3Protocol:GetAddress(0x8f16670, 0,
0)
Ipv4L3Protocol:GetInterface(0x8f16670,
0)
Ipv4L3Protocol:GetNInterfaces
()
Ipv4L3Protocol:GetAddress(0x8f16670, 1,
0)
Ipv4L3Protocol:GetInterface(0x8f16670,
1)
Sending one copy from 10.1.1.1 to 10.1.1.255 (mask is
255.255.255.0)
Ipv4L3Protocol:Send(0x8f16670, 0x8f217d8, 10.1.1.1, 10.1.1.255, 17,
0)
Ipv4L3Protocol:GetNAddresses(0x8f16670,
0)
Ipv4L3Protocol:GetInterface(0x8f16670,
0)
Ipv4L3Protocol:GetAddress(0x8f16670, 0,
0)
Ipv4L3Protocol:GetInterface(0x8f16670,
0)
Testing address 127.0.0.1 with mask
255.0.0.0
Ipv4L3Protocol:GetNAddresses(0x8f16670,
0)
Ipv4L3Protocol:GetInterface(0x8f16670,
0)
Ipv4L3Protocol:GetNAddresses(0x8f16670,
1)
Ipv4L3Protocol:GetInterface(0x8f16670,
1)
Ipv4L3Protocol:GetAddress(0x8f16670, 1,
0)
Ipv4L3Protocol:GetInterface(0x8f16670,
1)
Testing address 10.1.1.1 with mask
255.255.255.0
Ipv4L3Protocol::Send case 2: subnet directed bcast to
10.1.1.1
Ipv4L3Protocol:BuildHeader
()
UdpSocketImpl:GetTxAvailable
()
Ipv4L3Protocol:GetNInterfaces
()
Limited broadcast
end.

So what happens is that even though the *socket* is sending via a
specific device, the broadcast-address-matching doesn't work properly.
Only difference if bindtonetdevice is active is that the *socket*
skips the non-matching devices, but the ipv4-l3-protocol still sends
whatever way it wishes..

I'm not sure if this is actually working as-intended - like I said,
connecting multiple devices from a single node to same subnet sounds a
bit odd to me so I have never encountered this configuration. Of
course, you could also start matching the source address in the ipv4-
l3-protocol.cc (simply add a check "if source == ifAddr.GetLocal()"
around line 565), but no idea what it would break.

Michael

unread,
Jan 4, 2010, 7:36:39 AM1/4/10
to ns-3-users
Thanks Antti for looking at this! I'll have to see if there is some
work around I can come up with. I may have to just create multiple
nodes to get the effect of having multiple devices. Or is there a way
to do broadcast without IP addresses? Then the ipv4 code would not
get called, right?\

Thanks again!
Michael

Antti Mäkelä

unread,
Jan 4, 2010, 7:46:30 AM1/4/10
to ns-3-users
On Jan 4, 2:36 pm, Michael <nowat...@gmail.com> wrote:
> Thanks Antti for looking at this!  I'll have to see if there is some
> work around I can come up with.  I may have to just create multiple
> nodes to get the effect of having multiple devices.  Or is there a way
> to do broadcast without IP addresses?  Then the ipv4 code would not
> get called, right?\

If you want to skip IP altogether, look into Packet Sockets (for
sending stuff at Ethernet level). Look in examples/csma-packet-
socket.cc to help you along the way. I haven't experimented with them
at all so can't help you there.

Michael

unread,
Jan 4, 2010, 7:57:26 AM1/4/10
to ns-3-users
Thanks! I'll give that a try. It looks like PacketSocketAddress
allows specifying a particular NetDevice, similar to your
BindToNetDevice().

Michael

Michael

unread,
Jan 4, 2010, 12:58:46 PM1/4/10
to ns-3-users
Do you have a line " 'packet-socket.h'," in your /src/node/wscript
file? That line was not in mine, but there is a packet-socket.cc line
earlier in the file. I added the .h line, but not sure if there was a
reason it was not included.

Michael

> > at all so can't help you there.- Hide quoted text -
>
> - Show quoted text -

Reply all
Reply to author
Forward
0 new messages