?? ll.cc
字號:
/* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- *//* Modified and extended by Sandeep Kumar, Kopparapu Suman and Richa * Jain, Indian Institute of Technology, Bombay. * June, 2001.*/ /* Copyright (c) 2001 Indian Insitute of Technology, Bombay. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code and binary code must contain * the above copyright notice, this list of conditions and the following * disclaimer. * * 2. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed at Indian Insitute of * Technology, Bombay. * * 3. The name of the Institute may not be used to endorse or promote * products derived from this software without specific prior written * permission. * INDIAN INSTITUTE OF TECHNOLOGY, BOMBAY, MAKES NO REPRESENTATIONS * CONCERNING EITHER THE MERCHANTABILITY OF THIS SOFTWARE OR THE * SUITABILITY OF THIS SOFTWARE FOR ANY PARTICULAR PURPOSE. The software * is provided "as is" without express or implied warranty of any kind.*//* * Copyright (c) 1997 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the Daedalus Research * Group at the University of California Berkeley. * 4. Neither the name of the University nor of the Laboratory may be used * to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * Contributed by the Daedalus Research Group, http://daedalus.cs.berkeley.edu */#ifndef lintstatic const char rcsid[] = "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/ll.cc,v 1.44 1999/10/14 22:19:23 yuriy Exp $ (UCB)";#endif#include <errmodel.h>#include <mac.h>#include <ll.h>#include <address.h>#include <dsr/hdr_sr.h>#include <mac-gprs.h>//#include <mac-802_11.h>int hdr_ll::offset_;static class LLHeaderClass : public PacketHeaderClass {public: LLHeaderClass() : PacketHeaderClass("PacketHeader/LL", sizeof(hdr_ll)) { bind_offset(&hdr_ll::offset_); }} class_hdr_ll;static class LLClass : public TclClass {public: LLClass() : TclClass("LL") {} TclObject* create(int, const char*const*) { return (new LL); }} class_ll;int LL::llverbose_ = {0} ;//rjLL::LL() : LinkDelay(), seqno_(0), ackno_(0), macDA_(0), ifq_(0), mac_(0), lanrouter_(0), arptable_(0), varp_(0), downtarget_(0), uptarget_(0), acked_(1), lhSend_(this), acSend_(this), datacounter(0), ackcounter(0), llfraged_(1), llfragsz_(300){ bind("macDA_", &macDA_); bind("acked_", &acked_); bind("llfraged_",&llfraged_); bind("llfragsz_",&llfragsz_); bind("llverbose_",&llverbose_); buf_= new PacketQueue();}int LL::command(int argc, const char*const* argv){ Tcl& tcl = Tcl::instance(); if (argc == 3) { if (strcmp(argv[1], "ifq") == 0) { ifq_ = (Queue*) TclObject::lookup(argv[2]); return (TCL_OK); } if(strcmp(argv[1], "arptable") == 0) { arptable_ = (ARPTable*)TclObject::lookup(argv[2]); assert(arptable_); return TCL_OK; } if(strcmp(argv[1], "varp") == 0) { varp_ = (VARPTable*)TclObject::lookup(argv[2]); assert(varp_); return TCL_OK; } if (strcmp(argv[1], "mac") == 0) { mac_ = (Mac*) TclObject::lookup(argv[2]); assert(mac_); return (TCL_OK); } if (strcmp(argv[1], "down-target") == 0) { downtarget_ = (NsObject*) TclObject::lookup(argv[2]); return (TCL_OK); } if (strcmp(argv[1], "up-target") == 0) { uptarget_ = (NsObject*) TclObject::lookup(argv[2]); return (TCL_OK); } if (strcmp(argv[1], "lanrouter") == 0) { lanrouter_ = (LanRouter*) TclObject::lookup(argv[2]); return (TCL_OK); } } else if (argc == 2) { if (strcmp(argv[1], "ifq") == 0) { tcl.resultf("%s", ifq_->name()); return (TCL_OK); } if (strcmp(argv[1], "mac") == 0) { tcl.resultf("%s", mac_->name()); return (TCL_OK); } if (strcmp(argv[1], "down-target") == 0) { tcl.resultf("%s", downtarget_->name()); return (TCL_OK); } if (strcmp(argv[1], "up-target") == 0) { tcl.resultf("%s", uptarget_->name()); return (TCL_OK); } } return LinkDelay::command(argc, argv);}void LL::recv(Packet* p, Handler* /*h*/){ hdr_cmn *ch = HDR_CMN(p); hdr_ll *llh = HDR_LL(p);//sandy hdr_ip *iph =HDR_IP(p); //giving mac a pointer to the ifq.rj if ( mac_->q_ == 0 ) { //printf ("<%d> %f LL: mac q doesnt exist\n", mac_->addr(), NOW); mac_->q_= ifq_; //rj //printf("LL: mac q set \n "); } if (llverbose_==1) fprintf(stderr,"<%d> %f LL: recv. pkt_type=%s uid=%d seqno=%d bopno=%d eopno=%d ipsrc=%d ipdst=%d\n", mac_->addr(), NOW, packet_info.name(ch->ptype()), ch->uid_, llh->seqno_, llh->bopno_, llh->eopno_, Address::instance().get_nodeaddr(iph->saddr()), Address::instance().get_nodeaddr(iph->daddr())); // Sanity Check assert(initialized()); if(p->incoming) { p->incoming = 0; }//if arp packet send to approprite place //sandy if(ch->direction()==hdr_cmn::UP){ if(ch->ptype_ == PT_ARP){ if (llverbose_==1) fprintf(stderr,"<%d> %f LL: sent an ARP to arptable\n", mac_->addr(), NOW ); arptable_->arpinput(p, this); return; } }//if ack pkt or data pkt... //sandy if(llh->lltype_==LL_ACK) recvACK(p); else recvDATA(p);}void LL::recvDATA(Packet* p){ hdr_cmn *ch = HDR_CMN(p); if(ch->direction() == hdr_cmn::UP){ if (llverbose_==1) fprintf(stderr,"<%d> %f LL:DATA on its way up. calling SendUpDATA\n", mac_->addr(), NOW ); sendUpDATA(p); }else{ ch->direction() = hdr_cmn::DOWN; if (llverbose_==1) fprintf(stderr,"<%d> %f LL: DATA on its way down. calling enqueDATA\n", mac_->addr(), NOW ); enqueDATA(p); }}void LL::enqueDATA(Packet* p){ hdr_cmn *ch = HDR_CMN(p); hdr_ip *ih = HDR_IP(p); // XXX HACK for now - Padma, 03/99. nsaddr_t dst = (nsaddr_t)Address::instance().get_nodeaddr(ih->daddr()); //nsaddr_t dst = ih->dst(); hdr_ll *llh = HDR_LL(p); char *mh = (char*)p->access(hdr_mac::offset_); // llh->seqno_ = ++seqno_; llh->lltype() = LL_DATA; mac_->hdr_src(mh, mac_->addr()); mac_->hdr_type(mh, ETHERTYPE_IP);// moved below --sandy int tx = 0; switch(ch->addr_type()) { case NS_AF_ILINK: mac_->hdr_dst((char*) HDR_MAC(p), ch->next_hop()); break; case NS_AF_INET: dst = ch->next_hop(); /* FALL THROUGH */ case NS_AF_NONE: if (IP_BROADCAST == (u_int32_t) dst) { mac_->hdr_dst((char*) HDR_MAC(p), MAC_BROADCAST); break; } /* Assuming arptable is present, send query */ if (arptable_) { tx = arptable_->arpresolve(dst, p, this); break; } //if (varp_) { //tx = varp_->arpresolve(dst, p); //break; //} /* FALL THROUGH */ default: int IPnh = (lanrouter_) ? lanrouter_->next_hop(p) : -1; if (IPnh < 0) mac_->hdr_dst((char*) HDR_MAC(p),macDA_); else if (varp_) tx = varp_->arpresolve(IPnh, p); else mac_->hdr_dst((char*) HDR_MAC(p), IPnh); break; } if(tx==0) fragDATA(p);}void LL::fragDATA(Packet *p){ hdr_cmn *ch = HDR_CMN(p);//fragmenting to start here....//sandy int psize; if (llfraged_==1) psize=llfragsz_; else psize=ch->size_; int bopno=seqno_; int eopno=bopno + (int)((ch->size_-1)/psize); int i=seqno_; if (llverbose_==1) fprintf(stderr,"<%d> %f LL: creating ll %d fragments \n", mac_->addr(), NOW, eopno-bopno); for ( i = bopno; i <= eopno; i++){ if (i==eopno) //new changes for size -sandy psize=ch->size_-(eopno-bopno)*psize; Packet * sp = p->copy(); hdr_cmn *chsp = HDR_CMN(sp); hdr_ll *llhsp = HDR_LL(sp); hdr_ip *ihsp = HDR_IP(sp);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -