diff -urN click-1.2.4.orig/Makefile.in click-1.2.4/Makefile.in --- click-1.2.4.orig/Makefile.in Tue May 21 18:11:38 2002 +++ click-1.2.4/Makefile.in Fri May 31 13:18:18 2002 @@ -40,6 +40,8 @@ @cd bsdmodule && $(MAKE) all userlevel: Makefile click-compile stamp-h @cd userlevel && $(MAKE) all +simclick: Makefile click-compile stamp-h + @cd simclick && $(MAKE) all exopc: Makefile stamp-h @cd exopc && $(MAKE) all tools: Makefile @@ -168,6 +170,6 @@ .PHONY: all always elemlist elemlists \ - bsdmodule exopc linuxmodule tools userlevel \ + bsdmodule exopc linuxmodule tools userlevel simclick \ clean distclean dist distdir \ install install-doc install-man install-local install-include install-local-include diff -urN click-1.2.4.orig/click-buildtool click-1.2.4/click-buildtool --- click-1.2.4.orig/click-buildtool Thu Mar 7 12:07:27 2002 +++ click-1.2.4/click-buildtool Mon Jun 3 13:44:21 2002 @@ -495,6 +495,7 @@ for (file in INCLUDES) { print "#include ", file; } + print "\n#ifdef CLICK_SIM\nusing namespace CLICKSIM;\n#endif\n\n"; print "void\nexport_elements(Lexer *lexer)\n{"; print B, " CLICK_DMALLOC_REG(\"nXXX\");\n}"; } diff -urN click-1.2.4.orig/configure.in click-1.2.4/configure.in --- click-1.2.4.orig/configure.in Tue May 21 11:05:25 2002 +++ click-1.2.4/configure.in Fri May 31 13:20:35 2002 @@ -49,7 +49,7 @@ AC_ARG_ENABLE(userlevel, [ --disable-userlevel disable user-level driver], :, enable_userlevel=yes) AC_ARG_ENABLE(linuxmodule, [ --disable-linuxmodule disable Linux kernel driver], :, enable_linuxmodule=yes) AC_ARG_ENABLE(bsdmodule, [ --enable-bsdmodule enable FreeBSD kernel driver (EXPERIMENTAL)], :, enable_bsdmodule=no) - +AC_ARG_ENABLE(simclick, [ --disable-simclick disable simclick], :, enable_simclick=yes) dnl dnl How to build linuxmodule driver? @@ -461,7 +461,7 @@ dnl POSSIBLE_TARGETS= -for i in bsdmodule exopc linuxmodule userlevel; do +for i in bsdmodule exopc linuxmodule userlevel simclick; do test -f $srcdir/$i/Makefile.in && POSSIBLE_TARGETS="$POSSIBLE_TARGETS $i" done AC_SUBST(POSSIBLE_TARGETS) diff -urN click-1.2.4.orig/elements/app/ftpportmapper.cc click-1.2.4/elements/app/ftpportmapper.cc --- click-1.2.4.orig/elements/app/ftpportmapper.cc Tue May 21 17:29:58 2002 +++ click-1.2.4/elements/app/ftpportmapper.cc Sat Jun 1 23:23:50 2002 @@ -24,6 +24,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + FTPPortMapper::FTPPortMapper() : Element(1, 1), _pattern(0) { @@ -42,7 +46,11 @@ return errh->error("wrong number of arguments; expected `FTPPortMapper(element, pattern)'"); // get control packet rewriter - Element *e = cp_element(conf[0], this, errh); + Element *e = +#ifdef CLICK_SIM + CLICKSIM:: +#endif + cp_element(conf[0], this, errh); if (!e) return -1; _control_rewriter = (TCPRewriter *)e->cast("TCPRewriter"); diff -urN click-1.2.4.orig/elements/app/ftpportmapper.hh click-1.2.4/elements/app/ftpportmapper.hh --- click-1.2.4.orig/elements/app/ftpportmapper.hh Fri Apr 5 11:52:04 2002 +++ click-1.2.4/elements/app/ftpportmapper.hh Sat Jun 1 00:09:32 2002 @@ -88,6 +88,10 @@ * L */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class FTPPortMapper : public Element { TCPRewriter *_control_rewriter; @@ -111,5 +115,9 @@ Packet *simple_action(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ethernet/arpfaker.cc click-1.2.4/elements/ethernet/arpfaker.cc --- click-1.2.4.orig/elements/ethernet/arpfaker.cc Tue May 21 17:30:09 2002 +++ click-1.2.4/elements/ethernet/arpfaker.cc Sat Jun 1 23:37:18 2002 @@ -24,6 +24,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + ARPFaker::ARPFaker() : _timer(this) { diff -urN click-1.2.4.orig/elements/ethernet/arpfaker.hh click-1.2.4/elements/ethernet/arpfaker.hh --- click-1.2.4.orig/elements/ethernet/arpfaker.hh Thu Feb 7 11:10:04 2002 +++ click-1.2.4/elements/ethernet/arpfaker.hh Sat Jun 1 23:35:51 2002 @@ -32,6 +32,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class ARPFaker : public Element { public: @@ -61,5 +65,9 @@ Timer _timer; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ethernet/arpquerier.cc click-1.2.4/elements/ethernet/arpquerier.cc --- click-1.2.4.orig/elements/ethernet/arpquerier.cc Tue May 21 17:30:13 2002 +++ click-1.2.4/elements/ethernet/arpquerier.cc Sat Jun 1 23:40:53 2002 @@ -26,6 +26,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + ARPQuerier::ARPQuerier() : _expire_timer(expire_hook, this) { diff -urN click-1.2.4.orig/elements/ethernet/arpquerier.hh click-1.2.4/elements/ethernet/arpquerier.hh --- click-1.2.4.orig/elements/ethernet/arpquerier.hh Wed Apr 24 10:06:24 2002 +++ click-1.2.4/elements/ethernet/arpquerier.hh Sat Jun 1 23:39:11 2002 @@ -55,6 +55,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class ARPQuerier : public Element { public: ARPQuerier(); @@ -116,5 +120,9 @@ static String read_table(Element *, void *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ethernet/arpresponder.cc click-1.2.4/elements/ethernet/arpresponder.cc --- click-1.2.4.orig/elements/ethernet/arpresponder.cc Tue May 21 17:30:15 2002 +++ click-1.2.4/elements/ethernet/arpresponder.cc Sat Jun 1 23:41:29 2002 @@ -25,6 +25,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + ARPResponder::ARPResponder() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/ethernet/arpresponder.hh click-1.2.4/elements/ethernet/arpresponder.hh --- click-1.2.4.orig/elements/ethernet/arpresponder.hh Thu Feb 7 11:10:15 2002 +++ click-1.2.4/elements/ethernet/arpresponder.hh Sat Jun 1 23:41:57 2002 @@ -54,6 +54,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class ARPResponder : public Element { public: ARPResponder(); @@ -90,5 +94,9 @@ static String read_handler(Element *, void *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ethernet/ensureether.cc click-1.2.4/elements/ethernet/ensureether.cc --- click-1.2.4.orig/elements/ethernet/ensureether.cc Thu Feb 7 11:19:42 2002 +++ click-1.2.4/elements/ethernet/ensureether.cc Sat Jun 1 23:43:01 2002 @@ -22,6 +22,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + EnsureEther::EnsureEther() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/ethernet/ensureether.hh click-1.2.4/elements/ethernet/ensureether.hh --- click-1.2.4.orig/elements/ethernet/ensureether.hh Tue May 21 17:30:18 2002 +++ click-1.2.4/elements/ethernet/ensureether.hh Sat Jun 1 23:42:38 2002 @@ -38,6 +38,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class EnsureEther : public Element { public: EnsureEther(); @@ -58,5 +62,9 @@ click_ether _ethh; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ethernet/etherencap.cc click-1.2.4/elements/ethernet/etherencap.cc --- click-1.2.4.orig/elements/ethernet/etherencap.cc Thu Mar 28 21:48:36 2002 +++ click-1.2.4/elements/ethernet/etherencap.cc Sat Jun 1 23:43:35 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + EtherEncap::EtherEncap() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/ethernet/etherencap.hh click-1.2.4/elements/ethernet/etherencap.hh --- click-1.2.4.orig/elements/ethernet/etherencap.hh Tue May 21 17:30:22 2002 +++ click-1.2.4/elements/ethernet/etherencap.hh Sat Jun 1 23:45:34 2002 @@ -42,6 +42,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class EtherEncap : public Element { public: EtherEncap(); @@ -66,5 +70,9 @@ static String read_handler(Element *, void *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ethernet/ethermirror.cc click-1.2.4/elements/ethernet/ethermirror.cc --- click-1.2.4.orig/elements/ethernet/ethermirror.cc Tue May 21 17:30:25 2002 +++ click-1.2.4/elements/ethernet/ethermirror.cc Sat Jun 1 23:44:51 2002 @@ -19,6 +19,10 @@ #include "ethermirror.hh" #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + EtherMirror::EtherMirror() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/ethernet/ethermirror.hh click-1.2.4/elements/ethernet/ethermirror.hh --- click-1.2.4.orig/elements/ethernet/ethermirror.hh Wed Apr 24 09:52:06 2002 +++ click-1.2.4/elements/ethernet/ethermirror.hh Sat Jun 1 23:46:28 2002 @@ -13,6 +13,10 @@ * addresses are swapped before they are output. * */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class EtherMirror : public Element { public: EtherMirror(); @@ -24,5 +28,9 @@ Packet *simple_action(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif // CLICK_ETHERMIRROR_HH diff -urN click-1.2.4.orig/elements/ethernet/hostetherfilter.cc click-1.2.4/elements/ethernet/hostetherfilter.cc --- click-1.2.4.orig/elements/ethernet/hostetherfilter.cc Tue May 21 17:30:36 2002 +++ click-1.2.4/elements/ethernet/hostetherfilter.cc Sat Jun 1 23:47:54 2002 @@ -23,6 +23,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + HostEtherFilter::HostEtherFilter() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/ethernet/hostetherfilter.hh click-1.2.4/elements/ethernet/hostetherfilter.hh --- click-1.2.4.orig/elements/ethernet/hostetherfilter.hh Thu Feb 7 11:10:25 2002 +++ click-1.2.4/elements/ethernet/hostetherfilter.hh Sat Jun 1 23:47:27 2002 @@ -41,6 +41,10 @@ */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class HostEtherFilter : public Element { public: HostEtherFilter(); @@ -64,5 +68,9 @@ inline Packet *drop(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/icmp/checkicmpheader.cc click-1.2.4/elements/icmp/checkicmpheader.cc --- click-1.2.4.orig/elements/icmp/checkicmpheader.cc Tue May 21 17:31:21 2002 +++ click-1.2.4/elements/icmp/checkicmpheader.cc Sat Jun 1 23:49:29 2002 @@ -29,6 +29,10 @@ # include #endif +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + const char *CheckICMPHeader::reason_texts[NREASONS] = { "not ICMP", "bad packet length", "bad ICMP checksum" }; diff -urN click-1.2.4.orig/elements/icmp/checkicmpheader.hh click-1.2.4/elements/icmp/checkicmpheader.hh --- click-1.2.4.orig/elements/icmp/checkicmpheader.hh Thu Feb 7 11:13:46 2002 +++ click-1.2.4/elements/icmp/checkicmpheader.hh Sat Jun 1 23:48:59 2002 @@ -48,6 +48,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class CheckICMPHeader : public Element { public: CheckICMPHeader(); @@ -81,5 +85,9 @@ static String read_handler(Element *, void *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/icmp/icmperror.cc click-1.2.4/elements/icmp/icmperror.cc --- click-1.2.4.orig/elements/icmp/icmperror.cc Tue May 21 17:31:26 2002 +++ click-1.2.4/elements/icmp/icmperror.cc Sat Jun 1 23:50:08 2002 @@ -26,6 +26,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + ICMPError::ICMPError() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/icmp/icmperror.hh click-1.2.4/elements/icmp/icmperror.hh --- click-1.2.4.orig/elements/icmp/icmperror.hh Thu Feb 7 11:13:49 2002 +++ click-1.2.4/elements/icmp/icmperror.hh Sat Jun 1 23:50:34 2002 @@ -57,6 +57,10 @@ #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class ICMPError : public Element { public: ICMPError(); @@ -84,5 +88,9 @@ bool has_route_opt(const click_ip *ip); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/icmp/icmppingresponder.cc click-1.2.4/elements/icmp/icmppingresponder.cc --- click-1.2.4.orig/elements/icmp/icmppingresponder.cc Tue May 21 17:31:26 2002 +++ click-1.2.4/elements/icmp/icmppingresponder.cc Sat Jun 1 23:52:10 2002 @@ -27,6 +27,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + ICMPPingResponder::ICMPPingResponder() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/icmp/icmppingresponder.hh click-1.2.4/elements/icmp/icmppingresponder.hh --- click-1.2.4.orig/elements/icmp/icmppingresponder.hh Fri Oct 5 09:50:17 2001 +++ click-1.2.4/elements/icmp/icmppingresponder.hh Sat Jun 1 23:51:54 2002 @@ -26,6 +26,10 @@ #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class ICMPPingResponder : public Element { public: ICMPPingResponder(); @@ -40,5 +44,9 @@ Packet *simple_action(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/icmp/icmppingrewriter.cc click-1.2.4/elements/icmp/icmppingrewriter.cc --- click-1.2.4.orig/elements/icmp/icmppingrewriter.cc Tue May 21 17:31:26 2002 +++ click-1.2.4/elements/icmp/icmppingrewriter.cc Sat Jun 1 23:53:17 2002 @@ -24,6 +24,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + ICMPPingRewriter::ICMPPingRewriter() : Element(1, 1), _request_map(0), _reply_map(0), _timer(this) { diff -urN click-1.2.4.orig/elements/icmp/icmppingrewriter.hh click-1.2.4/elements/icmp/icmppingrewriter.hh --- click-1.2.4.orig/elements/icmp/icmppingrewriter.hh Tue May 21 17:31:26 2002 +++ click-1.2.4/elements/icmp/icmppingrewriter.hh Sat Jun 1 23:52:52 2002 @@ -50,6 +50,10 @@ IPRewriter, ICMPPingResponder */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class ICMPPingRewriter : public Element { public: ICMPPingRewriter(); @@ -125,5 +129,9 @@ // void take_state_map(Map &, const Vector &, const Vector &); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/icmp/icmprewriter.cc click-1.2.4/elements/icmp/icmprewriter.cc --- click-1.2.4.orig/elements/icmp/icmprewriter.cc Tue May 21 17:31:31 2002 +++ click-1.2.4/elements/icmp/icmprewriter.cc Sun Jun 2 00:06:19 2002 @@ -23,6 +23,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + ICMPRewriter::ICMPRewriter() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/icmp/icmprewriter.hh click-1.2.4/elements/icmp/icmprewriter.hh --- click-1.2.4.orig/elements/icmp/icmprewriter.hh Tue May 21 17:31:31 2002 +++ click-1.2.4/elements/icmp/icmprewriter.hh Sun Jun 2 00:06:01 2002 @@ -48,6 +48,10 @@ IPAddrRewriter, IPRewriter, ICMPPingRewriter, TCPRewriter */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class ICMPRewriter : public Element { public: ICMPRewriter(); @@ -73,5 +77,9 @@ const IPFlowID &, ICMPPingRewriter::Mapping *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/icmp/icmpsendpings.cc click-1.2.4/elements/icmp/icmpsendpings.cc --- click-1.2.4.orig/elements/icmp/icmpsendpings.cc Tue May 21 17:31:32 2002 +++ click-1.2.4/elements/icmp/icmpsendpings.cc Sun Jun 2 00:09:21 2002 @@ -25,6 +25,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + ICMPSendPings::ICMPSendPings() : _timer(this) { diff -urN click-1.2.4.orig/elements/icmp/icmpsendpings.hh click-1.2.4/elements/icmp/icmpsendpings.hh --- click-1.2.4.orig/elements/icmp/icmpsendpings.hh Tue May 14 14:50:21 2002 +++ click-1.2.4/elements/icmp/icmpsendpings.hh Sun Jun 2 00:08:39 2002 @@ -43,6 +43,10 @@ ICMPPingResponder, ICMPPingRewriter */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class ICMPSendPings : public Element { public: ICMPSendPings(); @@ -68,5 +72,9 @@ String _data; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/checkipheader.cc click-1.2.4/elements/ip/checkipheader.cc --- click-1.2.4.orig/elements/ip/checkipheader.cc Tue May 21 17:31:32 2002 +++ click-1.2.4/elements/ip/checkipheader.cc Sun Jun 2 00:12:22 2002 @@ -29,6 +29,10 @@ # include #endif +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + const char *CheckIPHeader::reason_texts[NREASONS] = { "tiny packet", "bad IP version", "bad IP header length", "bad IP length", "bad IP checksum", "bad source address" diff -urN click-1.2.4.orig/elements/ip/checkipheader.hh click-1.2.4/elements/ip/checkipheader.hh --- click-1.2.4.orig/elements/ip/checkipheader.hh Wed Apr 3 11:27:59 2002 +++ click-1.2.4/elements/ip/checkipheader.hh Sun Jun 2 00:11:42 2002 @@ -62,6 +62,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class CheckIPHeader : public Element { public: CheckIPHeader(); @@ -106,5 +110,9 @@ friend class CheckIPHeader2; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/checkipheader2.cc click-1.2.4/elements/ip/checkipheader2.cc --- click-1.2.4.orig/elements/ip/checkipheader2.cc Tue May 21 17:31:32 2002 +++ click-1.2.4/elements/ip/checkipheader2.cc Sun Jun 2 00:10:24 2002 @@ -24,6 +24,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + CheckIPHeader2::CheckIPHeader2() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/ip/checkipheader2.hh click-1.2.4/elements/ip/checkipheader2.hh --- click-1.2.4.orig/elements/ip/checkipheader2.hh Wed Apr 3 11:28:34 2002 +++ click-1.2.4/elements/ip/checkipheader2.hh Sun Jun 2 00:10:05 2002 @@ -64,6 +64,10 @@ #include "elements/ip/checkipheader.hh" +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class CheckIPHeader2 : public CheckIPHeader { public: CheckIPHeader2(); @@ -80,5 +84,9 @@ Packet *pull(int); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/decipttl.cc click-1.2.4/elements/ip/decipttl.cc --- click-1.2.4.orig/elements/ip/decipttl.cc Tue May 21 17:31:32 2002 +++ click-1.2.4/elements/ip/decipttl.cc Sun Jun 2 00:13:43 2002 @@ -20,6 +20,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + DecIPTTL::DecIPTTL() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/ip/decipttl.hh click-1.2.4/elements/ip/decipttl.hh --- click-1.2.4.orig/elements/ip/decipttl.hh Tue Sep 25 01:31:34 2001 +++ click-1.2.4/elements/ip/decipttl.hh Sun Jun 2 00:13:26 2002 @@ -29,6 +29,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class DecIPTTL : public Element { public: DecIPTTL(); @@ -51,5 +55,9 @@ uatomic32_t _drops; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/fixipsrc.cc click-1.2.4/elements/ip/fixipsrc.cc --- click-1.2.4.orig/elements/ip/fixipsrc.cc Tue May 21 17:31:32 2002 +++ click-1.2.4/elements/ip/fixipsrc.cc Sun Jun 2 00:14:33 2002 @@ -23,6 +23,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + FixIPSrc::FixIPSrc() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/ip/fixipsrc.hh click-1.2.4/elements/ip/fixipsrc.hh --- click-1.2.4.orig/elements/ip/fixipsrc.hh Thu Feb 7 11:14:07 2002 +++ click-1.2.4/elements/ip/fixipsrc.hh Sun Jun 2 00:14:16 2002 @@ -26,6 +26,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class FixIPSrc : public Element { struct in_addr _my_ip; @@ -42,5 +46,9 @@ Packet *simple_action(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/getipaddress.cc click-1.2.4/elements/ip/getipaddress.cc --- click-1.2.4.orig/elements/ip/getipaddress.cc Tue May 21 17:31:39 2002 +++ click-1.2.4/elements/ip/getipaddress.cc Sun Jun 2 00:15:46 2002 @@ -22,6 +22,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + GetIPAddress::GetIPAddress() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/ip/getipaddress.hh click-1.2.4/elements/ip/getipaddress.hh --- click-1.2.4.orig/elements/ip/getipaddress.hh Thu Feb 7 11:14:10 2002 +++ click-1.2.4/elements/ip/getipaddress.hh Sun Jun 2 00:15:10 2002 @@ -22,6 +22,9 @@ * =a ARPQuerier, LookupIPRoute, SetIPAddress, StoreIPAddress */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif class GetIPAddress : public Element { @@ -41,5 +44,9 @@ Packet *simple_action(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/ipaddrrewriter.cc click-1.2.4/elements/ip/ipaddrrewriter.cc --- click-1.2.4.orig/elements/ip/ipaddrrewriter.cc Tue May 21 17:31:39 2002 +++ click-1.2.4/elements/ip/ipaddrrewriter.cc Sun Jun 2 00:16:41 2002 @@ -24,6 +24,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + void IPAddrRewriter::IPAddrMapping::apply(WritablePacket *p) { diff -urN click-1.2.4.orig/elements/ip/ipaddrrewriter.hh click-1.2.4/elements/ip/ipaddrrewriter.hh --- click-1.2.4.orig/elements/ip/ipaddrrewriter.hh Wed Apr 24 10:07:07 2002 +++ click-1.2.4/elements/ip/ipaddrrewriter.hh Sun Jun 2 00:16:26 2002 @@ -79,6 +79,10 @@ =a TCPRewriter, IPRewriterPatterns, RoundRobinIPMapper, FTPPortMapper, ICMPRewriter, ICMPPingRewriter */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class IPAddrRewriter : public IPRw { public: class IPAddrMapping : public Mapping { public: @@ -142,5 +146,9 @@ IPFlowID rev(IPAddress(0), 0, in_flow.daddr(), 0); return _map[rev]; } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/ipclassifier.cc click-1.2.4/elements/ip/ipclassifier.cc --- click-1.2.4.orig/elements/ip/ipclassifier.cc Thu Feb 7 11:20:27 2002 +++ click-1.2.4/elements/ip/ipclassifier.cc Sun Jun 2 00:18:43 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + IPClassifier::IPClassifier() { // no MOD_INC_USE_COUNT; rely on Classifier diff -urN click-1.2.4.orig/elements/ip/ipclassifier.hh click-1.2.4/elements/ip/ipclassifier.hh --- click-1.2.4.orig/elements/ip/ipclassifier.hh Thu Feb 7 11:14:16 2002 +++ click-1.2.4/elements/ip/ipclassifier.hh Sun Jun 2 00:18:24 2002 @@ -194,6 +194,10 @@ =a Classifier, IPFilter, CheckIPHeader, MarkIPHeader, CheckIPHeader2, tcpdump(1) */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class IPClassifier : public IPFilter { public: @@ -208,5 +212,9 @@ int configure(Vector &, ErrorHandler *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/ipencap.cc click-1.2.4/elements/ip/ipencap.cc --- click-1.2.4.orig/elements/ip/ipencap.cc Thu Feb 7 11:20:34 2002 +++ click-1.2.4/elements/ip/ipencap.cc Sun Jun 2 00:23:23 2002 @@ -23,6 +23,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + IPEncap::IPEncap() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/ip/ipencap.hh click-1.2.4/elements/ip/ipencap.hh --- click-1.2.4.orig/elements/ip/ipencap.hh Tue May 21 17:31:39 2002 +++ click-1.2.4/elements/ip/ipencap.hh Sun Jun 2 00:23:10 2002 @@ -77,6 +77,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class IPEncap : public Element { public: IPEncap(); @@ -105,5 +109,9 @@ static String read_handler(Element *, void *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/ipfilter.cc click-1.2.4/elements/ip/ipfilter.cc --- click-1.2.4.orig/elements/ip/ipfilter.cc Tue May 21 17:31:40 2002 +++ click-1.2.4/elements/ip/ipfilter.cc Sun Jun 2 00:22:33 2002 @@ -26,6 +26,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + static HashMap *wordmap; static int ip_filter_count; #define WT(t, d) ((t << WT_TYPE_SHIFT) | d) diff -urN click-1.2.4.orig/elements/ip/ipfilter.hh click-1.2.4/elements/ip/ipfilter.hh --- click-1.2.4.orig/elements/ip/ipfilter.hh Wed Apr 24 09:51:29 2002 +++ click-1.2.4/elements/ip/ipfilter.hh Sun Jun 2 00:22:14 2002 @@ -107,6 +107,10 @@ IPClassifier, Classifier, CheckIPHeader, MarkIPHeader, CheckIPHeader2, AddressInfo, tcpdump(1) */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class IPFilter : public Classifier { public: IPFilter(); @@ -228,5 +232,9 @@ else return _type == TYPE_HOST || _type == TYPE_TOS || _type == TYPE_IPFRAG; } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/ipfragmenter.cc click-1.2.4/elements/ip/ipfragmenter.cc --- click-1.2.4.orig/elements/ip/ipfragmenter.cc Tue May 21 17:31:40 2002 +++ click-1.2.4/elements/ip/ipfragmenter.cc Sun Jun 2 00:24:25 2002 @@ -24,6 +24,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + IPFragmenter::IPFragmenter() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/ip/ipfragmenter.hh click-1.2.4/elements/ip/ipfragmenter.hh --- click-1.2.4.orig/elements/ip/ipfragmenter.hh Wed May 15 21:51:22 2002 +++ click-1.2.4/elements/ip/ipfragmenter.hh Sun Jun 2 00:24:07 2002 @@ -35,6 +35,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class IPFragmenter : public Element { bool _honor_df; @@ -65,5 +69,9 @@ void push(int, Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/ipgwoptions.cc click-1.2.4/elements/ip/ipgwoptions.cc --- click-1.2.4.orig/elements/ip/ipgwoptions.cc Tue May 21 17:31:40 2002 +++ click-1.2.4/elements/ip/ipgwoptions.cc Sun Jun 2 00:25:24 2002 @@ -25,6 +25,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + IPGWOptions::IPGWOptions() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/ip/ipgwoptions.hh click-1.2.4/elements/ip/ipgwoptions.hh --- click-1.2.4.orig/elements/ip/ipgwoptions.hh Thu Feb 7 11:15:36 2002 +++ click-1.2.4/elements/ip/ipgwoptions.hh Sun Jun 2 00:25:00 2002 @@ -33,6 +33,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class IPGWOptions : public Element { uatomic32_t _drops; @@ -58,5 +62,9 @@ Packet *simple_action(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/ipinputcombo.cc click-1.2.4/elements/ip/ipinputcombo.cc --- click-1.2.4.orig/elements/ip/ipinputcombo.cc Tue May 21 17:31:40 2002 +++ click-1.2.4/elements/ip/ipinputcombo.cc Sun Jun 2 00:26:08 2002 @@ -25,6 +25,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + IPInputCombo::IPInputCombo() : _bad_src(0) { diff -urN click-1.2.4.orig/elements/ip/ipinputcombo.hh click-1.2.4/elements/ip/ipinputcombo.hh --- click-1.2.4.orig/elements/ip/ipinputcombo.hh Thu Feb 7 11:15:36 2002 +++ click-1.2.4/elements/ip/ipinputcombo.hh Sun Jun 2 00:25:53 2002 @@ -25,6 +25,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class IPInputCombo : public Element { uatomic32_t _drops; @@ -54,5 +58,9 @@ Packet *pull(int); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/ipmirror.cc click-1.2.4/elements/ip/ipmirror.cc --- click-1.2.4.orig/elements/ip/ipmirror.cc Tue May 21 17:31:40 2002 +++ click-1.2.4/elements/ip/ipmirror.cc Sun Jun 2 00:27:20 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + IPMirror::IPMirror() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/ip/ipmirror.hh click-1.2.4/elements/ip/ipmirror.hh --- click-1.2.4.orig/elements/ip/ipmirror.hh Wed Apr 24 09:52:34 2002 +++ click-1.2.4/elements/ip/ipmirror.hh Sun Jun 2 00:26:56 2002 @@ -24,6 +24,10 @@ */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class IPMirror : public Element { public: @@ -38,5 +42,9 @@ Packet *simple_action(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif // CLICK_IPMIRROR_HH diff -urN click-1.2.4.orig/elements/ip/ipoutputcombo.cc click-1.2.4/elements/ip/ipoutputcombo.cc --- click-1.2.4.orig/elements/ip/ipoutputcombo.cc Thu Feb 7 11:20:38 2002 +++ click-1.2.4/elements/ip/ipoutputcombo.cc Sun Jun 2 00:28:06 2002 @@ -22,6 +22,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + IPOutputCombo::IPOutputCombo() : Element(1, 5) { diff -urN click-1.2.4.orig/elements/ip/ipoutputcombo.hh click-1.2.4/elements/ip/ipoutputcombo.hh --- click-1.2.4.orig/elements/ip/ipoutputcombo.hh Tue May 21 17:31:41 2002 +++ click-1.2.4/elements/ip/ipoutputcombo.hh Sun Jun 2 00:27:46 2002 @@ -40,6 +40,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Address; class IPOutputCombo : public Element { @@ -64,5 +68,9 @@ unsigned _mtu; // Fragmenter }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/ipprint.cc click-1.2.4/elements/ip/ipprint.cc --- click-1.2.4.orig/elements/ip/ipprint.cc Tue May 21 17:31:41 2002 +++ click-1.2.4/elements/ip/ipprint.cc Sun Jun 2 00:29:13 2002 @@ -33,6 +33,10 @@ # include #endif +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + IPPrint::IPPrint() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/ip/ipprint.hh click-1.2.4/elements/ip/ipprint.hh --- click-1.2.4.orig/elements/ip/ipprint.hh Fri Apr 5 11:52:11 2002 +++ click-1.2.4/elements/ip/ipprint.hh Sun Jun 2 00:28:57 2002 @@ -78,6 +78,10 @@ =a Print, CheckIPHeader */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class IPPrint : public Element { public: IPPrint(); @@ -113,5 +117,9 @@ ErrorHandler *_errh; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/ipratemon.cc click-1.2.4/elements/ip/ipratemon.cc --- click-1.2.4.orig/elements/ip/ipratemon.cc Thu May 2 21:51:35 2002 +++ click-1.2.4/elements/ip/ipratemon.cc Sun Jun 2 00:30:17 2002 @@ -26,6 +26,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + IPRateMonitor::IPRateMonitor() : _count_packets(true), _anno_packets(true), _thresh(1), _memmax(0), _ratio(1), diff -urN click-1.2.4.orig/elements/ip/ipratemon.hh click-1.2.4/elements/ip/ipratemon.hh --- click-1.2.4.orig/elements/ip/ipratemon.hh Tue May 21 17:31:41 2002 +++ click-1.2.4/elements/ip/ipratemon.hh Sun Jun 2 00:30:02 2002 @@ -65,6 +65,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + struct IPRateMonitor_HalfSecondsTimer { static unsigned now() { return click_jiffies() >> 3; } static unsigned freq() { return CLICK_HZ >> 3; } @@ -312,5 +316,9 @@ else update(ip->ip_dst.s_addr, val, p, false, update_ewma); } + +#ifdef CLICK_SIM +} +#endif #endif /* IPRATEMON_HH */ diff -urN click-1.2.4.orig/elements/ip/ipreassembler.cc click-1.2.4/elements/ip/ipreassembler.cc --- click-1.2.4.orig/elements/ip/ipreassembler.cc Fri May 17 17:16:37 2002 +++ click-1.2.4/elements/ip/ipreassembler.cc Sun Jun 2 00:34:15 2002 @@ -37,6 +37,10 @@ #define Q_PACKET_JIFFIES(p) ((p)->timestamp_anno().tv_usec) #define IP_BYTE_OFF(iph) ((ntohs((iph)->ip_off) & IP_OFFMASK) << 3) +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + IPReassembler::IPReassembler() : Element(1, 1), _expire_timer(expire_hook, (void *) this) { diff -urN click-1.2.4.orig/elements/ip/ipreassembler.hh click-1.2.4/elements/ip/ipreassembler.hh --- click-1.2.4.orig/elements/ip/ipreassembler.hh Tue May 21 17:31:41 2002 +++ click-1.2.4/elements/ip/ipreassembler.hh Sun Jun 2 00:33:50 2002 @@ -23,6 +23,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class IPReassembler : public Element { public: IPReassembler(); @@ -88,5 +92,9 @@ && h->ip_src.s_addr == h2->ip_src.s_addr && h->ip_dst.s_addr == h2->ip_dst.s_addr; } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/iproutetable.cc click-1.2.4/elements/ip/iproutetable.cc --- click-1.2.4.orig/elements/ip/iproutetable.cc Fri Feb 8 11:47:40 2002 +++ click-1.2.4/elements/ip/iproutetable.cc Sun Jun 2 00:41:44 2002 @@ -25,6 +25,10 @@ #include #include "iproutetable.hh" +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + void * IPRouteTable::cast(const char *name) { diff -urN click-1.2.4.orig/elements/ip/iproutetable.hh click-1.2.4/elements/ip/iproutetable.hh --- click-1.2.4.orig/elements/ip/iproutetable.hh Fri Feb 8 11:40:47 2002 +++ click-1.2.4/elements/ip/iproutetable.hh Sun Jun 2 00:41:32 2002 @@ -54,6 +54,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class IPRouteTable : public Element { public: void *cast(const char *); @@ -72,5 +76,9 @@ static String table_handler(Element *, void *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/iprw.cc click-1.2.4/elements/ip/iprw.cc --- click-1.2.4.orig/elements/ip/iprw.cc Tue May 21 17:31:42 2002 +++ click-1.2.4/elements/ip/iprw.cc Sat Jun 1 00:08:27 2002 @@ -35,6 +35,9 @@ } #endif +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif // // IPRw::Mapping diff -urN click-1.2.4.orig/elements/ip/iprw.hh click-1.2.4/elements/ip/iprw.hh --- click-1.2.4.orig/elements/ip/iprw.hh Tue May 21 17:31:42 2002 +++ click-1.2.4/elements/ip/iprw.hh Sat Jun 1 00:07:59 2002 @@ -6,6 +6,11 @@ #include #include #include + +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class IPMapper; class IPRw : public Element { public: @@ -275,5 +280,9 @@ { return ((int32_t)(_used - t)) >= 0 || ((int32_t)(_reverse->_used - t)) >= 0; } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/iprwpatterns.cc click-1.2.4/elements/ip/iprwpatterns.cc --- click-1.2.4.orig/elements/ip/iprwpatterns.cc Fri Apr 5 12:00:28 2002 +++ click-1.2.4/elements/ip/iprwpatterns.cc Sun Jun 2 00:43:54 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + IPRewriterPatterns::IPRewriterPatterns() : _name_map(-1) { diff -urN click-1.2.4.orig/elements/ip/iprwpatterns.hh click-1.2.4/elements/ip/iprwpatterns.hh --- click-1.2.4.orig/elements/ip/iprwpatterns.hh Fri Apr 5 11:52:14 2002 +++ click-1.2.4/elements/ip/iprwpatterns.hh Sun Jun 2 00:43:34 2002 @@ -20,6 +20,10 @@ * =a IPRewriter */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class IPRewriterPatterns : public Element { HashMap _name_map; @@ -40,5 +44,9 @@ static IPRw::Pattern *find(Element *, const String &, ErrorHandler *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/lineariplookup.cc click-1.2.4/elements/ip/lineariplookup.cc --- click-1.2.4.orig/elements/ip/lineariplookup.cc Thu Mar 28 21:46:01 2002 +++ click-1.2.4/elements/ip/lineariplookup.cc Sun Jun 2 00:53:26 2002 @@ -24,6 +24,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + LinearIPLookup::LinearIPLookup() { MOD_INC_USE_COUNT; @@ -263,11 +267,11 @@ sa << "# Active routes\n"; for (int i = 0; i < _t.size(); i++) if (!_t[i].addr || _t[i].mask) - sa << _t[i] << '\n'; + sa << _t[i].unparse_addr() << '\n'; if (_redundant.size()) sa << "# Redundant routes\n"; for (int i = 0; i < _redundant.size(); i++) - sa << _redundant[i] << '\n'; + sa << _redundant[i].unparse_addr() << '\n'; return sa.take_string(); } diff -urN click-1.2.4.orig/elements/ip/lineariplookup.hh click-1.2.4/elements/ip/lineariplookup.hh --- click-1.2.4.orig/elements/ip/lineariplookup.hh Fri Feb 8 15:46:24 2002 +++ click-1.2.4/elements/ip/lineariplookup.hh Sun Jun 2 00:45:53 2002 @@ -69,6 +69,10 @@ #define IP_RT_CACHE2 1 +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class LinearIPLookup : public IPRouteTable { public: LinearIPLookup(); @@ -115,5 +119,9 @@ int lookup_entry(IPAddress) const; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/lookupiproute.cc click-1.2.4/elements/ip/lookupiproute.cc --- click-1.2.4.orig/elements/ip/lookupiproute.cc Fri Feb 8 10:51:44 2002 +++ click-1.2.4/elements/ip/lookupiproute.cc Sun Jun 2 00:55:20 2002 @@ -24,6 +24,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + StaticIPLookup::StaticIPLookup() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/ip/lookupiproute.hh click-1.2.4/elements/ip/lookupiproute.hh --- click-1.2.4.orig/elements/ip/lookupiproute.hh Fri Feb 8 11:04:15 2002 +++ click-1.2.4/elements/ip/lookupiproute.hh Sun Jun 2 00:55:03 2002 @@ -25,6 +25,10 @@ #include "lineariplookup.hh" +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class StaticIPLookup : public LinearIPLookup { public: StaticIPLookup(); @@ -39,5 +43,9 @@ int remove_route(IPAddress, IPAddress, IPAddress, int, ErrorHandler *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/lookupiproute2.cc click-1.2.4/elements/ip/lookupiproute2.cc --- click-1.2.4.orig/elements/ip/lookupiproute2.cc Thu Feb 7 11:20:43 2002 +++ click-1.2.4/elements/ip/lookupiproute2.cc Sun Jun 2 00:54:22 2002 @@ -24,6 +24,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + LookupIPRoute2::LookupIPRoute2() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/ip/lookupiproute2.hh click-1.2.4/elements/ip/lookupiproute2.hh --- click-1.2.4.orig/elements/ip/lookupiproute2.hh Thu Feb 7 11:16:07 2002 +++ click-1.2.4/elements/ip/lookupiproute2.hh Sun Jun 2 00:54:00 2002 @@ -17,6 +17,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class LookupIPRoute2 : public Element { public: LookupIPRoute2(); @@ -27,6 +31,10 @@ LookupIPRoute2 *clone() const { return new LookupIPRoute2; } int configure(Vector &, ErrorHandler *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/markipce.cc click-1.2.4/elements/ip/markipce.cc --- click-1.2.4.orig/elements/ip/markipce.cc Tue May 21 17:31:42 2002 +++ click-1.2.4/elements/ip/markipce.cc Sun Jun 2 00:56:30 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + MarkIPCE::MarkIPCE() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/ip/markipce.hh click-1.2.4/elements/ip/markipce.hh --- click-1.2.4.orig/elements/ip/markipce.hh Tue Sep 25 01:31:32 2001 +++ click-1.2.4/elements/ip/markipce.hh Sun Jun 2 00:56:11 2002 @@ -20,6 +20,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class MarkIPCE : public Element { public: MarkIPCE(); @@ -43,5 +47,9 @@ static String read_handler(Element *, void *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/markipheader.cc click-1.2.4/elements/ip/markipheader.cc --- click-1.2.4.orig/elements/ip/markipheader.cc Tue May 21 17:31:42 2002 +++ click-1.2.4/elements/ip/markipheader.cc Sun Jun 2 00:57:55 2002 @@ -20,6 +20,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + MarkIPHeader::MarkIPHeader() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/ip/markipheader.hh click-1.2.4/elements/ip/markipheader.hh --- click-1.2.4.orig/elements/ip/markipheader.hh Thu Feb 7 11:16:13 2002 +++ click-1.2.4/elements/ip/markipheader.hh Sun Jun 2 00:57:32 2002 @@ -19,6 +19,10 @@ #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class MarkIPHeader : public Element { int _offset; @@ -35,5 +39,9 @@ Packet *simple_action(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/oldipfragmenter.cc click-1.2.4/elements/ip/oldipfragmenter.cc --- click-1.2.4.orig/elements/ip/oldipfragmenter.cc Tue May 21 17:31:42 2002 +++ click-1.2.4/elements/ip/oldipfragmenter.cc Sun Jun 2 00:58:44 2002 @@ -22,6 +22,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + OldIPFragmenter::OldIPFragmenter() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/ip/oldipfragmenter.hh click-1.2.4/elements/ip/oldipfragmenter.hh --- click-1.2.4.orig/elements/ip/oldipfragmenter.hh Wed May 15 21:51:39 2002 +++ click-1.2.4/elements/ip/oldipfragmenter.hh Sun Jun 2 00:58:28 2002 @@ -35,6 +35,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class OldIPFragmenter : public Element { bool _honor_df; @@ -65,5 +69,9 @@ void push(int, Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/radixiplookup.cc click-1.2.4/elements/ip/radixiplookup.cc --- click-1.2.4.orig/elements/ip/radixiplookup.cc Fri Apr 5 12:00:29 2002 +++ click-1.2.4/elements/ip/radixiplookup.cc Sun Jun 2 00:59:59 2002 @@ -26,6 +26,10 @@ #include #include "radixiplookup.hh" +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + RadixIPLookup::RadixIPLookup() : _entries(0) { diff -urN click-1.2.4.orig/elements/ip/radixiplookup.hh click-1.2.4/elements/ip/radixiplookup.hh --- click-1.2.4.orig/elements/ip/radixiplookup.hh Wed Apr 24 10:10:28 2002 +++ click-1.2.4/elements/ip/radixiplookup.hh Sun Jun 2 00:59:40 2002 @@ -4,6 +4,11 @@ #include #include #include "iproutetable.hh" + +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Radix; /* @@ -216,5 +221,9 @@ { return (x >> k) & (0xffffffff >> (KEYSIZE-j)); } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/rfc2507c.cc click-1.2.4/elements/ip/rfc2507c.cc --- click-1.2.4.orig/elements/ip/rfc2507c.cc Wed May 15 18:13:55 2002 +++ click-1.2.4/elements/ip/rfc2507c.cc Sun Jun 2 01:01:02 2002 @@ -21,6 +21,10 @@ #endif #include "rfc2507c.hh" +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + RFC2507c::RFC2507c() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/ip/rfc2507c.hh click-1.2.4/elements/ip/rfc2507c.hh --- click-1.2.4.orig/elements/ip/rfc2507c.hh Tue May 21 17:31:42 2002 +++ click-1.2.4/elements/ip/rfc2507c.hh Sun Jun 2 01:00:46 2002 @@ -19,6 +19,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class RFC2507c : public Element { public: @@ -66,5 +70,9 @@ int encodeX(int o, int n, char *p, int &i); Packet *make_compressed(int cid, Packet *p); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/rfc2507d.cc click-1.2.4/elements/ip/rfc2507d.cc --- click-1.2.4.orig/elements/ip/rfc2507d.cc Wed Jul 18 09:49:31 2001 +++ click-1.2.4/elements/ip/rfc2507d.cc Sun Jun 2 01:01:51 2002 @@ -19,6 +19,10 @@ #include "rfc2507d.hh" #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + RFC2507d::RFC2507d() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/ip/rfc2507d.hh click-1.2.4/elements/ip/rfc2507d.hh --- click-1.2.4.orig/elements/ip/rfc2507d.hh Tue May 21 17:31:48 2002 +++ click-1.2.4/elements/ip/rfc2507d.hh Sun Jun 2 01:01:31 2002 @@ -13,6 +13,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class RFC2507d : public Element { public: @@ -51,5 +55,9 @@ void decode(const u_char * &in, unsigned short &); void decode(const u_char * &in, unsigned int &); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/ripsend.cc click-1.2.4/elements/ip/ripsend.cc --- click-1.2.4.orig/elements/ip/ripsend.cc Tue May 21 17:31:48 2002 +++ click-1.2.4/elements/ip/ripsend.cc Sun Jun 2 01:02:43 2002 @@ -22,6 +22,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + RIPSend::RIPSend() : _timer(this) { diff -urN click-1.2.4.orig/elements/ip/ripsend.hh click-1.2.4/elements/ip/ripsend.hh --- click-1.2.4.orig/elements/ip/ripsend.hh Thu Feb 7 11:16:14 2002 +++ click-1.2.4/elements/ip/ripsend.hh Sun Jun 2 01:02:27 2002 @@ -24,6 +24,10 @@ * Note that this is just a tiny piece of a full RIP implementation. */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class RIPSend : public Element { IPAddress _src; // IP header src field @@ -49,5 +53,9 @@ void run_scheduled(); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/rripmapper.cc click-1.2.4/elements/ip/rripmapper.cc --- click-1.2.4.orig/elements/ip/rripmapper.cc Fri Apr 5 12:00:30 2002 +++ click-1.2.4/elements/ip/rripmapper.cc Sun Jun 2 01:03:29 2002 @@ -20,6 +20,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + RoundRobinIPMapper::RoundRobinIPMapper() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/ip/rripmapper.hh click-1.2.4/elements/ip/rripmapper.hh --- click-1.2.4.orig/elements/ip/rripmapper.hh Fri Apr 5 11:52:16 2002 +++ click-1.2.4/elements/ip/rripmapper.hh Sun Jun 2 01:03:12 2002 @@ -20,6 +20,10 @@ * * =a IPRewriter, TCPRewriter, IPRewriterPatterns */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class RoundRobinIPMapper : public Element, public IPMapper { Vector _patterns; @@ -44,5 +48,9 @@ IPRw::Mapping *get_map(IPRw *, int ip_p, const IPFlowID &, Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/setipaddress.cc click-1.2.4/elements/ip/setipaddress.cc --- click-1.2.4.orig/elements/ip/setipaddress.cc Thu Feb 7 11:20:48 2002 +++ click-1.2.4/elements/ip/setipaddress.cc Sun Jun 2 01:04:24 2002 @@ -20,6 +20,10 @@ #include "setipaddress.hh" #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + SetIPAddress::SetIPAddress() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/ip/setipaddress.hh click-1.2.4/elements/ip/setipaddress.hh --- click-1.2.4.orig/elements/ip/setipaddress.hh Thu Mar 14 13:41:56 2002 +++ click-1.2.4/elements/ip/setipaddress.hh Sun Jun 2 01:04:06 2002 @@ -15,6 +15,10 @@ * =a StoreIPAddress, GetIPAddress */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class SetIPAddress : public Element { IPAddress _ip; @@ -33,5 +37,9 @@ Packet *simple_action(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/setipchecksum.cc click-1.2.4/elements/ip/setipchecksum.cc --- click-1.2.4.orig/elements/ip/setipchecksum.cc Tue May 21 17:31:48 2002 +++ click-1.2.4/elements/ip/setipchecksum.cc Sun Jun 2 01:05:16 2002 @@ -20,6 +20,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + SetIPChecksum::SetIPChecksum() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/ip/setipchecksum.hh click-1.2.4/elements/ip/setipchecksum.hh --- click-1.2.4.orig/elements/ip/setipchecksum.hh Thu Mar 14 13:42:04 2002 +++ click-1.2.4/elements/ip/setipchecksum.hh Sun Jun 2 01:04:55 2002 @@ -19,6 +19,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class SetIPChecksum : public Element { public: SetIPChecksum(); @@ -30,5 +34,9 @@ Packet *simple_action(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/setipdscp.cc click-1.2.4/elements/ip/setipdscp.cc --- click-1.2.4.orig/elements/ip/setipdscp.cc Tue May 21 17:31:49 2002 +++ click-1.2.4/elements/ip/setipdscp.cc Sun Jun 2 01:06:12 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + SetIPDSCP::SetIPDSCP() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/ip/setipdscp.hh click-1.2.4/elements/ip/setipdscp.hh --- click-1.2.4.orig/elements/ip/setipdscp.hh Thu Mar 14 13:42:12 2002 +++ click-1.2.4/elements/ip/setipdscp.hh Sun Jun 2 01:05:54 2002 @@ -17,6 +17,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class SetIPDSCP : public Element { unsigned char _dscp; @@ -41,5 +45,9 @@ Packet *pull(int); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/setrandipaddress.cc click-1.2.4/elements/ip/setrandipaddress.cc --- click-1.2.4.orig/elements/ip/setrandipaddress.cc Thu Feb 7 11:20:50 2002 +++ click-1.2.4/elements/ip/setrandipaddress.cc Sun Jun 2 01:07:52 2002 @@ -20,6 +20,10 @@ #include "setrandipaddress.hh" #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + SetRandIPAddress::SetRandIPAddress() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/ip/setrandipaddress.hh click-1.2.4/elements/ip/setrandipaddress.hh --- click-1.2.4.orig/elements/ip/setrandipaddress.hh Thu Feb 7 11:16:21 2002 +++ click-1.2.4/elements/ip/setrandipaddress.hh Sun Jun 2 01:07:36 2002 @@ -17,6 +17,10 @@ * =a StoreIPAddress, GetIPAddress, SetIPAddress */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class SetRandIPAddress : public Element { IPAddress _ip; @@ -38,5 +42,9 @@ Packet *simple_action(Packet *); IPAddress pick(); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/sortediplookup.cc click-1.2.4/elements/ip/sortediplookup.cc --- click-1.2.4.orig/elements/ip/sortediplookup.cc Thu Mar 28 21:46:05 2002 +++ click-1.2.4/elements/ip/sortediplookup.cc Sun Jun 2 01:09:54 2002 @@ -23,6 +23,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + SortedIPLookup::SortedIPLookup() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/ip/sortediplookup.hh click-1.2.4/elements/ip/sortediplookup.hh --- click-1.2.4.orig/elements/ip/sortediplookup.hh Fri Feb 8 15:48:02 2002 +++ click-1.2.4/elements/ip/sortediplookup.hh Sun Jun 2 01:09:38 2002 @@ -22,6 +22,10 @@ #include "lineariplookup.hh" +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class SortedIPLookup : public LinearIPLookup { public: SortedIPLookup(); @@ -43,5 +47,9 @@ void sort_table(); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/storeipaddress.cc click-1.2.4/elements/ip/storeipaddress.cc --- click-1.2.4.orig/elements/ip/storeipaddress.cc Thu Feb 7 11:20:50 2002 +++ click-1.2.4/elements/ip/storeipaddress.cc Sun Jun 2 01:10:38 2002 @@ -20,6 +20,10 @@ #include "storeipaddress.hh" #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + StoreIPAddress::StoreIPAddress() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/ip/storeipaddress.hh click-1.2.4/elements/ip/storeipaddress.hh --- click-1.2.4.orig/elements/ip/storeipaddress.hh Thu Feb 7 11:16:22 2002 +++ click-1.2.4/elements/ip/storeipaddress.hh Sun Jun 2 01:10:22 2002 @@ -13,6 +13,10 @@ * at offset OFFSET. */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class StoreIPAddress : public Element { unsigned _offset; @@ -31,5 +35,9 @@ Packet *simple_action(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/stripipheader.cc click-1.2.4/elements/ip/stripipheader.cc --- click-1.2.4.orig/elements/ip/stripipheader.cc Tue May 21 17:31:49 2002 +++ click-1.2.4/elements/ip/stripipheader.cc Sun Jun 2 01:11:23 2002 @@ -19,6 +19,10 @@ #include "stripipheader.hh" #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + StripIPHeader::StripIPHeader() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/ip/stripipheader.hh click-1.2.4/elements/ip/stripipheader.hh --- click-1.2.4.orig/elements/ip/stripipheader.hh Wed Nov 1 17:35:25 2000 +++ click-1.2.4/elements/ip/stripipheader.hh Sun Jun 2 01:11:04 2002 @@ -14,6 +14,10 @@ #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class StripIPHeader : public Element { public: @@ -27,5 +31,9 @@ Packet *simple_action(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/ip/unstripipheader.cc click-1.2.4/elements/ip/unstripipheader.cc --- click-1.2.4.orig/elements/ip/unstripipheader.cc Tue May 21 17:31:49 2002 +++ click-1.2.4/elements/ip/unstripipheader.cc Sun Jun 2 01:11:50 2002 @@ -19,6 +19,10 @@ #include "unstripipheader.hh" #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + UnstripIPHeader::UnstripIPHeader() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/ip/unstripipheader.hh click-1.2.4/elements/ip/unstripipheader.hh --- click-1.2.4.orig/elements/ip/unstripipheader.hh Wed Nov 1 17:35:26 2000 +++ click-1.2.4/elements/ip/unstripipheader.hh Sun Jun 2 01:12:11 2002 @@ -16,6 +16,10 @@ #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class UnstripIPHeader : public Element { public: UnstripIPHeader(); @@ -27,5 +31,9 @@ Packet *simple_action(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/simclick/fakepcap.h click-1.2.4/elements/simclick/fakepcap.h --- click-1.2.4.orig/elements/simclick/fakepcap.h Wed Dec 31 17:00:00 1969 +++ click-1.2.4/elements/simclick/fakepcap.h Fri May 31 12:27:25 2002 @@ -0,0 +1,53 @@ +#ifndef FAKEPCAP_H +#define FAKEPCAP_H + +struct pcap_t; +#define pcap_fileno(p) -1 +#define pcap_close(p) (void)0 +#define pcap_open_live(a,b,c,d,e) 0 +#define pcap_open_offline(a,b) 0 +#define pcap_dispatch(a,b,c,d) 0 +#define PCAP_ERRBUF_SIZE 16 + + +#define FAKE_TCPDUMP_MAGIC 0xa1b2c3d4 +#define FAKE_PCAP_VERSION_MAJOR 2 +#define FAKE_PCAP_VERSION_MINOR 4 + +#define FAKE_DLT_EN10MB 1 /* Ethernet (10Mb) */ +#define FAKE_DLT_RAW 12 /* raw IP */ + +/* + * The first record in the file contains saved values for some + * of the flags used in the printout phases of tcpdump. + * Many fields here are 32 bit ints so compilers won't insert unwanted + * padding; these files need to be interchangeable across architectures. + */ +struct fake_pcap_file_header { + u_int32_t magic; + u_int16_t version_major; + u_int16_t version_minor; + int32_t thiszone; /* gmt to local correction */ + u_int32_t sigfigs; /* accuracy of timestamps */ + u_int32_t snaplen; /* max length saved portion of each pkt */ + u_int32_t linktype; /* data link type (DLT_*) */ +}; + +struct fake_bpf_timeval +{ + u_int32_t tv_sec; + u_int32_t tv_usec; +}; + +/* + * Each packet in the dump file is prepended with this generic header. + * This gets around the problem of different headers for different + * packet interfaces. + */ +struct fake_pcap_pkthdr { + struct fake_bpf_timeval ts; /* time stamp */ + u_int32_t caplen; /* length of portion present */ + u_int32_t len; /* length this packet (off wire) */ +}; + +#endif diff -urN click-1.2.4.orig/elements/simclick/fromsimdevice.cc click-1.2.4/elements/simclick/fromsimdevice.cc --- click-1.2.4.orig/elements/simclick/fromsimdevice.cc Wed Dec 31 17:00:00 1969 +++ click-1.2.4/elements/simclick/fromsimdevice.cc Wed Jun 5 17:27:49 2002 @@ -0,0 +1,157 @@ +/* + * 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 +#include +#include +#include "fromsimdevice.hh" +#include "tosimdevice.hh" +#include +#include +#include +#include +#include +#include + +#include + +using namespace CLICKSIM; + +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(const 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); + if (_fd < 0) return -1; + // 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) +{ + static char bcast_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + + // 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); + p->set_sim_packetinfo(pinfo); + output(0).push(p); + + return result; +} + +ELEMENT_REQUIRES(simclick) +EXPORT_ELEMENT(FromSimDevice) + diff -urN click-1.2.4.orig/elements/simclick/fromsimdevice.hh click-1.2.4/elements/simclick/fromsimdevice.hh --- click-1.2.4.orig/elements/simclick/fromsimdevice.hh Wed Dec 31 17:00:00 1969 +++ click-1.2.4/elements/simclick/fromsimdevice.hh Wed Jun 5 15:45:23 2002 @@ -0,0 +1,87 @@ +#ifndef FROMSIMDEVICE_HH +#define FROMSIMDEVICE_HH + +/***************************************************************************** + * 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) */ + +#include +#include + +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + +class FromSimDevice : public Element { + + String _ifname; + int _packetbuf_size; + int _fd; + unsigned char *_packetbuf; + + static void set_annotations(Packet *); + // 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(const 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); +}; + +#ifdef CLICK_SIM +} +#endif + +#endif diff -urN click-1.2.4.orig/elements/simclick/tosimdevice.cc click-1.2.4/elements/simclick/tosimdevice.cc --- click-1.2.4.orig/elements/simclick/tosimdevice.cc Wed Dec 31 17:00:00 1969 +++ click-1.2.4/elements/simclick/tosimdevice.cc Wed Jun 5 17:28:09 2002 @@ -0,0 +1,158 @@ +/* + * tosimdevice.{cc,hh} -- writes packets to simulated network devices + * + */ + +/***************************************************************************** + * 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 +#include + +using namespace CLICKSIM; + +ToSimDevice::ToSimDevice() + : Element(1, 0), _fd(-1), _my_fd(false), _task(this), _encap_type(SIMCLICK_PTYPE_ETHER) +{ + MOD_INC_USE_COUNT; +} + +ToSimDevice::~ToSimDevice() +{ + MOD_DEC_USE_COUNT; + uninitialize(); +} + +ToSimDevice * +ToSimDevice::clone() const +{ + return new ToSimDevice; +} + +int +ToSimDevice::configure(const Vector &conf, ErrorHandler *errh) +{ + String encap_type; + if (cp_va_parse(conf, this, errh, + cpString, "interface name", &_ifname, + cpOptional, + cpWord, "encapsulation type",&encap_type, + 0) < 0) + return -1; + if (!_ifname) + return errh->error("interface not set"); + if (!encap_type || encap_type == "ETHER") + _encap_type = SIMCLICK_PTYPE_ETHER; + else if (encap_type == "IP") + _encap_type = SIMCLICK_PTYPE_IP; + else + return errh->error("bad encapsulation type, expected `ETHER' or `IP'"); + + return 0; +} + +int +ToSimDevice::initialize(ErrorHandler *errh) +{ + _fd = -1; + if (!_ifname) + return errh->error("interface not set"); + + // Get the simulator ifid + Router* myrouter = router(); + _fd = myrouter->sim_get_ifid(_ifname); + if (_fd < 0) return -1; + + _my_fd = true; + if (input_is_pull(0)) + ScheduleInfo::join_scheduler(this, &_task, errh); + return 0; +} + +void +ToSimDevice::uninitialize() +{ + _task.unschedule(); +} + +void +ToSimDevice::send_packet(Packet *p) +{ + Router* myrouter = router(); + int retval; + // We send out either ethernet or IP + retval = myrouter->sim_write(_fd,_encap_type,p->data(),p->length(), + p->get_sim_packetinfo()); + p->kill(); +} + +void +ToSimDevice::push(int, Packet *p) +{ + assert(p->length() >= 14); + //fprintf(stderr,"Hey!!! Pushing!!!\n"); + send_packet(p); +} + +void +ToSimDevice::run_scheduled() +{ + // XXX reduce tickets when idle + Router* myrouter = router(); + if (myrouter->sim_if_ready(_fd)) { + //fprintf(stderr,"Hey!!! Pulling ready!!!\n"); + if (Packet *p = input(0).pull()) { + //fprintf(stderr,"Hey!!! Sending a packet!!!\n"); + send_packet(p); + } + } + + _task.fast_reschedule(); +} + +void +ToSimDevice::add_handlers() +{ + if (input_is_pull(0)) + add_task_handlers(&_task); +} + +ELEMENT_REQUIRES(FromSimDevice simclick) +EXPORT_ELEMENT(ToSimDevice) diff -urN click-1.2.4.orig/elements/simclick/tosimdevice.hh click-1.2.4/elements/simclick/tosimdevice.hh --- click-1.2.4.orig/elements/simclick/tosimdevice.hh Wed Dec 31 17:00:00 1969 +++ click-1.2.4/elements/simclick/tosimdevice.hh Wed Jun 5 15:44:24 2002 @@ -0,0 +1,98 @@ +#ifndef TOSIMDEVICE_HH +#define TOSIMDEVICE_HH + +/***************************************************************************** + * 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 "tosimdevice.hh" + +/* + * =title ToSimDevice.u + * =c + * ToSimDevice(DEVNAME) + * =s devices + * sends packets to simulated network device + * =d + * + * This manual page describes the ToSimDevice element. + * + * This element will only work with the click simulator interface. + * + * =a + * FromSimDevice.u */ + + +/* + * Write packets to a simulated network interface. + * Expects packets that already have an ether header. + * Can push or pull. + */ + +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + +class ToSimDevice : public Element { public: + + ToSimDevice(); + ~ToSimDevice(); + + const char *class_name() const { return "ToSimDevice"; } + const char *processing() const { return AGNOSTIC; } + //const char *flags() const { return "S2"; } + + ToSimDevice *clone() const; + int configure_phase() const { return CONFIGURE_PHASE_DEFAULT; } + int configure(const Vector &, ErrorHandler *); + int initialize(ErrorHandler *); + void uninitialize(); + void add_handlers(); + + String ifname() const { return _ifname; } + int fd() const { return _fd; } + + void push(int port, Packet *); + void run_scheduled(); + + private: + + String _ifname; + int _fd; + bool _my_fd; + Task _task; + int _encap_type; + + void send_packet(Packet *); + +}; + +#ifdef CLICK_SIM +} +#endif + +#endif diff -urN click-1.2.4.orig/elements/simclick/tosimdump.cc click-1.2.4/elements/simclick/tosimdump.cc --- click-1.2.4.orig/elements/simclick/tosimdump.cc Wed Dec 31 17:00:00 1969 +++ click-1.2.4/elements/simclick/tosimdump.cc Wed Jun 5 16:34:09 2002 @@ -0,0 +1,172 @@ +/* + * tosimdump.{cc,hh} -- element writes packets to tcpdump-like file + * Largely copied from the todump element included with the Click distribution + * + */ + +/***************************************************************************** + * 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 "tosimdump.hh" +#include +#include +#include +#include +#include +#include "fakepcap.h" +#ifdef CLICK_SIM +#include +#include +#endif + +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + +ToSimDump::ToSimDump() + : Element(1, 1), _fp(0) +{ + MOD_INC_USE_COUNT; +} + +ToSimDump::~ToSimDump() +{ + MOD_DEC_USE_COUNT; + uninitialize(); +} + +ToSimDump* +ToSimDump::clone() const +{ + return new ToSimDump; +} + +int +ToSimDump::configure(const Vector &conf, ErrorHandler *errh) +{ + String encap_type; + _snaplen = 2000; + if (cp_va_parse(conf, this, errh, + cpString, "dump filename", &_filename, + cpOptional, + cpUnsigned, "max packet length", &_snaplen, + cpWord, "encapsulation type", &encap_type, + 0) < 0) + return -1; + + if (!encap_type || encap_type == "ETHER") + _encap_type = FAKE_DLT_EN10MB; + else if (encap_type == "IP") + _encap_type = FAKE_DLT_RAW; + else + return errh->error("bad encapsulation type, expected `ETHER' or `IP'"); + +#ifdef CLICK_SIM + Router* myrouter = router(); + simclick_sim mysiminst = myrouter->get_siminst(); + char tmp[255]; + simclick_sim_get_node_name(mysiminst,tmp,255); + _filename = String(tmp) + String("_") + _filename; +#endif + + return 0; +} + +int +ToSimDump::initialize(ErrorHandler *errh) +{ + assert(!_fp); + _fp = fopen(_filename, "wb"); + if (!_fp) + return errh->error("%s: %s", _filename.cc(), strerror(errno)); + + struct fake_pcap_file_header h; + + h.magic = FAKE_TCPDUMP_MAGIC; + h.version_major = FAKE_PCAP_VERSION_MAJOR; + h.version_minor = FAKE_PCAP_VERSION_MINOR; + + h.thiszone = 0; // timestamps are in GMT + h.sigfigs = 0; // XXX accuracy of timestamps? + h.snaplen = _snaplen; + h.linktype = _encap_type; + + size_t wrote_header = fwrite(&h, sizeof(h), 1, _fp); + if (wrote_header != 1) + return errh->error("unable to write to dump file"); + + return 0; +} + +void +ToSimDump::uninitialize() +{ + if (_fp) + fclose(_fp); + _fp = 0; +} + +void +ToSimDump::write_packet(Packet *p) +{ + struct fake_pcap_pkthdr ph; + + const struct timeval &ts = p->timestamp_anno(); + if (!ts.tv_sec && !ts.tv_usec) { + struct timeval now; + click_gettimeofday(&now); + ph.ts.tv_sec = now.tv_sec; + ph.ts.tv_usec = now.tv_usec; + } else { + ph.ts.tv_sec = ts.tv_sec; + ph.ts.tv_usec = ts.tv_usec; + } + + unsigned to_write = p->length(); + if (to_write > _snaplen) + to_write = _snaplen; + ph.caplen = to_write; + ph.len = p->length(); + + // XXX writing to pipe? + if (fwrite(&ph, sizeof(ph), 1, _fp) == 0) + click_chatter("ToSimDump(%s): %s", _filename.cc(), strerror(errno)); + else if (fwrite(p->data(), 1, to_write, _fp) == 0) + click_chatter("ToSimDump(%s): %s", _filename.cc(), strerror(errno)); +} + +Packet * +ToSimDump::simple_action(Packet *p) +{ + write_packet(p); + return p; +} + +ELEMENT_REQUIRES(simclick) +EXPORT_ELEMENT(ToSimDump) diff -urN click-1.2.4.orig/elements/simclick/tosimdump.hh click-1.2.4/elements/simclick/tosimdump.hh --- click-1.2.4.orig/elements/simclick/tosimdump.hh Wed Dec 31 17:00:00 1969 +++ click-1.2.4/elements/simclick/tosimdump.hh Wed Jun 5 15:43:04 2002 @@ -0,0 +1,95 @@ +#ifndef TOSIMDUMP_HH +#define TOSIMDUMP_HH + +/***************************************************************************** + * 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 + +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + +/* + * =c + * + * ToSimDump(FILENAME [, SNAPLEN, ENCAPTYPE]) + * + * =s sinks + * + * writes packets to a tcpdump(1) file + * + * =d + * + * Writes incoming packets to FILENAME in `tcpdump -w' format. This file + * can be read `tcpdump -r', or by FromDump on a later run. + * + * Writes at most SNAPLEN bytes of each packet to the file. The default + * SNAPLEN is 2000. ENCAPTYPE specifies the first header each packet is + * expected to have. This information is stored in the file header, and must + * be correct or tcpdump won't be able to read the file correctly. It can be + * `C' or `C'; default is C. + * + * This element is only available with simclick. + * + * =a + * + * tcpdump(1) */ + +class ToSimDump : public Element { public: + + ToSimDump(); + ~ToSimDump(); + + const char *class_name() const { return "ToSimDump"; } + const char *processing() const { return AGNOSTIC; } + + ToSimDump *clone() const; + int configure(const Vector &, ErrorHandler *); + int initialize(ErrorHandler *); + void uninitialize(); + + Packet *simple_action(Packet *); + + private: + + String _filename; + FILE *_fp; + unsigned _snaplen; + unsigned _encap_type; + + void write_packet(Packet *); + +}; + +#ifdef CLICK_SIM +} +#endif + +#endif diff -urN click-1.2.4.orig/elements/standard/addressinfo.cc click-1.2.4/elements/standard/addressinfo.cc --- click-1.2.4.orig/elements/standard/addressinfo.cc Mon Mar 11 20:41:31 2002 +++ click-1.2.4/elements/standard/addressinfo.cc Wed Jun 5 17:22:56 2002 @@ -29,6 +29,10 @@ # include #endif +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + AddressInfo::AddressInfo() : _map(-1) { @@ -62,6 +66,31 @@ _as.push_back(Info()); } Info &a = _as[_map[name]]; + +#ifdef CLICK_SIM + // Maybe get info from the simulator... + String simif = parts[1]; + String simip; + String simeth; + const char* simsuffix = ":simnet"; + Router* myrouter = router(); + simclick_sim mysiminst = myrouter->get_siminst(); + + int colon = simif.find_right(':'); + if ((colon >= 0) && (simif.substring(colon).lower() == simsuffix)) { + parts.pop_back(); + char tmp[255]; + + simif = simif.substring(0,colon); + simclick_sim_ipaddr_from_name(mysiminst,simif,tmp,255); + simip = tmp; + simclick_sim_macaddr_from_name(mysiminst,simif,tmp,255); + simeth = tmp; + + parts.push_back(simip); + parts.push_back(simeth); + } +#endif for (int j = 1; j < parts.size(); j++) if (cp_ip_address(parts[j], &scrap.ip.c[0])) { diff -urN click-1.2.4.orig/elements/standard/align.cc click-1.2.4/elements/standard/align.cc --- click-1.2.4.orig/elements/standard/align.cc Wed Mar 27 20:22:04 2002 +++ click-1.2.4/elements/standard/align.cc Sun Jun 2 13:52:33 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + Align::Align() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/standard/align.hh click-1.2.4/elements/standard/align.hh --- click-1.2.4.orig/elements/standard/align.hh Tue Mar 26 16:38:30 2002 +++ click-1.2.4/elements/standard/align.hh Sun Jun 2 13:52:18 2002 @@ -23,6 +23,10 @@ * * =a AlignmentInfo, click-align(1) */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Align : public Element { int _offset; @@ -44,5 +48,9 @@ Packet *pull(int); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/alignmentinfo.cc click-1.2.4/elements/standard/alignmentinfo.cc --- click-1.2.4.orig/elements/standard/alignmentinfo.cc Thu Feb 7 11:21:50 2002 +++ click-1.2.4/elements/standard/alignmentinfo.cc Sat Jun 1 00:05:33 2002 @@ -23,6 +23,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + AlignmentInfo::AlignmentInfo() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/standard/averagecounter.cc click-1.2.4/elements/standard/averagecounter.cc --- click-1.2.4.orig/elements/standard/averagecounter.cc Thu Feb 7 11:21:51 2002 +++ click-1.2.4/elements/standard/averagecounter.cc Sun Jun 2 13:53:16 2002 @@ -23,6 +23,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + AverageCounter::AverageCounter() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/standard/averagecounter.hh click-1.2.4/elements/standard/averagecounter.hh --- click-1.2.4.orig/elements/standard/averagecounter.hh Tue Mar 26 16:38:36 2002 +++ click-1.2.4/elements/standard/averagecounter.hh Sun Jun 2 13:53:06 2002 @@ -33,6 +33,10 @@ * Resets the count and rate to zero. */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class AverageCounter : public Element { protected: uatomic32_t _count; @@ -62,5 +66,9 @@ Packet *simple_action(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/bandwidthmeter.cc click-1.2.4/elements/standard/bandwidthmeter.cc --- click-1.2.4.orig/elements/standard/bandwidthmeter.cc Thu Feb 7 11:21:52 2002 +++ click-1.2.4/elements/standard/bandwidthmeter.cc Sun Jun 2 13:54:06 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + BandwidthMeter::BandwidthMeter() : Element(1, 1), _meters(0), _nmeters(0) { diff -urN click-1.2.4.orig/elements/standard/bandwidthmeter.hh click-1.2.4/elements/standard/bandwidthmeter.hh --- click-1.2.4.orig/elements/standard/bandwidthmeter.hh Tue Mar 26 16:38:45 2002 +++ click-1.2.4/elements/standard/bandwidthmeter.hh Sun Jun 2 13:53:53 2002 @@ -32,6 +32,10 @@ * * =a Meter, BandwidthShaper, Shaper, RatedSplitter */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class BandwidthMeter : public Element { protected: RateEWMA _rate; @@ -62,5 +66,9 @@ void push(int port, Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/bandwidthshaper.cc click-1.2.4/elements/standard/bandwidthshaper.cc --- click-1.2.4.orig/elements/standard/bandwidthshaper.cc Thu May 24 18:03:42 2001 +++ click-1.2.4/elements/standard/bandwidthshaper.cc Sun Jun 2 13:54:54 2002 @@ -20,6 +20,10 @@ #include #include "bandwidthshaper.hh" +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + BandwidthShaper::BandwidthShaper() { // no MOD_INC_USE_COUNT; rely on Shaper diff -urN click-1.2.4.orig/elements/standard/bandwidthshaper.hh click-1.2.4/elements/standard/bandwidthshaper.hh --- click-1.2.4.orig/elements/standard/bandwidthshaper.hh Mon Oct 8 22:01:16 2001 +++ click-1.2.4/elements/standard/bandwidthshaper.hh Sun Jun 2 13:54:41 2002 @@ -23,6 +23,10 @@ * * =a Shaper, BandwidthRatedSplitter, BandwidthRatedUnqueue */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class BandwidthShaper : public Shaper { public: @@ -36,5 +40,9 @@ Packet *pull(int); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/burster.cc click-1.2.4/elements/standard/burster.cc --- click-1.2.4.orig/elements/standard/burster.cc Thu Feb 7 11:21:54 2002 +++ click-1.2.4/elements/standard/burster.cc Sun Jun 2 14:40:20 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + Burster::Burster() : Element(1, 1), _npackets(0), _timer(this) { diff -urN click-1.2.4.orig/elements/standard/burster.hh click-1.2.4/elements/standard/burster.hh --- click-1.2.4.orig/elements/standard/burster.hh Tue Mar 26 16:39:01 2002 +++ click-1.2.4/elements/standard/burster.hh Sun Jun 2 14:40:08 2002 @@ -23,6 +23,10 @@ * rates by being bursty. */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Burster : public Element { public: Burster(); @@ -44,5 +48,9 @@ int _interval; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/bwratedsplitter.cc click-1.2.4/elements/standard/bwratedsplitter.cc --- click-1.2.4.orig/elements/standard/bwratedsplitter.cc Thu May 24 18:03:43 2001 +++ click-1.2.4/elements/standard/bwratedsplitter.cc Sun Jun 2 14:41:18 2002 @@ -18,6 +18,10 @@ #include #include "bwratedsplitter.hh" +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + BandwidthRatedSplitter::BandwidthRatedSplitter() { // no MOD_INC_USE_COUNT; rely on RatedSplitter diff -urN click-1.2.4.orig/elements/standard/bwratedsplitter.hh click-1.2.4/elements/standard/bwratedsplitter.hh --- click-1.2.4.orig/elements/standard/bwratedsplitter.hh Tue Mar 26 16:39:19 2002 +++ click-1.2.4/elements/standard/bwratedsplitter.hh Sun Jun 2 14:41:01 2002 @@ -22,6 +22,10 @@ * * =a RatedSplitter, BandwidthMeter, BandwidthShaper, BandwidthRatedUnqueue */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class BandwidthRatedSplitter : public RatedSplitter { public: @@ -35,5 +39,9 @@ void push(int port, Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/bwratedunqueue.cc click-1.2.4/elements/standard/bwratedunqueue.cc --- click-1.2.4.orig/elements/standard/bwratedunqueue.cc Thu May 24 18:03:43 2001 +++ click-1.2.4/elements/standard/bwratedunqueue.cc Sun Jun 2 14:42:54 2002 @@ -19,6 +19,10 @@ #include #include "bwratedunqueue.hh" +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + BandwidthRatedUnqueue::BandwidthRatedUnqueue() { // no MOD_INC_USE_COUNT; rely on RatedUnqueue diff -urN click-1.2.4.orig/elements/standard/bwratedunqueue.hh click-1.2.4/elements/standard/bwratedunqueue.hh --- click-1.2.4.orig/elements/standard/bwratedunqueue.hh Tue Mar 26 16:39:27 2002 +++ click-1.2.4/elements/standard/bwratedunqueue.hh Sun Jun 2 14:42:39 2002 @@ -16,6 +16,10 @@ * * =a RatedUnqueue, Unqueue, BandwidthShaper, BandwidthRatedSplitter */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class BandwidthRatedUnqueue : public RatedUnqueue { public: BandwidthRatedUnqueue(); @@ -27,5 +31,9 @@ void run_scheduled(); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/checkcrc32.cc click-1.2.4/elements/standard/checkcrc32.cc --- click-1.2.4.orig/elements/standard/checkcrc32.cc Thu May 24 18:03:43 2001 +++ click-1.2.4/elements/standard/checkcrc32.cc Sun Jun 2 14:44:30 2002 @@ -22,6 +22,10 @@ #include } +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + CheckCRC32::CheckCRC32() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/standard/checkcrc32.hh click-1.2.4/elements/standard/checkcrc32.hh --- click-1.2.4.orig/elements/standard/checkcrc32.hh Tue Mar 26 16:39:33 2002 +++ click-1.2.4/elements/standard/checkcrc32.hh Sun Jun 2 14:44:12 2002 @@ -16,6 +16,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class EtherAddress; class CheckCRC32 : public Element { @@ -35,5 +39,9 @@ uatomic32_t _drops; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/checklength.cc click-1.2.4/elements/standard/checklength.cc --- click-1.2.4.orig/elements/standard/checklength.cc Thu Feb 7 11:21:55 2002 +++ click-1.2.4/elements/standard/checklength.cc Sun Jun 2 14:45:11 2002 @@ -20,6 +20,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + CheckLength::CheckLength() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/standard/checklength.hh click-1.2.4/elements/standard/checklength.hh --- click-1.2.4.orig/elements/standard/checklength.hh Tue Mar 26 16:39:38 2002 +++ click-1.2.4/elements/standard/checklength.hh Sun Jun 2 14:44:57 2002 @@ -18,6 +18,10 @@ output 1 (or dropped if there is no output 1). */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class CheckLength : public Element { public: CheckLength(); @@ -38,5 +42,9 @@ unsigned _max; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/checkpaint.cc click-1.2.4/elements/standard/checkpaint.cc --- click-1.2.4.orig/elements/standard/checkpaint.cc Thu Feb 7 11:21:56 2002 +++ click-1.2.4/elements/standard/checkpaint.cc Sun Jun 2 14:48:32 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + CheckPaint::CheckPaint() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/standard/checkpaint.hh click-1.2.4/elements/standard/checkpaint.hh --- click-1.2.4.orig/elements/standard/checkpaint.hh Tue Mar 26 16:39:44 2002 +++ click-1.2.4/elements/standard/checkpaint.hh Sun Jun 2 14:48:17 2002 @@ -19,6 +19,10 @@ =a Paint, PaintTee */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class CheckPaint : public Element { public: CheckPaint(); @@ -39,5 +43,9 @@ unsigned char _color; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/classifier.cc click-1.2.4/elements/standard/classifier.cc --- click-1.2.4.orig/elements/standard/classifier.cc Wed Apr 24 09:51:29 2002 +++ click-1.2.4/elements/standard/classifier.cc Sun Jun 2 21:29:30 2002 @@ -28,6 +28,10 @@ // CLASSIFIER::EXPR OPERATIONS // +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + #define UBYTES ((int)sizeof(uint32_t)) bool @@ -107,7 +111,17 @@ no = tmp; } +#ifdef CLICK_SIM +namespace CLICKSIM { +StringAccum & +operator<<(StringAccum &sa, const Classifier::Expr &e); +} +#endif + StringAccum & +#ifdef CLICK_SIM +CLICKSIM:: +#endif operator<<(StringAccum &sa, const Classifier::Expr &e) { char buf[20]; diff -urN click-1.2.4.orig/elements/standard/classifier.hh click-1.2.4/elements/standard/classifier.hh --- click-1.2.4.orig/elements/standard/classifier.hh Wed Apr 24 10:13:06 2002 +++ click-1.2.4/elements/standard/classifier.hh Sun Jun 2 00:21:22 2002 @@ -70,6 +70,10 @@ * * =a IPClassifier, IPFilter */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Classifier : public Element { public: class Expr; @@ -181,5 +185,9 @@ friend class DominatorOptimizer; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/compblock.cc click-1.2.4/elements/standard/compblock.cc --- click-1.2.4.orig/elements/standard/compblock.cc Tue May 21 17:32:00 2002 +++ click-1.2.4/elements/standard/compblock.cc Sun Jun 2 21:59:09 2002 @@ -23,6 +23,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + CompareBlock::CompareBlock() : Element(1, 2), _fwd_weight(0), _rev_weight(1) { diff -urN click-1.2.4.orig/elements/standard/compblock.hh click-1.2.4/elements/standard/compblock.hh --- click-1.2.4.orig/elements/standard/compblock.hh Tue Mar 26 16:39:50 2002 +++ click-1.2.4/elements/standard/compblock.hh Sun Jun 2 21:59:35 2002 @@ -32,6 +32,10 @@ * =a Block, IPRateMonitor */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class CompareBlock : public Element { public: CompareBlock(); @@ -63,6 +67,10 @@ static String fwd_weight_read_handler(Element *e, void *); static String thresh_read_handler(Element *e, void *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/counter.cc click-1.2.4/elements/standard/counter.cc --- click-1.2.4.orig/elements/standard/counter.cc Thu Feb 7 11:22:01 2002 +++ click-1.2.4/elements/standard/counter.cc Sun Jun 2 22:00:20 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + #ifdef HAVE_INT64_TYPES static CpVaParseCmd parse_cmd = cpUnsigned64; #else diff -urN click-1.2.4.orig/elements/standard/counter.hh click-1.2.4/elements/standard/counter.hh --- click-1.2.4.orig/elements/standard/counter.hh Wed Apr 3 15:21:38 2002 +++ click-1.2.4/elements/standard/counter.hh Sun Jun 2 22:01:03 2002 @@ -4,6 +4,10 @@ #include #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class HandlerCall; /* @@ -124,5 +128,9 @@ static int write_handler(const String&, Element*, void*, ErrorHandler*); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/delayshaper.cc click-1.2.4/elements/standard/delayshaper.cc --- click-1.2.4.orig/elements/standard/delayshaper.cc Fri Apr 5 11:36:29 2002 +++ click-1.2.4/elements/standard/delayshaper.cc Sun Jun 2 22:01:33 2002 @@ -23,6 +23,10 @@ #include "delayshaper.hh" #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + DelayShaper::DelayShaper() : Element(1, 1), _p(0) { diff -urN click-1.2.4.orig/elements/standard/delayshaper.hh click-1.2.4/elements/standard/delayshaper.hh --- click-1.2.4.orig/elements/standard/delayshaper.hh Fri Apr 5 11:36:37 2002 +++ click-1.2.4/elements/standard/delayshaper.hh Sun Jun 2 22:02:01 2002 @@ -22,6 +22,10 @@ =a BandwidthShaper, DelayUnqueue, SetTimestamp */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class DelayShaper : public Element { public: DelayShaper(); @@ -43,5 +47,9 @@ uint32_t _delay; Packet *_p; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/delayunqueue.cc click-1.2.4/elements/standard/delayunqueue.cc --- click-1.2.4.orig/elements/standard/delayunqueue.cc Fri May 17 16:30:01 2002 +++ click-1.2.4/elements/standard/delayunqueue.cc Sun Jun 2 22:02:51 2002 @@ -24,6 +24,10 @@ #include "delayunqueue.hh" #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + DelayUnqueue::DelayUnqueue() : Element(1, 1), _p(0), _task(this), _timer(&_task) { diff -urN click-1.2.4.orig/elements/standard/delayunqueue.hh click-1.2.4/elements/standard/delayunqueue.hh --- click-1.2.4.orig/elements/standard/delayunqueue.hh Fri Apr 5 11:36:59 2002 +++ click-1.2.4/elements/standard/delayunqueue.hh Sun Jun 2 22:03:24 2002 @@ -22,6 +22,10 @@ =a Queue, Unqueue, RatedUnqueue, BandwidthRatedUnqueue, SetTimestamp, NotifierQueue */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class DelayUnqueue : public Element { public: DelayUnqueue(); @@ -48,5 +52,9 @@ Timer _timer; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/devirtualizeinfo.cc click-1.2.4/elements/standard/devirtualizeinfo.cc --- click-1.2.4.orig/elements/standard/devirtualizeinfo.cc Thu Feb 7 11:22:11 2002 +++ click-1.2.4/elements/standard/devirtualizeinfo.cc Sun Jun 2 22:03:49 2002 @@ -19,6 +19,10 @@ #include "devirtualizeinfo.hh" #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + DevirtualizeInfo::DevirtualizeInfo() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/standard/devirtualizeinfo.hh click-1.2.4/elements/standard/devirtualizeinfo.hh --- click-1.2.4.orig/elements/standard/devirtualizeinfo.hh Tue Mar 26 16:40:02 2002 +++ click-1.2.4/elements/standard/devirtualizeinfo.hh Sun Jun 2 22:04:09 2002 @@ -2,6 +2,10 @@ #define CLICK_DEVIRTUALIZEINFO_HH #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class DevirtualizeInfo : public Element { public: @@ -14,5 +18,9 @@ int configure(Vector &, ErrorHandler *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/discard.cc click-1.2.4/elements/standard/discard.cc --- click-1.2.4.orig/elements/standard/discard.cc Fri Mar 29 13:03:34 2002 +++ click-1.2.4/elements/standard/discard.cc Sun Jun 2 22:04:28 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + Discard::Discard() : Element(1, 0), _task(this) { diff -urN click-1.2.4.orig/elements/standard/discard.hh click-1.2.4/elements/standard/discard.hh --- click-1.2.4.orig/elements/standard/discard.hh Fri Mar 29 13:02:50 2002 +++ click-1.2.4/elements/standard/discard.hh Sun Jun 2 22:04:50 2002 @@ -4,6 +4,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + /* * =c * Discard @@ -37,5 +41,9 @@ NotifierSignal _signal; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/discardnofree.cc click-1.2.4/elements/standard/discardnofree.cc --- click-1.2.4.orig/elements/standard/discardnofree.cc Thu Nov 22 12:44:29 2001 +++ click-1.2.4/elements/standard/discardnofree.cc Sun Jun 2 22:05:20 2002 @@ -19,6 +19,10 @@ #include "discardnofree.hh" #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + DiscardNoFree::DiscardNoFree() : Element(1, 0), _task(this) { diff -urN click-1.2.4.orig/elements/standard/discardnofree.hh click-1.2.4/elements/standard/discardnofree.hh --- click-1.2.4.orig/elements/standard/discardnofree.hh Tue Mar 26 16:40:12 2002 +++ click-1.2.4/elements/standard/discardnofree.hh Sun Jun 2 22:05:47 2002 @@ -13,6 +13,10 @@ * them. Only useful for benchmarking. */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class DiscardNoFree : public Element { public: DiscardNoFree(); @@ -33,5 +37,9 @@ Task _task; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/drivermanager.cc click-1.2.4/elements/standard/drivermanager.cc --- click-1.2.4.orig/elements/standard/drivermanager.cc Thu Feb 7 11:22:12 2002 +++ click-1.2.4/elements/standard/drivermanager.cc Sun Jun 2 22:06:12 2002 @@ -24,6 +24,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + DriverManager::DriverManager() : _timer(this) { diff -urN click-1.2.4.orig/elements/standard/dropbroadcasts.cc click-1.2.4/elements/standard/dropbroadcasts.cc --- click-1.2.4.orig/elements/standard/dropbroadcasts.cc Tue May 22 15:43:23 2001 +++ click-1.2.4/elements/standard/dropbroadcasts.cc Sun Jun 2 22:07:33 2002 @@ -2,6 +2,10 @@ #include "dropbroadcasts.hh" #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + DropBroadcasts::DropBroadcasts() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/standard/dropbroadcasts.hh click-1.2.4/elements/standard/dropbroadcasts.hh --- click-1.2.4.orig/elements/standard/dropbroadcasts.hh Tue Mar 26 16:40:17 2002 +++ click-1.2.4/elements/standard/dropbroadcasts.hh Sun Jun 2 22:07:53 2002 @@ -16,6 +16,10 @@ * =a FromDevice */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class DropBroadcasts : public Element { public: @@ -36,5 +40,9 @@ private: uatomic32_t _drops; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/drr.cc click-1.2.4/elements/standard/drr.cc --- click-1.2.4.orig/elements/standard/drr.cc Fri Apr 5 11:37:50 2002 +++ click-1.2.4/elements/standard/drr.cc Sun Jun 2 22:08:16 2002 @@ -19,6 +19,10 @@ #include #include "drr.hh" +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + DRRSched::DRRSched() : _quantum(500), _head(0), _deficit(0), _next(0) { diff -urN click-1.2.4.orig/elements/standard/drr.hh click-1.2.4/elements/standard/drr.hh --- click-1.2.4.orig/elements/standard/drr.hh Fri Apr 5 11:37:58 2002 +++ click-1.2.4/elements/standard/drr.hh Sun Jun 2 22:08:54 2002 @@ -17,6 +17,10 @@ * =a PrioSched, StrideSched, RoundRobinSched */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class DRRSched : public Element { public: DRRSched(); @@ -41,5 +45,9 @@ int _next; // Next input to consider. }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/errorelement.cc click-1.2.4/elements/standard/errorelement.cc --- click-1.2.4.orig/elements/standard/errorelement.cc Thu Feb 7 11:22:13 2002 +++ click-1.2.4/elements/standard/errorelement.cc Sat Jun 1 00:05:58 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + ErrorElement::ErrorElement() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/standard/frontdropqueue.cc click-1.2.4/elements/standard/frontdropqueue.cc --- click-1.2.4.orig/elements/standard/frontdropqueue.cc Thu Feb 7 11:07:18 2002 +++ click-1.2.4/elements/standard/frontdropqueue.cc Sun Jun 2 22:10:37 2002 @@ -20,6 +20,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + FrontDropQueue::FrontDropQueue() { // no MOD_INC_USE_COUNT; rely on Queue diff -urN click-1.2.4.orig/elements/standard/frontdropqueue.hh click-1.2.4/elements/standard/frontdropqueue.hh --- click-1.2.4.orig/elements/standard/frontdropqueue.hh Tue Mar 26 16:40:38 2002 +++ click-1.2.4/elements/standard/frontdropqueue.hh Sun Jun 2 22:11:00 2002 @@ -27,6 +27,10 @@ * =a Queue, RED */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class FrontDropQueue : public Queue { public: FrontDropQueue(); @@ -42,5 +46,9 @@ void push(int port, Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/hashswitch.cc click-1.2.4/elements/standard/hashswitch.cc --- click-1.2.4.orig/elements/standard/hashswitch.cc Thu Feb 7 11:22:14 2002 +++ click-1.2.4/elements/standard/hashswitch.cc Sun Jun 2 22:13:08 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + HashSwitch::HashSwitch() : _offset(-1) { diff -urN click-1.2.4.orig/elements/standard/hashswitch.hh click-1.2.4/elements/standard/hashswitch.hh --- click-1.2.4.orig/elements/standard/hashswitch.hh Fri May 17 15:26:06 2002 +++ click-1.2.4/elements/standard/hashswitch.hh Sun Jun 2 22:13:30 2002 @@ -21,6 +21,10 @@ * Switch, RoundRobinSwitch, StrideSwitch, RandomSwitch */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class HashSwitch : public Element { int _offset; @@ -41,5 +45,9 @@ void push(int port, Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/idle.cc click-1.2.4/elements/standard/idle.cc --- click-1.2.4.orig/elements/standard/idle.cc Fri Mar 29 13:00:08 2002 +++ click-1.2.4/elements/standard/idle.cc Sun Jun 2 22:14:19 2002 @@ -18,6 +18,10 @@ #include #include "idle.hh" +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + Idle::Idle() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/standard/idle.hh click-1.2.4/elements/standard/idle.hh --- click-1.2.4.orig/elements/standard/idle.hh Fri Mar 29 12:59:16 2002 +++ click-1.2.4/elements/standard/idle.hh Sun Jun 2 22:14:06 2002 @@ -16,6 +16,10 @@ * error messages. */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Idle : public Element, public AbstractNotifier { public: @@ -38,5 +42,9 @@ Packet *pull(int); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/infinitesource.cc click-1.2.4/elements/standard/infinitesource.cc --- click-1.2.4.orig/elements/standard/infinitesource.cc Fri Apr 5 11:38:09 2002 +++ click-1.2.4/elements/standard/infinitesource.cc Sun Jun 2 22:15:22 2002 @@ -24,6 +24,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + InfiniteSource::InfiniteSource() : Element(0, 1), _packet(0), _task(this) { diff -urN click-1.2.4.orig/elements/standard/infinitesource.hh click-1.2.4/elements/standard/infinitesource.hh --- click-1.2.4.orig/elements/standard/infinitesource.hh Fri Apr 5 11:38:17 2002 +++ click-1.2.4/elements/standard/infinitesource.hh Sun Jun 2 22:15:09 2002 @@ -77,6 +77,10 @@ RatedSource, PokeHandlers */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class InfiniteSource : public Element { public: InfiniteSource(); @@ -111,5 +115,9 @@ static int change_param(const String &, Element *, void *, ErrorHandler *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/meter.cc click-1.2.4/elements/standard/meter.cc --- click-1.2.4.orig/elements/standard/meter.cc Thu May 24 18:03:47 2001 +++ click-1.2.4/elements/standard/meter.cc Sun Jun 2 22:15:40 2002 @@ -19,6 +19,10 @@ #include #include "meter.hh" +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + Meter::Meter() { // no MOD_INC_USE_COUNT; rely on BandwidthMeter diff -urN click-1.2.4.orig/elements/standard/meter.hh click-1.2.4/elements/standard/meter.hh --- click-1.2.4.orig/elements/standard/meter.hh Tue Mar 26 16:41:05 2002 +++ click-1.2.4/elements/standard/meter.hh Sun Jun 2 22:16:19 2002 @@ -38,6 +38,10 @@ * * =a BandwidthMeter, RatedSplitter, Shaper, BandwidthShaper */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Meter : public BandwidthMeter { public: Meter(); @@ -49,5 +53,9 @@ void push(int port, Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/msqueue.cc click-1.2.4/elements/standard/msqueue.cc --- click-1.2.4.orig/elements/standard/msqueue.cc Fri Apr 5 13:48:01 2002 +++ click-1.2.4/elements/standard/msqueue.cc Sun Jun 2 22:16:39 2002 @@ -10,6 +10,9 @@ #define BATCH_SZ 7 #define BATCH_FORCE 128 +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif MSQueue::MSQueue() : Element(1, 1), _q(0) diff -urN click-1.2.4.orig/elements/standard/msqueue.hh click-1.2.4/elements/standard/msqueue.hh --- click-1.2.4.orig/elements/standard/msqueue.hh Fri Apr 5 11:38:37 2002 +++ click-1.2.4/elements/standard/msqueue.hh Sun Jun 2 22:17:05 2002 @@ -26,6 +26,9 @@ #include #include "elements/standard/queue.hh" +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif class MSQueue : public Element { @@ -99,5 +102,9 @@ { return (_head.value() != _tail.value() ? _q[_head.value()] : 0); } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/notifierqueue.cc click-1.2.4/elements/standard/notifierqueue.cc --- click-1.2.4.orig/elements/standard/notifierqueue.cc Wed Mar 13 20:20:52 2002 +++ click-1.2.4/elements/standard/notifierqueue.cc Sun Jun 2 22:17:22 2002 @@ -19,6 +19,10 @@ #include #include "notifierqueue.hh" +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + NotifierQueue::NotifierQueue() : _sleepiness(0) { diff -urN click-1.2.4.orig/elements/standard/notifierqueue.hh click-1.2.4/elements/standard/notifierqueue.hh --- click-1.2.4.orig/elements/standard/notifierqueue.hh Wed Apr 24 10:13:11 2002 +++ click-1.2.4/elements/standard/notifierqueue.hh Sun Jun 2 22:17:44 2002 @@ -53,6 +53,10 @@ =a Queue */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class NotifierQueue : public Queue, public Notifier { public: NotifierQueue(); @@ -73,5 +77,9 @@ int _sleepiness; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/nullelement.cc click-1.2.4/elements/standard/nullelement.cc --- click-1.2.4.orig/elements/standard/nullelement.cc Thu May 24 18:03:47 2001 +++ click-1.2.4/elements/standard/nullelement.cc Sun Jun 2 22:18:02 2002 @@ -18,6 +18,10 @@ #include #include "nullelement.hh" +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + NullElement::NullElement() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/standard/nullelement.hh click-1.2.4/elements/standard/nullelement.hh --- click-1.2.4.orig/elements/standard/nullelement.hh Tue Mar 26 16:41:15 2002 +++ click-1.2.4/elements/standard/nullelement.hh Sun Jun 2 22:18:33 2002 @@ -16,6 +16,10 @@ PushNull, PullNull */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class NullElement : public Element { public: NullElement(); @@ -82,5 +86,9 @@ Packet *pull(int); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/nulls.cc click-1.2.4/elements/standard/nulls.cc --- click-1.2.4.orig/elements/standard/nulls.cc Thu May 24 18:03:47 2001 +++ click-1.2.4/elements/standard/nulls.cc Sun Jun 2 22:19:06 2002 @@ -18,6 +18,10 @@ #include #include "nulls.hh" +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + EXPORT_ELEMENT(Null1) EXPORT_ELEMENT(Null2) EXPORT_ELEMENT(Null3) diff -urN click-1.2.4.orig/elements/standard/nulls.hh click-1.2.4/elements/standard/nulls.hh --- click-1.2.4.orig/elements/standard/nulls.hh Tue Mar 26 16:41:30 2002 +++ click-1.2.4/elements/standard/nulls.hh Sun Jun 2 22:19:29 2002 @@ -26,6 +26,10 @@ =a Null */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Null1 : public Element { public: @@ -145,5 +149,9 @@ Packet *simple_action(Packet *p) { return p; } }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/paint.cc click-1.2.4/elements/standard/paint.cc --- click-1.2.4.orig/elements/standard/paint.cc Thu Feb 7 11:22:16 2002 +++ click-1.2.4/elements/standard/paint.cc Sun Jun 2 22:19:48 2002 @@ -22,6 +22,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + Paint::Paint() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/standard/paint.hh click-1.2.4/elements/standard/paint.hh --- click-1.2.4.orig/elements/standard/paint.hh Tue Mar 26 16:41:26 2002 +++ click-1.2.4/elements/standard/paint.hh Sun Jun 2 22:20:11 2002 @@ -27,6 +27,10 @@ =a PaintTee */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Paint : public Element { unsigned char _color; @@ -52,5 +56,9 @@ static String color_read_handler(Element *, void *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/painttee.cc click-1.2.4/elements/standard/painttee.cc --- click-1.2.4.orig/elements/standard/painttee.cc Thu Feb 7 11:22:17 2002 +++ click-1.2.4/elements/standard/painttee.cc Sun Jun 2 22:20:33 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + PaintTee::PaintTee() : Element(1, 2) { diff -urN click-1.2.4.orig/elements/standard/painttee.hh click-1.2.4/elements/standard/painttee.hh --- click-1.2.4.orig/elements/standard/painttee.hh Tue Mar 26 16:41:40 2002 +++ click-1.2.4/elements/standard/painttee.hh Sun Jun 2 22:20:57 2002 @@ -23,6 +23,10 @@ * =a Paint, ICMPError */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class PaintTee : public Element { int _color; @@ -41,5 +45,9 @@ Packet *simple_action(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/peekhandlers.cc click-1.2.4/elements/standard/peekhandlers.cc --- click-1.2.4.orig/elements/standard/peekhandlers.cc Thu Feb 7 11:22:18 2002 +++ click-1.2.4/elements/standard/peekhandlers.cc Sun Jun 2 22:21:14 2002 @@ -19,6 +19,10 @@ #include "peekhandlers.hh" #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + PeekHandlers::PeekHandlers() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/standard/peekhandlers.hh click-1.2.4/elements/standard/peekhandlers.hh --- click-1.2.4.orig/elements/standard/peekhandlers.hh Thu Feb 7 11:17:56 2002 +++ click-1.2.4/elements/standard/peekhandlers.hh Sun Jun 2 22:21:36 2002 @@ -26,6 +26,10 @@ PokeHandlers */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class PeekHandlers : public Element { public: PeekHandlers(); @@ -37,5 +41,9 @@ int configure(Vector &, ErrorHandler *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/pokehandlers.cc click-1.2.4/elements/standard/pokehandlers.cc --- click-1.2.4.orig/elements/standard/pokehandlers.cc Wed Apr 24 09:51:29 2002 +++ click-1.2.4/elements/standard/pokehandlers.cc Sun Jun 2 22:21:59 2002 @@ -23,6 +23,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + static const char * const READ_MARKER = "r"; Element * const PokeHandlers::STOP_MARKER = (Element *)1; Element * const PokeHandlers::LOOP_MARKER = (Element *)2; diff -urN click-1.2.4.orig/elements/standard/pokehandlers.hh click-1.2.4/elements/standard/pokehandlers.hh --- click-1.2.4.orig/elements/standard/pokehandlers.hh Wed Apr 24 09:55:14 2002 +++ click-1.2.4/elements/standard/pokehandlers.hh Sun Jun 2 22:22:29 2002 @@ -61,6 +61,10 @@ =a dmesg(1) */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class PokeHandlers : public Element { public: PokeHandlers(); @@ -88,5 +92,9 @@ void add(Element *, const String &, const String &, int); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/print.cc click-1.2.4/elements/standard/print.cc --- click-1.2.4.orig/elements/standard/print.cc Wed Apr 3 11:31:53 2002 +++ click-1.2.4/elements/standard/print.cc Wed Jun 5 17:29:18 2002 @@ -27,6 +27,15 @@ } #endif +#ifdef CLICK_SIM +#include +#include +#endif + +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + Print::Print() : Element(1, 1) { @@ -67,6 +76,14 @@ cpEnd) < 0) return -1; +#ifdef CLICK_SIM + Router* myrouter = router(); + simclick_sim mysiminst = myrouter->get_siminst(); + char tmp[255]; + simclick_sim_get_node_name(mysiminst,tmp,255); + label = String(tmp) + String("_") + label; +#endif + _label = label; _bytes = bytes; _timestamp = timestamp; diff -urN click-1.2.4.orig/elements/standard/print.hh click-1.2.4/elements/standard/print.hh --- click-1.2.4.orig/elements/standard/print.hh Tue Mar 5 17:14:43 2002 +++ click-1.2.4/elements/standard/print.hh Sun Jun 2 22:23:16 2002 @@ -41,6 +41,10 @@ IPPrint */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Print : public Element { public: Print(); @@ -65,5 +69,9 @@ #endif }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/priosched.cc click-1.2.4/elements/standard/priosched.cc --- click-1.2.4.orig/elements/standard/priosched.cc Thu May 24 18:03:48 2001 +++ click-1.2.4/elements/standard/priosched.cc Sun Jun 2 22:23:33 2002 @@ -18,6 +18,10 @@ #include #include "priosched.hh" +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + PrioSched::PrioSched() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/standard/priosched.hh click-1.2.4/elements/standard/priosched.hh --- click-1.2.4.orig/elements/standard/priosched.hh Tue Mar 26 16:41:48 2002 +++ click-1.2.4/elements/standard/priosched.hh Sun Jun 2 22:24:00 2002 @@ -18,6 +18,10 @@ * =a Queue, RoundRobinSched, StrideSched, DRRSched */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class PrioSched : public Element { public: @@ -34,5 +38,9 @@ Packet *pull(int port); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/probsplitter.cc click-1.2.4/elements/standard/probsplitter.cc --- click-1.2.4.orig/elements/standard/probsplitter.cc Thu Feb 7 11:22:20 2002 +++ click-1.2.4/elements/standard/probsplitter.cc Sun Jun 2 22:24:19 2002 @@ -20,6 +20,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + ProbSplitter::ProbSplitter() : Element(1, 2) { diff -urN click-1.2.4.orig/elements/standard/probsplitter.hh click-1.2.4/elements/standard/probsplitter.hh --- click-1.2.4.orig/elements/standard/probsplitter.hh Tue Mar 26 16:41:58 2002 +++ click-1.2.4/elements/standard/probsplitter.hh Sun Jun 2 22:24:44 2002 @@ -15,6 +15,10 @@ * =a RandomSample */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class ProbSplitter : public Element { public: ProbSplitter(); @@ -26,6 +30,10 @@ int configure(Vector &, ErrorHandler *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/pullswitch.cc click-1.2.4/elements/standard/pullswitch.cc --- click-1.2.4.orig/elements/standard/pullswitch.cc Thu Feb 7 18:29:00 2002 +++ click-1.2.4/elements/standard/pullswitch.cc Sun Jun 2 22:25:05 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + PullSwitch::PullSwitch() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/standard/pullswitch.hh click-1.2.4/elements/standard/pullswitch.hh --- click-1.2.4.orig/elements/standard/pullswitch.hh Tue Mar 26 16:42:03 2002 +++ click-1.2.4/elements/standard/pullswitch.hh Sun Jun 2 22:25:28 2002 @@ -33,6 +33,10 @@ =a StaticPullSwitch, PrioSched, RoundRobinSched, StrideSched, Switch */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class PullSwitch : public Element { public: PullSwitch(); @@ -61,5 +65,9 @@ static int write_param(const String &, Element *, void *, ErrorHandler *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/queue.cc click-1.2.4/elements/standard/queue.cc --- click-1.2.4.orig/elements/standard/queue.cc Tue Apr 16 12:47:40 2002 +++ click-1.2.4/elements/standard/queue.cc Sun Jun 2 22:12:20 2002 @@ -20,6 +20,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + Queue::Queue() : Element(1, 1), _q(0) { diff -urN click-1.2.4.orig/elements/standard/queue.hh click-1.2.4/elements/standard/queue.hh --- click-1.2.4.orig/elements/standard/queue.hh Tue Apr 16 12:47:27 2002 +++ click-1.2.4/elements/standard/queue.hh Sun Jun 2 22:12:06 2002 @@ -50,6 +50,10 @@ =a NotifierQueue, RED, FrontDropQueue */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Storage { public: Storage() : _head(0), _tail(0) { } @@ -154,5 +158,9 @@ { return (_head != _tail ? _q[_head] : 0); } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/quitwatcher.cc click-1.2.4/elements/standard/quitwatcher.cc --- click-1.2.4.orig/elements/standard/quitwatcher.cc Thu Feb 7 11:22:23 2002 +++ click-1.2.4/elements/standard/quitwatcher.cc Sun Jun 2 22:26:54 2002 @@ -24,6 +24,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + QuitWatcher::QuitWatcher() : _timer(this) { diff -urN click-1.2.4.orig/elements/standard/quitwatcher.hh click-1.2.4/elements/standard/quitwatcher.hh --- click-1.2.4.orig/elements/standard/quitwatcher.hh Tue Mar 26 16:42:15 2002 +++ click-1.2.4/elements/standard/quitwatcher.hh Sun Jun 2 22:27:22 2002 @@ -27,6 +27,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class QuitWatcher : public Element { public: QuitWatcher(); @@ -46,5 +50,9 @@ Timer _timer; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/randomerror.cc click-1.2.4/elements/standard/randomerror.cc --- click-1.2.4.orig/elements/standard/randomerror.cc Tue Apr 30 16:14:42 2002 +++ click-1.2.4/elements/standard/randomerror.cc Sun Jun 2 22:27:55 2002 @@ -20,6 +20,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + static int bit_flip_array_idx[] = { 0, 1, 9, 37, 93, 163, 219, 247, 255, 256 }; diff -urN click-1.2.4.orig/elements/standard/randomerror.hh click-1.2.4/elements/standard/randomerror.hh --- click-1.2.4.orig/elements/standard/randomerror.hh Tue Mar 26 16:42:19 2002 +++ click-1.2.4/elements/standard/randomerror.hh Sun Jun 2 22:28:19 2002 @@ -26,6 +26,10 @@ * * =a RandomSample */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class RandomBitErrors : public Element { int _p_error[9]; // out of 0xFFFF @@ -54,5 +58,9 @@ Packet *simple_action(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/randomlossage.cc click-1.2.4/elements/standard/randomlossage.cc --- click-1.2.4.orig/elements/standard/randomlossage.cc Thu Feb 7 11:22:24 2002 +++ click-1.2.4/elements/standard/randomlossage.cc Sun Jun 2 22:28:38 2002 @@ -20,6 +20,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + RandomLossage::RandomLossage() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/standard/randomlossage.hh click-1.2.4/elements/standard/randomlossage.hh --- click-1.2.4.orig/elements/standard/randomlossage.hh Tue Mar 26 16:42:25 2002 +++ click-1.2.4/elements/standard/randomlossage.hh Sun Jun 2 22:29:13 2002 @@ -20,6 +20,10 @@ * * =a RandomSample */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class RandomLossage : public Element { public: RandomLossage(); @@ -31,5 +35,9 @@ int configure(Vector &, ErrorHandler *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/randomsample.cc click-1.2.4/elements/standard/randomsample.cc --- click-1.2.4.orig/elements/standard/randomsample.cc Thu Feb 7 18:29:10 2002 +++ click-1.2.4/elements/standard/randomsample.cc Sun Jun 2 22:29:50 2002 @@ -22,6 +22,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + RandomSample::RandomSample() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/standard/randomsample.hh click-1.2.4/elements/standard/randomsample.hh --- click-1.2.4.orig/elements/standard/randomsample.hh Wed Apr 24 10:13:23 2002 +++ click-1.2.4/elements/standard/randomsample.hh Sun Jun 2 22:30:22 2002 @@ -61,6 +61,10 @@ * * =a RandomBitErrors */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class RandomSample : public Element { public: RandomSample(); @@ -93,5 +97,9 @@ static String read_handler(Element *, void *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/randomsource.cc click-1.2.4/elements/standard/randomsource.cc --- click-1.2.4.orig/elements/standard/randomsource.cc Thu Feb 7 11:22:26 2002 +++ click-1.2.4/elements/standard/randomsource.cc Sun Jun 2 22:30:42 2002 @@ -23,6 +23,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + RandomSource::RandomSource() : Element(0, 1), _task(this) { diff -urN click-1.2.4.orig/elements/standard/randomsource.hh click-1.2.4/elements/standard/randomsource.hh --- click-1.2.4.orig/elements/standard/randomsource.hh Tue Mar 26 16:42:34 2002 +++ click-1.2.4/elements/standard/randomsource.hh Sun Jun 2 22:31:12 2002 @@ -13,6 +13,10 @@ * =a InfiniteSource */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class RandomSource : public Element { public: RandomSource(); @@ -36,5 +40,9 @@ Packet *make_packet(); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/randomswitch.cc click-1.2.4/elements/standard/randomswitch.cc --- click-1.2.4.orig/elements/standard/randomswitch.cc Fri May 17 15:27:47 2002 +++ click-1.2.4/elements/standard/randomswitch.cc Sun Jun 2 22:31:30 2002 @@ -19,6 +19,10 @@ #include #include "randomswitch.hh" +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + RandomSwitch::RandomSwitch() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/standard/randomswitch.hh click-1.2.4/elements/standard/randomswitch.hh --- click-1.2.4.orig/elements/standard/randomswitch.hh Fri May 17 15:27:01 2002 +++ click-1.2.4/elements/standard/randomswitch.hh Sun Jun 2 22:31:52 2002 @@ -17,6 +17,10 @@ * =a Switch, StrideSwitch, RoundRobinSwitch, HashSwitch */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class RandomSwitch : public Element { public: RandomSwitch(); @@ -30,5 +34,9 @@ void push(int, Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/ratedsource.cc click-1.2.4/elements/standard/ratedsource.cc --- click-1.2.4.orig/elements/standard/ratedsource.cc Wed Apr 24 10:25:32 2002 +++ click-1.2.4/elements/standard/ratedsource.cc Sun Jun 2 22:32:33 2002 @@ -23,6 +23,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + const unsigned RatedSource::NO_LIMIT; RatedSource::RatedSource() diff -urN click-1.2.4.orig/elements/standard/ratedsource.hh click-1.2.4/elements/standard/ratedsource.hh --- click-1.2.4.orig/elements/standard/ratedsource.hh Wed Apr 24 10:25:15 2002 +++ click-1.2.4/elements/standard/ratedsource.hh Sun Jun 2 22:33:12 2002 @@ -73,6 +73,10 @@ InfiniteSource, PokeHandlers */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class RatedSource : public Element { public: RatedSource(); @@ -107,5 +111,9 @@ static int change_param(const String &, Element *, void *, ErrorHandler *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/ratedsplitter.cc click-1.2.4/elements/standard/ratedsplitter.cc --- click-1.2.4.orig/elements/standard/ratedsplitter.cc Thu Feb 7 18:29:18 2002 +++ click-1.2.4/elements/standard/ratedsplitter.cc Sun Jun 2 14:42:02 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + RatedSplitter::RatedSplitter() : Element(1, 2) { diff -urN click-1.2.4.orig/elements/standard/ratedsplitter.hh click-1.2.4/elements/standard/ratedsplitter.hh --- click-1.2.4.orig/elements/standard/ratedsplitter.hh Tue Mar 26 16:42:45 2002 +++ click-1.2.4/elements/standard/ratedsplitter.hh Sun Jun 2 14:41:46 2002 @@ -36,6 +36,10 @@ * * =a BandwidthRatedSplitter, ProbSplitter, Meter, Shaper, RatedUnqueue, Tee */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class RatedSplitter : public Element { protected: GapRate _rate; @@ -60,5 +64,9 @@ void set_rate(unsigned r, ErrorHandler * = 0); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/ratedunqueue.cc click-1.2.4/elements/standard/ratedunqueue.cc --- click-1.2.4.orig/elements/standard/ratedunqueue.cc Thu Feb 7 18:29:26 2002 +++ click-1.2.4/elements/standard/ratedunqueue.cc Sun Jun 2 14:43:37 2002 @@ -22,6 +22,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + RatedUnqueue::RatedUnqueue() : Element(1, 1), _task(this) { diff -urN click-1.2.4.orig/elements/standard/ratedunqueue.hh click-1.2.4/elements/standard/ratedunqueue.hh --- click-1.2.4.orig/elements/standard/ratedunqueue.hh Tue Mar 26 16:42:50 2002 +++ click-1.2.4/elements/standard/ratedunqueue.hh Sun Jun 2 14:43:19 2002 @@ -16,6 +16,10 @@ * * =a BandwidthRatedUnqueue, Unqueue, Shaper, RatedSplitter */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class RatedUnqueue : public Element { public: RatedUnqueue(); @@ -41,5 +45,9 @@ Task _task; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/rrsched.cc click-1.2.4/elements/standard/rrsched.cc --- click-1.2.4.orig/elements/standard/rrsched.cc Thu May 24 18:03:51 2001 +++ click-1.2.4/elements/standard/rrsched.cc Sun Jun 2 22:33:32 2002 @@ -18,6 +18,10 @@ #include #include "rrsched.hh" +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + RRSched::RRSched() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/standard/rrsched.hh click-1.2.4/elements/standard/rrsched.hh --- click-1.2.4.orig/elements/standard/rrsched.hh Tue Mar 26 16:47:29 2002 +++ click-1.2.4/elements/standard/rrsched.hh Sun Jun 2 22:34:35 2002 @@ -19,6 +19,10 @@ * =a PrioSched, StrideSched, DRRSched, RoundRobinSwitch */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class RRSched : public Element { public: @@ -39,5 +43,9 @@ int _next; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/rrswitch.cc click-1.2.4/elements/standard/rrswitch.cc --- click-1.2.4.orig/elements/standard/rrswitch.cc Thu May 24 18:03:51 2001 +++ click-1.2.4/elements/standard/rrswitch.cc Sun Jun 2 22:34:56 2002 @@ -18,6 +18,10 @@ #include #include "rrswitch.hh" +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + RoundRobinSwitch::RoundRobinSwitch() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/standard/rrswitch.hh click-1.2.4/elements/standard/rrswitch.hh --- click-1.2.4.orig/elements/standard/rrswitch.hh Fri May 17 15:25:26 2002 +++ click-1.2.4/elements/standard/rrswitch.hh Sun Jun 2 22:35:20 2002 @@ -17,6 +17,10 @@ * =a StrideSwitch, Switch, HashSwitch, RandomSwitch, RoundRobinSched */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class RoundRobinSwitch : public Element { uatomic32_t _next; @@ -35,5 +39,9 @@ void push(int, Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/scheduleinfo.cc click-1.2.4/elements/standard/scheduleinfo.cc --- click-1.2.4.orig/elements/standard/scheduleinfo.cc Tue Apr 30 16:15:00 2002 +++ click-1.2.4/elements/standard/scheduleinfo.cc Sat Jun 1 00:07:09 2002 @@ -23,6 +23,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + ScheduleInfo::ScheduleInfo() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/standard/setcrc32.cc click-1.2.4/elements/standard/setcrc32.cc --- click-1.2.4.orig/elements/standard/setcrc32.cc Thu May 24 18:03:51 2001 +++ click-1.2.4/elements/standard/setcrc32.cc Sun Jun 2 22:35:43 2002 @@ -21,6 +21,10 @@ #include } +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + SetCRC32::SetCRC32() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/standard/setcrc32.hh click-1.2.4/elements/standard/setcrc32.hh --- click-1.2.4.orig/elements/standard/setcrc32.hh Tue Mar 26 16:43:08 2002 +++ click-1.2.4/elements/standard/setcrc32.hh Sun Jun 2 22:36:04 2002 @@ -14,6 +14,10 @@ #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class EtherAddress; class SetCRC32 : public Element { @@ -29,5 +33,9 @@ Packet *simple_action(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/setpackettype.cc click-1.2.4/elements/standard/setpackettype.cc --- click-1.2.4.orig/elements/standard/setpackettype.cc Thu Feb 7 11:22:31 2002 +++ click-1.2.4/elements/standard/setpackettype.cc Sun Jun 2 22:36:29 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + SetPacketType::SetPacketType() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/standard/setpackettype.hh click-1.2.4/elements/standard/setpackettype.hh --- click-1.2.4.orig/elements/standard/setpackettype.hh Thu Feb 7 11:18:14 2002 +++ click-1.2.4/elements/standard/setpackettype.hh Sun Jun 2 22:36:59 2002 @@ -20,6 +20,10 @@ was it broadcast? TYPE should be one of `C', `C', `C', `C', `C', or `C'. */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class SetPacketType : public Element { public: SetPacketType(); @@ -42,5 +46,9 @@ Packet::PacketType _ptype; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/settimestamp.cc click-1.2.4/elements/standard/settimestamp.cc --- click-1.2.4.orig/elements/standard/settimestamp.cc Thu Feb 7 11:22:32 2002 +++ click-1.2.4/elements/standard/settimestamp.cc Sun Jun 2 22:37:29 2002 @@ -22,6 +22,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + SetTimestamp::SetTimestamp() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/standard/settimestamp.hh click-1.2.4/elements/standard/settimestamp.hh --- click-1.2.4.orig/elements/standard/settimestamp.hh Tue Mar 26 16:43:13 2002 +++ click-1.2.4/elements/standard/settimestamp.hh Sun Jun 2 22:37:52 2002 @@ -19,6 +19,10 @@ =a PrintOld */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class SetTimestamp : public Element { public: SetTimestamp(); @@ -39,5 +43,9 @@ struct timeval _tv; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/shaper.cc click-1.2.4/elements/standard/shaper.cc --- click-1.2.4.orig/elements/standard/shaper.cc Thu Feb 7 11:22:33 2002 +++ click-1.2.4/elements/standard/shaper.cc Sun Jun 2 13:55:26 2002 @@ -24,6 +24,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + Shaper::Shaper() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/standard/shaper.hh click-1.2.4/elements/standard/shaper.hh --- click-1.2.4.orig/elements/standard/shaper.hh Thu Feb 7 11:18:15 2002 +++ click-1.2.4/elements/standard/shaper.hh Sun Jun 2 13:55:46 2002 @@ -34,6 +34,10 @@ * * =a BandwidthShaper, RatedSplitter, RatedUnqueue */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Shaper : public Element { public: Shaper(); @@ -54,5 +58,9 @@ GapRate _rate; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/spinlockacquire.cc click-1.2.4/elements/standard/spinlockacquire.cc --- click-1.2.4.orig/elements/standard/spinlockacquire.cc Thu Feb 7 11:22:34 2002 +++ click-1.2.4/elements/standard/spinlockacquire.cc Sun Jun 2 22:38:20 2002 @@ -17,6 +17,10 @@ #include "spinlockinfo.hh" #include "spinlockacquire.hh" +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + int SpinlockAcquire::configure(Vector &conf, ErrorHandler *errh) { diff -urN click-1.2.4.orig/elements/standard/spinlockacquire.hh click-1.2.4/elements/standard/spinlockacquire.hh --- click-1.2.4.orig/elements/standard/spinlockacquire.hh Fri Apr 5 11:50:53 2002 +++ click-1.2.4/elements/standard/spinlockacquire.hh Sun Jun 2 22:38:44 2002 @@ -12,6 +12,10 @@ * Acquires the spinlock named S. S must be defined in a SpinlockInfo element. */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class SpinlockAcquire : public Element { Spinlock *_lock; @@ -32,5 +36,9 @@ Packet *simple_action(Packet *p) { _lock->acquire(); return p; } }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/spinlockinfo.cc click-1.2.4/elements/standard/spinlockinfo.cc --- click-1.2.4.orig/elements/standard/spinlockinfo.cc Fri Apr 5 11:39:31 2002 +++ click-1.2.4/elements/standard/spinlockinfo.cc Sun Jun 2 22:39:12 2002 @@ -17,6 +17,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + SpinlockInfo::SpinlockInfo() : _map(-1) { diff -urN click-1.2.4.orig/elements/standard/spinlockinfo.hh click-1.2.4/elements/standard/spinlockinfo.hh --- click-1.2.4.orig/elements/standard/spinlockinfo.hh Fri Apr 5 11:39:36 2002 +++ click-1.2.4/elements/standard/spinlockinfo.hh Sun Jun 2 22:39:46 2002 @@ -19,6 +19,10 @@ * spinlock. */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class SpinlockInfo : public Element { HashMap _map; @@ -38,6 +42,10 @@ Spinlock *query(const String &, const String &) const; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/spinlockrelease.cc click-1.2.4/elements/standard/spinlockrelease.cc --- click-1.2.4.orig/elements/standard/spinlockrelease.cc Thu Feb 7 11:22:36 2002 +++ click-1.2.4/elements/standard/spinlockrelease.cc Sun Jun 2 22:40:11 2002 @@ -17,6 +17,10 @@ #include "spinlockinfo.hh" #include "spinlockrelease.hh" +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + int SpinlockRelease::configure(Vector &conf, ErrorHandler *errh) { diff -urN click-1.2.4.orig/elements/standard/spinlockrelease.hh click-1.2.4/elements/standard/spinlockrelease.hh --- click-1.2.4.orig/elements/standard/spinlockrelease.hh Fri Apr 5 11:51:13 2002 +++ click-1.2.4/elements/standard/spinlockrelease.hh Sun Jun 2 22:40:36 2002 @@ -12,6 +12,10 @@ * Releases the spinlock named S. S must be defined in a SpinlockInfo element. */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class SpinlockRelease : public Element { Spinlock *_lock; @@ -32,5 +36,9 @@ Packet *simple_action(Packet *p) { _lock->release(); return p; } }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/staticpullswitch.cc click-1.2.4/elements/standard/staticpullswitch.cc --- click-1.2.4.orig/elements/standard/staticpullswitch.cc Thu Feb 7 11:22:36 2002 +++ click-1.2.4/elements/standard/staticpullswitch.cc Sun Jun 2 22:40:58 2002 @@ -20,6 +20,10 @@ #include "staticpullswitch.hh" #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + StaticPullSwitch::StaticPullSwitch() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/standard/staticpullswitch.hh click-1.2.4/elements/standard/staticpullswitch.hh --- click-1.2.4.orig/elements/standard/staticpullswitch.hh Tue Mar 26 16:43:52 2002 +++ click-1.2.4/elements/standard/staticpullswitch.hh Sun Jun 2 22:41:21 2002 @@ -20,6 +20,10 @@ * * =a PullSwitch, PrioSched, RoundRobinSched, StrideSched, Switch */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class StaticPullSwitch : public Element { int _input; @@ -39,5 +43,9 @@ Packet *pull(int); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/staticswitch.cc click-1.2.4/elements/standard/staticswitch.cc --- click-1.2.4.orig/elements/standard/staticswitch.cc Thu Feb 7 11:22:37 2002 +++ click-1.2.4/elements/standard/staticswitch.cc Sun Jun 2 22:42:17 2002 @@ -20,6 +20,10 @@ #include "staticswitch.hh" #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + StaticSwitch::StaticSwitch() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/standard/staticswitch.hh click-1.2.4/elements/standard/staticswitch.hh --- click-1.2.4.orig/elements/standard/staticswitch.hh Tue Mar 26 16:43:59 2002 +++ click-1.2.4/elements/standard/staticswitch.hh Sun Jun 2 22:42:04 2002 @@ -20,6 +20,10 @@ * * =a Switch, StrideSwitch, PullSwitch */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class StaticSwitch : public Element { int _output; @@ -39,5 +43,9 @@ void push(int, Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/stridesched.cc click-1.2.4/elements/standard/stridesched.cc --- click-1.2.4.orig/elements/standard/stridesched.cc Fri Apr 5 11:39:43 2002 +++ click-1.2.4/elements/standard/stridesched.cc Sun Jun 2 22:42:40 2002 @@ -20,6 +20,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + StrideSched::StrideSched() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/standard/stridesched.hh click-1.2.4/elements/standard/stridesched.hh --- click-1.2.4.orig/elements/standard/stridesched.hh Fri Apr 26 11:01:57 2002 +++ click-1.2.4/elements/standard/stridesched.hh Sun Jun 2 22:43:08 2002 @@ -26,6 +26,10 @@ * =a PrioSched, RoundRobinSched, DRRSched, StrideSwitch */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class StrideSched : public Element { public: StrideSched(); @@ -124,5 +128,9 @@ { _pass += _stride; } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/strideswitch.cc click-1.2.4/elements/standard/strideswitch.cc --- click-1.2.4.orig/elements/standard/strideswitch.cc Thu Feb 7 11:22:40 2002 +++ click-1.2.4/elements/standard/strideswitch.cc Sun Jun 2 22:44:11 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + StrideSwitch::StrideSwitch() { // no MOD_INC_USE_COUNT; rely on StrideSched diff -urN click-1.2.4.orig/elements/standard/strideswitch.hh click-1.2.4/elements/standard/strideswitch.hh --- click-1.2.4.orig/elements/standard/strideswitch.hh Fri May 17 15:25:52 2002 +++ click-1.2.4/elements/standard/strideswitch.hh Sun Jun 2 22:44:37 2002 @@ -20,6 +20,10 @@ * =a RoundRobinSwitch, Switch, HashSwitch, RandomSwitch, StrideSched */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class StrideSwitch : public StrideSched { public: StrideSwitch(); @@ -34,5 +38,9 @@ void push(int, Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/strip.cc click-1.2.4/elements/standard/strip.cc --- click-1.2.4.orig/elements/standard/strip.cc Thu Feb 7 11:22:50 2002 +++ click-1.2.4/elements/standard/strip.cc Sun Jun 2 22:44:58 2002 @@ -22,6 +22,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + Strip::Strip() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/standard/strip.hh click-1.2.4/elements/standard/strip.hh --- click-1.2.4.orig/elements/standard/strip.hh Thu Feb 7 11:18:24 2002 +++ click-1.2.4/elements/standard/strip.hh Sun Jun 2 22:45:27 2002 @@ -17,6 +17,10 @@ * =a StripToNetworkHeader, EtherEncap, IPEncap */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Strip : public Element { public: Strip(); @@ -35,5 +39,9 @@ unsigned _nbytes; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/striptonet.cc click-1.2.4/elements/standard/striptonet.cc --- click-1.2.4.orig/elements/standard/striptonet.cc Mon Oct 8 15:32:46 2001 +++ click-1.2.4/elements/standard/striptonet.cc Sun Jun 2 22:46:06 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + StripToNetworkHeader::StripToNetworkHeader() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/standard/striptonet.hh click-1.2.4/elements/standard/striptonet.hh --- click-1.2.4.orig/elements/standard/striptonet.hh Mon Oct 8 15:31:12 2001 +++ click-1.2.4/elements/standard/striptonet.hh Sun Jun 2 22:46:31 2002 @@ -24,6 +24,10 @@ * =a Strip */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class StripToNetworkHeader : public Element { public: StripToNetworkHeader(); @@ -36,5 +40,9 @@ Packet *simple_action(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/suppressor.cc click-1.2.4/elements/standard/suppressor.cc --- click-1.2.4.orig/elements/standard/suppressor.cc Thu May 24 18:03:53 2001 +++ click-1.2.4/elements/standard/suppressor.cc Sun Jun 2 22:46:55 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + Suppressor::Suppressor() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/standard/suppressor.hh click-1.2.4/elements/standard/suppressor.hh --- click-1.2.4.orig/elements/standard/suppressor.hh Tue Mar 26 16:44:33 2002 +++ click-1.2.4/elements/standard/suppressor.hh Sun Jun 2 22:47:17 2002 @@ -22,6 +22,10 @@ * =h reset write-only * Resets every port to active. */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Suppressor : public Element { fd_set _suppressed; @@ -51,5 +55,9 @@ bool set(int output, bool suppressed); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/switch.cc click-1.2.4/elements/standard/switch.cc --- click-1.2.4.orig/elements/standard/switch.cc Thu Feb 7 18:29:37 2002 +++ click-1.2.4/elements/standard/switch.cc Sun Jun 2 22:47:34 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + Switch::Switch() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/standard/switch.hh click-1.2.4/elements/standard/switch.hh --- click-1.2.4.orig/elements/standard/switch.hh Fri May 17 15:25:39 2002 +++ click-1.2.4/elements/standard/switch.hh Sun Jun 2 22:47:57 2002 @@ -34,6 +34,10 @@ =a StaticSwitch, PullSwitch, RoundRobinSwitch, StrideSwitch, HashSwitch, RandomSwitch */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Switch : public Element { public: Switch(); @@ -62,5 +66,9 @@ static int write_param(const String &, Element *, void *, ErrorHandler *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/tee.cc click-1.2.4/elements/standard/tee.cc --- click-1.2.4.orig/elements/standard/tee.cc Thu Feb 7 11:22:54 2002 +++ click-1.2.4/elements/standard/tee.cc Sun Jun 2 22:48:14 2002 @@ -20,6 +20,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + Tee::Tee() { MOD_INC_USE_COUNT; diff -urN click-1.2.4.orig/elements/standard/tee.hh click-1.2.4/elements/standard/tee.hh --- click-1.2.4.orig/elements/standard/tee.hh Tue Mar 26 16:44:43 2002 +++ click-1.2.4/elements/standard/tee.hh Sun Jun 2 22:48:40 2002 @@ -21,6 +21,10 @@ * argument N. */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Tee : public Element { public: @@ -56,5 +60,9 @@ Packet *pull(int); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/timedsink.cc click-1.2.4/elements/standard/timedsink.cc --- click-1.2.4.orig/elements/standard/timedsink.cc Thu Feb 7 11:22:55 2002 +++ click-1.2.4/elements/standard/timedsink.cc Sun Jun 2 22:49:13 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + TimedSink::TimedSink() : Element(1, 0), _timer(this) { diff -urN click-1.2.4.orig/elements/standard/timedsink.hh click-1.2.4/elements/standard/timedsink.hh --- click-1.2.4.orig/elements/standard/timedsink.hh Tue Mar 26 16:44:48 2002 +++ click-1.2.4/elements/standard/timedsink.hh Sun Jun 2 22:49:33 2002 @@ -14,6 +14,10 @@ * =a Shaper */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class TimedSink : public Element { Timer _timer; @@ -34,5 +38,9 @@ void run_scheduled(); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/timedsource.cc click-1.2.4/elements/standard/timedsource.cc --- click-1.2.4.orig/elements/standard/timedsource.cc Fri Apr 5 11:40:16 2002 +++ click-1.2.4/elements/standard/timedsource.cc Sun Jun 2 22:49:55 2002 @@ -22,6 +22,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + TimedSource::TimedSource() : Element(0, 1), _packet(0), _timer(this) { diff -urN click-1.2.4.orig/elements/standard/timedsource.hh click-1.2.4/elements/standard/timedsource.hh --- click-1.2.4.orig/elements/standard/timedsource.hh Fri Apr 5 11:40:21 2002 +++ click-1.2.4/elements/standard/timedsource.hh Sun Jun 2 22:50:19 2002 @@ -56,6 +56,10 @@ =a InfiniteSource */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class TimedSource : public Element { public: TimedSource(); @@ -87,5 +91,9 @@ static int change_param(const String &, Element *, void *, ErrorHandler *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/unqueue.cc click-1.2.4/elements/standard/unqueue.cc --- click-1.2.4.orig/elements/standard/unqueue.cc Tue Mar 5 17:14:48 2002 +++ click-1.2.4/elements/standard/unqueue.cc Sun Jun 2 22:52:32 2002 @@ -22,6 +22,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + Unqueue::Unqueue() : Element(1, 1), _task(this) { diff -urN click-1.2.4.orig/elements/standard/unqueue.hh click-1.2.4/elements/standard/unqueue.hh --- click-1.2.4.orig/elements/standard/unqueue.hh Tue Mar 26 16:45:38 2002 +++ click-1.2.4/elements/standard/unqueue.hh Sun Jun 2 22:52:57 2002 @@ -41,6 +41,10 @@ =a RatedUnqueue, BandwidthRatedUnqueue */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Unqueue : public Element { public: Unqueue(); @@ -67,5 +71,9 @@ Task _task; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/unqueue2.cc click-1.2.4/elements/standard/unqueue2.cc --- click-1.2.4.orig/elements/standard/unqueue2.cc Tue Mar 5 17:14:52 2002 +++ click-1.2.4/elements/standard/unqueue2.cc Sun Jun 2 22:50:37 2002 @@ -26,6 +26,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + Unqueue2::Unqueue2() : Element(1, 1), _task(this) { diff -urN click-1.2.4.orig/elements/standard/unqueue2.hh click-1.2.4/elements/standard/unqueue2.hh --- click-1.2.4.orig/elements/standard/unqueue2.hh Tue Mar 26 16:45:46 2002 +++ click-1.2.4/elements/standard/unqueue2.hh Sun Jun 2 22:50:58 2002 @@ -19,6 +19,10 @@ * =a Unqueue, RatedUnqueue, BandwidthRatedUnqueue */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Unqueue2 : public Element { public: Unqueue2(); @@ -44,5 +48,9 @@ Vector _queue_elements; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/standard/unstrip.cc click-1.2.4/elements/standard/unstrip.cc --- click-1.2.4.orig/elements/standard/unstrip.cc Thu Feb 7 11:22:58 2002 +++ click-1.2.4/elements/standard/unstrip.cc Sun Jun 2 22:51:15 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + Unstrip::Unstrip(unsigned nbytes) : Element(1, 1), _nbytes(nbytes) { diff -urN click-1.2.4.orig/elements/standard/unstrip.hh click-1.2.4/elements/standard/unstrip.hh --- click-1.2.4.orig/elements/standard/unstrip.hh Tue Mar 26 16:45:50 2002 +++ click-1.2.4/elements/standard/unstrip.hh Sun Jun 2 22:51:43 2002 @@ -17,6 +17,10 @@ * =a EtherEncap, IPEncap */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Unstrip : public Element { unsigned _nbytes; @@ -35,5 +39,9 @@ Packet *simple_action(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/tcpudp/checktcpheader.cc click-1.2.4/elements/tcpudp/checktcpheader.cc --- click-1.2.4.orig/elements/tcpudp/checktcpheader.cc Tue May 21 17:32:00 2002 +++ click-1.2.4/elements/tcpudp/checktcpheader.cc Sun Jun 2 22:54:18 2002 @@ -29,6 +29,10 @@ # include #endif +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + const char *CheckTCPHeader::reason_texts[NREASONS] = { "not TCP", "bad packet length", "bad TCP checksum" }; diff -urN click-1.2.4.orig/elements/tcpudp/checktcpheader.hh click-1.2.4/elements/tcpudp/checktcpheader.hh --- click-1.2.4.orig/elements/tcpudp/checktcpheader.hh Tue Mar 26 16:48:04 2002 +++ click-1.2.4/elements/tcpudp/checktcpheader.hh Sun Jun 2 22:54:48 2002 @@ -51,6 +51,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class CheckTCPHeader : public Element { public: CheckTCPHeader(); @@ -87,5 +91,9 @@ static String read_handler(Element *, void *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/tcpudp/checkudpheader.cc click-1.2.4/elements/tcpudp/checkudpheader.cc --- click-1.2.4.orig/elements/tcpudp/checkudpheader.cc Tue May 21 17:32:05 2002 +++ click-1.2.4/elements/tcpudp/checkudpheader.cc Sun Jun 2 22:55:07 2002 @@ -28,6 +28,10 @@ # include #endif +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + const char *CheckUDPHeader::reason_texts[NREASONS] = { "not UDP", "bad packet length", "bad UDP checksum" }; diff -urN click-1.2.4.orig/elements/tcpudp/checkudpheader.hh click-1.2.4/elements/tcpudp/checkudpheader.hh --- click-1.2.4.orig/elements/tcpudp/checkudpheader.hh Tue Mar 26 16:48:08 2002 +++ click-1.2.4/elements/tcpudp/checkudpheader.hh Sun Jun 2 22:55:33 2002 @@ -51,6 +51,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class CheckUDPHeader : public Element { public: CheckUDPHeader(); @@ -87,5 +91,9 @@ static String read_handler(Element *, void *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/tcpudp/dynudpipencap.cc click-1.2.4/elements/tcpudp/dynudpipencap.cc --- click-1.2.4.orig/elements/tcpudp/dynudpipencap.cc Tue May 21 17:32:05 2002 +++ click-1.2.4/elements/tcpudp/dynudpipencap.cc Sun Jun 2 22:55:59 2002 @@ -26,6 +26,10 @@ # include #endif +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + DynamicUDPIPEncap::DynamicUDPIPEncap() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/tcpudp/dynudpipencap.hh click-1.2.4/elements/tcpudp/dynudpipencap.hh --- click-1.2.4.orig/elements/tcpudp/dynudpipencap.hh Tue May 21 17:32:05 2002 +++ click-1.2.4/elements/tcpudp/dynudpipencap.hh Sun Jun 2 22:56:26 2002 @@ -32,6 +32,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class DynamicUDPIPEncap : public Element { struct in_addr _saddr; @@ -58,5 +62,9 @@ Packet *simple_action(Packet *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/tcpudp/iprewriter.cc click-1.2.4/elements/tcpudp/iprewriter.cc --- click-1.2.4.orig/elements/tcpudp/iprewriter.cc Tue May 21 17:32:05 2002 +++ click-1.2.4/elements/tcpudp/iprewriter.cc Sun Jun 2 22:56:48 2002 @@ -27,6 +27,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + IPRewriter::IPRewriter() : _tcp_map(0), _udp_map(0), _tcp_done(0), _tcp_done_tail(0), diff -urN click-1.2.4.orig/elements/tcpudp/iprewriter.hh click-1.2.4/elements/tcpudp/iprewriter.hh --- click-1.2.4.orig/elements/tcpudp/iprewriter.hh Fri Apr 5 11:40:43 2002 +++ click-1.2.4/elements/tcpudp/iprewriter.hh Sun Jun 2 22:57:19 2002 @@ -166,6 +166,10 @@ # define IPRW_RWLOCKS 0 #endif +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class IPRewriter : public IPRw { public: IPRewriter(); @@ -243,5 +247,9 @@ else return 0; } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/tcpudp/settcpchecksum.cc click-1.2.4/elements/tcpudp/settcpchecksum.cc --- click-1.2.4.orig/elements/tcpudp/settcpchecksum.cc Tue May 21 17:32:05 2002 +++ click-1.2.4/elements/tcpudp/settcpchecksum.cc Sun Jun 2 22:57:43 2002 @@ -23,6 +23,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + SetTCPChecksum::SetTCPChecksum() : Element(1, 1), _fixoff(false) { diff -urN click-1.2.4.orig/elements/tcpudp/settcpchecksum.hh click-1.2.4/elements/tcpudp/settcpchecksum.hh --- click-1.2.4.orig/elements/tcpudp/settcpchecksum.hh Tue Mar 26 16:48:25 2002 +++ click-1.2.4/elements/tcpudp/settcpchecksum.hh Sun Jun 2 22:58:07 2002 @@ -18,6 +18,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class SetTCPChecksum : public Element { public: SetTCPChecksum(); @@ -33,5 +37,9 @@ private: bool _fixoff; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/tcpudp/snooptcp.cc click-1.2.4/elements/tcpudp/snooptcp.cc --- click-1.2.4.orig/elements/tcpudp/snooptcp.cc Fri Aug 3 16:21:25 2001 +++ click-1.2.4/elements/tcpudp/snooptcp.cc Sun Jun 2 22:58:31 2002 @@ -32,6 +32,10 @@ # define DEBUG_CHATTER(args...) /* nothing */ #endif +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + SnoopTCP::SnoopTCP() : Element(2, 4) { diff -urN click-1.2.4.orig/elements/tcpudp/snooptcp.hh click-1.2.4/elements/tcpudp/snooptcp.hh --- click-1.2.4.orig/elements/tcpudp/snooptcp.hh Tue May 21 17:32:05 2002 +++ click-1.2.4/elements/tcpudp/snooptcp.hh Sun Jun 2 22:58:56 2002 @@ -23,6 +23,10 @@ #define DEBUG +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class SnoopTCP : public Element { public: SnoopTCP(); @@ -111,5 +115,8 @@ }; +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/tcpudp/tcprewriter.cc click-1.2.4/elements/tcpudp/tcprewriter.cc --- click-1.2.4.orig/elements/tcpudp/tcprewriter.cc Tue May 21 17:32:06 2002 +++ click-1.2.4/elements/tcpudp/tcprewriter.cc Sat Jun 1 00:10:58 2002 @@ -25,6 +25,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + // TCPMapping TCPRewriter::TCPMapping::TCPMapping(bool dst_anno) diff -urN click-1.2.4.orig/elements/tcpudp/tcprewriter.hh click-1.2.4/elements/tcpudp/tcprewriter.hh --- click-1.2.4.orig/elements/tcpudp/tcprewriter.hh Tue May 21 17:32:06 2002 +++ click-1.2.4/elements/tcpudp/tcprewriter.hh Sat Jun 1 00:10:31 2002 @@ -67,6 +67,10 @@ =a IPRewriter, IPRewriterPatterns, FTPPortMapper */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class TCPRewriter : public IPRw { public: class TCPMapping : public Mapping { @@ -154,5 +158,9 @@ { return (SEQ_GEQ(seqno, _trigger) ? _delta : _old_delta); } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/tcpudp/udpipencap.cc click-1.2.4/elements/tcpudp/udpipencap.cc --- click-1.2.4.orig/elements/tcpudp/udpipencap.cc Tue May 21 17:32:06 2002 +++ click-1.2.4/elements/tcpudp/udpipencap.cc Sun Jun 2 22:59:26 2002 @@ -26,6 +26,10 @@ # include #endif +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + UDPIPEncap::UDPIPEncap() : Element(1, 1) { diff -urN click-1.2.4.orig/elements/tcpudp/udpipencap.hh click-1.2.4/elements/tcpudp/udpipencap.hh --- click-1.2.4.orig/elements/tcpudp/udpipencap.hh Tue May 21 17:32:06 2002 +++ click-1.2.4/elements/tcpudp/udpipencap.hh Sun Jun 2 22:59:50 2002 @@ -26,6 +26,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class UDPIPEncap : public Element { public: UDPIPEncap(); @@ -52,5 +56,9 @@ uatomic32_t _id; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/userlevel/controlsocket.cc click-1.2.4/elements/userlevel/controlsocket.cc --- click-1.2.4.orig/elements/userlevel/controlsocket.cc Fri Apr 5 11:44:49 2002 +++ click-1.2.4/elements/userlevel/controlsocket.cc Sun Jun 2 23:03:04 2002 @@ -29,6 +29,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + const char * const ControlSocket::protocol_version = "1.1"; struct ControlSocketErrorHandler : public ErrorHandler { public: diff -urN click-1.2.4.orig/elements/userlevel/controlsocket.hh click-1.2.4/elements/userlevel/controlsocket.hh --- click-1.2.4.orig/elements/userlevel/controlsocket.hh Wed Apr 24 10:14:09 2002 +++ click-1.2.4/elements/userlevel/controlsocket.hh Sun Jun 2 23:02:46 2002 @@ -1,6 +1,11 @@ #ifndef CLICK_CONTROLSOCKET_HH #define CLICK_CONTROLSOCKET_HH #include "elements/userlevel/handlerproxy.hh" + +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class ControlSocketErrorHandler; /* @@ -215,5 +220,9 @@ static ErrorHandler *proxy_error_function(const String &, void *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/elements/userlevel/handlerproxy.cc click-1.2.4/elements/userlevel/handlerproxy.cc --- click-1.2.4.orig/elements/userlevel/handlerproxy.cc Tue Jul 17 12:37:50 2001 +++ click-1.2.4/elements/userlevel/handlerproxy.cc Sun Jun 2 23:10:54 2002 @@ -19,6 +19,10 @@ #include "handlerproxy.hh" #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + HandlerProxy::HandlerProxy() : _err_rcvs(0), _nerr_rcvs(0) { diff -urN click-1.2.4.orig/elements/userlevel/handlerproxy.hh click-1.2.4/elements/userlevel/handlerproxy.hh --- click-1.2.4.orig/elements/userlevel/handlerproxy.hh Wed Apr 24 09:51:29 2002 +++ click-1.2.4/elements/userlevel/handlerproxy.hh Sun Jun 2 23:10:40 2002 @@ -2,6 +2,10 @@ #define CLICK_HANDLERPROXY_HH #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class HandlerProxy : public Element { public: typedef ErrorHandler *(*ErrorReceiverHook)(const String &, void *); @@ -36,5 +40,9 @@ int _nerr_rcvs; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/etc/libclick/Makefile click-1.2.4/etc/libclick/Makefile --- click-1.2.4.orig/etc/libclick/Makefile Wed Dec 31 17:00:00 1969 +++ click-1.2.4/etc/libclick/Makefile Wed Jun 5 16:53:11 2002 @@ -0,0 +1,81 @@ +# Generated automatically from Makefile.in by configure. +# Warning: this file must be usable by regular make +# (unlike the Makefiles in subdirectories). + +SHELL = /bin/sh + + +PACKAGE = click +VERSION = 1.2.4 + +top_srcdir = ../.. +srcdir = . +top_builddir = ../.. +subdir = etc/libclick +conf_auxdir = $(top_srcdir) + +AUTOCONF = autoconf +ACLOCAL = cp acclick.m4 aclocal.m4 +PERL = perl5 +INSTALL = /usr/bin/install -c +INSTALL_IF_CHANGED = /usr/bin/install -c -C +INSTALL_DATA = /usr/bin/install -c -m 644 +INSTALL_DATA_IF_CHANGED = /usr/bin/install -c -C -m 644 +mkinstalldirs = $(conf_auxdir)/mkinstalldirs + +prefix = /usr/local +exec_prefix = ${prefix} +includedir = ${prefix}/include/click +toolincludedir = ${prefix}/include/clicktool +bindir = /usr/local/bin +datadir = /usr/local/share/click + +all: + @echo This Makefile does not build anything. + @echo Its only important target is '`make dist'"'". + +Makefile: $(top_builddir)/config.status $(srcdir)/Makefile.in + cd $(top_builddir) && \ + CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status + +distdir = libclick-$(VERSION) +top_distdir = $(distdir) + +clean: + -rm -rf $(distdir) $(distdir).tar.gz +distclean: clean + -rm -f Makefile + +dist: $(distdir).tar.gz + -rm -rf $(distdir) +$(distdir).tar.gz: distdir + tar czf $(distdir).tar.gz $(distdir) +distdir: + @if test `grep 'CLICK_VERSION=' $(top_srcdir)/configure.in` != `grep 'CLICK_VERSION=' $(srcdir)/lc-configure.in`; then \ + echo 'ERROR: Bad libclick CLICK_VERSION!'; exit 1; \ + fi + -rm -rf $(distdir) + mkdir $(distdir) + @-chmod 777 $(distdir) + @echo Copying library, documentation, configuration, and driver files... + @echo DISTFILES >>$(distdir)/DISTFILES + @for file in `cat $(srcdir)/DISTFILES`; do \ + d=$(top_srcdir); \ + sf=`echo "$$file:$$file:" | sed 's/^\([^:]*\):.*/\1/'`; \ + df=`echo "$$file:$$file:" | sed 's/^[^:]*:\([^:]*\):.*/\1/'`; \ + if test -d "$$d/$$sf"; then \ + mkdir $(distdir)/$$df; \ + chmod 777 $(distdir)/$$df; \ + else \ + test -f "$(distdir)/$$df" \ + || ln $$d/$$sf $(distdir)/$$df 2>/dev/null \ + || cp -p $$d/$$sf $(distdir)/$$df \ + || echo "Could not copy $$d/$$sf!" 1>&2; \ + fi; \ + echo $$df >>$(distdir)/DISTFILES; \ + done + cd $(distdir) && $(PERL) -pi -e 's/enable_linuxmodule=yes/enable_linuxmodule=no/;' configure.in + cd $(distdir) && $(ACLOCAL) && $(AUTOCONF) + echo configure >>$(distdir)/DISTFILES + +.PHONY: all dist distdir diff -urN click-1.2.4.orig/include/click/archive.hh click-1.2.4/include/click/archive.hh --- click-1.2.4.orig/include/click/archive.hh Sun Dec 2 11:43:51 2001 +++ click-1.2.4/include/click/archive.hh Fri May 31 23:03:13 2002 @@ -3,6 +3,11 @@ #define CLICK_ARCHIVE_HH #include #include + +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class ErrorHandler; struct ArchiveElement { @@ -23,5 +28,9 @@ int separate_ar_string(const String &, Vector &, ErrorHandler * = 0); String create_ar_string(const Vector &, ErrorHandler * = 0); + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/bitvector.hh click-1.2.4/include/click/bitvector.hh --- click-1.2.4.orig/include/click/bitvector.hh Wed Apr 24 10:14:57 2002 +++ click-1.2.4/include/click/bitvector.hh Fri May 31 15:09:17 2002 @@ -3,6 +3,10 @@ #define CLICK_BITVECTOR_HH #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Bitvector { public: class Bit; @@ -230,5 +234,9 @@ { return *this & ~o; } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/confparse.hh click-1.2.4/include/click/confparse.hh --- click-1.2.4.orig/include/click/confparse.hh Wed Apr 24 09:51:29 2002 +++ click-1.2.4/include/click/confparse.hh Fri May 31 13:59:26 2002 @@ -3,6 +3,11 @@ #define CLICK_CONFPARSE_HH #include #include + +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class ErrorHandler; #ifndef CLICK_TOOL class Element; @@ -262,4 +267,9 @@ #undef CP_VA_ARGS_REST #undef CP_OPT_CONTEXT #undef CP_CONTEXT + +#ifdef CLICK_SIM +} +#endif + #endif diff -urN click-1.2.4.orig/include/click/element.hh click-1.2.4/include/click/element.hh --- click-1.2.4.orig/include/click/element.hh Tue Apr 30 16:16:13 2002 +++ click-1.2.4/include/click/element.hh Fri May 31 13:32:08 2002 @@ -5,6 +5,11 @@ #include #include #include + +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Router; class Task; class Element; @@ -325,6 +330,10 @@ else p->kill(); } + +#ifdef CLICK_SIM +} +#endif #undef CONNECTION_CTOR_INIT #endif diff -urN click-1.2.4.orig/include/click/elemfilter.hh click-1.2.4/include/click/elemfilter.hh --- click-1.2.4.orig/include/click/elemfilter.hh Fri Mar 29 12:26:47 2002 +++ click-1.2.4/include/click/elemfilter.hh Fri May 31 15:05:42 2002 @@ -3,6 +3,10 @@ #define CLICK_ELEMFILTER_HH #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class ElementFilter { public: ElementFilter() : _match_count(0) { } @@ -47,5 +51,9 @@ { return false; } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/error.hh click-1.2.4/include/click/error.hh --- click-1.2.4.orig/include/click/error.hh Tue Mar 5 16:51:05 2002 +++ click-1.2.4/include/click/error.hh Fri May 31 15:01:47 2002 @@ -7,6 +7,10 @@ #endif #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class ErrorHandler { public: enum Seriousness { @@ -163,6 +167,10 @@ int _exit_seriousness; }; +#endif + +#ifdef CLICK_SIM +} #endif #endif diff -urN click-1.2.4.orig/include/click/etheraddress.hh click-1.2.4/include/click/etheraddress.hh --- click-1.2.4.orig/include/click/etheraddress.hh Sun Dec 2 18:53:19 2001 +++ click-1.2.4/include/click/etheraddress.hh Fri May 31 14:10:05 2002 @@ -3,6 +3,10 @@ #define CLICK_ETHERADDRESS_HH #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class EtherAddress { public: EtherAddress() { _data[0] = _data[1] = _data[2] = 0; } @@ -72,5 +76,9 @@ const unsigned char *d = ea.data(); return (d[2] | (d[1] << 16)) ^ (d[0] << 9); } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/ewma.hh click-1.2.4/include/click/ewma.hh --- click-1.2.4.orig/include/click/ewma.hh Sun Dec 2 12:05:46 2001 +++ click-1.2.4/include/click/ewma.hh Sat Jun 1 23:33:28 2002 @@ -4,6 +4,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + template class DirectEWMAX { public: @@ -139,14 +143,26 @@ inline String DirectEWMAX::unparse() const { - return cp_unparse_real2(average(), scale); + return +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unparse_real2(average(), scale); } template inline String RateEWMAX::unparse(unsigned which) const { - return cp_unparse_real2(average(which) * Timer::freq(), scale); + return +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unparse_real2(average(which) * Timer::freq(), scale); +} + +#ifdef CLICK_SIM } +#endif #endif diff -urN click-1.2.4.orig/include/click/gaprate.hh click-1.2.4/include/click/gaprate.hh --- click-1.2.4.orig/include/click/gaprate.hh Wed Apr 24 10:19:27 2002 +++ click-1.2.4/include/click/gaprate.hh Fri May 31 15:07:01 2002 @@ -2,6 +2,11 @@ #ifndef CLICK_GAPRATE_HH #define CLICK_GAPRATE_HH #include + +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class ErrorHandler; class GapRate { public: @@ -83,5 +88,9 @@ #endif return ((int)need >= _sec_count); } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/glue.hh click-1.2.4/include/click/glue.hh --- click-1.2.4.orig/include/click/glue.hh Tue Apr 30 16:15:40 2002 +++ click-1.2.4/include/click/glue.hh Mon Jun 3 20:00:56 2002 @@ -7,9 +7,17 @@ * kernel and user space, and between operating systems. */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + // produce debugging output on the console or stderr void click_chatter(const char *fmt, ...); +#ifdef CLICK_SIM +} +#endif + #if CLICK_DMALLOC && (defined(CLICK_LINUXMODULE) || defined(CLICK_BSDMODULE)) extern int click_dmalloc_where; # define CLICK_DMALLOC_REG(s) do { const unsigned char *__str = reinterpret_cast(s); click_dmalloc_where = (__str[0]<<24) | (__str[1]<<16) | (__str[2]<<8) | __str[3]; } while (0) @@ -18,8 +26,16 @@ #endif // set random seed randomly +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + extern void click_random_srandom(); +#ifdef CLICK_SIM +} +#endif + #ifdef CLICK_LINUXMODULE /* @@ -175,6 +191,13 @@ # include # include # include +# ifdef CLICK_SIM +# include "simclick.h" +# endif + +# ifdef CLICK_SIM +namespace CLICKSIM { +# endif inline uint64_t click_get_cycles() @@ -182,12 +205,22 @@ return(0); } +// The CLICK_SIM flag means we shouldn't use the regular system +// gettimeofday, but rather the simulator interface code. +# ifndef CLICK_SIM # define click_gettimeofday(tvp) (gettimeofday(tvp, (struct timezone *) 0)) +# else +# define click_gettimeofday(tvp) (simclick_gettimeofday(tvp)) +# endif # define CLICK_HZ 100 // click_jiffies rate extern unsigned click_jiffies(); // provide a definition for net_device typedef struct device net_device; + +# ifdef CLICK_SIM +} +# endif #endif /* CLICK_LINUXMODULE */ diff -urN click-1.2.4.orig/include/click/handlercall.hh click-1.2.4/include/click/handlercall.hh --- click-1.2.4.orig/include/click/handlercall.hh Wed Apr 24 10:02:36 2002 +++ click-1.2.4/include/click/handlercall.hh Fri May 31 15:10:29 2002 @@ -3,6 +3,10 @@ #define CLICK_HANDLERCALL_HH #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class HandlerCall { public: HandlerCall() : _e(0), _hi(-1) { } @@ -92,5 +96,9 @@ { return call_write(context->router(), errh); } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/hashmap.hh click-1.2.4/include/click/hashmap.hh --- click-1.2.4.orig/include/click/hashmap.hh Fri Apr 26 12:55:35 2002 +++ click-1.2.4/include/click/hashmap.hh Sat Jun 1 23:35:23 2002 @@ -15,6 +15,10 @@ // V::V() // V & V::operator=(const V &) +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + template class HashMapIterator; template @@ -133,5 +137,9 @@ { return u; } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/ip6address.hh click-1.2.4/include/click/ip6address.hh --- click-1.2.4.orig/include/click/ip6address.hh Tue May 21 17:33:04 2002 +++ click-1.2.4/include/click/ip6address.hh Fri May 31 14:40:12 2002 @@ -5,6 +5,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class IP6Address { public: IP6Address(); @@ -178,5 +182,9 @@ { return a.data32()[3]; } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/ip6table.hh click-1.2.4/include/click/ip6table.hh --- click-1.2.4.orig/include/click/ip6table.hh Sun Dec 2 11:55:42 2001 +++ click-1.2.4/include/click/ip6table.hh Fri May 31 23:23:00 2002 @@ -10,6 +10,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class IP6Table { public: IP6Table(); @@ -33,5 +37,9 @@ Vector _v; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/ipaddress.hh click-1.2.4/include/click/ipaddress.hh --- click-1.2.4.orig/include/click/ipaddress.hh Tue May 21 17:33:07 2002 +++ click-1.2.4/include/click/ipaddress.hh Fri May 31 13:35:15 2002 @@ -5,6 +5,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class IPAddress { public: IPAddress() : _addr(0) { } @@ -188,5 +192,9 @@ { return a.addr(); } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/ipaddressset.hh click-1.2.4/include/click/ipaddressset.hh --- click-1.2.4.orig/include/click/ipaddressset.hh Sun Dec 2 12:08:17 2001 +++ click-1.2.4/include/click/ipaddressset.hh Fri May 31 14:50:46 2002 @@ -4,6 +4,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class IPAddressSet { public: IPAddressSet() { } @@ -24,5 +28,9 @@ Vector _s; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/ipflowid.hh click-1.2.4/include/click/ipflowid.hh --- click-1.2.4.orig/include/click/ipflowid.hh Thu Jan 24 12:14:33 2002 +++ click-1.2.4/include/click/ipflowid.hh Fri May 31 13:36:17 2002 @@ -2,6 +2,11 @@ #ifndef CLICK_IPFLOWID_HH #define CLICK_IPFLOWID_HH #include + +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Packet; class IPFlowID { public: @@ -94,5 +99,9 @@ } StringAccum &operator<<(StringAccum &, const IPFlowID &); + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/iptable.hh click-1.2.4/include/click/iptable.hh --- click-1.2.4.orig/include/click/iptable.hh Sun Dec 2 11:56:35 2001 +++ click-1.2.4/include/click/iptable.hh Fri May 31 23:14:28 2002 @@ -9,6 +9,10 @@ // Lookup by longest prefix. // Each entry contains a gateway and an output index. +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class IPTable { public: IPTable(); @@ -32,5 +36,9 @@ Vector _v; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/lexer.hh click-1.2.4/include/click/lexer.hh --- click-1.2.4.orig/include/click/lexer.hh Wed Apr 24 10:15:40 2002 +++ click-1.2.4/include/click/lexer.hh Wed Jun 5 16:43:52 2002 @@ -4,6 +4,11 @@ #include #include #include + +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class LexerExtra; class VariableEnvironment; @@ -93,11 +98,14 @@ void find_connections(const Hookup &, bool, Vector &) const; void expand_connection(const Hookup &, bool, Vector &) const; - + +#ifndef CLICK_SIM Router *create_router(); +#else + Router *create_router(simclick_sim siminst); +#endif private: - // lexer String _big_string; @@ -178,5 +186,9 @@ virtual void require(String, ErrorHandler *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/notifier.hh click-1.2.4/include/click/notifier.hh --- click-1.2.4.orig/include/click/notifier.hh Fri Mar 29 12:52:57 2002 +++ click-1.2.4/include/click/notifier.hh Sat Jun 1 00:03:11 2002 @@ -3,6 +3,10 @@ #define CLICK_NOTIFIER_HH #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class NotifierSignal { public: NotifierSignal(); // always true @@ -138,5 +142,9 @@ (*t)->reschedule(); _signal.set_active(true); } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/package.hh click-1.2.4/include/click/package.hh --- click-1.2.4.orig/include/click/package.hh Thu Jul 19 21:45:10 2001 +++ click-1.2.4/include/click/package.hh Sun Jun 2 00:40:24 2002 @@ -6,6 +6,10 @@ class Element; #endif +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + extern "C" { void click_provide(const char *); @@ -19,5 +23,9 @@ #endif } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/packet.hh click-1.2.4/include/click/packet.hh --- click-1.2.4.orig/include/click/packet.hh Thu May 16 10:55:46 2002 +++ click-1.2.4/include/click/packet.hh Fri May 31 12:47:40 2002 @@ -7,6 +7,14 @@ # include #endif +#ifdef CLICK_SIM +# include +#endif + +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class IP6Address; struct click_ether; struct click_ip; @@ -182,6 +190,12 @@ struct timeval ×tamp_anno() { return _timestamp; } void set_timestamp_anno(const struct timeval &tv) { _timestamp = tv; } void set_timestamp_anno(int s, int us) { _timestamp.tv_sec = s; _timestamp.tv_usec = us; } +#ifdef CLICK_SIM + simclick_simpacketinfo* get_sim_packetinfo() { return &_sim_packetinfo; } + void set_sim_packetinfo(simclick_simpacketinfo* pinfo) { + _sim_packetinfo = *pinfo; + } +#endif # ifdef CLICK_BSDMODULE /* BSD kernel module */ net_device *device_anno() const { if (m()) return m()->m_pkthdr.rcvif; else return NULL; } @@ -276,6 +290,9 @@ #ifdef CLICK_BSDMODULE struct mbuf *_m; #endif +#ifdef CLICK_SIM + simclick_simpacketinfo _sim_packetinfo; +#endif #endif Packet(); @@ -284,7 +301,11 @@ Packet &operator=(const Packet &); #ifndef CLICK_LINUXMODULE - Packet(int, int, int) { } + Packet(int, int, int) { +#ifdef CLICK_SIM + memset(&_sim_packetinfo,-1,sizeof(_sim_packetinfo)); +#endif + } static WritablePacket *make(int, int, int); bool alloc_data(uint32_t, uint32_t, uint32_t); #endif @@ -780,5 +801,9 @@ mskb->h.raw += (mskb->h.raw ? shift : 0); #endif } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/router.hh click-1.2.4/include/click/router.hh --- click-1.2.4.orig/include/click/router.hh Sat May 4 13:11:59 2002 +++ click-1.2.4/include/click/router.hh Wed Jun 5 17:07:20 2002 @@ -9,6 +9,16 @@ #if CLICK_USERLEVEL # include #endif +#ifdef CLICK_SIM +#include +#include +#include +#endif + +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class ElementFilter; class RouterThread; @@ -96,8 +106,17 @@ #if CLICK_USERLEVEL enum { SELECT_READ = Element::SELECT_READ, SELECT_WRITE = Element::SELECT_WRITE }; +#ifndef CLICK_SIM int add_select(int fd, int element, int mask); +#else + int add_select(int fd, int element, int mask) { invalid_in_sim(); } +#endif + +#ifndef CLICK_SIM int remove_select(int fd, int element, int mask); +#else + int remove_select(int fd, int element, int mask) { invalid_in_sim(); } +#endif #endif void *attachment(const String &) const; @@ -129,8 +148,29 @@ bool check_driver(); const volatile int *driver_runcount_ptr() const { return &_driver_runcount; } +#ifdef CLICK_SIM + void invalid_in_sim(); + int sim_get_ifid(const char* ifname); + int sim_listen(int ifid,int element); + int sim_if_ready(int ifid); + int sim_write(int ifid,int ptype,const unsigned char* data,int len, + simclick_simpacketinfo* pinfo); + int sim_incoming_packet(int ifid,int ptype,const unsigned char* data,int len, + simclick_simpacketinfo* pinfo); + void set_siminst(simclick_sim newinst) { siminst_ = newinst; } + simclick_sim get_siminst() { return siminst_; } + + void set_clickinst(simclick_click newinst) { clickinst_ = newinst; } + simclick_click get_clickinst() { return clickinst_; } + +protected: + simclick_sim siminst_; + simclick_click clickinst_; + hash_map< int,vector > ifidmap_; + +#endif + private: - TimerList _timer_list; TaskList _task_list; volatile int _driver_runcount; @@ -362,5 +402,9 @@ { _timer_list.run(); } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/routerthread.hh click-1.2.4/include/click/routerthread.hh --- click-1.2.4.orig/include/click/routerthread.hh Wed Apr 24 10:04:30 2002 +++ click-1.2.4/include/click/routerthread.hh Tue Jun 4 14:14:02 2002 @@ -8,6 +8,10 @@ // We cannot #include ourselves because of circular #include // dependency. +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class RouterThread : public Task { public: RouterThread(Router*); @@ -15,7 +19,6 @@ Router *router() const { return _router; } int thread_id() const { return _id; } - void driver(); void driver_once(); @@ -87,5 +90,9 @@ { _task_lock.release(); } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/simclick.h click-1.2.4/include/click/simclick.h --- click-1.2.4.orig/include/click/simclick.h Wed Dec 31 17:00:00 1969 +++ click-1.2.4/include/click/simclick.h Wed Jun 5 10:52:34 2002 @@ -0,0 +1,106 @@ +#ifndef SIMCLICK_H +#define SIMCLICK_H + +/* + * + * simclick.h + * + * API for sending packets to Click. Mostly intended for use + * by a network simulator which wants to use Click to do routing. + * + */ + + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Packet types used - generally going to be ethernet, but could + * possibly be something else I suppose... + */ +#define SIMCLICK_PTYPE_UNKNOWN 0 +#define SIMCLICK_PTYPE_ETHER 1 +#define SIMCLICK_PTYPE_IP 2 + +/* + * Not a whole lot to this. We have to create a click router object + * and also send packets and trigger events. + */ + +/* + * This encapsulates the state info that click needs from the simulator. + * Right now this is just a timestamp, but we might need to send over + * more stuff at some point. This is essentially a big old blob of globals, + * so watch out that it doesn't turn into a monstrosity. + */ +typedef struct { + struct timeval curtime; +} simclick_simstate; + + +/* + * This contains per packet data we need to preserve when the packet gets + * dragged through click. Heavily biased towards ns-2 right now. + */ +typedef struct { + /* + * Simulator ID number for the packet + */ + int id; + + /* + * Simulator flow ID number for the packet + */ + int fid; +} simclick_simpacketinfo; + +/* + * Opaque handles for the sim and click instances + */ +typedef void* simclick_click; +typedef void* simclick_sim; + +simclick_click simclick_click_create(simclick_sim siminst, + const char* router_file, + simclick_simstate* startstate); +int simclick_click_send(simclick_click clickinst,simclick_simstate* state, + int ifid,int type,const unsigned char* data,int len, + simclick_simpacketinfo* pinfo); + +void simclick_click_run(simclick_click clickinst,simclick_simstate* state); + +void simclick_click_kill(simclick_click clickinst,simclick_simstate* state); + +/* + * The simulated system also has to provide a few services to click, + * notably some way of injecting packets back into the system, + * mapping interface names to id numbers, and arranging for click + * to execute at a specified time in the future. + */ +int simclick_sim_ifid_from_name(simclick_sim siminst,const char* ifname); +void simclick_sim_ipaddr_from_name(simclick_sim siminst,const char* ifname, + char* buf,int len); +void simclick_sim_macaddr_from_name(simclick_sim siminst,const char* ifname, + char* buf,int len); +int simclick_sim_send_to_if(simclick_sim siminst,simclick_click clickinst, + int ifid,int type, const unsigned char* data, + int len,simclick_simpacketinfo*); +int simclick_sim_schedule(simclick_sim siminst,simclick_click clickinst, + struct timeval* when); +void simclick_sim_get_node_name(simclick_sim siminst,char* buf,int len); + +int simclick_sim_if_ready(simclick_sim siminst,simclick_click clickinst, + int ifid); + +/* + * We also provide a gettimeofday substitute which utilizes the + * state info passed to us by the simulator. + */ +int simclick_gettimeofday(struct timeval* tv); + +#ifdef __cplusplus +} +#endif + +#endif diff -urN click-1.2.4.orig/include/click/standard/addressinfo.hh click-1.2.4/include/click/standard/addressinfo.hh --- click-1.2.4.orig/include/click/standard/addressinfo.hh Thu Feb 7 11:24:09 2002 +++ click-1.2.4/include/click/standard/addressinfo.hh Fri May 31 15:11:27 2002 @@ -7,6 +7,10 @@ # include #endif +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + /* =c @@ -116,5 +120,9 @@ static AddressInfo *find_element(Element *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/standard/alignmentinfo.hh click-1.2.4/include/click/standard/alignmentinfo.hh --- click-1.2.4.orig/include/click/standard/alignmentinfo.hh Thu Feb 7 11:24:18 2002 +++ click-1.2.4/include/click/standard/alignmentinfo.hh Sat Jun 1 00:05:18 2002 @@ -24,6 +24,10 @@ #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class AlignmentInfo : public Element { public: AlignmentInfo(); @@ -45,5 +49,9 @@ Vector _offsets; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/standard/drivermanager.hh click-1.2.4/include/click/standard/drivermanager.hh --- click-1.2.4.orig/include/click/standard/drivermanager.hh Thu Feb 7 11:24:21 2002 +++ click-1.2.4/include/click/standard/drivermanager.hh Fri May 31 23:05:54 2002 @@ -94,6 +94,10 @@ */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class DriverManager : public Element { public: DriverManager(); @@ -130,5 +134,9 @@ bool step_insn(); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/standard/errorelement.hh click-1.2.4/include/click/standard/errorelement.hh --- click-1.2.4.orig/include/click/standard/errorelement.hh Thu Feb 7 11:24:23 2002 +++ click-1.2.4/include/click/standard/errorelement.hh Fri May 31 22:19:36 2002 @@ -15,6 +15,10 @@ * spurious error messages about bad configuration strings or connections. */ +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class ErrorElement : public Element { public: ErrorElement(); @@ -31,5 +35,9 @@ int initialize(ErrorHandler *); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/standard/scheduleinfo.hh click-1.2.4/include/click/standard/scheduleinfo.hh --- click-1.2.4.orig/include/click/standard/scheduleinfo.hh Thu Feb 7 11:24:27 2002 +++ click-1.2.4/include/click/standard/scheduleinfo.hh Sat Jun 1 00:06:49 2002 @@ -67,6 +67,10 @@ #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class ScheduleInfo : public Element { public: static const int FRAC_BITS = 10; @@ -107,5 +111,9 @@ { initialize_task(e, t, true, errh); } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/straccum.hh click-1.2.4/include/click/straccum.hh --- click-1.2.4.orig/include/click/straccum.hh Tue Mar 5 16:36:22 2002 +++ click-1.2.4/include/click/straccum.hh Fri May 31 14:08:59 2002 @@ -11,6 +11,10 @@ # include #endif +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class StringAccum { public: StringAccum() : _s(0), _len(0), _cap(0) { } @@ -98,7 +102,12 @@ StringAccum &operator<<(StringAccum &, double); #endif -struct timeval; +struct +#ifdef CLICK_SIM +:: +#endif +timeval; + StringAccum &operator<<(StringAccum &, const struct timeval &); @@ -256,5 +265,9 @@ sa.append(sb.data(), sb.length()); return sa; } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/string.hh click-1.2.4/include/click/string.hh --- click-1.2.4.orig/include/click/string.hh Sun Jan 20 12:44:50 2002 +++ click-1.2.4/include/click/string.hh Fri May 31 14:01:17 2002 @@ -5,6 +5,10 @@ # include "permstr.hh" #endif +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class String { public: // Call static_initialize() before any function which might deal with @@ -442,5 +446,9 @@ #endif int hashcode(const String &); + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/subvector.hh click-1.2.4/include/click/subvector.hh --- click-1.2.4.orig/include/click/subvector.hh Sun Dec 2 12:11:03 2001 +++ click-1.2.4/include/click/subvector.hh Sat Jun 1 10:29:37 2002 @@ -2,6 +2,10 @@ #define CLICK_SUBVECTOR_HH #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + template class Subvector { public: @@ -116,5 +120,9 @@ Subvector &operator=(const Subvector &); }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/sync.hh click-1.2.4/include/click/sync.hh --- click-1.2.4.orig/include/click/sync.hh Tue Mar 5 16:36:47 2002 +++ click-1.2.4/include/click/sync.hh Sun Jun 2 00:32:09 2002 @@ -15,6 +15,10 @@ // loop-in-cache spinlock implementation: 12 bytes. if the size of this class // changes, change size of padding in ReadWriteLock below. +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + #if defined(__KERNEL__) && defined(__SMP__) class Spinlock { public: @@ -263,6 +267,10 @@ }; #endif /* defined(__KERNEL__) && defined(__SMP__) */ + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/task.hh click-1.2.4/include/click/task.hh --- click-1.2.4.orig/include/click/task.hh Wed Apr 24 10:05:06 2002 +++ click-1.2.4/include/click/task.hh Sat Jun 1 23:27:06 2002 @@ -8,6 +8,10 @@ # include #endif +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + #define PASS_GT(a, b) ((int)(a - b) > 0) typedef void (*TaskHook)(Task *, void *); @@ -131,10 +135,16 @@ }; +#ifdef CLICK_SIM +} +#endif // need RouterThread's definition for inline functions #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif inline Task::Task(TaskHook hook, void *thunk) @@ -317,5 +327,9 @@ { return _lock.attempt(); } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/timer.hh click-1.2.4/include/click/timer.hh --- click-1.2.4.orig/include/click/timer.hh Fri Apr 5 11:03:58 2002 +++ click-1.2.4/include/click/timer.hh Wed Jun 5 16:37:07 2002 @@ -3,6 +3,11 @@ #define CLICK_TIMER_HH #include #include + +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class Element; class Router; class Timer; @@ -36,6 +41,14 @@ void reschedule_after_s(uint32_t); void reschedule_after_ms(uint32_t); void unschedule(); +#ifdef CLICK_SIM + void set_router(Router* srtr) { _sr = srtr; } +#endif + +#ifdef CLICK_SIM +protected: + Router* _sr; +#endif private: @@ -79,6 +92,9 @@ { assert(!initialized()); _head = t; +#ifdef CLICK_SIM + _sr = t->_sr; +#endif } inline bool @@ -98,5 +114,9 @@ { schedule_at(tv); } + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/userutils.hh click-1.2.4/include/click/userutils.hh --- click-1.2.4.orig/include/click/userutils.hh Wed Mar 27 21:56:23 2002 +++ click-1.2.4/include/click/userutils.hh Fri May 31 23:25:49 2002 @@ -3,6 +3,11 @@ #define CLICK_USERUTILS_HH #include #include + +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class ErrorHandler; bool glob_match(const String &string, const String &pattern); @@ -35,6 +40,10 @@ #if HAVE_DYNAMIC_LINKING int clickdl_load_package(String, ErrorHandler *); void clickdl_load_requirement(String, const Vector *archive, ErrorHandler *); +#endif + +#ifdef CLICK_SIM +} #endif #endif diff -urN click-1.2.4.orig/include/click/variableenv.hh click-1.2.4/include/click/variableenv.hh --- click-1.2.4.orig/include/click/variableenv.hh Sun Dec 2 12:11:24 2001 +++ click-1.2.4/include/click/variableenv.hh Fri May 31 22:17:09 2002 @@ -4,6 +4,10 @@ #include #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + class VariableEnvironment { public: VariableEnvironment() { } @@ -28,5 +32,9 @@ Vector _depths; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/click/vector.hh click-1.2.4/include/click/vector.hh --- click-1.2.4.orig/include/click/vector.hh Mon Mar 11 10:45:01 2002 +++ click-1.2.4/include/click/vector.hh Sat Jun 1 10:28:42 2002 @@ -1,5 +1,10 @@ #ifndef CLICK_VECTOR_HH #define CLICK_VECTOR_HH + +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + template class Subvector; template @@ -166,5 +171,9 @@ void swap(Vector &o) { Base::swap(o); } }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/clicknet/ether.h click-1.2.4/include/clicknet/ether.h --- click-1.2.4.orig/include/clicknet/ether.h Tue May 21 17:35:08 2002 +++ click-1.2.4/include/clicknet/ether.h Sat Jun 1 23:38:24 2002 @@ -6,6 +6,10 @@ * -- our own definitions of Ethernet and ARP headers * based on a file from one of the BSDs */ + +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif CLICK_SIZE_PACKED_STRUCTURE( struct click_ether {, @@ -87,5 +91,9 @@ uint8_t reserved[3]; uint8_t nd_tpa[16]; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/clicknet/icmp.h click-1.2.4/include/clicknet/icmp.h --- click-1.2.4.orig/include/clicknet/icmp.h Tue May 21 17:35:21 2002 +++ click-1.2.4/include/clicknet/icmp.h Fri May 31 14:58:51 2002 @@ -2,6 +2,10 @@ #define CLICKNET_ICMP_H #include +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + /* * -- our own definitions for ICMP packets * based on a file from one of the BSDs @@ -96,5 +100,9 @@ #define icmp_quence icmp_generic #define icmp_info icmp_sequenced #define icmp_echo icmp_sequenced + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/clicknet/ip.h click-1.2.4/include/clicknet/ip.h --- click-1.2.4.orig/include/clicknet/ip.h Tue May 21 17:35:48 2002 +++ click-1.2.4/include/clicknet/ip.h Fri May 31 23:09:11 2002 @@ -14,6 +14,12 @@ uint16_t click_in_cksum(const unsigned char *addr, int len); #endif +#ifdef __cplusplus +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif +#endif + /* * -- our own definitions of IP headers * based on a file from one of the BSDs @@ -120,6 +126,12 @@ sum = (sum & 0xFFFF) + (sum >> 16); *csum = ~(sum + (sum >> 16)); } + +#ifdef __cplusplus +#ifdef CLICK_SIM +} +#endif +#endif CLICK_CXX_UNPROTECT #include diff -urN click-1.2.4.orig/include/clicknet/ip6.h click-1.2.4/include/clicknet/ip6.h --- click-1.2.4.orig/include/clicknet/ip6.h Tue May 21 17:36:40 2002 +++ click-1.2.4/include/clicknet/ip6.h Fri May 31 14:57:16 2002 @@ -7,6 +7,10 @@ #undef s6_addr32 #undef s6_addr64 +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + /* * -- our own definitions of IP6 headers * based on RFC 2460 @@ -89,5 +93,9 @@ unsigned short ori_csum, unsigned char *addr, unsigned short len2); + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/include/clicknet/tcp.h click-1.2.4/include/clicknet/tcp.h --- click-1.2.4.orig/include/clicknet/tcp.h Tue May 21 17:36:06 2002 +++ click-1.2.4/include/clicknet/tcp.h Fri May 31 14:59:27 2002 @@ -2,6 +2,10 @@ #ifndef CLICKNET_TCP_H #define CLICKNET_TCP_H +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + /* * -- our own definition of the TCP header * based on a file from one of the BSDs @@ -43,5 +47,11 @@ #define SEQ_LEQ(x,y) ((int)((x)-(y)) <= 0) #define SEQ_GT(x,y) ((int)((x)-(y)) > 0) #define SEQ_GEQ(x,y) ((int)((x)-(y)) >= 0) + + +#ifdef CLICK_SIM +} +#endif + #endif diff -urN click-1.2.4.orig/include/clicknet/udp.h click-1.2.4/include/clicknet/udp.h --- click-1.2.4.orig/include/clicknet/udp.h Tue May 21 17:36:17 2002 +++ click-1.2.4/include/clicknet/udp.h Fri May 31 14:58:22 2002 @@ -1,6 +1,10 @@ #ifndef CLICKNET_UDP_H #define CLICKNET_UDP_H +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif + /* * -- our own definition of the UDP header * based on a file from one of the BSDs @@ -12,5 +16,9 @@ uint16_t uh_ulen; uint16_t uh_sum; }; + +#ifdef CLICK_SIM +} +#endif #endif diff -urN click-1.2.4.orig/lib/#confparse.cc# click-1.2.4/lib/#confparse.cc# --- click-1.2.4.orig/lib/#confparse.cc# Wed Dec 31 17:00:00 1969 +++ click-1.2.4/lib/#confparse.cc# Tue Jun 4 10:34:31 2002 @@ -0,0 +1,3620 @@ +// -*- c-basic-offset: 2; related-file-name: "../include/click/confparse.hh" -*- +/* + * confparse.{cc,hh} -- configuration string parsing + * Eddie Kohler + * + * Copyright (c) 1999-2000 Massachusetts Institute of Technology + * Copyright (c) 2000-2001 Mazu Networks, Inc. + * Copyright (c) 2001 International Computer Science Institute + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, subject to the conditions + * listed in the Click LICENSE file. These conditions include: you must + * preserve this copyright notice, and you cannot mention the copyright + * holders in advertising related to the Software without their permission. + * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This + * notice is a summary of the Click LICENSE file; the license in that file is + * legally binding. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_IP6 +#include +#endif +#ifndef CLICK_TOOL +# include +# include +# include +# define CP_CONTEXT_ARG , Element *context +# define CP_PASS_CONTEXT , context +#else +# define CP_CONTEXT_ARG +# define CP_PASS_CONTEXT +#endif +#ifdef CLICK_USERLEVEL +# include +#endif +#include + +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + +int +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_errno; + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_eat_space(String &str) +{ + const char *s = str.data(); + int len = str.length(); + int i = 0; + while (i < len) { + if (!isspace(s[i])) + break; + i++; + } + str = str.substring(i); + return true; +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_is_space(const String &str) +{ + const char *s = str.data(); + int len = str.length(); + for (int i = 0; i < len; i++) + if (!isspace(s[i])) + return false; + return true; +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_is_word(const String &str) +{ + const char *s = str.data(); + int len = str.length(); + for (int i = 0; i < len; i++) + if (s[i] == '\"' || s[i] == '\'' || s[i] == '\\' || s[i] == ',' + || s[i] <= 32 || s[i] >= 127) + return false; + return len > 0; +} + +static int +xvalue(int x) +{ + if (x >= '0' && x <= '9') + return x - '0'; + else if (x >= 'A' && x <= 'F') + return x - 'A' + 10; + else if (x >= 'a' && x <= 'f') + return x - 'a' + 10; + else + return -1; +} + +static int +skip_comment(const char *s, int pos, int len) +{ + assert(pos < len - 1 && s[pos] == '/' && (s[pos+1] == '/' || s[pos+1] == '*')); + + if (s[pos+1] == '/') { + for (pos += 2; pos < len - 1 && s[pos] != '\n' && s[pos] != '\r'; pos++) + /* nada */; + if (pos < len - 1 && s[pos] == '\r' && s[pos+1] == '\n') + pos++; + return pos + 1; + } else { /* s[pos+1] == '*' */ + for (pos += 2; pos < len - 2 && (s[pos] != '*' || s[pos+1] != '/'); pos++) + /* nada */; + return pos + 2; + } +} + +static int +skip_backslash_angle(const char *s, int pos, int len) +{ + assert(pos < len - 1 && s[pos] == '\\' && s[pos+1] == '<'); + + for (pos += 2; pos < len; ) + if (s[pos] == '>') + return pos + 1; + else if (s[pos] == '/' && pos < len - 1 && (s[pos+1] == '/' || s[pos+1] == '*')) + pos = skip_comment(s, pos, len); + else + pos++; + + return len; +} + +static int +skip_double_quote(const char *s, int pos, int len) +{ + assert(pos < len && s[pos] == '\"'); + + for (pos++; pos < len; ) + if (pos < len - 1 && s[pos] == '\\') { + if (s[pos+1] == '<') + pos = skip_backslash_angle(s, pos, len); + else + pos += 2; + } else if (s[pos] == '\"') + return pos + 1; + else + pos++; + + return len; +} + +static int +skip_single_quote(const char *s, int pos, int len) +{ + assert(pos < len && s[pos] == '\''); + + for (pos++; pos < len; pos++) + if (s[pos] == '\'') + return pos + 1; + + return len; +} + +static String +partial_uncomment(const String &str, int i, int *comma_pos) +{ + const char *s = str.data(); + int len = str.length(); + + // skip initial spaces + for (; i < len; i++) { + if (s[i] == '/' && i < len - 1 && (s[i+1] == '/' || s[i+1] == '*')) + i = skip_comment(s, i, len) - 1; + else if (!isspace(s[i])) + break; + } + + // accumulate text, skipping comments + StringAccum sa; + int left = i; + int right = i; + bool closed = false; + + while (i < len) { + if (isspace(s[i])) + i++; + else if (s[i] == '/' && i < len - 1 && (s[i+1] == '/' || s[i+1] == '*')) { + i = skip_comment(s, i, len); + closed = true; + } else if (s[i] == ',' && comma_pos) + break; + else { + if (closed) { + sa << str.substring(left, right - left) << ' '; + left = i; + closed = false; + } + if (s[i] == '\'') + i = skip_single_quote(s, i, len); + else if (s[i] == '\"') + i = skip_double_quote(s, i, len); + else if (s[i] == '\\' && i < len - 1 && s[i+1] == '<') + i = skip_backslash_angle(s, i, len); + else + i++; + right = i; + } + } + + if (comma_pos) + *comma_pos = i; + if (!sa) + return str.substring(left, right - left); + else { + sa << str.substring(left, right - left); + return sa.take_string(); + } +} + +String +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_uncomment(const String &str) +{ + return partial_uncomment(str, 0, 0); +} + +static int +process_backslash(const char *s, int i, int len, StringAccum &sa) +{ + assert(i < len - 1 && s[i] == '\\'); + + switch (s[i+1]) { + + case '\r': + return (i < len - 2 && s[i+2] == '\n' ? i + 3 : i + 2); + + case '\n': + return i + 2; + + case 'a': sa << '\a'; return i + 2; + case 'b': sa << '\b'; return i + 2; + case 'f': sa << '\f'; return i + 2; + case 'n': sa << '\n'; return i + 2; + case 'r': sa << '\r'; return i + 2; + case 't': sa << '\t'; return i + 2; + case 'v': sa << '\v'; return i + 2; + + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': { + int c = 0, d = 0; + for (i++; i < len && s[i] >= '0' && s[i] <= '7' && d < 3; + i++, d++) + c = c*8 + s[i] - '0'; + sa << (char)c; + return i; + } + + case 'x': { + int c = 0; + for (i += 2; i < len; i++) + if (s[i] >= '0' && s[i] <= '9') + c = c*16 + s[i] - '0'; + else if (s[i] >= 'A' && s[i] <= 'F') + c = c*16 + s[i] - 'A' + 10; + else if (s[i] >= 'a' && s[i] <= 'f') + c = c*16 + s[i] - 'a' + 10; + else + break; + sa << (char)c; + return i; + } + + case '<': { + int c = 0, d = 0; + for (i += 2; i < len; i++) { + if (s[i] == '>') + return i + 1; + else if (s[i] >= '0' && s[i] <= '9') + c = c*16 + s[i] - '0'; + else if (s[i] >= 'A' && s[i] <= 'F') + c = c*16 + s[i] - 'A' + 10; + else if (s[i] >= 'a' && s[i] <= 'f') + c = c*16 + s[i] - 'a' + 10; + else if (s[i] == '/' && i < len - 1 && (s[i+1] == '/' || s[i+1] == '*')) { + i = skip_comment(s, i, len) - 1; + continue; + } else + continue; // space (ignore it) or random (error) + if (++d == 2) { + sa << (char)c; + c = d = 0; + } + } + // ran out of space in string + return len; + } + + case '\\': case '\'': case '\"': case '$': + default: + sa << s[i+1]; + return i + 2; + + } +} + +String +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unquote(const String &in_str) +{ + String str = partial_uncomment(in_str, 0, 0); + const char *s = str.data(); + int len = str.length(); + int i = 0; + + // accumulate a word + StringAccum sa; + int start = i; + int quote_state = 0; + + for (; i < len; i++) + switch (s[i]) { + + case '\"': + case '\'': + if (quote_state == 0) { + if (start < i) sa << str.substring(start, i - start); + start = i + 1; + quote_state = s[i]; + } else if (quote_state == s[i]) { + if (start < i) sa << str.substring(start, i - start); + start = i + 1; + quote_state = 0; + } + break; + + case '\\': + if (i < len - 1 && (quote_state == '\"' + || (quote_state == 0 && s[i+1] == '<'))) { + sa << str.substring(start, i - start); + start = process_backslash(s, i, len, sa); + i = start - 1; + } + break; + + } + + if (start == 0) + return str; + else { + sa << str.substring(start, i - start); + return sa.take_string(); + } +} + +String +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_quote(const String &str, bool allow_newlines) +{ + if (!str) + return String("\"\""); + + const unsigned char *s = (const unsigned char *)str.data(); + int len = str.length(); + int i = 0; + + StringAccum sa; + int start = i; + + sa << '\"'; + + for (; i < len; i++) + switch (s[i]) { + + case '\\': case '\"': case '$': + sa << str.substring(start, i - start) << '\\' << s[i]; + start = i + 1; + break; + + case '\t': + sa << str.substring(start, i - start) << "\\t"; + start = i + 1; + break; + + case '\r': + sa << str.substring(start, i - start) << "\\r"; + start = i + 1; + break; + + case '\n': + if (!allow_newlines) { + sa << str.substring(start, i - start) << "\\n"; + start = i + 1; + } + break; + + default: + if (s[i] < 32 || s[i] >= 127) { + unsigned u = s[i]; + sa << str.substring(start, i - start) + << '\\' << (char)('0' + (u >> 6)) + << (char)('0' + ((u >> 3) & 7)) + << (char)('0' + (u & 7)); + start = i + 1; + } + break; + + } + + sa << str.substring(start, i - start) << '\"'; + return sa.take_string(); +} + +void +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_argvec(const String &conf, Vector &args) +{ + int len = conf.length(); + int i = 0; + bool first_arg = true; + + // common case: no configuration + if (len == 0) + return; + + // <= to handle case where `conf' ends in `,' (= an extra empty string + // argument) + while (i <= len) { + String arg = partial_uncomment(conf, i, &i); + + // add the argument if it is nonempty, or this isn't the first argument + if (arg || i < len || !first_arg) + args.push_back(arg); + + // bump `i' past the comma + i++; + first_arg = false; + } +} + +#ifdef CLICK_SIM +namespace CLICKSIM { +static String +cp_pop_spacevec(const String &conf, int &pos); +} +#endif + +static String +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_pop_spacevec(const String &conf, int &pos) +{ + const char *s = conf.data(); + int len = conf.length(); + int i = pos; + + // dump arguments into `vec' + int start = -1; + + for (; i < len; i++) + switch (s[i]) { + + case '/': + // skip comments + if (i == len - 1 || (s[i+1] != '/' && s[i+1] != '*')) + goto normal; + if (start >= 0) + goto done; + i = skip_comment(s, i, len) - 1; + break; + + case '\"': + if (start < 0) + start = i; + i = skip_double_quote(s, i, len) - 1; + break; + + case '\'': + if (start < 0) + start = i; + i = skip_single_quote(s, i, len) - 1; + break; + + case '\\': // check for \<...> strings + if (start < 0) + start = i; + if (i < len - 1 && s[i+1] == '<') + i = skip_backslash_angle(s, i, len) - 1; + break; + + case ' ': + case '\f': + case '\n': + case '\r': + case '\t': + case '\v': + if (start >= 0) + goto done; + break; + + default: + normal: + if (start < 0) + start = i; + break; + + } + + done: + pos = i; + if (start >= 0) + return conf.substring(start, i - start); + else + return String(); +} + +void +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_spacevec(const String &conf, Vector &vec) +{ + // common case: no configuration + if (conf.length() == 0) + return; + + // collect arguments with cp_pop_spacevec + String s; + int pos = 0; + while ((s = cp_pop_spacevec(conf, pos))) + vec.push_back(s); +} + +String +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_pop_spacevec(String &conf) +{ + int pos = 0; + String answer = cp_pop_spacevec(conf, pos); + conf = conf.substring(pos); + cp_eat_space(conf); + return answer; +} + +String +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unargvec(const Vector &args) +{ + if (args.size() == 0) + return String(); + else if (args.size() == 1) + return args[0]; + else { + StringAccum sa; + sa << args[0]; + for (int i = 1; i < args.size(); i++) + sa << ", " << args[i]; + return sa.take_string(); + } +} + +String +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unspacevec(const Vector &args) +{ + StringAccum sa; + for (int i = 0; i < args.size(); i++) { + if (i) sa << " "; + sa << args[i]; + } + return sa.take_string(); +} + + +// PARSING STRINGS + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_string(const String &str, String *return_value, String *rest) +{ + const char *s = str.data(); + int len = str.length(); + int i = 0; + + // accumulate a word + for (; i < len; i++) + switch (s[i]) { + + case ' ': + case '\f': + case '\n': + case '\r': + case '\t': + case '\v': + goto done; + + case '\"': + i = skip_double_quote(s, i, len) - 1; + break; + + case '\'': + i = skip_single_quote(s, i, len) - 1; + break; + + case '\\': + if (i < len - 1 && s[i+1] == '<') + i = skip_backslash_angle(s, i, len) - 1; + break; + + } + + done: + if (i == 0 || (!rest && i != len)) + return false; + else { + if (rest) + *rest = str.substring(i); + *return_value = cp_unquote(str.substring(0, i)); + return true; + } +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_word(const String &str, String *return_value, String *rest) +{ + String word; + if (!cp_string(str, &word, rest)) + return false; + else if (!cp_is_word(word)) + return false; + else { + *return_value = word; + return true; + } +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_keyword(const String &str, String *return_value, String *rest) +{ + const char *s = str.data(); + int len = str.length(); + int i = 0; + + // accumulate a word + for (; i < len; i++) + switch (s[i]) { + + case ' ': + case '\f': + case '\n': + case '\r': + case '\t': + case '\v': + goto done; + + // characters allowed unquoted in keywords + case '_': + case '.': + case ':': + break; + + default: + if (!isalnum(s[i])) + return false; + break; + + } + + done: + if (i == 0 || (!rest && i < len)) + return false; + else { + *return_value = str.substring(0, i); + if (rest) { + for (; i < len; i++) + if (!isspace(s[i])) + break; + *rest = str.substring(i); + } + return true; + } +} + + +// PARSING INTEGERS + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_bool(const String &str, bool *return_value) +{ + const char *s = str.data(); + int len = str.length(); + + if (len == 1 && s[0] == '0') + *return_value = false; + else if (len == 1 && s[0] == '1') + *return_value = true; + else if (len == 5 && memcmp(s, "false", 5) == 0) + *return_value = false; + else if (len == 4 && memcmp(s, "true", 4) == 0) + *return_value = true; + else if (len == 2 && memcmp(s, "no", 2) == 0) + *return_value = false; + else if (len == 3 && memcmp(s, "yes", 3) == 0) + *return_value = true; + else + return false; + + return true; +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unsigned(const String &str, int base, uint32_t *return_value) +{ + const char *s = str.data(); + int len = str.length(); + int i = 0; + + if (i < len && s[i] == '+') + i++; + + if ((base == 0 || base == 16) && i < len - 1 + && s[i] == '0' && (s[i+1] == 'x' || s[i+1] == 'X')) { + i += 2; + base = 16; + } else if (base == 0 && s[i] == '0') + base = 8; + else if (base == 0) + base = 10; + else if (base < 2 || base > 36) { + cp_errno = CPE_INVALID; + return false; + } + + if (i == len) // no digits + return false; + + uint32_t overflow_val = 0xFFFFFFFFU / base; + int32_t overflow_digit = 0xFFFFFFFFU - (overflow_val * base); + + uint32_t val = 0; + cp_errno = CPE_OK; + while (i < len) { + // find digit + int digit; + if (s[i] >= '0' && s[i] <= '9') + digit = s[i] - '0'; + else if (s[i] >= 'A' && s[i] <= 'Z') + digit = s[i] - 'A' + 10; + else if (s[i] >= 'a' && s[i] <= 'z') + digit = s[i] - 'a' + 10; + else + digit = 36; + if (digit >= base) + return false; + // check for overflow + if (val > overflow_val || (val == overflow_val && digit > overflow_digit)) + cp_errno = CPE_OVERFLOW; + // assign new value + val = val * base + digit; + i++; + } + + *return_value = (cp_errno ? 0xFFFFFFFFU : val); + return true; +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unsigned(const String &str, uint32_t *return_value) +{ + return cp_unsigned(str, 0, return_value); +} + + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_integer(const String &in_str, int base, int32_t *return_value) +{ + String str = in_str; + bool negative = false; + if (str.length() > 1 && str[0] == '-' && str[1] != '+') { + negative = true; + str = in_str.substring(1); + } + + uint32_t value; + if (!cp_unsigned(str, base, &value)) + return false; + + uint32_t max = (negative ? 0x80000000U : 0x7FFFFFFFU); + if (value > max) { + cp_errno = CPE_OVERFLOW; + value = max; + } + + *return_value = (negative ? -value : value); + return true; +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_integer(const String &str, int32_t *return_value) +{ + return cp_integer(str, 0, return_value); +} + + +#ifdef HAVE_INT64_TYPES + +static uint64_t unsigned64_overflow_vals[] = { 0, 0, 9223372036854775807ULL, 6148914691236517205ULL, 4611686018427387903ULL, 3689348814741910323ULL, 3074457345618258602ULL, 2635249153387078802ULL, 2305843009213693951ULL, 2049638230412172401ULL, 1844674407370955161ULL, 1676976733973595601ULL, 1537228672809129301ULL, 1418980313362273201ULL, 1317624576693539401ULL, 1229782938247303441ULL, 1152921504606846975ULL, 1085102592571150095ULL, 1024819115206086200ULL, 970881267037344821ULL, 922337203685477580ULL, 878416384462359600ULL, 838488366986797800ULL, 802032351030850070ULL, 768614336404564650ULL, 737869762948382064ULL, 709490156681136600ULL, 683212743470724133ULL, 658812288346769700ULL, 636094623231363848ULL, 614891469123651720ULL, 595056260442243600ULL, 576460752303423487ULL, 558992244657865200ULL, 542551296285575047ULL, 527049830677415760ULL }; + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unsigned64(const String &str, int base, uint64_t *return_value) +{ + const char *s = str.data(); + int len = str.length(); + int i = 0; + + if (i < len && s[i] == '+') + i++; + + if ((base == 0 || base == 16) && i < len - 1 + && s[i] == '0' && (s[i+1] == 'x' || s[i+1] == 'X')) { + i += 2; + base = 16; + } else if (base == 0 && s[i] == '0') + base = 8; + else if (base == 0) + base = 10; + else if (base < 2 || base > 36) { + cp_errno = CPE_INVALID; + return false; + } + + if (i == len) // no digits + return false; + + uint64_t overflow_val = unsigned64_overflow_vals[base]; + int64_t overflow_digit = 0xFFFFFFFFFFFFFFFFULL - (overflow_val * base); + + uint64_t val = 0; + cp_errno = CPE_OK; + while (i < len) { + // find digit + int digit; + if (s[i] >= '0' && s[i] <= '9') + digit = s[i] - '0'; + else if (s[i] >= 'A' && s[i] <= 'Z') + digit = s[i] - 'A' + 10; + else if (s[i] >= 'a' && s[i] <= 'z') + digit = s[i] - 'a' + 10; + else + digit = 36; + if (digit >= base) + return false; + // check for overflow + if (val > overflow_val || (val == overflow_val && digit > overflow_digit)) + cp_errno = CPE_OVERFLOW; + // assign new value + val = val * base + digit; + i++; + } + + *return_value = (cp_errno ? 0xFFFFFFFFFFFFFFFFULL : val); + return true; +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unsigned64(const String &str, uint64_t *return_value) +{ + return cp_unsigned64(str, 0, return_value); +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_integer64(const String &in_str, int base, int64_t *return_value) +{ + String str = in_str; + bool negative = false; + if (str.length() > 1 && str[0] == '-' && str[1] != '+') { + negative = true; + str = in_str.substring(1); + } + + uint64_t value; + if (!cp_unsigned64(str, base, &value)) + return false; + + uint64_t max = (negative ? 0x8000000000000000ULL : 0x7FFFFFFFFFFFFFFFULL); + if (value > max) { + cp_errno = CPE_OVERFLOW; + value = max; + } + + *return_value = (negative ? -value : value); + return true; +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_integer64(const String &str, int64_t *return_value) +{ + return cp_integer64(str, 0, return_value); +} + +#endif + + +// PARSING REAL NUMBERS + +static uint32_t +exp10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, + 10000000, 100000000, 1000000000 }; + + +#ifdef CLICK_SIM +namespace CLICKSIM { +bool cp_unsigned_real10(const String &str, int frac_digits, int exponent_delta, + uint32_t *return_int_part, uint32_t *return_frac_part); +} +#endif + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unsigned_real10(const String &str, int frac_digits, int exponent_delta, + uint32_t *return_int_part, uint32_t *return_frac_part) +{ + const char *s = str.data(); + const char *last = s + str.length(); + + cp_errno = CPE_FORMAT; + if (s == last) + return false; + if (frac_digits < 0 || frac_digits > 9) { + cp_errno = CPE_INVALID; + return false; + } + + if (*s == '+') + s++; + + // find integer part of string + const char *int_s = s; + while (s < last && isdigit(*s)) + s++; + int int_chars = s - int_s; + + // find fractional part of string + const char *frac_s; + int frac_chars; + if (s < last && *s == '.') { + frac_s = ++s; + while (s < last && isdigit(*s)) + s++; + frac_chars = s - frac_s; + } else + frac_s = s, frac_chars = 0; + + // no integer or fraction? illegal real + if (int_chars == 0 && frac_chars == 0) + return false; + + // find exponent, if any + int exponent = 0; + if (s < last && (*s == 'E' || *s == 'e')) { + if (++s == last) + return false; + + bool negexp = (*s == '-'); + if (*s == '-' || *s == '+') + s++; + if (s >= last || !isdigit(*s)) + return false; + + // XXX overflow? + for (; s < last && isdigit(*s); s++) + exponent = 10*exponent + *s - '0'; + + if (negexp) + exponent = -exponent; + } + + if (s != last) + return false; + + // OK! now create the result + // determine integer part; careful about overflow + uint32_t int_part = 0; + cp_errno = CPE_OK; + exponent += exponent_delta; + + for (int i = 0; i < int_chars + exponent; i++) { + int digit; + if (i < int_chars) + digit = int_s[i] - '0'; + else if (i - int_chars < frac_chars) + digit = frac_s[i - int_chars] - '0'; + else + digit = 0; + if (int_part > 0x19999999U || (int_part == 0x19999999U && digit > 5)) + cp_errno = CPE_OVERFLOW; + int_part = int_part * 10 + digit; + } + + // determine fraction part + uint32_t frac_part = 0; + int digit = 0; + + for (int i = 0; i <= frac_digits; i++) { + if (i + exponent + int_chars < 0) + digit = 0; + else if (i + exponent < 0) + digit = int_s[i + exponent + int_chars] - '0'; + else if (i + exponent < frac_chars) + digit = frac_s[i + exponent] - '0'; + else + digit = 0; + // skip out on the last digit + if (i == frac_digits) + break; + // no overflow possible b/c frac_digits was limited + frac_part = frac_part * 10 + digit; + } + + // round fraction part if required + if (digit >= 5) { + if (frac_part == exp10[frac_digits] - 1) { + frac_part = 0; + if (int_part == 0xFFFFFFFFU) + cp_errno = CPE_OVERFLOW; + int_part++; + } else + frac_part++; + } + + // done! + if (cp_errno) { // overflow + int_part = 0xFFFFFFFFU; + frac_part = exp10[frac_digits] - 1; + } + + //click_chatter("%d: %u %u", frac_digits, int_part, frac_part); + *return_int_part = int_part; + *return_frac_part = frac_part; + return true; +} + +#ifdef CLICK_SIM +namespace CLICKSIM { +static bool +unsigned_real10_2to1(uint32_t int_part, uint32_t frac_part, int frac_digits, + uint32_t *return_value); +} +#endif + +static bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +unsigned_real10_2to1(uint32_t int_part, uint32_t frac_part, int frac_digits, + uint32_t *return_value) +{ + uint32_t one = exp10[frac_digits]; + uint32_t int_max = 0xFFFFFFFFU / one; + uint32_t frac_max = 0xFFFFFFFFU - int_max * one; + if (int_part > int_max || (int_part == int_max && frac_part > frac_max)) { + cp_errno = CPE_OVERFLOW; + *return_value = 0xFFFFFFFFU; + } else + *return_value = int_part * one + frac_part; + return true; +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unsigned_real10(const String &str, int frac_digits, + uint32_t *return_int_part, uint32_t *return_frac_part) +{ + return cp_unsigned_real10(str, frac_digits, 0, + return_int_part, return_frac_part); +} + +#ifdef CLICK_SIM +namespace CLICKSIM { +bool +cp_unsigned_real10(const String &str, int frac_digits, int exponent_delta, + uint32_t *return_value); +} +#endif + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unsigned_real10(const String &str, int frac_digits, int exponent_delta, + uint32_t *return_value) +{ + uint32_t int_part, frac_part; + if (!cp_unsigned_real10(str, frac_digits, exponent_delta, &int_part, &frac_part)) + return false; + else + return unsigned_real10_2to1(int_part, frac_part, frac_digits, return_value); +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unsigned_real10(const String &str, int frac_digits, + uint32_t *return_value) +{ + uint32_t int_part, frac_part; + if (!cp_unsigned_real10(str, frac_digits, 0, &int_part, &frac_part)) + return false; + else + return unsigned_real10_2to1(int_part, frac_part, frac_digits, return_value); +} + + +static uint32_t +ureal2_digit_fractions[] = { + 0x00000000, 0x19999999, 0x33333333, 0x4CCCCCCC, 0x66666666, + 0x80000000, 0x99999999, 0xB3333333, 0xCCCCCCCC, 0xE6666666 +}; + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unsigned_real2(const String &str, int frac_bits, uint32_t *return_value) +{ + if (frac_bits < 0 || frac_bits > CP_REAL2_MAX_FRAC_BITS) { + cp_errno = CPE_INVALID; + return false; + } + + uint32_t int_part, frac_part; + if (!cp_unsigned_real10(str, 9, 0, &int_part, &frac_part)) { + cp_errno = CPE_FORMAT; + return false; + } + + // method from Knuth's TeX, round_decimals. Works well with + // cp_unparse_real2 below + uint32_t fraction = 0; + for (int i = 0; i < 9; i++) { + uint32_t digit = frac_part % 10; + fraction = (fraction / 10) + ureal2_digit_fractions[digit]; + frac_part /= 10; + } + fraction = ((fraction >> (31 - frac_bits)) + 1) / 2; + + // This can happen! (for example, 16 bits of fraction, .999999) Why? + if (fraction == (1U << frac_bits) && int_part < 0xFFFFFFFFU) + int_part++, fraction = 0; + + // check for overflow + if (cp_errno || int_part > (1U << (32 - frac_bits)) - 1) { + cp_errno = CPE_OVERFLOW; + *return_value = 0xFFFFFFFFU; + } else + *return_value = (int_part << frac_bits) + fraction; + + return true; +} + + +// Parsing signed reals + + +#ifdef CLICK_SIM +namespace CLICKSIM { +static bool +cp_real_base(const String &in_str, int frac_digits, int32_t *return_value, + bool (*func)(const String &, int, uint32_t *)); +} +#endif + +static bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_real_base(const String &in_str, int frac_digits, int32_t *return_value, + bool (*func)(const String &, int, uint32_t *)) +{ + String str = in_str; + bool negative = false; + if (str.length() > 1 && str[0] == '-' && str[1] != '+') { + negative = true; + str = str.substring(1); + } + + uint32_t value; + if (!func(str, frac_digits, &value)) + return false; + + // check for overflow + uint32_t umax = (negative ? 0x80000000 : 0x7FFFFFFF); + if (value > umax) { + cp_errno = CPE_OVERFLOW; + value = umax; + } + + *return_value = (negative ? -value : value); + return true; +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_real10(const String &str, int frac_digits, int32_t *return_value) +{ + return cp_real_base(str, frac_digits, return_value, cp_unsigned_real10); +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_real2(const String &str, int frac_bits, int32_t *return_value) +{ + return cp_real_base(str, frac_bits, return_value, cp_unsigned_real2); +} + +#ifdef HAVE_FLOAT_TYPES +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_double(const String &in_str, double *result) +{ + cp_errno = CPE_FORMAT; + if (in_str.length() == 0 || isspace(in_str[0])) + // check for space because strtod() accepts leading whitespace + return false; + + errno = 0; + String str = in_str; + char *endptr; + double val = strtod(str.cc(), &endptr); + if (*endptr) // bad format; garbage after number + return false; + + cp_errno = (errno == ERANGE ? CPE_OVERFLOW : 0); + *result = val; + return true; +} +#endif + +// PARSING TIME + +static String +cp_seconds_suffix(const String &str, int *power, int *factor) +{ + int len = str.length(); + const char *s = str.data(); + *power = 0; + *factor = 1; + + if (len > 1 && s[len-1] == 's') + len--; + else if (len > 3 && s[len-3] == 's' && s[len-2] == 'e' && s[len-1] == 'c') + len -= 3; + else if (len > 1 && s[len-1] == 'm') { + len--; + *power = 1, *factor = 6; + goto eat_space; + } else if (len > 3 && s[len-3] == 'm' && s[len-2] == 'i' && s[len-1] == 'n') { + len -= 3; + *power = 1, *factor = 6; + goto eat_space; + } else if (len > 1 && s[len-1] == 'h') { + len--; + *power = 2, *factor = 36; + goto eat_space; + } else if (len > 2 && s[len-3] == 'h' && s[len-2] == 'r') { + len -= 2; + *power = 2, *factor = 36; + goto eat_space; + } else + return str; + + if (s[len - 1] == 'm') + *power = -3, len--; + else if (s[len - 1] == 'u') + *power = -6, len--; + else if (s[len - 1] == 'n') + *power = -9, len--; + + eat_space: + while (len > 0 && isspace(s[len - 1])) + len--; + return str.substring(0, len); +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_seconds_as(int want_power, const String &str_in, uint32_t *return_value) +{ + int power, factor; + String str = cp_seconds_suffix(str_in, &power, &factor); + if (!cp_unsigned_real10(str, want_power, power, return_value)) + return false; + if (*return_value > 0xFFFFFFFFU / factor) { + cp_errno = CPE_OVERFLOW; + *return_value = 0xFFFFFFFFU; + } else + *return_value *= factor; + return true; +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_seconds_as_milli(const String &str_in, uint32_t *return_value) +{ + return cp_seconds_as(3, str_in, return_value); +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_seconds_as_micro(const String &str_in, uint32_t *return_value) +{ + return cp_seconds_as(6, str_in, return_value); +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_timeval(const String &str_in, struct timeval *return_value) +{ + int power, factor; + String str = cp_seconds_suffix(str_in, &power, &factor); + uint32_t tv_sec, tv_usec; + if (!cp_unsigned_real10(str, 6, power, &tv_sec, &tv_usec)) + return false; + if (factor != 1) { + tv_usec *= factor; + int delta = tv_usec / 1000000; + tv_usec -= delta * 1000000; + tv_sec = (tv_sec * factor) + delta; + } + return_value->tv_sec = tv_sec; + return_value->tv_usec = tv_usec; + return true; +} + + +// PARSING IPv4 ADDRESSES + +static int +ip_address_portion(const String &str, unsigned char *value) +{ + const char *s = str.data(); + int len = str.length(); + int pos = 0, part; + + for (int d = 0; d < 4; d++) { + if (d && pos < len && s[pos] == '.') + pos++; + if (pos >= len) { + memset(value + d, 0, 4 - d); + return d; + } else if (!isdigit(s[pos])) + return 0; + for (part = 0; pos < len && isdigit(s[pos]) && part <= 255; pos++) + part = part*10 + s[pos] - '0'; + if (part > 255) + return 0; + value[d] = part; + } + + return (pos == len ? 4 : 0); +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_ip_address(const String &str, unsigned char *return_value + CP_CONTEXT_ARG) +{ + unsigned char value[4]; + if (ip_address_portion(str, value) == 4) { + memcpy(return_value, value, 4); + return true; + } +#ifndef CLICK_TOOL + return AddressInfo::query_ip(str, return_value, context); +#else + return false; +#endif +} + + +static bool +bad_ip_prefix(const String &str, + unsigned char *return_value, unsigned char *return_mask, + bool allow_bare_address + CP_CONTEXT_ARG) +{ +#ifndef CLICK_TOOL + if (AddressInfo::query_ip_prefix(str, return_value, return_mask, context)) + return true; + else if (allow_bare_address + && AddressInfo::query_ip(str, return_value, context)) { + return_mask[0] = return_mask[1] = return_mask[2] = return_mask[3] = 255; + return true; + } +#else + // shut up, compiler! + (void)str, (void)return_value, (void)return_mask, (void)allow_bare_address; +#endif + return false; +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_ip_prefix(const String &str, + unsigned char *return_value, unsigned char *return_mask, + bool allow_bare_address CP_CONTEXT_ARG) +{ + do { + unsigned char value[4], mask[4]; + + int slash = str.find_right('/'); + String ip_part, mask_part; + if (slash < 0 && allow_bare_address) + ip_part = str; + else if (slash >= 0 && slash < str.length() - 1) { + ip_part = str.substring(0, slash); + mask_part = str.substring(slash + 1); + } else + goto failure; + + // read IP address part + int good_ip_bytes = ip_address_portion(ip_part, value); + if (good_ip_bytes == 0) { + if (!cp_ip_address(ip_part, value CP_PASS_CONTEXT)) + goto failure; + good_ip_bytes = 4; + } + + // check mask + if (allow_bare_address && !mask_part.length() && good_ip_bytes == 4) { + memcpy(return_value, value, 4); + return_mask[0] = return_mask[1] = return_mask[2] = return_mask[3] = 255; + return true; + } + + // check for complete IP address + int relevant_bits; + if (good_ip_bytes == 4 && cp_ip_address(mask_part, mask CP_PASS_CONTEXT)) + /* OK */; + + else if (cp_integer(mask_part, &relevant_bits) + && relevant_bits >= 0 && relevant_bits <= 32) { + // set bits + unsigned umask = 0; + if (relevant_bits > 0) + umask = 0xFFFFFFFFU << (32 - relevant_bits); + for (int i = 0; i < 4; i++, umask <<= 8) + mask[i] = (umask >> 24) & 255; + if (good_ip_bytes < (relevant_bits + 7)/8) + goto failure; + + } else + goto failure; + + memcpy(return_value, value, 4); + memcpy(return_mask, mask, 4); + return true; + + } while (0); + + failure: + return bad_ip_prefix(str, return_value, return_mask, allow_bare_address CP_PASS_CONTEXT); +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_ip_address(const String &str, IPAddress *address + CP_CONTEXT_ARG) +{ + return cp_ip_address(str, address->data() + CP_PASS_CONTEXT); +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_ip_prefix(const String &str, IPAddress *address, IPAddress *mask, + bool allow_bare_address CP_CONTEXT_ARG) +{ + return cp_ip_prefix(str, address->data(), mask->data(), + allow_bare_address CP_PASS_CONTEXT); +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_ip_prefix(const String &str, unsigned char *address, unsigned char *mask + CP_CONTEXT_ARG) +{ + return cp_ip_prefix(str, address, mask, + false CP_PASS_CONTEXT); +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_ip_prefix(const String &str, IPAddress *address, IPAddress *mask + CP_CONTEXT_ARG) +{ + return cp_ip_prefix(str, address->data(), mask->data(), + false CP_PASS_CONTEXT); +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_ip_address_set(const String &str, IPAddressSet *set + CP_CONTEXT_ARG) +{ + Vector words; + Vector additions; + IPAddress ip; + cp_spacevec(str, words); + for (int i = 0; i < words.size(); i++) { + if (!cp_ip_address(words[i], &ip CP_PASS_CONTEXT)) + return false; + additions.push_back(ip); + } + for (int i = 0; i < additions.size(); i++) + set->insert(IPAddress(additions[i])); + return true; +} + + +// PARSING IPv6 ADDRESSES + +#ifdef HAVE_IP6 + +static bool +bad_ip6_address(const String &str, unsigned char *return_value + CP_CONTEXT_ARG) +{ +#ifndef CLICK_TOOL + return AddressInfo::query_ip6(str, return_value, context); +#else + (void)str, (void)return_value; + return false; +#endif +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_ip6_address(const String &str, unsigned char *return_value + CP_CONTEXT_ARG) +{ + unsigned short parts[8]; + int coloncolon = -1; + const char *s = str.data(); + int len = str.length(); + int pos = 0; + + int d; + int last_part_pos = 0; + for (d = 0; d < 8; d++) { + if (coloncolon < 0 && pos < len - 1 && s[pos] == ':' && s[pos+1] == ':') { + coloncolon = d; + pos += 2; + } else if (d && pos < len - 1 && s[pos] == ':' && isxdigit(s[pos+1])) + pos++; + if (pos >= len || !isxdigit(s[pos])) + break; + unsigned part = 0; + last_part_pos = pos; + for (; pos < len && isxdigit(s[pos]) && part <= 0xFFFF; pos++) + part = (part<<4) + xvalue(s[pos]); + if (part > 0xFFFF) + return bad_ip6_address(str, return_value CP_PASS_CONTEXT); + parts[d] = part; + } + + // check if address ends in IPv4 address + if (pos < len && d <= 7 && s[pos] == '.') { + unsigned char ip4a[4]; + if (cp_ip_address(str.substring(last_part_pos), ip4a CP_PASS_CONTEXT)) { + parts[d-1] = (ip4a[0]<<8) + ip4a[1]; + parts[d] = (ip4a[2]<<8) + ip4a[3]; + d++; + pos = len; + } + } + + // handle zero blocks surrounding :: + if ((d < 8 && coloncolon < 0) || (d == 8 && coloncolon >= 0)) + return bad_ip6_address(str, return_value CP_PASS_CONTEXT); + else if (d < 8) { + int num_zeros = 8 - d; + for (int x = d - 1; x >= coloncolon; x--) + parts[x + num_zeros] = parts[x]; + for (int x = coloncolon; x < coloncolon + num_zeros; x++) + parts[x] = 0; + } + + // return + if (pos < len) + return bad_ip6_address(str, return_value CP_PASS_CONTEXT); + else { + for (d = 0; d < 8; d++) { + return_value[d<<1] = (parts[d]>>8) & 0xFF; + return_value[(d<<1) + 1] = parts[d] & 0xFF; + } + return true; + } +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_ip6_address(const String &str, IP6Address *address + CP_CONTEXT_ARG) +{ + return cp_ip6_address(str, address->data() CP_PASS_CONTEXT); +} + + +static bool +bad_ip6_prefix(const String &str, + unsigned char *return_value, int *return_bits, + bool allow_bare_address + CP_CONTEXT_ARG) +{ +#ifndef CLICK_TOOL + if (AddressInfo::query_ip6_prefix(str, return_value, return_bits, context)) + return true; + else if (allow_bare_address + && AddressInfo::query_ip6(str, return_value, context)) { + *return_bits = 128; + return true; + } +#else + // shut up, compiler! + (void)str, (void)return_value, (void)return_bits, (void)allow_bare_address; +#endif + return false; +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_ip6_prefix(const String &str, + unsigned char *return_value, int *return_bits, + bool allow_bare_address CP_CONTEXT_ARG) +{ + unsigned char value[16], mask[16]; + + int slash = str.find_right('/'); + String ip_part, mask_part; + if (slash >= 0) { + ip_part = str.substring(0, slash); + mask_part = str.substring(slash + 1); + } else if (!allow_bare_address) + return bad_ip6_prefix(str, return_value, return_bits, allow_bare_address CP_PASS_CONTEXT); + else + ip_part = str; + + if (!cp_ip6_address(ip_part, value CP_PASS_CONTEXT)) + return bad_ip6_prefix(str, return_value, return_bits, allow_bare_address CP_PASS_CONTEXT); + + // move past / + if (allow_bare_address && !mask_part.length()) { + memcpy(return_value, value, 16); + *return_bits = 64; + return true; + } + + // check for complete IP address + int relevant_bits = 0; + if (cp_ip6_address(mask_part, mask CP_PASS_CONTEXT)) { + // check that it really is a prefix. if not, return false right away + // (don't check with AddressInfo) + relevant_bits = IP6Address(mask).mask_to_prefix_len(); + if (relevant_bits < 0) + return false; + + } else if (cp_integer(mask_part, &relevant_bits) + && relevant_bits >= 0 && relevant_bits <= 128) + /* OK */; + + else + return bad_ip6_prefix(str, return_value, return_bits, allow_bare_address CP_PASS_CONTEXT); + + memcpy(return_value, value, 16); + *return_bits = relevant_bits; + return true; +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_ip6_prefix(const String &str, unsigned char *address, unsigned char *mask, + bool allow_bare_address CP_CONTEXT_ARG) +{ + int bits; + if (cp_ip6_prefix(str, address, &bits, allow_bare_address CP_PASS_CONTEXT)) { + IP6Address m = IP6Address::make_prefix(bits); + memcpy(mask, m.data(), 16); + return true; + } else + return false; +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_ip6_prefix(const String &str, IP6Address *address, int *prefix, + bool allow_bare_address CP_CONTEXT_ARG) +{ + return cp_ip6_prefix(str, address->data(), prefix, allow_bare_address CP_PASS_CONTEXT); +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_ip6_prefix(const String &str, IP6Address *address, IP6Address *prefix, + bool allow_bare_address CP_CONTEXT_ARG) +{ + return cp_ip6_prefix(str, address->data(), prefix->data(), allow_bare_address CP_PASS_CONTEXT); +} + +#endif /* HAVE_IP6 */ + + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_ethernet_address(const String &str, unsigned char *return_value + CP_CONTEXT_ARG) +{ + int i = 0; + const char *s = str.data(); + int len = str.length(); + + unsigned char value[6]; + for (int d = 0; d < 6; d++) { + if (i < len - 1 && isxdigit(s[i]) && isxdigit(s[i+1])) { + value[d] = xvalue(s[i])*16 + xvalue(s[i+1]); + i += 2; + } else if (i < len && isxdigit(s[i])) { + value[d] = xvalue(s[i]); + i += 1; + } else + goto bad; + if (d == 5) break; + if (i >= len - 1 || s[i] != ':') + goto bad; + i++; + } + + if (i == len) { + memcpy(return_value, value, 6); + return true; + } + + bad: +#ifndef CLICK_TOOL + return AddressInfo::query_ethernet(str, return_value, context); +#else + return false; +#endif +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_ethernet_address(const String &str, EtherAddress *address + CP_CONTEXT_ARG) +{ + return cp_ethernet_address(str, address->data() + CP_PASS_CONTEXT); +} + + +#ifndef CLICK_TOOL +Element * +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_element(const String &text_in, Element *context, ErrorHandler *errh) +{ + String name; + if (!cp_string(text_in, &name)) { + if (errh) + errh->error("bad name format"); + return 0; + } else + return context->router()->find(name, context, errh); +} + +Element * +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_element(const String &text_in, Router *router, ErrorHandler *errh) +{ + String name; + if (!cp_string(text_in, &name)) { + if (errh) + errh->error("bad name format"); + return 0; + } else + return router->find(name, errh); +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_handler(const String &str, Element *context, Element **result_element, + String *result_hname, ErrorHandler *errh) +{ + if (!errh) + errh = ErrorHandler::silent_handler(); + + String text; + if (!cp_string(str, &text) || !text) { + errh->error("bad handler name format"); + return false; + } + + int leftmost_dot = text.find_left('.'); + if (leftmost_dot < 0) { + *result_element = 0; + *result_hname = text; + return true; + } else if (leftmost_dot == text.length() - 1) { + errh->error("empty handler name"); + return false; + } + + Element *e = context->router()->find(text.substring(0, leftmost_dot), context, errh); + if (!e) + return false; + + *result_element = e; + *result_hname = text.substring(leftmost_dot + 1); + return true; +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_handler(const String &str, Element *context, bool need_read, + bool need_write, Element **result_element, int *result_hid, + ErrorHandler *errh) +{ + if (!errh) + errh = ErrorHandler::silent_handler(); + + Element *e; + String hname; + if (!cp_handler(str, context, &e, &hname, errh)) + return false; + + int hid = context->router()->find_handler(e, hname); + if (hid < 0) { + if (e) { + errh->error("element `%s' has no `%s' handler", e->id().cc(), hname.cc()); + if (context->router()->nhandlers() == 0) + errh->error("because handlers have not been added yet!"); + } else + errh->error("no global `%s' handler", hname.cc()); + return false; + } + + const Router::Handler &h = context->router()->handler(hid); + if (need_read && !h.readable()) { + errh->error("`%s' is not a read handler", h.unparse_name(e).cc()); + return false; + } else if (need_write && !h.writable()) { + errh->error("`%s' is not a write handler", h.unparse_name(e).cc()); + return false; + } else { + *result_element = e; + *result_hid = hid; + return true; + } +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_handler(const String &str, Element *context, Element **result_element, int *result_hid, ErrorHandler *errh) +{ + return cp_handler(str, context, false, false, result_element, result_hid, errh); +} + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_handler_call(const String &str, Element *context, bool is_write, HandlerCall **hcall, ErrorHandler *errh) +{ + if (!errh) + errh = ErrorHandler::silent_handler(); + HandlerCall hc; + if (hc.initialize(str, is_write, context, errh) < 0) + return false; + if (hcall) { + if (!*hcall) + *hcall = new HandlerCall; + **hcall = hc; + } + return true; +} +#endif + +#ifdef HAVE_IPSEC +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_des_cblock(const String &str, unsigned char *return_value) +{ + int i = 0; + const char *s = str.data(); + int len = str.length(); + + if (len != 16) + return false; + + unsigned char value[8]; + for (int d = 0; d < 8; d++) { + if (i < len - 1 && isxdigit(s[i]) && isxdigit(s[i+1])) { + value[d] = xvalue(s[i])*16 + xvalue(s[i+1]); + i += 2; + } else + return false; + } + + if (len != i) + return false; + else { + memcpy(return_value, value, 8); + return true; + } +} +#endif + +#ifdef CLICK_USERLEVEL +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_filename(const String &str, String *return_value) +{ + String fn; + if (!cp_string(str, &fn) || !fn) + return false; + + // expand home directory substitutions + if (fn[0] == '~') { + if (fn.length() == 1 || fn[1] == '/') { + const char *home = getenv("HOME"); + if (home) + fn = String(home) + fn.substring(1); + } else { + int off = 1; + while (off < fn.length() && fn[off] != '/') + off++; + String username = fn.substring(1, off - 1); + struct passwd *pwd = getpwnam(username.cc()); + if (pwd && pwd->pw_dir) + fn = String(pwd->pw_dir) + fn.substring(off); + } + } + + // replace double slashes with single slashes + int len = fn.length(); + for (int i = 0; i < len - 1; i++) + if (fn[i] == '/' && fn[i+1] == '/') { + fn = fn.substring(0, i) + fn.substring(i + 1); + i--; + len--; + } + + // return + *return_value = fn; + return true; +} +#endif + + +// +// CP_VA_PARSE AND FRIENDS +// + +// parse commands; those which must be recognized inside a keyword section +// must begin with "\377" +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif +CpVaParseCmd + cpOptional = "OPTIONAL", + cpKeywords = "\377KEYWORDS", + cpMandatoryKeywords = "\377MANDATORY_KEYWORDS", + cpIgnore = "IGNORE", + cpIgnoreRest = "\377IGNORE_REST", + cpArgument = "arg", + cpArguments = "args", + cpString = "string", + cpWord = "word", + cpKeyword = "keyword", + cpBool = "bool", + cpByte = "byte", + cpShort = "short", + cpUnsignedShort = "u_short", + cpInteger = "int", + cpUnsigned = "u_int", + cpInteger64 = "long_long", + cpUnsigned64 = "u_long_long", + cpUnsignedLongLong = "u_long_long", // synonym + cpReal2 = "real2", + cpUnsignedReal2 = "u_real2", + cpNonnegReal2 = "u_real2", // synonym + cpReal10 = "real10", + cpUnsignedReal10 = "u_real10", + cpNonnegReal10 = "u_real10", // synonym + cpDouble = "double", + cpSeconds = "sec", + cpSecondsAsMilli = "msec", + cpSecondsAsMicro = "usec", + cpMilliseconds = "msec", // synonym + cpTimeval = "timeval", + cpInterval = "interval", + cpIPAddress = "ip_addr", + cpIPPrefix = "ip_prefix", + cpIPAddressOrPrefix = "ip_addr_or_prefix", + cpIPAddressSet = "ip_addr_set", + cpEthernetAddress = "ether_addr", + cpEtherAddress = "ether_addr", // synonym + cpElement = "element", + cpHandlerName = "handler_name", + cpHandler = "handler", + cpReadHandler = "read_handler", + cpWriteHandler = "write_handler", + cpReadHandlerCall = "read_handler_call", + cpWriteHandlerCall = "write_handler_call", + cpIP6Address = "ip6_addr", + cpIP6Prefix = "ip6_prefix", + cpIP6AddressOrPrefix = "ip6_addr_or_prefix", + cpDesCblock = "des_cblock", + cpFilename = "filename"; +#ifdef CLICK_SIM +} +#endif +enum { + cpiEnd = 0, + cpiOptional, + cpiKeywords, + cpiMandatoryKeywords, + cpiIgnore, + cpiIgnoreRest, + cpiArgument, + cpiArguments, + cpiString, + cpiWord, + cpiKeyword, + cpiBool, + cpiByte, + cpiShort, + cpiUnsignedShort, + cpiInteger, + cpiUnsigned, + cpiInteger64, + cpiUnsigned64, + cpiReal2, + cpiUnsignedReal2, + cpiReal10, + cpiUnsignedReal10, + cpiDouble, + cpiSeconds, + cpiSecondsAsMilli, + cpiSecondsAsMicro, + cpiTimeval, + cpiInterval, + cpiIPAddress, + cpiIPPrefix, + cpiIPAddressOrPrefix, + cpiIPAddressSet, + cpiEthernetAddress, + cpiElement, + cpiHandlerName, + cpiHandler, + cpiReadHandler, + cpiWriteHandler, + cpiReadHandlerCall, + cpiWriteHandlerCall, + cpiIP6Address, + cpiIP6Prefix, + cpiIP6AddressOrPrefix, + cpiDesCblock, + cpiFilename +}; + +#define NARGTYPE_HASH 128 +static cp_argtype *argtype_hash[NARGTYPE_HASH]; + +static inline int +argtype_bucket(const char *command) +{ + const unsigned char *s = (const unsigned char *)command; + return (s[0] ? (s[0]%32 + strlen(command)*32) % NARGTYPE_HASH : 0); +} + +static cp_argtype * +find_argtype(const char *command) +{ + cp_argtype *t = argtype_hash[argtype_bucket(command)]; + while (t && strcmp(t->name, command) != 0) + t = t->next; + return t; +} + +#ifdef CLICK_SIM +namespace CLICKSIM { +static int +cp_register_argtype(const char *name, const char *desc, int extra, + cp_parsefunc parse, cp_storefunc store, int internal); +} +#endif + +static int +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_register_argtype(const char *name, const char *desc, int extra, + cp_parsefunc parse, cp_storefunc store, int internal) +{ + if (cp_argtype *t = find_argtype(name)) { + t->use_count++; + if (strcmp(desc, t->description) != 0 + || extra != t->extra + || parse != t->parse + || store != t->store + || internal != t->internal) + return -1; + else + return 0; + } + + if (cp_argtype *t = new cp_argtype) { + t->name = name; + t->parse = parse; + t->store = store; + t->extra = extra; + t->description = desc; + t->internal = internal; + t->use_count = 1; + int bucket = argtype_bucket(name); + t->next = argtype_hash[bucket]; + argtype_hash[bucket] = t; + return 0; + } else + return -2; +} + +int +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_register_argtype(const char *name, const char *desc, int extra, + cp_parsefunc parse, cp_storefunc store) +{ + return cp_register_argtype(name, desc, extra, parse, store, -1); +} + +void +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unregister_argtype(const char *name) +{ + cp_argtype **prev = &argtype_hash[argtype_bucket(name)]; + cp_argtype *trav = *prev; + while (trav && strcmp(trav->name, name) != 0) { + prev = &trav->next; + trav = trav->next; + } + if (trav) { + trav->use_count--; + if (trav->use_count <= 0) { + *prev = trav->next; + delete trav; + } + } +} + +#ifdef CLICK_SIM +namespace CLICKSIM { +static void +default_parsefunc(cp_value *v, const String &arg, + ErrorHandler *errh, const char *argname CP_CONTEXT_ARG); +} +#endif + +static void +#ifdef CLICK_SIM +CLICKSIM:: +#endif +default_parsefunc(cp_value *v, const String &arg, + ErrorHandler *errh, const char *argname CP_CONTEXT_ARG) +{ + const char *desc = v->description; + int underflower = -0x80000000; + unsigned overflower = 0xFFFFFFFFU; + const cp_argtype *argtype = v->argtype; + + switch (argtype->internal) { + + case cpiArgument: + case cpiArguments: + // nothing to do + break; + + case cpiString: + if (!cp_string(arg, &v->v_string)) + errh->error("%s takes string (%s)", argname, desc); + break; + + case cpiWord: + if (!cp_word(arg, &v->v_string)) + errh->error("%s takes word (%s)", argname, desc); + break; + + case cpiKeyword: + if (!cp_keyword(arg, &v->v_string)) + errh->error("%s takes keyword (%s)", argname, desc); + break; + + case cpiBool: + if (!cp_bool(arg, &v->v.b)) + errh->error("%s takes bool (%s)", argname, desc); + break; + + case cpiByte: + overflower = 255; + goto handle_unsigned; + + case cpiShort: + underflower = -0x8000; + overflower = 0x7FFF; + goto handle_signed; + + case cpiUnsignedShort: + overflower = 0xFFFF; + goto handle_unsigned; + + case cpiInteger: + underflower = -0x80000000; + overflower = 0x7FFFFFFF; + goto handle_signed; + + case cpiUnsigned: + overflower = 0xFFFFFFFFU; + goto handle_unsigned; + + handle_signed: + if (!cp_integer(arg, &v->v.i)) + errh->error("%s takes %s (%s)", argname, argtype->description, desc); + else if (cp_errno == CPE_OVERFLOW) + errh->error("%s (%s) too large; max %d", argname, desc, v->v.i); + else if (v->v.i < underflower) + errh->error("%s (%s) must be >= %d", argname, desc, underflower); + else if (v->v.i > (int)overflower) + errh->error("%s (%s) must be <= %u", argname, desc, overflower); + break; + + handle_unsigned: + if (!cp_unsigned(arg, &v->v.u)) + errh->error("%s takes %s (%s)", argname, argtype->description, desc); + else if (cp_errno == CPE_OVERFLOW) + errh->error("%s (%s) too large; max %u", argname, desc, v->v.u); + else if (v->v.u > overflower) + errh->error("%s (%s) must be <= %u", argname, desc, overflower); + break; + +#ifdef HAVE_INT64_TYPES + case cpiInteger64: + if (!cp_integer64(arg, &v->v.i64)) + errh->error("%s takes %s (%s)", argname, argtype->description, desc); + else if (cp_errno == CPE_OVERFLOW) + errh->error("%s (%s) too large; max %lld", argname, desc, v->v.i64); + break; + + case cpiUnsigned64: + if (!cp_unsigned64(arg, &v->v.u64)) + errh->error("%s takes %s (%s)", argname, argtype->description, desc); + else if (cp_errno == CPE_OVERFLOW) + errh->error("%s (%s) too large; max %llu", argname, desc, v->v.u64); + break; +#endif + + case cpiReal10: + if (!cp_real10(arg, v->extra, &v->v.i)) + errh->error("%s takes real (%s)", argname, desc); + else if (cp_errno == CPE_OVERFLOW) { + String m = cp_unparse_real10(v->v.i, v->extra); + errh->error("%s (%s) too large; max %s", argname, desc, m.cc()); + } + break; + + case cpiUnsignedReal10: + if (!cp_unsigned_real10(arg, v->extra, &v->v.u)) + errh->error("%s takes unsigned real (%s)", argname, desc); + else if (cp_errno == CPE_OVERFLOW) { + String m = cp_unparse_real10(v->v.u, v->extra); + errh->error("%s (%s) too large; max %s", argname, desc, m.cc()); + } + break; + +#ifdef HAVE_FLOAT_TYPES + case cpiDouble: + if (!cp_double(arg, &v->v.d)) + errh->error("%s takes %s (%s)", argname, argtype->description, desc); + else if (cp_errno == CPE_OVERFLOW) + errh->error("%s (%s) out of range; limit %g", argname, desc, v->v.d); + break; +#endif + + case cpiSeconds: + if (!cp_seconds_as(0, arg, &v->v.u)) + errh->error("%s takes time in seconds (%s)", argname, desc); + else if (cp_errno == CPE_OVERFLOW) + errh->error("%s (%s) too large; max %u", argname, desc, v->v.u); + break; + + case cpiSecondsAsMilli: + if (!cp_seconds_as(3, arg, &v->v.u)) + errh->error("%s takes time in seconds (%s)", argname, desc); + else if (cp_errno == CPE_OVERFLOW) { + String m = cp_unparse_milliseconds(v->v.u); + errh->error("%s (%s) too large; max %s", argname, desc, m.cc()); + } + break; + + case cpiSecondsAsMicro: + if (!cp_seconds_as(6, arg, &v->v.u)) + errh->error("%s takes time in seconds (%s)", argname, desc); + else if (cp_errno == CPE_OVERFLOW) { + String m = cp_unparse_microseconds(v->v.u); + errh->error("%s (%s) too large; max %s", argname, desc, m.cc()); + } + break; + + case cpiTimeval: + case cpiInterval: { + struct timeval tv; + if (!cp_timeval(arg, &tv)) { + if (cp_errno == CPE_NEGATIVE) + errh->error("%s (%s) must be >= 0", argname, desc); + else + errh->error("%s takes %s (%s)", argname, argtype->description, desc); + } else if (cp_errno == CPE_OVERFLOW) + errh->error("%s (%s) too large", argname, desc); + else { + v->v.i = tv.tv_sec; + v->v2.i = tv.tv_usec; + } + break; + } + + case cpiReal2: + if (!cp_real2(arg, v->extra, &v->v.i)) { + // CPE_INVALID would indicate a bad 'v->extra' + errh->error("%s takes real (%s)", argname, desc); + } else if (cp_errno == CPE_OVERFLOW) { + String m = cp_unparse_real2(v->v.i, v->extra); + errh->error("%s (%s) too large; max %s", argname, desc, m.cc()); + } + break; + + case cpiUnsignedReal2: + if (!cp_unsigned_real2(arg, v->extra, &v->v.u)) { + // CPE_INVALID would indicate a bad 'v->extra' + errh->error("%s takes unsigned real (%s)", argname, desc); + } else if (cp_errno == CPE_OVERFLOW) { + String m = cp_unparse_real2(v->v.u, v->extra); + errh->error("%s (%s) too large; max %s", argname, desc, m.cc()); + } + break; + + case cpiIPAddress: + if (!cp_ip_address(arg, v->v.address CP_PASS_CONTEXT)) + errh->error("%s takes IP address (%s)", argname, desc); + break; + + case cpiIPPrefix: + case cpiIPAddressOrPrefix: { + bool mask_optional = (argtype->internal == cpiIPAddressOrPrefix); + if (!cp_ip_prefix(arg, v->v.address, v->v2.address, mask_optional CP_PASS_CONTEXT)) + errh->error("%s takes IP address prefix (%s)", argname, desc); + break; + } + + case cpiIPAddressSet: { + IPAddressSet crap; + if (!cp_ip_address_set(arg, &crap CP_PASS_CONTEXT)) + errh->error("%s takes set of IP addresses (%s)", argname, desc); + break; + } + +#ifdef HAVE_IP6 + case cpiIP6Address: + if (!cp_ip6_address(arg, (unsigned char *)v->v.address)) + errh->error("%s takes IPv6 address (%s)", argname, desc); + break; + + case cpiIP6Prefix: + case cpiIP6AddressOrPrefix: { + bool mask_optional = (argtype->internal == cpiIP6AddressOrPrefix); + if (!cp_ip6_prefix(arg, v->v.address, v->v2.address, mask_optional CP_PASS_CONTEXT)) + errh->error("%s takes IPv6 address prefix (%s)", argname, desc); + break; + } +#endif + + case cpiEthernetAddress: + if (!cp_ethernet_address(arg, v->v.address CP_PASS_CONTEXT)) + errh->error("%s takes Ethernet address (%s)", argname, desc); + break; + +#ifdef HAVE_IPSEC + case cpiDesCblock: + if (!cp_des_cblock(arg, v->v.address)) + errh->error("%s takes DES encryption block (%s)", argname, desc); + break; +#endif + +#ifndef CLICK_TOOL + case cpiElement: { + ContextErrorHandler cerrh(errh, String(argname) + " (" + desc + "):"); + v->v.element = cp_element(arg, context, &cerrh); + break; + } + + case cpiHandlerName: { + ContextErrorHandler cerrh(errh, String(argname) + " (" + desc + "):"); + cp_handler(arg, context, &v->v.element, &v->v2_string, &cerrh); + break; + } + + case cpiHandler: + case cpiReadHandler: + case cpiWriteHandler: { + ContextErrorHandler cerrh(errh, String(argname) + " (" + desc + "):"); + cp_handler(arg, context, argtype->internal == cpiReadHandler, + argtype->internal == cpiWriteHandler, + &v->v.element, &v->v2.i, &cerrh); + break; + } + + case cpiReadHandlerCall: + case cpiWriteHandlerCall: { + ContextErrorHandler cerrh(errh, String(argname) + " (" + desc + "):"); + cp_handler_call(arg, context, argtype->internal == cpiWriteHandlerCall, + (HandlerCall **)0, &cerrh); + break; + } +#endif + +#ifdef CLICK_USERLEVEL + case cpiFilename: + if (!cp_filename(arg, &v->v_string)) + errh->error("%s takes filename (%s)", argname, desc); + break; +#endif + + } +} + +static void +default_storefunc(cp_value *v CP_CONTEXT_ARG) +{ + int address_bytes; + const cp_argtype *argtype = v->argtype; + + switch (argtype->internal) { + + case cpiBool: { + bool *bstore = (bool *)v->store; + *bstore = v->v.b; + break; + } + + case cpiByte: { + unsigned char *ucstore = (unsigned char *)v->store; + *ucstore = v->v.i; + break; + } + + case cpiShort: { + short *sstore = (short *)v->store; + *sstore = v->v.i; + break; + } + + case cpiUnsignedShort: { + unsigned short *usstore = (unsigned short *)v->store; + *usstore = v->v.u; + break; + } + + case cpiInteger: + case cpiReal2: + case cpiReal10: + case cpiSeconds: + case cpiSecondsAsMilli: + case cpiSecondsAsMicro: { + int *istore = (int *)v->store; + *istore = v->v.i; + break; + } + + case cpiUnsigned: + case cpiUnsignedReal2: + case cpiUnsignedReal10: { + unsigned *ustore = (unsigned *)v->store; + *ustore = v->v.u; + break; + } + +#ifdef HAVE_INT64_TYPES + case cpiInteger64: { + int64_t *llstore = (int64_t *)v->store; + *llstore = v->v.i64; + break; + } + + case cpiUnsigned64: { + uint64_t *ullstore = (uint64_t *)v->store; + *ullstore = v->v.u64; + break; + } +#endif + +#ifdef HAVE_FLOAT_TYPES + case cpiDouble: { + double *dstore = (double *)v->store; + *dstore = v->v.d; + break; + } +#endif + + case cpiTimeval: + case cpiInterval: { + struct timeval *tvstore = (struct timeval *)v->store; + tvstore->tv_sec = v->v.i; + tvstore->tv_usec = v->v2.i; + break; + } + + case cpiArgument: + case cpiString: + case cpiWord: + case cpiKeyword: + case cpiFilename: { + String *sstore = (String *)v->store; + *sstore = v->v_string; + break; + } + + case cpiArguments: { + Vector *vstore = (Vector *)v->store; + uint32_t pos = 0; + const char *len_str = v->v2_string.data(); + for (int len_pos = 0; len_pos < v->v2_string.length(); len_pos += 4) { + uint32_t pos2 = *((const uint32_t *)(len_str + len_pos)); + vstore->push_back(v->v_string.substring(pos, pos2 - pos)); + pos = pos2; + } + vstore->push_back(v->v_string.substring(pos)); + break; + } + + case cpiIPAddress: + address_bytes = 4; + goto address; + +#ifdef HAVE_IP6 + case cpiIP6Address: + address_bytes = 16; + goto address; +#endif + + case cpiEthernetAddress: + address_bytes = 6; + goto address; + +#ifdef HAVE_IPSEC + case cpiDesCblock: + address_bytes = 8; + goto address; +#endif + + address: { + unsigned char *addrstore = (unsigned char *)v->store; + memcpy(addrstore, v->v.address, address_bytes); + break; + } + + case cpiIPPrefix: + case cpiIPAddressOrPrefix: { + unsigned char *addrstore = (unsigned char *)v->store; + memcpy(addrstore, v->v.address, 4); + unsigned char *maskstore = (unsigned char *)v->store2; + memcpy(maskstore, v->v2.address, 4); + break; + } + +#ifdef HAVE_IP6 + case cpiIP6Prefix: + case cpiIP6AddressOrPrefix: { + unsigned char *addrstore = (unsigned char *)v->store; + memcpy(addrstore, v->v.address, 16); + unsigned char *maskstore = (unsigned char *)v->store2; + memcpy(maskstore, v->v2.address, 16); + break; + } +#endif + + case cpiIPAddressSet: { + // oog... parse set into stored set only when we know there are no errors + IPAddressSet *setstore = (IPAddressSet *)v->store; + cp_ip_address_set(v->v_string, setstore CP_PASS_CONTEXT); + break; + } + +#ifndef CLICK_TOOL + case cpiElement: { + Element **elementstore = (Element **)v->store; + *elementstore = v->v.element; + break; + } + + case cpiHandlerName: { + Element **elementstore = (Element **)v->store; + String *hnamestore = (String *)v->store2; + *elementstore = v->v.element; + *hnamestore = v->v2_string; + break; + } + + case cpiHandler: + case cpiReadHandler: + case cpiWriteHandler: { + Element **elementstore = (Element **)v->store; + int *hidstore = (int *)v->store2; + *elementstore = v->v.element; + *hidstore = v->v2.i; + break; + } + + case cpiReadHandlerCall: + case cpiWriteHandlerCall: { + cp_handler_call + (v->v_string, context, argtype->internal == cpiWriteHandlerCall, + (HandlerCall **)v->store, (ErrorHandler *)0); + break; + } +#endif + + default: + // no argument provided + break; + + } +} + + +#define CP_VALUES_SIZE 80 +#ifdef CLICK_SIM +usin +static cp_value *cp_values; +static Vector *cp_parameter_used; + +enum { + kwSuccess = 0, + kwDupKeyword = -1, + kwNoKeyword = -2, + kwUnkKeyword = -3, + kwMissingKeyword = -4 +}; + +static inline bool +special_argtype_for_keyword(const cp_argtype *t) +{ + return t->internal == cpiArguments; +} + +static int +handle_special_argtype_for_keyword(cp_value *val, const String &rest) +{ + if (val->argtype->internal == cpiArguments) { + if (val->v.i > 0) { + uint32_t l = val->v_string.length(); + val->v2_string += String((const char *)&l, 4); + val->v_string += rest; + } else { + val->v.i = 1; + val->v_string = rest; + val->v2_string = String(); + } + return kwSuccess; + } else { + assert(0); + return kwUnkKeyword; + } +} + +static int +assign_keyword_argument(const String &arg, int npositional, int nvalues) +{ + String keyword, rest; + // extract keyword + if (!cp_keyword(arg, &keyword, &rest)) + return kwNoKeyword; + // doesn't count as a keyword if there was no accompanying data + // (XXX is this a great idea?) + if (!rest) + return kwNoKeyword; + // look for keyword value + for (int i = npositional; i < nvalues; i++) + if (keyword == cp_values[i].keyword) { + cp_value *val = &cp_values[i]; + // handle special types differently + if (special_argtype_for_keyword(val->argtype)) + return handle_special_argtype_for_keyword(val, rest); + else { + // do not report error if keyword used already + // if (cp_values[i].v.i > 0) + // return kwDupKeyword; + val->v.i = 1; + val->v_string = rest; + return kwSuccess; + } + } + // no keyword found + return kwUnkKeyword; +} + +static void +add_keyword_error(StringAccum &sa, int err, const String &arg, + const char *argname, int argno) +{ + if (err >= 0) + return; + if (sa.length()) + sa << ", "; + if (err == kwNoKeyword) + sa << '<' << argname << ' ' << (argno + 1) << '>'; + else { + String keyword, rest; + (void) cp_keyword(arg, &keyword, &rest); + sa << keyword; + if (err == kwDupKeyword) + sa << " (duplicate keyword)"; + } +} + +static int +finish_keyword_error(const char *format, const char *bad_keywords, + int npositional, int nvalues, ErrorHandler *errh) +{ + StringAccum keywords_sa; + for (int i = npositional; i < nvalues; i++) { + if (i > npositional) + keywords_sa << ", "; + keywords_sa << cp_values[i].keyword; + } + errh->error(format, bad_keywords, keywords_sa.cc()); + return -1; +} + +#ifdef CLICK_SIM +namespace CLICKSIM { +static int +cp_va_parsev(const Vector &args, +#ifndef CLICK_TOOL + Element *context, +#endif + const char *argname, const char *separator, + bool keywords_only, + ErrorHandler *errh, va_list val); +} +#endif + +static int +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_va_parsev(const Vector &args, +#ifndef CLICK_TOOL + Element *context, +#endif + const char *argname, const char *separator, + bool keywords_only, + ErrorHandler *errh, va_list val) +{ + if (!cp_values || !cp_parameter_used) + return errh->error("out of memory in cp_va_parse"); + + int nvalues = 0; + int nrequired = -1; + int npositional = -1; + bool mandatory_keywords = false; + bool ignore_rest = false; + int nerrors_in = errh->nerrors(); + + // + // First, parse information about possible arguments from 'val'. + // + + if (keywords_only) { + nrequired = npositional = 0; + ignore_rest = true; + } + + while (1) { + + if (nvalues == CP_VALUES_SIZE - 1) + // no more space to store information about the arguments; break + return errh->error("too many arguments to cp_va_parsev!"); + + cp_value *v = &cp_values[nvalues]; + v->argtype = 0; + v->keyword = 0; + const char *command_name = 0; + + if (npositional >= 0) { + // read keyword if necessary; be careful of special "cp" values, + // which begin with "\377" + v->keyword = va_arg(val, const char *); + if (v->keyword == 0) + goto done; + else if (v->keyword[0] == '\377') + command_name = v->keyword; + } + + // read command name + if (command_name == 0) + command_name = va_arg(val, const char *); + if (command_name == 0) + goto done; + + // find cp_argtype + const cp_argtype *argtype = find_argtype(command_name); + if (!argtype) { + errh->error("unknown argument type `%s'!", command_name); + goto done; + } + + // check for special commands + if (argtype->internal == cpiOptional) { + if (nrequired < 0) + nrequired = nvalues; + continue; + } else if (argtype->internal == cpiKeywords + || argtype->internal == cpiMandatoryKeywords) { + if (nrequired < 0) + nrequired = nvalues; + if (npositional < 0) + npositional = nvalues; + mandatory_keywords = (argtype->internal == cpiMandatoryKeywords); + continue; + } else if (argtype->internal == cpiIgnore) { + v->argtype = argtype; + nvalues++; + continue; + } else if (argtype->internal == cpiIgnoreRest) { + if (nrequired < 0) + nrequired = nvalues; + ignore_rest = true; + goto done; + } + + // store stuff in v + v->argtype = argtype; + v->description = va_arg(val, const char *); + if (argtype->extra == cpArgExtraInt) + v->extra = va_arg(val, int); + v->store = va_arg(val, void *); + if (argtype->extra == cpArgStore2) + v->store2 = va_arg(val, void *); + v->v.i = (mandatory_keywords ? -1 : 0); + nvalues++; + } + + done: + + if (nrequired < 0) + nrequired = nvalues; + if (npositional < 0) + npositional = nvalues; + + // + // Next, assign parameters from 'conf' to argument slots. + // + + int npositional_supplied = 0; + StringAccum keyword_error_sa; + bool any_keywords = false; + cp_parameter_used->assign(args.size(), 0); + + for (int i = 0; i < args.size(); i++) { + // check for keyword if past mandatory positional arguments + if (npositional_supplied >= nrequired) { + int result = assign_keyword_argument(args[i], npositional, nvalues); + if (result == kwSuccess) { + (*cp_parameter_used)[i] = 1; + any_keywords = true; + } else if (!any_keywords) + goto positional_argument; // optional argument, or too many arguments + else if (ignore_rest) + /* no error */; + else + add_keyword_error(keyword_error_sa, result, args[i], argname, i); + continue; + } + + // otherwise, assign positional argument + positional_argument: + if (npositional_supplied < npositional) { + (*cp_parameter_used)[i] = 1; + cp_values[npositional_supplied].v_string = args[i]; + } + npositional_supplied++; + } + + // report keyword argument errors + if (keyword_error_sa.length() && !keywords_only) + return finish_keyword_error("bad keyword(s) %s\n(valid keywords are %s)", keyword_error_sa.cc(), npositional, nvalues, errh); + + // report missing mandatory keywords + for (int i = npositional; i < nvalues; i++) + if (cp_values[i].v.i < 0) { + if (keyword_error_sa.length()) + keyword_error_sa << ", "; + keyword_error_sa << cp_values[i].keyword; + } + if (keyword_error_sa.length()) + return errh->error("missing mandatory keyword(s) %s", keyword_error_sa.cc()); + + // if wrong number of arguments, print signature + if (npositional_supplied < nrequired + || (npositional_supplied > npositional && !ignore_rest)) { + StringAccum signature; + for (int i = 0; i < npositional; i++) { + if (i == nrequired) + signature << (nrequired > 0 ? " [" : "["); + if (i) + signature << separator; + if (const cp_argtype *t = cp_values[i].argtype) + signature << t->description; + else + signature << "??"; + } + if (ignore_rest) + signature << "..."; + if (nrequired < npositional) + signature << "]"; + if (npositional < nvalues) { + if (npositional) + signature << separator; + signature << "[keywords]"; + } + + const char *whoops = (npositional_supplied > npositional ? "too many" : "too few"); + if (signature.length()) + errh->error("%s %ss; expected `%s'", whoops, argname, signature.cc()); + else + errh->error("expected empty %s list", argname); + return -1; + } + + // clear 'argtype' on unused arguments + for (int i = npositional_supplied; i < npositional; i++) + cp_values[i].argtype = 0; + for (int i = npositional; i < nvalues; i++) + if (cp_values[i].v.i <= 0) + cp_values[i].argtype = 0; + + // parse arguments + char argname_buf[128]; + int argname_offset; + argname_offset = sprintf(argname_buf, "%s ", argname); + + for (int i = 0; i < npositional; i++) { + cp_value *v = &cp_values[i]; + if (v->argtype) { + sprintf(argname_buf + argname_offset, "%d", i + 1); + v->argtype->parse(v, v->v_string, errh, argname_buf CP_PASS_CONTEXT); + } + } + for (int i = npositional; i < nvalues; i++) { + cp_value *v = &cp_values[i]; + if (v->argtype) { + StringAccum sa; + sa << "keyword " << v->keyword; + v->argtype->parse(v, v->v_string, errh, sa.cc() CP_PASS_CONTEXT); + } + } + + // check for failure + if (errh->nerrors() != nerrors_in) + return -1; + + // if success, actually set the values + int nset = 0; + for (int i = 0; i < nvalues; i++) + if (const cp_argtype *t = cp_values[i].argtype) { + t->store(&cp_values[i] CP_PASS_CONTEXT); + nset++; + } + return nset; +} + +int +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_va_parse(const Vector &conf, +#ifndef CLICK_TOOL + Element *context, +#endif + ErrorHandler *errh, ...) +{ + va_list val; + va_start(val, errh); +#ifndef CLICK_TOOL + int retval = cp_va_parsev(conf, context, "argument", ", ", false, errh, val); +#else + int retval = cp_va_parsev(conf, "argument", ", ", false, errh, val); +#endif + va_end(val); + return retval; +} + +int +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_va_parse(const String &confstr, +#ifndef CLICK_TOOL + Element *context, +#endif + ErrorHandler *errh, ...) +{ + va_list val; + va_start(val, errh); + Vector conf; + cp_argvec(confstr, conf); +#ifndef CLICK_TOOL + int retval = cp_va_parsev(conf, context, "argument", ", ", false, errh, val); +#else + int retval = cp_va_parsev(conf, "argument", ", ", false, errh, val); +#endif + va_end(val); + return retval; +} + +int +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_va_space_parse(const String &argument, +#ifndef CLICK_TOOL + Element *context, +#endif + ErrorHandler *errh, ...) +{ + va_list val; + va_start(val, errh); + Vector args; + cp_spacevec(argument, args); +#ifndef CLICK_TOOL + int retval = cp_va_parsev(args, context, "word", " ", false, errh, val); +#else + int retval = cp_va_parsev(args, "word", " ", false, errh, val); +#endif + va_end(val); + return retval; +} + +int +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_va_parse_keyword(const String &arg, +#ifndef CLICK_TOOL + Element *context, +#endif + ErrorHandler *errh, ...) +{ + va_list val; + va_start(val, errh); + Vector conf; + conf.push_back(arg); +#ifndef CLICK_TOOL + int retval = cp_va_parsev(conf, context, "argument", ", ", true, errh, val); +#else + int retval = cp_va_parsev(conf, "argument", ", ", true, errh, val); +#endif + va_end(val); + return retval; +} + +int +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_va_parse_remove_keywords(Vector &conf, int first, +#ifndef CLICK_TOOL + Element *context, +#endif + ErrorHandler *errh, ...) +{ + Vector conf2, *confp = &conf; + if (first > 0) { + for (int i = first; i < conf.size(); i++) + conf2.push_back(conf[i]); + confp = &conf2; + } + + va_list val; + va_start(val, errh); +#ifndef CLICK_TOOL + int retval = cp_va_parsev(*confp, context, "argument", ", ", true, errh, val); +#else + int retval = cp_va_parsev(*confp, "argument", ", ", true, errh, val); +#endif + va_end(val); + + // remove keywords that were used + if (retval >= 0) { + int delta = 0; + for (int i = first; i < conf.size(); i++) + if ((*cp_parameter_used)[i - first]) + delta++; + else if (delta) + conf[i - delta] = conf[i]; + conf.resize(conf.size() - delta); + } + + return retval; +} + + +// UNPARSING + +String +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unparse_bool(bool b) +{ + return String(b ? "true" : "false"); +} + +#ifdef HAVE_INT64_TYPES + +String +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unparse_unsigned64(uint64_t q, int base, bool uppercase) +{ + // Unparse a uint64_t. Linux kernel sprintf can't handle %lld, so we provide + // our own function. + + char buf[256]; + char *lastbuf = buf + 255; + char *trav; + + if (base == 16 || base == 8) { + // different code. + const char *digits = (uppercase ? "0123456789ABCDEF" : "0123456789abcdef"); + int shift = (base == 16 ? 4 : 3); + for (trav = lastbuf; q > 0; trav--) { + *trav = digits[q & (base - 1)]; + q >>= shift; + } + } else { + assert(base == 10); + + for (trav = lastbuf; q > 0; trav--) { + + // k = Approx[q/10] -- know that k <= q/10 + uint64_t k = (q >> 4) + (q >> 5) + (q >> 8) + (q >> 9) + + (q >> 12) + (q >> 13) + (q >> 16) + (q >> 17); + uint64_t m; + + // increase k until it exactly equals floor(q/10). on exit, m is the + // remainder: m < 10 and q == 10*k + m. + while (1) { + // d = 10*k + uint64_t d = (k << 3) + (k << 1); + m = q - d; + if (m < 10) break; + + // delta = Approx[m/10] -- know that delta <= m/10 + uint64_t delta = (m >> 4) + (m >> 5) + (m >> 8) + (m >> 9); + if (m >= 0x1000) + delta += (m >> 12) + (m >> 13) + (m >> 16) + (m >> 17); + + // delta might have underflowed: add at least 1 + k += (delta ? delta : 1); + } + + *trav = '0' + (unsigned)m; + q = k; + } + } + + // make sure at least one 0 is written + if (trav == lastbuf) + *trav-- = '0'; + + return String(trav + 1, lastbuf - trav); +} + +String +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unparse_integer64(int64_t q, int base, bool uppercase) +{ + if (q < 0) + return "-" + cp_unparse_unsigned64(-q, base, uppercase); + else + return cp_unparse_unsigned64(q, base, uppercase); +} + +#endif + +String +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unparse_real2(uint32_t real, int frac_bits) +{ + // adopted from Knuth's TeX function print_scaled, hope it is correct in + // this context but not sure. + // Works well with cp_real2 above; as an invariant, + // unsigned x, y; + // cp_real2(cp_unparse_real2(x, FRAC_BITS), FRAC_BITS, &y) == true && x == y + + StringAccum sa; + assert(frac_bits <= CP_REAL2_MAX_FRAC_BITS); + + uint32_t int_part = real >> frac_bits; + sa << int_part; + + uint32_t one = 1 << frac_bits; + real &= one - 1; + if (!real) return sa.take_string(); + + sa << "."; + real = (10 * real) + 5; + unsigned allowable_inaccuracy = 10; + + unsigned inaccuracy_rounder = 5; + while (inaccuracy_rounder < (one >> 1)) + inaccuracy_rounder *= 10; + + do { + if (allowable_inaccuracy > one) + real += (one >> 1) - inaccuracy_rounder; + sa << static_cast('0' + (real >> frac_bits)); + real = 10 * (real & (one - 1)); + allowable_inaccuracy *= 10; + } while (real > allowable_inaccuracy); + + return sa.take_string(); +} + +#undef TEST_REAL2 +#ifdef TEST_REAL2 +void +test_unparse_real2() +{ +#define TEST(s, frac_bits, result) { String q = (#s); uint32_t r; if (!cp_unsigned_real2(q, (frac_bits), &r)) fprintf(stderr, "FAIL: %s unparsable\n", q.cc()); else { String qq = cp_unparse_real2(r, (frac_bits)); fprintf(stderr, "%s: %s %d/%d %s\n", (qq == (result) ? "PASS" : "FAIL"), q.cc(), r, (frac_bits), qq.cc()); }} + TEST(0.418, 8, "0.418"); + TEST(0.417, 8, "0.418"); + TEST(0.416, 8, "0.414"); + TEST(0.42, 8, "0.42"); + TEST(0.3, 16, "0.3"); + TEST(0.49, 16, "0.49"); + TEST(0.499, 16, "0.499"); + TEST(0.4999, 16, "0.4999"); + TEST(0.49999, 16, "0.49998"); + TEST(0.499999, 16, "0.5"); + TEST(0.49998, 16, "0.49998"); + TEST(0.999999, 16, "1"); +#undef TEST +} +#endif + +String +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unparse_real2(int32_t real, int frac_bits) +{ + if (real < 0) + return "-" + cp_unparse_real2(static_cast(-real), frac_bits); + else + return cp_unparse_real2(static_cast(real), frac_bits); +} + +#ifdef HAVE_INT64_TYPES +String +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unparse_real2(uint64_t real, int frac_bits) +{ + assert(frac_bits <= CP_REAL2_MAX_FRAC_BITS); + String int_part = cp_unparse_unsigned64(real >> frac_bits, 10, false); + String frac_part = cp_unparse_real2((uint32_t)(real & ((1 << frac_bits) - 1)), frac_bits); + return int_part + frac_part.substring(1); +} + +String +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unparse_real2(int64_t real, int frac_bits) +{ + if (real < 0) + return "-" + cp_unparse_real2(static_cast(-real), frac_bits); + else + return cp_unparse_real2(static_cast(real), frac_bits); +} +#endif + +String +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unparse_real10(uint32_t real, int frac_digits) +{ + assert(frac_digits >= 0 && frac_digits <= 9); + uint32_t one = exp10[frac_digits]; + uint32_t int_part = real / one; + uint32_t frac_part = real - (int_part * one); + + if (frac_part == 0) + return String(int_part); + + StringAccum sa(30); + sa << int_part << '.'; + if (char *x = sa.extend(frac_digits, 1)) + sprintf(x, "%0*d", frac_digits, frac_part); + else // out of memory + return sa.take_string(); + + // remove trailing zeros from fraction part + while (sa.back() == '0') + sa.pop_back(); + + return sa.take_string(); +} + +String +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unparse_real10(int32_t real, int frac_digits) +{ + if (real < 0) + return "-" + cp_unparse_real10(static_cast(-real), frac_digits); + else + return cp_unparse_real10(static_cast(real), frac_digits); +} + +String +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unparse_milliseconds(uint32_t ms) +{ + if (ms && ms < 1000) + return String(ms) + "ms"; + else + return cp_unparse_real10(ms, 3) + "s"; +} + +String +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unparse_microseconds(uint32_t us) +{ + if (us && us < 1000) + return String(us) + "us"; + else + return cp_unparse_real10(us, 6) + "s"; +} + +String +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unparse_interval(const struct timeval &tv) +{ + if (!tv.tv_sec) + return cp_unparse_microseconds(tv.tv_usec); + else { + StringAccum sa; + sa << tv << 's'; + return sa.take_string(); + } +} + + +// initialization and cleanup + +void +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_va_static_initialize() +{ + assert(!cp_values); + + cp_register_argtype(cpOptional, "", 0, default_parsefunc, default_storefunc, cpiOptional); + cp_register_argtype(cpKeywords, "", 0, default_parsefunc, default_storefunc, cpiKeywords); + cp_register_argtype(cpMandatoryKeywords, "", 0, default_parsefunc, default_storefunc, cpiMandatoryKeywords); + cp_register_argtype(cpIgnore, "", 0, default_parsefunc, default_storefunc, cpiIgnore); + cp_register_argtype(cpIgnoreRest, "", 0, default_parsefunc, default_storefunc, cpiIgnoreRest); + + cp_register_argtype(cpArgument, "arg", 0, default_parsefunc, default_storefunc, cpiArgument); + cp_register_argtype(cpArguments, "args", 0, default_parsefunc, default_storefunc, cpiArguments); + cp_register_argtype(cpString, "string", 0, default_parsefunc, default_storefunc, cpiString); + cp_register_argtype(cpWord, "word", 0, default_parsefunc, default_storefunc, cpiWord); + cp_register_argtype(cpKeyword, "keyword", 0, default_parsefunc, default_storefunc, cpiKeyword); + cp_register_argtype(cpBool, "bool", 0, default_parsefunc, default_storefunc, cpiBool); + cp_register_argtype(cpByte, "byte", 0, default_parsefunc, default_storefunc, cpiByte); + cp_register_argtype(cpShort, "short", 0, default_parsefunc, default_storefunc, cpiShort); + cp_register_argtype(cpUnsignedShort, "unsigned short", 0, default_parsefunc, default_storefunc, cpiUnsignedShort); + cp_register_argtype(cpInteger, "int", 0, default_parsefunc, default_storefunc, cpiInteger); + cp_register_argtype(cpUnsigned, "unsigned", 0, default_parsefunc, default_storefunc, cpiUnsigned); +#ifdef HAVE_INT64_TYPES + cp_register_argtype(cpInteger64, "64-bit int", 0, default_parsefunc, default_storefunc, cpiInteger64); + cp_register_argtype(cpUnsigned64, "64-bit unsigned", 0, default_parsefunc, default_storefunc, cpiUnsigned64); +#endif + cp_register_argtype(cpReal2, "real", cpArgExtraInt, default_parsefunc, default_storefunc, cpiReal2); + cp_register_argtype(cpUnsignedReal2, "unsigned real", cpArgExtraInt, default_parsefunc, default_storefunc, cpiUnsignedReal2); + cp_register_argtype(cpReal10, "real", cpArgExtraInt, default_parsefunc, default_storefunc, cpiReal10); + cp_register_argtype(cpUnsignedReal10, "unsigned real", cpArgExtraInt, default_parsefunc, default_storefunc, cpiUnsignedReal10); +#ifdef HAVE_FLOAT_TYPES + cp_register_argtype(cpDouble, "double", 0, default_parsefunc, default_storefunc, cpiDouble); +#endif + cp_register_argtype(cpSeconds, "time in sec", 0, default_parsefunc, default_storefunc, cpiSeconds); + cp_register_argtype(cpSecondsAsMilli, "time in sec (msec precision)", 0, default_parsefunc, default_storefunc, cpiSecondsAsMilli); + cp_register_argtype(cpSecondsAsMicro, "time in sec (usec precision)", 0, default_parsefunc, default_storefunc, cpiSecondsAsMicro); + cp_register_argtype(cpTimeval, "seconds since the epoch", 0, default_parsefunc, default_storefunc, cpiTimeval); + cp_register_argtype(cpInterval, "time in sec (usec precision)", 0, default_parsefunc, default_storefunc, cpiInterval); + cp_register_argtype(cpIPAddress, "IP address", 0, default_parsefunc, default_storefunc, cpiIPAddress); + cp_register_argtype(cpIPPrefix, "IP address prefix", cpArgStore2, default_parsefunc, default_storefunc, cpiIPPrefix); + cp_register_argtype(cpIPAddressOrPrefix, "IP address or prefix", cpArgStore2, default_parsefunc, default_storefunc, cpiIPAddressOrPrefix); + cp_register_argtype(cpIPAddressSet, "set of IP addresses", 0, default_parsefunc, default_storefunc, cpiIPAddressSet); + cp_register_argtype(cpEthernetAddress, "Ethernet address", 0, default_parsefunc, default_storefunc, cpiEthernetAddress); +#ifndef CLICK_TOOL + cp_register_argtype(cpElement, "element name", 0, default_parsefunc, default_storefunc, cpiElement); + cp_register_argtype(cpHandlerName, "handler name", cpArgStore2, default_parsefunc, default_storefunc, cpiHandlerName); + cp_register_argtype(cpHandler, "handler name", cpArgStore2, default_parsefunc, default_storefunc, cpiHandler); + cp_register_argtype(cpReadHandler, "read handler name", cpArgStore2, default_parsefunc, default_storefunc, cpiReadHandler); + cp_register_argtype(cpWriteHandler, "write handler name", cpArgStore2, default_parsefunc, default_storefunc, cpiWriteHandler); + cp_register_argtype(cpReadHandlerCall, "read handler name", 0, default_parsefunc, default_storefunc, cpiReadHandlerCall); + cp_register_argtype(cpWriteHandlerCall, "write handler name and value", 0, default_parsefunc, default_storefunc, cpiWriteHandlerCall); +#endif +#ifdef HAVE_IP6 + cp_register_argtype(cpIP6Address, "IPv6 address", 0, default_parsefunc, default_storefunc, cpiIP6Address); + cp_register_argtype(cpIP6Prefix, "IPv6 address prefix", cpArgStore2, default_parsefunc, default_storefunc, cpiIP6Prefix); + cp_register_argtype(cpIP6AddressOrPrefix, "IPv6 address or prefix", cpArgStore2, default_parsefunc, default_storefunc, cpiIP6AddressOrPrefix); +#endif +#ifdef HAVE_IPSEC + cp_register_argtype(cpDesCblock, "DES cipher block", 0, default_parsefunc, default_storefunc, cpiDesCblock); +#endif +#ifdef CLICK_USERLEVEL + cp_register_argtype(cpFilename, "filename", 0, default_parsefunc, default_storefunc, cpiFilename); +#endif + + cp_values = new cp_value[CP_VALUES_SIZE]; + cp_parameter_used = new Vector; + +#ifdef TEST_REAL2 + test_unparse_real2(); +#endif +} + +void +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_va_static_cleanup() +{ + for (int i = 0; i < NARGTYPE_HASH; i++) { + cp_argtype *t = argtype_hash[i]; + while (t) { + cp_argtype *n = t->next; + delete t; + t = n; + } + } + memset(argtype_hash, 0, sizeof(argtype_hash)); + + delete[] cp_values; + delete cp_parameter_used; + cp_values = 0; + cp_parameter_used = 0; +} diff -urN click-1.2.4.orig/lib/archive.cc click-1.2.4/lib/archive.cc --- click-1.2.4.orig/lib/archive.cc Wed Apr 24 09:51:29 2002 +++ click-1.2.4/lib/archive.cc Fri May 31 23:03:29 2002 @@ -24,6 +24,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + /* `ar' file format: "!\n" diff -urN click-1.2.4.orig/lib/bitvector.cc click-1.2.4/lib/bitvector.cc --- click-1.2.4.orig/lib/bitvector.cc Sat Jan 5 01:43:57 2002 +++ click-1.2.4/lib/bitvector.cc Fri May 31 15:09:40 2002 @@ -21,6 +21,10 @@ #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + void Bitvector::finish_copy_constructor(const Bitvector &o) { diff -urN click-1.2.4.orig/lib/confparse.cc click-1.2.4/lib/confparse.cc --- click-1.2.4.orig/lib/confparse.cc Tue Apr 30 16:13:42 2002 +++ click-1.2.4/lib/confparse.cc Mon Jun 3 20:30:02 2002 @@ -45,9 +45,20 @@ #endif #include -int cp_errno; +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + +int +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_errno; bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_eat_space(String &str) { const char *s = str.data(); @@ -63,6 +74,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_is_space(const String &str) { const char *s = str.data(); @@ -74,6 +88,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_is_word(const String &str) { const char *s = str.data(); @@ -220,6 +237,9 @@ } String +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_uncomment(const String &str) { return partial_uncomment(str, 0, 0); @@ -305,6 +325,9 @@ } String +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unquote(const String &in_str) { String str = partial_uncomment(in_str, 0, 0); @@ -353,6 +376,9 @@ } String +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_quote(const String &str, bool allow_newlines) { if (!str) @@ -410,6 +436,9 @@ } void +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_argvec(const String &conf, Vector &args) { int len = conf.length(); @@ -435,7 +464,17 @@ } } +#ifdef CLICK_SIM +namespace CLICKSIM { static String +cp_pop_spacevec(const String &conf, int &pos); +} +#endif + +static String +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_pop_spacevec(const String &conf, int &pos) { const char *s = conf.data(); @@ -503,6 +542,9 @@ } void +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_spacevec(const String &conf, Vector &vec) { // common case: no configuration @@ -517,6 +559,9 @@ } String +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_pop_spacevec(String &conf) { int pos = 0; @@ -527,6 +572,9 @@ } String +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unargvec(const Vector &args) { if (args.size() == 0) @@ -543,6 +591,9 @@ } String +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unspacevec(const Vector &args) { StringAccum sa; @@ -557,6 +608,9 @@ // PARSING STRINGS bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_string(const String &str, String *return_value, String *rest) { const char *s = str.data(); @@ -602,6 +656,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_word(const String &str, String *return_value, String *rest) { String word; @@ -616,6 +673,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_keyword(const String &str, String *return_value, String *rest) { const char *s = str.data(); @@ -666,6 +726,9 @@ // PARSING INTEGERS bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_bool(const String &str, bool *return_value) { const char *s = str.data(); @@ -690,6 +753,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unsigned(const String &str, int base, uint32_t *return_value) { const char *s = str.data(); @@ -746,6 +812,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unsigned(const String &str, uint32_t *return_value) { return cp_unsigned(str, 0, return_value); @@ -753,6 +822,9 @@ bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_integer(const String &in_str, int base, int32_t *return_value) { String str = in_str; @@ -777,6 +849,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_integer(const String &str, int32_t *return_value) { return cp_integer(str, 0, return_value); @@ -788,6 +863,9 @@ static uint64_t unsigned64_overflow_vals[] = { 0, 0, 9223372036854775807ULL, 6148914691236517205ULL, 4611686018427387903ULL, 3689348814741910323ULL, 3074457345618258602ULL, 2635249153387078802ULL, 2305843009213693951ULL, 2049638230412172401ULL, 1844674407370955161ULL, 1676976733973595601ULL, 1537228672809129301ULL, 1418980313362273201ULL, 1317624576693539401ULL, 1229782938247303441ULL, 1152921504606846975ULL, 1085102592571150095ULL, 1024819115206086200ULL, 970881267037344821ULL, 922337203685477580ULL, 878416384462359600ULL, 838488366986797800ULL, 802032351030850070ULL, 768614336404564650ULL, 737869762948382064ULL, 709490156681136600ULL, 683212743470724133ULL, 658812288346769700ULL, 636094623231363848ULL, 614891469123651720ULL, 595056260442243600ULL, 576460752303423487ULL, 558992244657865200ULL, 542551296285575047ULL, 527049830677415760ULL }; bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unsigned64(const String &str, int base, uint64_t *return_value) { const char *s = str.data(); @@ -844,12 +922,18 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unsigned64(const String &str, uint64_t *return_value) { return cp_unsigned64(str, 0, return_value); } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_integer64(const String &in_str, int base, int64_t *return_value) { String str = in_str; @@ -874,6 +958,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_integer64(const String &str, int64_t *return_value) { return cp_integer64(str, 0, return_value); @@ -884,10 +971,22 @@ // PARSING REAL NUMBERS -static uint32_t exp10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, +static uint32_t +exp10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; + +#ifdef CLICK_SIM +namespace CLICKSIM { +bool cp_unsigned_real10(const String &str, int frac_digits, int exponent_delta, + uint32_t *return_int_part, uint32_t *return_frac_part); +} +#endif + bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unsigned_real10(const String &str, int frac_digits, int exponent_delta, uint32_t *return_int_part, uint32_t *return_frac_part) { @@ -1011,8 +1110,19 @@ return true; } +#ifdef CLICK_SIM +namespace CLICKSIM { static bool unsigned_real10_2to1(uint32_t int_part, uint32_t frac_part, int frac_digits, + uint32_t *return_value); +} +#endif + +static bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +unsigned_real10_2to1(uint32_t int_part, uint32_t frac_part, int frac_digits, uint32_t *return_value) { uint32_t one = exp10[frac_digits]; @@ -1027,6 +1137,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unsigned_real10(const String &str, int frac_digits, uint32_t *return_int_part, uint32_t *return_frac_part) { @@ -1034,8 +1147,19 @@ return_int_part, return_frac_part); } +#ifdef CLICK_SIM +namespace CLICKSIM { bool cp_unsigned_real10(const String &str, int frac_digits, int exponent_delta, + uint32_t *return_value); +} +#endif + +bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_unsigned_real10(const String &str, int frac_digits, int exponent_delta, uint32_t *return_value) { uint32_t int_part, frac_part; @@ -1046,6 +1170,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unsigned_real10(const String &str, int frac_digits, uint32_t *return_value) { @@ -1056,12 +1183,17 @@ return unsigned_real10_2to1(int_part, frac_part, frac_digits, return_value); } -static uint32_t ureal2_digit_fractions[] = { + +static uint32_t +ureal2_digit_fractions[] = { 0x00000000, 0x19999999, 0x33333333, 0x4CCCCCCC, 0x66666666, 0x80000000, 0x99999999, 0xB3333333, 0xCCCCCCCC, 0xE6666666 }; bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unsigned_real2(const String &str, int frac_bits, uint32_t *return_value) { if (frac_bits < 0 || frac_bits > CP_REAL2_MAX_FRAC_BITS) { @@ -1102,8 +1234,20 @@ // Parsing signed reals + +#ifdef CLICK_SIM +namespace CLICKSIM { static bool cp_real_base(const String &in_str, int frac_digits, int32_t *return_value, + bool (*func)(const String &, int, uint32_t *)); +} +#endif + +static bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_real_base(const String &in_str, int frac_digits, int32_t *return_value, bool (*func)(const String &, int, uint32_t *)) { String str = in_str; @@ -1129,12 +1273,18 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_real10(const String &str, int frac_digits, int32_t *return_value) { return cp_real_base(str, frac_digits, return_value, cp_unsigned_real10); } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_real2(const String &str, int frac_bits, int32_t *return_value) { return cp_real_base(str, frac_bits, return_value, cp_unsigned_real2); @@ -1142,6 +1292,9 @@ #ifdef HAVE_FLOAT_TYPES bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_double(const String &in_str, double *result) { cp_errno = CPE_FORMAT; @@ -1209,6 +1362,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_seconds_as(int want_power, const String &str_in, uint32_t *return_value) { int power, factor; @@ -1224,18 +1380,27 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_seconds_as_milli(const String &str_in, uint32_t *return_value) { return cp_seconds_as(3, str_in, return_value); } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_seconds_as_micro(const String &str_in, uint32_t *return_value) { return cp_seconds_as(6, str_in, return_value); } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_timeval(const String &str_in, struct timeval *return_value) { int power, factor; @@ -1283,6 +1448,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_ip_address(const String &str, unsigned char *return_value CP_CONTEXT_ARG) { @@ -1321,6 +1489,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_ip_prefix(const String &str, unsigned char *return_value, unsigned char *return_mask, bool allow_bare_address CP_CONTEXT_ARG) @@ -1383,6 +1554,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_ip_address(const String &str, IPAddress *address CP_CONTEXT_ARG) { @@ -1391,6 +1565,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_ip_prefix(const String &str, IPAddress *address, IPAddress *mask, bool allow_bare_address CP_CONTEXT_ARG) { @@ -1399,6 +1576,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_ip_prefix(const String &str, unsigned char *address, unsigned char *mask CP_CONTEXT_ARG) { @@ -1407,6 +1587,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_ip_prefix(const String &str, IPAddress *address, IPAddress *mask CP_CONTEXT_ARG) { @@ -1415,6 +1598,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_ip_address_set(const String &str, IPAddressSet *set CP_CONTEXT_ARG) { @@ -1450,6 +1636,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_ip6_address(const String &str, unsigned char *return_value CP_CONTEXT_ARG) { @@ -1513,6 +1702,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_ip6_address(const String &str, IP6Address *address CP_CONTEXT_ARG) { @@ -1542,6 +1734,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_ip6_prefix(const String &str, unsigned char *return_value, int *return_bits, bool allow_bare_address CP_CONTEXT_ARG) @@ -1590,6 +1785,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_ip6_prefix(const String &str, unsigned char *address, unsigned char *mask, bool allow_bare_address CP_CONTEXT_ARG) { @@ -1603,6 +1801,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_ip6_prefix(const String &str, IP6Address *address, int *prefix, bool allow_bare_address CP_CONTEXT_ARG) { @@ -1610,6 +1811,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_ip6_prefix(const String &str, IP6Address *address, IP6Address *prefix, bool allow_bare_address CP_CONTEXT_ARG) { @@ -1620,6 +1824,9 @@ bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_ethernet_address(const String &str, unsigned char *return_value CP_CONTEXT_ARG) { @@ -1657,6 +1864,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_ethernet_address(const String &str, EtherAddress *address CP_CONTEXT_ARG) { @@ -1667,6 +1877,9 @@ #ifndef CLICK_TOOL Element * +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_element(const String &text_in, Element *context, ErrorHandler *errh) { String name; @@ -1679,6 +1892,9 @@ } Element * +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_element(const String &text_in, Router *router, ErrorHandler *errh) { String name; @@ -1691,6 +1907,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_handler(const String &str, Element *context, Element **result_element, String *result_hname, ErrorHandler *errh) { @@ -1723,6 +1942,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_handler(const String &str, Element *context, bool need_read, bool need_write, Element **result_element, int *result_hid, ErrorHandler *errh) @@ -1761,12 +1983,18 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_handler(const String &str, Element *context, Element **result_element, int *result_hid, ErrorHandler *errh) { return cp_handler(str, context, false, false, result_element, result_hid, errh); } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_handler_call(const String &str, Element *context, bool is_write, HandlerCall **hcall, ErrorHandler *errh) { if (!errh) @@ -1785,6 +2013,9 @@ #ifdef HAVE_IPSEC bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_des_cblock(const String &str, unsigned char *return_value) { int i = 0; @@ -1814,6 +2045,9 @@ #ifdef CLICK_USERLEVEL bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_filename(const String &str, String *return_value) { String fn; @@ -1859,7 +2093,9 @@ // parse commands; those which must be recognized inside a keyword section // must begin with "\377" - +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif CpVaParseCmd cpOptional = "OPTIONAL", cpKeywords = "\377KEYWORDS", @@ -1911,7 +2147,9 @@ cpIP6AddressOrPrefix = "ip6_addr_or_prefix", cpDesCblock = "des_cblock", cpFilename = "filename"; - +#ifdef CLICK_SIM +} +#endif enum { cpiEnd = 0, cpiOptional, @@ -1980,8 +2218,19 @@ return t; } +#ifdef CLICK_SIM +namespace CLICKSIM { static int cp_register_argtype(const char *name, const char *desc, int extra, + cp_parsefunc parse, cp_storefunc store, int internal); +} +#endif + +static int +#ifdef CLICK_SIM +CLICKSIM:: +#endif +cp_register_argtype(const char *name, const char *desc, int extra, cp_parsefunc parse, cp_storefunc store, int internal) { if (cp_argtype *t = find_argtype(name)) { @@ -2013,6 +2262,9 @@ } int +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_register_argtype(const char *name, const char *desc, int extra, cp_parsefunc parse, cp_storefunc store) { @@ -2020,6 +2272,9 @@ } void +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unregister_argtype(const char *name) { cp_argtype **prev = &argtype_hash[argtype_bucket(name)]; @@ -2037,8 +2292,19 @@ } } +#ifdef CLICK_SIM +namespace CLICKSIM { static void default_parsefunc(cp_value *v, const String &arg, + ErrorHandler *errh, const char *argname CP_CONTEXT_ARG); +} +#endif + +static void +#ifdef CLICK_SIM +CLICKSIM:: +#endif +default_parsefunc(cp_value *v, const String &arg, ErrorHandler *errh, const char *argname CP_CONTEXT_ARG) { const char *desc = v->description; @@ -2610,8 +2876,23 @@ return -1; } +#ifdef CLICK_SIM +namespace CLICKSIM { +static int +cp_va_parsev(const Vector &args, +#ifndef CLICK_TOOL + Element *context, +#endif + const char *argname, const char *separator, + bool keywords_only, + ErrorHandler *errh, va_list val); +} +#endif static int +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_va_parsev(const Vector &args, #ifndef CLICK_TOOL Element *context, @@ -2839,6 +3120,9 @@ } int +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_va_parse(const Vector &conf, #ifndef CLICK_TOOL Element *context, @@ -2857,6 +3141,9 @@ } int +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_va_parse(const String &confstr, #ifndef CLICK_TOOL Element *context, @@ -2877,6 +3164,9 @@ } int +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_va_space_parse(const String &argument, #ifndef CLICK_TOOL Element *context, @@ -2897,6 +3187,9 @@ } int +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_va_parse_keyword(const String &arg, #ifndef CLICK_TOOL Element *context, @@ -2917,6 +3210,9 @@ } int +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_va_parse_remove_keywords(Vector &conf, int first, #ifndef CLICK_TOOL Element *context, @@ -2957,6 +3253,9 @@ // UNPARSING String +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unparse_bool(bool b) { return String(b ? "true" : "false"); @@ -2965,6 +3264,9 @@ #ifdef HAVE_INT64_TYPES String +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unparse_unsigned64(uint64_t q, int base, bool uppercase) { // Unparse a uint64_t. Linux kernel sprintf can't handle %lld, so we provide @@ -3022,6 +3324,9 @@ } String +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unparse_integer64(int64_t q, int base, bool uppercase) { if (q < 0) @@ -3033,6 +3338,9 @@ #endif String +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unparse_real2(uint32_t real, int frac_bits) { // adopted from Knuth's TeX function print_scaled, hope it is correct in @@ -3093,6 +3401,9 @@ #endif String +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unparse_real2(int32_t real, int frac_bits) { if (real < 0) @@ -3103,6 +3414,9 @@ #ifdef HAVE_INT64_TYPES String +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unparse_real2(uint64_t real, int frac_bits) { assert(frac_bits <= CP_REAL2_MAX_FRAC_BITS); @@ -3112,6 +3426,9 @@ } String +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unparse_real2(int64_t real, int frac_bits) { if (real < 0) @@ -3122,6 +3439,9 @@ #endif String +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unparse_real10(uint32_t real, int frac_digits) { assert(frac_digits >= 0 && frac_digits <= 9); @@ -3147,6 +3467,9 @@ } String +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unparse_real10(int32_t real, int frac_digits) { if (real < 0) @@ -3156,6 +3479,9 @@ } String +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unparse_milliseconds(uint32_t ms) { if (ms && ms < 1000) @@ -3165,6 +3491,9 @@ } String +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unparse_microseconds(uint32_t us) { if (us && us < 1000) @@ -3174,6 +3503,9 @@ } String +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_unparse_interval(const struct timeval &tv) { if (!tv.tv_sec) @@ -3189,6 +3521,9 @@ // initialization and cleanup void +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_va_static_initialize() { assert(!cp_values); @@ -3261,6 +3596,9 @@ } void +#ifdef CLICK_SIM +CLICKSIM:: +#endif cp_va_static_cleanup() { for (int i = 0; i < NARGTYPE_HASH; i++) { diff -urN click-1.2.4.orig/lib/element.cc click-1.2.4/lib/element.cc --- click-1.2.4.orig/lib/element.cc Fri Apr 5 12:01:03 2002 +++ click-1.2.4/lib/element.cc Fri May 31 15:07:39 2002 @@ -36,6 +36,10 @@ # include #endif +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + const char * const Element::AGNOSTIC = "a"; const char * const Element::PUSH = "h"; const char * const Element::PULL = "l"; diff -urN click-1.2.4.orig/lib/elemfilter.cc click-1.2.4/lib/elemfilter.cc --- click-1.2.4.orig/lib/elemfilter.cc Fri Mar 29 12:26:51 2002 +++ click-1.2.4/lib/elemfilter.cc Fri May 31 23:04:12 2002 @@ -19,6 +19,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + void ElementFilter::filter(Vector &v) { diff -urN click-1.2.4.orig/lib/error.cc click-1.2.4/lib/error.cc --- click-1.2.4.orig/lib/error.cc Tue Apr 30 16:12:41 2002 +++ click-1.2.4/lib/error.cc Fri May 31 15:02:05 2002 @@ -25,6 +25,10 @@ #endif #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + const int ErrorHandler::OK_RESULT; const int ErrorHandler::ERROR_RESULT = -EINVAL; diff -urN click-1.2.4.orig/lib/etheraddress.cc click-1.2.4/lib/etheraddress.cc --- click-1.2.4.orig/lib/etheraddress.cc Sun Dec 2 11:46:20 2001 +++ click-1.2.4/lib/etheraddress.cc Mon Jun 3 20:23:29 2002 @@ -23,6 +23,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + EtherAddress::EtherAddress(const unsigned char *addr) { memcpy(data(), addr, 6); @@ -39,6 +43,9 @@ } StringAccum & +#ifdef CLICK_SIM +CLICKSIM:: +#endif operator<<(StringAccum &sa, const EtherAddress &ea) { char buf[24]; diff -urN click-1.2.4.orig/lib/gaprate.cc click-1.2.4/lib/gaprate.cc --- click-1.2.4.orig/lib/gaprate.cc Sun Dec 2 11:46:48 2001 +++ click-1.2.4/lib/gaprate.cc Fri May 31 15:06:21 2002 @@ -22,6 +22,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + void GapRate::set_rate(unsigned r, ErrorHandler *errh) { diff -urN click-1.2.4.orig/lib/glue.cc click-1.2.4/lib/glue.cc --- click-1.2.4.orig/lib/glue.cc Tue May 21 17:28:01 2002 +++ click-1.2.4/lib/glue.cc Mon Jun 3 20:11:10 2002 @@ -40,6 +40,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + void click_check_header_sizes() { @@ -81,6 +85,9 @@ } void +#ifdef CLICK_SIM +CLICKSIM:: +#endif click_chatter(const char *fmt, ...) { va_list val; @@ -421,6 +428,9 @@ #if defined(CLICK_USERLEVEL) unsigned +#ifdef CLICK_SIM +CLICKSIM:: +#endif click_jiffies() { struct timeval tv; @@ -431,6 +441,9 @@ #endif /* CLICK_USERLEVEL */ void +#ifdef CLICK_SIM +CLICKSIM:: +#endif click_random_srandom() { static const int bufsiz = 16; diff -urN click-1.2.4.orig/lib/handlercall.cc click-1.2.4/lib/handlercall.cc --- click-1.2.4.orig/lib/handlercall.cc Wed Apr 24 09:51:29 2002 +++ click-1.2.4/lib/handlercall.cc Sat Jun 1 00:01:16 2002 @@ -22,6 +22,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + const char * const HandlerCall::READ_MARKER = "r"; int diff -urN click-1.2.4.orig/lib/ip6address.cc click-1.2.4/lib/ip6address.cc --- click-1.2.4.orig/lib/ip6address.cc Thu Apr 4 16:20:22 2002 +++ click-1.2.4/lib/ip6address.cc Fri May 31 23:17:47 2002 @@ -25,6 +25,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + IP6Address::IP6Address() { static_assert(sizeof(struct click_ip6) == 40); diff -urN click-1.2.4.orig/lib/ip6table.cc click-1.2.4/lib/ip6table.cc --- click-1.2.4.orig/lib/ip6table.cc Thu Apr 4 16:21:26 2002 +++ click-1.2.4/lib/ip6table.cc Fri May 31 23:23:25 2002 @@ -20,6 +20,10 @@ #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + IP6Table::IP6Table() { } diff -urN click-1.2.4.orig/lib/ipaddress.cc click-1.2.4/lib/ipaddress.cc --- click-1.2.4.orig/lib/ipaddress.cc Sun Dec 2 11:47:49 2001 +++ click-1.2.4/lib/ipaddress.cc Mon Jun 3 20:23:04 2002 @@ -24,6 +24,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + IPAddress::IPAddress(const unsigned char *data) { #ifdef HAVE_INDIFFERENT_ALIGNMENT @@ -86,6 +90,9 @@ } StringAccum & +#ifdef CLICK_SIM +CLICKSIM:: +#endif operator<<(StringAccum &sa, IPAddress ipa) { const unsigned char *p = ipa.data(); diff -urN click-1.2.4.orig/lib/ipaddressset.cc click-1.2.4/lib/ipaddressset.cc --- click-1.2.4.orig/lib/ipaddressset.cc Sun Dec 2 11:48:24 2001 +++ click-1.2.4/lib/ipaddressset.cc Fri May 31 14:51:22 2002 @@ -22,6 +22,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + void IPAddressSet::insert(IPAddress ip) { diff -urN click-1.2.4.orig/lib/ipflowid.cc click-1.2.4/lib/ipflowid.cc --- click-1.2.4.orig/lib/ipflowid.cc Tue May 21 17:29:30 2002 +++ click-1.2.4/lib/ipflowid.cc Fri May 31 14:51:48 2002 @@ -25,6 +25,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + IPFlowID::IPFlowID(Packet *p) { const click_ip *iph = p->ip_header(); diff -urN click-1.2.4.orig/lib/iptable.cc click-1.2.4/lib/iptable.cc --- click-1.2.4.orig/lib/iptable.cc Thu Mar 28 21:45:30 2002 +++ click-1.2.4/lib/iptable.cc Fri May 31 23:13:26 2002 @@ -20,6 +20,10 @@ #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + IPTable::IPTable() { } diff -urN click-1.2.4.orig/lib/lexer.cc click-1.2.4/lib/lexer.cc --- click-1.2.4.orig/lib/lexer.cc Wed Apr 24 09:51:29 2002 +++ click-1.2.4/lib/lexer.cc Wed Jun 5 16:51:18 2002 @@ -28,6 +28,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + // // CLASS LEXER::TUNNELEND // @@ -532,7 +536,11 @@ for (pos++; pos < len && data[pos] != '\"' && data[pos] != '\n' && data[pos] != '\r'; pos++) if (data[pos] == '\\' && pos < len - 1 && data[pos+1] != '\n' && data[pos+1] != '\r') pos++; - _filename = cp_unquote(_big_string.substring(first_in_filename, pos - first_in_filename) + "\":"); + _filename = +#ifdef CLICK_SIM +CLICKSIM:: +#endif + cp_unquote(_big_string.substring(first_in_filename, pos - first_in_filename) + "\":"); // an empty filename means return to the input file's name if (_filename == ":") _filename = _original_filename; @@ -1017,7 +1025,11 @@ const Lexeme &tword = lex(); if (tword.is(lexIdent)) { +#ifdef CLICK_SIM + if (!CLICKSIM::cp_integer(tword.string(), &port)) { +#else if (!cp_integer(tword.string(), &port)) { +#endif lerror("syntax error: port number should be integer"); port = 0; } @@ -1361,13 +1373,23 @@ Vector args; String word; +#ifdef CLICK_SIM + CLICKSIM:: +#endif cp_argvec(requirement, args); for (int i = 0; i < args.size(); i++) { Vector words; +#ifdef CLICK_SIM + CLICKSIM:: +#endif cp_spacevec(args[i], words); if (words.size() == 0) /* do nothing */; +#ifdef CLICK_SIM + else if (!CLICKSIM::cp_word(words[0], &word)) +#else else if (!cp_word(words[0], &word)) +#endif lerror("bad requirement: not a word"); else if (words.size() > 1) lerror("bad requirement: too many words"); @@ -1470,6 +1492,9 @@ // find right version Vector args; +#ifdef CLICK_SIM + CLICKSIM:: +#endif cp_argvec(_element_configurations[which], args); int inputs_used = 0, outputs_used = 0; for (int i = 0; i < _hookup_from.size(); i++) { @@ -1510,12 +1535,21 @@ found_comp->expand_into(this, which, new_ve); } +#ifndef CLICK_SIM Router * Lexer::create_router() +#else +Router * +Lexer::create_router(simclick_sim siminst) +#endif { Router *router = new Router; if (!router) return 0; + +#ifdef CLICK_SIM + router->set_siminst(siminst); +#endif // expand compounds int initial_elements_size = _elements.size(); diff -urN click-1.2.4.orig/lib/notifier.cc click-1.2.4/lib/notifier.cc --- click-1.2.4.orig/lib/notifier.cc Fri Mar 29 12:50:47 2002 +++ click-1.2.4/lib/notifier.cc Sat Jun 1 00:02:22 2002 @@ -22,6 +22,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + #define NUM_SIGNALS 4096 static uint32_t signals[NUM_SIGNALS / 32]; diff -urN click-1.2.4.orig/lib/packageutils.cc click-1.2.4/lib/packageutils.cc --- click-1.2.4.orig/lib/packageutils.cc Mon Nov 5 10:11:43 2001 +++ click-1.2.4/lib/packageutils.cc Mon Jun 3 19:49:40 2002 @@ -44,7 +44,9 @@ // GENERIC PACKAGE SUPPORT - +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif struct ClickProvision { String name; bool loaded : 1; @@ -53,8 +55,25 @@ static int nprovisions; static int provisions_cap; static ClickProvision *provisions; +#ifdef CLICK_SIM +} +#endif -static ClickProvision * +#ifdef CLICK_SIM +namespace CLICKSIM { +static +ClickProvision *find_provision(const String &name); +} +#endif + +static +#ifdef CLICK_SIM +CLICKSIM:: +#endif +ClickProvision * +#ifdef CLICK_SIM +CLICKSIM:: +#endif find_provision(const String &name) { for (int i = 0; i < nprovisions; i++) @@ -83,6 +102,9 @@ extern "C" void +#ifdef CLICK_SIM +CLICKSIM:: +#endif click_provide(const char *package) { ClickProvision *p = find_provision(package); @@ -95,6 +117,9 @@ } extern "C" void +#ifdef CLICK_SIM +CLICKSIM:: +#endif click_unprovide(const char *package) { ClickProvision *p = find_provision(package); @@ -107,6 +132,9 @@ } extern "C" bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif click_has_provision(const char *package) { ClickProvision *p = find_provision(package); @@ -114,6 +142,9 @@ } extern "C" void +#ifdef CLICK_SIM +CLICKSIM:: +#endif click_public_packages(Vector &v) { for (int i = 0; i < nprovisions; i++) @@ -134,10 +165,26 @@ #if HAVE_DYNAMIC_LINKING && !defined(CLICK_LINUXMODULE) && !defined(CLICK_BSDMODULE) +#ifdef CLICK_SIM +namespace CLICKSIM { +#endif static String::Initializer crap_initializer; static String click_compile_prog, tmpdir; +#ifdef CLICK_SIM +} +#endif +#ifdef CLICK_SIM +namespace CLICKSIM { static int +archive_index(const Vector *archive, const String &what); +} +#endif + +static int +#ifdef CLICK_SIM +CLICKSIM:: +#endif archive_index(const Vector *archive, const String &what) { if (archive) @@ -147,7 +194,17 @@ return -1; } +#ifdef CLICK_SIM +namespace CLICKSIM { +static bool +check_tmpdir(const Vector *archive, ErrorHandler *errh); +} +#endif + static bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif check_tmpdir(const Vector *archive, ErrorHandler *errh) { // change to temporary directory @@ -180,7 +237,21 @@ return tmpdir; } +#ifdef CLICK_SIM +namespace CLICKSIM { static String +compile_archive_file(String package, const Vector *archive, int ai, ErrorHandler *errh); +} +#endif + +static +#ifdef CLICK_SIM +CLICKSIM:: +#endif +String +#ifdef CLICK_SIM +CLICKSIM:: +#endif compile_archive_file(String package, const Vector *archive, int ai, ErrorHandler *errh) { if (!check_tmpdir(archive, errh)) @@ -225,6 +296,9 @@ } void +#ifdef CLICK_SIM +CLICKSIM:: +#endif clickdl_load_requirement(String name, const Vector *archive, ErrorHandler *errh) { ClickProvision *p = find_provision(name); diff -urN click-1.2.4.orig/lib/packet.cc click-1.2.4/lib/packet.cc --- click-1.2.4.orig/lib/packet.cc Tue May 21 18:42:38 2002 +++ click-1.2.4/lib/packet.cc Fri May 31 13:07:17 2002 @@ -25,6 +25,10 @@ #include #endif +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + #ifdef CLICK_LINUXMODULE /* Linux kernel module */ Packet::Packet() @@ -69,6 +73,9 @@ #elif CLICK_BSDMODULE _m = 0; #endif +#ifdef CLICK_SIM + memset(&_sim_packetinfo,-1,sizeof(_sim_packetinfo)); +#endif clear_annotations(); } @@ -196,6 +203,9 @@ # else p->_m = 0; # endif +#ifdef CLICK_SIM + p->_sim_packetinfo = _sim_packetinfo; +#endif // increment our reference count because of _data_packet reference _use_count++; return p; diff -urN click-1.2.4.orig/lib/router.cc click-1.2.4/lib/router.cc --- click-1.2.4.orig/lib/router.cc Sat May 4 17:55:17 2002 +++ click-1.2.4/lib/router.cc Wed Jun 5 17:10:54 2002 @@ -34,6 +34,13 @@ #ifdef CLICK_USERLEVEL # include #endif +#ifdef CLICK_SIM +#include "../elements/simclick/fromsimdevice.hh" +#endif + +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif static Router::Handler *globalh; static int nglobalh; @@ -49,6 +56,13 @@ // RouterThreads will add themselves to _threads (void) new RouterThread(this); // quiescent thread (void) new RouterThread(this); // first normal thread + +#ifdef CLICK_SIM + clickinst_ = 0; + siminst_ = 0; + _timer_list.set_router(this); +#endif + } Router::~Router() @@ -220,7 +234,11 @@ void Router::add_requirement(const String &r) { +#ifdef CLICK_SIM + assert(CLICKSIM::cp_is_word(r)); +#else assert(cp_is_word(r)); +#endif _requirements.push_back(r); } @@ -921,6 +939,9 @@ ErrorHandler *errh1 = (verbose_errors ? &cerrh : errh); int before = errh1->nerrors(); conf.clear(); +#ifdef CLICK_SIM + CLICKSIM:: +#endif cp_argvec(_configurations[i], conf); if (_elements[i]->configure(conf, errh1) < 0) { element_ok[i] = all_ok = false; @@ -1382,6 +1403,7 @@ // SELECT +#ifndef CLICK_SIM #if CLICK_USERLEVEL int @@ -1441,7 +1463,7 @@ } #endif - +#endif #if CLICK_USERLEVEL @@ -1452,6 +1474,10 @@ // selected() methods. // Return early if there are no selectors and there are tasks to run. +#ifdef CLICK_SIM + // Click simulator layer doesn't do the wait on select thing. + return; +#else if (_selectors.size() == 0 && more_tasks) return; @@ -1479,6 +1505,7 @@ _elements[s.element]->selected(s.fd); } } +#endif } #endif @@ -1490,8 +1517,13 @@ Router::unparse_requirements(StringAccum &sa, const String &indent) const { // requirements - if (_requirements.size()) + if (_requirements.size()) { +#ifdef CLICK_SIM + sa << indent << "require(" << CLICKSIM::cp_unargvec(_requirements) << ");\n\n"; +#else sa << indent << "require(" << cp_unargvec(_requirements) << ");\n\n"; +#endif + } } void @@ -1675,6 +1707,68 @@ return sa.take_string(); } + +#ifdef CLICK_SIM + +void +Router::invalid_in_sim() +{ + fprintf(stderr,"Your simclick configuration has used an invalid router function\n"); + abort(); +} + +int +Router::sim_get_ifid(const char* ifname) { + return simclick_sim_ifid_from_name(siminst_,ifname); +} + +int +Router::sim_listen(int ifid,int element) { + int result = 0; + + // Got a vector for the ifid? Add the element to it + // if it isn't there already. + int n = ifidmap_[ifid].size(); + int i = 0; + for (i=0;i=n) { + //fprintf(stderr,"router %d element %d listening to ifid %d\n",(int)this,element,ifid); + ifidmap_[ifid].push_back(element); + } + return result; +} + +int +Router::sim_write(int ifid,int ptype,const unsigned char* data,int len, + simclick_simpacketinfo* pinfo) { + return simclick_sim_send_to_if(siminst_,clickinst_,ifid,ptype,data,len,pinfo); +} + +int +Router::sim_if_ready(int ifid) { + return simclick_sim_if_ready(siminst_,clickinst_,ifid); +} + +int +Router::sim_incoming_packet(int ifid,int ptype,const unsigned char* data, + int len,simclick_simpacketinfo* pinfo) { + int result = 0; + vector ifidlist = ifidmap_[ifid]; + int n = ifidlist.size(); + int i = 0; + for (i=0;iincoming_packet(ifid,ptype,data, + len,pinfo); + } + return result; +} +#endif // CLICK_SIM #if CLICK_USERLEVEL // Vector template instance diff -urN click-1.2.4.orig/lib/routerthread.cc click-1.2.4/lib/routerthread.cc --- click-1.2.4.orig/lib/routerthread.cc Wed Apr 24 10:04:35 2002 +++ click-1.2.4/lib/routerthread.cc Fri Jun 7 11:19:18 2002 @@ -32,15 +32,29 @@ #define DEBUG_RT_SCHED 0 +#ifndef CLICK_SIM #define DRIVER_TASKS_PER_ITER 128 +#else +#define DRIVER_TASKS_PER_ITER 256 +#endif + #define PROFILE_ELEMENT 20 +#ifndef CLICK_SIM #define DRIVER_ITER_ANY 32 #define DRIVER_ITER_TIMERS 32 +#else +#define DRIVER_ITER_ANY 1 +#define DRIVER_ITER_TIMERS 1 +#endif + #define DRIVER_ITER_SELECT 64 #define DRIVER_ITER_LINUXSCHED 256 #define DRIVER_ITER_BSDSCHED 256 +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif RouterThread::RouterThread(Router *r) : Task(Task::error_hook, 0), _router(r) @@ -147,8 +161,14 @@ iter++; if (iter % DRIVER_ITER_ANY == 0) wait(iter); + } +#ifdef CLICK_SIM + // The simulator layer should only go once around + break; +#endif + } while (_router->check_driver()); unlock_tasks(); @@ -204,7 +224,18 @@ iter++; if (iter % DRIVER_ITER_ANY == 0) wait(iter); + +#ifdef CLICK_SIM + // The simulator layer should only go once around + break; +#endif + } + +#ifdef CLICK_SIM + // The simulator layer should only go once around + break; +#endif } while (_router->check_driver()); diff -urN click-1.2.4.orig/lib/straccum.cc click-1.2.4/lib/straccum.cc --- click-1.2.4.orig/lib/straccum.cc Thu Feb 7 17:58:56 2002 +++ click-1.2.4/lib/straccum.cc Mon Jun 3 20:21:05 2002 @@ -24,6 +24,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + void StringAccum::make_out_of_memory() { @@ -81,6 +85,9 @@ } StringAccum & +#ifdef CLICK_SIM +CLICKSIM:: +#endif operator<<(StringAccum &sa, long i) { if (char *x = sa.reserve(24)) { @@ -91,6 +98,9 @@ } StringAccum & +#ifdef CLICK_SIM +CLICKSIM:: +#endif operator<<(StringAccum &sa, unsigned long u) { if (char *x = sa.reserve(24)) { @@ -102,6 +112,9 @@ #ifdef HAVE_INT64_TYPES StringAccum & +#ifdef CLICK_SIM +CLICKSIM:: +#endif operator<<(StringAccum &sa, int64_t q) { String qstr = cp_unparse_integer64(q, 10, false); @@ -109,6 +122,9 @@ } StringAccum & +#ifdef CLICK_SIM +CLICKSIM:: +#endif operator<<(StringAccum &sa, uint64_t q) { String qstr = cp_unparse_unsigned64(q, 10, false); @@ -118,6 +134,9 @@ #if defined(CLICK_USERLEVEL) || defined(CLICK_TOOL) StringAccum & +#ifdef CLICK_SIM +CLICKSIM:: +#endif operator<<(StringAccum &sa, double d) { if (char *x = sa.reserve(256)) { @@ -129,6 +148,9 @@ #endif StringAccum & +#ifdef CLICK_SIM +CLICKSIM:: +#endif operator<<(StringAccum &sa, const struct timeval &tv) { if (char *x = sa.reserve(30)) { diff -urN click-1.2.4.orig/lib/string.cc click-1.2.4/lib/string.cc --- click-1.2.4.orig/lib/string.cc Tue Apr 30 16:13:30 2002 +++ click-1.2.4/lib/string.cc Mon Jun 3 20:22:27 2002 @@ -22,6 +22,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + String::Memo *String::null_memo = 0; String::Memo *String::permanent_memo = 0; String::Memo *String::oom_memo = 0; @@ -516,6 +520,9 @@ } int +#ifdef CLICK_SIM +CLICKSIM:: +#endif hashcode(const String &s) { int length = s.length(); diff -urN click-1.2.4.orig/lib/task.cc click-1.2.4/lib/task.cc --- click-1.2.4.orig/lib/task.cc Fri Apr 5 11:04:39 2002 +++ click-1.2.4/lib/task.cc Fri May 31 15:03:18 2002 @@ -22,6 +22,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + void Task::error_hook(Task *, void *) { diff -urN click-1.2.4.orig/lib/templatei.cc click-1.2.4/lib/templatei.cc --- click-1.2.4.orig/lib/templatei.cc Thu May 24 18:04:16 2001 +++ click-1.2.4/lib/templatei.cc Wed Jun 5 17:06:54 2002 @@ -23,6 +23,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + #include template class Vector; template class Vector; diff -urN click-1.2.4.orig/lib/timer.cc click-1.2.4/lib/timer.cc --- click-1.2.4.orig/lib/timer.cc Mon Feb 11 23:13:08 2002 +++ click-1.2.4/lib/timer.cc Wed Jun 5 17:05:35 2002 @@ -20,10 +20,19 @@ #include #include +#ifdef CLICK_SIM +#include +#include +#include +#endif #include #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + /* * element_hook is a callback that gets called when a Timer, * constructed with just an Element instance, expires. @@ -109,7 +118,11 @@ _next = trav; _prev->_next = this; trav->_prev = this; - +#ifdef CLICK_SIM + // Make sure the simulator runs us when we need it. + // XXX are "duplicate" events at the same time acceptable? + simclick_sim_schedule(_sr->get_siminst(),_sr->get_clickinst(),&_expires); +#endif // done _head->release_lock(); } diff -urN click-1.2.4.orig/lib/userutils.cc click-1.2.4/lib/userutils.cc --- click-1.2.4.orig/lib/userutils.cc Thu May 2 21:52:01 2002 +++ click-1.2.4/lib/userutils.cc Mon Jun 3 20:24:02 2002 @@ -38,8 +38,14 @@ # include #endif +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif glob_match(const String &str, const String &pattern) { const char *sdata = str.data(); @@ -130,6 +136,9 @@ } String +#ifdef CLICK_SIM +CLICKSIM:: +#endif percent_substitute(const String &pattern, int format1, ...) { const char *results[256]; @@ -169,6 +178,9 @@ } int +#ifdef CLICK_SIM +CLICKSIM:: +#endif click_strcmp(const String &a, const String &b) { const char *ad = a.data(), *ae = a.data() + a.length(); @@ -223,6 +235,9 @@ } String +#ifdef CLICK_SIM +CLICKSIM:: +#endif file_string(FILE *f, ErrorHandler *errh) { StringAccum sa; @@ -239,6 +254,9 @@ } String +#ifdef CLICK_SIM +CLICKSIM:: +#endif file_string(const char *filename, ErrorHandler *errh) { FILE *f; @@ -268,6 +286,9 @@ String +#ifdef CLICK_SIM +CLICKSIM:: +#endif unique_tmpnam(const String &pattern, ErrorHandler *errh) { String tmpdir; @@ -346,6 +367,9 @@ } void +#ifdef CLICK_SIM +CLICKSIM:: +#endif remove_file_on_exit(const String &file) { if (file) { @@ -402,6 +426,9 @@ static const char *the_clickpath = 0; const char * +#ifdef CLICK_SIM +CLICKSIM:: +#endif clickpath() { if (!the_clickpath) { @@ -413,6 +440,9 @@ } void +#ifdef CLICK_SIM +CLICKSIM:: +#endif set_clickpath(const char *p) { the_clickpath = p; @@ -420,6 +450,9 @@ String +#ifdef CLICK_SIM +CLICKSIM:: +#endif clickpath_find_file(const String &filename, const char *subdir, String default_path, ErrorHandler *errh) { @@ -455,6 +488,9 @@ } bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif path_allows_default_path(String path) { while (1) { @@ -469,6 +505,9 @@ } String +#ifdef CLICK_SIM +CLICKSIM:: +#endif click_mktmpdir(ErrorHandler *errh) { String tmpdir; @@ -499,6 +538,9 @@ } void +#ifdef CLICK_SIM +CLICKSIM:: +#endif parse_tabbed_lines(const String &str, Vector *fields1, ...) { va_list val; @@ -540,6 +582,9 @@ } ArchiveElement +#ifdef CLICK_SIM +CLICKSIM:: +#endif init_archive_element(const String &name, int mode) { ArchiveElement ae; @@ -554,6 +599,9 @@ bool +#ifdef CLICK_SIM +CLICKSIM:: +#endif compressed_data(const unsigned char *buf, int len) { return (len >= 3 @@ -563,6 +611,9 @@ } FILE * +#ifdef CLICK_SIM +CLICKSIM:: +#endif open_uncompress_pipe(const String &filename, const unsigned char *buf, int, ErrorHandler *errh) { String command; @@ -588,6 +639,9 @@ } int +#ifdef CLICK_SIM +CLICKSIM:: +#endif clickdl_load_package(String package, ErrorHandler *errh) { #ifndef RTLD_NOW diff -urN click-1.2.4.orig/lib/variableenv.cc click-1.2.4/lib/variableenv.cc --- click-1.2.4.orig/lib/variableenv.cc Sun Dec 2 11:50:32 2001 +++ click-1.2.4/lib/variableenv.cc Fri May 31 22:16:38 2002 @@ -22,6 +22,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + VariableEnvironment::VariableEnvironment(const String &prefix) : _prefix(prefix) { diff -urN click-1.2.4.orig/lib/vectorv.cc click-1.2.4/lib/vectorv.cc --- click-1.2.4.orig/lib/vectorv.cc Thu May 24 18:04:18 2001 +++ click-1.2.4/lib/vectorv.cc Sat Jun 1 10:29:08 2002 @@ -21,6 +21,10 @@ #include #include +#ifdef CLICK_SIM +using namespace CLICKSIM; +#endif + Vector::Vector(const Vector &o) : _l(0), _n(0), _cap(0) { diff -urN click-1.2.4.orig/simclick/CUT_BinHeap.h click-1.2.4/simclick/CUT_BinHeap.h --- click-1.2.4.orig/simclick/CUT_BinHeap.h Wed Dec 31 17:00:00 1969 +++ click-1.2.4/simclick/CUT_BinHeap.h Fri May 31 12:33:41 2002 @@ -0,0 +1,510 @@ +//-*-c++-*- +#ifndef _CUT_BinHeap_h_ +#define _CUT_BinHeap_h_ + + +#include + +// #define CHECK_BinHeap_INVARIANTS + +template +class CUT_BinHeap +{ +public: + typedef void *Pix; + protected: + /////////////////////////////////////////////////////////////////////////// + // Beginning of Node class + /////////////////////////////////////////////////////////////////////////// + + class Node { + public: + Node* next; // used to link all used items + Node* prev; + Node* parent; + Node* kid1; // a child + Node* kid2; // a child + + Key key; + Data data; + + void init(Key k, Data d) { + key = k; data = d; + parent = NULL; + kid1 = NULL; + kid2 = NULL; + next = NULL; + prev = NULL; + } +}; + + /////////////////////////////////////////////////////////////////////////// + // End of Node class + /////////////////////////////////////////////////////////////////////////// + + Node* get_node(Key k, Data d) { + // + // Get new node from freelist + // + Node *n; + if ( free_list ) { + n = free_list; + free_list = free_list -> next; + if ( free_list ) { + free_list -> prev = NULL; + } + } else { + n = new Node; + } + + n -> init(k, d); + + // + // Link into node list + // + n -> next = node_list; + n -> prev = NULL; + if ( node_list ) { + node_list -> prev = n; + } + node_list = n; + return n; + } + + void put_node(Node *n) { + // + // Remove from node list + // + if ( n -> prev == NULL ) { + assert(n == node_list); + node_list = n -> next; + } else { + n -> prev -> next = n -> next; + } + if ( n -> next != NULL ) { + n -> next -> prev = n -> prev; + } + // + // Now, link into the free list + // + n -> next = free_list; + n -> prev = NULL; + free_list = n; + } + + +public: + + // + // Iterator functions, used in other functions. We can't let the + // user change the key, but we can let them change the data. + // + + const Key& key(Pix xx) const { + Node* x = (Node *) xx; + return x->key; + } + + Data& data(Pix xx) const { + Node* x = (Node *) xx; + return x->data; + } + + Data& operator()(Pix xx) const { + Node* x = (Node *) xx; + return x->data; + } + + Pix first() const { +#ifdef CHECK_BinHeap_INVARIANTS + if ( node_list ) { + assert(node_list -> prev == NULL); + } +#endif + return (Pix) node_list; + } + + int tree_height() { + return tree_height(root); + } + + void invariant() { +#ifdef CHECK_BinHeap_INVARIANTS + assert(heap_property(root) == true ); + parent_property(root); +#endif + } + + // + // Access next item in the iterator + // + void next(Pix& pp) { + Node* p = (Node *) pp; + assert(p != NULL); + pp = (Pix) p -> next; + } + + // + // Clean out the entire BinHeap + // + void clear() { + // + // Clear out BinHeap.. + // + for (Node *FF = node_list; FF != NULL; ) { + Node *NN = FF -> next; + delete FF; + FF = NN; + } + // + // Clear out free list + // + for (Node *GG = free_list; GG != NULL; ) { + Node *NN = GG -> next; + delete GG; + GG = NN; + } + + node_count = 0; + node_list = NULL; + free_list = NULL; + root = NULL; + } + + int size() { + return node_count; + } + + ///////////////////////////////////////////////////////////////////////////// + // Constructors/Destructors + ///////////////////////////////////////////////////////////////////////////// + + CUT_BinHeap() { + node_count = 0; + root = NULL; + node_list = NULL; + free_list = NULL; + } + + ~CUT_BinHeap() { + clear(); + } + + ///////////////////////////////////////////////////////////////////////////// + // Insertion/deletion + ///////////////////////////////////////////////////////////////////////////// + Pix insert(Key k, Data d) { + invariant(); + Node *n = get_node(k,d); + node_count++; + + if ( root == NULL ) { + n -> parent = NULL; + root = n; + } else { + if (compare(root -> key, n -> key)) { + // root < n + hang_under(root,n); + } else { + // n < root + hang_under(n,root); + root = n; + n -> parent = NULL; + } + } + invariant(); + return ( (Pix) n ); + } + + // + // Remove an arbitrary node in the heap + // + void erase(Pix ref) { + invariant(); + + Node *n = (Node*) ref; + if ( n == root ) { + root = remove_node(root); + } else { + Node *p = n -> parent; + assert(p != NULL); + assert(n == p -> kid1 || n == p -> kid2); + // + // Determine which kid we were.. + // + if ( n == p -> kid1 ) { + p -> kid1 = remove_node(p -> kid1); + } else { + p -> kid2 = remove_node(p -> kid2); + } +#ifdef CHECK_BinHeap_INVARIANTS + assert(p -> kid1 == NULL || p -> kid1 -> parent == p ); + assert(p -> kid2 == NULL || p -> kid2 -> parent == p ); +#endif + } + // + // Recover storage + // + put_node(n); + node_count--; + + invariant(); + } + + void deq() { + erase(root); + } + + Pix find_top() const { + return((Pix) root); + } + + Data& top() const { +#ifdef CHECK_BinHeap_INVARIANTS + assert( root != NULL ); +#endif + return root -> data; + } + + bool empty() const { + if ( node_count == 0 ) { +#ifdef CHECK_BinHeap_INVARIANTS + assert( root == NULL ); +#endif + return true; + } else { +#ifdef CHECK_BinHeap_INVARIANTS + assert( root != NULL ); +#endif + return false; + } + } + // + // Internal functions + // + protected: + + // + // Does the node have the heap property? + // + bool heap_property(Node *n) { + if (n == NULL) { + return true; + } else { + // + // Check parent connectivity + // + if (n -> kid1 == NULL && n -> kid2 == NULL) { + return true; + } else { + bool cmp1 = true; + bool cmp2 = true; + if ( n -> kid1 != NULL ) { + cmp1 = !compare(n -> kid1 -> key, n -> key); + } + if ( n -> kid2 != NULL ) { + cmp2 = !compare(n -> kid2 -> key, n -> key); + } + return cmp1 & cmp2; + } + } + } + + // + // Assert that the parent links are maintained + // + void parent_property(Node *n) { + if (n == NULL) { + return; + } else { + // + // Check parent connectivity + // + if ( n == root ) { + assert(n -> parent == NULL); + } else { + assert(n -> parent != NULL); + } + parent_property(n -> kid1); + parent_property(n -> kid2); + } + } + + // + // Returns the height of the heap + // + int tree_height(Node* n) { + if ( n == NULL ) { + return 0; + } else { + int cnt1 = tree_height(n -> kid1); + int cnt2 = tree_height(n -> kid2); + if (cnt1 < cnt2) { + return cnt2+1; + } else { + return cnt1+1; + } + } + } + + // + // Remove a Node and return the replacement Node for this. This is + // either used to dequeue the root not *or* to remove a Node in the + // middle of the heap. + // + Node* remove_node(Node* here) { +#ifdef CHECK_BinHeap_INVARIANTS + assert(here!= NULL); +#endif + + Node *kid1 = here -> kid1; + Node *kid2 = here -> kid2; + + if ( kid1 == NULL & kid2 == NULL ) { + return NULL; + }else if ( kid1 == NULL & kid2 != NULL ) { + kid2 -> parent = here -> parent; + return kid2; + } else if (kid1 != NULL && kid2 == NULL) { + kid1 -> parent = here -> parent; + return kid1; + } else { + // + // Both kids are non-null. Hang the greater + // over the lessor + // + if (compare(kid1->key, kid2->key)) { + // kid1 < kid2, hang kid2 under kid1 + hang_under(kid1, kid2); + kid1 -> parent = here -> parent; + return kid1; + } else { + hang_under(kid2, kid1); + kid2 -> parent = here -> parent; + return kid2; + } + } + } + + // + // Hang Node y under Node x + // + void hang_under(Node *x, Node* y) { + for(;;) { +#ifdef CHECK_BinHeap_INVARIANTS + assert(x != NULL); + assert(y != NULL); + assert( !compare(y -> key, x -> key) ); + + assert(heap_property(x)); + assert(heap_property(y)); +#endif + + Node *kid1 = x -> kid1; + Node *kid2 = x -> kid2; + + if ( kid1 == NULL & kid2 == NULL ) { + // + // Both null. Hang based on tree size + // + if (node_count & 0x1) { + x -> kid1 = y; + y -> parent = x; + } else { + x -> kid2 = y; + y -> parent = x; + } + return; + } else if (kid1 == NULL) { + x -> kid1 = y; + y -> parent = x; + return; + } else if (x -> kid2 == NULL ){ + x -> kid2 = y; + y -> parent = x; + return; + } else { + // + // Neither is null + // + bool cmp_kid1 = compare(kid1 -> key, y -> key); + bool cmp_kid2 = compare(kid2 -> key, y -> key); + + if( cmp_kid1 & cmp_kid2) { + // + // The new node could be placed under either + // kid. Pick on based on the number of nodes + // in the tree. + // + if (node_count & 0x1) { + // + // Set up for un-wound tail-recursive call. + // + x = kid1; + y = y; + } else { + // + // Recursive call + // + x = kid2; + y = y; + } + } else if ( cmp_kid1 ){ + // kid1 < y + // + // Recursive call + // + x = kid1; + y = y; + } else if (cmp_kid2){ + // kid2 < y + // + // Recursive call + // + x = kid2; + y = y; + } else { + // + // The new node is smaller than either + // node. We could hang either one under + // the new node. Choose one based on the + // number of nodes in the tree + // + if (node_count & 0x1) { + // y < kid1 - swap, and hang + x -> kid1 = y; + y -> parent = x; + kid1 -> parent = NULL; + // + // Recursive call + // + x = y; + y = kid1; + } else { + // y < kid2 - swap, and hang + x -> kid2 = y; + y -> parent = x; + kid2 -> parent = NULL; + // + // Recursive call + // + x = y; + y = kid2; + } + } + } + } + } + +private: + Compare compare; + int node_count; // number of Nodes + + // Root of binary tree + Node *root; + Node* node_list; // List of all Nodes (for iteration) + Node* free_list; // free list of Nodes; + +}; + +#endif diff -urN click-1.2.4.orig/simclick/Makefile.in click-1.2.4/simclick/Makefile.in --- click-1.2.4.orig/simclick/Makefile.in Wed Dec 31 17:00:00 1969 +++ click-1.2.4/simclick/Makefile.in Wed Jun 5 16:18:55 2002 @@ -0,0 +1,111 @@ +SHELL = @SHELL@ + +srcdir := @srcdir@ +top_srcdir := @top_srcdir@ +top_builddir := .. +subdir := simclick + +prefix = @prefix@ +exec_prefix = @exec_prefix@ +bindir = @bindir@ +sbindir = @sbindir@ +libdir = @libdir@ + +VPATH = .:$(top_srcdir)/lib:$(top_srcdir)/$(subdir):$(top_srcdir)/elements/simclick@elements_vpath@ + +CC = @CC@ +CPP = @CPP@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +AR = ar +RANLIB = @RANLIB@ +INSTALL = @INSTALL@ +mkinstalldirs = @top_srcdir@/mkinstalldirs + +.SUFFIXES: +.SUFFIXES: .S .c .cc .o .s .ii + +.c.o: + $(COMPILE) -c $< +.s.o: + $(COMPILE) -c $< +.S.o: + $(COMPILE) -c $< +.cc.o: + $(CXXCOMPILE) -c $< +.cc.ii: + $(CXXCOMPILE) -E $< > $@ + + +GENERIC_OBJS = string.o straccum.o \ + bitvector.o vectorv.o templatei.o bighashmap_arena.o \ + ipaddress.o ip6address.o ipaddressset.o ipflowid.o etheraddress.o \ + packet.o \ + error.o glue.o task.o timer.o atomic.o gaprate.o \ + element.o routerthread.o \ + confparse.o variableenv.o lexer.o archive.o elemfilter.o router.o \ + packageutils.o crc32.o in_cksum.o iptable.o ip6table.o \ + userutils.o handlercall.o notifier.o integers.o crc32.o \ + in_cksum.o + +-include elements.mk + +LIBOBJS = $(GENERIC_OBJS) \ + addressinfo.o alignmentinfo.o errorelement.o scheduleinfo.o clp.o \ + $(ELEMENT_OBJS) simclick.o elements.o +OBJS = $(ELEMENT_OBJS) + +CPPFLAGS = @CPPFLAGS@ -MD -DCLICK_USERLEVEL -DCLICK_SIM +CFLAGS = @CFLAGS@ +CXXFLAGS = @CXXFLAGS@ + +DEFS = @DEFS@ -DCLICK_BINDIR='"$(bindir)"' -DCLICK_LIBDIR='"$(libdir)"' -DHAVE_IP6 +INCLUDES = -I$(top_builddir) -I$(top_builddir)/include -I$(srcdir) \ + -I$(top_srcdir) -I$(top_srcdir)/include +LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ `$(top_builddir)/click-compile --libs` + +CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(CXXLD) $(CXXFLAGS) $(LDFLAGS) -o $@ +COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(CCLD) $(CFLAGS) $(LDFLAGS) -o $@ + +all: libsimclick.a + +libsimclick.a: Makefile $(LIBOBJS) + $(AR) cru libsimclick.a $(LIBOBJS) + $(RANLIB) libsimclick.a + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status + +elemlist: + @/bin/rm -f elements.conf + @$(MAKE) elements.conf +elements.conf: $(top_builddir)/config.status $(top_srcdir)/click-buildtool + echo "simclick@element_groups@" | (cd $(top_srcdir); ./click-buildtool findelem) > elements.conf +elements.mk: elements.conf $(top_srcdir)/click-buildtool + (cd $(top_srcdir); ./click-buildtool elem2make -x addressinfo.o -x alignmentinfo.o -x errorelement.o -x scheduleinfo.o) < elements.conf > elements.mk +elements.cc: elements.conf $(top_srcdir)/click-buildtool + (cd $(top_srcdir); ./click-buildtool elem2export) < elements.conf > elements.cc + @rm -f elements.d + +DEPFILES := $(wildcard *.d) +ifneq ($(DEPFILES),) +include $(DEPFILES) +endif + +install: libsimclick.a + $(mkinstalldirs) $(libdir) + $(INSTALL) libsimclick.a $(libdir)/libsimclick.a +install-man: + +clean: + rm -f *.d *.o elements.mk elements.cc elements.conf libsimclick.a +distclean: clean + -rm -f Makefile + +.PHONY: all clean distclean elemlist install install-man diff -urN click-1.2.4.orig/simclick/config.h.in click-1.2.4/simclick/config.h.in --- click-1.2.4.orig/simclick/config.h.in Wed Dec 31 17:00:00 1969 +++ click-1.2.4/simclick/config.h.in Fri May 31 15:03:33 2002 @@ -0,0 +1 @@ +/* config.h.in. Generated automatically from configure.in by autoheader. */ diff -urN click-1.2.4.orig/simclick/simclick.cc click-1.2.4/simclick/simclick.cc --- click-1.2.4.orig/simclick/simclick.cc Wed Dec 31 17:00:00 1969 +++ click-1.2.4/simclick/simclick.cc Wed Jun 5 17:31:19 2002 @@ -0,0 +1,433 @@ +/* + * click.cc -- user-level Click main program + * Eddie Kohler + * + * Copyright (c) 1999-2000 Massachusetts Institute of Technology + * Copyright (c) 2000 Mazu Networks, Inc. + * Copyright (c) 2001 International Computer Science Institute + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, subject to the conditions + * listed in the Click LICENSE file. These conditions include: you must + * preserve this copyright notice, and you cannot mention the copyright + * holders in advertising related to the Software without their permission. + * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This + * notice is a summary of the Click LICENSE file; the license in that file is + * legally binding. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "elements/standard/quitwatcher.hh" +#include "elements/userlevel/controlsocket.hh" + +using namespace CLICKSIM; + +#define HELP_OPT 300 +#define VERSION_OPT 301 +#define CLICKPATH_OPT 302 +#define ROUTER_OPT 303 +#define QUIT_OPT 304 +#define OUTPUT_OPT 305 +#define HANDLER_OPT 306 +#define TIME_OPT 307 +#define STOP_OPT 308 +#define PORT_OPT 309 +#define UNIX_SOCKET_OPT 310 +#define NO_WARNINGS_OPT 311 +#define WARNINGS_OPT 312 +#define EXPRESSION_OPT 313 + + +// +// State for each simulated machine +// + +class SimState { +public: + Router *router; + + //String::Initializer crap_initializer; + //Vector packages; + //String configuration_string; + //Vector handlers; + + SimState() { + router = NULL; + } + + static SimState* simmain(simclick_sim siminst,const char* router_file); + static bool didinit_; +}; + +bool SimState::didinit_ = false; + +static simclick_simstate* cursimclickstate = NULL; + +// +// XXX +// OK, this bit of code here should work fine as long as your simulator +// isn't multithreaded. If it is, there could be multiple threads stomping +// on each other and potentially causing subtle or unsubtle problems. +// +static void setsimstate(simclick_simstate* newstate) { + cursimclickstate = newstate; +} + +static simclick_simstate* getsimstate() { + return cursimclickstate; +} + +static Router *router; +static ErrorHandler *errh; +static bool started = 0; + +// functions for packages + +static String::Initializer crap_initializer; +static String configuration_string; + +extern "C" int +CLICKSIM::click_add_element_type(const char *ename, Element *e) +{ + //return lexer->add_element_type(ename, e); + fprintf(stderr,"Hey! Need to do click_add_element_type!\n"); + return 0; +} + +extern "C" void +click_remove_element_type(int which) +{ + //lexer->remove_element_type(which); + fprintf(stderr,"Hey! Need to do click_remove_element_type!\n"); +} + + +// global handlers for ControlSocket + +enum { + GH_VERSION, GH_LIST, GH_CLASSES, GH_CONFIG, + GH_FLATCONFIG, GH_PACKAGES, GH_REQUIREMENTS +}; + +namespace CLICKSIM { +String read_global_handler(Element *, void *thunk); +} + +String +CLICKSIM::read_global_handler(Element *, void *thunk) +{ + return "Error - read handler not implemented in SimClick"; +#if 0 + StringAccum sa; + + switch (reinterpret_cast(thunk)) { + + case GH_VERSION: + return String(CLICK_VERSION "\n"); + + case GH_LIST: + return router->element_list_string(); + + case GH_CLASSES: { + Vector v; + lexer->element_type_names(v); + for (int i = 0; i < v.size(); i++) + sa << v[i] << "\n"; + return sa.take_string(); + } + + case GH_CONFIG: + return configuration_string; + + case GH_FLATCONFIG: + return router->flat_configuration_string(); + + case GH_PACKAGES: { + Vector p; + click_public_packages(p); + for (int i = 0; i < p.size(); i++) + sa << p[i] << "\n"; + return sa.take_string(); + } + + case GH_REQUIREMENTS: { + const Vector &v = router->requirements(); + for (int i = 0; i < v.size(); i++) + sa << v[i] << "\n"; + return sa.take_string(); + } + + default: + return "\n"; + + } +#endif +} + +namespace CLICKSIM { +int +stop_global_handler(const String &s, Element *, void *, ErrorHandler *); +} + +int +CLICKSIM:: +stop_global_handler(const String &s, Element *, void *, ErrorHandler *) +{ + int n = 1; + (void) cp_integer(cp_uncomment(s), &n); + router->adjust_driver_reservations(-n); + return 0; +} + + +// report handler results + +namespace CLICKSIM { +static int +call_read_handler(Element *e, String handler_name, Router *r, + bool print_name, ErrorHandler *errh); +} + +static int +CLICKSIM:: +call_read_handler(Element *e, String handler_name, Router *r, + bool print_name, ErrorHandler *errh) +{ + int hi = r->find_handler(e, handler_name); + if (hi < 0) + return errh->error("no `%s' handler", Router::Handler::unparse_name(e, handler_name).cc()); + + const Router::Handler &rh = r->handler(hi); + String full_name = rh.unparse_name(e); + + if (!rh.visible()) + return errh->error("no `%s' handler", full_name.cc()); + else if (!rh.read_visible()) + return errh->error("`%s' is a write handler", full_name.cc()); + String result = rh.call_read(e); + + if (print_name) + fprintf(stdout, "%s:\n", full_name.cc()); + fputs(result.cc(), stdout); + if (print_name) + fputs("\n", stdout); + + return 0; +} + +namespace CLICKSIM { +static bool +expand_handler_elements(const String &pattern, const String &handler_name, + Vector &elements, Router *router); +} + +static bool +CLICKSIM:: +expand_handler_elements(const String &pattern, const String &handler_name, + Vector &elements, Router *router) +{ + int nelem = router->nelements(); + bool any_elements = false; + for (int i = 0; i < nelem; i++) { + const String &id = router->ename(i); + if (glob_match(id, pattern)) { + any_elements = true; + Element *e = router->element(i); + int hi = router->find_handler(e, handler_name); + if (hi >= 0 && router->handler(hi).read_visible()) + elements.push_back(e); + } + } + return any_elements; +} + +namespace CLICKSIM { +static int +call_read_handlers(Vector &handlers, ErrorHandler *errh); +} + +static int +CLICKSIM:: +call_read_handlers(Vector &handlers, ErrorHandler *errh) +{ + Vector handler_elements; + Vector handler_names; + bool print_names = (handlers.size() > 1); + int before = errh->nerrors(); + + // expand handler names + for (int i = 0; i < handlers.size(); i++) { + int dot = handlers[i].find_left('.'); + if (dot < 0) { + call_read_handler(0, handlers[i], router, print_names, errh); + continue; + } + + String element_name = handlers[i].substring(0, dot); + String handler_name = handlers[i].substring(dot + 1); + + Vector elements; + if (Element *e = router->find(element_name)) + elements.push_back(e); + else if (expand_handler_elements(element_name, handler_name, elements, router)) + print_names = true; + else + errh->error("no element matching `%s'", element_name.cc()); + + for (int j = 0; j < elements.size(); j++) + call_read_handler(elements[j], handler_name, router, print_names, errh); + } + + return (errh->nerrors() == before ? 0 : -1); +} + + +// include requirements + +class RequireLexerExtra : public LexerExtra { public: + + RequireLexerExtra() { } + + void require(String, ErrorHandler *); + +}; + +void +RequireLexerExtra::require(String name, ErrorHandler *errh) +{ + if (!click_has_provision(name)) + errh->error("requirement `%s' not available", name.cc()); +} + + +// main + +extern void export_elements(Lexer *); + +SimState* +SimState::simmain(simclick_sim siminst,const char *router_file) +{ + if (!didinit_) { + String::static_initialize(); + cp_va_static_initialize(); + errh = new FileErrorHandler(stderr, ""); + ErrorHandler::static_initialize(errh); + + CLICK_DEFAULT_PROVIDES; + + didinit_ = true; + } + + + bool quit_immediately = false; + bool report_time = false; + bool stop = false; + bool stop_guess = false; + bool warnings = true; + Vector handlers; + Vector stops; + + String config_str = file_string(router_file, errh); + SimState* newstate = new SimState(); + + // prepare lexer (for packages) + Lexer* lexer = new Lexer(errh); + export_elements(lexer); + + // lex + RequireLexerExtra lextra; + int cookie = lexer->begin_parse(config_str, router_file, &lextra); + while (lexer->ystatement()) + /* do nothing */; + newstate->router = lexer->create_router(newstate); + newstate->router->set_clickinst((simclick_click)newstate); + newstate->router->set_siminst(siminst); + lexer->end_parse(cookie); + + if (newstate->router->nelements() == 0 && warnings) + errh->warning("%s: configuration has no elements", router_file); + + if (errh->nerrors() > 0 || newstate->router->initialize(errh) < 0) + exit(1); + + // + // XXX memory leak - see if the lexers can be deleted + //delete lexer; + + return newstate; +} + + +simclick_click simclick_click_create(simclick_sim siminst, + const char* router_file, + simclick_simstate* startstate) { + setsimstate(startstate); + return SimState::simmain(siminst,router_file); +} + +/* + * XXX Need to actually implement this a little more intelligenetly... + */ +void simclick_click_run(simclick_click clickinst,simclick_simstate* state) { + setsimstate(state); + //fprintf(stderr,"Hey! Need to implement simclick_click_run!\n"); + // not right - mostly smoke testing for now... + ((SimState*)clickinst)->router->thread(0)->driver(); +} + +void simclick_click_kill(simclick_click clickinst,simclick_simstate* state) { + fprintf(stderr,"Hey! Need to implement simclick_click_kill!\n"); + setsimstate(state); +} + +int simclick_gettimeofday(struct timeval* tv) { + simclick_simstate* sstate = getsimstate(); + if (sstate) { + *tv = sstate->curtime; + } + else { + fprintf(stderr,"Hey! Called simclick_gettimeofday without simstate set!\n"); + } + return 0; +} + +int simclick_click_send(simclick_click clickinst,simclick_simstate* state, + int ifid,int type,const unsigned char* data,int len, + simclick_simpacketinfo* pinfo) { + setsimstate(state); + int result = 0; + + ((SimState*)clickinst)->router->sim_incoming_packet(ifid,type,data,len,pinfo); + ((SimState*)clickinst)->router->thread(0)->driver(); + return result; +} + diff -urN click-1.2.4.orig/simclick/simclicktest.cc click-1.2.4/simclick/simclicktest.cc --- click-1.2.4.orig/simclick/simclicktest.cc Wed Dec 31 17:00:00 1969 +++ click-1.2.4/simclick/simclicktest.cc Wed Jun 5 10:53:31 2002 @@ -0,0 +1,396 @@ +/* + * A "simulator" testbed for simclick library. Note that this could + * have been just a normal old C file except for the fact that I + * decided I wanted to use an existing template heap class, and + * it seemed like as good a time as any to exercise my rusty + * STL skills. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "CUT_BinHeap.h" +#include "click/simclick.h" + +const int TESTSIM_IFID_KERNELTAP=0; +const int TESTSIM_IFID_FIRSTIF=1; + +class Simulator { +public: + Simulator(); + virtual ~Simulator(); + + int nextevent(); + struct timeval gettime() { return cursimtime_; }; + + class SimTime : public timeval { + public: + SimTime() {tv_sec = 0, tv_usec = 0;}; + SimTime(long sec,long usec) { tv_sec = sec, tv_usec = usec; }; + SimTime(struct timeval tv) {tv_sec = tv.tv_sec,tv_usec = tv.tv_usec;}; + + bool operator<(const struct timeval& tv) const { + return ((tv_sec < tv.tv_sec) || + ((tv_sec == tv.tv_sec) && (tv_usec < tv.tv_usec))); + } + bool operator==(const struct timeval& tv) const { + return ((tv_sec == tv.tv_sec) && (tv_usec == tv.tv_usec)); + } + bool operator>(const struct timeval& tv) const { + return ((tv_sec > tv.tv_sec) || + ((tv_usec == tv.tv_usec) && (tv_usec > tv.tv_usec))); + } + SimTime operator+(SimTime rhs) const { + SimTime result; + result.tv_sec = tv_sec + rhs.tv_sec + (tv_usec + rhs.tv_usec)/1000000; + result.tv_usec = (tv_usec + rhs.tv_usec) % 1000000; + return result; + } + }; + + // Base class for all simulator events + class SimEvent { + public: + SimEvent() {}; + virtual ~SimEvent(); + virtual int go(SimTime* when) = 0; + }; +protected: + SimTime cursimtime_; + typedef CUT_BinHeap< SimTime,SimEvent*,less_equal > SimBinHeap; + SimBinHeap eventheap_; +}; + +Simulator::Simulator() { +} + +Simulator::~Simulator() { +} + +int +Simulator::nextevent() { + SimBinHeap::Pix pix = eventheap_.find_top(); + SimTime etime = eventheap_.key(pix); + SimEvent* event = eventheap_.data(pix); + cursimtime_ = etime; + event->go(&etime); + eventheap_.deq(); + delete event; + return eventheap_.size(); +} + +Simulator::SimEvent::~SimEvent() {} + +class TestClickSimulator : public Simulator { +public: + TestClickSimulator(); + virtual ~TestClickSimulator(); + + int add_node(char* clickfile); + void handle_packet_from_click(simclick_click node,int ifid,int ptype, + const unsigned char* data,int len); + void handle_schedule_from_click(simclick_click node,struct timeval* when); + void add_lan_entry(simclick_click node,int ifid,int lanid); + void add_lan_entry(int nodenum,int ifid,int lanid); + simclick_click get_node(int nodenum); + + class PacketEvent : public Simulator::SimEvent { + public: + PacketEvent(); + virtual ~PacketEvent(); + virtual int go(SimTime* when); + + simclick_click clickinst_; + simclick_sim siminst_; + int ifid_; + unsigned char* data_; + int len_; + int ptype_; + }; + + class ScheduledEvent : public Simulator::SimEvent { + public: + ScheduledEvent(); + virtual ~ScheduledEvent(); + virtual int go(SimTime* when); + + simclick_click clickinst_; + simclick_sim siminst_; + }; +protected: + simclick_simstate clickstate_; + struct netif { + netif(simclick_click n,int i) { node=n,ifid=i; } + simclick_click node; + int ifid; + bool operator==(const netif& rhs) const { + return((node == rhs.node) && (ifid == rhs.ifid)); + } + }; + struct hash { + size_t operator()(const netif& x) const { + // Probably not much of a hash function, but it + // should do for now. + return ((int)x.node + x.ifid); + } + }; + + vector clickrouters_; + hash_map netiftolanid_; + hash_map< int,vector > lanidtonetif_; +}; + +TestClickSimulator::TestClickSimulator() { + memset(&clickstate_,0,sizeof(simclick_simstate)); +} + +TestClickSimulator::~TestClickSimulator() { +} + +int +TestClickSimulator::add_node(char* clickfile) { + int result = -1; + simclick_click newnode = simclick_click_create((simclick_sim)this, + clickfile,&clickstate_); + if (newnode) { + clickrouters_.push_back(newnode); + result = clickrouters_.size(); + } + + return result; +} + +void +TestClickSimulator::handle_packet_from_click(simclick_click node,int ifid, + int ptype, + const unsigned char* data,int len) +{ + // Use the node-ifid combo to find the lanid, and then use the lanid + // to get the list of node-ifid combos attached to it. + netif fromif(node,ifid); + + int onlan = netiftolanid_[fromif]; + int i = 0; + int n = lanidtonetif_[onlan].size(); + + for (i=0;iclickinst_ = lanidtonetif_[onlan][i].node; + pkt->siminst_ = (simclick_sim*)this; + pkt->ifid_ = lanidtonetif_[onlan][i].ifid; + pkt->data_ = new unsigned char[len]; + pkt->len_ = len; + pkt->ptype_ = ptype; + memcpy(pkt->data_,data,len); + eventheap_.insert(newtime,pkt); + fprintf(stderr,"Added send packet event: clickinst: %d ifid: %d time: %d %d\n",(int)(pkt->clickinst_),pkt->ifid_,newtime.tv_sec,newtime.tv_usec); + } +} + +void +TestClickSimulator::handle_schedule_from_click(simclick_click node, + struct timeval* when) { + // Stuff a click trigger event into the simulator queue + ScheduledEvent* sevent = new ScheduledEvent; + SimTime newtime(*when); + sevent->clickinst_ = node; + sevent->siminst_ = (simclick_sim*)this; + eventheap_.insert(newtime,sevent); +} + +simclick_click +TestClickSimulator::get_node(int nodenum) { + return clickrouters_[nodenum]; +} + +void +TestClickSimulator::add_lan_entry(int nodenum,int ifid,int lanid) { + add_lan_entry(clickrouters_[nodenum],ifid,lanid); +} + +void +TestClickSimulator::add_lan_entry(simclick_click node,int ifid,int lanid) { + netif newif(node,ifid); + netiftolanid_[newif] = lanid; + lanidtonetif_[lanid].push_back(newif); +} + +int +TestClickSimulator::PacketEvent::go(SimTime* when) { + int result = 0; + struct simclick_simpacketinfo pinfo; + simclick_simstate curstate; + + curstate.curtime.tv_sec = when->tv_sec; + curstate.curtime.tv_usec = when->tv_usec; + pinfo.id = 2; + pinfo.fid =2; + fprintf(stderr,"Dispatching send packet event: clickinst: %d ifid: %d time: %d %d pid %d fid %d\n",(int)clickinst_,ifid_,when->tv_sec,when->tv_usec,pinfo.id,pinfo.fid); + simclick_click_send(clickinst_,&curstate,ifid_,ptype_,data_,len_,&pinfo); + + return result; +} + +TestClickSimulator::PacketEvent::PacketEvent() { + clickinst_ = 0; + ifid_ = -1; + ptype_ = -1; + data_ = 0; + len_ = 0; +} + +TestClickSimulator::PacketEvent::~PacketEvent() { + if (data_) { + delete[] data_; + } +} + +TestClickSimulator::ScheduledEvent::ScheduledEvent() { +} + +TestClickSimulator::ScheduledEvent::~ScheduledEvent() { +} + +int +TestClickSimulator::ScheduledEvent::go(SimTime* when) { + int result = 0; + + simclick_simstate curstate; + curstate.curtime.tv_sec = when->tv_sec; + curstate.curtime.tv_usec = when->tv_usec; + simclick_click_run(clickinst_,&curstate); + + return result; +} + +static TestClickSimulator thesim; + +int main(int argc,char** argv) { + int result = 0; + int i = 0; + const int numclicks = 3; + const unsigned char mypacket[] = "this is my bogus packet\n"; + + printf("Testing the simclick interface...\n"); + + char* scripts[numclicks] = {"../conf/test-simclick-udpgen.click", \ + "../conf/test-simclick-device.click", \ + "../conf/test-simclick-device.click"}; + + for (i=0;i