00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #ifdef NS_DIFFUSION
00049
00050 #include "diffagent.h"
00051 #include "diffrtg.h"
00052
00053
00054 static class DiffAppAgentClass : public TclClass {
00055 public:
00056 DiffAppAgentClass() : TclClass("Agent/DiffusionApp") {}
00057 TclObject* create(int , const char*const* ) {
00058 return(new DiffAppAgent());
00059 }
00060 } class_diffusion_app_agent;
00061
00062
00063 void NsLocal::sendPacket(DiffPacket p, int len, int dst) {
00064 agent_->sendPacket(p, len, dst);
00065 }
00066
00067 DiffPacket NsLocal::recvPacket(int fd) {
00068 DiffPacket p;
00069 fprintf(stderr, "This function should not get called; call DiffAppAgent::recv(Packet *, Handler *) instead\n\n");
00070 exit(1);
00071 return (p);
00072 }
00073
00074
00075 DiffAppAgent::DiffAppAgent() : Agent(PT_DIFF) {
00076 dr_ = NR::create_ns_NR(DEFAULT_DIFFUSION_PORT, this);
00077 }
00078
00079
00080 int DiffAppAgent::command(int argc, const char*const* argv) {
00081
00082
00083 if (argc == 3) {
00084 if (strcmp(argv[1], "node") == 0) {
00085 MobileNode *node = (MobileNode *)TclObject::lookup(argv[2]);
00086 ((DiffusionRouting *)dr_)->getNode(node);
00087 return TCL_OK;
00088 }
00089 if (strcmp(argv[1], "agent-id") == 0) {
00090 int id = atoi(argv[2]);
00091 ((DiffusionRouting *)dr_)->getAgentId(id);
00092 return TCL_OK;
00093 }
00094 }
00095 return Agent::command(argc, argv);
00096 }
00097
00098
00099
00100 void DiffAppAgent::recv(Packet* p, Handler* h)
00101 {
00102 Message *msg;
00103 DiffusionData *diffdata;
00104
00105 diffdata = (DiffusionData *)(p->userdata());
00106 msg = diffdata->data();
00107
00108 DiffusionRouting *dr = (DiffusionRouting*)dr_;
00109 dr->recvMessage(msg);
00110
00111 Packet::free(p);
00112
00113 }
00114
00115 void
00116 DiffAppAgent::initpkt(Packet* p, Message* msg, int len)
00117 {
00118 hdr_cmn* ch = HDR_CMN(p);
00119 hdr_ip* iph = HDR_IP(p);
00120 AppData *diffdata;
00121
00122 diffdata = new DiffusionData(msg, len);
00123 p->setdata(diffdata);
00124
00125
00126 ch->uid() = msg->pkt_num_;
00127 ch->ptype() = type_;
00128 ch->size() = size_;
00129 ch->timestamp() = Scheduler::instance().clock();
00130 ch->iface() = UNKN_IFACE.value();
00131 ch->direction() = hdr_cmn::NONE;
00132 ch->error() = 0;
00133
00134 iph->saddr() = addr();
00135 iph->sport() = ((DiffusionRouting*)dr_)->getAgentId();
00136 iph->daddr() = addr();
00137 iph->flowid() = fid_;
00138 iph->prio() = prio_;
00139 iph->ttl() = defttl_;
00140
00141 hdr_flags* hf = hdr_flags::access(p);
00142 hf->ecn_capable_ = 0;
00143 hf->ecn_ = 0;
00144 hf->eln_ = 0;
00145 hf->ecn_to_echo_ = 0;
00146 hf->fs_ = 0;
00147 hf->no_ts_ = 0;
00148 hf->pri_ = 0;
00149 hf->cong_action_ = 0;
00150
00151 }
00152
00153 Packet*
00154 DiffAppAgent::createNsPkt(Message *msg, int len)
00155 {
00156 Packet *p;
00157
00158 p = Packet::alloc();
00159 initpkt(p, msg, len);
00160 return (p);
00161 }
00162
00163
00164 void DiffAppAgent::sendPacket(DiffPacket dp, int len, int dst) {
00165 Packet *p;
00166 hdr_ip *iph;
00167 Message *msg;
00168
00169 msg = (Message *)dp;
00170 p = createNsPkt(msg, len);
00171 iph = HDR_IP(p);
00172 iph->dport() = dst;
00173
00174
00175 (void)Scheduler::instance().schedule(target_, p, 0.000001);
00176
00177 }
00178
00179
00180 #endif // NS
00181
00182
00183