NS2 EXAMPLES SOURCE CODE
NS2 Examples Source Code offers you complete code support for your project, assignments and research work accomplishment. Our vision to support our students in all the ways we can has made us to reach the highest pinnacle of success today. We have crossed 7 successful years with a satisfaction that we have done the best to our students and will continue it, till our students feel contented with us.
You can approach us for any coding support in Ns2 regarding your projects, assignments and research work. We have well trained developers and experts with us, who can support you with their expertise to bring out the best in you. Commit with us today and feel our expertise and vast knowledge, to uplift your career value and performance.
NS2-EXAMPLES SOURCE CODE
NS2 Examples Source Code offers you few sample codes in Ns2, which reflects our code efficiency and expertise. You can approach us with any particular topic or concept in NS2; we will give you complete code support along with our guidance. We have given few example codes in Ns2 below for students to get an idea about NS2 simulation. For further programming help in Ns2, approach our experts through our online tutoring service and get more such example programs in Ns2.
Now let’s see some of the major networking areas, where NS2 simulation can be used.
- Wireless Sensor Ad hoc Networks
- Wireless sensor also in Network
- Underwater Acoustic sensor also in Network
- Cognitive Radio Network
- Vehicular Ad hoc also in Network
- Ad hoc Cognitive packet Network
- Software defined also in Network
All the above mentioned networks can be implemented in NS2. NS2 simulator is one of the widely used simulation tool, which is used to simulate a wide range of networking protocols, algorithms and techniques. To work with NS2 simulation we must be aware of the major concepts used in networking i.e. cluster formation, scheduling techniques, routing algorithms, congestion control schemes etc.
Another major aspect of NS2 simulation is the language used in it i.e. C++ and TCL [Tool command language]. You will work on both these major aspect of Ns2, while working with your simulation project. Now let’s see few example programs in NS2, to get more clear idea about NS2 simulation.
Example 1: Code for Software Defined Network
SDN::SDN(netsimaddr_t id) : Agent(PT_SDN),btimer(this), htimer(this), ntimer(this), rtimer(this), lrtimer(this), rqueue() {
identity = id;
sqnum = 2;
bid = 1;
LIST_INIT(&nbhead);
LIST_INIT(&bihead);
logtarget = 1;
ifqueue = 1;
xpos=0.2;
ypos=0.2;
zpos=0.2;
MobileNode *jNode;
}
void
BroadcastTimer::handle(Event*)
{
agent->id_purge();
Scheduler::instance().schedule(this, &intr, Broadcast_id);
}
void
HelloTimer::handle(Event*)
{
agent->sendHello();
double intrvl = Minintrvl +
((Maxintrvl – Minintrvl) * Random::uniform());
assert(intrvl >= 0);
Scheduler::instance().schedule(this, &intr, intrvl);
}
void
NeighborTimer::handle(Event*)
{
agent->nb_purge();
Scheduler::instance().schedule(this, &intr, intrvl);
}
void
RouteCacheTimer::handle(Event*)
{
agent->rt_purge();
Scheduler::instance().schedule(this, &intr, FREQUENCY);
}
Example 2: Code for VANET
This code explains about how a VANET routing protocol broadcast a message sending code.
void
VanetRBCAgent::sendRBC_pkt()
{
int pktsz;
Packet* pkt = allocpkt(); // Create a new packet
struct hdr_vanet_rbc *hdr = HDR_VANET_RBC(pkt);
hdr_ip* iph = HDR_IP(pkt);
iph->daddr() = IP_BROADCAST;
iph->dport() = iph->sport();
hdr->rbc_msgtype = VANETTYPE_REGBC; // (necessary for dispatching!)
hdr->rbc_senderID = vanetID_;
hdr->rbc_timestamp = Scheduler::instance().clock();
MobileNode *pnode = (MobileNode*)Node::get_node_by_address(vanetID_);
pnode->update_position(); // update the position, before using it
hdr->rbc_posx = pnode->X(); // include current own location
hdr->rbc_posy = pnode->Y();
pktsz = hdr->size(); // get packet-size of this type
hdr_cmn::access(pkt)->size() = pktsz; // set it in the simulator
Scheduler::instance().schedule(target_, pkt,
crypto_delay_ + JITTER*jitterfactor_);
if(running_ == true)
pkt_timer_.resched(interval_);
}
Example 3: Routing protocol in cognitive networks
int
RouteCache::checkRoute_logall(Path *p, int action, int start)
{
int c;
int route_wrong_count = 0;
if(p->length() == 0)
return 0;
assert(p->length() >= 2);
assert(action == ACTION_DEAD_LINK ||
action == ACTION_EVICT ||
action == ACTION_FIND_ROUTE);
for (c = start; c < p->length() – 1; c++)
{
if (God::instance()->hops((*p)1.getNSAddr_t(), (*p)1.getNSAddr_t()) != 1)
{
trace(“SRC %.9f _%s_ %s [%d %d] %s->%s dead %d %.9f”,
Scheduler::instance().clock(), net_id.dump(),
action_name[action], p->length(), c,
(*p)1.dump(), (*p)1.dump(),
(*p)1.link_type, (*p)1.t);
if(route_wrong_count == 0)
route_wrong_count = p->length() – c – 1;
}
}
Hope that, the above mentioned programs also would helpful for you in some ways. This was just a sample program in NS2, which we have provided to show our expertise in Ns2. You can also approach us anytime regarding your final year projects, assignment or research work , we will offer you our all round support. You can also get additional supports from us like thesis support, journal publication support and viva voice guidance.
STARTING POINT FOR ALL SUCCESS IS…………….
THE DESIRE TO ACHIEVE IT……………………………..
HAVE OUR GUIDANCE……………ACHIEVE YOUR SUCCESS…………..