How to use NetDevice->Send

538 views
Skip to first unread message

João Loureiro

unread,
Dec 13, 2013, 12:39:03 PM12/13/13
to ns-3-...@googlegroups.com
Hi.

I'm starting with the development of a wired network grid, in which I need to test some basic concepts before moving to higher layers. In order to emulate the behavior of a microcontroller, I will have develop my own mac layer and so on...
But, as a beginner, I am already missing the basic concepts.

My question is. How can I send a packet by accessing the Send method at the NetDevice, without getting errors?

If possible, instead of using the Mac48 bases, I would like to create my own address basis, which is still beyond my poor knowledge.

Appreciate any help.

The code piece is this:

(the error msg goes bellow)

-----------------------------------------------------------------------------------------------------------------

NodeContainer my_nodes;

[...]

network_discovery(uint16_t start) {
    Ptr<Packet> pck = Create<Packet> (1000); //1000 bytes of dummy data
    Ptr<NetDevice> nd;
    Address mac_address = Mac48Address("00:00:00:00:00:d3");

    uint32_t n_nodes = my_nodes.GetN();
    for (uint32_t i = 0; i < n_nodes; ++i) {
        Ptr<Node> n = my_nodes.Get(i);
        nd = n->GetDevice(1);
        nd->Send(pck, mac_address, 0);
    }

}

[...]

my_nodes.Create(size_x * size_y);

Simulator::Schedule(Seconds(start), &network_discovery, start);

[...]

-----------------------------------------------------------------------------------------------------------------

I get the following error: (sometimes just a core dumped, without the PPP) 

assert failed. cond="false", msg="PPP Protocol number not defined!", file=../src/point-to-point/model/point-to-point-net-device.cc, line=622
terminate called without an active exception

RUN FINISHED; Aborted; core dumped; real time: 350ms; user: 10ms; system: 180ms

João Loureiro

unread,
Dec 13, 2013, 1:41:43 PM12/13/13
to ns-3-...@googlegroups.com
I actually found out that for the p2p network device, the protocol number has to be 0x800...

How could I create my own Adrress basis?

Tommaso Pecorella

unread,
Dec 14, 2013, 3:00:16 AM12/14/13
to ns-3-...@googlegroups.com
You can subclass the base "Address" class. Check the differences in Mac[16,48,64]Address. They're all a good starting point.

About the protocol number, this refers to the IANA assigned protocol numbers. You might need a protocol number or not.

Hope this helps.

T.

PS: with new addresses, you'll need also a NetDevice handling them.

João Loureiro

unread,
Dec 14, 2013, 12:00:44 PM12/14/13
to ns-3-...@googlegroups.com
Tommaso, thank you very much for ur help!

I think u got my idea. I feel somehow limited by the actual netdevice, and I really think I should develop a new netdevice based on the available, which better fits my needs. But the fact is that I dont know even where to start from. I could copy and paste some code, but I really think I should go through the more correct and formal approach of development of ns3 modules.

What I want is to develop a network of microcontrollers, which are also sensors. Ill plan to further connect this network to a fluid dynamic simulator to feed the network with "real" sensor data. The simulation model which I am thinking on, could be also used to simulate Networks on Chip. I would need network devices in which I could simulate digital pins connections, for handshaking and signaling, aside the data connections, all the layers above could be based on Network on Chip protocols and further on...

This is part of my PhD research topic, and even not fitting exactly inside the proposition of the ns3, I still found this to be the best simulation core in terms of performance and scalability. 

Could you recommend any good approach? where to start from? Any advice is very welcome. I still find hard to find help to some very specific points of the ns3 platform.

Thanks again!

cheers,

João 




2013/12/14 Tommaso Pecorella <tomm...@gmail.com>

--
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/4xJvyiyzdG0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/groups/opt_out.

Tommaso Pecorella

unread,
Dec 14, 2013, 12:33:24 PM12/14/13
to ns-3-...@googlegroups.com
Hi,

I'd suggest to start from the basics (i.e., the ns-3 tutorial and manual). In particular you should understand very well the Events, Callbacks and Object Model.

About your goal, I'd also suggest to study a simple NetDevice. The CsmaNetDevice is one of the simplest ones.

However, after you have a good idea of the above mentioned things, I'd also suggest to grab a piece of paper and write down some assumptions, otherwise you'll be in trouble later on.
As an example: let's assume you'd like to simulate a popular SCADA system: ModBus.
Since ns-3 is a Discrete Event simulator, you'll be perfectly able to simulate a serial line, but... not bit by bit.
ns-3 can do all the things you want at message level, but it will have issues if you want to go down at signal level (i.e., actual signals raising a pin in the serial), as it's not meant for that. Note that it's not impossible to use ns-3 for single bits, it's just... I don't know. It might work as well, but nobody tried it in that way, so I can't say if it could work efficiently. I fear not.

Of course, if raising a pin means receiving a message (i.e., channel busy), that's perfectly fine. But splitting a data message into its single bits... can be done, but it's damn tricky.

So, I'd say that ns-3 can be successfully used for IEC, CAN, ModBus, etc., but at message level. The only thing that could effectively work at signal level is the spectrum model, which could be leveraged to simulate the overlap of bits, like the CAN priority headers (which, by the way, could be simulated more efficiently with some tricks).

Hope this helps,

T.

João Loureiro

unread,
Dec 18, 2013, 8:36:27 PM12/18/13
to ns-3-...@googlegroups.com
Tommaso, thank you again.

I took a look at some net-devices, specially at the Carrier Sense example as u said. What is done is some kind of signaling  based on flags at the channel level, right? If i got it right, I think that what I would need is something pretty much like this, since I could have many flags to represent the different signals, and specify a delay for reading and writing those flags.

But, between the net-devices, I found more appropriate the PointToPoint Net device. My network will be based in only p2p connections, and as less overhead as possible is desirable, so not even a MAC address is required. Also, it is very simple.

From that, I started a new module called "usn", which is a copy of the point-to-point module, in such a way that, after making the first advances with this development, I would start changing/removing/adding stuff from/to this module.

I started well, and then I have usn-channel, usn-remote-channell, usn-header, usn-net-device, usn-helper etc.... But now Im facing a problem which is somehow beyond my understanding now.

When I call the helper, just like the p2p-helper does, it creates two net devices, in my case usn-net-devices, and attach it to the nodes. But, whenever I try to reach this  net-devices again, later on in the code, the node actually returns a NetDevice, but not the usn-net-device, which the helper have added it to. So, can I access the net-device i've created, by accessing the node?

I'm afraid I was a confusing. But follows the code In any case, where my doubt is bellow:

******************************************+
 void
    network_discovery() {
        Ptr<Packet> pck = Create<Packet> (10); //10 bytes of dummy data
        Ptr<USNNetDevice> nd;     <----------------------------------------------------------------Depending on the Pointer type ....
        Address mac_address = Mac48Address("ff:ff:ff:ff:ff:ff");

        uint32_t n_nodes = m_nodes.GetN();
        for (uint32_t i = 0; i < n_nodes; ++i) {
            Ptr<Node> n = m_nodes.Get(i);
            uint16_t n_nodes = n->GetNDevices();

            if (n_nodes > 0) {
                nd = n->GetDevice(0);     <--------------------------------- Error on doing this convention, or...
                nd->Send(pck, mac_address, 0x800);
                nd->SendPacket(pck);    <----------------------------------- Error on finding this method.
+++++++++++++++++++++++++++


Thank you very much!
usn-example.cc

João Loureiro

unread,
Dec 18, 2013, 9:13:18 PM12/18/13
to ns-3-...@googlegroups.com
I just found out that I missed this convertion:

->GetObject<USNNetDevice>()

So it would becomes

    network_discovery() {
        Ptr<Packet> pck = Create<Packet> (10); //10 bytes of dummy data
        Ptr<USNNetDevice> nd;
        Address mac_address = Mac48Address("ff:ff:ff:ff:ff:ff");

        uint32_t n_nodes = m_nodes.GetN();
        for (uint32_t i = 0; i < n_nodes; ++i) {
            Ptr<Node> n = m_nodes.Get(i);
            uint16_t n_nodes = n->GetNDevices();

            if (n_nodes > 0) {
                nd = n->GetDevice(0)->GetObject<USNNetDevice>();
                nd->Send(pck, mac_address, 0x800);
                nd->SendPacket(pck);

Tommaso Pecorella

unread,
Dec 19, 2013, 6:00:38 AM12/19/13
to ns-3-...@googlegroups.com
Hi,

that should work as intended.

Cheers,

T.
Reply all
Reply to author
Forward
0 new messages