sending packet from ns-3 to real world

1,619 views
Skip to first unread message

Luca Costantino

unread,
Jan 11, 2012, 10:26:55 AM1/11/12
to ns-3-users
hi everyone

i need to send data from ns-3 to the outside world...

i started by creating a topology with two nodes, connected through a
csma connection. this nodes have address 10.0.0.1 and 10.0.0.2 with a
/24 netmask.
on the second node i installed a second netdevice with address 10.0.1.1/24

using the udpsocket example i installed a src socket on the first node
on 10.0.0.1/24 and dst socket on the second node on 10.0.1.1/24.

the program works as expected, and messages are exchanges smoothly :)
here is the code http://pastebin.com/3R1jgNRx


second step has been to create a tap interface and attach it
10.0.1.1/24. on the real machine i have a real nic with ip address
10.0.1.2/24.
i changed the destination address of the SendStuff ro 10.0.1.2,
launched a server listening on the same address and same port but
nothing is received...

here is the code http://pastebin.com/qVCAPUXS

any hint on how to solve this?

thanks
luca

--
Chiave pubblica http://luca.costantino.googlepages.com/luca.costantino.asc

Prima di tutto vennero a prendere gli zingari e fui contento, perché
rubacchiavano.
Poi vennero a prendere gli ebrei e stetti zitto, perché mi stavano antipatici.
Poi vennero a prendere gli omosessuali, e fui sollevato, perché mi
erano fastidiosi.
Poi vennero a prendere i comunisti, e io non dissi niente, perché non
ero comunista.
Un giorno vennero a prendere me, e non c’era rimasto nessuno a protestare.
(Martin Niemöller)

Tom Henderson

unread,
Jan 12, 2012, 12:27:14 AM1/12/12
to ns-3-...@googlegroups.com
On 01/11/2012 07:26 AM, Luca Costantino wrote:
> hi everyone
>
> i need to send data from ns-3 to the outside world...
>
> i started by creating a topology with two nodes, connected through a
> csma connection. this nodes have address 10.0.0.1 and 10.0.0.2 with a
> /24 netmask.
> on the second node i installed a second netdevice with address 10.0.1.1/24
>
> using the udpsocket example i installed a src socket on the first node
> on 10.0.0.1/24 and dst socket on the second node on 10.0.1.1/24.
>
> the program works as expected, and messages are exchanges smoothly :)
> here is the code http://pastebin.com/3R1jgNRx
>
>
> second step has been to create a tap interface and attach it
> 10.0.1.1/24. on the real machine i have a real nic with ip address
> 10.0.1.2/24.
> i changed the destination address of the SendStuff ro 10.0.1.2,
> launched a server listening on the same address and same port but
> nothing is received...
>
> here is the code http://pastebin.com/qVCAPUXS
>
> any hint on how to solve this?
>
> thanks
> luca
>

Have you tried instead the EmuNetDevice instead of the TapBridge? It
sounds like you want the functionality of emu (src/emu).

- Tom

Luca Costantino

unread,
Jan 12, 2012, 1:44:24 AM1/12/12
to ns-3-...@googlegroups.com
Il 12 gennaio 2012 06:27, Tom Henderson <to...@tomh.org> ha scritto:
> Have you tried instead the EmuNetDevice instead of the TapBridge?  It sounds
> like you want the functionality of emu (src/emu).
>
> - Tom

hi and thanks for your reply... i wasn't sure about what to use,
tapbridge or emunet... i'm gonna do some test with emunet, then.

thanks again

Frederic Urbani

unread,
Jan 12, 2012, 4:04:24 AM1/12/12
to ns-3-...@googlegroups.com
Hi,

There is also 3 exemples using DCE and TapBridge and CCNx.
Did you set the good rights to the executable named tap-creator ?

Frederic.

Luca Costantino

unread,
Jan 12, 2012, 4:13:50 AM1/12/12
to ns-3-...@googlegroups.com
>l 12 gennaio 2012 06:27, Tom Henderson <to...@tomh.org> ha scritto:
> Have you tried instead the EmuNetDevice instead of the TapBridge?  It sounds
> like you want the functionality of emu (src/emu).
>
> - Tom

so... i started using src/examples/emu-ping.cc modifying it to ping
8.8.8.8 (google dns) and it worked like a charm.
next step has been to put a socket a sending function in the source
instead of the v4ping application.

here's the code http://pastebin.com/kDducyS9

unfortunately my code is not working ;( i'm not even able to see any
packet coming from 192.168.27.90 with wireshark...

what am i doing wrong?

luca

Luca Costantino

unread,
Jan 12, 2012, 4:15:10 AM1/12/12
to ns-3-...@googlegroups.com
Il 12 gennaio 2012 10:04, Frederic Urbani <frederi...@inria.fr> ha scritto:
> There is also 3 exemples using DCE and TapBridge and CCNx.
> Did you set the good rights  to the executable named tap-creator ?
>
> Frederic.

I don't think I got what you're trying to say... It seem to me that
EmuNetDevice is the right component to use if I want to communicate
from ns-3 to the real world (instead of tap taht is use to communicate
from the real world to ns-3)...

Luca Costantino

unread,
Jan 12, 2012, 4:28:21 AM1/12/12
to ns-3-...@googlegroups.com
Il 12 gennaio 2012 10:18, Frederic Urbani <frederi...@inria.fr> ha scritto:
> Tap works in 2 directions  ie NS3 -> real , real -> NS3.

thanks for having pointed that out! i think that the documentation
section should be revisited!

did you have a look at the not working code that i posted yesterday
with tad device?
i *really* need some help in this

thanks

Frederic Urbani

unread,
Jan 12, 2012, 5:08:36 AM1/12/12
to ns-3-...@googlegroups.com
On 01/12/2012 10:28 AM, Luca Costantino wrote:
> Il 12 gennaio 2012 10:18, Frederic Urbani<frederi...@inria.fr> ha scritto:
>> Tap works in 2 directions ie NS3 -> real , real -> NS3.
> thanks for having pointed that out! i think that the documentation
> section should be revisited!
>
> did you have a look at the not working code that i posted yesterday
> with tad device?
> i *really* need some help in this
>
> thanks
> luca
>
Yes, I do not see what could be wrong ? But my experience of tap is some
old now .

Frederic.

Luca Costantino

unread,
Jan 12, 2012, 5:37:32 AM1/12/12
to ns-3-...@googlegroups.com
Il 12 gennaio 2012 11:08, Frederic Urbani <frederi...@inria.fr> ha scritto:
> Yes, I do not see what could be wrong ? But my experience of tap is some old
> now .

i think i found the problem

it seems that i cannot send udp packet to a server hosted on the same
machine i'm running ns-3
here's the code http://pastebin.com/vSuhxgdi

i made a test using both a ping application a send-through-udp-socket
application, and i watched the output of ns-3, of the real server
application and of wireshark

test 1: remoteIP 192.168.27.95, i.e. a working node on my subnet.
ping worked fine, and through wireshark i was able to see that 2 kind
of packets were sent, ICMP packets (from the ping application) and udp
packet (from my application).
of course those last packets went lost because there were no server
application on that machine.

test 2: remoteIp 192.168.27.117, i.e. a workin node on my subnet with
my server application running.
everything works fine, ping are received and udp data are correctly
received by my application --> yeah!

test 3: remoteIp 192.168.27.76, i.e. my pc eth0's real address, where
the same server application as before is running
ping doesn't works and but server receives no data.

is that a bug?

Luca Costantino

unread,
Jan 12, 2012, 5:47:53 AM1/12/12
to ns-3-...@googlegroups.com
Il 12 gennaio 2012 11:37, Luca Costantino <luca.co...@gmail.com>
ha scritto:

> Il 12 gennaio 2012 11:08, Frederic Urbani <frederi...@inria.fr> ha scritto:
>> Yes, I do not see what could be wrong ? But my experience of tap is some old
>> now .
>
> i think i found the problem
>
> it seems that i cannot send udp packet to a server hosted on the same
> machine i'm running ns-3
> here's the code http://pastebin.com/vSuhxgdi

In particular i can see arp messages sent from 00:00:00:00:00:01 (i.e.
the emunetdevice node) asking for 192.68.27.76's mac address... but no
one responds...

Tom Henderson

unread,
Jan 13, 2012, 12:32:49 AM1/13/12
to ns-3-...@googlegroups.com

No, case 3 is not supported. eth0 will not see the arps.

If you had a spare physical device such as an eth1, you could use that
in emu mode and add it to the bridge along with eth0.
brctl addbr br0
brctl addif br0 eth0
brctl addif br0 eth1

If not, if you want to send to your own machine's eth0, you might be
able to create a tap device, do not assign it an address, and add it to
a Linux bridge with eth0; e.g.
brctl addbr br0
brctl addif br0 eth0
brctl addif br0 tap0
and then use the TapBridge in 'UseLocal' mode in ns-3. On the ns-3
side, you would want to bridge the ns-3 net device (CSMA) to another
CSMA device so that it could talk to an ns-3 IP layer. Kind of
convoluted and untested, but might work.

But it would be simpler to just talk to your local server via another
subnet that you put on the tap device in the usual fashion. In general,
it is easier to use TapBridge to talk to your localhost and namespaces,
and Emu to talk to other hosts.

- Tom

Luca Costantino

unread,
Jan 13, 2012, 4:45:19 AM1/13/12
to ns-3-...@googlegroups.com
Il 13 gennaio 2012 06:32, Tom Henderson <to...@tomh.org> ha scritto:
> No, case 3 is not supported.  eth0 will not see the arps.
>
> If you had a spare physical device such as an eth1, you could use that in
> emu mode and add it to the bridge along with eth0.
> brctl addbr br0
> brctl addif br0 eth0
> brctl addif br0 eth1
>
> If not, if you want to send to your own machine's eth0, you might be able to
> create a tap device, do not assign it an address, and add it to a Linux
> bridge with eth0; e.g.
> brctl addbr br0
> brctl addif br0 eth0
> brctl addif br0 tap0
> and then use the TapBridge in 'UseLocal' mode in ns-3.  On the ns-3 side,
> you would want to bridge the ns-3 net device (CSMA) to another CSMA device
> so that it could talk to an ns-3 IP layer.  Kind of convoluted and untested,
> but might work.
>
> But it would be simpler to just talk to your local server via another subnet
> that you put on the tap device in the usual fashion.  In general, it is
> easier to use TapBridge to talk to your localhost and namespaces, and Emu to
> talk to other hosts.

thanks for your reply
i finally succeeded in what i need...

client app --> client/server app --> ns3 --> server app, everythin
running on the same machine

i.e. i have a certain number of client apps that sends data to a gw
application that forwards data with a certain policy to ns3, wich in
turn manipulate data ad forwards it to a server application that
collects everything

i used two tap interfaces in ns3, one for the incoming connection, and
one for the outgoing

thanks again for your help

Ali Esswie

unread,
Jan 29, 2013, 12:34:40 PM1/29/13
to ns-3-...@googlegroups.com, luca.co...@gmail.com
Dear Mr Luca,
           may you please send me your e-mail to get in touch with you regarding some key concepts of simulation in the loop over NS-3.

Thanks
Ali esswie

Christopher Mansour

unread,
Mar 15, 2013, 4:33:32 PM3/15/13
to ns-3-...@googlegroups.com, luca.co...@gmail.com
Can you post your codes, all I need is to know how to take the real packets from an interface and send them to a node on NS3
thanks

Frederic Urbani

unread,
Jan 12, 2012, 4:18:59 AM1/12/12
to ns-3-...@googlegroups.com
On 01/12/2012 10:15 AM, Luca Costantino wrote:
> Il 12 gennaio 2012 10:04, Frederic Urbani<frederi...@inria.fr> ha scritto:
>> There is also 3 exemples using DCE and TapBridge and CCNx.
>> Did you set the good rights to the executable named tap-creator ?
>>
>> Frederic.
> I don't think I got what you're trying to say... It seem to me that
> EmuNetDevice is the right component to use if I want to communicate
> from ns-3 to the real world (instead of tap taht is use to communicate
> from the real world to ns-3)...
>
> luca
>
>
Tap works in 2 directions ie NS3 -> real , real -> NS3.

Frederic.

Anton Nelson

unread,
Jun 8, 2017, 3:54:34 PM6/8/17
to ns-3-users, luca.co...@gmail.com
Was it necessary to configure one ingoing and one outgoing connection, or could a single tap be used?

Tommaso Pecorella

unread,
Jul 9, 2017, 9:28:25 AM7/9/17
to ns-3-users
Please read the posting guidelines.

T.
Reply all
Reply to author
Forward
0 new messages