From bart.braem at ua.ac.be Wed Nov 3 01:36:17 2004 From: bart.braem at ua.ac.be (Bart Braem) Date: Wed Nov 3 01:36:52 2004 Subject: [nsclick-users] Bug in FromSimDevice? Message-ID: <200411030936.18238.bart.braem@ua.ac.be> Why does FromSimDevice set annotations on broadcast using ethernet headers? Because when using the example scripts the data enters as IP data, not encapsulated in ethernet headers? Am I making a mistake here or did a small bug occur? Thanks for any help, Bart From Michael.Neufeld at colorado.edu Wed Nov 3 07:49:40 2004 From: Michael.Neufeld at colorado.edu (Michael Neufeld) Date: Wed Nov 3 07:49:54 2004 Subject: [nsclick-users] Bug in FromSimDevice? In-Reply-To: <200411030936.18238.bart.braem@ua.ac.be> References: <200411030936.18238.bart.braem@ua.ac.be> Message-ID: <4188F004.6080106@colorado.edu> Ahhhh. I see the problem. It's a bug. The "FromSimDevice" element wasn't checking the packet type, just assuming all would be ethernet. True for my simulations, but not for everyone... I've attached modified "fromsimdevice.hh,cc" files which should do the trick if you still want to use IP encapsulation, though in general I'd encourage the use of ethernet enacpsulation since it'll reduce the number of changes made between the simulator and real life. -Mike Bart Braem wrote: > Why does FromSimDevice set annotations on broadcast using ethernet headers? > Because when using the example scripts the data enters as IP data, not > encapsulated in ethernet headers? Am I making a mistake here or did a small > bug occur? > > Thanks for any help, > Bart > _______________________________________________ > nsclick-users mailing list > nsclick-users@cs-lists.cs.colorado.edu > http://cs-lists.cs.colorado.edu/mailman/listinfo/nsclick-users From Michael.Neufeld at colorado.edu Wed Nov 3 07:51:20 2004 From: Michael.Neufeld at colorado.edu (Michael Neufeld) Date: Wed Nov 3 07:51:26 2004 Subject: [nsclick-users] Bug in FromSimDevice? In-Reply-To: <4188F004.6080106@colorado.edu> References: <200411030936.18238.bart.braem@ua.ac.be> <4188F004.6080106@colorado.edu> Message-ID: <4188F068.5030401@colorado.edu> Helps if I actually attach the files... I'll also check this into the click CVS. -Mike Michael Neufeld wrote: > Ahhhh. I see the problem. It's a bug. The "FromSimDevice" element wasn't > checking the packet type, just assuming all would be ethernet. True for > my simulations, but not for everyone... > > I've attached modified "fromsimdevice.hh,cc" files which should do the > trick if you still want to use IP encapsulation, though in general I'd > encourage the use of ethernet enacpsulation since it'll reduce the > number of changes made between the simulator and real life. > > -Mike > > Bart Braem wrote: > >> Why does FromSimDevice set annotations on broadcast using ethernet >> headers? Because when using the example scripts the data enters as IP >> data, not encapsulated in ethernet headers? Am I making a mistake here >> or did a small bug occur? >> >> Thanks for any help, >> Bart >> _______________________________________________ >> nsclick-users mailing list >> nsclick-users@cs-lists.cs.colorado.edu >> http://cs-lists.cs.colorado.edu/mailman/listinfo/nsclick-users -------------- next part -------------- #ifndef CLICK_FROMSIMDEVICE_HH #define CLICK_FROMSIMDEVICE_HH #include #include CLICK_DECLS /***************************************************************************** * 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. * * * ****************************************************************************/ /* * =title FromSimDevice.u * =c * FromSimDevice(DEVNAME [, PROMISC? [, MAXPACKETSIZE]]) * =s devices * reads packets from a simulator device * =d * * This manual page describes the user-level version of the FromSimDevice * element. * * =e * FromSimDevice(eth0, 0) -> ... * * =a ToSimDevice.u, FromDump, ToDump, FromDevice(n) */ class FromSimDevice : public Element { String _ifname; int _packetbuf_size; int _fd; unsigned char *_packetbuf; static void set_annotations(Packet *,int ptype); // set appropriate annotations, i.e. MAC packet type. // modifies the packet. public: FromSimDevice(); ~FromSimDevice(); const char *class_name() const { return "FromSimDevice"; } const char *processing() const { return PUSH; } FromSimDevice *clone() const; int configure_phase() const { return CONFIGURE_PHASE_DEFAULT; } int configure(Vector &, ErrorHandler *); int initialize(ErrorHandler *); void uninitialize(); String ifname() const { return _ifname; } int fd() const { return _fd; } int incoming_packet(int ifid,int ptype,const unsigned char* data,int len, simclick_simpacketinfo* pinfo); }; CLICK_ENDDECLS #endif -------------- next part -------------- /* * fromsimevice.{cc,hh} -- element reads packets from a simulated network * interface. * */ /***************************************************************************** * 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 "fromsimdevice.hh" #include "tosimdevice.hh" #include #include #include #include #include #include #include CLICK_DECLS FromSimDevice::FromSimDevice() : Element(0, 1), _packetbuf_size(0),_packetbuf(0) { MOD_INC_USE_COUNT; } FromSimDevice::~FromSimDevice() { MOD_DEC_USE_COUNT; uninitialize(); } FromSimDevice * FromSimDevice::clone() const { return new FromSimDevice; } int FromSimDevice::configure(Vector &conf, ErrorHandler *errh) { _packetbuf_size = 2048; if (cp_va_parse(conf, this, errh, cpString, "interface name", &_ifname, cpUnsigned, "maximum packet length", &_packetbuf_size, cpEnd) < 0) return -1; if (_packetbuf_size > 8192 || _packetbuf_size < 128) return errh->error("maximum packet length out of range"); return 0; } int FromSimDevice::initialize(ErrorHandler *errh) { if (!_ifname) return errh->error("interface not set"); // Get the simulator ifid Router* myrouter = router(); _fd = myrouter->sim_get_ifid(_ifname.cc()); if (_fd < 0) return errh->error("unable to open netowrk interface"); // create packet buffer _packetbuf = new unsigned char[_packetbuf_size]; if (!_packetbuf) { close(_fd); return errh->error("out of memory"); } // Request that we get packets sent to us from the simulator myrouter->sim_listen(_fd,eindex()); return 0; } void FromSimDevice::uninitialize() { if (_fd >= 0) { //close(_fd); //remove_select(_fd, SELECT_READ); _fd = -1; } if (_packetbuf) { delete[] _packetbuf; _packetbuf = 0; } } void FromSimDevice::set_annotations(Packet *p,int ptype) { static char bcast_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; if (SIMCLICK_PTYPE_ETHER == ptype) { // check if multicast // ! mcast => ! bcast if (!(p->data()[0] & 1)) return; // check for bcast if (memcmp(bcast_addr, p->data(), 6) == 0) p->set_packet_type_anno(Packet::BROADCAST); else p->set_packet_type_anno(Packet::MULTICAST); } return; } int FromSimDevice::incoming_packet(int ifid,int ptype,const unsigned char* data, int len,simclick_simpacketinfo* pinfo){ int result = 0; Packet *p = Packet::make(data, len); set_annotations(p,ptype); p->set_sim_packetinfo(pinfo); output(0).push(p); return result; } CLICK_ENDDECLS ELEMENT_REQUIRES(ns) EXPORT_ELEMENT(FromSimDevice) From bart.braem at ua.ac.be Wed Nov 3 08:26:54 2004 From: bart.braem at ua.ac.be (Bart Braem) Date: Wed Nov 3 08:27:23 2004 Subject: [nsclick-users] Bug in FromSimDevice? In-Reply-To: References: Message-ID: <200411031626.55111.bart.braem@ua.ac.be> > Ahhhh. I see the problem. It's a bug. The "FromSimDevice" element wasn't > checking the packet type, just assuming all would be ethernet. True for > my simulations, but not for everyone... > > I've attached modified "fromsimdevice.hh,cc" files which should do the > trick if you still want to use IP encapsulation, though in general I'd > encourage the use of ethernet enacpsulation since it'll reduce the > number of changes made between the simulator and real life. Thanks for the patch, always nice when after looking for hours it turns out you found the bug... However I don't understand how I should convince ns to use ethernet encapsulation, what should I add to the following script? ... Agent/Null set sport_ 5000 Agent/Null set dport_ 5000 Agent/CBR set sport_ 5000 Agent/CBR set dport_ 5000 ... set raw_(0) [new Agent/Raw] $ns_ attach-agent $node_($origin) $raw_(0) set null_(0) [new Agent/Null] $ns_ attach-agent $node_($destination) $null_(0) set cbr_(0) [new Application/Traffic/CBR] $cbr_(0) set packetSize_ $packetsize $cbr_(0) set interval_ $xmitinterval $cbr_(0) set maxpkts_ [expr ($stoptime - $startxmittime)*$xmitrate] $cbr_(0) attach-agent $raw_(0) $raw_(0) set-srcip [$node_($origin) getip eth0] $raw_(0) set-srcport 5000 $raw_(0) set-destport 5000 $raw_(0) set-destip [$node_($destination) getip eth0] Thanks for your help! Bart From bart.braem at ua.ac.be Thu Nov 4 03:10:23 2004 From: bart.braem at ua.ac.be (Bart Braem) Date: Thu Nov 4 03:10:52 2004 Subject: [nsclick-users] Click ICMP messages into ns Message-ID: <200411041110.24011.bart.braem@ua.ac.be> Hello, I managed to solve one of these nice ns errors like this: --- Classfier::no-slot{} default handler (tcl/lib/ns-lib.tcl) --- _o49: no target for slot 0 _o49 type: Classifier/Port content dump: classifier _o49 0 offset 0 shift 2147483647 mask 0 slots ---------- Finished standard no-slot{} default handler ---------- In my case my Click ICMP messages (timeouts) went nowhere... Is it possible to have ns discard these messages by attaching a null agent or something like that? That would be easier when testing only with Click in the near future. Thanks for any help, Bart From Michael.Neufeld at colorado.edu Thu Nov 4 07:12:35 2004 From: Michael.Neufeld at colorado.edu (Michael Neufeld) Date: Thu Nov 4 07:12:57 2004 Subject: [nsclick-users] Bug in FromSimDevice? In-Reply-To: <200411031626.55111.bart.braem@ua.ac.be> References: <200411031626.55111.bart.braem@ua.ac.be> Message-ID: <418A38D3.7020608@colorado.edu> You don't have to add anything to the ns tcl script to use ethernet packets -- it's all determined in your Click script. I personally find it useful to add predefined ethernet and IP addresses for the individual nsclick nodes from tcl, but that's not required. Here's a snippet of tcl which generates a chunk of both ethernet and IP addresses: # # 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 "10.%d.%d.%d" set mactemplate "00:03:47:%0x:%0x:%0x" set b 0 set c 0 set d 1 for {set i 0} {$i < $nodecount} {incr i} { set node_ip($i) [format $iptemplate $b $c $d] set node_mac($i) [format $mactemplate $b $c $d] set d [expr $d + 1] if { $d >= 255 } { set d 1 set c [expr $c + 1] } if { $c >= 255 } { set c 0 set b [expr $b + 1] } # XXX should die if we wrap b over... } ------------------------------ You then need to have a loop which creates the nodes, adds the ethernet interfaces, and sets the IP and ethernet addresses so you can use AddressInfo from the nodes. Here's another chunk of code which does that: # # 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 256 $netphy $antenna # # Now configure the interface eth0 # $node_($i) setip "eth0" $node_ip($i) $node_($i) setmac "eth0" $node_mac($i) $node_($i) setpromiscuous 0 1 } ------------------------ Finally, here's a simple Click script which does ARP routing. ------------- router.click ---------------- // // 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. AddressInfo(me0 eth0:simnet); class :: Classifier(12/0806 20/0001,12/0806 20/0002, -); mypackets :: IPClassifier(dst host me0,-); myarpquerier :: ARPQuerier(me0,me0); myarpresponder :: ARPResponder(me0 me0); ethout :: Queue -> ToSimDevice(eth0); FromSimDevice(eth0,4096) -> HostEtherFilter(me0) -> 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] -> ToSimDevice(tap0,IP); // Packets for other folks or broadcast packets get discarded mypackets[1] -> Discard; // Packets sent out by the "kernel" get pushed into the ARP query module FromSimDevice(tap0,4096) -> CheckIPHeader -> GetIPAddress(16) -> myarpquerier; // Both the ARP query and response modules send data out to // the simulated network device, eth0. myarpquerier -> ethout; myarpresponder -> ethout; FromSimDevice(drop0,4096) -> Discard; FromSimDevice(ack0,4096) -> Discard; Bart Braem wrote: >>Ahhhh. I see the problem. It's a bug. The "FromSimDevice" element wasn't >>checking the packet type, just assuming all would be ethernet. True for >>my simulations, but not for everyone... >> >>I've attached modified "fromsimdevice.hh,cc" files which should do the >>trick if you still want to use IP encapsulation, though in general I'd >>encourage the use of ethernet enacpsulation since it'll reduce the >>number of changes made between the simulator and real life. > > > Thanks for the patch, always nice when after looking for hours it turns out > you found the bug... However I don't understand how I should convince ns to > use ethernet encapsulation, what should I add to the following script? > > ... > > Agent/Null set sport_ 5000 > Agent/Null set dport_ 5000 > > Agent/CBR set sport_ 5000 > Agent/CBR set dport_ 5000 > > ... > > set raw_(0) [new Agent/Raw] > $ns_ attach-agent $node_($origin) $raw_(0) > > set null_(0) [new Agent/Null] > $ns_ attach-agent $node_($destination) $null_(0) > > set cbr_(0) [new Application/Traffic/CBR] > $cbr_(0) set packetSize_ $packetsize > $cbr_(0) set interval_ $xmitinterval > $cbr_(0) set maxpkts_ [expr ($stoptime - $startxmittime)*$xmitrate] > $cbr_(0) attach-agent $raw_(0) > > $raw_(0) set-srcip [$node_($origin) getip eth0] > $raw_(0) set-srcport 5000 > $raw_(0) set-destport 5000 > $raw_(0) set-destip [$node_($destination) getip eth0] > > Thanks for your help! > Bart > _______________________________________________ > nsclick-users mailing list > nsclick-users@cs-lists.cs.colorado.edu > http://cs-lists.cs.colorado.edu/mailman/listinfo/nsclick-users From Michael.Neufeld at colorado.edu Thu Nov 4 07:16:41 2004 From: Michael.Neufeld at colorado.edu (Michael Neufeld) Date: Thu Nov 4 07:16:46 2004 Subject: [nsclick-users] Click ICMP messages into ns In-Reply-To: <200411041110.24011.bart.braem@ua.ac.be> References: <200411041110.24011.bart.braem@ua.ac.be> Message-ID: <418A39C9.8080206@colorado.edu> I'm assuming that these are packets you're delivering to the ToSimDevice(tap0) element? As I recall you can catch them in ns by adding an application of some sort -- it's been a while since I looked at it so I don't remember for certain. Usually I just drop these quietly in Click without ever sending them to ns. You should be able to use a classifier to distinguish them from data packets and shunt them off into a Discard element when running in nsclick. -Mike Bart Braem wrote: > Hello, > > I managed to solve one of these nice ns errors like this: > > --- Classfier::no-slot{} default handler (tcl/lib/ns-lib.tcl) --- > _o49: no target for slot 0 > _o49 type: Classifier/Port > content dump: > classifier _o49 > 0 offset > 0 shift > 2147483647 mask > 0 slots > ---------- Finished standard no-slot{} default handler ---------- > > In my case my Click ICMP messages (timeouts) went nowhere... Is it possible to > have ns discard these messages by attaching a null agent or something like > that? That would be easier when testing only with Click in the near future. > > Thanks for any help, > Bart > _______________________________________________ > nsclick-users mailing list > nsclick-users@cs-lists.cs.colorado.edu > http://cs-lists.cs.colorado.edu/mailman/listinfo/nsclick-users