Yes, of course.

You must remember that a packet is a pointer to an object in NS-2 (C++).

You can create a new type of packet. A customized one. A, say, ZhangPacket.

So you must teach your new packet what "special" data It will carry
and you must "notify" NS-2 how to deal with It.

For that, you must inherit from Packet class to ZhangPacket child
class. I suppose that ZhangPacket carries buffers, variables,
information in general (whenever you want).

In your program, you must call a function from the transport agent
called send(), like this:

-----------
void
MYPROGRAM::send(int nbytes, AppData* data) {
       agent_->send(nbytes, data);
}
-----------

this function receives a type AppData*. Why? All packets carry
AppData*. Your ZhangPacket will carry ZhangData* (this is what you
want to carry on inside your packets, your payload).

So, you can pass a ZhangData to a function which received AppData
(because inherit properties).

At the other side, your program in another node, can receive from
transport the pointer to a ZhangPacket and open it. So you will
process a ZhangData* and voilà.

Transport will call a function from app, called process_data().

Let's see an example:

------------
void
MYPROGRAM::process_data(int nbytes, AppData* data) {
       if ((data == NULL) || (data->type() != ZHANG_DATA) ||
           (((ZHANGData*)data)->bits() == NULL))
           return;
       char* buffer = ((ZHANGData*)data)->bits();
       switch (((ZHANGData*)data)->cmdType()) {
           case ZHANG_DATA_1:
               processZhangData1(buffer);
               break;
           case ZHANG_DATA_2:
               processZhangData2(buffer);
               break;
       }
}
-------------

You MUST declare all new data types and all new packet types.

Take a look in manual. Look for App layer. This section show us how to
create them.

A critical point is: Remember to allocate and deallocate your payload!
Pointers aren't data! They (believe to) point to allocated data.

Sidney Doria
Brazil



2008/10/24 Zhang Shangying <[EMAIL PROTECTED]>:
> Dear Sidney Doria,
>
>     Sorry to bother you!
>
>    I know you from the ns-users list.Can you kindly tell me how to perform
> Application Layer Payload Transfer in NS2?  some piece of code or links
> where I can study it would be wonderful for me. I appreciate your help very
> much.
>
>    Thanks in advances!
>
>    Best regards,
>
>    Shangying Zhang
>



--
Sidney Doria
Redes ad hoc móveis
Mestrado em Computação
UFCG
Brasil

"Nessa jornada, o conhecimento será o seu escudo..."
(Mestre dos Magos no episódio do grimoire de ouro)

Reply via email to