4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program 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.
13 // This program 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.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 /** \mainpage SENF: The Simple and Extensible Network Framework
25 The SENF Simple and Extensible Network Framework aims to be a complete set of libraries to
26 facilitate the development of network applications focusing on network protocols on the layers
27 below the application layer. However, the framework includes many general purpose utilities and
28 will be expedient to use well beyond its primary objective.
32 The main goals of this library are (in no particular order):
34 \li modular framework design
35 \li utilizing the power of modern C++
36 \li very low overhead for frequently called members
40 \section start Getting started
42 To get started using this library, begin by checking out the code from the <a
43 href="http://developer.berlios.de/svn/?group_id=7489">BerliOS SVN repository</a>. You may find
44 help on using the library at '\ref senf_usage'. If you are interested in SENF, feel free to subscribe
45 to the <a href="http://developer.berlios.de/mail/?group_id=7489">SENF mailing lists</a>. If you
46 want to contribute, read the docs and \e please adhere to the \ref senf_conventions.
48 \see \ref senf_usage\n
49 <a href="../../Examples/doc/html/index.html">Examples</a>
51 \section senfutil_overview Building Projects using SENF
53 When building projects using %senf, SENFSCons has a very simple helper module
54 \ref senf_senfutil "senfutil.py" to make the building of libraries utilizing %senf simpler.
56 \see \ref senf_senfutil
59 /** \page senf_senfutil SENF SCons build utility (senfutil.py)
63 The \c senfutil utility for SCons helps setting up a project to compile against SENF:
65 \li \c senfutil adds all necessary libraries to link against
66 \li \c senfutil will set necessary compile options.
67 \li \c senfutil supports normal, debug and final project build options
68 \li \c senfutil adds support for Boost unit tests
69 \li \c senfutil implements a very simple to use enhanced doxygen build with SENF symbol
71 \li \c senfutil allows specifying variables on the scons command line
72 \li \c senfutil supports more readable compile-time SENF loglevel configuration
74 Using the utility is quite simple
78 sys.path.extend(('senf/site_scons','/usr/lib/senf/site_scons'))
82 senfutil.SetupForSENF(env)
83 # senfutil.DefaultOptions(env)
85 # Set or change SCons environment variables with env.Append, env.Replace or env.SetDefault
87 CXXFLAGS = [ '-Wall', '-Woverloaded-virtual' ],
88 CXXFLAGS_final = [ '-O2' ],
89 CXXFLAGS_normal = [ '-O0', '-g' ],
90 CXXFLAGS_debug = [ '$CXXFLAGS_normal' ],
92 LINKFLAGS_normal = [ '-Wl,-S' ],
94 LOGLEVELS_debug = [ 'senf::log::Debug||VERBOSE' ],
96 PROJECTNAME = 'Example project',
97 PROJECTEMAIL = 'developer@domain.com',
98 DOCLINKS = [ ('Homepage', 'http://www.domain.com') ]
101 # Create a list of sources and tests. Sources are all *.cc files, test are *.test.cc
102 sources, tests = senfutil.Glob(env, exclude=['main.cc'] )
104 # Build objects from sources
105 objects = env.Object(sources)
108 env.Default( env.Program( target='example', source=objects + ['main.cc'] ) )
110 # Build a boost unit-test from additional test sources
111 env.BoostUnitTest( 'test', source=objects + tests)
113 # Build a documentation, autogenerates a Doxyfile
114 senfutil.Doxygen(env)
117 This example builds a simple binary from a number of source files (all '.cc' files). It links
118 against the SENF library and automatically sets all the correct compiler options using
119 <tt>senfutil.SetupForSENF( env )</tt>.
121 This script automatically uses a SENF installation either symlinked or imported into the current
122 project in directory 'senf' or, if this directory does not exist, a globally installed SENF.
124 \section senf_senfutil_options Build options
126 \c senfutil supports the <tt>debug=1</tt> or <tt>final=1</tt> build options. These parameters
127 select one of the build configurations 'debug', 'normal' or 'final'. The following variables are
128 supported each with separate values for all three configurations:
135 \c senfutil will detect the type of SENF library used (final or not) and set the correct compile
138 \section senf_senfutil_loglevels Specifying compile-time loglevels
140 To simplify specifying the compile-time loglevel configuration, the build variable \c LOGLEVELS
141 (and it's build configuration specific variants) may be set. This variable will be parsed and
142 converted into the correct \c SENF_LOG_CONF definition. The \c LOGLEVELS Syntax is
144 \par "" \e optional_stream \c | \e optional_area | \e level
146 where \e optional_stream and \e optional_area are optional fully scoped C++ names (e.g. \c
147 senf::log::Debug) and \e level is the loglevel. There must be \e no whitespace in a single
148 specification, multiple specifications are either specified using an array or separated with
151 \section senf_senfutil_default Default options
153 In the example above, all compile options are set manually. To specify the default customary
154 compile options for SENF programs, \c senfutil.DefaultOptions(env) is provided. This function is
158 senfutil.DefaultOptions(env) =>
160 CXXFLAGS = [ '-Wall', '-Woverloaded-virtual' ],
161 CXXFLAGS_final = [ '-O2' ],
162 CXXFLAGS_normal = [ '-O0', '-g' ],
163 CXXFLAGS_debug = [ '$CXXFLAGS_normal' ],
165 LINKFLAGS_normal = [ '-Wl,-S' ],
169 Thus above example can be simplified to
172 sys.path.extend(('senf/site_scons','/usr/lib/senf/site_scons'))
173 import glob, senfutil
176 senfutil.SetupForSENF(env)
177 senfutil.DefaultOptions(env)
179 env.Append( LOGLEVELS_debug = [ 'senf::log::Debug||VERBOSE' ],
180 PROJECTNAME = 'Example project',
181 PROJECTEMAIL = 'developer@domain.com',
182 DOCLINKS = [ ('Homepage', 'http://www.domain.com') ] )
184 sources, tests = senfutil.Glob(env, exclude=['main.cc'] )
186 objects = env.Object(sources)
187 env.Default( env.Program( target='example', source=objects + ['main.cc'] ) )
188 env.BoostUnitTest( 'test', source=objects + tests)
189 senfutil.Doxygen(env)
192 \section senf_senfutil_tests Building unit tests
194 Building unit tests mostly follows a standard pattern
197 # Generate list of sources and tests (sources=*.cc, tests=*.test.cc)
198 extra_sources = ['main.cc']
199 sources, tests = senfutil.Glob(env, exclude=extra_sources)
201 # Build object files needed for both main target and unit tests
202 objects = env.Object(sources)
204 # Build main target, e.g. a Binary with additional sources which are not part of the unit test
205 env.Program('example', objects+extra_sources)
207 # Build unit tests including additional test sources
208 env.BoostUnitTest('test', objects+tests)
211 It is important to exclude the \c main function from the unit-test build since the boost unit
212 test library provides it's own.
214 \section senf_senfutil_doxygen Building documentation
216 Documentation is built using the \c senfutil.Doxygen utility
219 env.Append( PROJECTNAME = "Example project",
220 PROJECTEMAIL = "coder@example.com",
221 COPYRIGHT = "The Master Coders",
222 DOCLINKS = [ ('Homeage', 'http://www.example.com') ],
223 REVISION = 'r'+os.popen('svnversion').read().strip().lower() )
225 senfutil.Doxygen(env)
228 The \c senfutil.Doxygen utility autogenerates a \c Doxyfile.
230 The utility will search for a SENF documentation in the \c senfdoc and \c %senf subdirectories
231 as well as via the senfutil module directory and some other standard locations. If SENF
232 documentation is found, the SENF tagfiles will automatically be added. Links will be resolved
233 to the documentation found.
235 \c senfutil.Doxygen takes some additional optional keyword arguments:
236 \li \c doxyheader: Path of an alternative HTML header
237 \li \c doxyfooter: Path of an alternative HTML footer
238 \li \c doxycss: Path on an alternative CSS file
239 \li \c mydoxyfile: If set to \c True, don't generate or clean the \c Doxyfile\
240 \li \c senfdoc_path: List of additional directories to search for SENF documentation
242 \section senf_senfutil_arguments 'scons' Command line arguments
244 \c senfutil automatically parses SCons command line arguments into the SCons build
245 environment. This allows specifying any parameter on the command line:
247 $ scons CXX=myg++ CXXFLAGS+=-mtune=geode
249 You may either set variables unconditionally using '=' or append values to the end of a list
253 /** \page senf_usage Using the SENF framework
255 The SENF Framework is a collection of loosely coupled modules. The libraries are heavily object
256 oriented and template based. For compatibility reasons, the libraries are therefore built
257 together with every project making use of the framework.
259 When starting a new project based on the SENF framework, it is advisable, to make use of the
260 SENFSCons build environment and use SVN to manage the code repository. This is the
261 configuration, described in this documentation.
263 \see \ref senf_build \n
265 \ref senf_components \n
268 \section senf_preliminaries Preliminaries
270 Before starting the development, make sure to fulfill the following requirements:
272 \li GNU g++, version at least 3.4
273 \li The Boost libraries (http://www.boost.org)
274 \li The SCons build tool (http://www.scons.org)
276 If you want to build the documentation, you additionally need
278 \li Doxygen (http://www.doxygen.org)
279 \li The \c dia diagram editor (http://www.gnome.org/projects/dia/)
280 \li HTML \c tidy (http://tidy.sourceforge.net/)
281 \li The \c xsltproc XSLT processor (http://xmlsoft.org/XSLT/xsltproc2.html)
282 \li The \c graphviz library (http://www.graphviz.org)
284 The library is only tested with gcc-3.4 and 4.0 on Linux. On other POSIX platforms with a BSD
285 Socket API, the library should be usable, possibly with some tweaking (except for the Scheduler,
286 which relies on \c epoll)
288 \section senf_compiler_options Compiler and Linker Options
290 If SENF is compiled in debug mode (SENF_DEBUG is defined), exception messages will automatically
291 include a stack backtrace. For this to work, you need to add the -rdynamic option to all link
292 commands. This feature depends on gcc and the GNU-libc.
294 It is <B>very important</B> that both the SENF library and the application using it are compiled
295 \e both either with or without this compiler switch (-DSENF_DEBUG). Otherwise, the compiler will
296 emit error messages which might be hard to debug.
299 /** \page senf_build Building the SENF framework
301 This procedure will test building the complete framework including the unit tests and the
302 Sniffer test application. This build is \e not needed to use the framework since every project
303 will include the full SENF source code itself (via Subversion).
305 After you have successfully built the library tests, you can continue to setup your own project
308 \see \ref senf_setup \n
309 \ref senf_components \n
312 \section senf_checkout Getting the code
314 To access the code, check out the code from the BerliOS repository. Change to your development
315 directory and use the following subversion command
318 $ svn checkout http://svn.berlios.de/svnroot/repos/senf/trunk senf
321 This will create a new directory \c senf within the current directory. For further documentation
322 on the use of Subversion, see the \c svn man-page or the subversion homepage at
323 http://subversion.tigris.org. A very good introduction and reference to subversion is available
324 at http://svnbook.red-bean.com.
326 \section senf_compile Building
328 To build the library, execute all unit tests and build the Sniffer test application, use
335 in the \c %senf directory. This assumes, that you want to build the library with your default
336 gcc and requires the boost libraries to be available in the system include paths. If this is
337 not the case, you can take a look at <tt>SConfig.template</tt> file. Copy this file to
338 <tt>SConfig</tt> and comment out all the variables you don't want to change (The \e values in
339 the template file are just arbitrary examples).
342 /** \page senf_setup Setting up a new project using SENF
344 The most simple way to use SENF for now is to checkout the svn repository and build SENF
345 yourselves. After you have built SENF, reference your SENF build directory from your build
346 environment. The most flexible way to do this, is to use a symbolic link to your SENF build.
348 Here an example \c SConstruct file for a project using SENF. This script expects SENF to be
349 found in the <tt>%senf</tt> sub-directory of the directory, where the \c SConstruct file is
350 found. This may either be a SENF checkout (if managing your project via subversion, you can use
351 <tt>svn:externals</tt> for this) or a symbolic link to your SENF checkout.
358 LIBS = [ 'senf', 'boost_regex', 'boost_iostreams' ],
359 CXXFLAGS = [ '-Wall', '-Woverloaded-virtual', '-Wno-long-long' ],
365 source = glob.glob('*.cc'),
369 When building against a self-built SENF which will probably be in debug mode, the '-DSENF_DEBUG'
370 option must be added to the compile command.
372 The most simple way to build using SENF is to use a very simple SCons helper which automatically
373 supports debug and final builds, uses SENF either centrally installed or locally built and has
374 some other nice features. See <a
375 href="../../senfscons/doc/html/index.html#senfutil_overview">Building Projects using SENF</a>
376 for more info and an example for this utility.
378 \see \ref senf_components \n
382 /** \page senf_components The SENF modules
384 The framework is made up of several modular components. When using the library, it is possible
385 to selectively choose to use only a subset of the implemented modules.
387 \see \ref senf_overview
389 \section libPPI libPPI: Packet Processing Infrastructure
391 The Packet Processing Infrastructure implements a modular framework for implementing packet
392 oriented network applications. The library provides a large set of pre-defined modules as well
393 as the necessary helpers to implement application specific processing modules.
395 \see <a href="../../PPI/doc/html/index.html">libPPI API reference</a>
397 \section libSocket libSocket: C++ abstraction of the BSD socket API
399 This library provides a high performance and object oriented abstraction of the standard socket
400 API. It utilizes a flexible and extensible policy based design. The library provides predefined
401 types for the important socket types (UDP and TCP sockets etc) including raw and packet sockets.
403 \see <a href="../../Socket/doc/html/index.html">libSocket API reference</a>
405 \section libPackets libPackets: Network packet manipulation
407 This library provides a very flexible infrastructure to parse, create and otherwise manipulate
408 packetized network data. Included is a library of several protocol parsers covering the basic
409 IPv4 and IPv6 network protocols down to the Ethernet layer.
411 \see <a href="../../Packets/doc/html/index.html">libPackets API reference</a>
413 \section libScheduler libScheduler: Asynchronous event handling
415 The scheduler library provides an object oriented interface to the standard UNIX \c select type
416 event dispatcher. It is based on the high performance \c epoll system call. It provides support
417 for read/write events as well as simple timer based events.
419 \see <a href="../../Scheduler/doc/html/index.html">libScheduler API reference</a>
421 \section libUtils libUtils: Collection of arbitrary utilities
423 This library is used be most all of the other modules for miscellaneous tools and utilities. We
426 \li Simple functions to manage daemon processes
427 \li Standard exception classes
428 \li senf::intrusive_refcount to simplify the implementation of classes usable with
430 \li boost::bind extensions
431 \li An interface to the \c g++ de-mangler integrated with type_info
432 \li Typedefs and rudimentary methods to simplify handling high-resolution time values
434 \see <a href="../../Utils/doc/html/index.html">libUtils API reference</a>
436 \section senfscons SENFSCons, the SENF build environment
438 SENF relies on SCons (http://www.scons.org) to build. To further simplify the common tasks, SENF
439 includes a library of custom routines and builders comprising a very concise build
440 environment. Included are a number of templates to help bootstrapping a new project or
443 \see <a href="../../senfscons/doc/html/index.html">SENFSCons reference</a>
446 /** \page senf_overview Introduction to the framework
448 The SENF framework is relatively complex and makes use of advanced features of the C++
449 language. To make the most efficient use of the framework, you should have at least a basic
450 understanding of C++ templates and the standard library concepts.
452 The library implementation at places makes heavy use of advanced template techniques and relies
453 on some very advanced template libraries from Boost. The aim was however for the \e external
454 interface of the library to be as simple as possible without sacrificing important functionality
455 or adversely impacting the runtime performance.
457 As already mentioned several times, the library relies on Boost (http://www.boost.org) as a
458 generic library of high quality reusable C++ components. It also makes frequent use of the
459 standard library. It is designed, to integrate well into both libraries and to use the same
462 \section senf_startup Getting starting developing with SENF
464 To introduce the framework and it's general structure, a simple example application is provided
465 in the SENF repository in the \c Sniffer module. Peruse this example to get a first look at how
468 When building a network Application with SENF, you will use several modules:
470 \li Use the <a href="../../Socket/doc/html/index.html">Socket library</a> for network
471 communication needs. This library includes support for raw and packet sockets to allow low
472 level network access.
473 \li Use the <a href="../../Scheduler/doc/html/index.html">Scheduler library</a> to coordinate
474 the asynchronous event processing. This drastically reduces the number of threads needed in
475 your application and will greatly enhance the overall responsiveness.
476 \li To interpret low level network packets, use the <a
477 href="../../Packets/doc/html/index.html">Packets library</a>. This library will provide
478 efficient and convenient access to all protocol fields. It supports parsing as well as
479 modifying and creating packets. It has default support for the most important Internet
480 protocols and is highly extensible with new protocols.
481 \li Go over the <a href="../../Utils/doc/html/index.html">Utils library</a>. It contains small
482 helpers to simplify tasks like daemonization, exception handling, debugging and so on.
484 The simplest way to get started is: copy the Sniffer application and start to modify it.
486 \see <a href="../../Examples/doc/html/index.html">Examples</a> \n
487 \ref senf_components \n
490 \section senf_conventions Coding Conventions
492 Here we have laid down the coding conventions used throughout the SENF framework. Please ad here
493 to these conventions when changing or adding code. If you use emacs, you can use the C++ IDE for
494 emacs from http://g0dil.de which greatly simplifies following these conventions.
496 \subsection senf_conventions_file_naming File Naming
498 Files should be named according to the main class they define. A single header file should
499 define only one main class. Exceptions to this rule are OK.
502 This simplifies finding the implementation/header for a given class and also reduces the
503 size of each single file.
505 The implementation is divided into a number of different files:
507 <table class="glossary"> <tr><td>\c .h</td><td>C public header</td></tr>
509 <tr><td>\c .hh</td><td>C++ public header</td></tr>
511 <tr><td>\c .ih</td><td>C++ internal header used only by the implementation. This header will
512 probably be included indirectly by the public header but is not meant to be perused by the
513 library user</td></tr>
515 <tr><td>\c .c</td><td>C implementation</td></tr>
517 <tr><td>\c .cc</td><td>C++ implementation of non-inline non-template functions and
520 <tr><td>\c .ct</td><td>C++ implementation of non-inline template functions and members</td></tr>
522 <tr><td>\c .cci</td><td>C++ implementation of inline non-template functions and
525 <tr><td>\c .cti</td><td>C++ implementation of inline template functions and members</td></tr>
527 <tr><td>\c .mpp</td><td>Special include file used for external iteration by the
528 Boost.Preprocessor library</td></tr> </table>
531 There are two part's to this: First, separating the implementation of inlines and templates
532 out of the header file makes the header file much easier to read. This is important, since
533 the header file will be used as a reference by the developers.
535 Separating inline from non-inline members is used together with the \c prefix_ convention
536 below to ensure the correct placement of inline vs non-inline members in the source
537 code. The C++ language requires, that inline members must be included into \e every
538 compilation unit, non-inline members however must be included \e only in one compilation
539 unit. Placing the inline members into a separate file allows to automate this: Simply moving
540 an implementation from one of the inline files into one of the non-inline files will change
541 the type of implementation accordingly.
543 \subsection senf_conventions_type_naming Type Naming
545 SENF prefers the use of the CapitalziedLettersToSeparateWords convention for class names. In
546 this case, class names must start with a capital letter. There are some exceptions to this rule:
547 Types which define new basic data types to be used like other built-in types may be named using
548 lowercase letters plus underscores. Also, if a type or class is directly related to some other
549 library (STL or Boost) which uses the underscore convention, it might be more sensible to follow
550 this convention. This is open to debate.
553 Naming types with capital letters nicely gives a visual clue, that a symbol is a type
554 name. This can also be used by the editor to highlight type names correctly. Additionally,
555 this convention is compact and does not add additional or repeated overhead.
557 \subsection senf_conventions_impl Implementation
559 Only in very few places, SENF allows the use of inline implementations (not to be confused with
560 inline functions). An \e implementation is inline, if it is written directly into the class
561 definition in the header file. Again there are exceptions to this rule but they are very few:
562 \li When defining simple exception classes, the 'what()' member may be defined inline if it
563 returns a string constant.
564 \li It may be OK to use inline implementations for one-line implementations in internal
566 \li The Packet library allows inline implementations for the definition of parsers since doing
567 so outside the declaration just gets to verbose and parsers definitions are quite length but
568 very simple and straight forward.
571 Implementing members inline inside the class declaration makes the declaration much harder
572 to read. Since the declaration in the header file will be used as a reference by the
573 developer, the header files should be as readable as possible.
575 Every function or method implementation in one of the implementation files must \e always be
576 prefixed with \c prefix_. This symbol is defined at the beginning of the file and undefined at
577 the end. The symbol must be defined to be \c inline in the \c .cti and \c .cci files and must be
578 defined empty in the \c .cc and \c .ct files.
581 Together with splitting inlines and non-inlines into separate files, this allows to
582 automatically include the inline definitions at the right places. See above.
584 Private data members are named with a trailing underscore character.
587 This helps distinguishing local variables from parameter names. The trailing underscore
588 does not interfere with other naming conventions and is allowed by the standard (underscore
589 at the beginning of the name are problematic since some classes of names beginning with an
590 underscore are reserved for the standard library implementation)
594 // :vim:textwidth=100
598 // c-file-style: "senf"
599 // indent-tabs-mode: nil
600 // ispell-local-dictionary: "american"
601 // compile-command: "scons doc"