Forum Replies Created
Simply you need to add your custom fields in packet header structure of ns-2 and use it in your code.
In packet.h modify the structure hdr_cmn as follows :
struct hdr_cmn {
enum dir_t { DOWN= -1, NONE= 0, UP= 1 };
packet_t ptype_; // packet type (see above)
int size_; // simulated packet size
int uid_; // unique id
int error_; // error flag
int errbitcnt_; // # of corrupted bits jahn
int fecsize_;
double ts_; // timestamp: for q-delay measurement
int iface_; // receiving interface (label)
dir_t direction_; // direction: 0=none, 1=up, -1=down
x; // the node’s x location
y; // the node’s y location
….
….
}
After that you can access that x and y values from any packet that you are creating of using.
For example, before transmitting a packet you may store the x and y location of the node in the packet header structure and then send it.
If a node which receives a packet wan to know the location from which that packet originated, then it can also read it from the received packet header.
The average delay and average end to end delay calculation are the metrics you are mentioning in an indirect manner.
Even you can do that average calculation for any selected data flows.
Just search internet with keywords “delay”, “e2e delay” “trace analysis” awk scripts – you will find a suitable awk script for doing the measurement of your interest.
Check the following link. It is a similar project using same kind of routing protocol.
http://www.projectguideline.com/performance-of-swarm-routing-protocol-under-manet/
In fact, the Answer is simple, you didn’t declare the variable “ns_” in the global memory space.
you only declared a variable named “ns”.
# ==================================================== =================
# Main Program
# ======================================================================
set ns [new Simulator]
So, if you are referring an undeclared variable “ns_” from the global memory space, then you should receive the error
can’t read “ns_”: no such variable
while executing
“global $ns_”
(file “wireless.tcl” line 24)
Since there is no such variable declared in global scope.
For doing this, you can write a “hello Like” protocol or a beacon protocol.
If a mobile agent(data mules) starts to move, it should send a “hello” or “beacon” message. A sensor node which hears that “hello” or “beacon” message will start to send data to that mobile agent.
You can see a similar project in the following link :
In that VANET project, the stationary nodes will do something while recieving the beacon of the moving node(vehicle).
You may design your protocol based on this model.
By default, an ns-2 packet will not contain any payload. Payload is just mentioned as size in the packet header. So, under ns-2, generally, there will not be any payload data.
So, you can not print that nothing.
For advanced Users :
The message passing agent of ns2 will hold little bit of sting data along with the packet – learn to use message passing agent
There exists another way to send real payload under ns-2 – but as far as I know, no one ever used that in any of the research simulation. (Some earlier video trace related projects used real payload under ns-2? – I am not sure)
In fact, labels are meant for rendering in NAM. So, generally, there is no simple way to access them from .cc code. But any way, you can do it in one way or another if you know the usage of bind command.
Bind command is used to do this tcl to cc or cc to tcl binding.
Learn about bind command.