📄 hawaii.cc
字号:
/* * File: Implementation of New Hawaii Agent Class for the ns * network simulator * Author: Chieh-Yih Wan (wan@comet.columbia.edu), Feb 2000 * * ================================================================ */// #ident "@(#)hawaii.cc 0.9 2000/3/8 SMI"#include <template.h>#include <random.h>#include <address.h>#include <mobilenode.h>#include <hawaii.h>static class HawaiiAgentClass : public TclClass {public: HawaiiAgentClass() : TclClass("Agent/Hawaii") {} TclObject* create(int, const char*const*) { return (new HawaiiAgent()); }} class_hawaiiagent;HawaiiAgent::HawaiiAgent() : Agent(PT_UDP), drr_addr_(-1), Pcoa_(-1){ bind("off_hawaii_", &off_hawaii_); bind("previous_coa_", &Pcoa_); bind("domain_root_router_", &drr_addr_);}/* Wan:Generate Hawaii specific messages, special for BS node */void HawaiiAgent::genHawaii(HwMsgType type, int homeAddr, int oldBS){ Node* mynode = 0 ; int myNodeId; int nodeaddr = MY_ADDR; Tcl::instance().evalf("%s myNodeID", name_); myNodeId = atoi(Tcl::instance().result()); printf("BS's node ID is: %d \n", myNodeId); Packet *p = allocpkt(); hdr_ip *iph = (hdr_ip *)p->access(off_ip_); hdr_hawaii *h = (hdr_hawaii *)p->access(off_hawaii_); h->hawaiiTag_ = -127; switch (type) { case HW_Power_Up: /* (1) generate power up Hawaii msgs * (2) forward to DRR hop-by-hop */ if(nodeaddr == drr_addr_) { printf("I am Domain Root Router, ACK the message\n"); } else { iph->daddr() = drr_addr_; iph->dport() = 0; h->type_ = HW_Power_Up; h->home_addr_ = homeAddr; h->old_base_station_ = -1; h->new_base_station_ = nodeaddr; h->route_lifetime_ = 2; h->previous_hop_ = myNodeId; send(p, 0); } break; case HW_Handoff: /* (1) Generate Hawaii Handoff msg. * (2) If I am the old BS, reply ACK. only for intermediate nodes. * (3) If I am not, forward it to old BS hop-by-hop. */ iph->daddr() = oldBS; iph->dport() = 0; h->type_ = HW_Handoff; h->home_addr_ = homeAddr; h->old_base_station_ = oldBS; h->new_base_station_ = nodeaddr; h->route_lifetime_ = 2; h->previous_hop_ = myNodeId; send(p, 0); DEBUG(2) printf("Send Hawaii Msg to %d at %f\n", oldBS, CUR_TIME); fflush(stdout); break; case HW_ACK: /* (1) When receive hawaii Ack, if I am the BS/FA, I should generate * Reg Reply to MH. * (2) This message is generated by DRR or old BS, and send directly * from src to dst. not hop-by-hop. */ break; case HW_Refresh: break; default: break; } }/* Wan: Process Hawaii Msgs */void HawaiiAgent::recv(Packet* p, Handler *){ Tcl& tcl = Tcl::instance(); char *objname = NULL; NsObject *obj = NULL; hdr_ip *iph = (hdr_ip *)p->access(off_ip_); hdr_cmn *ch = (hdr_cmn*)p->access(off_cmn_); int nodeaddr = Address::instance().get_nodeaddr(addr()); hdr_hawaii *hwh = (hdr_hawaii *)p->access(off_hawaii_); int myNodeId, nextHop; Tcl::instance().evalf("%s myNodeID", name_); myNodeId = atoi(Tcl::instance().result()); if(hwh->hawaiiTag_ == -127){ DEBUG(2) printf("ROUTER[%d:%d]:Hawaii Msg at %fs->", nodeaddr, myNodeId, CUR_TIME); switch(hwh->type_) { case HW_Power_Up: /* (1) forward to DRR hop-by-hop * (2) if I am neither DRR nor FA, change the route info * for this MH. * (3) if I am DRR, ack the message. */ if(nodeaddr == drr_addr_) { printf("DRR[%d:%d]: Power up Msg at time %fs\n", nodeaddr, myNodeId, CUR_TIME); tcl.evalf("%s change-route %d %d", name_, hwh->home_addr_, hwh->previous_hop_); iph->daddr() = hwh->new_base_station_; iph->saddr() = addr(); hwh->type_ = HW_ACK; send(p,0); } else { DEBUG(2) printf("Power Up:create RouteEntry[%d] and forward Msg\n", hwh->home_addr_); /* Change the route entry for this MH */ tcl.evalf("%s change-route %d %d", name_, hwh->home_addr_, hwh->previous_hop_); hwh->previous_hop_ = myNodeId; /* forward to nexthop */ tcl.evalf("addrToString %d", drr_addr_); tcl.evalf("%s get-nexthop %s", name_, TCL_RESULT); iph->daddr() = atoi(TCL_RESULT); /* next hop */ send(p, 0); } break; case HW_Handoff: /* (1) Generate Hawaii Handoff msg. * (2) If I am the old BS, reply ACK. only for intermediate nodes. * (3) If I am not, forward it to old BS hop-by-hop. Update current * node's ID as previous hop. */ if(hwh->old_base_station_ == nodeaddr){ DEBUG(2) printf("Old BS: Change Route and ACK\n"); } else { DEBUG(2) printf("Handoff->Update Routing Table for MH[%d]", hwh->home_addr_); fflush(stdout); tcl.evalf("%s change-route %d %d", name_, hwh->home_addr_, hwh->previous_hop_); tcl.evalf("addrToString %d", hwh->old_base_station_); DEBUG(2) printf("\nThe address of %d is %s\n", hwh->old_base_station_, TCL_RESULT); tcl.evalf("%s get-nexthop %s", name_, TCL_RESULT); nextHop = atoi(TCL_RESULT); iph->daddr() = nextHop; hwh->previous_hop_ = myNodeId; send(p, 0); DEBUG(2) printf("Forward to next hop[%d]\n", iph->daddr()); } break; case HW_ACK: /* (1) When receive hawaii Ack, if I am the BS/FA, I should generate * Reg Reply to MH. * (2) This message is generated by DRR or old BS, and send directly * from src to dst. not hop-by-hop. */ break; case HW_Refresh: break; case HW_MSF: Tcl::instance().evalf("addrToString %d", hwh->new_base_station_); DEBUG(2) printf("\n new base station is %d \n", TCL_RESULT); Tcl::instance().evalf("%s get-nexthop %s", name_, TCL_RESULT); nextHop = atoi(TCL_RESULT); DEBUG(2) printf("\nNext-Hop is %d \n", nextHop); iph->daddr() = nextHop; iph->saddr() = addr(); tcl.evalf("%s change-route-addr %d %d", name_, hwh->home_addr_, nextHop); send(p, 0); DEBUG(2) printf("Old BS[%d]: Change Route and ACK -> %d\n", addr(), iph->daddr()); DEBUG(2) printf("Handoff-> Update Routing Table\n"); fflush(stdout); break; default: break; } } else { } }void HawaiiAgent::timeout(int ){}int HawaiiAgent::command(int argc, const char*const* argv){ if (argc == 3) { if (strcmp(argv[1], "beacon-period") == 0) { // beacon_ = atof(argv[2]); // timer_.resched(Random::uniform(0, beacon_)); return TCL_OK; } if (strcmp(argv[1], "bcast-target") == 0) { // bcast_target_ = (NsObject *)TclObject::lookup(argv[2]); return TCL_OK; } if (strcmp(argv[1], "ragent") == 0) { // ragent_ = (NsObject *)TclObject::lookup(argv[2]); return TCL_OK; } } return (Agent::command(argc, argv));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -