diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/Makefile.in ns-2.1b9/Makefile.in --- ns-2.1b9.orig/Makefile.in Tue Sep 10 23:12:14 2002 +++ ns-2.1b9/Makefile.in Tue Sep 10 23:27:59 2002 @@ -129,7 +129,7 @@ OBJ_CC = \ tools/random.o tools/rng.o tools/ranvar.o common/misc.o common/timer-handler.o \ - common/scheduler.o common/object.o common/packet.o \ + common/scheduler.o common/object.o common/packet.o common/rawpacket.o \ common/ip.o routing/route.o common/connector.o common/ttl.o \ trace/trace.o trace/trace-ip.o \ classifier/classifier.o classifier/classifier-addr.o \ @@ -140,6 +140,7 @@ classifier/classifier-mpath.o mcast/replicator.o \ classifier/classifier-mac.o \ classifier/classifier-port.o src_rtg/classifier-sr.o \ + classifier/classifier-ext.o classifier/classifier-click.o \ src_rtg/sragent.o src_rtg/hdr_src.o adc/ump.o \ apps/app.o apps/telnet.o tcp/tcplib-telnet.o \ tools/trafgen.o trace/traffictrace.o tools/pareto.o \ @@ -165,7 +166,7 @@ tcp/nilist.o \ tools/integrator.o tools/queue-monitor.o \ tools/flowmon.o tools/loss-monitor.o \ - queue/queue.o queue/drop-tail.o \ + queue/queue.o queue/drop-tail.o queue/clickqueue.o \ adc/simple-intserv-sched.o queue/red.o \ queue/semantic-packetqueue.o queue/semantic-red.o \ tcp/ack-recons.o \ @@ -192,14 +193,14 @@ common/pkt-counter.o \ common/Decapsulator.o common/Encapsulator.o \ common/encap.o \ - mac/channel.o mac/mac.o mac/ll.o mac/mac-802_11.o \ + mac/channel.o mac/mac.o mac/ll.o mac/ll-ext.o mac/mac-802_11.o \ mac/mac-802_3.o mac/mac-tdma.o \ mobile/mip.o mobile/mip-reg.o mobile/gridkeeper.o \ mobile/propagation.o mobile/tworayground.o \ mobile/antenna.o mobile/omni-antenna.o \ mobile/shadowing.o mobile/shadowing-vis.o \ common/bi-connector.o common/node.o \ - common/mobilenode.o \ + common/mobilenode.o common/clicknode.o \ mac/arp.o mobile/god.o mobile/dem.o \ mobile/topography.o mobile/modulation.o \ queue/priqueue.o \ @@ -256,6 +257,7 @@ pushback/pushback-queue.o pushback/pushback.o \ common/parentnode.o trace/basetrace.o \ common/simulator.o asim/asim.o \ + routing/extrouter.o routing/extclickrouter.o \ @V_STLOBJ@ @@ -412,6 +414,7 @@ tcl/mpls/ns-mpls-simulator.tcl \ tcl/lib/ns-pushback.tcl \ tcl/lib/ns-srcrt.tcl \ + tcl/lib/ns-clicknode.tcl \ @V_NS_TCL_LIB_STL@ $(GEN_DIR)ns_tcl.cc: $(NS_TCL_LIB) diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/classifier/classifier-click.cc ns-2.1b9/classifier/classifier-click.cc --- ns-2.1b9.orig/classifier/classifier-click.cc Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/classifier/classifier-click.cc Tue Sep 10 23:28:00 2002 @@ -0,0 +1,552 @@ +/* + * classifier-click classifier file for nsclick + * $Header: /srl/dirkcvs/nsclick/ns-2.1b9/classifier/classifier-click.cc,v 1.4 2002/09/09 19:12:00 neufeldm Exp $ + */ + +/***************************************************************************** + * Copyright 2002, Univerity of Colorado at Boulder. * + * * + * All Rights Reserved * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose other than its incorporation into a * + * commercial product is hereby granted without fee, provided that the * + * above copyright notice appear in all copies and that both that * + * copyright notice and this permission notice appear in supporting * + * documentation, and that the name of the University not be used in * + * advertising or publicity pertaining to distribution of the software * + * without specific, written prior permission. * + * * + * UNIVERSITY OF COLORADO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS * + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * + * FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE UNIVERSITY * + * OF COLORADO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL * + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA * + * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * + * PERFORMANCE OF THIS SOFTWARE. * + * * + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "agent.h" +#include "packet.h" +#include "rawpacket.h" +#include "ip.h" +#include "extrouter.h" +#include "classifier.h" +#include "classifier-ext.h" +#include "mobilenode.h" +#include "clicknode.h" +#include "address.h" +#include +#include "scheduler.h" +#include "classifier-click.h" +#include "ll-ext.h" +#include "clickqueue.h" + +static class ClickClassifierClass : public TclClass { +public: + ClickClassifierClass() : TclClass("Classifier/Ext/Click") {} + TclObject* create(int, const char*const*) { + return (new ClickClassifier()); + } +} class_click_classifier; + + +void +ClickEventHandler::handle(Event* event) { + // XXX dangerous downcast - should use RTTI + ClickEvent* cevent = (ClickEvent*) event; + simclick_simstate esimstate; + esimstate.curtime = cevent->when_; + //fprintf(stderr,"Should be calling simclick_click_run: %lf\n",event->time_); + + simclick_click_run(cevent->clickinst_,&esimstate); + delete cevent; +} + +hash_map ClickClassifier::global_macmap_; +hash_map ClickClassifier::global_ipmap_; + +ClickClassifier::ClickClassifier() { + extrouter_ = this; + clickinst_ = NULL; +} + +int +ClickClassifier::command(int argc, const char*const* argv) +{ + Tcl& tcl = Tcl::instance(); + if (2 == argc) { + if (strcmp(argv[1], "getnodename") == 0) { + // getnodename + tcl.resultf(nodename_.c_str()); + return TCL_OK; + } + } + else if (3 == argc) { + if(strcmp(argv[1], "loadclick") == 0) { + simclick_simstate simstate; + simstate.curtime = GetSimTime(); + clickinst_ = simclick_click_create((simclick_sim)this,argv[2],&simstate); + + return TCL_OK; + } + if (strcmp(argv[1], "getip") == 0) { + // getip + int theif = simclick_sim_ifid_from_name((simclick_sim)this,argv[2]); + //fprintf(stderr,"get ipaddr is %s\n",ifipaddrs_[theif].c_str()); + tcl.resultf(ifipaddrs_[theif].c_str()); + return TCL_OK; + } + if (strcmp(argv[1], "getmac") == 0) { + // getmac + int theif = simclick_sim_ifid_from_name((simclick_sim)this,argv[2]); + //fprintf(stderr,"get macaddr is %s\n",ifmacaddrs_[theif].c_str()); + tcl.resultf(ifmacaddrs_[theif].c_str()); + return TCL_OK; + } + if (strcmp(argv[1], "setnodename") == 0) { + // setnodename + nodename_ = argv[2]; + return TCL_OK; + } + if (strcmp(argv[1], "setnodeaddr") == 0) { + // setnodeaddr + nodeaddr_ = Address::instance().str2addr(argv[2]); + return TCL_OK; + } + } + else if (4 == argc) { + if(strcmp(argv[1], "setip") == 0) { + // setip + int theif = simclick_sim_ifid_from_name((simclick_sim)this,argv[2]); + ifipaddrs_[theif] = string(argv[3]); + //fprintf(stderr,"ipaddr is %s\n",ifipaddrs_[theif].c_str()); + // Also save the binary form of this IP address in a static + // (i.e. simulator global) hash map of IP addresses to ns-2 + // addresses. This lets us track map IP to ns-2 address when + // we might need it. + global_ipmap_[inet_addr(argv[3])] = nodeaddr_; + return TCL_OK; + } + else if(strcmp(argv[1], "setmac") == 0) { + // setmac + int theif = simclick_sim_ifid_from_name((simclick_sim)this,argv[2]); + ifmacaddrs_[theif] = string(argv[3]); + //fprintf(stderr,"macaddr is %s\n",ifmacaddrs_[theif].c_str()); + + // Also save the binary form of this MAC address in a static + // (i.e. simulator global) hash map of MAC addresses to ns-2 + // addresses. This lets us set the destination address in the + // ns-2 packet header. + global_macmap_[MACAddr(string(argv[3]))] = nodeaddr_; + return TCL_OK; + } + } + + return ExtClassifier::command(argc, argv); +} + + +ClickClassifier::~ClickClassifier() { +} + +int +ClickClassifier::route(Packet* p) { + int result = 0; + if (clickinst_) { + unsigned char* data = NULL; + int len = ((PacketData*)(p->userdata()))->size(); + simclick_simpacketinfo simpinfo; + hdr_cmn* chdr = HDR_CMN(p); + int ifid = chdr->iface_; + hdr_ip* iphdr = hdr_ip::access(p); + simpinfo.id = chdr->uid(); + simpinfo.fid = iphdr->flowid(); + hdr_raw* rhdr = hdr_raw::access(p); + int nssubtype = rhdr->subtype; + int clicktype = GetClickPacketType(nssubtype); + unsigned char* pdat = p->accessdata(); + data = new unsigned char[len]; + memcpy(data,pdat,len); + /* + * XXX Destroy packet for now. This may change if we wind + * up having to track and reuse ns packets after they've gone through + * click. + */ + Packet::free(p); + p = NULL; + + simclick_simstate simstate; + simstate.curtime = GetSimTime(); + //fprintf(stderr,"Sending packet up to click...\n"); + simclick_click_send(clickinst_,&simstate,ifid,clicktype,data,len,&simpinfo); + delete data; + data = 0; + } + else { + fprintf(stderr,"No click upcall set!\n"); + } + return result; +} + +string +ClickClassifier::GetIPAddr(int ifid) { + return ifipaddrs_[ifid]; +} + +string +ClickClassifier::GetMACAddr(int ifid) { + return ifmacaddrs_[ifid]; +} + +string +ClickClassifier::GetNodeName() { + return nodename_; +} + +/* + * Click service methods + */ +int simclick_sim_ifid_from_name(simclick_sim simid, const char* ifname) { + int ifid = -1; + char* devname = NULL; + + /* + * Provide a mapping between a textual interface name + * and the id numbers used. This is mostly for the + * benefit of click scripts, i.e. you can still refer to + * an interface as, say, /dev/eth0. + */ + if (strstr(ifname,"tap") || strstr(ifname,"tun")) { + /* + * A tapX or tunX interface goes to and from the kernel - + * always IFID_KERNELTAP + */ + ifid = ExtRouter::IFID_KERNELTAP; + } + else if ((devname = strstr(ifname,"eth"))) { + /* + * Anything with an "eth" followed by a number is + * a regular interface. Add the number to IFID_FIRSTIF + * to get the handle. + */ + while (*devname && !isdigit(*devname)) { + devname++; + } + if (*devname) { + ifid = atoi(devname) + ExtRouter::IFID_FIRSTIF; + } + } + else if ((devname = strstr(ifname,"drop"))) { + /* + * Anything with an "drop" followed by a number is + * a special interface on which we place packets that + * get dropped due to MAC layer feedback. Add the number to + * IFID_FIRSTIFDROP to get the handle. + */ + while (*devname && !isdigit(*devname)) { + devname++; + } + if (*devname) { + ifid = atoi(devname) + ExtRouter::IFID_FIRSTIFDROP; + } + } + return ifid; +} + +int +simclick_sim_send_to_if(simclick_sim siminst,simclick_click clickinst, + int ifid,int type, const unsigned char* data,int len, + simclick_simpacketinfo* pinfo) { + + if (NULL == siminst) { + return -1; + } + + /* + * Bail out if we get a bad ifid + */ + if (ExtRouter::IFID_LASTIF < ifid) { + return -1; + } + /* + * XXX should probably use RTTI typesafe casts if they are now + * reliably implemented across the compilers/platforms we want + * to run on. + */ + ClickClassifier* theclassifier = (ClickClassifier*)siminst; + + return theclassifier->send_to_if(ifid,type,data,len,pinfo); +} + +int +simclick_sim_schedule(simclick_sim siminst,simclick_click clickinst, + struct timeval* when) { + + int result = 0; + double simtime = when->tv_sec + (when->tv_usec/1.0e6); + double simdelay = simtime - Scheduler::instance().clock(); + ClickClassifier* theclassifier = (ClickClassifier*)siminst; + ClickEvent* ev = new ClickEvent(); + ev->clickinst_ = clickinst; + ev->when_ = *when; + Scheduler::instance().schedule(&(theclassifier->cevhandler_),ev,simdelay); + //fprintf(stderr,"Event scheduled in %f seconds\n",simdelay); + + return result; +} + +void +simclick_sim_ipaddr_from_name(simclick_sim siminst,const char* ifname, + char* buf,int len) { + ClickClassifier* theclassifier = (ClickClassifier*)siminst; + int theif = simclick_sim_ifid_from_name(siminst,ifname); + string ipaddr = theclassifier->GetIPAddr(theif); + memset(buf,0,len); + ipaddr.copy(buf,len-1); +} + +void +simclick_sim_macaddr_from_name(simclick_sim siminst,const char* ifname, + char* buf,int len) { + ClickClassifier* theclassifier = (ClickClassifier*)siminst; + int theif = simclick_sim_ifid_from_name(siminst,ifname); + string macaddr = theclassifier->GetMACAddr(theif); + memset(buf,0,len); + macaddr.copy(buf,len-1); +} + +void +simclick_sim_get_node_name(simclick_sim siminst,char* buf,int len) { + ClickClassifier* theclassifier = (ClickClassifier*)siminst; + string nodename = theclassifier->GetNodeName(); + memset(buf,0,len); + nodename.copy(buf,len-1); +} + +int +ClickClassifier::send_to_if(int ifid,int type,const unsigned char* data, + int len,simclick_simpacketinfo* pinfo) { + int result = 0; + Tcl& tcl = Tcl::instance(); + + /* + * Package raw data into an ns-2 format raw packet, then send + * it on down the line. + */ + + Packet* pkt = MakeRawPacket(type,ifid,data,len,pinfo); + //fprintf(stderr,"simclickid == %d\n",simclickid); + recv(pkt,0); + + return result; +} + +int +ClickClassifier::IFReady(int ifid) { + NsObject* target = NULL; + // XXX assumes direct ifid->slot mapping + if (ExtRouter::IFID_KERNELTAP == ifid) { + return 1; + } + + target = slot_[ifid]; + LLExt* llext = (LLExt*) target; + return llext->ready(); +} + +int +simclick_sim_if_ready(simclick_sim siminst,simclick_click clickinst,int ifid) { + int result = 0; + ClickClassifier* theclassifier = (ClickClassifier*)siminst; + result = theclassifier->IFReady(ifid); + return result; +} + +int +ClickClassifier::GetNSSubtype(int type) { + switch (type) { + case SIMCLICK_PTYPE_ETHER: + return hdr_raw::ETHERNET; + + case SIMCLICK_PTYPE_IP: + return hdr_raw::IP; + + default: + return hdr_raw::NONE; + } + + return hdr_raw::NONE; +} + +int +ClickClassifier::GetClickPacketType(int nssubtype) { + switch (nssubtype) { + case hdr_raw::ETHERNET: + return SIMCLICK_PTYPE_ETHER; + + case hdr_raw::IP: + return SIMCLICK_PTYPE_IP; + + default: + return SIMCLICK_PTYPE_UNKNOWN; + } + + return SIMCLICK_PTYPE_UNKNOWN; +} + +// XXX +// Normally I'd bitterly complain about code like this. However, +// I don't really want to worry about annoying differences +// between IP header files across different platforms, and I +// want to get this code up and running ASAP. So... I'm defining +// a few things here to handle the minimal packet cracking I +// need to do to create raw packets. If more complicated +// packet munging is called for, something better should be created. +#define NS_ETHER_OFFSET_DADDR 0 +#define NS_ETHER_OFFSET_SADDR 6 +#define NS_ETHER_HEADER_SIZE 14 + + +void +ClickClassifier::LinkLayerFailedCallback(Packet* p, void* arg) { + // Hit the callback and then free the packet + ((ClickClassifier*)arg)->LinkLayerFailed(p); + Packet::free(p); +} + +void +ClickClassifier::LinkLayerFailed(Packet* p) { + //fprintf(stderr,"XXX Lost a packet!!!\n"); + if (clickinst_) { + unsigned char* data = NULL; + int len = ((PacketData*)(p->userdata()))->size(); + simclick_simpacketinfo simpinfo; + hdr_cmn* chdr = HDR_CMN(p); + int ifid = chdr->iface_ + IFID_LASTIF; + hdr_ip* iphdr = hdr_ip::access(p); + simpinfo.id = chdr->uid(); + simpinfo.fid = iphdr->flowid(); + hdr_raw* rhdr = hdr_raw::access(p); + int nssubtype = rhdr->subtype; + int clicktype = GetClickPacketType(nssubtype); + unsigned char* pdat = p->accessdata(); + data = new unsigned char[len]; + memcpy(data,pdat,len); + simclick_simstate simstate; + simstate.curtime = GetSimTime(); + //fprintf(stderr,"Sending packet up to click...\n"); + simclick_click_send(clickinst_,&simstate,ifid,clicktype,data,len,&simpinfo); + delete data; + data = 0; + } + else { + fprintf(stderr,"No click upcall set!\n"); + } +} + +Packet* +ClickClassifier::MakeRawPacket(int type,int ifid,const unsigned char* data, + int len,simclick_simpacketinfo* pinfo){ + Packet* pkt = Packet::alloc(len); + /* + * Shovel raw data into packet + */ + hdr_raw* rhdr = hdr_raw::access(pkt); + rhdr->subtype = GetNSSubtype(type); + unsigned char* pdat = pkt->accessdata(); + memcpy(pdat,data,len); + + /* + * Set some of the packet header stuff ns-2 wants + */ + struct hdr_cmn* chdr = HDR_CMN(pkt); + chdr->iface() = ifid; + chdr->ptype() = PT_RAW; + chdr->size() = len; + if (pinfo->id >= 0) { + chdr->uid() = pinfo->id; + } + else { + chdr->uid() = Agent::getnextuid(); + } + chdr->xmit_failure_ = LinkLayerFailedCallback; + chdr->xmit_failure_data_ = (void*)this; + + hdr_ip* iphdr = hdr_ip::access(pkt); + iphdr->flowid() = 0; + if (pinfo->fid >= 0) { + iphdr->flowid() = pinfo->fid; + } + + /* + * A packet coming in from click on the kernel tap device is + * considered to be going up into the node, on any other device + * going down out of it. + */ + if (ExtRouter::IFID_KERNELTAP == ifid) { + chdr->direction() = hdr_cmn::UP; + } + else { + chdr->direction() = hdr_cmn::DOWN; + // Going out to a network adapter, and we're already + // ethernet encapsulated. The ns-2 interface code will + // tack on ethernet header overhead as well, so we subtract + // it out of our simulated size here to avoid actual packet + // size inflation + if (hdr_raw::ETHERNET == rhdr->subtype) { + chdr->size() -= NS_ETHER_HEADER_SIZE; + } + } + + // If we've got ethernet encapsulation, translate mac address + // to ns address. Otherwise we're SOL. + struct hdr_mac* mhdr = HDR_MAC(pkt); + if (hdr_raw::ETHERNET == rhdr->subtype) { + MACAddr dmac(data + NS_ETHER_OFFSET_DADDR); + MACAddr smac(data + NS_ETHER_OFFSET_SADDR); + if (dmac.is_broadcast()) { + mhdr->macDA_ = MAC_BROADCAST; + } + else { + mhdr->macDA_ = global_macmap_[dmac]; + //fprintf(stderr,"XXX using real MAC: %s -> %d\n",dmac.to_string().c_str(),mhdr->macDA_); + } + mhdr->macSA_ = global_macmap_[smac]; + chdr->next_hop() = mhdr->macDA_; + chdr->prev_hop_ = mhdr->macSA_; + } + else { + //fprintf(stderr,"XXX using broadcast mac XXX\n"); + mhdr->macDA_ = MAC_BROADCAST; + } + + // Got an IP packet? Must have come from click, and therefore + // the next hop is us. + if ((ExtRouter::IFID_KERNELTAP == ifid) && (hdr_raw::IP == rhdr->subtype)) { + chdr->next_hop() = nodeaddr_; + } + + return pkt; +} + +struct timeval +ClickClassifier::GetSimTime() { + struct timeval curtime; + double ns2time = Scheduler::instance().clock(); + double fracp,intp; + fracp = modf(ns2time,&intp); + curtime.tv_sec = intp; + curtime.tv_usec = (fracp * 1.0e6 + 0.5); + return curtime; +} diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/classifier/classifier-click.h ns-2.1b9/classifier/classifier-click.h --- ns-2.1b9.orig/classifier/classifier-click.h Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/classifier/classifier-click.h Tue Sep 10 23:28:00 2002 @@ -0,0 +1,143 @@ +/* + * + * This might not seem like a regular classifier, and it isn't. + * It essentially has a fixed interface ID which it sends along + * with its packet to the ClickNode it lives on, the idea being + * that the Click subsystem will be the thing which actually + * does the classifying, not the classifier. + * + * $Header: /srl/dirkcvs/nsclick/ns-2.1b9/classifier/classifier-click.h,v 1.2 2002/09/07 03:19:05 neufeldm Exp $ + */ + +/***************************************************************************** + * Copyright 2002, Univerity of Colorado at Boulder. * + * * + * All Rights Reserved * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose other than its incorporation into a * + * commercial product is hereby granted without fee, provided that the * + * above copyright notice appear in all copies and that both that * + * copyright notice and this permission notice appear in supporting * + * documentation, and that the name of the University not be used in * + * advertising or publicity pertaining to distribution of the software * + * without specific, written prior permission. * + * * + * UNIVERSITY OF COLORADO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS * + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * + * FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE UNIVERSITY * + * OF COLORADO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL * + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA * + * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * + * PERFORMANCE OF THIS SOFTWARE. * + * * + ****************************************************************************/ + +#ifndef ns_classifier_click_h +#define ns_classifier_click_h + +#include "object.h" + +class Packet; + + +class ClickEvent : public Event { + public: + simclick_click clickinst_; + // Store an extra copy of the call time in sec/usec format. + // This is to sidestep some roundoff errors which occured + // when going back and forth between sec/usec and doubles. + struct timeval when_; +}; + +class ClickEventHandler : public Handler { + public: + virtual void handle(Event* event); +}; + +class MACAddr { + public: + MACAddr() { + memset(macaddr_,0,6); + } + explicit MACAddr(const string straddr) { + sscanf(straddr.c_str(), "%02X:%02X:%02X:%02X:%02X:%02X", &macaddr_[0], + &macaddr_[1], &macaddr_[2], &macaddr_[3], &macaddr_[4], + &macaddr_[5]); + } + explicit MACAddr(const unsigned char* rawaddr) { + memcpy(macaddr_,rawaddr,6); + } + bool operator==(const MACAddr& rhs) const { + return(0 == memcmp(macaddr_,rhs.macaddr_,6)); + } + struct hash { + size_t operator()(const MACAddr& x) const { + // Probably not much of a hash function, but it + // should do for now. + return ((x.macaddr_[2] << 3) + (x.macaddr_[3] << 2) + + (x.macaddr_[4] << 1) + (x.macaddr_[5])); + } + }; + + bool is_broadcast() { + for (int i=0;i<6;i++) { + if (macaddr_[i] != 0xff) { + return false; + } + } + return true; + } + + string to_string() { + char tmp[64]; + sprintf(tmp, "%02X:%02X:%02X:%02X:%02X:%02X", macaddr_[0], + macaddr_[1], macaddr_[2], macaddr_[3], macaddr_[4], + macaddr_[5]); + + return string(tmp); + } + unsigned char macaddr_[6]; +}; + +class ClickClassifier : public ExtClassifier,public ExtRouter { + public: + ClickClassifier(); + virtual ~ClickClassifier(); + virtual int command(int argc, const char*const* argv); + + /* + * Stuff to handle click requests + */ + public: + virtual int send_to_if(int ifid,int type,const unsigned char* data, + int len,simclick_simpacketinfo* pinfo); + ClickEventHandler cevhandler_; + + // ExtRouter method + virtual int route(Packet* p); + + string GetIPAddr(int ifid); + string GetMACAddr(int ifid); + string GetNodeName(); + int IFReady(int ifid); + simclick_click GetClickinst() { return clickinst_; } + static void LinkLayerFailedCallback(Packet* p, void* arg); + void LinkLayerFailed(Packet* p); + protected: + int GetNSSubtype(int clicktype); + int GetClickPacketType(int nssubtype); + struct timeval GetSimTime(); + Packet* MakeRawPacket(int type,int ifid,const unsigned char* data,int len, + simclick_simpacketinfo* pinfo); + simclick_click clickinst_; + hash_map ifipaddrs_; + hash_map ifmacaddrs_; + static hash_map global_macmap_; + static hash_map global_ipmap_; + string nodename_; + int nodeaddr_; +}; + +#endif diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/classifier/classifier-ext.cc ns-2.1b9/classifier/classifier-ext.cc --- ns-2.1b9.orig/classifier/classifier-ext.cc Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/classifier/classifier-ext.cc Tue Sep 10 23:28:00 2002 @@ -0,0 +1,162 @@ +/* + * classifier-ext.cc + * Base external router classifier + * + * $Header: /srl/dirkcvs/nsclick/ns-2.1b9/classifier/classifier-ext.cc,v 1.1 2002/06/10 19:22:59 neufeldm Exp $ + */ + +/***************************************************************************** + * Copyright 2002, Univerity of Colorado at Boulder. * + * * + * All Rights Reserved * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose other than its incorporation into a * + * commercial product is hereby granted without fee, provided that the * + * above copyright notice appear in all copies and that both that * + * copyright notice and this permission notice appear in supporting * + * documentation, and that the name of the University not be used in * + * advertising or publicity pertaining to distribution of the software * + * without specific, written prior permission. * + * * + * UNIVERSITY OF COLORADO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS * + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * + * FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE UNIVERSITY * + * OF COLORADO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL * + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA * + * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * + * PERFORMANCE OF THIS SOFTWARE. * + * * + ****************************************************************************/ + +#include +#include "config.h" +#include "packet.h" +#include "ip.h" +#include "extrouter.h" +#include "classifier.h" +#include "classifier-hash.h" +#include "classifier-ext.h" + + +static class ExtClassifierClass : public TclClass { +public: + ExtClassifierClass() : TclClass("Classifier/Ext") {} + TclObject* create(int, const char*const*) { + return (new ExtClassifier()); + } +} class_ext_classifier; + + +ExtClassifier::ExtClassifier() { + extrouter_ = NULL; +} + +ExtClassifier::~ExtClassifier() { +} + +int ExtClassifier::command(int argc, const char*const* argv) { + int result = TCL_OK; + Tcl& tcl = Tcl::instance(); + + result = Classifier::command(argc,argv); + return result; +} + +void ExtClassifier::recv(Packet* p, Handler* h) { + /* + * Use the interface and direction to decide what to do. If the + * packet is going down and came from an agent, it needs to + * go to the external router for processing. If coming up + * from the external router it needs to be sent to the appropriate + * local agent for processing. Otherwise, it just goes either down + * to the ns network interface or up to the external router. + */ + struct hdr_cmn* hdr = HDR_CMN(p); + int extid = hdr->iface(); + if (hdr_cmn::DOWN == hdr->direction()) { + if (ExtRouter::IFID_KERNELTAP == extid) { + /* + * Packet came from an agent - needs to go to the external router + */ + //fprintf(stderr,"To external router\n"); + if (NULL != extrouter_) { + extrouter_->route(p); + } + else { + fprintf(stderr,"No external router set!\n"); + } + } + else { + /* + * Packet came from the external router - needs to go to the net + */ + int cl = classify(p); + if ((cl >= 0) && (cl <= maxslot_)) { + NsObject* target = NULL; + target = slot_[cl]; + if (NULL == target) { + /* + * "Drop" the packet + */ + //puts("Dropping the packet"); + Packet::free(p); + } + else { + //puts("Sending packet out!!!"); + target->recv(p,h); + } + } + else { + fprintf(stderr,"Invalid slot: %d maxslot is %d\n",cl,maxslot_); + } + } + } + else if (hdr_cmn::UP == hdr->direction()) { + if (ExtRouter::IFID_KERNELTAP == extid) { + /* + * Packet came from the external router - needs to go to an agent. + */ + NsObject* target = NULL; + target = slot_[0]; + if (NULL == target) { + /* + * "Drop" the packet + */ + //fprintf(stderr,"Dropping the packet\n"); + Packet::free(p); + } + else { + //fprintf(stderr,"Packet going to agent\n"); + target->recv(p,h); + } + + //fprintf(stderr,"Hey! Send packets to agents!\n"); + } + else { + /* + * Packet came from the net - needs to go to the external router + */ + if (NULL != extrouter_) { + extrouter_->route(p); + } + } + } + else { + fprintf(stderr,"No packet direction set..."); + } +} + +int +ExtClassifier::classify(Packet* p) { + struct hdr_cmn* hdr = HDR_CMN(p); + int extid = hdr->iface(); + + /* + * Simple mapping between extid and slot number. + * No real reason to make things more complicated right now. + */ + int slot = extid; + return slot; +} diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/classifier/classifier-ext.h ns-2.1b9/classifier/classifier-ext.h --- ns-2.1b9.orig/classifier/classifier-ext.h Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/classifier/classifier-ext.h Tue Sep 10 23:28:00 2002 @@ -0,0 +1,59 @@ +/* + * + * This classifier is intended for use with external routers bolted + * on to ns-2, e.g. Click. It uses a combination of the packet direction + * and interface ID to decide where to send stuff. + * + * $Header: /srl/dirkcvs/nsclick/ns-2.1b9/classifier/classifier-ext.h,v 1.1 2002/06/10 19:22:59 neufeldm Exp $ + */ + +/***************************************************************************** + * Copyright 2002, Univerity of Colorado at Boulder. * + * * + * All Rights Reserved * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose other than its incorporation into a * + * commercial product is hereby granted without fee, provided that the * + * above copyright notice appear in all copies and that both that * + * copyright notice and this permission notice appear in supporting * + * documentation, and that the name of the University not be used in * + * advertising or publicity pertaining to distribution of the software * + * without specific, written prior permission. * + * * + * UNIVERSITY OF COLORADO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS * + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * + * FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE UNIVERSITY * + * OF COLORADO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL * + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA * + * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * + * PERFORMANCE OF THIS SOFTWARE. * + * * + ****************************************************************************/ + +#ifndef ns_classifier_ext_h +#define ns_classifier_ext_h + +#include "object.h" + +class Packet; + +class ExtClassifier : public Classifier { + public: + ExtClassifier(); + virtual ~ExtClassifier(); + + virtual void recv(Packet* p, Handler* h); + + void setExtRouter(ExtRouter* ext) {extrouter_ = ext;} + ExtRouter* getExtRouter() {return extrouter_;} + + virtual int classify(Packet*); + + protected: + virtual int command(int argc, const char*const* argv); + ExtRouter* extrouter_; +}; + +#endif diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/common/agent.h ns-2.1b9/common/agent.h --- ns-2.1b9.orig/common/agent.h Tue Sep 10 23:12:14 2002 +++ ns-2.1b9/common/agent.h Tue Sep 10 23:28:00 2002 @@ -98,6 +98,7 @@ inline nsaddr_t& daddr() { return dst_.addr_; } inline nsaddr_t& dport() { return dst_.port_; } void set_pkttype(packet_t pkttype) { type_ = pkttype; } + static int getnextuid() { return uidcnt_++; } protected: int command(int argc, const char*const* argv); diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/common/clicknode.cc ns-2.1b9/common/clicknode.cc --- ns-2.1b9.orig/common/clicknode.cc Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/common/clicknode.cc Tue Sep 10 23:28:00 2002 @@ -0,0 +1,134 @@ +/* + * clicknode.cc + * Base class for nsclick nodes. + * + * XXX Should probably move a bunch of the functionality in this + * class to a superclass, i.e. something called ExtNode, since a lot + * of this should work with most Ext routing stuff, not just click. + * + * $Header: /srl/dirkcvs/nsclick/ns-2.1b9/common/clicknode.cc,v 1.1 2002/06/10 19:23:01 neufeldm Exp $ + * + */ + +/***************************************************************************** + * Copyright 2002, Univerity of Colorado at Boulder. * + * * + * All Rights Reserved * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose other than its incorporation into a * + * commercial product is hereby granted without fee, provided that the * + * above copyright notice appear in all copies and that both that * + * copyright notice and this permission notice appear in supporting * + * documentation, and that the name of the University not be used in * + * advertising or publicity pertaining to distribution of the software * + * without specific, written prior permission. * + * * + * UNIVERSITY OF COLORADO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS * + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * + * FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE UNIVERSITY * + * OF COLORADO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL * + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA * + * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * + * PERFORMANCE OF THIS SOFTWARE. * + * * + ****************************************************************************/ + +#include +#include +#include +#include + +#include "connector.h" +#include "delay.h" +#include "packet.h" +#include "agent.h" +#include "rawpacket.h" +#include "random.h" +#include "trace.h" +#include "address.h" + +#include "arp.h" +#include "topography.h" +#include "ll.h" +#include "mac.h" +#include "propagation.h" +#include "mobilenode.h" +#include "phy.h" +#include "wired-phy.h" +#include "god.h" +#include "extrouter.h" +#include "extclickrouter.h" +#include +#include +#include "clicknode.h" + + +static class ClickNodeClass : public TclClass { +public: + ClickNodeClass() : TclClass("Node/MobileNode/ClickNode") {} + TclObject* create(int, const char*const*) { + ClickNode* thenode = new ClickNode; + if (!thenode) { + return NULL; + } + + /* + * Do post-constructor initialization. + */ + int result = thenode->cinit(); + if (0 > result) { + delete thenode; + thenode = NULL; + } + + return thenode; + } +} class_clicknode; + + +ClickNode::ClickNode(void) { +} + +int +ClickNode::cinit() { + int result = 0; + return result; +} + +int +ClickNode::command(int argc, const char*const* argv) +{ + Tcl& tcl = Tcl::instance(); + if (2 == argc) { + } + else if (3 == argc) { + if(strcmp(argv[1], "addif") == 0) { + Phy* phyp = (Phy*)TclObject::lookup(argv[2]); + if(phyp == 0) { + return TCL_ERROR; + } + phyp->insertnode(&ifhead_); + phyp->setnode(this); + return TCL_OK; + } + } + else if (4 == argc) { + } + else if (5 == argc) { + } + + return MobileNode::command(argc, argv); +} + + +/* ====================================================================== + Other class functions + ====================================================================== */ +void +ClickNode::dump(void) { + printf("Dumping a clicknode...\n"); +} + + diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/common/clicknode.h ns-2.1b9/common/clicknode.h --- ns-2.1b9.orig/common/clicknode.h Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/common/clicknode.h Tue Sep 10 23:28:00 2002 @@ -0,0 +1,66 @@ +/* + * clicknode.h + * + * $Header: /srl/dirkcvs/nsclick/ns-2.1b9/common/clicknode.h,v 1.1 2002/06/10 19:23:01 neufeldm Exp $ + * + */ + +/***************************************************************************** + * Copyright 2002, Univerity of Colorado at Boulder. * + * * + * All Rights Reserved * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose other than its incorporation into a * + * commercial product is hereby granted without fee, provided that the * + * above copyright notice appear in all copies and that both that * + * copyright notice and this permission notice appear in supporting * + * documentation, and that the name of the University not be used in * + * advertising or publicity pertaining to distribution of the software * + * without specific, written prior permission. * + * * + * UNIVERSITY OF COLORADO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS * + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * + * FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE UNIVERSITY * + * OF COLORADO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL * + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA * + * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * + * PERFORMANCE OF THIS SOFTWARE. * + * * + ****************************************************************************/ + +#ifndef __ns_clicknode_h__ +#define __ns_clicknode_h__ + +#include "object.h" +#include "trace.h" +#include "lib/bsd-list.h" +#include "node.h" + +class ClickNode : public MobileNode +{ + +public: + ClickNode(); + virtual int cinit(); + virtual int command(int argc, const char*const* argv); + inline ClickNode* nextnode() { return link_.le_next; } + + void dump(void); + +private: + + /* + * A global list of click nodes + */ + LIST_ENTRY(ClickNode) link_; + + /* + * Trace Target + */ + Trace* log_target_; + +}; + +#endif diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/common/packet.h ns-2.1b9/common/packet.h --- ns-2.1b9.orig/common/packet.h Tue Sep 10 23:12:14 2002 +++ ns-2.1b9/common/packet.h Tue Sep 10 23:28:00 2002 @@ -146,6 +146,8 @@ // Pragmatic General Multicast PT_PGM, #endif + // Raw data packets + PT_RAW, // insert new packet types here PT_NTYPE // This MUST be the LAST one @@ -226,6 +228,9 @@ // for PGM name_[PT_PGM] = "PGM"; #endif + + // Raw packets + name_[PT_RAW] = "raw"; name_[PT_NTYPE]= "undefined"; } diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/common/rawpacket.cc ns-2.1b9/common/rawpacket.cc --- ns-2.1b9.orig/common/rawpacket.cc Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/common/rawpacket.cc Tue Sep 10 23:28:00 2002 @@ -0,0 +1,172 @@ +/* + * rawpacket.cc + * Main file for the raw packet type + * + * $Header: /srl/dirkcvs/nsclick/ns-2.1b9/common/rawpacket.cc,v 1.1 2002/06/13 01:35:06 neufeldm Exp $ + * + */ + +/***************************************************************************** + * Copyright 2002, Univerity of Colorado at Boulder. * + * * + * All Rights Reserved * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose other than its incorporation into a * + * commercial product is hereby granted without fee, provided that the * + * above copyright notice appear in all copies and that both that * + * copyright notice and this permission notice appear in supporting * + * documentation, and that the name of the University not be used in * + * advertising or publicity pertaining to distribution of the software * + * without specific, written prior permission. * + * * + * UNIVERSITY OF COLORADO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS * + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * + * FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE UNIVERSITY * + * OF COLORADO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL * + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA * + * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * + * PERFORMANCE OF THIS SOFTWARE. * + * * + ****************************************************************************/ + +#include +#include "agent.h" +#include "packet.h" +#include "rawpacket.h" +#include "extrouter.h" +extern "C" { +#include +} +int hdr_raw::offset_; + +/* + * RawHeaderClass based on the ping example in the ns-2 tutorial. + */ +static class RawHeaderClass : public PacketHeaderClass { +public: + RawHeaderClass() : PacketHeaderClass("PacketHeader/Raw",sizeof(hdr_raw)){ + bind_offset(&hdr_raw::offset_); + } +} class_rawhdr; + +static class RawClass : public TclClass { +public: + RawClass() : TclClass("Agent/Raw") {} + TclObject* create(int,const char*const*) { + return (new RawAgent()); + } +} class_raw; + + +RawAgent::RawAgent() : Agent(PT_RAW) { + ipseq_ = 0; +} + +int RawAgent::command(int argc,const char*const* argv) { + if (argc == 2) { + if (strcmp(argv[1], "send") == 0) { + char* testmsg = "Howdy Howdy Howdy\n"; + send_udp_str(srcip_,srcport_,destip_,destport_,testmsg); + return (TCL_OK); + } + } + else if (argc == 3) { + if (strcmp(argv[1], "send") == 0) { + const char* testmsg = argv[2]; + send_udp_str(srcip_,srcport_,destip_,destport_,testmsg); + return (TCL_OK); + } + if (strcmp(argv[1], "set-srcip") == 0) { + srcip_ = libnet_name_resolve((unsigned char*)argv[2],0); + return (TCL_OK); + } + if (strcmp(argv[1], "set-srcport") == 0) { + srcport_ = atoi(argv[2]); + return (TCL_OK); + } + if (strcmp(argv[1], "set-destip") == 0) { + destip_ = libnet_name_resolve((unsigned char*)argv[2],0); + return (TCL_OK); + } + if (strcmp(argv[1], "set-destport") == 0) { + destport_ = atoi(argv[2]); + return (TCL_OK); + } + } + else if (argc == 7) { + if (strcmp(argv[1],"send-udp") == 0) { + // saddr,sport,daddr,dport,payload + // For right now only text strings can be sent + // as payload. + u_long saddr = libnet_name_resolve((unsigned char*)argv[2],0); + u_short sport = atoi(argv[3]); + u_long daddr = libnet_name_resolve((unsigned char*)argv[4],0); + u_short dport = atoi(argv[5]); + send_udp_str(saddr,sport,daddr,dport,argv[6]); + // return TCL_OK, so the calling function knows that the + // command has been processed + return (TCL_OK); + } + } + + // If the command hasn't been processed by RawAgent()::command, + // call the command() function for the base class + return (Agent::command(argc, argv)); +} + +void +RawAgent::sendmsg(int nbytes, const char *flags) { + // Make a string full of 'A's and use it for the payload + char* stuff = new char[nbytes]; + memset(stuff,'A',nbytes); + send_udp(srcip_,srcport_,destip_,destport_,stuff,nbytes); + delete[] stuff; + stuff = 0; +} + +void +RawAgent::send_udp_str(u_long saddr,u_short sport,u_long daddr,u_short dport, + const char* payload) { + send_udp(saddr,sport,daddr,dport,payload,strlen(payload)); +} + +void +RawAgent::send_udp(u_long saddr,u_short sport,u_long daddr,u_short dport, + const char* payload,int paylen) { + int packetlen = paylen + LIBNET_IP_H + LIBNET_UDP_H; + Packet* pkt = allocpkt(packetlen); + hdr_cmn* hcmn = HDR_CMN(pkt); + hcmn->direction() = hdr_cmn::DOWN; + hcmn->iface() = ExtRouter::IFID_KERNELTAP; + hcmn->ptype() = PT_RAW; + hcmn->size() = packetlen; + // Access the raw header for the new packet: + hdr_raw* hdr = hdr_raw::access(pkt); + hdr->subtype = hdr_raw::IP; + unsigned char* pdat = pkt->accessdata(); + memset(pdat,0,packetlen); + libnet_build_ip(packetlen-LIBNET_IP_H,IPTOS_LOWDELAY,ipseq_,0,255, + IPPROTO_UDP,saddr,daddr,NULL,0,pdat); + libnet_build_udp(sport,dport,(unsigned char*)payload,paylen,pdat+LIBNET_IP_H); + libnet_do_checksum(pdat,IPPROTO_UDP,LIBNET_UDP_H+paylen); + libnet_do_checksum(pdat,IPPROTO_IP,LIBNET_IP_H); + // Send the packet + send(pkt, 0); + ipseq_++; +} + +void RawAgent::recv(Packet* pkt, Handler*) +{ + // Access the raw header for the received packet + hdr_raw* hdr = hdr_raw::access(pkt); + + if (hdr_raw::PSTRING == hdr->subtype) { + unsigned char* pdat = pkt->accessdata(); + unsigned int len = pdat[0]; + + // Shovel the string to the screen... + fwrite(pdat+1,sizeof(char),len,stdout); + } +} diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/common/rawpacket.h ns-2.1b9/common/rawpacket.h --- ns-2.1b9.orig/common/rawpacket.h Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/common/rawpacket.h Tue Sep 10 23:28:00 2002 @@ -0,0 +1,82 @@ +/* + * rawpacket.h + * + * $Header: /srl/dirkcvs/nsclick/ns-2.1b9/common/rawpacket.h,v 1.1 2002/06/13 01:35:06 neufeldm Exp $ + * + */ + +/***************************************************************************** + * Copyright 2002, Univerity of Colorado at Boulder. * + * * + * All Rights Reserved * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose other than its incorporation into a * + * commercial product is hereby granted without fee, provided that the * + * above copyright notice appear in all copies and that both that * + * copyright notice and this permission notice appear in supporting * + * documentation, and that the name of the University not be used in * + * advertising or publicity pertaining to distribution of the software * + * without specific, written prior permission. * + * * + * UNIVERSITY OF COLORADO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS * + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * + * FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE UNIVERSITY * + * OF COLORADO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL * + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA * + * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * + * PERFORMANCE OF THIS SOFTWARE. * + * * + ****************************************************************************/ + +/* + * Raw packet type. + */ +struct hdr_raw { + /* + * This indicates the actual type of the stuff in the + * packet. The actual packet stuff is pointed to by + * the data thing. + */ + int subtype; + + /* + * Not many raw subtypes defined so far. + */ + enum { + NONE, + PSTRING, + IP, + ETHERNET, + }; + + /* Packet header access functions */ + static int offset_; + inline static int& offset() { return offset_; } + inline static hdr_raw* access(const Packet* p) { + return (hdr_raw*) p->access(offset_); + } +}; + +/* + * The base RawAgent class + */ +class RawAgent : public Agent { + public: + RawAgent(); + int command(int argc,const char*const* argv); + void recv(Packet*, Handler*); + virtual void sendmsg(int nbytes, const char *flags = 0); + protected: + void send_udp_str(u_long saddr,u_short sport,u_long daddr,u_short dport, + const char* payload); + void send_udp(u_long saddr,u_short sport,u_long daddr,u_short dport, + const char* payload,int paylen); + + u_int16_t ipseq_; + u_long srcip_; + u_short srcport_; + u_long destip_; + u_short destport_; +}; diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/conf/configure.in.click ns-2.1b9/conf/configure.in.click --- ns-2.1b9.orig/conf/configure.in.click Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/conf/configure.in.click Tue Sep 10 23:28:00 2002 @@ -0,0 +1,31 @@ +dnl autoconf rules to find click - copied from dmalloc example +dnl $Header: /srl/dirkcvs/nsclick/ns-2.1b9/conf/configure.in.click,v 1.1 2002/06/13 01:33:48 neufeldm Exp $ + +AC_ARG_WITH(click, --with-click=path specify a pathname for the click modular router, d="$withval", d="") + +CLICK_VERS=1.2.4 + +CLICK_PATH="$PWD/../click \ + $PWD/../../click \ + $PWD/../click-$CLICK_VERS \ + $PWD/../../click-$CLICK_VERS \ + $PWD/../click/include/click \ + $PWD/../../click/include/click \ + $PWD/../click-$CLICK_VERS/include/click \ + $PWD/../../click-$CLICK_VERS/include/click \ + $PWD/../click/simclick \ + $PWD/../../click/simclick \ + $PWD/../click-$CLICK_VERS/simclick \ + $PWD/../../click-$CLICK_VERS/simclick \ + " +CLICK_PATH_D="$d \ + $d/simclick \ + $d/include/click \ + " + +NS_BEGIN_PACKAGE(click) +NS_CHECK_HEADER_PATH(simclick.h,$CLICK_PATH,$d,$CLICK_PATH_D,V_HEADER_CLICK,click) +NS_CHECK_LIB_PATH(simclick,$CLICK_PATH,$d,$CLICK_PATH_D,V_LIB_CLICK,click) +NS_END_PACKAGE(click,yes) + + diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/conf/configure.in.libnet ns-2.1b9/conf/configure.in.libnet --- ns-2.1b9.orig/conf/configure.in.libnet Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/conf/configure.in.libnet Tue Sep 10 23:28:00 2002 @@ -0,0 +1,33 @@ +dnl autoconf rules to find libnet - copied from dmalloc example +dnl $Header: /srl/dirkcvs/nsclick/ns-2.1b9/conf/configure.in.libnet,v 1.1 2002/06/13 01:33:48 neufeldm Exp $ + +AC_ARG_WITH(libnet, --with-libnet=path specify a pathname for libnet, d="$withval", d="") + +LIBNET_VERS=1.0.2a + +LIBNET_PATH="$PWD/../libnet \ + $PWD/../../libnet \ + $PWD/../Libnet-$LIBNET_VERS \ + $PWD/../../Libnet-$LIBNET_VERS \ + $PWD/../libnet/include \ + $PWD/../../libnet/include \ + $PWD/../Libnet-$LIBNET_VERS/include \ + $PWD/../../Libnet-$LIBNET_VERS/include \ + $PWD/../libnet/lib \ + $PWD/../../libnet/lib \ + $PWD/../Libnet-$LIBNET_VERS/lib \ + $PWD/../../Libnet-$LIBNET_VERS/lib \ + " +LIBNET_PATH_D="$d \ + $d/include \ + $d/lib \ + " + +NS_BEGIN_PACKAGE(libnet) +NS_CHECK_HEADER_PATH(libnet.h,$LIBNET_PATH,$d,$LIBNET_PATH_D,V_HEADER_LIBNET,libnet) +NS_CHECK_LIB_PATH(net,$LIBNET_PATH,$d,$LIBNET_PATH_D,V_LIB_LIBNET,libnet) +NS_CHECK_ANY_PATH(libnet-config,$LIBNET_PATH,$d,$LIBNET_PATH_D,LIBNETCONFIG,libnet) +V_DEFINES="`$LIBNETCONFIG/libnet-config --defines` $V_DEFINES" +NS_END_PACKAGE(libnet,yes) + + diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/configure.in ns-2.1b9/configure.in --- ns-2.1b9.orig/configure.in Tue Sep 10 23:12:14 2002 +++ ns-2.1b9/configure.in Tue Sep 10 23:27:59 2002 @@ -22,6 +22,8 @@ builtin(include, ./conf/configure.in.x11) builtin(include, ./conf/configure.in.tcldebug) builtin(include, ./conf/configure.in.dmalloc) +builtin(include, ./conf/configure.in.click) +builtin(include, ./conf/configure.in.libnet) default_classinstvar=yes builtin(include, ./conf/configure.in.debugopts) Binary files ns-2.1b9.orig/emulate/support/nrgarp and ns-2.1b9/emulate/support/nrgarp differ diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/mac/ll-ext.cc ns-2.1b9/mac/ll-ext.cc --- ns-2.1b9.orig/mac/ll-ext.cc Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/mac/ll-ext.cc Tue Sep 10 23:28:02 2002 @@ -0,0 +1,146 @@ +/* + * ll-ext.cc + * This is a special link layer which explicitly notifies the attached + * queue when it becomes free. + * + * $Header: /srl/dirkcvs/nsclick/ns-2.1b9/mac/ll-ext.cc,v 1.2 2002/09/07 03:19:28 neufeldm Exp $ + */ + +/***************************************************************************** + * Copyright 2002, Univerity of Colorado at Boulder. * + * * + * All Rights Reserved * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose other than its incorporation into a * + * commercial product is hereby granted without fee, provided that the * + * above copyright notice appear in all copies and that both that * + * copyright notice and this permission notice appear in supporting * + * documentation, and that the name of the University not be used in * + * advertising or publicity pertaining to distribution of the software * + * without specific, written prior permission. * + * * + * UNIVERSITY OF COLORADO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS * + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * + * FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE UNIVERSITY * + * OF COLORADO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL * + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA * + * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * + * PERFORMANCE OF THIS SOFTWARE. * + * * + ****************************************************************************/ + +// XXX This is really a click link layer now - not just ext... + +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "packet.h" +#include "ip.h" +#include "mac.h" +#include "classifier.h" +//#include "classifier-hash.h" +#include "scheduler.h" +#include "ll.h" +#include +#include "ll-ext.h" +#include "packet.h" +#include "extrouter.h" +#include "classifier.h" +#include "classifier-ext.h" +#include "classifier-click.h" +#include "clickqueue.h" + +static class LLExtClass : public TclClass { +public: + LLExtClass() : TclClass("LL/Ext") {} + TclObject* create(int, const char*const*) { + return (new LLExt()); + } +} class_ll_ext; + +void +LLExtEventHandler::handle(Event* event) { + // XXX dangerous downcast - should use RTTI + LLExtEvent* myevent = (LLExtEvent*) event; + myevent->llext->setpending(0); + delete myevent; +} + + +LLExt::LLExt() { + extid_ = -1; + macDA_ = -1; + packetpending_ = 0; +} + +LLExt::~LLExt() { +} + +int LLExt::command(int argc, const char*const* argv) { + Tcl& tcl = Tcl::instance(); + if(argc == 2) { + } + else if (argc == 3) { + if (strcmp("setid",argv[1]) == 0) { + extid_ = atoi(argv[2]); + return TCL_OK; + } + } + else if (argc == 4) { + } + + return LL::command(argc,argv); +} + +void LLExt::recv(Packet* p, Handler* h) { + /* + * Tag the packet and then defer to standard link layer handling. + */ + struct hdr_cmn* hdr = HDR_CMN(p); + hdr->iface() = extid_; + // printf("ll = %d, ifid = %d\n",(int)this,hdr->iface()); + LL::recv(p,h); +} + +void LLExt::sendDown(Packet* p) { + // Someone decided that it would be A Good Thing to overlay + // the 802.11 MAC packet info on top of the regular MAC packet info. + // I'm sure it saved them a few bytes, and it was just one of + // many, many violations of good programming practice that you + // get to see in ns-2 every day. In any case, we need to fix + // the source and destination addresses here by accessing the + // MAC object itself. + struct hdr_mac* mhdr = HDR_MAC(p); + int macdst = mhdr->macDA(); + int macsrc = mhdr->macSA(); + memset(mhdr,0,sizeof(struct hdr_mac)); + mac_->hdr_dst((char*)mhdr,macdst); + mac_->hdr_src((char*)mhdr,macsrc); + + // Bleah. Send the packet down, mark ourself as being busy, and then + // schedule an event to mark ourselves unbusy. + packetpending_ = 1; + LL::sendDown(p); + LLExtEvent* llev = new LLExtEvent(); + llev->llext = this; + Scheduler& s = Scheduler::instance(); + s.schedule(&evhandle_,llev,delay_); +} + +int LLExt::ready() { + ClickQueue* pcq = (ClickQueue*) ifq_; + if (pcq) { + return (!packetpending_ && pcq->ready()); + } + + // No ClickQueue? Then we're always ready. + return 1; +} diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/mac/ll-ext.h ns-2.1b9/mac/ll-ext.h --- ns-2.1b9.orig/mac/ll-ext.h Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/mac/ll-ext.h Tue Sep 10 23:28:02 2002 @@ -0,0 +1,76 @@ +/* + * ll-ext.h + * + * Much like the multicast routing system, ext routers needs to know what + * interface packets come in from. However, the multicast interface + * thing doesn't quite do what we need it to, so you get what + * we've got here. + * + * $Header: /srl/dirkcvs/nsclick/ns-2.1b9/mac/ll-ext.h,v 1.1 2002/06/10 19:23:03 neufeldm Exp $ + */ + +/***************************************************************************** + * Copyright 2002, Univerity of Colorado at Boulder. * + * * + * All Rights Reserved * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose other than its incorporation into a * + * commercial product is hereby granted without fee, provided that the * + * above copyright notice appear in all copies and that both that * + * copyright notice and this permission notice appear in supporting * + * documentation, and that the name of the University not be used in * + * advertising or publicity pertaining to distribution of the software * + * without specific, written prior permission. * + * * + * UNIVERSITY OF COLORADO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS * + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * + * FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE UNIVERSITY * + * OF COLORADO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL * + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA * + * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * + * PERFORMANCE OF THIS SOFTWARE. * + * * + ****************************************************************************/ + +#ifndef ns_ll_ext_h +#define ns_ll_ext_h + +#include "object.h" + +class Packet; +class LLExt; + +class LLExtEvent : public Event { + public: + LLExt* llext; +}; + +class LLExtEventHandler : public Handler { + public: + virtual void handle(Event* event); +}; + +class LLExt : public LL { + public: + LLExt(); + virtual ~LLExt(); + + virtual void recv(Packet* p, Handler* h); + virtual void sendDown(Packet* p); + + void setExtID(int newid) {extid_ = newid;} + int getExtID() {return extid_;} + int ready(); + int getpending() { return packetpending_; } + void setpending(int newpend) { packetpending_ = newpend; }; + + protected: + virtual int command(int argc, const char*const* argv); + int extid_; + int packetpending_; + LLExtEventHandler evhandle_; +}; + +#endif diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/mac/ll.cc ns-2.1b9/mac/ll.cc --- ns-2.1b9.orig/mac/ll.cc Tue Sep 10 23:12:15 2002 +++ ns-2.1b9/mac/ll.cc Tue Sep 10 23:28:02 2002 @@ -201,6 +201,9 @@ /* Assuming arptable is present, send query */ if (arptable_) { tx = arptable_->arpresolve(dst, p, this); + break; + } + if (PT_RAW == ch->ptype()) { break; } //if (varp_) { diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/queue/clickqueue.cc ns-2.1b9/queue/clickqueue.cc --- ns-2.1b9.orig/queue/clickqueue.cc Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/queue/clickqueue.cc Tue Sep 10 23:28:02 2002 @@ -0,0 +1,151 @@ +/* + * clickqueue.cc + * Special queue which runs the external Click router when it unblocks + * + */ + +/***************************************************************************** + * Copyright 2002, Univerity of Colorado at Boulder. * + * * + * All Rights Reserved * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose other than its incorporation into a * + * commercial product is hereby granted without fee, provided that the * + * above copyright notice appear in all copies and that both that * + * copyright notice and this permission notice appear in supporting * + * documentation, and that the name of the University not be used in * + * advertising or publicity pertaining to distribution of the software * + * without specific, written prior permission. * + * * + * UNIVERSITY OF COLORADO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS * + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * + * FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE UNIVERSITY * + * OF COLORADO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL * + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA * + * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * + * PERFORMANCE OF THIS SOFTWARE. * + * * + ****************************************************************************/ + +#ifndef lint +static const char rcsid[] = + "$Header: /srl/dirkcvs/nsclick/ns-2.1b9/queue/clickqueue.cc,v 1.1 2002/06/10 19:23:05 neufeldm Exp $"; +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "packet.h" +#include "extrouter.h" +#include "classifier.h" +#include "classifier-ext.h" +#include "classifier-click.h" +#include "clickqueue.h" + +static class ClickQueueClass : public TclClass { +public: + ClickQueueClass() : TclClass("Queue/ClickQueue") {} + TclObject* create(int, const char*const*) { + return (new ClickQueue); + } +} class_click_queue; + +int +ClickQueue::command(int argc, const char*const* argv) { + if (3 == argc) { + if (!strcmp(argv[1],"setclickclassifier")) { + cc_ = (ClickClassifier*)TclObject::lookup(argv[2]); + return TCL_OK; + } + } + return Queue::command(argc, argv); +} +/* + * drop-tail + */ +ClickQueue::ClickQueue() { + pq_ = new PacketQueue; + qlim_ = 1; + cc_ = 0; +} + +ClickQueue::~ClickQueue() { + delete pq_; +} + +int +ClickQueue::is_full() { + return (pq_->length() >= qlim_); +} + +int +ClickQueue::ready() { + return (!is_full() && !blocked()); +} + +void ClickQueue::enque(Packet* p) +{ + pq_->enque(p); + if (pq_->length() > qlim_) { + fprintf(stderr,"Hey!!! IFQ Overflow!!!\n"); + Packet *pp = pq_->deque(); + drop(pp); + } +} + +Packet* ClickQueue::deque() +{ + Packet* retval = pq_->deque(); + return retval; +} + +void ClickQueue::on_unblock() { + // + // Queue has space - run the external router + // and give it a chance to fill things up. + // + if (cc_) { + simclick_click clickinst = cc_->GetClickinst(); + Scheduler& s = Scheduler::instance(); + double dcurtime = s.clock(); + simclick_simstate curstate; + memset(&curstate,0,sizeof(curstate)); + double fracp, intp; + fracp = modf(dcurtime,&intp); + curstate.curtime.tv_sec = intp; + curstate.curtime.tv_usec = (fracp*1.0e6+0.5); + simclick_click_run(clickinst,&curstate); + } +} + +#if 0 +void ClickQueue::runclick() { + if (is_full()) { + return; + } + // + // Queue has space - run the external router + // and give it a chance to fill things up. + // + if (cc_) { + simclick_click clickinst = cc_->GetClickinst(); + Scheduler& s = Scheduler::instance(); + double dcurtime = s.clock(); + simclick_simstate curstate; + memset(&curstate,0,sizeof(curstate)); + double fracp, intp; + fracp = modf(dcurtime,&intp); + curstate.curtime.tv_sec = intp; + curstate.curtime.tv_usec = (fracp*1.0e6+0.5); + simclick_click_run(clickinst,&curstate); + } +} +#endif diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/queue/clickqueue.h ns-2.1b9/queue/clickqueue.h --- ns-2.1b9.orig/queue/clickqueue.h Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/queue/clickqueue.h Tue Sep 10 23:28:02 2002 @@ -0,0 +1,61 @@ +/* + * clickqueue.h + * Special queue which runs the external Click router when it unblocks + * + */ + +/***************************************************************************** + * Copyright 2002, Univerity of Colorado at Boulder. * + * * + * All Rights Reserved * + * * + * Permission to use, copy, modify, and distribute this software and its * + * documentation for any purpose other than its incorporation into a * + * commercial product is hereby granted without fee, provided that the * + * above copyright notice appear in all copies and that both that * + * copyright notice and this permission notice appear in supporting * + * documentation, and that the name of the University not be used in * + * advertising or publicity pertaining to distribution of the software * + * without specific, written prior permission. * + * * + * UNIVERSITY OF COLORADO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS * + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * + * FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE UNIVERSITY * + * OF COLORADO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL * + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA * + * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * + * PERFORMANCE OF THIS SOFTWARE. * + * * + ****************************************************************************/ + +#ifndef ns_clickqueue_h +#define ns_clickqueue_h + +#include +#include "queue.h" +#include "config.h" + +/* + * A degenerate queue designed to work with Click routers. Should only + * have 1 packet ever sitting in it since the queueing should be handled + * by Click. Also makes sure that simclick gets run whenever the queue + * empties and unblocks so that the polling simulated network driver + * will insert packets when it has them. + */ +class ClickQueue : public Queue { + public: + ClickQueue(); + ~ClickQueue(); + void enque(Packet*); + Packet* deque(); + + int is_full(); + int ready(); + protected: + int command(int argc, const char*const* argv); + ClickClassifier* cc_; + virtual void on_unblock(); +}; + +#endif diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/queue/queue.cc ns-2.1b9/queue/queue.cc --- ns-2.1b9.orig/queue/queue.cc Tue Sep 10 23:12:16 2002 +++ ns-2.1b9/queue/queue.cc Tue Sep 10 23:28:02 2002 @@ -130,12 +130,19 @@ if (p != 0) { target_->recv(p, &qh_); } else { - if (unblock_on_resume_) + if (unblock_on_resume_) { blocked_ = 0; - else + on_unblock(); + } + else { blocked_ = 1; + } } } + +void Queue::on_unblock() { + // Do nothing in base class +}; void Queue::reset() { diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/queue/queue.h ns-2.1b9/queue/queue.h --- ns-2.1b9.orig/queue/queue.h Tue Sep 10 23:12:16 2002 +++ ns-2.1b9/queue/queue.h Tue Sep 10 23:28:02 2002 @@ -145,6 +145,7 @@ * like DropTail and RED). */ double true_ave_; /* true long-term average queue size */ double total_time_; /* total time average queue size compute for */ + virtual void on_unblock(); }; #endif diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/routing/extclickrouter.cc ns-2.1b9/routing/extclickrouter.cc --- ns-2.1b9.orig/routing/extclickrouter.cc Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/routing/extclickrouter.cc Tue Sep 10 23:28:02 2002 @@ -0,0 +1,22 @@ +/* + * XXX Insert CU copyright stuff here... + * + * $Header: /srl/dirkcvs/nsclick/ns-2.1b9/routing/extclickrouter.cc,v 1.1 2002/06/10 19:23:06 neufeldm Exp $ + * + */ + +#include "packet.h" +#include "extrouter.h" +#include "extclickrouter.h" + +ExtClickRouter::ExtClickRouter() { +} + +ExtClickRouter::~ExtClickRouter() { +} + +int ExtClickRouter::recv(Packet* p) { + int result = 0; + + return result; +} diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/routing/extclickrouter.h ns-2.1b9/routing/extclickrouter.h --- ns-2.1b9.orig/routing/extclickrouter.h Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/routing/extclickrouter.h Tue Sep 10 23:28:02 2002 @@ -0,0 +1,29 @@ +/* + * XXX Insert CU copyright stuff here... + * + * $Header: /srl/dirkcvs/nsclick/ns-2.1b9/routing/extclickrouter.h,v 1.1 2002/06/10 19:23:06 neufeldm Exp $ + * + * This defines the interface used by all external raw packet routing + * modules bolted on to ns. + * + */ + +#ifndef __ns_extclickrouter_h__ +#define __ns_extclickrouter_h__ + +class ExtClickRouter +{ + + public: + ExtClickRouter(); + virtual ~ExtClickRouter(); + virtual int recv(Packet* p); + + void* SetClickRouterPtr(void* crtptr); + + private: + void* clickrouter_; + +}; + +#endif diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/routing/extrouter.cc ns-2.1b9/routing/extrouter.cc --- ns-2.1b9.orig/routing/extrouter.cc Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/routing/extrouter.cc Tue Sep 10 23:28:02 2002 @@ -0,0 +1,17 @@ +/* + * XXX Insert CU copyright stuff here... + * + * $Header: /srl/dirkcvs/nsclick/ns-2.1b9/routing/extrouter.cc,v 1.1 2002/06/10 19:23:07 neufeldm Exp $ + * + * This defines the interface used by all external raw packet routing + * modules bolted on to ns. + * + */ + +#include "packet.h" +#include "extrouter.h" + +// Just here so we get virtual destructors +ExtRouter::~ExtRouter() { +} + diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/routing/extrouter.h ns-2.1b9/routing/extrouter.h --- ns-2.1b9.orig/routing/extrouter.h Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/routing/extrouter.h Tue Sep 10 23:28:02 2002 @@ -0,0 +1,31 @@ +/* + * XXX Insert CU copyright stuff here... + * + * $Header: /srl/dirkcvs/nsclick/ns-2.1b9/routing/extrouter.h,v 1.2 2002/09/07 07:34:19 neufeldm Exp $ + * + * This defines the interface used by all external raw packet routing + * modules bolted on to ns. + * + */ + +#ifndef __ns_extrouter_h__ +#define __ns_extrouter_h__ + +class ExtRouter +{ + +public: + enum { + IFID_NONE = -1, + IFID_KERNELTAP = 0, + IFID_FIRSTIF = 1, + IFID_LASTIF = 32, + IFID_FIRSTIFDROP = 33, + IFID_LASTIFDROP = 64 + }; + virtual ~ExtRouter(); + virtual int route(Packet* p) = 0; + +}; + +#endif diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/routing/rtmodule.cc ns-2.1b9/routing/rtmodule.cc --- ns-2.1b9.orig/routing/rtmodule.cc Tue Sep 10 23:12:16 2002 +++ ns-2.1b9/routing/rtmodule.cc Tue Sep 10 23:28:02 2002 @@ -93,6 +93,14 @@ #endif // PGM +static class ClickRoutingModuleClass : public TclClass { +public: + ClickRoutingModuleClass() : TclClass("RtModule/Click") {} + TclObject* create(int, const char*const*) { + return (new ClickRoutingModule); + } +} class_click_routing_module; + RoutingModule::RoutingModule() : next_rtm_(NULL), n_(NULL), classifier_(NULL) { bind("classifier_", (TclObject**)&classifier_); @@ -432,4 +440,3 @@ if (next_rtm_ != NULL) next_rtm_->add_route(dst, target); } - diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/routing/rtmodule.h ns-2.1b9/routing/rtmodule.h --- ns-2.1b9.orig/routing/rtmodule.h Tue Sep 10 23:12:16 2002 +++ ns-2.1b9/routing/rtmodule.h Tue Sep 10 23:28:02 2002 @@ -135,5 +135,11 @@ }; #endif // PGM + +class ClickRoutingModule : public RoutingModule { +public: + ClickRoutingModule() : RoutingModule() {} + virtual const char* module_name() const { return "Click"; } +}; #endif // ns_rtmodule_h diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/tcl/ex/nsclick-simple-bridge.click ns-2.1b9/tcl/ex/nsclick-simple-bridge.click --- ns-2.1b9.orig/tcl/ex/nsclick-simple-bridge.click Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/tcl/ex/nsclick-simple-bridge.click Tue Sep 10 23:28:03 2002 @@ -0,0 +1,40 @@ +// +// Copyright 2002, Univerity of Colorado at Boulder. +// +// All Rights Reserved +// +// Permission to use, copy, modify, and distribute this software and its +// documentation for any purpose other than its incorporation into a +// commercial product is hereby granted without fee, provided that the +// above copyright notice appear in all copies and that both that +// copyright notice and this permission notice appear in supporting +// documentation, and that the name of the University not be used in +// advertising or publicity pertaining to distribution of the software +// without specific, written prior permission. +// +// UNIVERSITY OF COLORADO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +// SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE UNIVERSITY +// OF COLORADO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL +// DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA +// OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. +// + +// nsclick-simple-bridge.click +// +// This is a simple and stupid network "bridge." Packets coming +// in off of eth0 are pumped out on eth1, and packets coming +// in off of eth1 are pumped out on eth0. +// + +FromSimDevice(eth0,4096) + -> Queue + -> ToSimDevice(eth1); + +FromSimDevice(eth1,4096) + -> Queue + -> ToSimDevice(eth0); + + diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/tcl/ex/nsclick-simple-hybrid.tcl ns-2.1b9/tcl/ex/nsclick-simple-hybrid.tcl --- ns-2.1b9.orig/tcl/ex/nsclick-simple-hybrid.tcl Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/tcl/ex/nsclick-simple-hybrid.tcl Tue Sep 10 23:28:03 2002 @@ -0,0 +1,389 @@ +# +# Copyright 2002, Univerity of Colorado at Boulder. +# +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose other than its incorporation into a +# commercial product is hereby granted without fee, provided that the +# above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of the University not be used in +# advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# UNIVERSITY OF COLORADO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE UNIVERSITY +# OF COLORADO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL +# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA +# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +# nsclick-simple-hybrid.tcl +# @(#) $Header: /srl/dirkcvs/nsclick/ns-2.1b9/tcl/ex/nsclick-simple-hybrid.tcl,v 1.2 2002/06/13 02:34:34 neufeldm Exp $ +# +# A sample nsclick script simulating a small hybrid wired/wireless +# + +# +# Set some general simulation parameters +# + +# +# Unity gain, omnidirectional antennas, centered 1.5m above each node. +# These values are lifted from the ns-2 sample files. +# +Antenna/OmniAntenna set X_ 0 +Antenna/OmniAntenna set Y_ 0 +Antenna/OmniAntenna set Z_ 1.5 +Antenna/OmniAntenna set Gt_ 1.0 +Antenna/OmniAntenna set Gr_ 1.0 + +# +# Initialize the SharedMedia interface with parameters to make +# it work like the 914MHz Lucent WaveLAN DSSS radio interface +# These are taken directly from the ns-2 sample files. +# +Phy/WirelessPhy set CPThresh_ 10.0 +Phy/WirelessPhy set CSThresh_ 1.559e-11 +Phy/WirelessPhy set RXThresh_ 3.652e-10 +Phy/WirelessPhy set Rb_ 2*1e6 +Phy/WirelessPhy set Pt_ 0.2818 +Phy/WirelessPhy set freq_ 914e+6 +Phy/WirelessPhy set L_ 1.0 + +# +# Set the size of the playing field and the topography. +# +set xsize 100 +set ysize 100 +set wtopo [new Topography] +$wtopo load_flatgrid $xsize $ysize + +# +# The network channel, physical layer, MAC, propagation model, +# and antenna model are all standard ns-2. +# +set wirelesschan Channel/WirelessChannel +set wiredchan Channel + +set wirelessphy Phy/WirelessPhy +set wiredphy Phy/WiredPhy + +set wirelessmac Mac/802_11 +set wiredmac Mac/802_3 + +set netprop Propagation/TwoRayGround +set antenna Antenna/OmniAntenna + +# +# We have to use a special queue and link layer. This is so that +# Click can have control over the network interface packet queue, +# which is vital if we want to play with, e.g. QoS algorithms. +# +set netifq Queue/ClickQueue +set netll LL/Ext +LL set delay_ 1ms + +# +# These are pretty self-explanatory, just the number of nodes +# and when we'll stop. +# +set wirednodecount 3 +set wirelessnodecount 3 +set bridgenodecount 1 +set nodecount 7 +set stoptime 10.0 + +# +# With nsclick, we have to worry about details like which network +# port to use for communication. This sets the default ports to 5000. +# +Agent/Null set sport_ 5000 +Agent/Null set dport_ 5000 + +Agent/CBR set sport_ 5000 +Agent/CBR set dport_ 5000 + +# +# Standard ns-2 stuff here - create the simulator object. +# +set ns_ [new Simulator] + +# +# Create and activate trace files. +# +set tracefd [open "nsclick-simple-hybrid.tr" w] +set namtrace [open "nsclick-simple-hybrid.nam" w] +$ns_ trace-all $tracefd +$ns_ namtrace-all-wireless $namtrace $xsize $ysize +$ns_ use-newtrace + + +# +# Create the "god" object. This is another artifact of using +# the mobile node type. We have to have this even though +# we never use it. +# +set god_ [create-god $nodecount] + +# +# Tell the simulator to create Click nodes. +# +Simulator set node_factory_ Node/MobileNode/ClickNode + +# +# Create a network Channel for the nodes to use. One channel +# per LAN. Also set the propagation model to be used. +# +set wired_chan_ [new $wiredchan] +set wireless_chan_ [new $wirelesschan] +set prop_ [new $netprop] + +# +# In nsclick we have to worry about assigning IP and MAC addresses +# to out network interfaces. Here we generate a list of IP and MAC +# addresses, one per node since we've only got one network interface +# per node in this case. Also note that this scheme only works for +# fewer than 255 nodes, and we aren't worrying about subnet masks. +# +set iptemplate "192.168.1.%d" +set mactemplate "00:03:47:70:89:%0x" +for {set i 0} {$i < $wirednodecount} {incr i} { + set wired_node_ip($i) [format $iptemplate [expr $i+1]] + set wired_node_mac($i) [format $mactemplate [expr $i+1]] +} + +set iptemplate "192.168.2.%d" +set mactemplate "00:03:47:70:8A:%0x" +for {set i 0} {$i < $wirelessnodecount} {incr i} { + set wireless_node_ip($i) [format $iptemplate [expr $i+1]] + set wireless_node_mac($i) [format $mactemplate [expr $i+1]] +} + + +# +# We set the routing protocol to "Empty" so that ns-2 doesn't do +# any packet routing. All of the routing will be done by the +# Click script. +# +$ns_ rtproto Empty + +# +# Here is where we actually create all of the nodes. +# We'll create the wired, wireless, and the bridge node +# separately. +# + +# +# Start with the wireless nodes +# +for {set i 0} {$i < $wirelessnodecount } {incr i} { + set wireless_node_($i) [$ns_ node] + + # + # After creating the node, we add one wireless network interface to + # it. By default, this interface will be named "eth0". If we + # added a second interface it would be named "eth1", a third + # "eth2" and so on. + # + $wireless_node_($i) add-interface $wireless_chan_ $prop_ $netll \ + $wirelessmac $netifq 1 $wirelessphy $antenna + + # + # Now configure the interface eth0 + # + $wireless_node_($i) setip "eth0" $wireless_node_ip($i) + $wireless_node_($i) setmac "eth0" $wireless_node_mac($i) + + # + # Set some node properties + # + $wireless_node_($i) random-motion 0 + $wireless_node_($i) topography $wtopo + $wireless_node_($i) nodetrace $tracefd + + # + # The node name is used by Click to distinguish information + # coming from different nodes. For example, a "Print" element + # prepends this to the printed string so it's clear exactly + # which node is doing the printing. + # + [$wireless_node_($i) set classifier_] setnodename "wirelessnode$i-hybrid" + + # + # Load the appropriate Click router script for the node. + # + [$wireless_node_($i) entry] loadclick "nsclick-simple-lan.click" +} + +# +# Now create the wired nodes +# +for {set i 0} {$i < $wirednodecount } {incr i} { + set wired_node_($i) [$ns_ node] + + # + # After creating the node, we add one wired network interface to + # it. By default, this interface will be named "eth0". If we + # added a second interface it would be named "eth1", a third + # "eth2" and so on. + # + $wired_node_($i) add-wired-interface $wired_chan_ $netll $wiredmac \ + $netifq 1 $wiredphy + + # + # Now configure the interface eth0 + # + $wired_node_($i) setip "eth0" $wired_node_ip($i) + $wired_node_($i) setmac "eth0" $wired_node_mac($i) + + # + # Set some node properties + # + $wired_node_($i) random-motion 0 + $wired_node_($i) topography $wtopo + $wired_node_($i) nodetrace $tracefd + + # + # The node name is used by Click to distinguish information + # coming from different nodes. For example, a "Print" element + # prepends this to the printed string so it's clear exactly + # which node is doing the printing. + # + [$wired_node_($i) set classifier_] setnodename "wirednode$i-hybrid" + + # + # Load the appropriate Click router script for the node. + # All nodes in this simulation are using the same script, + # but there's no reason why each node couldn't use a different + # script. + # + [$wired_node_($i) entry] loadclick "nsclick-simple-lan.click" +} + +# +# Finally make the bridge node +# +set bridge_node_ [$ns_ node] +$bridge_node_ add-wired-interface $wired_chan_ $netll $wiredmac \ + $netifq 1 $wiredphy +$bridge_node_ add-interface $wireless_chan_ $prop_ $netll \ + $wirelessmac $netifq 1 $wirelessphy $antenna + +$bridge_node_ random-motion 0 +$bridge_node_ topography $wtopo +$bridge_node_ nodetrace $tracefd + +[$bridge_node_ entry] loadclick "nsclick-simple-bridge.click" +[$bridge_node_ set classifier_] setnodename "bridgenode-hybrid" + +# +# Define node network traffic. There isn't a whole lot going on +# in this simple test case, we're just going to have the first wireless node +# send packets to the first wired node, starting at 1 second, and ending at 10. +# There are Perl scripts available to automatically generate network +# traffic. +# + + +# +# Start transmitting at $startxmittime, $xmitrate packets per second. +# +set startxmittime 1 +set xmitrate 4 +set xmitinterval 0.25 +set packetsize 64 + +# +# We use the "raw" packet type, which sends real packet data +# down the pipe. +# +set raw_(0) [new Agent/Raw] +$ns_ attach-agent $wireless_node_(0) $raw_(0) + +set null_(0) [new Agent/Null] +$ns_ attach-agent $wired_node_(0) $null_(0) + +# +# The CBR object is just the default ns-2 CBR object, so +# no change in the meaning of the parameters. +# +set cbr_(0) [new Application/Traffic/CBR] +$cbr_(0) set packetSize_ $packetsize +$cbr_(0) set interval_ $xmitinterval +$cbr_(0) set random_ 0 +$cbr_(0) set maxpkts_ [expr ($stoptime - $startxmittime)*$xmitrate] +$cbr_(0) attach-agent $raw_(0) + +# +# The Raw agent creates real UDP packets, so it has to know +# the source and destination IP addresses and port numberes. +# +$raw_(0) set-srcip [$wireless_node_(0) getip eth0] +$raw_(0) set-srcport 5000 +$raw_(0) set-destport 5000 +$raw_(0) set-destip [$wired_node_(0) getip eth0] + +$ns_ at $startxmittime "$cbr_(0) start" + + +$wireless_node_(0) set X_ 10 +$wireless_node_(0) set Y_ 50 +$wireless_node_(0) set Z_ 0 + +$wireless_node_(1) set X_ 50 +$wireless_node_(1) set Y_ 50 +$wireless_node_(1) set Z_ 0 + +$wireless_node_(2) set X_ 90 +$wireless_node_(2) set Y_ 50 +$wireless_node_(2) set Z_ 0 + +$bridge_node_ set X_ 50 +$bridge_node_ set Y_ 10 +$bridge_node_ set Z_ 0 + +$wired_node_(0) set X_ 10 +$wired_node_(0) set Y_ 0 +$wired_node_(0) set Z_ 0 + +$wired_node_(1) set X_ 50 +$wired_node_(1) set Y_ 0 +$wired_node_(1) set Z_ 0 + +$wired_node_(2) set X_ 90 +$wired_node_(2) set Y_ 0 +$wired_node_(2) set Z_ 0 +# +# This sizes the nodes for use in nam. +# +for {set i 0} {$i < $wirelessnodecount} {incr i} { + $ns_ initial_node_pos $wireless_node_($i) 10 +} + +for {set i 0} {$i < $wirednodecount} {incr i} { + $ns_ initial_node_pos $wired_node_($i) 10 +} + +$ns_ initial_node_pos $bridge_node_ 10 + +# +# Stop the simulation +# +$ns_ at $stoptime.000000001 "puts \"NS EXITING...\" ; $ns_ halt" + +# +# Let nam know that the simulation is done. +# +$ns_ at $stoptime "$ns_ nam-end-wireless $stoptime" + + +puts "Starting Simulation..." +$ns_ run + + + + diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/tcl/ex/nsclick-simple-lan.click ns-2.1b9/tcl/ex/nsclick-simple-lan.click --- ns-2.1b9.orig/tcl/ex/nsclick-simple-lan.click Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/tcl/ex/nsclick-simple-lan.click Tue Sep 10 23:28:03 2002 @@ -0,0 +1,101 @@ +// +// Copyright 2002, Univerity of Colorado at Boulder. +// +// All Rights Reserved +// +// Permission to use, copy, modify, and distribute this software and its +// documentation for any purpose other than its incorporation into a +// commercial product is hereby granted without fee, provided that the +// above copyright notice appear in all copies and that both that +// copyright notice and this permission notice appear in supporting +// documentation, and that the name of the University not be used in +// advertising or publicity pertaining to distribution of the software +// without specific, written prior permission. +// +// UNIVERSITY OF COLORADO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +// SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE UNIVERSITY +// OF COLORADO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL +// DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA +// OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. +// + +// nsclick-simple-lan.click +// +// This is a simple and stupid flat routing mechanism. +// It broadcasts ARP requests if it wants to find a destination +// address, and it responds to ARP requests made for it. + +elementclass DumbRouter { + $myaddr, $myaddr_ethernet | + + class :: Classifier(12/0806 20/0001,12/0806 20/0002, -); + mypackets :: IPClassifier(dst host $myaddr,-); + myarpquerier :: ARPQuerier($myaddr,$myaddr_ethernet); + myarpresponder :: ARPResponder($myaddr $myaddr_ethernet); + ethout :: Queue -> ToSimDevice(eth0); + + FromSimDevice(eth0,4096) + -> Print(eth0,64) + -> ToSimDump(in_eth0) + -> HostEtherFilter($myaddr_ethernet) + -> class; + + // ARP queries from other nodes go to the ARP responder module + class[0] -> myarpresponder; + + // ARP responses go to our query module + class[1] -> [1]myarpquerier; + + // All other packets get checked to see if they're meant for us + class[2] + -> Strip(14) + -> CheckIPHeader + -> MarkIPHeader + -> GetIPAddress(16) + -> mypackets; + + // Packets for us go to "tap0" which sends them to the kernel + mypackets[0] + -> IPPrint(tokernel) + -> ToSimDump(tokernel,2000,IP) + -> ToSimDevice(tap0,IP); + + // Packets for other folks or broadcast packets get discarded + mypackets[1] + -> Print(discard,64) + -> ToSimDump(discard,2000,IP) + -> Discard; + + // Packets sent out by the "kernel" get pushed into the ARP query module + FromSimDevice(tap0,4096) + -> CheckIPHeader + -> IPPrint(fromkernel) + -> ToSimDump(fromkernel,2000,IP) + -> GetIPAddress(16) + -> myarpquerier; + + // Both the ARP query and response modules send data out to + // the simulated network device, eth0. + myarpquerier + -> Print(fromarpquery,64) + -> ToSimDump(out_arpquery) + -> ethout; + + myarpresponder + -> Print(arpresponse,64) + -> ToSimDump(out_arprespond) + -> ethout; +} + + +// Note the use of the :simnet suffix. This means that +// the simulator will be asked for the particular value +// for the variable in this node. +AddressInfo(me0 eth0:simnet); +u :: DumbRouter(me0,me0); + + + diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/tcl/ex/nsclick-simple-lan.tcl ns-2.1b9/tcl/ex/nsclick-simple-lan.tcl --- ns-2.1b9.orig/tcl/ex/nsclick-simple-lan.tcl Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/tcl/ex/nsclick-simple-lan.tcl Tue Sep 10 23:28:03 2002 @@ -0,0 +1,271 @@ +# +# Copyright 2002, Univerity of Colorado at Boulder. +# +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose other than its incorporation into a +# commercial product is hereby granted without fee, provided that the +# above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of the University not be used in +# advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# UNIVERSITY OF COLORADO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE UNIVERSITY +# OF COLORADO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL +# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA +# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +# nsclick-simple-lan.tcl +# @(#) $Header: /srl/dirkcvs/nsclick/ns-2.1b9/tcl/ex/nsclick-simple-lan.tcl,v 1.2 2002/06/13 02:34:34 neufeldm Exp $ +# +# A sample nsclick script simulating a small LAN +# + +# +# Set some general simulation parameters +# + +# +# Even though this is a wired simulation with non-moving nodes, nsclick +# uses the mobile node type. This means we have to set the size of the +# playing field and the topography even though it won't matter. +# +set xsize 100 +set ysize 100 +set wtopo [new Topography] +$wtopo load_flatgrid $xsize $ysize + +# +# The network channel, physical layer, and MAC are all standard ns-2. +# +set netchan Channel +set netphy Phy/WiredPhy +set netmac Mac/802_3 + +# +# We have to use a special queue and link layer. This is so that +# Click can have control over the network interface packet queue, +# which is vital if we want to play with, e.g. QoS algorithms. +# +set netifq Queue/ClickQueue +set netll LL/Ext +LL set delay_ 1ms + +# +# These are pretty self-explanatory, just the number of nodes +# and when we'll stop. +# +set nodecount 4 +set stoptime 10.0 + +# +# With nsclick, we have to worry about details like which network +# port to use for communication. This sets the default ports to 5000. +# +Agent/Null set sport_ 5000 +Agent/Null set dport_ 5000 + +Agent/CBR set sport_ 5000 +Agent/CBR set dport_ 5000 + +# +# Standard ns-2 stuff here - create the simulator object. +# +Simulator set MacTrace_ ON +set ns_ [new Simulator] + +# +# Create and activate trace files. +# +set tracefd [open "nsclick-simple-lan.tr" w] +set namtrace [open "nsclick-simple-lan.nam" w] +$ns_ trace-all $tracefd +$ns_ namtrace-all-wireless $namtrace $xsize $ysize +$ns_ use-newtrace + + +# +# Create the "god" object. This is another artifact of using +# the mobile node type. We have to have this even though +# we never use it. +# +set god_ [create-god $nodecount] + +# +# Tell the simulator to create Click nodes. +# +Simulator set node_factory_ Node/MobileNode/ClickNode + +# +# Create a network Channel for the nodes to use. One channel +# per LAN. +# +set chan_1_ [new $netchan] + +# +# In nsclick we have to worry about assigning IP and MAC addresses +# to out network interfaces. Here we generate a list of IP and MAC +# addresses, one per node since we've only got one network interface +# per node in this case. Also note that this scheme only works for +# fewer than 255 nodes, and we aren't worrying about subnet masks. +# +set iptemplate "192.168.1.%d" +set mactemplate "00:03:47:70:89:%0x" +for {set i 0} {$i < $nodecount} {incr i} { + set node_ip($i) [format $iptemplate [expr $i+1]] + set node_mac($i) [format $mactemplate [expr $i+1]] +} + +# +# We set the routing protocol to "Empty" so that ns-2 doesn't do +# any packet routing. All of the routing will be done by the +# Click script. +# +$ns_ rtproto Empty + +# +# Here is where we actually create all of the nodes. +# +for {set i 0} {$i < $nodecount } {incr i} { + set node_($i) [$ns_ node] + + # + # After creating the node, we add one wired network interface to + # it. By default, this interface will be named "eth0". If we + # added a second interface it would be named "eth1", a third + # "eth2" and so on. + # + $node_($i) add-wired-interface $chan_1_ $netll $netmac \ + $netifq 1 $netphy + + # + # Now configure the interface eth0 + # + $node_($i) setip "eth0" $node_ip($i) + $node_($i) setmac "eth0" $node_mac($i) + + # + # Set some node properties + # + $node_($i) random-motion 0 + $node_($i) topography $wtopo + $node_($i) nodetrace $tracefd + + # + # The node name is used by Click to distinguish information + # coming from different nodes. For example, a "Print" element + # prepends this to the printed string so it's clear exactly + # which node is doing the printing. + # + [$node_($i) set classifier_] setnodename "node$i-simplelan" + + # + # Load the appropriate Click router script for the node. + # All nodes in this simulation are using the same script, + # but there's no reason why each node couldn't use a different + # script. + # + [$node_($i) entry] loadclick "nsclick-simple-lan.click" +} + + +# +# Define node network traffic. There isn't a whole lot going on +# in this simple test case, we're just going to have the first node +# send packets to the last node, starting at 1 second, and ending at 10. +# There are Perl scripts available to automatically generate network +# traffic. +# + + +# +# Start transmitting at $startxmittime, $xmitrate packets per second. +# +set startxmittime 1 +set xmitrate 4 +set xmitinterval 0.25 +set packetsize 64 + +# +# We use the "raw" packet type, which sends real packet data +# down the pipe. +# +set raw_(0) [new Agent/Raw] +$ns_ attach-agent $node_(0) $raw_(0) + +set lastnode [expr $nodecount-1] +set null_(0) [new Agent/Null] +$ns_ attach-agent $node_($lastnode) $null_(0) + +# +# The CBR object is just the default ns-2 CBR object, so +# no change in the meaning of the parameters. +# +set cbr_(0) [new Application/Traffic/CBR] +$cbr_(0) set packetSize_ $packetsize +$cbr_(0) set interval_ $xmitinterval +$cbr_(0) set random_ 0 +$cbr_(0) set maxpkts_ [expr ($stoptime - $startxmittime)*$xmitrate] +$cbr_(0) attach-agent $raw_(0) + +# +# The Raw agent creates real UDP packets, so it has to know +# the source and destination IP addresses and port numberes. +# +$raw_(0) set-srcip [$node_(0) getip eth0] +$raw_(0) set-srcport 5000 +$raw_(0) set-destport 5000 +$raw_(0) set-destip [$node_($lastnode) getip eth0] + +$ns_ at $startxmittime "$cbr_(0) start" + +# +# Set node positions. For wired networks, these are only used +# when looking at nam traces. +# +$node_(0) set X_ 10 +$node_(0) set Y_ 50 +$node_(0) set Z_ 0 + +$node_(1) set X_ 50 +$node_(1) set Y_ 50 +$node_(1) set Z_ 0 + +$node_(2) set X_ 90 +$node_(2) set Y_ 50 +$node_(2) set Z_ 0 + +$node_(3) set X_ 50 +$node_(3) set Y_ 10 +$node_(3) set Z_ 0 + +# +# This sizes the nodes for use in nam. +# +for {set i 0} {$i < $nodecount} {incr i} { + $ns_ initial_node_pos $node_($i) 20 +} + +# +# Stop the simulation +# +$ns_ at $stoptime.000000001 "puts \"NS EXITING...\" ; $ns_ halt" + +# +# Let nam know that the simulation is done. +# +$ns_ at $stoptime "$ns_ nam-end-wireless $stoptime" + + +puts "Starting Simulation..." +$ns_ run + + + + diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/tcl/ex/nsclick-simple-wlan.tcl ns-2.1b9/tcl/ex/nsclick-simple-wlan.tcl --- ns-2.1b9.orig/tcl/ex/nsclick-simple-wlan.tcl Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/tcl/ex/nsclick-simple-wlan.tcl Tue Sep 10 23:28:03 2002 @@ -0,0 +1,295 @@ +# +# Copyright 2002, Univerity of Colorado at Boulder. +# +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose other than its incorporation into a +# commercial product is hereby granted without fee, provided that the +# above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of the University not be used in +# advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# UNIVERSITY OF COLORADO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE UNIVERSITY +# OF COLORADO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL +# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA +# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +# nsclick-simple-lan.tcl +# @(#) $Header: /srl/dirkcvs/nsclick/ns-2.1b9/tcl/ex/nsclick-simple-wlan.tcl,v 1.2 2002/06/13 02:34:34 neufeldm Exp $ +# +# A sample nsclick script simulating a small LAN +# + +# +# Set some general simulation parameters +# + +# +# Unity gain, omnidirectional antennas, centered 1.5m above each node. +# These values are lifted from the ns-2 sample files. +# +Antenna/OmniAntenna set X_ 0 +Antenna/OmniAntenna set Y_ 0 +Antenna/OmniAntenna set Z_ 1.5 +Antenna/OmniAntenna set Gt_ 1.0 +Antenna/OmniAntenna set Gr_ 1.0 + +# +# Initialize the SharedMedia interface with parameters to make +# it work like the 914MHz Lucent WaveLAN DSSS radio interface +# These are taken directly from the ns-2 sample files. +# +Phy/WirelessPhy set CPThresh_ 10.0 +Phy/WirelessPhy set CSThresh_ 1.559e-11 +Phy/WirelessPhy set RXThresh_ 3.652e-10 +Phy/WirelessPhy set Rb_ 2*1e6 +Phy/WirelessPhy set Pt_ 0.2818 +Phy/WirelessPhy set freq_ 914e+6 +Phy/WirelessPhy set L_ 1.0 + +# +# Set the size of the playing field and the topography. +# +set xsize 100 +set ysize 100 +set wtopo [new Topography] +$wtopo load_flatgrid $xsize $ysize + +# +# The network channel, physical layer, MAC, propagation model, +# and antenna model are all standard ns-2. +# +set netchan Channel/WirelessChannel +set netphy Phy/WirelessPhy +set netmac Mac/802_11 +set netprop Propagation/TwoRayGround +set antenna Antenna/OmniAntenna + +# +# We have to use a special queue and link layer. This is so that +# Click can have control over the network interface packet queue, +# which is vital if we want to play with, e.g. QoS algorithms. +# +set netifq Queue/ClickQueue +set netll LL/Ext +LL set delay_ 1ms + +# +# These are pretty self-explanatory, just the number of nodes +# and when we'll stop. +# +set nodecount 4 +set stoptime 10.0 + +# +# With nsclick, we have to worry about details like which network +# port to use for communication. This sets the default ports to 5000. +# +Agent/Null set sport_ 5000 +Agent/Null set dport_ 5000 + +Agent/CBR set sport_ 5000 +Agent/CBR set dport_ 5000 + +# +# Standard ns-2 stuff here - create the simulator object. +# +Simulator set MacTrace_ ON +set ns_ [new Simulator] + +# +# Create and activate trace files. +# +set tracefd [open "nsclick-simple-wlan.tr" w] +set namtrace [open "nsclick-simple-wlan.nam" w] +$ns_ trace-all $tracefd +$ns_ namtrace-all-wireless $namtrace $xsize $ysize +$ns_ use-newtrace + + +# +# Create the "god" object. This is another artifact of using +# the mobile node type. We have to have this even though +# we never use it. +# +set god_ [create-god $nodecount] + +# +# Tell the simulator to create Click nodes. +# +Simulator set node_factory_ Node/MobileNode/ClickNode + +# +# Create a network Channel for the nodes to use. One channel +# per LAN. Also set the propagation model to be used. +# +set chan_1_ [new $netchan] +set prop_ [new $netprop] + +# +# In nsclick we have to worry about assigning IP and MAC addresses +# to out network interfaces. Here we generate a list of IP and MAC +# addresses, one per node since we've only got one network interface +# per node in this case. Also note that this scheme only works for +# fewer than 255 nodes, and we aren't worrying about subnet masks. +# +set iptemplate "192.168.1.%d" +set mactemplate "00:03:47:70:89:%0x" +for {set i 0} {$i < $nodecount} {incr i} { + set node_ip($i) [format $iptemplate [expr $i+1]] + set node_mac($i) [format $mactemplate [expr $i+1]] +} + +# +# We set the routing protocol to "Empty" so that ns-2 doesn't do +# any packet routing. All of the routing will be done by the +# Click script. +# +$ns_ rtproto Empty + +# +# Here is where we actually create all of the nodes. +# +for {set i 0} {$i < $nodecount } {incr i} { + set node_($i) [$ns_ node] + + # + # After creating the node, we add one wireless network interface to + # it. By default, this interface will be named "eth0". If we + # added a second interface it would be named "eth1", a third + # "eth2" and so on. + # + $node_($i) add-interface $chan_1_ $prop_ $netll $netmac \ + $netifq 1 $netphy $antenna + + # + # Now configure the interface eth0 + # + $node_($i) setip "eth0" $node_ip($i) + $node_($i) setmac "eth0" $node_mac($i) + + # + # Set some node properties + # + $node_($i) random-motion 0 + $node_($i) topography $wtopo + $node_($i) nodetrace $tracefd + + # + # The node name is used by Click to distinguish information + # coming from different nodes. For example, a "Print" element + # prepends this to the printed string so it's clear exactly + # which node is doing the printing. + # + [$node_($i) set classifier_] setnodename "node$i-simplelan" + + # + # Load the appropriate Click router script for the node. + # All nodes in this simulation are using the same script, + # but there's no reason why each node couldn't use a different + # script. + # + [$node_($i) entry] loadclick "nsclick-simple-lan.click" +} + + +# +# Define node network traffic. There isn't a whole lot going on +# in this simple test case, we're just going to have the first node +# send packets to the last node, starting at 1 second, and ending at 10. +# There are Perl scripts available to automatically generate network +# traffic. +# + + +# +# Start transmitting at $startxmittime, $xmitrate packets per second. +# +set startxmittime 1 +set xmitrate 4 +set xmitinterval 0.25 +set packetsize 64 + +# +# We use the "raw" packet type, which sends real packet data +# down the pipe. +# +set raw_(0) [new Agent/Raw] +$ns_ attach-agent $node_(0) $raw_(0) + +set lastnode [expr $nodecount-1] +set null_(0) [new Agent/Null] +$ns_ attach-agent $node_($lastnode) $null_(0) + +# +# The CBR object is just the default ns-2 CBR object, so +# no change in the meaning of the parameters. +# +set cbr_(0) [new Application/Traffic/CBR] +$cbr_(0) set packetSize_ $packetsize +$cbr_(0) set interval_ $xmitinterval +$cbr_(0) set random_ 0 +$cbr_(0) set maxpkts_ [expr ($stoptime - $startxmittime)*$xmitrate] +$cbr_(0) attach-agent $raw_(0) + +# +# The Raw agent creates real UDP packets, so it has to know +# the source and destination IP addresses and port numberes. +# +$raw_(0) set-srcip [$node_(0) getip eth0] +$raw_(0) set-srcport 5000 +$raw_(0) set-destport 5000 +$raw_(0) set-destip [$node_($lastnode) getip eth0] + +$ns_ at $startxmittime "$cbr_(0) start" + + +$node_(0) set X_ 10 +$node_(0) set Y_ 50 +$node_(0) set Z_ 0 + +$node_(1) set X_ 50 +$node_(1) set Y_ 50 +$node_(1) set Z_ 0 + +$node_(2) set X_ 90 +$node_(2) set Y_ 50 +$node_(2) set Z_ 0 + +$node_(3) set X_ 50 +$node_(3) set Y_ 10 +$node_(3) set Z_ 0 + + +# +# This sizes the nodes for use in nam. Currently, the trace files +# produced by nsclick don't really work in nam. +# +for {set i 0} {$i < $nodecount} {incr i} { + $ns_ initial_node_pos $node_($i) 20 +} + +# +# Stop the simulation +# +$ns_ at $stoptime.000000001 "puts \"NS EXITING...\" ; $ns_ halt" + +# +# Let nam know that the simulation is done. +# +$ns_ at $stoptime "$ns_ nam-end-wireless $stoptime" + + +puts "Starting Simulation..." +$ns_ run + + + + diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/tcl/lib/ns-clicknode.tcl ns-2.1b9/tcl/lib/ns-clicknode.tcl --- ns-2.1b9.orig/tcl/lib/ns-clicknode.tcl Wed Dec 31 17:00:00 1969 +++ ns-2.1b9/tcl/lib/ns-clicknode.tcl Tue Sep 10 23:28:04 2002 @@ -0,0 +1,334 @@ +# +# Copyright 2002, Univerity of Colorado at Boulder. +# +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose other than its incorporation into a +# commercial product is hereby granted without fee, provided that the +# above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of the University not be used in +# advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# UNIVERSITY OF COLORADO DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE UNIVERSITY +# OF COLORADO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL +# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA +# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +# +# @(#) $Header: /srl/dirkcvs/nsclick/ns-2.1b9/tcl/lib/ns-clicknode.tcl,v 1.1 2002/06/13 01:07:40 neufeldm Exp $ +# + +Class ClickNode -superclass Node/MobileNode + +Node/MobileNode/ClickNode instproc init args { + $self instvar nifs_ netif_ mac_ ifq_ ll_ dmux_ + set ns [Simulator instance] + eval $self next $args + set nifs_ 0 + $self register-module [new RtModule/Click] + + # + # This Trace Target is used to log changes in direction + # and velocity for the mobile node. + # + set tracefd [$ns get-ns-traceall] + if {$tracefd != "" } { + $self nodetrace $tracefd + #$self agenttrace $tracefd + } + + set namtracefd [$ns get-nam-traceall] + if {$namtracefd != "" } { + $self namattach $namtracefd + } + +} + +Node/MobileNode/ClickNode instproc getip { ifname } { + [$self entry] getip $ifname +} + +Node/MobileNode/ClickNode instproc getmac { ifname } { + [$self entry] getmac $ifname +} + +Node/MobileNode/ClickNode instproc setip { ifname ipaddr } { + [$self entry] setip $ifname $ipaddr +} + +Node/MobileNode/ClickNode instproc setmac { ifname macaddr } { + [$self entry] setmac $ifname $macaddr +} + +Node/MobileNode/ClickNode instproc add-route { dst target } { + #puts "ClickNode does routing via Click - not ns." +} + +Node/MobileNode/ClickNode instproc delete-route args { + #puts "ClickNode does routing via Click - not ns." +} + +Node/MobileNode/ClickNode instproc route-notify { module } { + #puts "ClickNode does routing via Click - not ns." +} + +# +# The following setups up link layer, mac layer, network interface +# and physical layer structures for the click node. Stolen from +# the MobileNode code, and then modified a bit, e.g. the ARP +# stuff got removed. +# +Node/MobileNode/ClickNode instproc add-interface { channel pmodel lltype mactype \ + qtype qlen iftype anttype} { + + $self instvar nifs_ netif_ mac_ ifq_ ll_ + set ns [Simulator instance] + set t $nifs_ + incr nifs_ + + set netif_($t) [new $iftype] ;# interface + set mac_($t) [new $mactype] ;# mac layer + set ifq_($t) [new $qtype] ;# interface queue + set ll_($t) [new $lltype] ;# link layer + set ant_($t) [new $anttype] + + set namfp [$ns get-nam-traceall] + + # + # Local Variables + # + set nullAgent_ [$ns set nullAgent_] + set netif $netif_($t) + set mac $mac_($t) + set ifq $ifq_($t) + set ll $ll_($t) + + # + # Link Layer + # + $ll mac $mac + $ll down-target $ifq + $ll up-target [$self entry] + # Stuff the link layer into the next available classifier slot, and + # use that slot number as the network id + $ll setid [[$self entry] installNext $ll] + + # + # Interface Queue + # + $ifq target $mac + $ifq set limit_ $qlen + set drpT [cmu-trace Drop "IFQ" $self] + $ifq drop-target $drpT + if { $namfp != "" } { + $drpT namattach $namfp + } + if {$qtype == "Queue/ClickQueue"} { + $ifq setclickclassifier [$self entry] + $ll ifq $ifq + } + + # + # Mac Layer + # + $mac netif $netif + $mac up-target $ll + $mac down-target $netif + set god_ [God instance] + if {$mactype == "Mac/802_11"} { + $mac nodes [$god_ num_nodes] + } + # + # Network Interface + # + $netif channel $channel + $netif up-target $mac + $netif propagation $pmodel ;# Propagation Model + $netif node $self ;# Bind node <---> interface + $netif antenna $ant_($t) + # + # Physical Channel + # + $channel addif $netif + + # ============================================================ + + if { [Simulator set MacTrace_] == "ON" } { + # + # Trace RTS/CTS/ACK Packets + # + set rcvT [cmu-trace Recv "MAC" $self] + $mac log-target $rcvT + if { $namfp != "" } { + $rcvT namattach $namfp + } + # + # Trace Sent Packets + # + set sndT [cmu-trace Send "MAC" $self] + $sndT target [$mac down-target] + $mac down-target $sndT + if { $namfp != "" } { + $sndT namattach $namfp + } + # + # Trace Received Packets + # + set rcvT [cmu-trace Recv "MAC" $self] + $rcvT target [$mac up-target] + $mac up-target $rcvT + if { $namfp != "" } { + $rcvT namattach $namfp + } + # + # Trace Dropped Packets + # + set drpT [cmu-trace Drop "MAC" $self] + $mac drop-target $drpT + if { $namfp != "" } { + $drpT namattach $namfp + } + } else { + $mac log-target [$ns set nullAgent_] + $mac drop-target [$ns set nullAgent_] + } + + # ============================================================ + + $self addif $netif +} + + +# +# The following setups up link layer, mac layer, network interface +# and physical layer structures for the click node. Stolen from +# the MobileNode code, and then modified a bit, e.g. the ARP +# stuff got removed. +# +Node/MobileNode/ClickNode instproc add-wired-interface { channel lltype mactype qtype qlen iftype} { + + $self instvar nifs_ netif_ mac_ ifq_ ll_ + set ns [Simulator instance] + set t $nifs_ + incr nifs_ + + set netif_($t) [new $iftype] ;# interface + set mac_($t) [new $mactype] ;# mac layer + set ifq_($t) [new $qtype] ;# interface queue + set ll_($t) [new $lltype] ;# link layer + + + set namfp [$ns get-nam-traceall] + + # + # Local Variables + # + set nullAgent_ [$ns set nullAgent_] + set netif $netif_($t) + set mac $mac_($t) + set ifq $ifq_($t) + set ll $ll_($t) + + # + # Link Layer + # + $ll mac $mac + $ll down-target $ifq + $ll up-target [$self entry] + # Stuff the link layer into the next available classifier slot, and + # use that slot number as the network id + $ll setid [[$self entry] installNext $ll] + + # + # Interface Queue + # + $ifq target $mac + $ifq set limit_ $qlen + set drpT [cmu-trace Drop "IFQ" $self] + $ifq drop-target $drpT + if { $namfp != "" } { + $drpT namattach $namfp + } + if {$qtype == "Queue/ClickQueue"} { + $ifq setclickclassifier [$self entry] + $ll ifq $ifq + } + + # + # Mac Layer + # + $mac netif $netif + $mac up-target $ll + $mac down-target $netif + set god_ [God instance] + if {$mactype == "Mac/802_11"} { + $mac nodes [$god_ num_nodes] + } + # + # Network Interface + # + $netif channel $channel + $netif up-target $mac + $netif node $self ;# Bind node <---> interface + # + # Physical Channel + # + $channel addif $netif + + # ============================================================ + + if { [Simulator set MacTrace_] == "ON" } { + # + # Trace RTS/CTS/ACK Packets + # + set rcvT [cmu-trace Recv "MAC" $self] + $mac log-target $rcvT + if { $namfp != "" } { + $rcvT namattach $namfp + } + # + # Trace Sent Packets + # + set sndT [cmu-trace Send "MAC" $self] + $sndT target [$mac down-target] + $mac down-target $sndT + if { $namfp != "" } { + $sndT namattach $namfp + } + # + # Trace Received Packets + # + set rcvT [cmu-trace Recv "MAC" $self] + $rcvT target [$mac up-target] + $mac up-target $rcvT + if { $namfp != "" } { + $rcvT namattach $namfp + } + # + # Trace Dropped Packets + # + set drpT [cmu-trace Drop "MAC" $self] + $mac drop-target $drpT + if { $namfp != "" } { + $drpT namattach $namfp + } + } else { + $mac log-target [$ns set nullAgent_] + $mac drop-target [$ns set nullAgent_] + } + + # ============================================================ + + $self addif $netif +} + +Node/MobileNode/ClickNode instproc dump-namconfig {} { +# Do nothing +} \ No newline at end of file diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/tcl/lib/ns-lib.tcl ns-2.1b9/tcl/lib/ns-lib.tcl --- ns-2.1b9.orig/tcl/lib/ns-lib.tcl Tue Sep 10 23:12:17 2002 +++ ns-2.1b9/tcl/lib/ns-lib.tcl Tue Sep 10 23:28:04 2002 @@ -200,6 +200,8 @@ source ns-default.tcl source ../emulate/ns-emulate.tcl + +source ns-clicknode.tcl #pushback source ns-pushback.tcl diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/tcl/lib/ns-packet.tcl ns-2.1b9/tcl/lib/ns-packet.tcl --- ns-2.1b9.orig/tcl/lib/ns-packet.tcl Tue Sep 10 23:12:17 2002 +++ ns-2.1b9/tcl/lib/ns-packet.tcl Tue Sep 10 23:28:04 2002 @@ -136,7 +136,8 @@ PGM PGM_SPM PGM_NAK - RAP + RAP + Raw RTP Resv rtProtoDV diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/tcl/lib/ns-rtmodule.tcl ns-2.1b9/tcl/lib/ns-rtmodule.tcl --- ns-2.1b9.orig/tcl/lib/ns-rtmodule.tcl Tue Sep 10 23:12:18 2002 +++ ns-2.1b9/tcl/lib/ns-rtmodule.tcl Tue Sep 10 23:28:04 2002 @@ -352,4 +352,42 @@ RtModule/Nix instproc route-notify { module } { } +# +# Click routing module. Intended to subvert the normal routing process +# and defer to Click. +# +RtModule/Click instproc init {} { + $self next +} + +RtModule/Click instproc register { node } { + $self next $node + $self make-classifier +} + +RtModule/Click instproc make-classifier {} { + $self instvar classifier_ + set classifier_ [new Classifier/Ext/Click] + [$self node] install-entry $self $classifier_ + $classifier_ setnodename [format "node%d" [[$self node] set id_]] + $classifier_ setnodeaddr [[$self node] set address_] + [$self node] set dmux_ [new Classifier/Port] + # Always stick the kernel tap interface into slot 0 + $classifier_ install 0 [[$self node] set dmux_] +} + +RtModule/Click instproc attach { agent port } { + # Send target + $agent target [[$self node] entry] + # Recv target + [[$self node] demux] install $port $agent +} + +RtModule/Click instproc detach { agent nullagent } { + # Empty method +} + +RtModule/Nix instproc route-notify { module } { + # Empty method +} diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/tcl/rtglib/route-proto.tcl ns-2.1b9/tcl/rtglib/route-proto.tcl --- ns-2.1b9.orig/tcl/rtglib/route-proto.tcl Tue Sep 10 23:12:18 2002 +++ ns-2.1b9/tcl/rtglib/route-proto.tcl Tue Sep 10 23:28:04 2002 @@ -723,6 +723,15 @@ Agent/rtProto/Manual proc init-all args { # The user will do all routing. } +# +# Empty. Does NOTHING - even less than the Manual routing. +# +Class Agent/rtProto/Empty -superclass Agent/rtProto + +Agent/rtProto/Empty proc init-all args { + # Do nothing +} + ### Local Variables: ### mode: tcl diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/trace/cmu-trace.cc ns-2.1b9/trace/cmu-trace.cc --- ns-2.1b9.orig/trace/cmu-trace.cc Tue Sep 10 23:12:18 2002 +++ ns-2.1b9/trace/cmu-trace.cc Tue Sep 10 23:28:05 2002 @@ -635,6 +635,20 @@ } } +// XXX Fix this +void +CMUTrace::format_raw(Packet *p, int offset) +{ + struct hdr_cmn *ch = HDR_CMN(p); + struct hdr_tcp *th = HDR_TCP(p); + + if( newtrace_ ) { + sprintf(pt_->buffer() + offset,"raw "); + } else { + sprintf(pt_->buffer() + offset,"raw "); + } +} + void CMUTrace::nam_format(Packet *p, int offset) { @@ -825,6 +839,9 @@ case PT_DIFF: break; case PT_GAF: + break; + case PT_RAW: + format_raw(p, offset); break; default: fprintf(stderr, "%s - invalid packet type (%s).\n", diff -urN --exclude=CVS -I .*[$][HID] ns-2.1b9.orig/trace/cmu-trace.h ns-2.1b9/trace/cmu-trace.h --- ns-2.1b9.orig/trace/cmu-trace.h Tue Sep 10 23:12:18 2002 +++ ns-2.1b9/trace/cmu-trace.h Tue Sep 10 23:28:05 2002 @@ -117,6 +117,7 @@ void format_tora(Packet *p, int offset); void format_imep(Packet *p, int offset); void format_aodv(Packet *p, int offset); + void format_raw(Packet *p, int offset); }; #endif /* __cmu_trace__ */