Add senf.conf support and update senfutil
[senf.git] / Mainpage.dox
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \mainpage SENF: The Simple and Extensible Network Framework
24
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.
29
30     \section Goals
31
32     The main goals of this library are (in no particular order):
33
34     \li modular framework design
35     \li utilizing the power of modern C++
36     \li very low overhead for frequently called members
37     \li extensible design
38     \li concise interface
39
40     \section start Getting started
41
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.
47
48     \see \ref senf_usage\n
49          <a href="../../Examples/doc/html/index.html">Examples</a>
50
51     \section senfutil_overview Building Projects using SENF
52
53     When building projects using senf, SENFSCons has a very simple helper module \ref senfutil to
54     make the building of libraries utilizing senf simpler:
55     \code
56     import sys
57     sys.path.extend(('senf/site_scons','/usr/lib/senf/site_scons'))
58     import glob, senfutil
59
60     env = Environment()
61     senfutil.SetupForSENF(env)
62     senfutil.DefaultOptions(env)
63
64     env.Append( LOGLEVELS_debug  = [ 'senf::log::Debug||VERBOSE' ] )
65
66     env.Default(
67         env.Program( target = 'udpforward', source = glob.glob('*.cc') )
68     )
69     \endcode
70
71     This example builds a simple binary from a number of source files (all '.cc' files). It links
72     against the SENF library and automatically sets all the correct compiler options using
73     <tt>senfutil.SetupForSENF( env )</tt>.
74
75     This script automatically uses a SENF installation either symlinked or imported into the current
76     project in directory 'senf' or, if this directory does not exist, a globally installed SENF.
77
78     \see \ref senf_senfutil
79 */
80
81 /** \page senf_senfutil SENF SCons build utility
82
83     The \c senfutil utility for SCons helps setting up a project to compile against SENF:
84
85     \li \c senfutil adds all necessary libraries to link against
86     \li \c senfutil will set necessary compile options.
87     \li \c senfutil supports normal, debug and final project build options
88     \li \c senfutil allows specifying variables on the scons command line
89     \li \c senfutil supports more readable compile-time SENF loglevel configuration
90
91     Using the utility is quite simple
92
93     \code
94     import sys
95     sys.path.extend(('senf/site_scons','/usr/lib/senf/site_scons'))
96     import glob, senfutil
97
98     env = Environment()
99     senfutil.SetupForSENF(env)
100     # senfutil.DefaultOptions(env)
101
102     # Set or change SCons environment variables with env.Append, env.Replace or env.SetDefault
103     env.Append(
104         CXXFLAGS         = [ '-Wall', '-Woverloaded-virtual' ],
105         CXXFLAGS_final   = [ '-O2' ],
106         CXXFLAGS_normal  = [ '-O0', '-g' ],
107         CXXFLAGS_debug   = [ '$CXXFLAGS_normal' ],
108     
109         LINKFLAGS_normal = [ '-Wl,-S' ],
110
111         LOGLEVELS_debug  = [ 'senf::log::Debug||VERBOSE' ],
112     )
113
114     env.Default(
115         env.Program( target='udpforward', source=glob.glob('*.cc') )
116     )
117     \endcode
118
119     \section senf_senfutil_options Build options
120
121     \c senfutil supports the <tt>debug=1</tt> or <tt>final=1</tt> build options. These parameters
122     select one of the build configurations 'debug', 'normal' or 'final'. The following variables are
123     supported each with separate values for all three configurations:
124
125     \li \c CXXFLAGS    
126     \li \c CPPDEFINES
127     \li \c LINKFLAGS
128     \li \c LOGLEVELS
129
130     \c senfutil will detect the type of SENF library used (final or not) and set the correct compile
131     options.
132
133     \section senf_senfutil_loglevels Specifying compile-time loglevels
134
135     To simplify specifying the compile-time loglevel configuration, the build variable \c LOGLEVELS
136     (and it's build configuration specific variants) may be set. This variable will be parsed and
137     converted into the correct \c SENF_LOG_CONF definition. The \c LOGLEVELS Syntax is
138
139     \par "" \e optional_stream \c | \e optional_area | \e level
140
141     where \e optional_stream and \e optional_area are optional fully scoped C++ names (e.g. \c
142     senf::log::Debug) and \e level is the loglevel. There must be \e no whitespace in a single
143     specification, multiple specifications are either specified using an array or separated with
144     whitespace. 
145
146     \section senf_senfutil_default Default options
147
148     In the example above, all compile options are set manually. To specify the default customary
149     compile options for SENF programs, \c senfutil.DefaultOptions(env) is provided. This function is
150     identical to:
151
152     \code
153     senfutil.DefaultOptions(env) =>
154         env.Append(
155             CXXFLAGS         = [ '-Wall', '-Woverloaded-virtual' ],
156             CXXFLAGS_final   = [ '-O2' ],
157             CXXFLAGS_normal  = [ '-O0', '-g' ],
158             CXXFLAGS_debug   = [ '$CXXFLAGS_normal' ],
159
160             LINKFLAGS_normal = [ '-Wl,-S' ],
161         )
162     \endcode
163  */
164
165 /** \page senf_usage Using the SENF framework
166
167     The SENF Framework is a collection of loosely coupled modules. The libraries are heavily object
168     oriented and template based. For compatibility reasons, the libraries are therefore built
169     together with every project making use of the framework.
170
171     When starting a new project based on the SENF framework, it is advisable, to make use of the
172     SENFSCons build environment and use SVN to manage the code repository. This is the
173     configuration, described in this documentation.
174
175     \see \ref senf_build \n
176          \ref senf_setup \n
177          \ref senf_components \n
178          \ref senf_overview
179
180     \section senf_preliminaries Preliminaries
181
182     Before starting the development, make sure to fulfill the following requirements:
183
184     \li GNU g++, version at least 3.4
185     \li The Boost libraries (http://www.boost.org)
186     \li The SCons build tool (http://www.scons.org)
187
188     If you want to build the documentation, you additionally need
189
190     \li Doxygen (http://www.doxygen.org)
191     \li The \c dia diagram editor (http://www.gnome.org/projects/dia/)
192     \li HTML \c tidy (http://tidy.sourceforge.net/)
193     \li The \c xsltproc XSLT processor (http://xmlsoft.org/XSLT/xsltproc2.html)
194     \li The \c graphviz library (http://www.graphviz.org)
195
196
197     The library is only tested with gcc-3.4 and 4.0 on Linux. On other POSIX platforms with a BSD
198     Socket API, the library should be usable, possibly with some tweaking (except for the Scheduler,
199     which relies on \c epoll)
200
201     \section senf_compiler_options Compiler and Linker Options
202
203     If SENF is compiled in debug mode (SENF_DEBUG is defined), exception messages will automatically
204     include a stack backtrace. For this to work, you need to add the -rdynamic option to all link
205     commands. This feature depends on gcc and the GNU-libc.
206
207     It is <B>very important</B> that both the SENF library and the application using it are compiled
208     \e both either with or without this compiler switch (-DSENF_DEBUG). Otherwise, the compiler will
209     emit error messages which might be hard to debug.
210  */
211
212 /** \page senf_build Building the SENF framework
213
214     This procedure will test building the complete framework including the unit tests and the
215     Sniffer test application. This build is \e not needed to use the framework since every project
216     will include the full SENF source code itself (via Subversion).
217
218     After you have successfully built the library tests, you can continue to setup your own project
219     using SENF.
220
221     \see \ref senf_setup \n
222          \ref senf_components \n
223          \ref senf_overview
224
225     \section senf_checkout Getting the code
226
227     To access the code, check out the code from the BerliOS repository. Change to your development
228     directory and use the following subversion command
229
230     <pre>
231     $ svn checkout http://svn.berlios.de/svnroot/repos/senf/trunk senf
232     </pre>
233
234     This will create a new directory \c senf within the current directory. For further documentation
235     on the use of Subversion, see the \c svn man-page or the subversion homepage at
236     http://subversion.tigris.org. A very good introduction and reference to subversion is available
237     at http://svnbook.red-bean.com.
238
239     \section senf_compile Building
240
241     To build the library, execute all unit tests and build the Sniffer test application, use
242
243     <pre>
244     $ scons
245     $ scons all_tests
246     </pre>
247
248     in the \c senf directory. This assumes, that you want to build the library with your default gcc
249     and requires the boost libraries to be available in the system include paths. If this is not the
250     case, you can take a look at <tt>SConfig.template</tt> file. Copy this file to <tt>SConfig</tt>
251     and comment out all the variables you don't want to change (The \e values in the template file
252     are just arbitrary examples).
253  */
254
255 /** \page senf_setup Setting up a new project using SENF
256
257     The most simple way to use SENF for now is to checkout the svn repository and build SENF
258     yourselves. After you have built SENF, reference your SENF build directory from your build
259     environment. The most flexible way to do this, is to use a symbolic link to your SENF build.
260
261     Here an example \c SConstruct file for a project using SENF. This script expects SENF to be
262     found in the <tt>%senf</tt> sub-directory of the directory, where the \c SConstruct file is
263     found. This may either be a SENF checkout (if managing your project via subversion, you can use
264     <tt>svn:externals</tt> for this) or a symbolic link to your SENF checkout.
265
266     \code
267     import glob
268
269     env = Environment(
270
271         LIBS     = [ 'senf', 'boost_regex', 'boost_iostreams' ],
272         CXXFLAGS = [ '-Wall', '-Woverloaded-virtual', '-Wno-long-long' ],
273
274     )
275
276     env.Program(
277         target = 'mytarget',
278         source = glob.glob('*.cc'),
279     );
280     \endcode
281
282     When building against a self-built SENF which will probably be in debug mode, the '-DSENF_DEBUG'
283     option must be added to the compile command.
284
285     The most simple way to build using SENF is to use a very simple SCons helper which automatically
286     supports debug and final builds, uses SENF either centrally installed or locally built and has
287     some other nice features. See <a
288     href="../../senfscons/doc/html/index.html#senfutil_overview">Building Projects using SENF</a>
289     for more info and an example for this utility.
290
291     \see \ref senf_components \n
292          \ref senf_overview
293  */
294
295 /** \page senf_components The SENF modules
296
297     The framework is made up of several modular components. When using the library, it is possible
298     to selectively choose to use only a subset of the implemented modules.
299
300     \see \ref senf_overview
301
302     \section libPPI libPPI: Packet Processing Infrastructure
303
304     The Packet Processing Infrastructure implements a modular framework for implementing packet
305     oriented network applications. The library provides a large set of pre-defined modules as well
306     as the necessary helpers to implement application specific processing modules.
307
308     \see <a href="../../PPI/doc/html/index.html">libPPI API reference</a>
309
310     \section libSocket libSocket: C++ abstraction of the BSD socket API
311
312     This library provides a high performance and object oriented abstraction of the standard socket
313     API. It utilizes a flexible and extensible policy based design. The library provides predefined
314     types for the important socket types (UDP and TCP sockets etc) including raw and packet sockets.
315
316     \see <a href="../../Socket/doc/html/index.html">libSocket API reference</a>
317
318     \section libPackets libPackets: Network packet manipulation
319
320     This library provides a very flexible infrastructure to parse, create and otherwise manipulate
321     packetized network data. Included is a library of several protocol parsers covering the basic
322     IPv4 and IPv6 network protocols down to the Ethernet layer.
323
324     \see <a href="../../Packets/doc/html/index.html">libPackets API reference</a>
325
326     \section libScheduler libScheduler: Asynchronous event handling
327
328     The scheduler library provides an object oriented interface to the standard UNIX \c select type
329     event dispatcher. It is based on the high performance \c epoll system call. It provides support
330     for read/write events as well as simple timer based events.
331
332     \see <a href="../../Scheduler/doc/html/index.html">libScheduler API reference</a>
333
334     \section libUtils libUtils: Collection of arbitrary utilities
335
336     This library is used be most all of the other modules for miscellaneous tools and utilities. We
337     have
338
339     \li Simple functions to manage daemon processes
340     \li Standard exception classes
341     \li senf::intrusive_refcount to simplify the implementation of classes usable with
342         boost::intrusive_ptr
343     \li boost::bind extensions
344     \li An interface to the \c g++ de-mangler integrated with type_info
345     \li Typedefs and rudimentary methods to simplify handling high-resolution time values
346
347     \see <a href="../../Utils/doc/html/index.html">libUtils API reference</a>
348
349     \section senfscons SENFSCons, the SENF build environment
350
351     SENF relies on SCons (http://www.scons.org) to build. To further simplify the common tasks, SENF
352     includes a library of custom routines and builders comprising a very concise build
353     environment. Included are a number of templates to help bootstrapping a new project or
354     component.
355
356     \see <a href="../../senfscons/doc/html/index.html">SENFSCons reference</a>
357  */
358
359 /** \page senf_overview Introduction to the framework
360
361     The SENF framework is relatively complex and makes use of advanced features of the C++
362     language. To make the most efficient use of the framework, you should have at least a basic
363     understanding of C++ templates and the standard library concepts.
364
365     The library implementation at places makes heavy use of advanced template techniques and relies
366     on some very advanced template libraries from Boost. The aim was however for the \e external
367     interface of the library to be as simple as possible without sacrificing important functionality
368     or adversely impacting the runtime performance.
369
370     As already mentioned several times, the library relies on Boost (http://www.boost.org) as a
371     generic library of high quality reusable C++ components. It also makes frequent use of the
372     standard library. It is designed, to integrate well into both libraries and to use the same
373     concepts and ideas.
374
375     \section senf_startup Getting starting developing with SENF
376
377     To introduce the framework and it's general structure, a simple example application is provided
378     in the SENF repository in the \c Sniffer module. Peruse this example to get a first look at how
379     to make use of SENF.
380
381     When building a network Application with SENF, you will use several modules:
382
383     \li Use the <a href="../../Socket/doc/html/index.html">Socket library</a> for network
384         communication needs. This library includes support for raw and packet sockets to allow low
385         level network access.
386     \li Use the <a href="../../Scheduler/doc/html/index.html">Scheduler library</a> to coordinate
387         the asynchronous event processing. This drastically reduces the number of threads needed in
388         your application and will greatly enhance the overall responsiveness.
389     \li To interpret low level network packets, use the <a
390         href="../../Packets/doc/html/index.html">Packets library</a>. This library will provide
391         efficient and convenient access to all protocol fields. It supports parsing as well as
392         modifying and creating packets. It has default support for the most important Internet
393         protocols and is highly extensible with new protocols.
394     \li Go over the <a href="../../Utils/doc/html/index.html">Utils library</a>. It contains small
395         helpers to simplify tasks like daemonization, exception handling, debugging and so on.
396
397     The simplest way to get started is: copy the Sniffer application and start to modify it.
398
399     \see <a href="../../Examples/doc/html/index.html">Examples</a> \n
400          \ref senf_components \n
401          \ref senf_setup
402
403     \section senf_conventions Coding Conventions
404     
405     Here we have laid down the coding conventions used throughout the SENF framework. Please ad here
406     to these conventions when changing or adding code. If you use emacs, you can use the C++ IDE for
407     emacs from http://g0dil.de which greatly simplifies following these conventions.
408
409     \subsection senf_conventions_file_naming File Naming
410
411     Files should be named according to the main class they define. A single header file should
412     define only one main class. Exceptions to this rule are OK.
413
414     \par Rationale:
415         This simplifies finding the implementation/header for a given class and also reduces the
416         size of each single file.
417     
418     The implementation is divided into a number of different files:
419
420     <table class="glossary"> <tr><td>\c .h</td><td>C public header</td></tr>
421
422     <tr><td>\c .hh</td><td>C++ public header</td></tr>
423
424     <tr><td>\c .ih</td><td>C++ internal header used only by the implementation. This header will
425     probably be included indirectly by the public header but is not meant to be perused by the
426     library user</td></tr>
427
428     <tr><td>\c .c</td><td>C implementation</td></tr>
429
430     <tr><td>\c .cc</td><td>C++ implementation of non-inline non-template functions and
431     members</td></tr>
432
433     <tr><td>\c .ct</td><td>C++ implementation of non-inline template functions and members</td></tr>
434
435     <tr><td>\c .cci</td><td>C++ implementation of inline non-template functions and
436     members</td></tr>
437     
438     <tr><td>\c .cti</td><td>C++ implementation of inline template functions and members</td></tr>
439
440     <tr><td>\c .mpp</td><td>Special include file used for external iteration by the
441     Boost.Preprocessor library</td></tr> </table>
442
443     \par Rationale:
444         There are two part's to this: First, separating the implementation of inlines and templates
445         out of the header file makes the header file much easier to read. This is important, since
446         the header file will be used as a reference by the developers.
447     \par
448         Separating inline from non-inline members is used together with the \c prefix_ convention
449         below to ensure the correct placement of inline vs non-inline members in the source
450         code. The C++ language requires, that inline members must be included into \e every
451         compilation unit, non-inline members however must be included \e only in one compilation
452         unit. Placing the inline members into a separate file allows to automate this: Simply moving
453         an implementation from one of the inline files into one of the non-inline files will change
454         the type of implementation accordingly.
455
456     \subsection senf_conventions_type_naming Type Naming
457
458     SENF prefers the use of the CapitalziedLettersToSeparateWords convention for class names. In
459     this case, class names must start with a capital letter. There are some exceptions to this rule:
460     Types which define new basic data types to be used like other built-in types may be named using
461     lowercase letters plus underscores. Also, if a type or class is directly related to some other
462     library (STL or Boost) which uses the underscore convention, it might be more sensible to follow
463     this convention. This is open to debate.
464
465     \par Rationale:
466         Naming types with capital letters nicely gives a visual clue, that a symbol is a type
467         name. This can also be used by the editor to highlight type names correctly. Additionally,
468         this convention is compact and does not add additional or repeated overhead.
469
470     \subsection senf_conventions_impl Implementation
471
472     Only in very few places, SENF allows the use of inline implementations (not to be confused with
473     inline functions). An \e implementation is inline, if it is written directly into the class
474     definition in the header file. Again there are exceptions to this rule but they are very few:
475     \li When defining simple exception classes, the 'what()' member may be defined inline if it
476         returns a string constant.
477     \li It may be OK to use inline implementations for one-line implementations in internal
478         headers. 
479     \li The Packet library allows inline implementations for the definition of parsers since doing
480         so outside the declaration just gets to verbose and parsers definitions are quite length but
481         very simple and straight forward.
482
483     \par Rationale:
484         Implementing members inline inside the class declaration makes the declaration much harder
485         to read. Since the declaration in the header file will be used as a reference by the
486         developer, the header files should be as readable as possible.
487
488     Every function or method implementation in one of the implementation files must \e always be
489     prefixed with \c prefix_. This symbol is defined at the beginning of the file and undefined at
490     the end. The symbol must be defined to be \c inline in the \c .cti and \c .cci files and must be
491     defined empty in the \c .cc and \c .ct files.
492
493     \par Rationale:
494         Together with splitting inlines and non-inlines into separate files, this allows to
495         automatically include the inline definitions at the right places. See above.
496
497     Private data members are named with a trailing underscore character.
498
499     \par Rationale:
500         This helps distinguishing local variables from parameter names. The trailing underscore
501         does not interfere with other naming conventions and is allowed by the standard (underscore
502         at the beginning of the name are problematic since some classes of names beginning with an
503         underscore are reserved for the standard library implementation)
504  */
505
506 \f
507 // :vim:textwidth=100
508 // Local Variables:
509 // mode: c++
510 // fill-column: 100
511 // c-file-style: "senf"
512 // indent-tabs-mode: nil
513 // ispell-local-dictionary: "american"
514 // compile-command: "scons doc"
515 // mode: flyspell
516 // mode: auto-fill
517 // End: