Write a new layer 3 protocol for ns3

361 views
Skip to first unread message

Fabrizio Serpi

unread,
Jan 27, 2017, 3:55:40 AM1/27/17
to ns-3-users
Hello everyone,

for some simulations I need to write a new protocol/application for layer 3 that works over the existent layer 2 csma. I don't need any other layer above 3.

Can you suggest a good point where to start? I checked the documentation but it seems there isn't a clear explanation on how to insert and make it work together with the simualtor a new protocol, especially when it comes to intra layer communication.


Thanks.

Fabrizio

Tommaso Pecorella

unread,
Jan 29, 2017, 8:22:50 PM1/29/17
to ns-3-users
Hi Fabrizio,

"Down" calls are easy: call the appropriate methods in the NetDevice.

Note that IP uses the TrafficControl layer. As a consequence, there's (also) a similar function in the TrafficControl layer.

T.

Fabrizio Serpi

unread,
Jan 30, 2017, 6:44:58 AM1/30/17
to ns-3-users
Thank you for the reply Dott. Pecorella,

actually I need to stop just at layer 3. I need to simulate a network of sensors based on MAC addresses and write protocols and some operations all in the same layer above 2. I'll check the down calls first as you suggested.


Fabrizio

Fabrizio Serpi

unread,
Feb 3, 2017, 11:19:47 AM2/3/17
to ns-3-users
Hi Tommaso, hi everyone,

I tried as suggested to work on the NetDevice, actually the CsmaNetDevice in my case, and I was successful in sending a packet from one node to another.

What I was wondering now is how I can inspect the packet at the receiving end, that is, how I can receive the packet. Is it involved the use of callbacks and protocol handlers? or

there is an easier way.

I'm also following a post found in http://tommy-ns-3-corner.blogspot.it/2014/03/how-to-develop-new-protocol.html, I already created a new header that I attached to the packet.


Thank

Fabrizio

Tommaso Pecorella

unread,
Feb 4, 2017, 8:50:53 AM2/4/17
to ns-3-users
No easier way, sorry. Callbacks and handlers.

Cheers,

T.

Fabrizio Serpi

unread,
Feb 9, 2017, 3:34:32 AM2/9/17
to ns-3-users
Hi Tommaso, I all,

I implemented the necessary methods to receive a packet with the callback mechanism, so that the packet can be received at layer 3. I managed to send a packet down the line through the csma net device, but the strange thing is that the packet is not always received. When I try different layer 3 packet length I have different results, like the packet has to be around 100 bytes, otherwise I receive errors from the net device comparing headers to payloads (errors from lines 758 and 760 depending on the packet length, in file csma-net-device.cc). When the packet length is ok, I can't receive a packet sent in Dix encapsulation mode, but I can receive a packet encapsulated in Llc mode, and this happens whether I interpose the traffic control layer between layer 2 and 3 or not. Is this normal or I'm missing something? I thought the minimum packet length for layer 3 could be the minimum packet length for Dix spec or Llc spec, 46 byte and 38 byte respectively, if I'm not mistaken. I can't figure it out.

Thanks

Fabrizio

Tommaso Pecorella

unread,
Feb 12, 2017, 8:41:12 PM2/12/17
to ns-3-users
Hi,

it sounds like a case of Serialization / Deserialization size mismatch. Double check your headers.

T.

Fabrizio Serpi

unread,
Feb 21, 2017, 10:50:57 AM2/21/17
to ns-3-users
Hi all,

thank you Tommaso,

actually there were problems in the serialization and deserialization of the MAC addresses in my custom header. Moreover I used a custom protocol number too small, and when I used one higher than 1500 (decimal) it was all ok, with every payload and encapsulation mode.

By the way, I'm working on writing an application on top of level 3, or in level 3, since I'm not using any IP layer. I was wondering if Sockets are necessary and can work with MAC addresses instead of the IP ones, and if a single application can work both as a client and as a server.


Thank you in advance

Fabrizio


Tommaso Pecorella

unread,
Feb 25, 2017, 7:32:19 PM2/25/17
to ns-3-users
Hi,

if you don't install IP at all, you can forget about sockets as well. You'll have to reinvent the wheel tho :)
Anyway, take a look at PacketSockets (they're not for the fainted hearth, but they're mostly mandatory).

Have fun,

T.

Fabrizio Serpi

unread,
Mar 3, 2017, 5:30:53 AM3/3/17
to ns-3-users
Thank you Tommaso,

actually they are quite hard to manage. I realized a client/server application which can be installed in every node, but the biggest problem now is the coordination of client and server in each node so that they can communicate with each other. I managed an exchange of packets between two nodes, but the solution doesn't seem to be easily scalable.

Fabrizio
Reply all
Reply to author
Forward
0 new messages