├── AUTHORS ├── COPYING ├── ChangeLog ├── INSTALL ├── Makefile.am ├── Makefile.in ├── NEWS ├── README ├── aclocal.m4 ├── config.h.in ├── config ├── config.guess ├── config.sub ├── depcomp ├── install-sh ├── ltmain.sh ├── missing └── mkinstalldirs ├── configure ├── configure.in ├── dist ├── Makefile.am ├── Makefile.in ├── netmate-ssl.spec.in └── netmate.spec.in ├── doc ├── Doxyfile.in ├── FAQ ├── Makefile.am ├── Makefile.in ├── known-bugs ├── user_manual.pdf └── wishlist ├── etc ├── Makefile.am ├── Makefile.in ├── example_rules1.xml ├── example_rules2.xml ├── example_rules3.xml ├── filterdef.dtd ├── filterdef.xml ├── filterval.dtd ├── filterval.xml ├── gen_cert.sh.in ├── main.html ├── netmate.conf.dtd ├── netmate.conf.xml.in ├── nmctl.in ├── reply.xml ├── reply.xsl ├── reply2.xsl └── rulefile.dtd ├── netAI-rules-stats-dscp.xml ├── netAI-rules-stats-ni.xml ├── src ├── Makefile.am ├── Makefile.in ├── export_modules │ ├── ExportModule.cc │ ├── ExportModule.h │ ├── Makefile.am │ ├── Makefile.in │ ├── ac_file.cc │ ├── ac_udp.cc │ ├── bin_file.cc │ ├── ctext_file.cc │ ├── ipfix.cc │ ├── netai_arff.cc │ ├── netai_socket.cc │ ├── testexp.cc │ └── text_file.cc ├── include │ ├── ExportModuleInterface.h │ ├── Makefile.am │ ├── Makefile.in │ ├── ProcModuleInterface.h │ ├── constants.h │ ├── metadata.h │ ├── stdinc.h │ └── stdincpp.h ├── lib │ ├── Makefile.am │ ├── Makefile.in │ ├── getopt_long │ │ ├── Makefile.am │ │ ├── Makefile.in │ │ ├── getopt_long.c │ │ └── getopt_long.h │ ├── getpass │ │ ├── COPYING │ │ ├── Makefile.am │ │ ├── Makefile.in │ │ ├── getpass.c │ │ └── getpass.h │ └── httpd │ │ ├── Makefile.am │ │ ├── Makefile.in │ │ ├── README │ │ ├── httpd.c │ │ ├── httpd.h │ │ ├── mime.c │ │ ├── quote.c │ │ ├── request.c │ │ ├── response.c │ │ └── ssl.c ├── netmate │ ├── Bitmap.cc │ ├── Bitmap.h │ ├── Classifier.cc │ ├── Classifier.h │ ├── ClassifierNetfilter.cc │ ├── ClassifierNetfilter.h │ ├── ClassifierRFC.cc │ ├── ClassifierRFC.h │ ├── ClassifierRFCConf.h │ ├── ClassifierSimple.cc │ ├── ClassifierSimple.h │ ├── CommandLineArgs.cc │ ├── CommandLineArgs.h │ ├── ConfigManager.cc │ ├── ConfigManager.h │ ├── ConfigParser.cc │ ├── ConfigParser.h │ ├── CtrlComm.cc │ ├── CtrlComm.h │ ├── Error.cc │ ├── Error.h │ ├── Event.cc │ ├── Event.h │ ├── EventScheduler.cc │ ├── EventScheduler.h │ ├── ExportList.cc │ ├── ExportList.h │ ├── ExportModule.cc │ ├── ExportModule.h │ ├── Exporter.cc │ ├── Exporter.h │ ├── FilterDefParser.cc │ ├── FilterDefParser.h │ ├── FilterValParser.cc │ ├── FilterValParser.h │ ├── FilterValue.cc │ ├── FilterValue.h │ ├── FlowCreator.cc │ ├── FlowCreator.h │ ├── FlowRecord.cc │ ├── FlowRecord.h │ ├── FlowRecordDB.cc │ ├── FlowRecordDB.h │ ├── Logger.cc │ ├── Logger.h │ ├── MAPIRuleParser.cc │ ├── MAPIRuleParser.h │ ├── Makefile.am │ ├── Makefile.in │ ├── Meter.cc │ ├── Meter.h │ ├── MeterComponent.cc │ ├── MeterComponent.h │ ├── MeterInfo.cc │ ├── MeterInfo.h │ ├── MetricData.cc │ ├── MetricData.h │ ├── Module.cc │ ├── Module.h │ ├── ModuleLoader.cc │ ├── ModuleLoader.h │ ├── NetTap.cc │ ├── NetTap.h │ ├── NetTapERF.cc │ ├── NetTapERF.h │ ├── NetTapPcap.cc │ ├── NetTapPcap.h │ ├── PacketProcessor.cc │ ├── PacketProcessor.h │ ├── PacketQueue.cc │ ├── PacketQueue.h │ ├── PageRepository.cc │ ├── PageRepository.h │ ├── ParserFcts.cc │ ├── ParserFcts.h │ ├── PerfTimer.cc │ ├── PerfTimer.h │ ├── ProcModule.cc │ ├── ProcModule.h │ ├── Rule.cc │ ├── Rule.h │ ├── RuleFileParser.cc │ ├── RuleFileParser.h │ ├── RuleIdSource.cc │ ├── RuleIdSource.h │ ├── RuleManager.cc │ ├── RuleManager.h │ ├── Sampler.cc │ ├── Sampler.h │ ├── SamplerAll.cc │ ├── SamplerAll.h │ ├── Threads.h │ ├── Timeval.cc │ ├── Timeval.h │ ├── XMLParser.cc │ ├── XMLParser.h │ └── constants.cc ├── nmrsh │ ├── Makefile.am │ ├── Makefile.in │ ├── README │ └── nmrsh.cc ├── proc_modules │ ├── Makefile.am │ ├── Makefile.in │ ├── ProcModule.c │ ├── ProcModule.h │ ├── bandwidth.c │ ├── capture.c │ ├── count.c │ ├── global.h │ ├── ip.h │ ├── jitter.c │ ├── md5.h │ ├── md5c.c │ ├── netai_flowstats.c │ ├── netai_flowstats_dscp.c │ ├── netai_flowstats_dscp_1s.c │ ├── pktid_crc32.c │ ├── pktid_md5.c │ ├── pktlen.c │ ├── port_use.c │ ├── rtploss.c │ ├── rtt_ping.c │ ├── show_ascii.c │ └── testmod.c └── test │ ├── Makefile.am │ ├── Makefile.in │ ├── PacketQueueTest.cc │ └── PerfTimerTest.cc └── tools ├── Makefile.am ├── Makefile.in ├── genrules.c ├── ports.sh └── protocols.sh /AUTHORS: -------------------------------------------------------------------------------- 1 | Sebastian Zander (szander@swin.edu.au) 2 | Carsten Schmoll (schmoll@fokus.fraunhofer.de) 3 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ## Makefile.am -- Process this file with automake to produce Makefile.in 2 | 3 | SUBDIRS = dist etc src tools doc 4 | 5 | PERL = perl 6 | 7 | 8 | # 9 | # Build source and binary rpms. For rpm-3.0 and above, the ~/.rpmmacros 10 | # must contain the following line: 11 | # %_topdir /home//rpm 12 | # and that /home//rpm contains the directory SOURCES, BUILD etc. 13 | # 14 | # cd /home//rpm ; mkdir -p SOURCES BUILD RPMS/i586 SPECS SRPMS 15 | # 16 | # If additional configure flags are needed to build the package, add the 17 | # following in ~/.rpmmacros 18 | # %configure CFLAGS="%{optflags}" ./configure %{_target_platform} --prefix=%{_prefix} ${AM_CONFIGFLAGS} 19 | # and run make rpms in the following way: 20 | # AM_CONFIGFLAGS='--param=value' make rpms 21 | # 22 | 23 | rpmmacros: 24 | @if test ! -e $(HOME)/.rpmmacros ; then \ 25 | echo "Can't find $(HOME)/.rpmmacros. Read the documentation in Makefile.am." ; \ 26 | fi; 27 | 28 | rpms: rpmmacros $(HOME)/.rpmmacros 29 | $(MAKE) dist 30 | $(MAKE) RPMDIST=$(PACKAGE) rpm 31 | $(MAKE) RPMDIST=$(PACKAGE)-ssl rpm 32 | 33 | rpm: 34 | RPM_TOPDIR=`rpm --showrc | $(PERL) -n -e 'print if(s/.*_topdir\s+(.*)/$$1/)'` ; \ 35 | cp dist/$(RPMDIST).spec $$RPM_TOPDIR/SPECS ; \ 36 | cp $(PACKAGE)-$(VERSION).tar.gz $$RPM_TOPDIR/SOURCES/ ; \ 37 | rpmbuild -ba --clean --rmsource $$RPM_TOPDIR/SPECS/$(RPMDIST).spec ; \ 38 | mv $$RPM_TOPDIR/RPMS/i586/$(RPMDIST)-*.rpm . ; \ 39 | mv $$RPM_TOPDIR/SRPMS/$(RPMDIST)-*.src.rpm . 40 | 41 | # 42 | # omit stuff that should not be released yet 43 | # -> distribute Makefile.dist (if present) instead of Makefile.am 44 | # 45 | 46 | dist-hook: 47 | @echo "Replacing makefiles for distribution:" ; \ 48 | SFILES=`find $(srcdir) -name 'Makefile.dist'` ; \ 49 | for SFILE in $$SFILES ; do \ 50 | TFILE=`echo $$SFILE | sed -e 's/\.//g' | sed -e 's/Makefiledist/Makefile.am/g'` ; \ 51 | echo " $$TFILE" ; \ 52 | cp -f $$SFILE $(distdir)/$$TFILE ; \ 53 | done ; \ 54 | cd $(distdir) ; \ 55 | autoheader ; \ 56 | automake ; \ 57 | autoconf ; \ 58 | rm -rf autom4te.cache ; \ 59 | cd $(srcdir) ; 60 | 61 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | Please see ChangeLog 2 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Network Measurement and Accounting Meter (NETMATE) 2 | 3 | README 4 | 5 | NETMATE is a network measurement tool. It can be used for 6 | accounting, delay/loss measurement, capturing and much 7 | more. 8 | 9 | For basic installation instructions read the file INSTALL. 10 | 11 | When there are questions or problems please read the FAQ 12 | (doc/FAQ) first and have a look at the netmate documentation 13 | in the doc directory before contacting the authors. 14 | 15 | WEB SITE 16 | 17 | Here you can download the complete user and developer 18 | documentation and the latest version of netmate in 19 | binary and source format. 20 | 21 | 22 | 23 | DOWNLOAD 24 | 25 | The software is available as source distribution or binary RPM 26 | (Linux x86 only) from: 27 | 28 | http://sourceforge.net/projects/netmate-meter/ 29 | 30 | CONTACT 31 | 32 | If you have problems, questions, ideas or suggestions, please contact us: 33 | 34 | Sebastian Zander (szander@swin.edu.au) 35 | Carsten Schmoll (schmoll@fokus.fraunhofer.de) 36 | 37 | -------------------------------------------------------------------------------- /config/mkinstalldirs: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # mkinstalldirs --- make directory hierarchy 3 | 4 | scriptversion=2005-06-29.22 5 | 6 | # Original author: Noah Friedman 7 | # Created: 1993-05-16 8 | # Public domain. 9 | # 10 | # This file is maintained in Automake, please report 11 | # bugs to or send patches to 12 | # . 13 | 14 | errstatus=0 15 | dirmode= 16 | 17 | usage="\ 18 | Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ... 19 | 20 | Create each directory DIR (with mode MODE, if specified), including all 21 | leading file name components. 22 | 23 | Report bugs to ." 24 | 25 | # process command line arguments 26 | while test $# -gt 0 ; do 27 | case $1 in 28 | -h | --help | --h*) # -h for help 29 | echo "$usage" 30 | exit $? 31 | ;; 32 | -m) # -m PERM arg 33 | shift 34 | test $# -eq 0 && { echo "$usage" 1>&2; exit 1; } 35 | dirmode=$1 36 | shift 37 | ;; 38 | --version) 39 | echo "$0 $scriptversion" 40 | exit $? 41 | ;; 42 | --) # stop option processing 43 | shift 44 | break 45 | ;; 46 | -*) # unknown option 47 | echo "$usage" 1>&2 48 | exit 1 49 | ;; 50 | *) # first non-opt arg 51 | break 52 | ;; 53 | esac 54 | done 55 | 56 | for file 57 | do 58 | if test -d "$file"; then 59 | shift 60 | else 61 | break 62 | fi 63 | done 64 | 65 | case $# in 66 | 0) exit 0 ;; 67 | esac 68 | 69 | # Solaris 8's mkdir -p isn't thread-safe. If you mkdir -p a/b and 70 | # mkdir -p a/c at the same time, both will detect that a is missing, 71 | # one will create a, then the other will try to create a and die with 72 | # a "File exists" error. This is a problem when calling mkinstalldirs 73 | # from a parallel make. We use --version in the probe to restrict 74 | # ourselves to GNU mkdir, which is thread-safe. 75 | case $dirmode in 76 | '') 77 | if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then 78 | echo "mkdir -p -- $*" 79 | exec mkdir -p -- "$@" 80 | else 81 | # On NextStep and OpenStep, the `mkdir' command does not 82 | # recognize any option. It will interpret all options as 83 | # directories to create, and then abort because `.' already 84 | # exists. 85 | test -d ./-p && rmdir ./-p 86 | test -d ./--version && rmdir ./--version 87 | fi 88 | ;; 89 | *) 90 | if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 && 91 | test ! -d ./--version; then 92 | echo "mkdir -m $dirmode -p -- $*" 93 | exec mkdir -m "$dirmode" -p -- "$@" 94 | else 95 | # Clean up after NextStep and OpenStep mkdir. 96 | for d in ./-m ./-p ./--version "./$dirmode"; 97 | do 98 | test -d $d && rmdir $d 99 | done 100 | fi 101 | ;; 102 | esac 103 | 104 | for file 105 | do 106 | case $file in 107 | /*) pathcomp=/ ;; 108 | *) pathcomp= ;; 109 | esac 110 | oIFS=$IFS 111 | IFS=/ 112 | set fnord $file 113 | shift 114 | IFS=$oIFS 115 | 116 | for d 117 | do 118 | test "x$d" = x && continue 119 | 120 | pathcomp=$pathcomp$d 121 | case $pathcomp in 122 | -*) pathcomp=./$pathcomp ;; 123 | esac 124 | 125 | if test ! -d "$pathcomp"; then 126 | echo "mkdir $pathcomp" 127 | 128 | mkdir "$pathcomp" || lasterr=$? 129 | 130 | if test ! -d "$pathcomp"; then 131 | errstatus=$lasterr 132 | else 133 | if test ! -z "$dirmode"; then 134 | echo "chmod $dirmode $pathcomp" 135 | lasterr= 136 | chmod "$dirmode" "$pathcomp" || lasterr=$? 137 | 138 | if test ! -z "$lasterr"; then 139 | errstatus=$lasterr 140 | fi 141 | fi 142 | fi 143 | fi 144 | 145 | pathcomp=$pathcomp/ 146 | done 147 | done 148 | 149 | exit $errstatus 150 | 151 | # Local Variables: 152 | # mode: shell-script 153 | # sh-indentation: 2 154 | # eval: (add-hook 'write-file-hooks 'time-stamp) 155 | # time-stamp-start: "scriptversion=" 156 | # time-stamp-format: "%:y-%02m-%02d.%02H" 157 | # time-stamp-end: "$" 158 | # End: 159 | -------------------------------------------------------------------------------- /dist/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = netmate.spec.in netmate-ssl.spec.in 2 | -------------------------------------------------------------------------------- /dist/netmate-ssl.spec.in: -------------------------------------------------------------------------------- 1 | %define name netmate-ssl 2 | %define tarball netmate 3 | %define version @VERSION@ 4 | %define release 1 5 | %define prefix /usr/local 6 | 7 | %define builddir $RPM_BUILD_DIR/%{tarball}-%{version} 8 | 9 | Summary: netmate - network measurment and accounting tool 10 | Name: %{name} 11 | Version: %{version} 12 | Release: %{release} 13 | License: GPL 14 | Vendor: Fraunhofer FOKUS 15 | Packager: Sebastian Zander 16 | Group: Utilities/Console 17 | Source: %{tarball}-%{version}.tar.gz 18 | URL: http://fokus.fraunhofer.de/research/cc/meteor/projects/ipqos/netmate 19 | BuildRoot: /tmp/%{tarball}-%{version}-root 20 | 21 | %description 22 | netmate is a flexible and extensible tool for accounting and 23 | network measurement. It can easily extended with new metric 24 | and export modules. 25 | 26 | Note: this version is compiled with SSL and thread support. 27 | 28 | %prep 29 | rm -rf %{builddir} 30 | 31 | %setup -n %{tarball}-%{version} 32 | 33 | %build 34 | ./configure --enable-ssl --enable-threads --prefix=%{prefix} 35 | make 36 | 37 | %install 38 | rm -rf $RPM_BUILD_ROOT 39 | make DESTDIR=$RPM_BUILD_ROOT install-strip 40 | rm -rf $RPM_BUILD_ROOT/%{prefix}/etc/%{tarball}/netmate.pem 41 | rm -rf $RPM_BUILD_ROOT/%{prefix}/bin/genrules 42 | 43 | %clean 44 | rm -rf $RPM_BUILD_ROOT 45 | rm -rf %{builddir} 46 | 47 | %post 48 | /sbin/ldconfig 49 | echo "Generating certificate for SSL" 50 | %{prefix}/bin/gen_cert.sh %{prefix}/etc/%{tarball} 51 | 52 | %postun 53 | /sbin/ldconfig 54 | rm -rf %{prefix}/etc/%{tarball}/netmate.pem 55 | 56 | %files 57 | %defattr(-,root,root) 58 | %attr(0755,root,root) %{prefix}/bin/netmate 59 | %attr(0755,root,root) %{prefix}/bin/nmrsh 60 | %attr(0755,root,root) %{prefix}/bin/nmctl 61 | %attr(0755,root,root) %{prefix}/bin/gen_cert.sh 62 | %{prefix}/lib/%{tarball}/* 63 | %{prefix}/etc/%{tarball}/example_rules1.xml 64 | %{prefix}/etc/%{tarball}/example_rules2.xml 65 | %{prefix}/etc/%{tarball}/example_rules3.xml 66 | %{prefix}/etc/%{tarball}/filterdef.dtd 67 | %{prefix}/etc/%{tarball}/filterdef.xml 68 | %{prefix}/etc/%{tarball}/filterval.dtd 69 | %{prefix}/etc/%{tarball}/filterval.xml 70 | %{prefix}/etc/%{tarball}/main.html 71 | %{prefix}/etc/%{tarball}/netmate.conf.dtd 72 | %{prefix}/etc/%{tarball}/netmate.conf.xml 73 | %{prefix}/etc/%{tarball}/reply.xml 74 | %{prefix}/etc/%{tarball}/reply.xsl 75 | %{prefix}/etc/%{tarball}/reply2.xsl 76 | %{prefix}/etc/%{tarball}/rulefile.dtd 77 | %doc AUTHORS COPYING INSTALL NEWS README ChangeLog 78 | %doc doc/FAQ doc/known-bugs doc/wishlist doc/user_manual.pdf 79 | 80 | %changelog 81 | * Fri Feb 6 2001 Sebastian Zander 82 | - initial 83 | -------------------------------------------------------------------------------- /dist/netmate.spec.in: -------------------------------------------------------------------------------- 1 | %define name netmate 2 | %define version @VERSION@ 3 | %define release 1 4 | %define prefix /usr/local 5 | 6 | %define builddir $RPM_BUILD_DIR/%{name}-%{version} 7 | 8 | Summary: netmate - network measurment and accounting tool 9 | Name: %{name} 10 | Version: %{version} 11 | Release: %{release} 12 | License: GPL 13 | Vendor: Fraunhofer FOKUS 14 | Packager: Sebastian Zander 15 | Group: Utilities/Console 16 | Source: %{name}-%{version}.tar.gz 17 | URL: http://fokus.fraunhofer.de/research/cc/meteor/projects/ipqos/netmate 18 | BuildRoot: /tmp/%{name}-%{version}-root 19 | 20 | %description 21 | netmate is a flexible and extensible tool for accounting and 22 | network measurement. It can easily extended with new metric 23 | and export modules. 24 | 25 | Note: this version is compiled without SSL and thread support. 26 | 27 | %prep 28 | rm -rf %{builddir} 29 | 30 | %setup 31 | 32 | %build 33 | ./configure --enable-threads --prefix=%{prefix} 34 | make 35 | 36 | %install 37 | rm -rf $RPM_BUILD_ROOT 38 | make DESTDIR=$RPM_BUILD_ROOT install-strip 39 | rm -rf $RPM_BUILD_ROOT/%{prefix}/bin/genrules 40 | 41 | %clean 42 | rm -rf $RPM_BUILD_ROOT 43 | rm -rf %{builddir} 44 | 45 | %post 46 | /sbin/ldconfig 47 | 48 | %postun 49 | /sbin/ldconfig 50 | 51 | %files 52 | %defattr(-,root,root) 53 | %attr(0755,root,root) %{prefix}/bin/netmate 54 | %attr(0755,root,root) %{prefix}/bin/nmrsh 55 | %attr(0755,root,root) %{prefix}/bin/nmctl 56 | %{prefix}/lib/%{name}/* 57 | %{prefix}/etc/%{name}/example_rules1.xml 58 | %{prefix}/etc/%{name}/example_rules2.xml 59 | %{prefix}/etc/%{name}/example_rules3.xml 60 | %{prefix}/etc/%{name}/filterdef.dtd 61 | %{prefix}/etc/%{name}/filterdef.xml 62 | %{prefix}/etc/%{name}/filterval.dtd 63 | %{prefix}/etc/%{name}/filterval.xml 64 | %{prefix}/etc/%{name}/main.html 65 | %{prefix}/etc/%{name}/netmate.conf.dtd 66 | %{prefix}/etc/%{name}/netmate.conf.xml 67 | %{prefix}/etc/%{name}/reply.xml 68 | %{prefix}/etc/%{name}/reply.xsl 69 | %{prefix}/etc/%{name}/reply2.xsl 70 | %{prefix}/etc/%{name}/rulefile.dtd 71 | %doc AUTHORS COPYING INSTALL NEWS README ChangeLog 72 | %doc doc/FAQ doc/known-bugs doc/wishlist doc/user_manual.pdf 73 | 74 | %changelog 75 | * Fri Feb 6 2001 Sebastian Zander 76 | - initial 77 | -------------------------------------------------------------------------------- /doc/FAQ: -------------------------------------------------------------------------------- 1 | Frequently asked questions (FAQ) 2 | 3 | Q: Where does "make install" put the files by default? 4 | 5 | A: By default netmate is installed in the /usr/local tree: 6 | /usr/local/bin holds the generated executables, 7 | /usr/local/etc/netmate holds the netmate configuration, 8 | /usr/local/lib/netmate holds all plug-in modules. 9 | 10 | 11 | Q: How can I install netmate to a different directory? 12 | 13 | A: Call ./configure with the option --prefix= 14 | 15 | 16 | Q: When I start netmate I get the error message 17 | "Terminating netmate on error: cannot open pidfile '/var/run/netmate.pid' \ 18 | for writing: Permission denied". What is wrong? 19 | 20 | A: You will need to run netmate as user 'root'. This is usually required to 21 | capture packets from the network interface card and also for writing in 22 | /var/run/ 23 | 24 | You can also configure netmate so that pid file and log file will be 25 | created in different directories (where you have write permissions). If 26 | the interface is readable for you or you do not capture from an interface 27 | (e.g. input from a tcpdump file) you do not need to have root permissions. 28 | 29 | 30 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | DOXY = @DOXY@ 2 | DOXYDIR = netmate_source_doc 3 | 4 | EXTRA_DIST = FAQ known-bugs wishlist user_manual.pdf Doxyfile.in 5 | 6 | # FIXME include doc files in distribution 7 | 8 | all: Doxyfile 9 | 10 | @if test $(DOXY) ; then \ 11 | echo "Building netmate source code documentation (html)" ; \ 12 | doxygen ; \ 13 | else \ 14 | echo "WARNING: not building source code documentation because Doxygen is not installed!" ; \ 15 | fi; 16 | 17 | clean: 18 | @echo "Removing netmate source code documentation (html)" 19 | 20 | @if test -d $(DOXYDIR) ; then \ 21 | rm -rf $(DOXYDIR) ; \ 22 | fi; 23 | 24 | distclean: clean 25 | @rm -rf Makefile 26 | @rm -rf Doxyfile 27 | 28 | maintainer-clean: distclean 29 | 30 | -------------------------------------------------------------------------------- /doc/known-bugs: -------------------------------------------------------------------------------- 1 | Known bugs & problems 2 | --------------------- 3 | 4 | duplicate httpd access log entries when remote config is used 5 | (sometimes) 6 | 7 | memory leak in nmrsh/readline (constant 40 byte), readline bug? 8 | memory leak in crypto lib!? (happens only when remote config 9 | via SSL is used) 10 | 11 | C++ memory optimization leads to still reachable blocks after 12 | program exit; C++ memory optimization can be disabled with 13 | seeting GLIBCPP_FORCE_NEW environment variable (not a bug) 14 | 15 | netmate sometimes does not properly terminate when running 16 | multithreaded 17 | 18 | when using netmate on trace files the export timestamp in the 19 | exported data files is the current time but not based on the 20 | trace 21 | 22 | -------------------------------------------------------------------------------- /doc/user_manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DanielArndt/netmate-flowcalc/ea12931a21c1cd2c1c6ba1d4bfed7d88fccad77d/doc/user_manual.pdf -------------------------------------------------------------------------------- /doc/wishlist: -------------------------------------------------------------------------------- 1 | Wishlist 2 | -------- 3 | 4 | - packet id modules report ttl 5 | - better meter gui (aka help.html) lists for meter info, easier rule insertion) 6 | 7 | -------------------------------------------------------------------------------- /etc/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Makefile.am -- Process this file with automake to produce Makefile.in 2 | 3 | nodist_bin_SCRIPTS = nmctl 4 | 5 | dist_sysconf_DATA = netmate.conf.dtd filterdef.xml \ 6 | filterdef.dtd filterval.xml filterval.dtd rulefile.dtd \ 7 | main.html reply.xml reply.xsl reply2.xsl \ 8 | example_rules1.xml example_rules2.xml example_rules3.xml \ 9 | #ipfix_mapping.txt 10 | nodist_sysconf_DATA = netmate.conf.xml 11 | 12 | DISTCLEANFILES = nmctl gen_cert.sh netmate.conf.xml 13 | 14 | if ENABLE_SSL 15 | nodist_bin_SCRIPTS += gen_cert.sh 16 | DISTCLEANFILES += netmate.pem 17 | endif 18 | 19 | install-exec-hook: 20 | if ENABLE_SSL 21 | @echo "Generating certificate for SSL" ; \ 22 | $(DESTDIR)/$(bindir)/gen_cert.sh $(DESTDIR)/$(sysconfdir) 23 | endif 24 | -------------------------------------------------------------------------------- /etc/example_rules1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 1000 9 | 10 | 11 | 1 12 | 13 | 14 | 15 | * 16 | 17 | 18 | 19 | 20 | 22 | 23 | capture 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /etc/example_rules2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 | 1000 10 | 11 | 10 12 | 13 | 14 | 15 | 16 | 19 | 20 | 21 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 193.175.133.0 32 | 33 | 34 | 35 | 36 | 5 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | * 45 | udp,tcp 46 | 47 | 1-1024 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | * 58 | www.google.com 59 | http 60 | 61 | 62 | 63 | 64 | 65 | yes 66 | 67 | 68 | +10 69 | 70 | 71 | 990 72 | 5 73 | 74 | 75 | -------------------------------------------------------------------------------- /etc/example_rules3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 1000 6 | 2 7 | 8 | 9 | 10 | ruleset1-export 11 | 12 | 13 | 14 | 15 | 16 | * 17 | 18 | 19 | value 20 | 21 | 22 | 23 | 24 | 26 | * 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /etc/filterdef.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 14 | 15 | 20 | -------------------------------------------------------------------------------- /etc/filterdef.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | DstMAC 6 | SrcMAC 7 | 8 | 9 | IPVer 10 | IPToS 11 | IPTTL 12 | Proto 13 | SrcIP 14 | DstIP 15 | 16 | TrafficClass 17 | FlowLabel 18 | Proto6 19 | HopLimit 20 | SrcIP6 21 | DstIP6 22 | 23 | 24 | ICMPType 25 | ICMPCode 26 | 27 | 28 | SrcPort 29 | DstPort 30 | TCPFlags 31 | 32 | 33 | -------------------------------------------------------------------------------- /etc/filterval.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | -------------------------------------------------------------------------------- /etc/gen_cert.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | path=$1 4 | 5 | if [ "x$path" = "x" ] ; then 6 | pem=netmate.pem 7 | else 8 | pem=$path/netmate.pem 9 | fi ; 10 | 11 | 12 | fqdn=`hostname` 13 | if [ "x$fqdn" = "x" ] ; then 14 | fqdn="localhost.localdomain" 15 | fi ; 16 | cat << EOF | openssl req -passout pass:@SSL_PASSWD@ -keyout $pem -out $pem -new -x509 2> /dev/null 17 | -- 18 | SomeState 19 | SomeCity 20 | SomeOrganization 21 | SomeOrganizationalUnit 22 | $fqdn 23 | root@$fqdn 24 | EOF 25 | -------------------------------------------------------------------------------- /etc/main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Netmate Main 4 | 5 | 6 |

Netmate Main

7 |

Commands:

8 |
9 | /help: displays this help

10 | 11 | /get_info?IType=<type>[&IParam=<param>]: displays varies information

12 |
13 | Type = 14 | 27 |
28 | Param =
29 | 30 |

31 | 32 | /rm_task?RuleID=<rule_id>: delete rule(s)

33 |
34 | RuleID =
35 | 36 |

37 | 38 | /add_task?Rule=<rule>: add rule(s)

39 |
40 | Rule =
41 | 42 |

43 | 44 | /get_modinfo?IName=<mod_name>: get module specific information

45 |
46 | Name =
47 | 48 |
49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /etc/netmate.conf.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 20 | 23 | 26 | 31 | -------------------------------------------------------------------------------- /etc/reply.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @STATUS@ 5 | @MESSAGE@ 6 | 7 | -------------------------------------------------------------------------------- /etc/reply.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | <xsl:value-of select="status"/> 10 | 11 | 12 |

13 | 14 |

15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 |

35 | Module: 36 |

37 | (version 38 | , uid=) 39 | 40 |

Creation Date:
41 | Last Modified:

42 | 43 | Description: 44 | 45 |

46 | 47 | 48 | 49 | 50 | 51 |
Short
Verbose
documented at
per Rule paramaters
Exported Data

52 | 53 | Author: 54 | 55 |

56 | 57 | 58 | 59 | 66 | 67 | 74 |
Name
Affiliation
E-Mail 60 | 61 | mailto: 62 | 63 | 64 | 65 |
Homepage 68 | 69 | 70 | 71 | 72 | 73 |

75 |
76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 92 | 95 | 96 | 97 |
ItemValue
90 | 91 | 93 | 94 |
98 | 99 |
100 | 101 | 102 | 103 | 104 | 105 | 106 |

107 |       
108 | 

109 |
110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
122 | 123 | 124 | 125 |
126 | 127 | 128 | 129 |
130 |
131 | 132 | 133 |
134 | -------------------------------------------------------------------------------- /etc/reply2.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Module: 24 | (version , uid=) 25 | 26 | Creation Date: 27 | Last Modified: 28 | 29 | Description: 30 | 31 | Short 32 | Verbose 33 | documented at 34 | Rule paramaters 35 | Exported Data 36 | 37 | Author: 38 | 39 | Name 40 | Affiliation 41 | E-Mail 42 | Homepage 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /etc/rulefile.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 | 12 | 13 | 16 | 17 | 21 | 22 | 24 | 25 | 28 | 29 | -------------------------------------------------------------------------------- /netAI-rules-stats-dscp.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 1000000 7 | 8 | 9 | /home/darndt/netmate-ni.out 10 | no 11 | no 12 | 13 | 14 | 15 | 16 | * 17 | * 18 | * 19 | * 20 | tcp,udp 21 | yes 22 | yes 23 | 600 24 | 25 | 26 | -------------------------------------------------------------------------------- /netAI-rules-stats-ni.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 1000000 10 | 11 | 12 | 13 | /home/darndt/netmate.out 14 | no 15 | no 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | * 26 | * 27 | * 28 | * 29 | tcp,udp 30 | 31 | yes 32 | yes 33 | 600 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Makefile.am -- Process this file with automake to produce Makefile.in 2 | 3 | SUBDIRS = include lib proc_modules export_modules netmate nmrsh 4 | 5 | if ENABLE_TEST 6 | SUBDIRS += test 7 | endif 8 | 9 | -------------------------------------------------------------------------------- /src/export_modules/ExportModule.cc: -------------------------------------------------------------------------------- 1 | 2 | /*! \file export_modules/ExportModule.cc 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | implementation of helper functions for Exporter Modules 25 | 26 | $Id: ExportModule.cc 748 2009-09-10 02:54:03Z szander $ 27 | 28 | */ 29 | 30 | #include "ExportModule.h" 31 | 32 | /*! \short embed magic cookie number in every exporting module 33 | _N_et_M_ate _E_xport Module */ 34 | int magic = EXPORT_MAGIC; 35 | 36 | 37 | /*! \short declaration of struct containing all function pointers of a module */ 38 | ExportModuleInterface_t func = 39 | { 40 | 3, 41 | initModule, 42 | destroyModule, 43 | resetModule, 44 | timeout, 45 | initExportRec, 46 | getTimers, 47 | destroyExportRec, 48 | exportData, 49 | getModuleInfo, 50 | getErrorMsg 51 | }; 52 | -------------------------------------------------------------------------------- /src/export_modules/ExportModule.h: -------------------------------------------------------------------------------- 1 | 2 | /*! \file export_modules/ExportModule.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | declaration of interface for Classifier Action Modules 25 | 26 | $Id: ExportModule.h 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | 30 | #ifndef __EXPORTMODULE_H 31 | #define __EXPORTMODULE_H 32 | 33 | 34 | #include "ExportModuleInterface.h" 35 | 36 | 37 | /*! \short declaration of struct containing all function pointers of a module */ 38 | extern ExportModuleInterface_t func; 39 | 40 | #endif /* __EXPORTMODULE_H */ 41 | -------------------------------------------------------------------------------- /src/export_modules/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = ExportModule.h ExportModule.cc 2 | 3 | INCLUDES = -I$(top_srcdir)/src/include \ 4 | -I$(top_srcdir)/netfilter_userspace/include \ 5 | -I$(top_srcdir)/src/netmate \ 6 | -I$(top_srcdir)/src/lib/getopt_long \ 7 | -I$(top_srcdir)/src/lib/libipfix \ 8 | -I/usr/src/linux/include 9 | 10 | lib_LTLIBRARIES = testexp.la text_file.la bin_file.la ctext_file.la ac_file.la netai_socket.la netai_arff.la 11 | if ENABLE_IPFIX 12 | lib_LTLIBRARIES += ipfix.la 13 | endif 14 | 15 | if ENABLE_DEBUG 16 | AM_CXXFLAGS = -g -fPIC -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GLIBCXX_DEBUG -DDEBUG -DPROFILING 17 | else 18 | AM_CXXFLAGS = -O2 -fPIC -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 19 | endif 20 | 21 | testexp_la_LDFLAGS = -export-dynamic -module 22 | testexp_la_SOURCES = testexp.cc 23 | testexp_la_LIBADD = ExportModule.lo 24 | 25 | text_file_la_LDFLAGS = -export-dynamic -module 26 | text_file_la_SOURCES = text_file.cc 27 | text_file_la_LIBADD = ExportModule.lo 28 | 29 | bin_file_la_LDFLAGS = -export-dynamic -module 30 | bin_file_la_SOURCES = bin_file.cc 31 | bin_file_la_LIBADD = ExportModule.lo 32 | 33 | ctext_file_la_LDFLAGS = -export-dynamic -module 34 | ctext_file_la_SOURCES = ctext_file.cc 35 | ctext_file_la_LIBADD = ExportModule.lo 36 | 37 | ac_file_la_LDFLAGS = -export-dynamic -module 38 | ac_file_la_SOURCES = ac_file.cc 39 | ac_file_la_LIBADD = ExportModule.lo 40 | 41 | netai_socket_la_LDFLAGS = -export-dynamic -module 42 | netai_socket_la_SOURCES = netai_socket.cc 43 | netai_socket_la_LIBADD = ExportModule.lo 44 | 45 | netai_arff_la_LDFLAGS = -export-dynamic -module 46 | netai_arff_la_SOURCES = netai_arff.cc 47 | netai_arff_la_LIBADD = ExportModule.lo 48 | 49 | 50 | 51 | ipfix_la_LDFLAGS = -export-dynamic -module 52 | ipfix_la_SOURCES = ipfix.cc 53 | ipfix_la_LIBADD = ExportModule.lo @IPFIXLIB@ 54 | -------------------------------------------------------------------------------- /src/export_modules/testexp.cc: -------------------------------------------------------------------------------- 1 | 2 | /*! \file testexp.cc 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | used for testing export module functions 25 | 26 | $Id: testexp.cc 748 2009-09-10 02:54:03Z szander $ 27 | 28 | */ 29 | 30 | 31 | #include "stdincpp.h" 32 | #include "ConfigManager.h" 33 | #include "./ExportModule.h" 34 | #include "Rule.h" 35 | #include "ConfigParser.h" 36 | 37 | 38 | /* 39 | define here the timers which such a module is using on default 40 | */ 41 | 42 | timers_t timers[] = { /* handle, ival_msec, flags */ 43 | { 1, 2000, 0 }, 44 | { 2, 4000, TM_RECURRING }, 45 | { 3, 6000, TM_ALIGNED }, 46 | { 4, 8000, TM_RECURRING | TM_ALIGNED }, 47 | { 5, 10000, TM_NONE /*==0*/ }, 48 | TIMER_END 49 | }; 50 | 51 | 52 | static int first = 0; 53 | 54 | 55 | int initModule( ConfigManager *confMan ) 56 | { 57 | return 0; 58 | } 59 | 60 | 61 | int resetModule() 62 | { 63 | return 0; 64 | } 65 | 66 | 67 | int destroyModule() 68 | { 69 | return 0; 70 | } 71 | 72 | 73 | int initExportRec( configItemList_t conf, void **expRecord ) 74 | { 75 | fprintf(stderr, "testexp : initExportRec\n"); 76 | first = time(NULL); 77 | return 0; 78 | } 79 | 80 | 81 | int destroyExportRec( void *expRecord ) 82 | { 83 | fprintf( stderr, "testexp : destroyFlowRec\n" ); 84 | return 0; 85 | } 86 | 87 | 88 | int timeout( int timerID ) 89 | { 90 | fprintf( stderr, "testexp_module: timeout (timer id = %d," 91 | " time sice start = %ld seconds)\n\n", 92 | timerID, time(NULL) - first ); 93 | return 0; 94 | } 95 | 96 | 97 | int exportMetricData( MetricData *mdata ) 98 | { 99 | cout << "testexp::exportData (mod='" << mdata->getModName() << "')" <getNextData()) != NULL ) { 110 | 111 | exportMetricData( mdata ); 112 | } 113 | 114 | return 0; 115 | } 116 | 117 | 118 | 119 | char* getErrorMsg( int ) 120 | { 121 | return "200"; 122 | } 123 | 124 | 125 | char* getModuleInfo(int i) 126 | { 127 | return "200"; 128 | } 129 | 130 | 131 | timers_t* getTimers() 132 | { 133 | return timers; 134 | } 135 | 136 | -------------------------------------------------------------------------------- /src/include/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | EXTRA_DIST = ExportModuleInterface.h ProcModuleInterface.h metadata.h \ 3 | stdinc.h stdincpp.h constants.h 4 | -------------------------------------------------------------------------------- /src/include/constants.h: -------------------------------------------------------------------------------- 1 | 2 | /* \file constants.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | here all string and numeric constants for the netmate toolset are declared 25 | 26 | $Id: constants.h 748 2009-09-10 02:54:03Z szander $ 27 | 28 | */ 29 | 30 | 31 | #include "config.h" 32 | 33 | 34 | #ifndef _CONSTANTS_H_ 35 | #define _CONSTANTS_H_ 36 | 37 | 38 | // RuleManager.cc 39 | extern const unsigned int DONE_LIST_SIZE; 40 | extern const string FILTERVAL_FILE; 41 | 42 | // Meter.h 43 | extern const string DEFAULT_CONFIG_FILE; 44 | extern const string NETMATE_LOCK_FILE; 45 | extern const int DEF_SNAPSIZE; 46 | 47 | // Logger.h 48 | extern const string DEFAULT_LOG_FILE; 49 | 50 | // RuleFileParser.cc 51 | extern const string RULEFILE_DTD; 52 | 53 | // Rule.cc 54 | extern const string TIME_FORMAT; 55 | extern const string DEFAULT_SETNAME; 56 | 57 | // FilterValParser.cc 58 | extern const string FILTERVAL_DTD; 59 | 60 | // FilterDefParser.cc 61 | extern const string FILTERDEF_FILE; 62 | extern const string FILTERDEF_DTD; 63 | 64 | // CtrlComm.cc 65 | extern const string REPLY_TEMPLATE; //!< html response template 66 | extern const string MAIN_PAGE_FILE; 67 | extern const string XSL_PAGE_FILE; 68 | extern const int EXPIRY_TIME; //!< expiry time for web pages served from cache 69 | extern const int DEF_PORT; //!< default TCP port to connect to 70 | 71 | // ConfigParser.h 72 | extern const string CONFIGFILE_DTD; 73 | 74 | // nmrsh.cc 75 | extern const string PROMPT; //!< user prompt for interactive mode 76 | extern const string DEF_SERVER; //!< default netmate host 77 | extern const int HISTLEN; //!< history length (lines) 78 | extern const string HISTFILE; //!< name of the history file 79 | extern const string DEF_XSL; //!< xsl file for decoding xml responses 80 | extern const string HOME; //!< environment var pointing to the dir where the hist file is 81 | extern const string HELP; //!< help text in interactive shell 82 | 83 | #ifdef USE_SSL 84 | // certificate file location (SSL) 85 | extern const string CERT_FILE; 86 | #endif 87 | 88 | 89 | #endif // _CONSTANTS_H_ 90 | -------------------------------------------------------------------------------- /src/include/metadata.h: -------------------------------------------------------------------------------- 1 | 2 | /*! \file metadata.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | packet meta data format 25 | 26 | $Id: metadata.h 748 2009-09-10 02:54:03Z szander $ 27 | 28 | */ 29 | 30 | #ifndef __METADATA_H 31 | #define __METADATA_H 32 | 33 | // max number of rules which can match a single packet 34 | #define MAX_RULES_MATCH 128 35 | 36 | 37 | #include "stdinc.h" 38 | #ifdef ENABLE_NF 39 | #ifdef HAVE_LIBIPULOG_LIBIPULOG_H 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | #include 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | #endif 48 | #endif 49 | 50 | // protocol constants for layer array 51 | 52 | typedef enum { 53 | L_UNKNOWN = 0, 54 | L_ETHERNET, 55 | L_ATM_RFC1483 56 | } linkProt_t; 57 | 58 | typedef enum { 59 | N_UNKNOWN = 0, 60 | N_IP, 61 | N_IP6 62 | } netProt_t; 63 | 64 | typedef enum { 65 | T_UNKNOWN = 0, 66 | T_ICMP = 1, 67 | T_IGMP = 2, 68 | T_GGP = 3, 69 | T_IPIP = 4, 70 | T_STREAM = 5, 71 | T_TCP = 6, 72 | T_EGP = 8, 73 | T_IGP = 9, 74 | T_UDP = 17, 75 | T_MUX = 18, 76 | T_IDPR = 35, 77 | T_IPV6 = 41, 78 | T_IDRP = 45, 79 | T_RSVP = 46, 80 | T_GRE = 47, 81 | T_MOBILE = 55, 82 | T_ICMP6 = 58 83 | } transProt_t; 84 | 85 | 86 | typedef enum { 87 | L_LINK = 0, 88 | L_NET, 89 | L_TRANS, 90 | L_DATA 91 | } pktLayer_t; 92 | 93 | 94 | /* \short data that will be supplied to the packet processor by the classifier 95 | */ 96 | 97 | #ifdef ENABLE_NF 98 | #ifdef HAVE_LIBIPULOG_LIBIPULOG_H 99 | // netfilter specific struct not yet 100 | #endif 101 | // we should never get here 102 | #else 103 | typedef struct { 104 | unsigned long tv_sec; 105 | unsigned long tv_usec; 106 | char indev_name[255]; 107 | char outdev_name[255]; 108 | // == min( snaplen, pktlen ) 109 | size_t cap_len; 110 | // size of the original packet 111 | size_t len; 112 | // offsets to the different headers 113 | // 0: mac (should always be 0) 114 | // 1: ip 115 | // 2: trans 116 | // 3: data 117 | int offs[4]; 118 | // protocol for each layer as determined by NetTapPcap 119 | int layers[4]; 120 | // indicate reverse direction (for bidir flows) 121 | // FIXME: not supported by RFC classifier 122 | int reverse; 123 | // count and rule ids of matching rules 124 | unsigned short match_cnt; 125 | unsigned int match[MAX_RULES_MATCH]; 126 | 127 | // pointer to the data 128 | unsigned char payload[1]; 129 | } metaData_t; 130 | 131 | #endif 132 | 133 | #endif /* __METADATA_H */ 134 | -------------------------------------------------------------------------------- /src/include/stdinc.h: -------------------------------------------------------------------------------- 1 | 2 | /*!\file stdinc.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | Include this file (stdinc.h) in every .h file. 25 | This .h file includes all the standard include 26 | files such as stdio.h, stdlib.h and others 27 | 28 | $Id: stdinc.h 748 2009-09-10 02:54:03Z szander $ 29 | 30 | */ 31 | 32 | #ifndef __STDINC_H 33 | #define __STDINC_H 34 | 35 | #include "config.h" 36 | 37 | #ifndef _GNU_SOURCE 38 | #define _GNU_SOURCE 39 | #endif 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | 57 | #ifdef LINUX 58 | #include 59 | #include 60 | #endif 61 | 62 | #ifdef HAVE_FLOAT_H 63 | #include 64 | #define MINFLOAT FLT_MIN 65 | #define MINDOUBLE DBL_MIN 66 | #define MAXDOUBLE DBL_MAX 67 | #endif 68 | 69 | #include 70 | #include 71 | 72 | #ifdef ENABLE_THREADS 73 | #include 74 | #endif 75 | 76 | #include 77 | #include 78 | #include 79 | #include 80 | #include 81 | #include 82 | #include 83 | #include 84 | #include 85 | #include 86 | #include 87 | #include 88 | 89 | #ifdef HAVE_ETHER_H 90 | #include 91 | #endif 92 | #ifdef HAVE_NET_BPF_H 93 | #include 94 | #endif 95 | #ifdef HAVE_NET_ETHERNET_H 96 | #include 97 | #endif 98 | 99 | #ifdef HAVE_IPTABLES_H 100 | #include 101 | #endif 102 | #ifdef HAVE_LIBIPULOG_LIBIPULOG_H 103 | #include "libipulog/libipulog.h" 104 | #endif 105 | #ifdef HAVE_LIBIPTC_LIBIPTC_H 106 | #include "libiptc/libiptc.h" 107 | #endif 108 | 109 | 110 | #ifdef HRTIME_PROFILING 111 | #include 112 | #endif 113 | 114 | #ifdef ENABLE_MP 115 | #include "mpatrol.h" 116 | #endif 117 | 118 | 119 | #ifndef ULLONG_MAX 120 | #define ULLONG_MAX 18446744073709551615ULL 121 | #endif 122 | #ifndef LLONG_MAX 123 | #define LLONG_MAX 9223372036854775807LL 124 | #endif 125 | #ifndef LLONG_MIN 126 | #define LLONG_MIN (-LLONG_MAX - 1LL) 127 | #endif 128 | 129 | #ifndef HAVE_STRTOF 130 | #define strtof(nptr,endptr) strtod(nptr,endptr) 131 | #endif 132 | 133 | // global for alarm timeout (implemented in Meter.cc) 134 | extern int g_timeout; 135 | 136 | #endif // __STDINC_H 137 | 138 | -------------------------------------------------------------------------------- /src/include/stdincpp.h: -------------------------------------------------------------------------------- 1 | 2 | /*!\file stdincpp.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | Include this file (stdincpp) in every .h file.\n 25 | This .h file includes all the C++ standard include 26 | files such as map, string and others 27 | 28 | $Id: stdincpp.h 748 2009-09-10 02:54:03Z szander $ 29 | 30 | */ 31 | 32 | #ifndef __STDINCPP_H 33 | #define __STDINCPP_H 34 | 35 | extern "C" { 36 | #include "stdinc.h" 37 | } 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 0)) 47 | // dont need include 48 | #else 49 | #include 50 | #endif 51 | #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 0)) 52 | #include 53 | using namespace __gnu_cxx; 54 | #else 55 | #include 56 | #endif 57 | #include 58 | #include 59 | #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 0)) 60 | #include 61 | #endif 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | 69 | using namespace std; 70 | 71 | // definition of 'safeDelete' and 'safeDeleteArr' as 72 | // a safer replacement for delete and delete [] 73 | 74 | // Put an assert to check if x is NULL, this is to catch 75 | // program "logic" errors early. Even though delete works 76 | // fine with NULL by using assert you are actually catching 77 | // "bad code" very early 78 | // Defining saveDelete using templates 79 | template 80 | inline void saveDelete(T& x) { 81 | assert(x != NULL); 82 | delete x; 83 | x = NULL; 84 | } 85 | template 86 | inline void saveDelete(T*& x) { 87 | assert(x != NULL); 88 | delete x; 89 | x = NULL; 90 | } 91 | // For delete array 92 | template 93 | inline void saveDeleteArr(T& x) { 94 | assert(x != NULL); 95 | delete [] x; 96 | x = NULL; 97 | } 98 | 99 | // tolower (string) 100 | #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 0)) 101 | struct ToLower { 102 | 103 | private: 104 | std::locale loc; 105 | 106 | public: 107 | ToLower () 108 | : loc(std::locale("C")) {;} 109 | 110 | char operator() (char c) { return std::tolower(c,loc); } 111 | 112 | }; 113 | #else 114 | struct ToLower { 115 | ToLower () {;} 116 | char operator() (char c) { return std::tolower(c); } 117 | private: 118 | 119 | }; 120 | #endif 121 | 122 | #endif // __STDINCPP_H 123 | -------------------------------------------------------------------------------- /src/lib/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = httpd getopt_long getpass 2 | -------------------------------------------------------------------------------- /src/lib/getopt_long/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LIBRARIES = libgetopt_long.a 2 | 3 | if ENABLE_DEBUG 4 | AM_CFLAGS = -g -fno-inline -DDEBUG @USE_SSL@ 5 | else 6 | AM_CFLAGS = -O2 @USE_SSL@ 7 | endif 8 | 9 | INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src/include 10 | 11 | libgetopt_long_a_SOURCES = getopt_long.h getopt_long.c 12 | 13 | -------------------------------------------------------------------------------- /src/lib/getpass/COPYING: -------------------------------------------------------------------------------- 1 | COPYRIGHT AND PERMISSION NOTICE 2 | 3 | Copyright (c) 1996 - 2005, Daniel Stenberg, . 4 | 5 | All rights reserved. 6 | 7 | Permission to use, copy, modify, and distribute this software for any purpose 8 | with or without fee is hereby granted, provided that the above copyright 9 | notice and this permission notice appear in all copies. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN 14 | NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 15 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 16 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 17 | OR OTHER DEALINGS IN THE SOFTWARE. 18 | 19 | Except as contained in this notice, the name of a copyright holder shall not 20 | be used in advertising or otherwise to promote the sale, use or other dealings 21 | in this Software without prior written authorization of the copyright holder. 22 | -------------------------------------------------------------------------------- /src/lib/getpass/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LIBRARIES = libgetpass.a 2 | 3 | EXTRA_DIST = COPYING 4 | 5 | if ENABLE_DEBUG 6 | AM_CFLAGS = -g -fno-inline -DDEBUG @USE_SSL@ 7 | else 8 | AM_CFLAGS = -O2 @USE_SSL@ 9 | endif 10 | 11 | INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src/include 12 | 13 | libgetpass_a_SOURCES = getpass.h getpass.c 14 | 15 | -------------------------------------------------------------------------------- /src/lib/getpass/getpass.h: -------------------------------------------------------------------------------- 1 | #ifndef __GETPASS_H 2 | #define __GETPASS_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at http://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | * $Id: getpass.h 748 2009-09-10 02:54:03Z szander $ 24 | ***************************************************************************/ 25 | #ifndef HAVE_GETPASS_R 26 | /* If there's a system-provided function named like this, we trust it is 27 | also found in one of the standard headers. */ 28 | 29 | /* 30 | * Returning NULL will abort the continued operation! 31 | */ 32 | char* getpass_r(const char *prompt, char* buffer, size_t buflen ); 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/lib/httpd/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LIBRARIES = libhttpd.a 2 | 3 | EXTRA_DIST = README 4 | 5 | if ENABLE_DEBUG 6 | AM_CFLAGS = -g -fno-inline -DDEBUG @USE_SSL@ 7 | else 8 | AM_CFLAGS = -O2 @USE_SSL@ 9 | endif 10 | 11 | INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src/include 12 | 13 | libhttpd_a_SOURCES = httpd.h mime.c quote.c ssl.c request.c response.c httpd.c 14 | 15 | -------------------------------------------------------------------------------- /src/lib/httpd/README: -------------------------------------------------------------------------------- 1 | based on webfs from Gerd Knorr 2 | 3 | changes: 4 | -removed dir listing 5 | -removed CGI support 6 | -added POST support 7 | -added hook registration for command handling 8 | -------------------------------------------------------------------------------- /src/lib/httpd/mime.c: -------------------------------------------------------------------------------- 1 | 2 | /*! \file mime.c 3 | 4 | Based on webfs Copyright (C) 1999-2001 Gerd Knorr 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License with 17 | the Debian GNU/Linux distribution in file /usr/share/common-licenses/GPL; 18 | if not, write to the Free Software Foundation, Inc., 59 Temple Place, 19 | Suite 330, Boston, MA 02111-1307 USA 20 | 21 | Description: 22 | mime type handling 23 | 24 | $Id: mime.c 748 2009-09-10 02:54:03Z szander $ 25 | 26 | */ 27 | 28 | #include "config.h" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include "httpd.h" 40 | 41 | 42 | struct MIME { 43 | char ext[8]; 44 | char type[64]; 45 | }; 46 | 47 | static char *mime_default; 48 | static struct MIME *mime_types; 49 | static int mime_count; 50 | 51 | 52 | 53 | static void add_mime(char *ext, char *type) 54 | { 55 | if ((mime_count % 64) == 0) { 56 | mime_types = realloc(mime_types,(mime_count+64)*sizeof(struct MIME)); 57 | } 58 | strcpy(mime_types[mime_count].ext, ext); 59 | strcpy(mime_types[mime_count].type,type); 60 | mime_count++; 61 | } 62 | 63 | char *get_mime(char *file) 64 | { 65 | int i; 66 | char *ext; 67 | 68 | ext = strrchr(file,'.'); 69 | if (NULL == ext) { 70 | return mime_default; 71 | } 72 | ext++; 73 | for (i = 0; i < mime_count; i++) { 74 | if (strcasecmp(ext,mime_types[i].ext) == 0){ 75 | return mime_types[i].type; 76 | } 77 | } 78 | return mime_default; 79 | } 80 | 81 | void init_mime(char *file,char *def) 82 | { 83 | FILE *fp; 84 | char line[128], type[64], ext[8]; 85 | int len,off; 86 | 87 | mime_default = strdup(def); 88 | if ((fp = fopen(file,"r")) == NULL) { 89 | fprintf(stderr,"open %s: %s\n",file,strerror(errno)); 90 | return; 91 | } 92 | while (NULL != fgets(line,127,fp)) { 93 | if (line[0] == '#') { 94 | continue; 95 | } 96 | if (sscanf(line,"%63s%n",type,&len) != 1){ 97 | continue; 98 | } 99 | off = len; 100 | for (;;) { 101 | if (sscanf(line+off,"%7s%n",ext,&len) != 1) { 102 | break; 103 | } 104 | off += len; 105 | add_mime(ext,type); 106 | } 107 | } 108 | fclose(fp); 109 | } 110 | 111 | void shutdown_mime() 112 | { 113 | free(mime_default); 114 | free(mime_types); 115 | } 116 | -------------------------------------------------------------------------------- /src/lib/httpd/quote.c: -------------------------------------------------------------------------------- 1 | 2 | /*! \file quote.c 3 | 4 | Based on webfs Copyright (C) 1999-2001 Gerd Knorr 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License with 17 | the Debian GNU/Linux distribution in file /usr/share/common-licenses/GPL; 18 | if not, write to the Free Software Foundation, Inc., 59 Temple Place, 19 | Suite 330, Boston, MA 02111-1307 USA 20 | 21 | Description: 22 | html quoting/unquoting functions 23 | 24 | $Id: quote.c 748 2009-09-10 02:54:03Z szander $ 25 | 26 | */ 27 | 28 | #include "config.h" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #include "httpd.h" 47 | 48 | 49 | 50 | static char do_quote[256]; 51 | 52 | void init_quote(void) 53 | { 54 | int i; 55 | 56 | for (i = 0; i < 256; i++) { 57 | do_quote[i] = (isalnum(i) || ispunct(i)) ? 0 : 1; 58 | } 59 | do_quote['+'] = 1; 60 | do_quote['#'] = 1; 61 | do_quote['%'] = 1; 62 | } 63 | 64 | char *quote(unsigned char *path, int maxlength) 65 | { 66 | static unsigned char buf[2048]; /* FIXME: threads break this... */ 67 | int i,j,n=strlen(path); 68 | 69 | if (n > maxlength) { 70 | n = maxlength; 71 | } 72 | 73 | for (i=0, j=0; ib)[bpos / BITS_PER_ELEM] & (1ULL << (bpos % BITS_PER_ELEM))) > 0ULL); 38 | } 39 | 40 | 41 | //! set bit bpos in bm 42 | void bmSet(bitmap_t *bm, unsigned long long bpos) 43 | { 44 | if ((bpos / BITS_PER_ELEM) > (unsigned long long)bm->msb) { 45 | bm->msb = bpos / BITS_PER_ELEM; 46 | } 47 | (bm->b)[bpos / BITS_PER_ELEM] |= (1ULL << ((bpos % BITS_PER_ELEM))); 48 | } 49 | 50 | 51 | //! reset bit bpos in bm 52 | void bmReset(bitmap_t *bm, unsigned long long bpos) 53 | { 54 | (bm->b)[bpos / BITS_PER_ELEM] &= ~(1ULL << (bpos % BITS_PER_ELEM)); 55 | while ((bm->msb > 0) && ((bm->b)[bm->msb] == 0ULL)) { 56 | bm->msb -= 1; 57 | } 58 | } 59 | 60 | 61 | //! set all bits in bm 62 | void bmSet(bitmap_t *bm) 63 | { 64 | bm->msb = BITMAP_SIZE-1; 65 | memset((bm->b), 0xFF, BITMAP_SIZE * BITMAP_ELEM_SIZE); 66 | } 67 | 68 | 69 | //! reset all bits in bm 70 | void bmReset(bitmap_t *bm) 71 | { 72 | bm->msb = 0; 73 | memset((bm->b), 0, BITMAP_SIZE * BITMAP_ELEM_SIZE); 74 | } 75 | 76 | 77 | //! test whether bitmap is zero 78 | int bmIsZero(const bitmap_t *bm) 79 | { 80 | if ((bm->msb == 0) && ((bm->b)[0] == 0ULL)) { 81 | return 1; 82 | } else { 83 | return 0; 84 | } 85 | } 86 | 87 | 88 | //! and bm1 and bm2 and return the result in bmres 89 | void bmAnd(const bitmap_t *bm1, const bitmap_t *bm2, bitmap_t *bmres) 90 | { 91 | int min = (bm1->msb < bm2->msb) ? bm1->msb : bm2->msb; 92 | 93 | bmReset(bmres); 94 | 95 | for (int i = min; i >= 0; i--) { 96 | (bmres->b)[i] = (bm1->b)[i] & (bm2->b)[i]; 97 | if ((bmres->msb == 0) && (bmres->b[i] != 0ULL)) { 98 | bmres->msb = i; 99 | } 100 | } 101 | } 102 | 103 | 104 | //! print a bitmap without leading zeros 105 | void bmPrint(const bitmap_t *bm1) 106 | { 107 | int seen1 = 0; 108 | int bit = 0; 109 | 110 | for (int i = bm1->msb; i >= 0; i--) { 111 | for (int j = BITS_PER_ELEM-1; j >= 0; j--) { 112 | bit = ( ((bm1->b)[i] & (1ULL << j)) > 0ULL); 113 | seen1 |= bit; 114 | 115 | if (seen1) { 116 | printf("%d", bit); 117 | } 118 | } 119 | } 120 | if (!seen1) { 121 | printf("0"); 122 | } 123 | } 124 | 125 | //! return 1 (b1 < b2), 0 (b1 == b2) or -1 (b2 > b1) 126 | int bmCompare(const bitmap_t *b1, const bitmap_t *b2) 127 | { 128 | if (b1->msb != b2->msb) { 129 | return (b1->msb < b2->msb); 130 | } 131 | 132 | for (int i = b1->msb; i >= 0; i--) { 133 | if (b1->b[i] < b2->b[i]) { 134 | return 1; 135 | } else if (b1->b[i] > b2->b[i]) { 136 | return 0; 137 | } 138 | } 139 | return 0; 140 | } 141 | -------------------------------------------------------------------------------- /src/netmate/Bitmap.h: -------------------------------------------------------------------------------- 1 | 2 | /*! \file Bitmap.h 3 | 4 | bitmap implementation used by ClassifierRFC 5 | this is faster than the bitset stuff from STL (uses 64bit ints internally) 6 | FIXME not a class (yet) 7 | 8 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 9 | Berlin, Germany 10 | 11 | This file is part of Network Measurement and Accounting System (NETMATE). 12 | 13 | NETMATE is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2 of the License, or 16 | (at your option) any later version. 17 | 18 | NETMATE is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this software; if not, write to the Free Software 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | 27 | Description: 28 | Bitmap implementation for Classifier RFC 29 | 30 | $Id: Bitmap.h 748 2009-09-10 02:54:03Z szander $ 31 | */ 32 | 33 | #ifndef _BITMAP_H_ 34 | #define _BITMAP_H_ 35 | 36 | 37 | #include "stdincpp.h" 38 | #include "ClassifierRFCConf.h" 39 | 40 | 41 | //! size of one element 42 | const int BITMAP_ELEM_SIZE = sizeof(unsigned long long); 43 | 44 | //! bits per element 45 | const int BITS_PER_ELEM = BITMAP_ELEM_SIZE * 8; 46 | 47 | //! bitmap size in bytes 48 | const int BITMAP_SIZE = MAX_RULES / BITS_PER_ELEM; 49 | 50 | 51 | //! msb is used to speed up the precomputation for small rulesets 52 | typedef struct { 53 | //! index to first non-zero element 54 | int msb; 55 | unsigned long long b[BITMAP_SIZE]; 56 | } bitmap_t; 57 | 58 | 59 | //! test if bit bpos is set in bm 60 | int bmTest(bitmap_t *bm, unsigned long long bpos); 61 | 62 | //! set bit bpos in bm 63 | void bmSet(bitmap_t *bm, unsigned long long bpos); 64 | 65 | //! reset bit bpos in bm 66 | void bmReset(bitmap_t *bm, unsigned long long bpos); 67 | 68 | //! set all bits in bm 69 | void bmSet(bitmap_t *bm); 70 | 71 | //! reset all bits in bm 72 | void bmReset(bitmap_t *bm); 73 | 74 | //! test whether bitmap is zero 75 | int bmIsZero(const bitmap_t *bm); 76 | 77 | //! and bm1 and bm2 and return the result in bmres 78 | void bmAnd(const bitmap_t *bm1, const bitmap_t *bm2, bitmap_t *bmres); 79 | 80 | //! print a bitmap without leading zeros 81 | void bmPrint(const bitmap_t *bm1); 82 | 83 | int bmCompare(const bitmap_t *b1, const bitmap_t *b2); 84 | 85 | #endif // _BITMAP_H_ 86 | -------------------------------------------------------------------------------- /src/netmate/ClassifierRFCConf.h: -------------------------------------------------------------------------------- 1 | 2 | /*! \file ClassifierRFCConf.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | configuration of RFC classifier used by Bitmap and ClassifierRFC 25 | 26 | $Id: ClassifierRFCConf.h 748 2009-09-10 02:54:03Z szander $ 27 | 28 | */ 29 | 30 | #ifndef _CLASSIFIER_RFC_CONF_H_ 31 | #define _CLASSIFIER_RFC_CONF_H_ 32 | 33 | 34 | /*! max number of rules supported (must be power of 2!) 35 | multiply by 2 because each rule can result in 2 equiv classes (bidir rules) 36 | */ 37 | const unsigned short MAX_RULES = 1024 * 2; 38 | 39 | //! max number of chunks (should be power of 2) 40 | const unsigned short MAX_CHUNKS = 32; 41 | 42 | //! max number of phases 43 | const unsigned short MAX_PHASES = 6; 44 | 45 | //! define this for faster incremental add but higher memory usage 46 | #define PREALLOC_EQUIV_CLASSES 47 | const unsigned PREALLOC_CLASSES = 32; 48 | 49 | //! define this for remapping phase 0 chunks entries after rule delete 50 | //#define REMAP_AFTER_DELETE 51 | 52 | #endif // _CLASSIFIER_RFC_CONF_H_ 53 | -------------------------------------------------------------------------------- /src/netmate/CommandLineArgs.h: -------------------------------------------------------------------------------- 1 | 2 | /*! \file CommandLineArgs.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | parses command line args and puts values in config db 25 | 26 | $Id: CommandLineArgs.h 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #ifndef _COMMANDLINEARGS_H_ 30 | #define _COMMANDLINEARGS_H_ 31 | 32 | 33 | #include "stdincpp.h" 34 | #include "getopt_long.h" 35 | 36 | #include "Error.h" 37 | #include "Logger.h" 38 | 39 | 40 | 41 | //! command line arg 42 | typedef struct 43 | { 44 | int flag; //!< is flag 45 | string param; //!< parameter(s) 46 | string help; //!< help text for the argument 47 | string name; //!< name of the argument 48 | string group; //!< group of the argument 49 | string longname; //!< longname of the argument 50 | } commandLineArg_t; 51 | 52 | //! sort command line options alphabetically: a,A,b,B,c,D etc. 53 | struct ltarg 54 | { 55 | bool operator()(const char a1, const char a2) const 56 | { 57 | double t1 = a1, t2 = a2; 58 | 59 | if (t1 < 'a') { 60 | t1 += ('a'-'A') + 0.5; 61 | } 62 | if (t2 < 'a') { 63 | t2 += ('a'-'A') + 0.5; 64 | } 65 | return (t1 < t2); 66 | } 67 | }; 68 | 69 | //! command line argument list 70 | typedef map commandLineArgList_t; 71 | typedef map::iterator commandLineArgListIter_t; 72 | 73 | //! list of values for each argument 74 | typedef map commandLineArgValList_t; 75 | typedef map::iterator commandLineArgValListIter_t; 76 | 77 | //! from getopt.h 78 | typedef struct option option_t; 79 | 80 | class CommandLineArgs 81 | { 82 | private: 83 | 84 | commandLineArgList_t args; //!< the command line arguments list 85 | commandLineArgValList_t argVals; //!< and their values 86 | 87 | /*! \short add a possible command line option to list own known options 88 | \arg \c flag 1 if option if only flag (on/off) and has no parameters 89 | \arg \c opt the option character 90 | \arg \c name the option name 91 | \arg \c param parameter(s) 92 | \arg \c help a textual option description 93 | \arg \c group the option group 94 | \arg \c longname the long name (for --longname format) for this option 95 | */ 96 | void addEntry( int flag, char opt, string name, string param, string help, string group, 97 | string longname); 98 | 99 | public: 100 | 101 | //! construct a new CommandLineArgs object 102 | CommandLineArgs(); 103 | 104 | //! add a command line argument expecting a value 105 | void add(char opt, string name, string param="", string help="", string group="", string longname=""); 106 | 107 | //! add a command line argument flag (yes/no) 108 | void addFlag(char opt, string name, string help="", string group="", string longname=""); 109 | 110 | //! get the value for an argument 111 | string getArgValue(char opt); 112 | 113 | //! parse the command line args supplied to main 114 | int parseArgs(int argc, char *argv[]); 115 | 116 | //! get pointer to argument values 117 | commandLineArgValList_t *getArgVals() 118 | { 119 | return &argVals; 120 | } 121 | 122 | //! get pointer to argument definition list 123 | commandLineArgList_t *getArgList() 124 | { 125 | return &args; 126 | } 127 | 128 | //! get usage string (is build from options description) 129 | string getUsage(); 130 | 131 | }; 132 | 133 | 134 | #endif // _COMMANDLINEARGS_H_ 135 | -------------------------------------------------------------------------------- /src/netmate/ConfigParser.h: -------------------------------------------------------------------------------- 1 | 2 | /* \file ConfigParser.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | parses configuration file and adds item into config db 25 | 26 | $Id: ConfigParser.h 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #ifndef _CONFIGPARSER_H_ 30 | #define _CONFIGPARSER_H_ 31 | 32 | 33 | #include "stdincpp.h" 34 | #include "libxml/parser.h" 35 | #include "Logger.h" 36 | #include "XMLParser.h" 37 | 38 | 39 | //! configuration item 40 | typedef struct configItem 41 | { 42 | string group; 43 | string module; 44 | string name; 45 | string value; 46 | string type; 47 | } configItem_t; 48 | 49 | //! overload operator << for configItem_t so that it can be thorown in an ostream 50 | ostream& operator<< ( ostream &os, configItem_t &item ); 51 | 52 | //! allow or deny 53 | typedef enum 54 | { 55 | ALLOW=0, 56 | DENY=1 57 | } ad_t; 58 | 59 | //! access configuration item 60 | typedef struct 61 | { 62 | ad_t ad; 63 | string value; 64 | string type; 65 | /*! may contain IP address if host based item and value is 66 | valid IP address or host name */ 67 | string resolve_addr; 68 | } configADItem_t; 69 | 70 | //! overload operator << for configADItem_t so that it can be thorown in an ostream 71 | ostream& operator<< ( ostream &os, configADItem_t &item ); 72 | 73 | //! list of config items 74 | class configItemList_t : public list { 75 | public: 76 | string getValue( string name ); 77 | }; 78 | 79 | typedef list::iterator configItemListIter_t; 80 | 81 | //! list of access items 82 | typedef list configADList_t; 83 | typedef list::iterator configADListIter_t; 84 | 85 | ostream& operator<< ( ostream &os, configItemList_t &list ); 86 | ostream& operator<< ( ostream &os, configADList_t &list ); 87 | 88 | 89 | class ConfigParser : public XMLParser 90 | { 91 | 92 | private: 93 | 94 | static string bindir; // 0) { 75 | double _when = when.tv_sec*1e6+when.tv_usec; 76 | double _ival = interval*1000; 77 | 78 | _when = floor(_when/_ival)*_ival + _ival; 79 | 80 | when.tv_sec = (unsigned long) floor(_when/1e6); 81 | when.tv_usec = (unsigned long) (_when-when.tv_sec*1e6); 82 | } 83 | } 84 | 85 | 86 | void Event::advance() 87 | { 88 | struct timeval ad; 89 | 90 | ad.tv_sec = (unsigned long) interval/1000; 91 | ad.tv_usec = (unsigned long) ( (interval % 1000)*1000); 92 | 93 | when = Timeval::add(when, ad); 94 | } 95 | 96 | 97 | void Event::dump( ostream &os ) 98 | { 99 | os << eventNames[type] << " event: " 100 | << when.tv_sec*1e6+when.tv_usec << " (" << interval << ")"; 101 | } 102 | 103 | 104 | ostream& operator<< (ostream &os, Event &ev ) 105 | { 106 | ev.dump(os); 107 | return os; 108 | } 109 | -------------------------------------------------------------------------------- /src/netmate/EventScheduler.h: -------------------------------------------------------------------------------- 1 | 2 | /*! \file EventScheduler.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | event scheduling 25 | 26 | $Id: EventScheduler.h 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #ifndef _EVENTSCHEDULER_H_ 30 | #define _EVENTSCHEDULER_H_ 31 | 32 | 33 | #include "stdincpp.h" 34 | #include "Logger.h" 35 | #include "Rule.h" 36 | #include "Event.h" 37 | #include "Timeval.h" 38 | 39 | 40 | class Event; // forward declaration 41 | 42 | //! comparison operator for events 43 | struct lttv 44 | { 45 | bool operator()(const struct timeval t1, const struct timeval t2) const 46 | { 47 | return (Timeval::cmp(t1, t2) < 0); 48 | } 49 | }; 50 | 51 | //! event list definition (sorted by expiry time) 52 | typedef multimap eventList_t; 53 | typedef multimap::iterator eventListIter_t; 54 | 55 | 56 | /*! \short schedule timed events and execute the corresponding function at the correct time 57 | 58 | The EventScheduler's task is to schedule and execute timed events in the 59 | meter system such as timed addition/removal of tasks (rules). 60 | A number of different events that are derived from the basic event class 61 | can be put into the EventSchedulers event queue. 62 | */ 63 | 64 | class EventScheduler 65 | { 66 | private: 67 | 68 | Logger *log; //!< link to global logger object 69 | int ch; //!< logging channel number used by objects of this class 70 | 71 | eventList_t events; //!< event list 72 | 73 | public: 74 | 75 | //! construct and initialize an EventScheduler object 76 | EventScheduler(); 77 | 78 | 79 | //! destroy an EventScheduler object 80 | ~EventScheduler(); 81 | 82 | 83 | /*! \short add an Event to the event queue 84 | 85 | \arg \c ev - an event (or an object derived from Event) that is 86 | schdeuled for a particular time (possibly repeatedly 87 | at a given interval) 88 | */ 89 | void addEvent(Event *ev); 90 | 91 | 92 | /*! \short delete all events for a given rule 93 | 94 | delete all Events related to the specified rule from the list of events 95 | 96 | \arg \c uid - the unique identification number of the rule 97 | */ 98 | void delRuleEvents(int uid); 99 | 100 | // get pointer to first/next event 101 | Event *getNextEvent(); 102 | 103 | //! requeus (if recurring) the event ev advancing its expiry time 104 | void reschedNextEvent(Event *ev); 105 | 106 | //! return the time of the next event due 107 | struct timeval getNextEventTime(); 108 | 109 | //! dump an EventScheduler object 110 | void dump(ostream &os); 111 | 112 | }; 113 | 114 | 115 | //! overload for << so that a EventScheduler object can be thrown into an ostream 116 | ostream& operator<<(ostream &os, EventScheduler &es); 117 | 118 | 119 | 120 | #endif // _EVENTSCHEDULER_H_ 121 | -------------------------------------------------------------------------------- /src/netmate/ExportList.h: -------------------------------------------------------------------------------- 1 | 2 | /*! \file ExportList.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | $Id: ExportList.h 748 2009-09-10 02:54:03Z szander $ 24 | */ 25 | 26 | #ifndef _EXPORTLIST_H_ 27 | #define _EXPORTLIST_H_ 28 | 29 | 30 | #include "stdincpp.h" 31 | #include "ProcModuleInterface.h" 32 | 33 | 34 | //! column definition 35 | typedef struct { 36 | enum DataType_e type; 37 | string label; 38 | } column_t; 39 | 40 | //! list of columns 41 | typedef vector< column_t > exportColumns_t; 42 | typedef vector< column_t >::iterator exportColumnsIter_t; 43 | 44 | //! FIXME add documentation 45 | typedef struct { 46 | exportColumns_t cols; 47 | int nrows; 48 | } exportTable_t; 49 | 50 | //! table definition 51 | typedef vector< exportTable_t > exportLists_t; 52 | typedef vector< exportTable_t >::iterator exportListsIter_t; 53 | 54 | /*! 55 | This class encapsulates the name and type data for one 56 | proc module. It stores (possibly multiple) list(s) and 57 | their width, and the types and names of the columns 58 | */ 59 | 60 | class ExportList 61 | { 62 | private: 63 | 64 | exportLists_t exportLists; //! list of configured export lists for a proc module 65 | 66 | public: 67 | 68 | /*! \brief construct a new ExportLists object 69 | 70 | \arg crttList - the export structure specification from the proc module 71 | */ 72 | ExportList( typeInfo_t* rttList ); 73 | 74 | //! return the size of the export list 75 | inline unsigned int size() 76 | { 77 | return exportLists.size(); 78 | } 79 | 80 | //! get pointer to the export list 81 | inline exportTable_t* getList(unsigned int i) 82 | { 83 | return &exportLists[i]; 84 | } 85 | 86 | /*! \brief construct a new (sub)list 87 | 88 | This function parses the supplied runtime type information (rttList) and 89 | stores internally the types and names for a tables of the specified size. 90 | 91 | \arg cncols - number of columns in this table 92 | \arg cnrows - number of rows in this table (==0 means that true size is 93 | only known at runtime from export data record (MetricData)) 94 | \arg crttList - the export structure specification from the proc module 95 | at the position where a list starts (behind LIST entry) 96 | */ 97 | void newList( int ncols, typeInfo_t* rttList, int nrows ); 98 | 99 | //! write this object to an ostream 100 | void dump( ostream &os ); 101 | 102 | }; 103 | 104 | 105 | ostream& operator<< ( ostream &os, ExportList &list ); 106 | 107 | 108 | #endif // _EXPORTLIST_H_ 109 | -------------------------------------------------------------------------------- /src/netmate/ExportModule.cc: -------------------------------------------------------------------------------- 1 | 2 | /*!\file netmate/ExportModule.cc 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | container class for export module information 25 | 26 | $Id: ExportModule.cc 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #include "ExportModule.h" 30 | 31 | 32 | /* ----- init static class members ----- */ 33 | 34 | Logger *ExportModule::s_log = NULL; 35 | int ExportModule::s_ch = 0; 36 | 37 | 38 | /* ------------------------- ExportModule ------------------------- */ 39 | 40 | ExportModule::ExportModule( ConfigManager *conf, string libName, 41 | string libFileName, libHandle_t libhandle ) : 42 | Module( libName, libFileName, libhandle ), timersActive(0) 43 | { 44 | int res; 45 | 46 | if (s_log == NULL ) { 47 | s_log = Logger::getInstance(); 48 | s_ch = s_log->createChannel("ExportModule"); 49 | } 50 | 51 | #ifdef DEBUG 52 | s_log->dlog(s_ch, "Creating" ); 53 | #endif 54 | 55 | checkMagic(EXPORT_MAGIC); 56 | 57 | funcList = (ExportModuleInterface_t *) loadAPI( "func" ); 58 | 59 | setOwnName(libName); 60 | 61 | res = funcList->initModule(conf); 62 | if (res != 0 ) { 63 | s_log->elog(s_ch, "initialization of module '%s' failed: %s", 64 | libName.c_str(), funcList->getErrorMsg(res) ); 65 | } 66 | } 67 | 68 | 69 | /* ------------------------- ~ExportModule ------------------------- */ 70 | 71 | ExportModule::~ExportModule() 72 | { 73 | funcList->destroyModule(); 74 | #ifdef DEBUG 75 | s_log->dlog(s_ch, "Destroyed" ); 76 | #endif 77 | } 78 | 79 | 80 | /* -------------------- addTimerEvents -------------------- */ 81 | 82 | void ExportModule::addTimerEvents( EventScheduler &evs ) 83 | { 84 | if (timersActive != 0) { 85 | return; 86 | } 87 | 88 | ExportModuleInterface_t *mapi = getAPI(); 89 | timers_t *timers = mapi->getTimers(); 90 | 91 | if (timers != NULL) { 92 | while (timers->flags != TM_END) { 93 | evs.addEvent(new ExportTimerEvent(mapi->timeout, timers++)); 94 | } 95 | } 96 | timersActive = 1; 97 | } 98 | 99 | 100 | /* ------------------------- dump ------------------------- */ 101 | 102 | void ExportModule::dump( ostream &os ) 103 | { 104 | Module::dump(os); 105 | } 106 | 107 | 108 | /* ------------------------- operator<< ------------------------- */ 109 | 110 | ostream& operator<< ( ostream &os, ExportModule &obj ) 111 | { 112 | obj.dump(os); 113 | return os; 114 | } 115 | 116 | -------------------------------------------------------------------------------- /src/netmate/ExportModule.h: -------------------------------------------------------------------------------- 1 | 2 | /*! \file netmate/ExportModule.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | $Id: ExportModule.h 748 2009-09-10 02:54:03Z szander $ 24 | */ 25 | 26 | #ifndef _EXPORTMODULE_H_ 27 | #define _EXPORTMODULE_H_ 28 | 29 | 30 | #include "stdincpp.h" 31 | #include "Logger.h" 32 | #include "Module.h" 33 | #include "ConfigManager.h" 34 | #include "ExportModuleInterface.h" 35 | #include "EventScheduler.h" 36 | 37 | 38 | /*! \short container class that stores information about an export module 39 | 40 | container class - stores information about an export module such as 41 | name, libhandle and reference counter 42 | */ 43 | 44 | class ExportModule : public Module 45 | { 46 | private: 47 | 48 | static Logger *s_log; //!< link to the global Logger instance 49 | static int s_ch; //!< logging channel number for ExportModule class 50 | 51 | //!< struct of functions pointers for dynamically loaded library 52 | ExportModuleInterface_t *funcList; 53 | 54 | //!< number of active timers 55 | unsigned int timersActive; 56 | 57 | public: 58 | 59 | //! return block of function pointers (API) for a module 60 | inline ExportModuleInterface_t *getAPI() 61 | { 62 | return funcList; 63 | } 64 | 65 | //! return a module's version 66 | virtual int getVersion() 67 | { 68 | return funcList->version; 69 | } 70 | 71 | 72 | virtual string getModuleType() 73 | { 74 | return "data export"; 75 | } 76 | 77 | 78 | /*! \short construct and initialize an ExportModule object 79 | 80 | take the library handle of an export module and retrieve all the 81 | other information (name, uid, function list) via this handle 82 | 83 | \arg \c conf - the global available configuration manager 84 | \arg \c libname - name of the export module 85 | \arg \c filename - name of module including path and extension 86 | \arg \c libhandle - system handle for loaded library (see dlopen) 87 | */ 88 | ExportModule( ConfigManager *conf, string libName, 89 | string libFileName, libHandle_t libhandle ); 90 | 91 | //! destroy an ExportModule object 92 | ~ExportModule(); 93 | 94 | /*! \short add timers of this module as new events to the event 95 | scheduler component (but only once per module!) 96 | \arg \c evs - the meter's event scheduler component 97 | */ 98 | void addTimerEvents( EventScheduler &evs ); 99 | 100 | 101 | //! dump an ExportModule object 102 | void dump( ostream &os ); 103 | 104 | }; 105 | 106 | 107 | //! overload for <<, so that an ExportModule object can be thrown into an ostream 108 | ostream& operator<< ( ostream &os, ExportModule &obj ); 109 | 110 | 111 | #endif // _EXPORTMODULE_H_ 112 | -------------------------------------------------------------------------------- /src/netmate/FilterDefParser.h: -------------------------------------------------------------------------------- 1 | 2 | /* \file FilterDefParser.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | parse filter definition files 25 | 26 | $Id: FilterDefParser.h 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #ifndef _FILTERDEFPARSER_H_ 30 | #define _FILTERDEFPARSER_H_ 31 | 32 | 33 | #include "stdincpp.h" 34 | #include "libxml/parser.h" 35 | #include "Logger.h" 36 | #include "XMLParser.h" 37 | #include "FilterValue.h" 38 | 39 | 40 | const string DEF_MASK_IP = "255.255.255.255"; 41 | const string DEF_MASK_IP6 = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"; 42 | 43 | 44 | //! conditional item 45 | typedef struct 46 | { 47 | string name; 48 | 49 | FilterValue mask; 50 | FilterValue val; 51 | 52 | } condItem_t; 53 | 54 | 55 | //! reference points 56 | typedef enum 57 | { 58 | MAC = 0, 59 | IP, 60 | TRANS, 61 | DATA 62 | } refer_t; 63 | 64 | 65 | //! filter definition 66 | typedef struct 67 | { 68 | string name; 69 | string rname; 70 | string type; 71 | refer_t refer; 72 | condItem_t cond; 73 | unsigned short offs; 74 | unsigned short len; 75 | FilterValue mask; 76 | //! position of lowest set bit in mask (only computed for len == 1) 77 | unsigned char shift; 78 | } filterDefItem_t; 79 | 80 | 81 | //! filter list 82 | typedef map filterDefList_t; 83 | typedef map::iterator filterDefListIter_t; 84 | 85 | 86 | class FilterDefParser : public XMLParser 87 | { 88 | 89 | private: 90 | 91 | Logger *log; 92 | int ch; 93 | 94 | //! parse filter definition 95 | filterDefItem_t parseDef(xmlNodePtr cur); 96 | 97 | //! parse reference point 98 | refer_t parseRefer(string refer); 99 | 100 | //! get reference name 101 | string getRefer(refer_t r); 102 | 103 | public: 104 | 105 | FilterDefParser(string fname = ""); 106 | 107 | virtual ~FilterDefParser() {} 108 | 109 | //! add parsed filter definitions to list 110 | virtual void parse(filterDefList_t *list); 111 | }; 112 | 113 | 114 | #endif // _FILTERDEFPARSER_H_ 115 | -------------------------------------------------------------------------------- /src/netmate/FilterValParser.cc: -------------------------------------------------------------------------------- 1 | 2 | /* \file FilterValParser.cc 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | parse filter constant files 25 | 26 | $Id: FilterValParser.cc 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #include "FilterValParser.h" 30 | #include "constants.h" 31 | 32 | 33 | FilterValParser::FilterValParser(string filename) 34 | : XMLParser(FILTERVAL_DTD, filename, "FILTERVAL") 35 | { 36 | log = Logger::getInstance(); 37 | ch = log->createChannel("FilterValParser" ); 38 | } 39 | 40 | 41 | filterValItem_t FilterValParser::parseDef(xmlNodePtr cur) 42 | { 43 | filterValItem_t item; 44 | string mask; 45 | 46 | // get DEF 47 | item.name = xmlCharToString(xmlGetProp(cur, (const xmlChar *)"NAME")); 48 | if (item.name.empty()) { 49 | throw Error("Filter Val Error: missing name at line %d", XML_GET_LINE(cur)); 50 | } 51 | // use lower case internally 52 | transform(item.name.begin(), item.name.end(), item.name.begin(), ToLower()); 53 | 54 | item.type = xmlCharToString(xmlGetProp(cur, (const xmlChar *)"TYPE")); 55 | item.svalue = xmlCharToString(xmlNodeListGetString(XMLDoc, cur->xmlChildrenNode, 1)); 56 | if (item.svalue.empty()) { 57 | throw Error("Filter Val Error: missing value at line %d", XML_GET_LINE(cur)); 58 | } 59 | // use lower case internally 60 | transform(item.svalue.begin(), item.svalue.end(), item.svalue.begin(), ToLower()); 61 | // do not parse value here 62 | 63 | return item; 64 | } 65 | 66 | 67 | void FilterValParser::parse(filterValList_t *list) 68 | { 69 | xmlNodePtr cur; 70 | 71 | cur = xmlDocGetRootElement(XMLDoc); 72 | 73 | cur = cur->xmlChildrenNode; 74 | while (cur != NULL) { 75 | 76 | if ((!xmlStrcmp(cur->name, (const xmlChar *)"DEF")) && (cur->ns == ns)) { 77 | // parse 78 | filterValItem_t item = parseDef(cur); 79 | // add 80 | list->insert(make_pair(item.name, item)); 81 | #ifdef DEBUG 82 | log->dlog(ch, "%s = %s", item.name.c_str(), item.svalue.c_str()); 83 | #endif 84 | } 85 | 86 | cur = cur->next; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/netmate/FilterValParser.h: -------------------------------------------------------------------------------- 1 | 2 | /* \file FilterValParser.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | parse filter constant files 25 | 26 | $Id: FilterValParser.h 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #ifndef _FILTERVALPARSER_H_ 30 | #define _FILTERVALPARSER_H_ 31 | 32 | 33 | #include "stdincpp.h" 34 | #include "libxml/parser.h" 35 | #include "Logger.h" 36 | #include "XMLParser.h" 37 | #include "FilterValue.h" 38 | #include "FilterDefParser.h" 39 | 40 | 41 | //! filter value 42 | typedef struct 43 | { 44 | string name; 45 | string type; 46 | string svalue; 47 | } filterValItem_t; 48 | 49 | //! filter value list 50 | typedef map filterValList_t; 51 | typedef map::iterator filterValListIter_t; 52 | 53 | 54 | class FilterValParser : public XMLParser 55 | { 56 | private: 57 | 58 | Logger *log; 59 | int ch; 60 | 61 | //! parse filter value definition 62 | filterValItem_t parseDef(xmlNodePtr cur); 63 | 64 | public: 65 | 66 | FilterValParser(string fname); 67 | 68 | virtual ~FilterValParser() {} 69 | 70 | //! add parsed filter values to list 71 | virtual void parse(filterValList_t *list); 72 | }; 73 | 74 | 75 | #endif // _FILTERVALPARSER_H_ 76 | -------------------------------------------------------------------------------- /src/netmate/FilterValue.cc: -------------------------------------------------------------------------------- 1 | 2 | /* \file FilterValue.cc 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | Class used to store filter/match values with 25 | flexible length in network byteorder 26 | 27 | $Id: FilterValue.cc 748 2009-09-10 02:54:03Z szander $ 28 | */ 29 | 30 | #include "FilterValue.h" 31 | #include "Error.h" 32 | #include "ParserFcts.h" 33 | 34 | 35 | FilterValue::FilterValue(string type, string value) 36 | : ftype(type), len(0) 37 | { 38 | 39 | if (type == "UInt8") { 40 | setValue((unsigned char) ParserFcts::parseULong(value)); 41 | } else if (type == "SInt8") { 42 | setValue((char) ParserFcts::parseULong(value)); 43 | } else if (type == "UInt16") { 44 | setValue((unsigned short) ParserFcts::parseULong(value)); 45 | } else if (type == "SInt16") { 46 | setValue((short) ParserFcts::parseLong(value)); 47 | } else if (type == "UInt32") { 48 | setValue((unsigned long) ParserFcts::parseULong(value)); 49 | } else if (type == "SInt32") { 50 | setValue((long) ParserFcts::parseULong(value)); 51 | } else if (type == "IPAddr") { 52 | setValue(ParserFcts::parseIPAddr(value)); 53 | } else if (type == "IP6Addr") { 54 | setValue(ParserFcts::parseIP6Addr(value)); 55 | } else if (type == "Binary") { 56 | setValue(value.length(), value.c_str()); 57 | } else if (type == "String") { 58 | setValue(value.c_str()); 59 | } else { 60 | throw Error("Unsupported type for filter value: %s", type.c_str()); 61 | } 62 | } 63 | 64 | int FilterValue::getTypeLength(string type) 65 | { 66 | if ((type == "UInt8") || (type == "SInt8")) { 67 | return 1; 68 | } else if ((type == "UInt16") || (type == "SInt16")) { 69 | return 2; 70 | } else if ((type == "UInt32") || (type == "SInt32")) { 71 | return 4; 72 | } else if (type == "IPAddr") { 73 | return 4; 74 | } else if (type == "IP6Addr") { 75 | return 16; 76 | } else if (type == "Binary") { 77 | return 0; 78 | } else if (type == "String") { 79 | return 0; 80 | } else { 81 | throw Error("Unsupported type for filter value: %s", type.c_str()); 82 | } 83 | } 84 | 85 | string FilterValue::getString() 86 | { 87 | ostringstream s; 88 | char buf[64]; 89 | 90 | if (len > 0) { 91 | 92 | if ((ftype == "UInt8") || (ftype =="Int8")) { 93 | s << (int) val[0]; 94 | } else if (ftype == "UInt16") { 95 | s << ntohs(*((unsigned short *) val)); 96 | } else if (ftype == "Int16") { 97 | s << ntohs(*((short *) val)); 98 | } else if (ftype == "Uint32") { 99 | s << ntohl(*((unsigned long *) val)); 100 | } else if (ftype == "Int32") { 101 | s << ntohl(*((long *) val)); 102 | } else if (ftype == "IPAddr") { 103 | inet_ntop(AF_INET, val, buf, 64); 104 | s << buf; 105 | } else if (ftype == "IP6Addr") { 106 | inet_ntop(AF_INET6, val, buf, 64); 107 | s << buf; 108 | } else if (ftype == "Binary") { 109 | s << "0x" << hex << setfill('0'); 110 | for (int i=0; i < len; i++) { 111 | s << setw(2) << (int) val[i]; 112 | } 113 | } 114 | 115 | } 116 | 117 | return s.str(); 118 | } 119 | -------------------------------------------------------------------------------- /src/netmate/FlowCreator.cc: -------------------------------------------------------------------------------- 1 | 2 | /*! \file FlowCreator.cc 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | create flows based on flow key 25 | 26 | $Id: FlowCreator.cc 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #include "FlowCreator.h" 30 | 31 | 32 | FlowCreator::FlowCreator() 33 | { 34 | flows.resize(START_BUCKETS); 35 | idSource = RuleIdSource(1); 36 | } 37 | 38 | FlowCreator::~FlowCreator() 39 | { 40 | flowListIter_t tmp; 41 | 42 | flowListIter_t i = flows.begin(); 43 | while (i != flows.end()) { 44 | tmp = i; 45 | i++; 46 | deleteFlow(tmp); 47 | } 48 | } 49 | 50 | void FlowCreator::deleteFlow(flowListIter_t f) 51 | { 52 | unsigned char *tmp; 53 | 54 | idSource.freeId(f->second.flowId); 55 | tmp = f->first.keyData; 56 | flows.erase(f); 57 | saveDeleteArr(tmp); 58 | } 59 | 60 | void FlowCreator::deleteFlow(flowInfo_t *fi) 61 | { 62 | hkey_t k; 63 | unsigned char *tmp; 64 | 65 | idSource.freeId(fi->flowId); 66 | tmp = fi->keyData; 67 | k.len = fi->len; 68 | k.keyData = fi->keyData; 69 | flows.erase(k); 70 | saveDeleteArr(tmp); 71 | } 72 | 73 | flowInfo_t *FlowCreator::addFlow(const unsigned char *keyData, unsigned short len) 74 | { 75 | hkey_t k; 76 | flowInfo_t entry; 77 | 78 | k.keyData = new unsigned char[len]; 79 | memcpy(k.keyData, keyData, len); 80 | entry.keyData = k.keyData; 81 | entry.len = len; 82 | entry.flowId = idSource.newId(); 83 | entry.newFlow = 1; 84 | k.len = len; 85 | 86 | pair res = flows.insert(make_pair(k, entry)); 87 | 88 | return &res.first->second; 89 | } 90 | 91 | flowInfo_t *FlowCreator::getFlow(const unsigned char *keyData, unsigned short len) 92 | { 93 | hkey_t k; 94 | flowListIter_t f; 95 | 96 | k.len = len; 97 | k.keyData = (unsigned char *) keyData; 98 | 99 | f = flows.find(k); 100 | 101 | if (f == flows.end()) { 102 | return NULL; 103 | } 104 | 105 | return &f->second; 106 | } 107 | -------------------------------------------------------------------------------- /src/netmate/FlowRecord.cc: -------------------------------------------------------------------------------- 1 | 2 | /*!\file FlowRecord.cc 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | implementation for FlowRecord data container class 25 | 26 | $Id: FlowRecord.cc 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #include "Error.h" 30 | #include "Logger.h" 31 | #include "FlowRecord.h" 32 | 33 | 34 | /* ------------------------- FlowRecord ------------------------- */ 35 | 36 | FlowRecord::FlowRecord( int id, string rname, int final ) 37 | : deleteRec(0) 38 | { 39 | ruleId = id; 40 | time = ::time(NULL); 41 | ruleName = rname; 42 | finalRec = final; 43 | } 44 | 45 | 46 | /* ------------------------- ~FlowRecord ------------------------- */ 47 | 48 | FlowRecord::~FlowRecord() 49 | { 50 | moduleDataListIter_t iter; 51 | 52 | for ( iter = resultData.begin(); iter != resultData.end(); iter++ ) { 53 | // delete a MetricData object 54 | saveDelete(*iter); 55 | } 56 | } 57 | 58 | 59 | /* ------------------------- addData ------------------------- */ 60 | 61 | void FlowRecord::addData( MetricData *mdata ) 62 | { 63 | resultData.push_back( mdata ); 64 | curr = resultData.begin(); 65 | } 66 | 67 | 68 | /* ------------------------- getData ------------------------- */ 69 | 70 | MetricData* FlowRecord::getNextData() 71 | { 72 | if (curr == resultData.end()) { 73 | return NULL; 74 | } else { 75 | return *(curr)++; 76 | } 77 | } 78 | 79 | 80 | /* ------------------------- dump ------------------------- */ 81 | 82 | void FlowRecord::dump( ostream &os ) 83 | { 84 | moduleDataListIter_t iter; 85 | 86 | for ( iter = resultData.begin(); iter != resultData.end(); iter++ ) { 87 | os << (*iter)->toString() << " "; 88 | } 89 | 90 | os << endl; 91 | } 92 | 93 | 94 | /* ------------------------- operator<< ------------------------- */ 95 | 96 | ostream& operator<< ( ostream &os, FlowRecord &obj ) 97 | { 98 | obj.dump(os); 99 | return os; 100 | } 101 | -------------------------------------------------------------------------------- /src/netmate/FlowRecord.h: -------------------------------------------------------------------------------- 1 | 2 | /*! \file FlowRecord.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | header file for CollectionResult data container class 25 | 26 | $Id: FlowRecord.h 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #ifndef _FLOWRECORDLIST_H_ 30 | #define _FLOWRECORDLIST_H_ 31 | 32 | 33 | #include "stdincpp.h" 34 | #include "ModuleLoader.h" 35 | #include "MetricData.h" 36 | #include "Module.h" 37 | 38 | 39 | /*! \short brief FlowRecord class description 40 | 41 | a FlowRecord is an object which stores the results of one 42 | collection for one metering rule including the measurement data 43 | from one or more evaluation modules used by this metering rule. 44 | Additional information include taskID, timestamp and moduleName + 45 | typeInformation for every used evaluation module 46 | */ 47 | 48 | //! module data list 49 | typedef list moduleDataList_t; 50 | typedef list::iterator moduleDataListIter_t; 51 | 52 | 53 | class FlowRecord 54 | { 55 | private: 56 | 57 | //! corresponding rule identifier 58 | int ruleId; 59 | 60 | //! creation time 61 | time_t time; 62 | 63 | //! data 64 | moduleDataList_t resultData; 65 | 66 | //! pointer to current metric data 67 | moduleDataListIter_t curr; 68 | 69 | //! name of the rule 70 | string ruleName; 71 | 72 | //! is interim or final flow record; 73 | int finalRec; 74 | 75 | //! indicate that this flow record should be deleted after poped from 76 | // the exporter queue 77 | int deleteRec; 78 | 79 | public: 80 | 81 | //! construct and initialize a FlowRecord object 82 | FlowRecord( int ruleId, string rname, int final = 0); 83 | 84 | //! destroy a FlowRecord object 85 | ~FlowRecord(); 86 | 87 | /*! \short return timestamp for creation of this FlowRecord 88 | /returns time of object creation in seconds from 1.1.1970 89 | */ 90 | time_t when() 91 | { 92 | return time; 93 | } 94 | 95 | void markForDelete() 96 | { 97 | deleteRec = 1; 98 | } 99 | 100 | int getDelete() 101 | { 102 | return deleteRec; 103 | } 104 | 105 | void setFinal(int final) 106 | { 107 | finalRec = final; 108 | } 109 | 110 | int isFinal() 111 | { 112 | return finalRec; 113 | } 114 | 115 | //! return rule id of this flow record 116 | int getRuleId() 117 | { 118 | return ruleId; 119 | } 120 | 121 | //! return rule name of this flow record 122 | string getRuleName() 123 | { 124 | return ruleName; 125 | } 126 | 127 | //! add other data exported from an evaluation module to a FlowRecord 128 | void addData( MetricData *mdata ); 129 | 130 | /* \short get the i-th measurement result from the collection 131 | 132 | returns a pointer to the next stored MetricData object and 133 | advances the internal pointer to the next MetricData or 134 | returns NULL if there is no more results data stored in this 135 | object (end of list) 136 | */ 137 | MetricData* getNextData(); 138 | 139 | //! reset internal data pointer to start of data list */ 140 | void startExport() 141 | { 142 | curr = resultData.begin(); 143 | } 144 | 145 | //! dump a FlowRecord object 146 | void dump( ostream &os ); 147 | 148 | }; 149 | 150 | 151 | //! overload for <<, so that a FlowRecord object can be thrown into an ostream 152 | ostream& operator<< ( ostream &os, FlowRecord &obj ); 153 | 154 | 155 | #endif // _FLOWRECORDLIST_H_ 156 | -------------------------------------------------------------------------------- /src/netmate/FlowRecordDB.h: -------------------------------------------------------------------------------- 1 | 2 | /*! \file FlowRecordDB.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | store flow records for all flows 25 | 26 | $Id: FlowRecordDB.h 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #ifndef _FLOWRECORDDB_H_ 30 | #define _FLOWRECORDDB_H_ 31 | 32 | 33 | #include "stdincpp.h" 34 | #include "Logger.h" 35 | #include "FlowRecord.h" 36 | #include "Threads.h" 37 | #include "Rule.h" 38 | 39 | 40 | //! extended flow record 41 | typedef struct 42 | { 43 | //! export module name 44 | expnames_t expmods; 45 | FlowRecord *fr; 46 | } flowRec_t; 47 | 48 | //! flow record queue (push based export) 49 | typedef deque flowRecExpList_t; 50 | typedef deque::iterator flowRecExpListIter_t; 51 | 52 | //! flow record DB index by rule id (pull based export) 53 | typedef multimap flowRecDB_t; 54 | typedef multimap::iterator flowRecDBIter_t; 55 | 56 | /*! \short save measurement results and store these until retrieval 57 | 58 | The FlowRecordDB class will receive flow records from the packet 59 | processor and store them into a queue and a map. The queue is used 60 | for push based export (also called FIFO). The map is used for pull 61 | based export (also called DB). 62 | */ 63 | 64 | class FlowRecordDB 65 | { 66 | private: 67 | 68 | Logger *log; //!< link to global logger 69 | int ch; //!< logging channel used by objects of this class 70 | 71 | int threaded; //!< flag, indicates whether db runs as a separate class 72 | 73 | //! flow record db 74 | flowRecDB_t db; 75 | 76 | //! flow record FIFO 77 | flowRecExpList_t elist; 78 | 79 | #ifdef ENABLE_THREADS 80 | mutex_t maccess; 81 | thread_cond_t emptyListCond; 82 | #endif 83 | 84 | public: 85 | 86 | //! construct and initialize a FlowRecordDB object 87 | FlowRecordDB( int threaded ); 88 | 89 | //! destroy a FlowRecordDB object 90 | ~FlowRecordDB(); 91 | 92 | /*! \short store measurement data into repository 93 | \arg \c ruleId unique rule id 94 | \arg \c expmod export module name 95 | \arg \c fr pointer to the flow record 96 | */ 97 | void storeData( int ruleId, expnames_t expmods, FlowRecord *fr ); 98 | 99 | /*! \short get flow record from DB 100 | \arg \c ruleId unique rule id 101 | \arg \c expmod export module name 102 | FIXME need expmod as parameter? 103 | */ 104 | FlowRecord *getData( int ruleId, string expmod ); 105 | 106 | //! delete all flow records of rule 107 | void delData(int ruleID); 108 | 109 | //! get next flow record from the FIFO 110 | flowRec_t *getNextRec(); 111 | 112 | //! dump a FlowRecordDB object 113 | void dump( ostream &os ); 114 | 115 | //! get number of queued records 116 | int getRecords() 117 | { 118 | return elist.size(); 119 | } 120 | }; 121 | 122 | 123 | //! overload for <<, so that a FlowRecordDB object can be thrown into an iostream 124 | ostream& operator<< ( ostream &os, FlowRecordDB &ds ); 125 | 126 | 127 | #endif // _DATASTORAGE_H_ 128 | -------------------------------------------------------------------------------- /src/netmate/MAPIRuleParser.h: -------------------------------------------------------------------------------- 1 | 2 | /* \file MAPIRuleParser.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | parser for the old Meter API rule syntax 25 | 26 | $Id: MAPIRuleParser.h 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #ifndef _MAPI_RULE_PARSER_H_ 30 | #define _MAPI_RULE_PARSER_H_ 31 | 32 | 33 | #include "stdincpp.h" 34 | #include "RuleFileParser.h" 35 | 36 | //! parse Meter API syntax old style rule format 37 | 38 | class MAPIRuleParser 39 | { 40 | 41 | private: 42 | 43 | Logger *log; 44 | int ch; 45 | char *buf; 46 | int len; 47 | string fileName; 48 | 49 | //! FIXME document! 50 | void parseFilterValue(filterValList_t *filterVals, string value, filter_t *f); 51 | 52 | string lookup(filterValList_t *filterVals, string fvalue, filter_t *f); 53 | 54 | public: 55 | 56 | MAPIRuleParser(string fname); 57 | 58 | MAPIRuleParser(char *b, int l); 59 | 60 | virtual ~MAPIRuleParser() {} 61 | 62 | //! parse given rules and add parsed rules to rules 63 | virtual void parse(filterDefList_t *filters, filterValList_t *filterVals, ruleDB_t *rules); 64 | 65 | }; 66 | 67 | 68 | #endif // _MAPI_RULE_PARSER_H_ 69 | -------------------------------------------------------------------------------- /src/netmate/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | bin_PROGRAMS = netmate 3 | 4 | if ENABLE_DEBUG 5 | AM_CXXFLAGS = -g -fno-inline -D_GLIBCXX_DEBUG -DDEBUG -DPROFILING 6 | else 7 | AM_CXXFLAGS = -O2 8 | endif 9 | 10 | if ENABLE_NF 11 | AM_CXXFLAGS += -fpermissive -DPROGRAM_VERSION=\"@IPTABLES_VERSION@\" 12 | endif 13 | 14 | netmate_LDFLAGS = -export-dynamic -module 15 | 16 | 17 | netmate_SOURCES = Error.cc Logger.cc XMLParser.cc ConfigParser.cc ConfigManager.cc PerfTimer.cc \ 18 | RuleIdSource.cc Rule.cc RuleManager.cc Event.cc EventScheduler.cc ProcModule.cc \ 19 | MeterComponent.cc NetTap.cc NetTapPcap.cc Classifier.cc ClassifierSimple.cc \ 20 | MetricData.cc FlowRecord.cc Exporter.cc Module.cc ModuleLoader.cc ExportModule.cc \ 21 | PacketQueue.cc PacketProcessor.cc CtrlComm.cc CommandLineArgs.cc FilterValue.cc \ 22 | FilterDefParser.cc RuleFileParser.cc FlowRecordDB.cc Bitmap.cc ClassifierRFC.cc Meter.cc \ 23 | ExportList.cc MeterInfo.cc MAPIRuleParser.cc FilterValParser.cc ParserFcts.cc \ 24 | Sampler.cc SamplerAll.cc Timeval.cc PageRepository.cc constants.cc \ 25 | Error.h Logger.h XMLParser.h ConfigParser.h ConfigManager.h PerfTimer.h \ 26 | RuleIdSource.h Rule.h RuleManager.h Event.h EventScheduler.h ProcModule.h \ 27 | MeterComponent.h NetTap.h NetTapPcap.h Classifier.h ClassifierSimple.h \ 28 | MetricData.h FlowRecord.h Exporter.h Module.h ModuleLoader.h ExportModule.h \ 29 | PacketQueue.h PacketProcessor.h CtrlComm.h CommandLineArgs.h FilterValue.h \ 30 | FilterDefParser.h RuleFileParser.h FlowRecordDB.h Bitmap.h ClassifierRFC.h Meter.h \ 31 | ExportList.h MeterInfo.h MAPIRuleParser.h FilterValParser.h ParserFcts.h \ 32 | Sampler.h SamplerAll.h ClassifierRFCConf.h Timeval.h PageRepository.h Threads.h \ 33 | FlowCreator.h FlowCreator.cc 34 | 35 | if ENABLE_ERF 36 | netmate_SOURCES += NetTapERF.h NetTapERF.cc 37 | endif 38 | 39 | if ENABLE_NF 40 | netmate_SOURCES += ClassifierNetfilter.cc ClassifierNetfilter.h 41 | endif 42 | 43 | 44 | INCLUDES = -I$(top_srcdir)/src/include -I$(top_srcdir)/src/lib/httpd -I$(top_srcdir)/src/lib/getopt_long 45 | 46 | netmate_LDADD = $(top_builddir)/src/lib/httpd/libhttpd.a $(top_builddir)/src/lib/getopt_long/libgetopt_long.a \ 47 | @PTHREADLIB@ @DLLIB@ @PCAPLIB@ @SSLLIB@ @XMLLIB@ @MATHLIB@ @MPATROLLIB@ @ERFLIB@ 48 | 49 | if ENABLE_NF 50 | INCLUDES += -I/usr/src/linux/include 51 | netmate_LDADD += @ULOGLIB@ 52 | endif 53 | 54 | $(top_builddir)/src/lib/httpd/libhttpd.a: 55 | cd $(top_builddir)/src/lib/httpd ; $(MAKE) 56 | 57 | $(top_builddir)/src/lib/getopt_long/libgetopt_long.a: 58 | cd $(top_builddir)/src/lib/getopt_long ; $(MAKE) 59 | 60 | install-data-hook: 61 | $(INSTALL) -d $(DESTDIR)/$(localstatedir)/run 62 | $(INSTALL) -d $(DESTDIR)/$(localstatedir)/log 63 | 64 | -------------------------------------------------------------------------------- /src/netmate/MeterComponent.cc: -------------------------------------------------------------------------------- 1 | 2 | /* \file MeterComponent.cc 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | meter component base class, provides common functionality 25 | for all meter components (e.g. threads, fd handling, ...) 26 | 27 | $Id: MeterComponent.cc 748 2009-09-10 02:54:03Z szander $ 28 | */ 29 | 30 | #include "MeterComponent.h" 31 | 32 | 33 | 34 | MeterComponent::MeterComponent(ConfigManager *_cnf, string name, int thread ) 35 | : running(0), cname(name), threaded(thread), cnf(_cnf) 36 | { 37 | log = Logger::getInstance(); 38 | ch = log->createChannel( name ); 39 | perf = PerfTimer::getInstance(); 40 | 41 | #ifdef ENABLE_THREADS 42 | if (threaded) { 43 | mutexInit(&maccess); 44 | threadCondInit(&doneCond); 45 | } 46 | #endif 47 | } 48 | 49 | 50 | MeterComponent::~MeterComponent() 51 | { 52 | #ifdef ENABLE_THREADS 53 | if (threaded) { 54 | mutexLock(&maccess); 55 | stop(); 56 | mutexUnlock(&maccess); 57 | mutexDestroy(&maccess); 58 | threadCondDestroy(&doneCond); 59 | } 60 | #endif 61 | } 62 | 63 | 64 | void MeterComponent::run(void) 65 | { 66 | #ifdef ENABLE_THREADS 67 | if (threaded && !running) { 68 | int res = threadCreate(&thread, thread_func, this); 69 | if (res != 0) { 70 | throw Error("Cannot create thread within %s: %s", 71 | cname.c_str(), strerror(res)); 72 | } 73 | 74 | running = 1; 75 | } 76 | #endif 77 | } 78 | 79 | 80 | void MeterComponent::stop(void) 81 | { 82 | #ifdef ENABLE_THREADS 83 | if (threaded && running) { 84 | threadCancel(thread); 85 | threadJoin(thread); 86 | running = 0; 87 | } 88 | #endif 89 | } 90 | 91 | 92 | void* MeterComponent::thread_func(void *arg) 93 | { 94 | #ifdef ENABLE_THREADS 95 | // asynch cancel 96 | threadSetCancelType(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); 97 | 98 | ((MeterComponent *)arg)->main(); 99 | #endif 100 | return NULL; 101 | } 102 | 103 | 104 | void MeterComponent::main(void) 105 | { 106 | // nothing here 107 | } 108 | 109 | 110 | -------------------------------------------------------------------------------- /src/netmate/MeterInfo.cc: -------------------------------------------------------------------------------- 1 | 2 | /*! \file MeterInfo.cc 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | meter info data structs used in getinfo meter command 25 | 26 | $Id: MeterInfo.cc 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #include "MeterInfo.h" 30 | 31 | 32 | char *MeterInfo::INFOS[] = { "all", 33 | "version", 34 | "uptime", 35 | "tasks_stored", 36 | "modules_loaded", 37 | "configfile", 38 | "use_ssl", 39 | "hello", 40 | "tasklist", 41 | "modlist", 42 | "task" }; 43 | 44 | typeMap_t MeterInfo::typeMap; //std::map< string, infoType_t >(); 45 | 46 | 47 | MeterInfo::MeterInfo() : list(NULL) 48 | { 49 | // init static type map for name->type lookup via getInfoType() 50 | 51 | if (typeMap.empty()) { // only fill map first time here 52 | for (int i = 0; i < I_NUMMETERINFOS; i++ ) { 53 | typeMap[INFOS[i]] = (infoType_t)i; 54 | } 55 | } 56 | } 57 | 58 | 59 | MeterInfo::~MeterInfo() 60 | { 61 | if (list != NULL) { 62 | saveDelete(list); 63 | } 64 | } 65 | 66 | 67 | string MeterInfo::getInfoString( infoType_t info ) 68 | { 69 | if (info < 0 || info >= I_NUMMETERINFOS ) { 70 | return ""; 71 | } else { 72 | return INFOS[info]; 73 | } 74 | } 75 | 76 | 77 | infoType_t MeterInfo::getInfoType( string item ) 78 | { 79 | typeMapIter_t i = typeMap.find(item); 80 | 81 | if (i != typeMap.end()) { // item found 82 | return i->second; /* type */ 83 | } else { 84 | return I_UNKNOWN; 85 | } 86 | } 87 | 88 | 89 | void MeterInfo::addInfo( infoType_t type, string param ) 90 | { 91 | if (list == NULL) { 92 | list = new infoList_t(); 93 | } 94 | 95 | list->push_back(info_t(type, param)); 96 | } 97 | 98 | 99 | void MeterInfo::addInfo( string item, string param ) 100 | { 101 | infoType_t type = getInfoType(item); 102 | 103 | if (type == I_UNKNOWN) { // no such info item 104 | throw Error("Unknown meter info '%s'", item.c_str()); 105 | } 106 | 107 | switch (type) { 108 | case I_ALL: 109 | addInfo(I_HELLO); 110 | addInfo(I_UPTIME); 111 | addInfo(I_TASKS_STORED); 112 | addInfo(I_FUNCTIONS_LOADED); 113 | addInfo(I_CONFIGFILE); 114 | addInfo(I_USE_SSL); 115 | addInfo(I_TASKLIST); 116 | addInfo(I_MODLIST); 117 | break; 118 | case I_TASK: 119 | addInfo(I_TASK, param ); 120 | break; 121 | default: 122 | addInfo( type ); 123 | break; 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /src/netmate/MeterInfo.h: -------------------------------------------------------------------------------- 1 | 2 | /*! \file MeterInfo.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | meter info data structs used in getinfo mete command 25 | 26 | $Id: MeterInfo.h 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #ifndef _METERINFO_H_ 30 | #define _METERINFO_H_ 31 | 32 | 33 | #include "stdincpp.h" 34 | #include "Error.h" 35 | 36 | //! types of information available via get_info command 37 | enum infoType_t { 38 | I_UNKNOWN = -1, 39 | I_ALL = 0, 40 | I_METER_VERSION, 41 | I_UPTIME, 42 | I_TASKS_STORED, 43 | I_FUNCTIONS_LOADED, 44 | I_CONFIGFILE, 45 | I_USE_SSL, 46 | I_HELLO, 47 | I_TASKLIST, 48 | I_MODLIST, 49 | I_TASK, 50 | // insert new items here 51 | I_NUMMETERINFOS 52 | }; 53 | 54 | //! type and value of a single meter info 55 | struct info_t 56 | { 57 | infoType_t type; 58 | string param; 59 | 60 | info_t( infoType_t t, string p = "" ) { 61 | type = t; 62 | param = p; 63 | } 64 | }; 65 | 66 | //! list of meter infos (type + parameters) 67 | typedef vector< info_t > infoList_t; 68 | typedef vector< info_t >::iterator infoListIter_t; 69 | 70 | //! get numeric info type from string 71 | typedef std::map< string, infoType_t > typeMap_t; 72 | typedef std::map< string, infoType_t >::iterator typeMapIter_t; 73 | 74 | 75 | class MeterInfo { 76 | 77 | private: 78 | 79 | static char *INFOS[]; //!< names of the info items 80 | static typeMap_t typeMap; 81 | 82 | //!< currently stored list of info items 83 | infoList_t *list; 84 | 85 | public: 86 | 87 | MeterInfo(); 88 | 89 | ~MeterInfo(); 90 | 91 | //! get info name from info type 92 | static string getInfoString(infoType_t info); 93 | 94 | //! get info type from info name 95 | static infoType_t getInfoType (string item); 96 | 97 | //! add info by type 98 | void addInfo( infoType_t type, string param = ""); 99 | 100 | //! add info by name 101 | void addInfo( string item, string param = ""); 102 | 103 | /*! \brief release list of added info_t items. 104 | caller is responsible for the disposal of this list 105 | */ 106 | inline infoList_t *getList() 107 | { 108 | infoList_t *tmp = list; 109 | list = NULL; 110 | return tmp; 111 | } 112 | 113 | }; 114 | 115 | 116 | #endif // _METERINFO_H_ 117 | -------------------------------------------------------------------------------- /src/netmate/Module.cc: -------------------------------------------------------------------------------- 1 | 2 | /*!\file Module.cc 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | this class represents the base class for 25 | packet processing modules and data export modules 26 | 27 | $Id: Module.cc 748 2009-09-10 02:54:03Z szander $ 28 | */ 29 | 30 | #include "Error.h" 31 | #include "Logger.h" 32 | #include "Module.h" 33 | 34 | 35 | /* ------------------------- Module ------------------------- */ 36 | 37 | Module::Module( string name, string libfile, libHandle_t libhandle ) 38 | { 39 | log = Logger::getInstance(); 40 | ch = log->createChannel("Module"); 41 | #ifdef DEBUG 42 | log->dlog(ch, "Creating"); 43 | #endif 44 | 45 | modName = name; 46 | fileName = libfile; 47 | libHandle = libhandle; 48 | ownName = ""; 49 | refs = 0; 50 | calls = 0; 51 | } 52 | 53 | 54 | /* ------------------------- ~Module ------------------------- */ 55 | 56 | Module::~Module() 57 | { 58 | dlclose(libHandle); 59 | 60 | #ifdef DEBUG 61 | log->dlog(ch, "Destroyed"); 62 | #endif 63 | } 64 | 65 | 66 | /* ------------------------- loadAPI ------------------------- */ 67 | 68 | void *Module::loadAPI( string apiName ) 69 | { 70 | void *funcList; 71 | 72 | funcList = dlsym(libHandle, apiName.c_str()); 73 | if (funcList == NULL) { 74 | throw Error("cannot find API called '%s' in lib %s, error: %s", 75 | apiName.c_str(), fileName.c_str(), dlerror()); 76 | } else { 77 | return funcList; 78 | } 79 | } 80 | 81 | 82 | /* ------------------------- checkMagic ------------------------- */ 83 | 84 | void Module::checkMagic( int magicNumber ) 85 | { 86 | // test for magic number in loaded module 87 | int *magic = (int *)dlsym(libHandle, "magic"); 88 | 89 | if (magic == NULL) { 90 | throw Error("invalid module - no magic number present"); 91 | } 92 | if (*magic != magicNumber) { 93 | throw Error("invalid module - wrong magic number"); 94 | } 95 | } 96 | 97 | 98 | /* ------------------------- dump ------------------------- */ 99 | 100 | void Module::dump( ostream &os ) 101 | { 102 | os << modName << " (refs=" << refs << ",calls=" << calls << ")\n"; 103 | } 104 | 105 | 106 | /* ------------------------- operator<< ------------------------- */ 107 | 108 | ostream& operator<< ( ostream &os, Module &obj ) 109 | { 110 | obj.dump(os); 111 | return os; 112 | } 113 | -------------------------------------------------------------------------------- /src/netmate/NetTap.cc: -------------------------------------------------------------------------------- 1 | 2 | /*!\file NetTap.cc 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | abstract base class for possible network taps 25 | 26 | $Id: NetTap.cc 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #include "NetTap.h" 30 | 31 | 32 | NetTapStats *NetTap::getStats() 33 | { 34 | return stats.get(); 35 | } 36 | 37 | 38 | ostream& operator<< ( ostream &os, NetTap &nt ) 39 | { 40 | nt.dump(os); 41 | return os; 42 | } 43 | 44 | 45 | ostream& operator<< ( ostream &os, NetTapStats &nst ) 46 | { 47 | nst.dump(os); 48 | return os; 49 | } 50 | -------------------------------------------------------------------------------- /src/netmate/NetTap.h: -------------------------------------------------------------------------------- 1 | 2 | /*! \file NetTap.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | abstract base class for possible network taps 25 | 26 | $Id: NetTap.h 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #ifndef _NETTAP_H_ 30 | #define _NETTAP_H_ 31 | 32 | 33 | #include "stdincpp.h" 34 | #include "ProcModuleInterface.h" 35 | #include "CommandLineArgs.h" 36 | 37 | 38 | //! store some statistical values for the net tap 39 | 40 | class NetTapStats { 41 | 42 | public: 43 | 44 | unsigned long long packets; //!< number of packets processed so far 45 | unsigned long long bytes; //!< size of volume of processed packets 46 | 47 | NetTapStats() { 48 | packets = 0; 49 | bytes = 0; 50 | } 51 | 52 | virtual ~NetTapStats() {} 53 | 54 | virtual void dump( ostream &os) { 55 | os << "packets: " << packets << endl; 56 | os << "bytes: " << bytes << endl; 57 | } 58 | }; 59 | 60 | 61 | //! overload for <<, so that a NetTap stats object can be thrown into an ostream 62 | ostream& operator<< ( ostream &os, NetTapStats &nst ); 63 | 64 | 65 | /*! \short capture packets from lower layer (network, file, ...) 66 | 67 | An instance of this abstract class is called by the classifier to 68 | get packets as input 69 | 70 | */ 71 | 72 | class NetTap 73 | { 74 | protected: 75 | 76 | auto_ptr stats; //!< net tap usage statistics counters 77 | 78 | public: 79 | 80 | virtual ~NetTap() {}; 81 | 82 | //! check a filter 83 | virtual void checkFilter(string filter) = 0; 84 | 85 | /*! \short add a filter 86 | This functions adds a filter to the capturing device. This 87 | is NOT a classification rule but e.g. a prefilter like BPF in the 88 | OS kernel. 89 | */ 90 | virtual void addFilter(string filter) = 0; 91 | 92 | /*! \short delete a filter 93 | This removes a previously installed filter rule from the network tap. 94 | */ 95 | virtual void delFilter() = 0; 96 | 97 | /*! \short get packet from network tap 98 | This function return the next packet in the queue to the caller. It 99 | blocks if there is no packet in the queue. The return value can be 100 | used for error signalization. 101 | */ 102 | virtual metaData_t *getPacket(char *buf, unsigned long len) = 0; 103 | 104 | /*! \short read statistical information from the network tap 105 | \returns a struct containing numerous statistical values 106 | */ 107 | virtual NetTapStats *getStats(); 108 | 109 | //! dump a network tap object 110 | virtual void dump( ostream &os ) 111 | { 112 | os << "NetTap Dump" << endl; 113 | os << *stats << endl; 114 | } 115 | 116 | //! get file descriptor net tap is reading from 117 | virtual int getFd() = 0; 118 | 119 | //! indicate whether the tap is online or file 120 | virtual int isOnline() = 0; 121 | }; 122 | 123 | 124 | //! overload for <<, so that a network tap object can be thrown into an ostream 125 | ostream& operator<< ( ostream &os, NetTap &nt ); 126 | 127 | 128 | #endif // _NETTAP_H_ 129 | -------------------------------------------------------------------------------- /src/netmate/PageRepository.cc: -------------------------------------------------------------------------------- 1 | 2 | /*! \file PageRepository.cc 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | 24 | This file contains the definition for class PageRepository 25 | 26 | $Id: PageRepository.cc 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | 30 | #include "Error.h" 31 | #include "PageRepository.h" 32 | 33 | 34 | void PageRepository::addPageFile( string url, string fname ) 35 | { 36 | string line; 37 | string content; 38 | ifstream in(fname.c_str()); 39 | 40 | if (!in) { 41 | throw Error("cannot access/read file '%s'", fname.c_str()); 42 | } 43 | 44 | while (getline(in, line)) { 45 | content += line; 46 | content += "\n"; 47 | } 48 | 49 | addPage(url, content); 50 | 51 | fileNames[url] = fname; 52 | } 53 | 54 | 55 | string PageRepository::getPage( string url ) 56 | { 57 | repositoryIter_t iter = pages.find(url); 58 | 59 | if (iter != pages.end()) { 60 | return iter->second; 61 | } else { 62 | return ""; 63 | } 64 | } 65 | 66 | 67 | string PageRepository::getFileName( string url ) 68 | { 69 | repositoryIter_t iter = fileNames.find(url); 70 | 71 | if (iter != fileNames.end()) { 72 | return iter->second; 73 | } else { 74 | return ""; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/netmate/PageRepository.h: -------------------------------------------------------------------------------- 1 | 2 | /*! \file PageRepository.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | This file contains the declaration for class PageRepository 24 | 25 | $Id: PageRepository.h 748 2009-09-10 02:54:03Z szander $ 26 | */ 27 | 28 | #ifndef _PAGE_REPOSITORY_H_ 29 | #define _PAGE_REPOSITORY_H_ 30 | 31 | 32 | #include "stdincpp.h" 33 | 34 | //! url to page content map 35 | typedef map repository_t; 36 | typedef map::iterator repositoryIter_t; 37 | 38 | 39 | /*! \short stores HTML pages (i.e. text strings) which can be found 40 | based on their URI name (path + page-name) 41 | */ 42 | 43 | class PageRepository 44 | { 45 | private: 46 | 47 | //! maps url to page content 48 | repository_t pages; 49 | 50 | //! maps url to filename 51 | repository_t fileNames; 52 | 53 | public: 54 | 55 | PageRepository() {} 56 | 57 | ~PageRepository() {} 58 | 59 | //! FIXME document 60 | void addPage( string url, string content ) 61 | { 62 | pages[url] = content; 63 | } 64 | 65 | void addPageFile( string url, string filename ); 66 | 67 | string getPage( string url ); 68 | 69 | string getFileName( string url ); 70 | }; 71 | 72 | 73 | #endif // _PAGE_REPOSITORY_H_ 74 | -------------------------------------------------------------------------------- /src/netmate/ParserFcts.h: -------------------------------------------------------------------------------- 1 | 2 | /* \file ParserFcts.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | functions for parsing string data into varies data formats 25 | 26 | $Id: ParserFcts.h 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #ifndef _PARSERFCTS_H_ 30 | #define _PARSERFCTS_H_ 31 | 32 | 33 | #include "stdincpp.h" 34 | 35 | 36 | class ParserFcts 37 | { 38 | public: 39 | 40 | static long parseLong(string s, long min=LONG_MIN, long max=LONG_MAX); 41 | 42 | static unsigned long parseULong(string s, unsigned long min=0, unsigned long max=ULONG_MAX); 43 | 44 | static long long parseLLong(string s, long long min=LLONG_MIN, long long max=LLONG_MAX); 45 | 46 | static unsigned long long parseULLong(string s, unsigned long long min=0, 47 | unsigned long long max=ULLONG_MAX); 48 | 49 | static int parseInt(string s, int min=LONG_MIN, int max=LONG_MAX); 50 | 51 | static struct in_addr parseIPAddr(string s); 52 | 53 | static struct in6_addr parseIP6Addr(string s); 54 | 55 | static int parseBool(string s); 56 | 57 | static float parseFloat(string s, float min=MINFLOAT, float max=MAXFLOAT); 58 | 59 | static double parseDouble(string s, double min=MINDOUBLE, double max=MAXDOUBLE); 60 | 61 | static void parseItem(string type, string value); 62 | 63 | }; 64 | 65 | #endif // _PARSERFCTS_H_ 66 | -------------------------------------------------------------------------------- /src/netmate/RuleFileParser.h: -------------------------------------------------------------------------------- 1 | 2 | /* \file RuleFileParser.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | parse rule files 25 | 26 | $Id: RuleFileParser.h 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #ifndef _RULEFILEPARSER_H_ 30 | #define _RULEFILEPARSER_H_ 31 | 32 | 33 | #include "stdincpp.h" 34 | #include "libxml/parser.h" 35 | #include "Logger.h" 36 | #include "XMLParser.h" 37 | #include "Rule.h" 38 | #include "ConfigParser.h" 39 | #include "FilterDefParser.h" 40 | #include "FilterValParser.h" 41 | 42 | 43 | //! rule list 44 | typedef vector ruleDB_t; 45 | typedef vector::iterator ruleDBIter_t; 46 | 47 | class RuleFileParser : public XMLParser 48 | { 49 | private: 50 | 51 | Logger *log; 52 | int ch; 53 | 54 | //! parse a config item 55 | configItem_t parsePref(xmlNodePtr cur); 56 | 57 | //! lookup filter value 58 | string lookup(filterValList_t *filterVals, string fvalue, filter_t *f); 59 | //! parse a filter value 60 | void parseFilterValue(filterValList_t *filterVals, string value, filter_t *f); 61 | 62 | public: 63 | 64 | RuleFileParser(string fname); 65 | 66 | RuleFileParser(char *buf, int len); 67 | 68 | virtual ~RuleFileParser() {} 69 | 70 | //! parse rules and add parsed rules to the list of rules 71 | virtual void parse(filterDefList_t *filters, filterValList_t *filterVals, ruleDB_t *rules); 72 | }; 73 | 74 | #endif // _RULEFILEPARSER_H_ 75 | -------------------------------------------------------------------------------- /src/netmate/RuleIdSource.cc: -------------------------------------------------------------------------------- 1 | 2 | /*!\file RuleIdSource.cc 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | manage unique numeric rule id space 25 | 26 | $Id: RuleIdSource.cc 748 2009-09-10 02:54:03Z szander $ 27 | 28 | */ 29 | 30 | #include "RuleIdSource.h" 31 | 32 | 33 | 34 | RuleIdSource::RuleIdSource(int _unique) 35 | : num(0), unique(_unique) 36 | { 37 | 38 | } 39 | 40 | 41 | RuleIdSource::~RuleIdSource() 42 | { 43 | // nothing to do 44 | } 45 | 46 | 47 | unsigned long long RuleIdSource::newId(void) 48 | { 49 | unsigned long long id; 50 | 51 | if (freeIds.empty()) { 52 | return num++; 53 | } 54 | 55 | // else use id from free list 56 | id = freeIds.front(); 57 | freeIds.pop_front(); 58 | 59 | return id; 60 | } 61 | 62 | 63 | void RuleIdSource::freeId(unsigned long long id) 64 | { 65 | if (!unique) { 66 | freeIds.push_back(id); 67 | num--; 68 | } 69 | } 70 | 71 | 72 | void RuleIdSource::dump( ostream &os ) 73 | { 74 | os << "RuleIdSource dump:" << endl 75 | << "Number of used ids is : " << num - freeIds.size() << endl; 76 | } 77 | 78 | 79 | ostream& operator<< ( ostream &os, RuleIdSource &rim ) 80 | { 81 | rim.dump(os); 82 | return os; 83 | } 84 | -------------------------------------------------------------------------------- /src/netmate/RuleIdSource.h: -------------------------------------------------------------------------------- 1 | 2 | /*! \file RuleIdSource.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | manage unique numeric rule id space 25 | 26 | $Id: RuleIdSource.h 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #ifndef _RULEIDSOURCE_H_ 30 | #define _RULEIDSOURCE_H_ 31 | 32 | 33 | #include "stdincpp.h" 34 | #include "Error.h" 35 | #include "Logger.h" 36 | 37 | 38 | /*! \short generate unique id numbers 39 | 40 | The RuleIdSource class can generate unique 32 bit integer numbers for 41 | use by other functions. A single number can be lent from the pool of 42 | available numbers, and this number will not be generated by a call to 43 | the newId function until it has been previously released with a call 44 | to the freeId function. 45 | */ 46 | 47 | class RuleIdSource 48 | { 49 | private: 50 | 51 | unsigned long long num; 52 | int unique; 53 | list freeIds; //!< list of previously freed (now unused) ids 54 | 55 | public: 56 | 57 | //! construct and initialize a RuleIdSource object 58 | // if unique is set to 1 Ids should be unique until we wrap around 2^63 59 | RuleIdSource(int unique = 0); 60 | 61 | //! destroy a RuleIdSource object 62 | ~RuleIdSource(); 63 | 64 | /*! \short generate a new internal id number 65 | 66 | return a new Id value that is currently not in use. This value will be 67 | marked as used and will not returned by a call to newId unless it has 68 | been released again with a call to freeId 69 | \returns unique unused id value 70 | */ 71 | unsigned long long newId( void ); 72 | 73 | /*! \short release an id number 74 | 75 | The released id number can be reused (i.e. returned by newId) after 76 | the call to freeId. Do not release numbers that have not been obtained 77 | by a call to newId this will result in unpredictable behaviour. 78 | 79 | \arg \c id - id value that is to be released for future use 80 | */ 81 | void freeId( unsigned long long id ); 82 | 83 | //! dump a RuleIdSource object 84 | void dump( ostream &os ); 85 | 86 | }; 87 | 88 | 89 | //! overload for <<, so that a RuleIdSource object can be thrown into an iostream 90 | ostream& operator<< ( ostream &os, RuleIdSource &ris ); 91 | 92 | 93 | #endif // _RULEIDSOURCE_H_ 94 | -------------------------------------------------------------------------------- /src/netmate/Sampler.cc: -------------------------------------------------------------------------------- 1 | 2 | /*! \file Sampler.cc 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | abstract base class for all samplers 25 | 26 | $Id: Sampler.cc 748 2009-09-10 02:54:03Z szander $ 27 | 28 | */ 29 | 30 | #include "Sampler.h" 31 | 32 | Sampler::Sampler() 33 | { 34 | 35 | } 36 | 37 | Sampler::~Sampler() 38 | { 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/netmate/Sampler.h: -------------------------------------------------------------------------------- 1 | 2 | /*! \file Sampler.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | abstract base class for all samplers 25 | 26 | $Id: Sampler.h 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #ifndef _SAMPLER_H_ 30 | #define _SAMPLER_H_ 31 | 32 | 33 | #include "stdincpp.h" 34 | #include "metadata.h" 35 | #include "Error.h" 36 | 37 | 38 | class Sampler 39 | { 40 | 41 | public: 42 | 43 | Sampler(); 44 | 45 | virtual ~Sampler(); 46 | 47 | /*! flag wether packet is sampled 48 | \returns 1 if sampled 0 otherwise */ 49 | virtual int sample(metaData_t* pkt) = 0; 50 | 51 | }; 52 | 53 | #endif // _SAMPLER_H_ 54 | -------------------------------------------------------------------------------- /src/netmate/SamplerAll.cc: -------------------------------------------------------------------------------- 1 | 2 | /*! \file SamplerAll.cc 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | samples *each and every* packet 25 | 26 | $Id: SamplerAll.cc 748 2009-09-10 02:54:03Z szander $ 27 | 28 | */ 29 | 30 | #include "SamplerAll.h" 31 | 32 | SamplerAll::SamplerAll() 33 | { 34 | 35 | } 36 | 37 | SamplerAll::~SamplerAll() 38 | { 39 | 40 | } 41 | 42 | // samples *all* packets 43 | int SamplerAll::sample(metaData_t* pkt) 44 | { 45 | return 1; 46 | } 47 | -------------------------------------------------------------------------------- /src/netmate/SamplerAll.h: -------------------------------------------------------------------------------- 1 | 2 | /*! \file SamplerAll.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | samples *each and every* packet 25 | 26 | $Id: SamplerAll.h 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #ifndef _SAMPLERALL_H_ 30 | #define _SAMPLERALL_H_ 31 | 32 | 33 | #include "stdincpp.h" 34 | #include "Error.h" 35 | #include "Sampler.h" 36 | 37 | 38 | class SamplerAll : public Sampler 39 | { 40 | 41 | public: 42 | 43 | SamplerAll(); 44 | 45 | virtual ~SamplerAll(); 46 | 47 | /*! flag whether packet is sampled 48 | \returns 1 if sampled 0 otherwise 49 | */ 50 | virtual int sample(metaData_t* pkt); 51 | 52 | }; 53 | 54 | #endif // _SAMPLERALL_H_ 55 | -------------------------------------------------------------------------------- /src/netmate/Timeval.cc: -------------------------------------------------------------------------------- 1 | 2 | /* \file Timeval.cc 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | functions for comparing, adding and subtracting timevals 25 | 26 | $Id: Timeval.cc 748 2009-09-10 02:54:03Z szander $ 27 | 28 | */ 29 | 30 | #include "Timeval.h" 31 | #include "Error.h" 32 | 33 | 34 | // global time from tcpdump file 35 | struct timeval Timeval::g_time = {0, 0}; 36 | int Timeval::onlineCap = 1; 37 | 38 | 39 | int Timeval::cmp(struct timeval t1, struct timeval t2) 40 | { 41 | 42 | if (t1.tv_sec < t2.tv_sec) { 43 | return -1; 44 | } else if (t1.tv_sec > t2.tv_sec) { 45 | return +1; 46 | } else { 47 | if (t1.tv_usec < t2.tv_usec) { 48 | return -1; 49 | } else if (t1.tv_usec > t2.tv_usec) { 50 | return +1; 51 | } else { 52 | return 0; 53 | } 54 | } 55 | } 56 | 57 | struct timeval Timeval::add(struct timeval a, struct timeval b) 58 | { 59 | struct timeval rv; 60 | 61 | rv.tv_sec = a.tv_sec + b.tv_sec; 62 | rv.tv_usec = a.tv_usec + b.tv_usec; 63 | if (rv.tv_usec >= 1000000) { 64 | rv.tv_usec -= 1000000; 65 | rv.tv_sec++; 66 | } 67 | 68 | return rv; 69 | } 70 | 71 | struct timeval Timeval::sub0(struct timeval num, struct timeval sub) 72 | { 73 | struct timeval rv; 74 | 75 | rv.tv_sec = num.tv_sec - sub.tv_sec; 76 | rv.tv_usec = num.tv_usec - sub.tv_usec; 77 | if (rv.tv_usec < 0) { 78 | rv.tv_usec += 1000000; 79 | rv.tv_sec--; 80 | } 81 | if (rv.tv_sec < 0) { 82 | rv.tv_sec = 0; 83 | rv.tv_usec = 0; 84 | } 85 | 86 | return rv; 87 | } 88 | 89 | // function for reading the current time 90 | // the time will either be the current system time or the time derived 91 | // from a pcap trace file 92 | int Timeval::gettimeofday(struct timeval *tv, struct timezone *tz) 93 | { 94 | if (!onlineCap) { 95 | // use timestamps from the trace 96 | tv->tv_sec = g_time.tv_sec; 97 | tv->tv_usec = g_time.tv_usec; 98 | return 0; 99 | } else { 100 | return ::gettimeofday(tv, tz); 101 | } 102 | 103 | } 104 | 105 | time_t Timeval::time(time_t *t) 106 | { 107 | if (!onlineCap) { 108 | if (t != NULL) { 109 | *t = g_time.tv_sec; 110 | } 111 | return g_time.tv_sec; 112 | } else { 113 | return ::time(t); 114 | } 115 | } 116 | 117 | 118 | // set the time (used when reading the time from a pcap file) 119 | int Timeval::settimeofday(const struct timeval *tv) 120 | { 121 | if ( (tv->tv_sec*1e6 + tv->tv_usec) < (g_time.tv_sec*1e6 + g_time.tv_usec) ) { 122 | cerr << "Encountered a packet from the past" << endl; 123 | return -1; 124 | } 125 | 126 | g_time.tv_sec = tv->tv_sec; 127 | g_time.tv_usec = tv->tv_usec; 128 | 129 | return 0; 130 | } 131 | -------------------------------------------------------------------------------- /src/netmate/Timeval.h: -------------------------------------------------------------------------------- 1 | 2 | /* \file Timeval.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | functions for comparing, adding and subtracting timevals 25 | 26 | $Id: Timeval.h 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #ifndef _TIMEVAL_H_ 30 | #define _TIMEVAL_H_ 31 | 32 | 33 | #include "stdincpp.h" 34 | 35 | 36 | class Timeval 37 | { 38 | private: 39 | static struct timeval g_time; 40 | static int onlineCap; 41 | 42 | public: 43 | 44 | /*! \short compare t1 and t2 45 | \returns -1 if t1t2 46 | */ 47 | static int cmp(struct timeval t1, struct timeval t2); 48 | 49 | //! add timval a and b and return the result 50 | static struct timeval add(struct timeval a, struct timeval b); 51 | 52 | //! subtract timval sub from timeval num and return result; if result < 0 return 0 53 | static struct timeval sub0(struct timeval num, struct timeval sub); 54 | 55 | //! function for reading the current time 56 | // the time will either be the current system time or the time derived 57 | // from a pcap trace file 58 | static int gettimeofday(struct timeval *tv, struct timezone *tz); 59 | static time_t time(time_t *t); 60 | 61 | //! set the time (used when reading the time from a pcap file) 62 | // return 0 if ok and -1 if time is in the past (reordering) 63 | static int settimeofday(const struct timeval *tv); 64 | 65 | //! set the capture mode: 1 = online, 0 = offline 66 | static void setCapMode(int oc) 67 | { 68 | onlineCap = oc; 69 | } 70 | }; 71 | 72 | #endif // _TIMEVAL_H_ 73 | -------------------------------------------------------------------------------- /src/netmate/XMLParser.h: -------------------------------------------------------------------------------- 1 | 2 | /* \file XMLParser.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | parse XML files, base class for specific parsers 25 | 26 | $Id: XMLParser.h 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #ifndef _XMLPARSER_H_ 30 | #define _XMLPARSER_H_ 31 | 32 | 33 | #include "stdincpp.h" 34 | #include "libxml/parser.h" 35 | #include "Logger.h" 36 | 37 | 38 | class XMLParser 39 | { 40 | 41 | private: 42 | Logger *log; 43 | int ch; 44 | 45 | //! xml file name 46 | string fileName; 47 | 48 | //! corresponding dtd file name 49 | string dtdName; 50 | 51 | static string err, warn; 52 | 53 | //! callback for parser errors 54 | static void XMLErrorCB(void *ctx, const char *msg, ...); 55 | 56 | //! callback for parser warnings 57 | static void XMLWarningCB(void *ctx, const char *msg, ...); 58 | 59 | //! validates doc vs. dtd 60 | void validate(string root); 61 | 62 | protected: 63 | 64 | //! pointer to the root of the doc 65 | xmlDocPtr XMLDoc; 66 | 67 | //! name space 68 | xmlNsPtr ns; 69 | 70 | public: 71 | 72 | XMLParser(string dtdname, string fname, string root); 73 | 74 | XMLParser(string dtdname, char *buf, int len, string root); 75 | 76 | ~XMLParser(); 77 | 78 | string xmlCharToString(xmlChar *in); 79 | 80 | }; 81 | 82 | #endif // _XMLPARSER_H_ 83 | -------------------------------------------------------------------------------- /src/netmate/constants.cc: -------------------------------------------------------------------------------- 1 | 2 | /* \file constants.cc 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | here all string and numeric constants for the netmate toolset are stored 25 | 26 | $Id: constants.cc 748 2009-09-10 02:54:03Z szander $ 27 | 28 | */ 29 | 30 | #include "stdincpp.h" 31 | #include "constants.h" 32 | 33 | using namespace std; 34 | 35 | // RuleManager.cc 36 | const unsigned int DONE_LIST_SIZE = 50; 37 | const string FILTERVAL_FILE = DEF_SYSCONFDIR "/filterval.xml"; 38 | const string FILTERDEF_FILE = DEF_SYSCONFDIR "/filterdef.xml"; 39 | 40 | // Meter.h 41 | const string DEFAULT_CONFIG_FILE = DEF_SYSCONFDIR "/netmate.conf.xml"; 42 | const string NETMATE_LOCK_FILE = DEF_STATEDIR "/run/netmate.pid"; 43 | const int DEF_SNAPSIZE = 65536; 44 | 45 | // Logger.h 46 | const string DEFAULT_LOG_FILE = DEF_STATEDIR "/log/netmate.log"; 47 | 48 | // RuleFileParser.cc 49 | const string RULEFILE_DTD = DEF_SYSCONFDIR "/rulefile.dtd"; 50 | 51 | // Rule.cc 52 | const string TIME_FORMAT = "%Y-%m-%d %T"; 53 | const string DEFAULT_SETNAME = "default"; 54 | 55 | // FilterValParser.cc 56 | const string FILTERVAL_DTD = DEF_SYSCONFDIR "/filterval.dtd"; 57 | 58 | // FilterDefParser.cc 59 | const string FILTERDEF_DTD = DEF_SYSCONFDIR "/filterdef.dtd"; 60 | 61 | // CtrlComm.cc 62 | const string REPLY_TEMPLATE = DEF_SYSCONFDIR "/reply.xml"; //!< html response template 63 | const string MAIN_PAGE_FILE = DEF_SYSCONFDIR "/main.html"; 64 | const string XSL_PAGE_FILE = DEF_SYSCONFDIR "/reply.xsl"; 65 | const int EXPIRY_TIME = 3600; //!< expiry time for web pages served from cache 66 | const int DEF_PORT = 12244; //!< default TCP port to connect to 67 | 68 | // ConfigParser.h 69 | const string CONFIGFILE_DTD = DEF_SYSCONFDIR "/netmate.conf.dtd"; 70 | 71 | // nmrsh.cc 72 | const string PROMPT = "> "; //!< user prompt for interactive mode 73 | const string DEF_SERVER = "localhost"; //!< default netmate host 74 | const int HISTLEN = 200; //!< history length (lines) 75 | const string HISTFILE = "/.nmrsh_hist"; //!< name of the history file 76 | const string DEF_XSL = DEF_SYSCONFDIR "/reply2.xsl"; //!< xsl file for decoding xml responses 77 | 78 | // environment var which points to the home dir where the hist file is 79 | const string HOME = "HOME"; 80 | 81 | #ifdef USE_SSL 82 | // certificate file location (SSL) 83 | const string CERT_FILE = DEF_SYSCONFDIR "/netmate.pem"; 84 | #endif 85 | 86 | // help text in interactive shell 87 | const string HELP = "" \ 88 | "interactive commands: \n" \ 89 | "help displays this help text \n" \ 90 | "quit, exit, bye end telly program \n" \ 91 | "get_info get meter information \n" \ 92 | "rm_task remove rule(s) \n" \ 93 | "add_task add rule \n" \ 94 | "add_tasks add rules from file \n" \ 95 | "get_modinfo get meter module information \n \n" \ 96 | "any other text is sent to the server and the reply from the server is displayed."; 97 | 98 | -------------------------------------------------------------------------------- /src/nmrsh/Makefile.am: -------------------------------------------------------------------------------- 1 | if BUILD_NMRSH 2 | 3 | bin_PROGRAMS = nmrsh 4 | 5 | if ENABLE_DEBUG 6 | AM_CFLAGS = -g -fno-inline -D_GLIBCXX_DEBUG -DDEBUG -DPROFILING 7 | else 8 | AM_CFLAGS = -O2 9 | endif 10 | 11 | nmrsh_SOURCES = nmrsh.cc $(top_srcdir)/src/netmate/Error.cc \ 12 | $(top_srcdir)/src/netmate/CommandLineArgs.cc \ 13 | $(top_srcdir)/src/netmate/constants.cc \ 14 | $(top_srcdir)/src/lib/getopt_long/getopt_long.c \ 15 | $(top_srcdir)/src/lib/getpass/getpass.c 16 | 17 | nmrsh_LDADD = @READLINELIB@ @SSLLIB@ @MPATROLLIB@ @CURLLIB@ @XMLLIB@ @XSLTLIB@ \ 18 | $(top_builddir)/src/lib/getopt_long/libgetopt_long.a \ 19 | $(top_builddir)/src/lib/getpass/libgetpass.a 20 | 21 | INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src/include -I$(top_srcdir)/src/netmate -I$(top_srcdir)/src/lib/getopt_long -I$(top_srcdir)/src/lib/getpass 22 | 23 | $(top_builddir)/src/lib/getopt_long/libgetopt_long.a: 24 | cd $(top_builddir)/src/lib/getopt_long ; $(MAKE) 25 | 26 | $(top_builddir)/src/lib/getpass/libgetpass.a: 27 | cd $(top_builddir)/src/lib/getpass ; $(MAKE) 28 | 29 | else 30 | all: 31 | @echo "WARNING: not building nmrsh because libxslt and/or libcurl are missing!" 32 | endif 33 | -------------------------------------------------------------------------------- /src/nmrsh/README: -------------------------------------------------------------------------------- 1 | requires libcurl (http://curl.haxx.se/download.html) 2 | -------------------------------------------------------------------------------- /src/proc_modules/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = ProcModule.h ProcModule.c 2 | 3 | INCLUDES = -I$(top_srcdir)/src/include \ 4 | -I$(top_srcdir)/netfilter_userspace/include \ 5 | -I$(top_srcdir)/src/proc_modules \ 6 | -I/usr/src/linux/include 7 | 8 | lib_LTLIBRARIES = count.la bandwidth.la jitter.la pktid_crc32.la pktid_md5.la pktlen.la port_use.la rtploss.la rtt_ping.la show_ascii.la testmod.la netai_flowstats.la netai_flowstats_dscp.la netai_flowstats_dscp_1s.la capture.la 9 | 10 | if ENABLE_DEBUG 11 | AM_CFLAGS = -g -fPIC -DDEBUG -DPROFILING 12 | else 13 | AM_CFLAGS = -O2 -fPIC 14 | endif 15 | 16 | count_la_LDFLAGS = -export-dynamic -module 17 | count_la_SOURCES = count.c 18 | count_la_LIBADD = ProcModule.lo 19 | 20 | bandwidth_la_LDFLAGS = -export-dynamic -module 21 | bandwidth_la_SOURCES = bandwidth.c 22 | bandwidth_la_LIBADD = ProcModule.lo 23 | 24 | jitter_la_LDFLAGS = -export-dynamic -module 25 | jitter_la_SOURCES = jitter.c 26 | jitter_la_LIBADD = ProcModule.lo 27 | 28 | pktid_crc32_la_LDFLAGS = -export-dynamic -module 29 | pktid_crc32_la_SOURCES = pktid_crc32.c ip.h 30 | pktid_crc32_la_LIBADD = ProcModule.lo 31 | 32 | pktid_md5_la_LDFLAGS = -export-dynamic -module 33 | pktid_md5_la_SOURCES = global.h md5.h md5c.c pktid_md5.c 34 | pktid_md5_la_LIBADD = ProcModule.lo 35 | 36 | pktlen_la_LDFLAGS = -export-dynamic -module 37 | pktlen_la_SOURCES = pktlen.c 38 | pktlen_la_LIBADD = ProcModule.lo 39 | 40 | port_use_la_LDFLAGS = -export-dynamic -module 41 | port_use_la_SOURCES = port_use.c 42 | port_use_la_LIBADD = ProcModule.lo 43 | 44 | rtploss_la_LDFLAGS = -export-dynamic -module 45 | rtploss_la_SOURCES = rtploss.c 46 | rtploss_la_LIBADD = ProcModule.lo 47 | 48 | rtt_ping_la_LDFLAGS = -export-dynamic -module 49 | rtt_ping_la_SOURCES = rtt_ping.c 50 | rtt_ping_la_LIBADD = ProcModule.lo 51 | 52 | show_ascii_la_LDFLAGS = -export-dynamic -module 53 | show_ascii_la_SOURCES = show_ascii.c 54 | show_ascii_la_LIBADD = ProcModule.lo 55 | 56 | testmod_la_LDFLAGS = -export-dynamic -module 57 | testmod_la_SOURCES = testmod.c 58 | testmod_la_LIBADD = ProcModule.lo 59 | 60 | netai_flowstats_la_LDFLAGS = -export-dynamic -module 61 | netai_flowstats_la_SOURCES = netai_flowstats.c 62 | netai_flowstats_la_LIBADD = ProcModule.lo 63 | 64 | netai_flowstats_dscp_la_LDFLAGS = -export-dynamic -module 65 | netai_flowstats_dscp_la_SOURCES = netai_flowstats_dscp.c 66 | netai_flowstats_dscp_la_LIBADD = ProcModule.lo 67 | 68 | netai_flowstats_dscp_1s_la_LDFLAGS = -export-dynamic -module 69 | netai_flowstats_dscp_1s_la_SOURCES = netai_flowstats_dscp_1s.c 70 | netai_flowstats_dscp_1s_la_LIBADD = ProcModule.lo 71 | 72 | capture_la_LDFLAGS = -export-dynamic -module 73 | capture_la_SOURCES = capture.c 74 | capture_la_LIBADD = ProcModule.lo 75 | 76 | -------------------------------------------------------------------------------- /src/proc_modules/ProcModule.h: -------------------------------------------------------------------------------- 1 | 2 | /*! \file proc_modules/ProcModule.h 3 | 4 | Modifications Copyright Daniel Arndt, 2010 5 | 6 | This version has been modified to provide additional output and 7 | compatibility. For more information, please visit 8 | 9 | http://web.cs.dal.ca/darndt 10 | 11 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 12 | Berlin, Germany 13 | 14 | This file is part of Network Measurement and Accounting System (NETMATE). 15 | 16 | NETMATE is free software; you can redistribute it and/or modify 17 | it under the terms of the GNU General Public License as published by 18 | the Free Software Foundation; either version 2 of the License, or 19 | (at your option) any later version. 20 | 21 | NETMATE is distributed in the hope that it will be useful, 22 | but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | GNU General Public License for more details. 25 | 26 | You should have received a copy of the GNU General Public License 27 | along with this software; if not, write to the Free Software 28 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 29 | 30 | Description: 31 | declaration of interface for Classifier Action Modules 32 | 33 | $Id: ProcModule.h 748 2009-09-10 02:54:03Z szander $ 34 | 35 | */ 36 | 37 | 38 | #ifndef __PROCMODULE_H 39 | #define __PROCMODULE_H 40 | 41 | 42 | #include "ProcModuleInterface.h" 43 | 44 | 45 | 46 | /*! functions for exporting data */ 47 | inline void STARTEXPORT(void *data); 48 | inline void ENDEXPORT(void **exp, int *len); 49 | inline void ADD_CHAR(char val); 50 | inline void ADD_INT8(char val); 51 | inline void ADD_INT16(short val); 52 | inline void ADD_INT32(int32_t val); 53 | inline void ADD_INT64(int64_t val); 54 | inline void ADD_UINT8(unsigned char val); 55 | inline void ADD_UINT16(unsigned short val); 56 | inline void ADD_UINT32(uint32_t val); 57 | inline void ADD_UINT64(uint64_t val); 58 | inline void ADD_FLOAT(float val); 59 | inline void ADD_DOUBLE(double val); 60 | inline void ADD_IPV4ADDR(unsigned int val); 61 | inline void ADD_LIST(unsigned int num); 62 | inline void END_LIST(); 63 | inline void ADD_STRING(char *txt); 64 | inline void ADD_BINARY(unsigned int size, char *src); 65 | 66 | 67 | /*! \short declaration of struct containing all function pointers of a module */ 68 | extern ProcModuleInterface_t func; 69 | 70 | 71 | extern typeInfo_t exportInfo[]; 72 | 73 | #endif /* __PROCMODULE_H */ 74 | 75 | -------------------------------------------------------------------------------- /src/proc_modules/global.h: -------------------------------------------------------------------------------- 1 | /*! \file GLOBAL.H - RSAREF types and constants 2 | 3 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 4 | Berlin, Germany 5 | 6 | This file is part of Network Measurement and Accounting System (NETMATE). 7 | 8 | NETMATE is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 2 of the License, or 11 | (at your option) any later version. 12 | 13 | NETMATE is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this software; if not, write to the Free Software 20 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | 22 | Description: 23 | 24 | $Id: global.h 748 2009-09-10 02:54:03Z szander $ 25 | */ 26 | 27 | /* PROTOTYPES should be set to one if and only if the compiler supports 28 | function argument prototyping. 29 | The following makes PROTOTYPES default to 0 if it has not already 30 | been defined with C compiler flags. 31 | */ 32 | 33 | #include "stdinc.h" 34 | 35 | #ifndef PROTOTYPES 36 | #define PROTOTYPES 0 37 | #endif 38 | 39 | /* POINTER defines a generic pointer type */ 40 | typedef unsigned char *POINTER; 41 | 42 | /* UINT2 defines a two byte word */ 43 | typedef unsigned short int UINT2; 44 | 45 | /* UINT4 defines a four byte word */ 46 | typedef unsigned long int UINT4; 47 | 48 | /* PROTO_LIST is defined depending on how PROTOTYPES is defined above. 49 | If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it 50 | returns an empty list. 51 | */ 52 | #if PROTOTYPES 53 | #define PROTO_LIST(list) list 54 | #else 55 | #define PROTO_LIST(list) () 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /src/proc_modules/ip.h: -------------------------------------------------------------------------------- 1 | 2 | /*! \file ip.h 3 | 4 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 5 | Berlin, Germany 6 | 7 | This file is part of Network Measurement and Accounting System (NETMATE). 8 | 9 | NETMATE is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | NETMATE is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this software; if not, write to the Free Software 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | 23 | Description: 24 | portable IP header definition 25 | 26 | $Id: ip.h 748 2009-09-10 02:54:03Z szander $ 27 | */ 28 | 29 | #include "config.h" 30 | 31 | #ifdef HAVE_SYS_TYPES_H 32 | #include 33 | #endif 34 | #ifdef HAVE_INTTYPES_H 35 | #include 36 | #endif 37 | 38 | struct iphdr 39 | { 40 | #if __BYTE_ORDER == __LITTLE_ENDIAN 41 | unsigned int ihl:4; 42 | unsigned int version:4; 43 | #elif __BYTE_ORDER == __BIG_ENDIAN 44 | unsigned int version:4; 45 | unsigned int ihl:4; 46 | #else 47 | # error "Please fix " 48 | #endif 49 | uint8_t tos; 50 | uint16_t tot_len; 51 | uint16_t id; 52 | uint16_t frag_off; 53 | uint8_t ttl; 54 | uint8_t protocol; 55 | uint16_t check; 56 | uint32_t saddr; 57 | uint32_t daddr; 58 | /*The options start here. */ 59 | }; 60 | 61 | /* 62 | 63 | struct ip6hdr 64 | { 65 | #if __BYTE_ORDER == __LITTLE_ENDIAN 66 | unsigned int flowlabel:20; 67 | unsigned int trafficclass:8; 68 | unsigned int version:4; 69 | #elif __BYTE_ORDER == __BIG_ENDIAN 70 | unsigned int version:4; 71 | unsigned int trafficclass:8; 72 | unsigned int flowlabel:20; 73 | #else 74 | # error "Please fix " 75 | #endif 76 | uint16_t payloadlen; 77 | uint8_t nextheader; 78 | uint8_t ttl; 79 | struct in6_addr saddr; 80 | struct in6_addr daddr; 81 | }; 82 | */ 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/proc_modules/md5.h: -------------------------------------------------------------------------------- 1 | /* MD5.H - header file for MD5C.C 2 | */ 3 | 4 | /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All 5 | rights reserved. 6 | 7 | License to copy and use this software is granted provided that it 8 | is identified as the "RSA Data Security, Inc. MD5 Message-Digest 9 | Algorithm" in all material mentioning or referencing this software 10 | or this function. 11 | 12 | License is also granted to make and use derivative works provided 13 | that such works are identified as "derived from the RSA Data 14 | Security, Inc. MD5 Message-Digest Algorithm" in all material 15 | mentioning or referencing the derived work. 16 | 17 | RSA Data Security, Inc. makes no representations concerning either 18 | the merchantability of this software or the suitability of this 19 | software for any particular purpose. It is provided "as is" 20 | without express or implied warranty of any kind. 21 | 22 | These notices must be retained in any copies of any part of this 23 | documentation and/or software. 24 | */ 25 | 26 | /* MD5 context. */ 27 | typedef struct { 28 | UINT4 state[4]; /* state (ABCD) */ 29 | UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ 30 | unsigned char buffer[64]; /* input buffer */ 31 | } MD5_CTX; 32 | 33 | 34 | 35 | void MD5Init PROTO_LIST ((MD5_CTX *)); 36 | void MD5Update PROTO_LIST 37 | ((MD5_CTX *, unsigned char *, unsigned int)); 38 | void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *)); 39 | 40 | -------------------------------------------------------------------------------- /src/test/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | if ENABLE_DEBUG 3 | AM_CXXFLAGS = -g -O2 -D_GLIBCXX_DEBUG -DDEBUG 4 | else 5 | AM_CXXFLAGS = -O2 6 | endif 7 | 8 | 9 | if ENABLE_TEST 10 | 11 | COMMON_SOURCES=../netmate/Error.cc ../netmate/Logger.cc 12 | 13 | # tests 14 | 15 | bin_PROGRAMS = PacketQueueTest PerfTimerTest 16 | 17 | PacketQueueTest_SOURCES = $(COMMON_SOURCES) ../netmate/PacketQueue.cc PacketQueueTest.cc 18 | 19 | PerfTimerTest_SOURCES = $(COMMON_SOURCES) ../netmate/PerfTimer.cc PerfTimerTest.cc 20 | 21 | # tests end 22 | 23 | INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src/include -I$(top_srcdir)/src/lib/ctrlcomm \ 24 | -I$(top_srcdir)/src/netmate 25 | 26 | LDADD = -L$(top_srcdir)/src/lib/ctrlcomm -lctrlcomm \ 27 | @PTHREADLIB@ @DLLIB@ @PCAPLIB@ @SSLLIB@ @XMLLIB@ @MATHLIB@ 28 | endif 29 | -------------------------------------------------------------------------------- /src/test/PacketQueueTest.cc: -------------------------------------------------------------------------------- 1 | 2 | #include "Error.h" 3 | #include "Logger.h" 4 | #include "PacketQueue.h" 5 | 6 | #define LOG logger->log 7 | 8 | #define BUFFERS 10000 9 | #define MINLEN 32 10 | #define MAXLEN 1500 11 | #define LENSTEP 20 12 | #define RUNS 100000 13 | 14 | 15 | void writeData( char *buf, int lin, char in ) 16 | { 17 | char *pos = buf; 18 | 19 | // fprintf( stdout, "writing test data to %d, len = %d, c = %d \n", 20 | // (int) buf, lin, in ); 21 | 22 | *((int*)pos)++ = lin; 23 | *pos++ = in; 24 | 25 | for( ; pos < buf+lin-5 ; pos++ ) { 26 | *pos = in++; 27 | } 28 | } 29 | 30 | 31 | int checkData( char *buf ) 32 | { 33 | char *pos = buf; 34 | int len = *((int*)pos)++; 35 | char c = *pos++; 36 | 37 | //fprintf( stdout, "reading test data from %d, len = %d, c = %d \n", 38 | // (int) buf, len, c ); 39 | 40 | for( ; pos < buf+len-5; pos++ ) { 41 | if( *pos != c++ ) { 42 | return -1; 43 | } 44 | } 45 | 46 | return 0; 47 | } 48 | 49 | 50 | 51 | int main(int argc, char** argv) 52 | { 53 | Logger *logger = NULL; 54 | int res, len; 55 | unsigned char in, out; 56 | int lin, lout; 57 | PacketQueue *pq; 58 | char *buf; 59 | // metaData_t *meta; 60 | 61 | try{ 62 | logger = Logger::getInstance(); 63 | logger->setDefaultLogfile( "PacketQueueTest.log" ); 64 | LOG( 0, "------- starting test -------" ); 65 | 66 | // logger->log( L_INFO, 0, "hallo %d", 222 ); 67 | 68 | in = out = 0; 69 | lin = lout = MINLEN; 70 | 71 | pq = new PacketQueue( BUFFERS ); 72 | 73 | for (int i=0; igetBufferSpace( &buf ); 78 | 79 | if (res != 0) { 80 | // printf( "getBufferSpace failed.\n" ); 81 | printf( "." ); 82 | break; 83 | } 84 | 85 | writeData( buf, lin, in++ ); 86 | 87 | res = pq->setBufferOccupied( lin ); 88 | 89 | if (res != 0) { 90 | // printf( "setBufferOccupied failed.\n" ); 91 | printf( "#" ); 92 | break; 93 | } 94 | 95 | lin += LENSTEP; 96 | if (lin > MAXLEN ) { 97 | lin = MINLEN; 98 | } 99 | } 100 | 101 | res = pq->readBuffer( &buf, &len ); 102 | 103 | if (res != 0) { 104 | // printf( "readBuffer failed.\n" ); 105 | printf( "1" ); 106 | break; 107 | } 108 | 109 | // check buffer contents 110 | if( checkData( buf ) == -1 ) { 111 | // printf( "data verify error" ); 112 | printf( "!" ); 113 | } 114 | 115 | res = pq->releaseBuffer(); 116 | 117 | if (res != 0) { 118 | // printf( "releaseBuffer failed.\n" ); 119 | printf( "2" ); 120 | break; 121 | } 122 | 123 | // printf( "\n" ); 124 | // sleep(2); 125 | } 126 | 127 | delete pq; 128 | 129 | } catch( Error &e ) { 130 | cerr << e.getError() << "\n"; 131 | LOG( 0, "------- catched exception -------" ); 132 | LOG( 0, e.getError().c_str() ); 133 | } 134 | 135 | LOG( 0, "------- shutdown -------" ); 136 | delete logger; 137 | 138 | return 0; 139 | } 140 | -------------------------------------------------------------------------------- /src/test/PerfTimerTest.cc: -------------------------------------------------------------------------------- 1 | #include "stdincpp.h" 2 | #include "PerfTimer.h" 3 | #include "Error.h" 4 | 5 | main (int argc, char **argv) 6 | { 7 | PerfTimer *pt = NULL; 8 | 9 | try { 10 | cout << "------- startup -------" << endl; 11 | 12 | pt = PerfTimer::getInstance(); 13 | 14 | cout << "------- testrun -------" << endl; 15 | 16 | // do some testing ### 17 | 18 | pt->start(slot1); 19 | pt->start(slot2); 20 | pt->start(slot3); 21 | // sleep(1); 22 | pt->stop(slot3); 23 | pt->stop(slot2); 24 | pt->stop(slot1); 25 | 26 | fprintf( stderr, " %llu < %llu < %llu \n", 27 | pt->avg(slot3), pt->avg(slot2), pt->avg(slot1) ); 28 | 29 | // dump PerfTimer object 30 | cout << *pt; 31 | 32 | } catch (Error &e) { 33 | cerr << e.getError() << endl; 34 | cout << "------- catched exception -------" << endl; 35 | cout << e.getError().c_str() << endl; 36 | } 37 | 38 | cout << "------- shutdown -------" << endl; 39 | delete pt; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /tools/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | EXTRA_DIST = ports.sh protocols.sh 3 | 4 | bin_PROGRAMS = genrules 5 | 6 | if ENABLE_DEBUG 7 | AM_CFLAGS = -g -fno-inline -DDEBUG -DPROFILING 8 | else 9 | AM_CFLAGS = -O2 10 | endif 11 | 12 | genrules_SOURCES = genrules.c 13 | 14 | -------------------------------------------------------------------------------- /tools/genrules.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 2003-2004 Fraunhofer Institute for Open Communication Systems (FOKUS), 4 | Berlin, Germany 5 | 6 | This file is part of Network Measurement and Accounting System (NETMATE). 7 | 8 | NETMATE is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 2 of the License, or 11 | (at your option) any later version. 12 | 13 | NETMATE is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this software; if not, write to the Free Software 20 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | 22 | Description: 23 | small program to generate artificial rule files 24 | 25 | $Id: genrules.c,v 1.1.1.1 2004/12/23 05:52:37 s_zander Exp $ 26 | 27 | */ 28 | 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | void usage() 37 | { 38 | printf("Usage: \n"); 39 | printf(" -n number of rules to generate\n"); 40 | printf(" -f file name\n"); 41 | } 42 | 43 | int getRandByte() 44 | { 45 | return (int) (drand48() * 255); 46 | } 47 | 48 | int getRandWord() 49 | { 50 | return (int) (drand48() * 65535); 51 | } 52 | 53 | int main(int argc, char *argv[]) 54 | { 55 | int i; 56 | int n = 0; 57 | char *fname = NULL; 58 | FILE *f; 59 | 60 | srand48(time(NULL)); 61 | 62 | while ((i = getopt(argc, argv, "n:f:h?")) != -1) { 63 | if ((i != '?') && (i != 'h')) { 64 | switch(i) { 65 | case 'n': 66 | n = atoi(optarg); 67 | break; 68 | case 'f': 69 | fname = strdup(optarg); 70 | break; 71 | default: 72 | break; 73 | } 74 | } else { 75 | usage(); 76 | } 77 | } 78 | 79 | if (fname == NULL) { 80 | usage(); 81 | exit(1); 82 | } 83 | 84 | f = fopen(fname, "w"); 85 | 86 | fprintf(f, "\n"); 87 | fprintf(f, "\n"); 88 | fprintf(f, "\n"); 89 | fprintf(f, "1000\n"); 90 | fprintf(f, "1\n"); 91 | fprintf(f, "\n"); 92 | fprintf(f, "\n"); 93 | fprintf(f, "/tmp/netmate-results\n"); 94 | fprintf(f, "\n"); 95 | fprintf(f, "\n"); 96 | 97 | // print rules 98 | 99 | for (i=1; i\n", i); 101 | fprintf(f, "%d.%d.%d.%d\n", getRandByte(), 102 | getRandByte(), getRandByte(), getRandByte()); 103 | fprintf(f, "%d.%d.%d.%d\n", getRandByte(), 104 | getRandByte(), getRandByte(), getRandByte()); 105 | fprintf(f, "%d\n", getRandByte()); 106 | fprintf(f, "%d\n", getRandWord()); 107 | fprintf(f, "%d\n", getRandWord()); 108 | fprintf(f, "\n"); 109 | } 110 | 111 | // add a rule later 112 | fprintf(f, "\n", n); 113 | fprintf(f, "192.168.60.1\n"); 114 | fprintf(f, "192.168.60.3\n"); 115 | fprintf(f, "udp\n"); 116 | fprintf(f, "1024\n"); 117 | fprintf(f, "1025\n"); 118 | fprintf(f, "\n"); 119 | 120 | fprintf(f, ""); 121 | 122 | fclose(f); 123 | 124 | return 0; 125 | } 126 | -------------------------------------------------------------------------------- /tools/ports.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | SED_EXP="s/\([^ \t]*\)[ \t]*\([0-9-]*\)\/.*/ \2<\/DEF>/g" 4 | cat /etc/services | egrep "^[^#].*udp.*" | sed -e "$SED_EXP" | egrep "NAME=\"[A-z0-9./-]+\"" 5 | -------------------------------------------------------------------------------- /tools/protocols.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | SED_EXP="s/\([^ \t]*\)[ \t]*\([0-9]*\).*/ \2<\/DEF>/g" 4 | cat /etc/protocols | egrep "^[^#].*" | sed -e "$SED_EXP" | egrep "NAME=\"[A-z0-9./-]+\"" 5 | --------------------------------------------------------------------------------