File: tcc.inc

package info (click to toggle)
tcng 10b-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,644 kB
  • sloc: ansic: 19,040; pascal: 4,640; yacc: 2,619; sh: 1,914; perl: 1,546; lex: 772; makefile: 751
file content (606 lines) | stat: -rw-r--r-- 21,578 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
%
% tcc.inc - Traffic Control Compiler
%
% Written 2001,2002,2004 by Werner Almesberger
% Copyright 2001 EPFL-ICA
% Copyright 2001,2002 Bivio Networks, Network Robots
% Copyright 2002,2004 Werner Almesberger
%


%------------------------------------------------------------------------------


\prog{tcng} reads traffic control specifications in the \prog{tcng}
language and generates command or files for a number of mechanisms
that are used to implement traffic control functionality.

We describe the invocation of \prog{tcng}, and give an overview how
\prog{tcng} interacts with the output processors of the respective
targets.


%------------------------------------------------------------------------------


\section{Invocation}

The number of \prog{tcng}'s command-line options may be intimidating at
first. \prog{tcng} is typically invoked from scripts that provide all
the default options needed in the specific scenario. In interactive use,
the most common options are the target selectors \raw{-t} and \raw{-x}.

If only using traffic control configured by \name{iproute2/tc}, no
command line options are needed.


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


\subsection{Usage}
\label{tccusg}

\raw{tcng}
$[$\raw{-c}$]$
$[$\raw{-d} $\ldots]$
$[$\raw{-E}$]$
$[$\raw{-i \meta{default\_interface}}$]$
$[$\raw{-l \meta{location\_file}}$]$
$[$\raw{-n}$]$
$[$\raw{-q}$]$
$[$\raw{-r}$]$
$[$\raw{-w}$]$
$[$\raw{-W$[$no$]$\meta{condition}}$]$
$[$\raw{-O$[$no$]$\meta{option}}$]$
$[$\raw{-x \meta{element}:\meta{ext\_target}} $\ldots]$
$[$\raw{-t $[$no$]$\meta{target}} $\ldots]$
$[$\raw{-u \meta{var\_use\_file}}$]$
$[$\raw{-X\meta{phase},\meta{argument}}$]$
$[$\meta{cpp\_option}$]$
$[$\meta{file}$]$

\raw{tcng} \raw{-V}

\begin{description}
  \item[\raw{-c}] only check validity of input, don't build a
    configuration. If requested, the location file and the variable use
    file are also generated when using \raw{-c}
  \item[\raw{-d}] increase debugging level
  \item[\raw{-E}] only run \prog{cpp}, and send its output to standard
    output. This is useful for separately running files through \prog{cpp},
    while using the default includes added by \prog{tcng}.
  \item[\raw{-i \meta{default\_interface}}] interface to use if none is
    specified in the description file. See section \ref{inthist} for
    further details.
  \item[\raw{-l \meta{location\_file}}] write a list of source code locations
    of traffic control elements to the specified file. See section
    \ref{locfile} for details. Using the special file name \name{stderr} sends
    the output to standard error.
  \item[\raw{-n}] do not include \name{default.tc}. By default, \prog{tcng}
    includes this file, which in turn includes the files described
    in section \ref{tcnginc}. This can be undesirable, e.g. if operating in
    a non-TCP/IP context, or if using a different default include file with
    application-specific definitions. In the latter case, the following
    options should be used: \\
    \verb"tcng" $\ldots$ \verb"-n" $\ldots$ \verb"-Xp,--include"
      \verb"-Xp,/"\meta{directory}\verb"/"\meta{file} $\ldots$
  \item[\raw{-O$[$no$]$\meta{option}}] enable or disable the specified
    optimization. The following optimizations are recognized:
    \begin{description}
      \item[\name{cse}] common subexpression elimination
      \item[\name{ne}] turn \raw{!=} into multiple \raw{==}s
      \item[\name{prefix}] generate prefix matches instead of bit tests
    \end{description}
    By default, all optimizations except \name{cse} are turned off.
  \item[\raw{-q}] quiet, produce terse output
  \item[\raw{-r}] remove old queuing disciplines before adding new
    ones (\name{tc} only)
  \item[\raw{-t $[$\meta{elem\raw{:}}$][$no$]$\meta{target}} $\ldots$]
    enable or disable target (see section \ref{targets}).
    The only element currently supported is
    \name{if}. Supported targets are \name{all}, \name{tc} (default), \name{c},
    and \name{ext}. The \raw{-t} options can be repeated to enable or disable
    multiple targets.
  \item[\raw{-u \meta{var\_use\_file}}] for each variable, write its name and
    value to the specified file. See section
    \ref{varfile} for details. Using the special file name \name{stderr} sends
    the output to standard error.
  \item[\raw{-V}] print version number and exit
  \item[\raw{-w}] suppress all warnings
  \item[\raw{-W$[$no$]$\meta{condition}}] enable or disable issuing a warning
    message on the specified condition. The following conditions are
    recognized:
    \begin{description}
      \item[\name{constpfx}] warn if using the \verb"/" (mask) operator on a
	constant IPv4 or IPv6 address, as in \verb"ip_src == 1.2.3.0/24",
        which should probably be \verb"ip_src/24 == 1.2.3.0"
      \item[\name{expensive}]  generate warnings when encountering
	``expensive'' constructs in \name{if} classifier.
	A construct is considered ``expensive'' if processing it
	may take \prog{tcng} an unusual amount of time.
	Operations like negation, certain tests for non-equality, or
	static classification that follows metering, are ``expensive''.

	Because \name{expensive} may be overly pessimistic,
	\name{exppostopt} should be used whenever possible.
      \item[\name{experror}] turns warnings from \name{expensive} or
	\name{exppostopt} into fatal errors. Setting \name{experror} without
	also setting \name{expensive} or \name{exppostopt} has no effect.
      \item[\name{explicit}] warn if a class if explicitly specified for the
        inner queuing discipline of \name{dsmark}, \name{egress}, or
	\name{ingress}
      \item[\name{exppostopt}] like \name{expensive},
	but test for ``expensive'' constructs
	after trying to optimize the expression, which may eliminate some
	apparently expensive constructs. \name{exppostopt} can only
	indicate in which \name{if} classifier the expression occurred,
	not in which selector of that classifier.
	\name{expensive} has no effect if \name{exppostopt} is set.

	Note that neither
	\name{expensive} nor \name{exppostopt} are useful when using
	\name{nocombine} (see section{barriers}).
      \item[\name{redefine}] warn if re-defining variables
      \item[\name{truncate}] warn if truncating values, e.g. when converting
        a floating-point number to an integer
      \item[\name{unused}] report unused variables
    \end{description}
    By default, all warnings except \name{explicit} and \name{unused} are
    turned off.
  \item[\raw{-x \meta{element}:\meta{ext\_target}} $\ldots$]
    register external target (see section \ref{targets}). The \raw{-x} option
    can be repeated to register multiple external targets.
  \item[\raw{-X\meta{phase},\meta{argument}}] verbatim argument for specific
     build phase. See section \ref{phtcc} for details.
  \item[\meta{cpp\_option}] one of the following options for the C
    pre-processor: \raw{-I\meta{dir}},
    \raw{-D\meta{name}}$[$\raw{=\meta{value}}$]$, or \raw{-U\meta{name}}
\end{description}

\prog{tcng} also recognizes a number of undocumented options, such as
\raw{-B} and \raw{-N}. These options usually enable experimental
features, like alternative algorithms for processing \name{if}
expressions, and they are not recommended for normal use of \prog{tcng}.
Changes to undocumented options are mentioned in \prog{tcng}'s change
log (file \path{CHANGES}).


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


\subsection{Phases underneath \prog{tcng}}
\label{phtcc}

\prog{tcng} and its companion program \prog{tcc-module} do not only take
command-line options for themselves, but they can also pass command-line
options to programs they invoke. 

Each such program invocation is called a ``phase'', and has a one-letter
name assigned to it. Options are passed to that specific phase, with the
command-line option \raw{-X\meta{phase},\meta{option}}

The phases and their names are shown in figure \ref{phtccfig}.

\begin{figure}[ht]
\begin{center}
\epsfig{file=phtcc.eps}
\end{center}
\caption{Parameter passing to phases underneath \prog{tcng}.}
\label{phtccfig}
\end{figure}

Note the two \prog{cpp} phases of \prog{tcsim} and \prog{tcng} are 
identified by a upper and lower case ``p'', respectively.

For the external interface, parameters can also be sent to a specific
external program (\name{tcc-ext-\meta{name}}) with the phase name
\raw{x\meta{name}}.


%------------------------------------------------------------------------------


\section{Targets}
\label{targets}

\prog{tcng} can generate output for various ``targets'', which then
perform the actual configuration. Targets are selected with the
command-line options \raw{-t} and \raw{-x}.


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


\subsection{The ``tc'' target}

This is the default target.

\prog{tcng} outputs commands for the
\prog{tc} command, which configures the software-based traffic
control subsystem in the Linux kernel.

These commands are written to standard output, and can be processed
by a shell. Note that \prog{tcng} may detect errors only after it has
begun generating output, so in order to avoid partial configuration,
the output should be stored in a temporary file, and only passed to
the shell after \prog{tcng} has completed.

Example:

\begin{verbatim}
#!/bin/sh
tcng ... >tmpfile || { rm -f tmpfile; exit 1; }
. tmpfile
rm -f tmpfile
\end{verbatim}


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


\subsection{The ``C'' target}

The ``C'' target is enabled with the command-line option \raw{-tc}.

Instead of using the \name{u32} classifier for the \name{if} construct,
``C'' writes the corresponding expression in the C language to a file,
and generates a kernel module for it. The resulting custom-built
classifier should be much more efficient than a classifier using
\name{u32}.

The commands to load the kernel module are issued on standard output,
along with the \name{tc} commands, so the same scripts as for the
``tc'' target can be used.


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


\subsection{The external target}

The external target is enabled with the command-line option
\raw{-xall:\meta{name}} or
\raw{-xif:\meta{name}}, where \meta{name} is the corresponding external
program.

The external interface is described in chapter \ref{chpext}. As
discussed further in that chapter, \prog{tcng} may build a hybrid
configuration combining \name{tc} and elements from the external
interface with \raw{-xif:\meta{name}}, while it uses only the
external interface with \raw{-xall:\meta{name}}.

Example:

The following configuration

\begin{verbatim}
egress {
    drop if tcp_sport != PORT_SSH;
}
\end{verbatim}

yields, when invoking \prog{tcng} with \raw{-xif:err} (the external
program \path{tcc-ext-err} simply echoes the configuration data
from \prog{tcng} on standard error):

\name{tc} commands on standard output:
{\small
\begin{verbatim}
tc qdisc add dev eth0 handle 1:0 root dsmark indices 1 default_index 0
\end{verbatim}
}

External configuration on standard error:
\begin{verbatim}
# 7700
block eth0 egress
offset 100 = 0+(0:4:4 << 5)
action 0 = drop
action 1 = unspec
match 0:72:8=0x06 100:0:16=0x0016 action 1
match 0:72:8=0x06 action 0
match action 1
# END
\end{verbatim}

When invoking \prog{tcng} with \raw{-xall:err}, we only get an
external configuration, on standard error:

\begin{verbatim}
# fc00
offset 100 = 0+(0:4:4 << 5)
block eth0 egress
qdisc 1 = dsmark indices 1
action 0 = drop
action 1 = unspec
match 0:72:8=0x06 100:0:16=0x0016 action 1
match 0:72:8=0x06 action 0
match action 1
# END
\end{verbatim}

Note: the comment lines (\verb"# ...") are inserted by \path{tcc-ext-err}
and are not part of the configuration data passed from \prog{tcng}.


%------------------------------------------------------------------------------


\section{File formats}

\prog{tcng} generates a number of different output files. The target-specific
files have already been described in section \ref{targets}, with more details
on the external interface in section \ref{extcfg}. In this section, we
describe the files which do not depend on a specific target.


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


\subsection{Location map}
\label{locfile}

When invoked with the option \raw{-l \meta{location\_file}}, \prog{tcng} writes
the source code locations of traffic control elements to the specified file.

The file format is as follows:

\meta{type} \meta{identifier} \meta{tag} \meta{file\_name} \meta{line\_number}

\begin{description}
  \item[\meta{type}] is the type of the element (see below)
  \item[\meta{identifier}] is a string that uniquely identifies the element
  \item[\meta{tag}] is a user-provided identifier (``--'' if no identifier was
    provided)
  \item[\meta{file\_name}] is the name of the source file containing the
    definition of the element (``--'' if no file name is available; note that
    \prog{tcng} uses the name \raw{<stdin>} for standard input)
  \item[\meta{line\_number}] is the approximate line number
\end{description}

The format of the identifier depends on the type of the element:

\begin{tabular}{ll}
  Type name & Identifier string \\
  \hline
  \name{device}  & \meta{interface} \\
  \name{qdisc}   & \raw{\meta{interface}:\meta{qdisc}} \\
  \name{class}   & \raw{\meta{interface}:\meta{qdisc}:\meta{class\_number}} \\
  \name{filter}  & \raw{\meta{interface}:\meta{qdisc}:\meta{class\_number}%
:\meta{priority}} \\
  \name{tunnel}  & \raw{\meta{interface}:\meta{qdisc}:\meta{class\_number}%
:\meta{priority}:\meta{tunnel\_number}} \\
  \name{element} & \raw{\meta{interface}:\meta{qdisc}:\meta{class\_number}%
:\meta{priority}:\meta{element\_index}} \\
  \name{police}  & \meta{bucket\_number} \\
\end{tabular}

\meta{qdisc} is the queuing discipline number for egress, or
\name{ingress} at ingress. For \name{filter} and \name{element},
\meta{class\_number} is an empty string if the filter is rooted at the
queuing discipline. \meta{element\_index} is the zero-based number of the
element on that filter. Note that buckets are also identified as
policers.

Programs reading location maps should not make any assumption about
the order in which entries are written.

Future versions of \prog{tcng} may add more fields to a map line, so any
programs reading location maps should not assume that a line ends
after the line number.

Example:

\begin{verbatim}
dev "eth0" {
    prio (1) {
        class (1,"aTag")
            if 1
        {
            fifo (2,tag "another_tag");
        }
    }
}
\end{verbatim}

yields the following location map:

\begin{verbatim}
device eth0 - <stdin> 1
qdisc eth0:1 - <stdin> 2
class eth0:1:1 aTag <stdin> 3
qdisc eth0:2 another_tag <stdin> 6
filter eth0:1::1 - <stdin> 2
element eth0:1::1:0 - <stdin> 4
\end{verbatim}

Note that \name{if} is converted into a filter with elements.


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


\subsection{Variable use list}
\label{varfile}

When invoked with the option \raw{-u \meta{variable\_use\_file}},
\prog{tcng} writes the names of all variables and their content to the
specified file.

Each line is in one of the following formats:

\raw{\{ \meta{type} \meta{identifier}}

\raw{\{}

\raw{\}}

\raw{\$\meta{name} = \meta{number}}

\raw{\$\meta{name} = \meta{number} \meta{unit}}

\raw{\$\meta{name} = expression}

\raw{\$\meta{name} = \meta{type} \meta{identifier}}

\meta{name} is the variable name. \meta{number} is an integer or a
floating-point number. \meta{unit} is the unit of measurement, without
prefix. Units are described in section \ref{units}.

For variables containing non-constant expressions, simply the word
\raw{expression} is output as the value. Future versions of \prog{tcng}
may add further information after this keyword.

For variables containing traffic control elements, the format is
identical to the first two fields in the location map entry of that
element. Note that only queuing disciplines, classes, filters, buckets,
and policers can be assigned to variables.

The beginning of a scope is indicated with an opening curly brace
followed by the identifier of the element that started the scope.
Scopes created by nesting a block directly within another block have
no element identifying the scope and are denoted by a line containing
only the opening curly brace. Likewise, the end of a scope is
indicated with a closing curly brace.

Example:

\begin{verbatim}
prio {
    $foo = 42
}
\end{verbatim}

yields the following variable use list:

\begin{verbatim}
{ device eth0
{ qdisc eth0:1
$foo = 42
}
}
\end{verbatim}

Note that the scope for the default device is automatically generated.
As a special case, the scope of an unnumbered class is marked with
the identifier \raw{\meta{interface}:\meta{qdisc}:unnumbered}

Programs reading a variable use list file should not make any
assumption about the order in which entries within the same scope are
written. Variables with the same name will appear once per distinct
variable, within the respective scope.

Note that forward-declared variables are placed in the scope of their
assignment, and not the scope of their declaration.

Future versions of \prog{tcng} may include whitespace before dollar signs
and curly braces. Furthermore, the syntax
\raw{\$\meta{name} = forward}
is reserved for possible future use.


%------------------------------------------------------------------------------


\section{Adding new traffic control elements to \prog{tcng}}

While it is possible to add new traffic control elements to \prog{tcng},
this is currently somewhat complicated. In this section, we outline the
general procedure. For further details, the source code of existing
traffic control elements provides the best reference.

Before adding new elements to \prog{tcng}, the possibility of re-using
existing elements should be considered. It is frequently easier to
provide a set of macros that adapt an existing element, than
implementing new elements from scratch.


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


\subsection{Adding new queuing disciplines}

If the new queuing discipline requires new parameters, the following
files need to be changed:

\begin{description}
  \item[\path{tcc/Parameters}] defines name and type of the parameters.
    Various include files are automatically generated from this file.
  \item[\path{tcc/tcng.l}] parses the parameter name and returns a
    suitable token
  \item[\path{tcc/tcng.y}] declares the token (in a \verb"%token"
    line), and processes the parameter in the \name{parameter\_expression}
    rule
\end{description}

For the queuing discipline, a file called \path{q\_\meta{name}.c}
needs to be written, that provides the functions and data structures
that define how the queuing discipline is processed.

In addition to writing the \path{q\_\meta{name}.c} file, the following
files need to be changed:

\begin{description}
  \item[\path{Makefile}] include \path{q\_\meta{name}.c} in \name{FILES}
  \item[\path{tcc/Makefile}] include \path{q\_\meta{name}.o} in \name{OBJS}
  \item[\path{tcc/qdisc.h}] add a declaration of the descriptor
  \item[\path{tcc/tcng.l}] parses the queuing discipline name and returns
    a suitable token
  \item[\path{tcc/tcng.y}] declares the token (in a \verb"%token"
    line), and processes the queuing discipline in the \name{qdisc\_name}
    rule
\end{description}

Also, new elements should be exercised by the regression tests. Adding
a new test case involves the following files:

\begin{description}
  \item[\path{tests/\meta{name}}] the file containing the actual tests
  \item[\path{Makefile}] include \path{tests/\meta{name}} in \name{FILES}
\end{description}


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


\subsection{Adding new filters}

The procedures for adding parameters and regression tests are the same
for filters as for queuing disciplines.

For the filter, a file called \path{f\_\meta{name}.c}
needs to be written, that provides the functions and data structures
that define how the filter is processed. Furthermore, the following
files need to be changed:

\begin{description}
  \item[\path{Makefile}] include \path{f\_\meta{name}.c} in \name{FILES}
  \item[\path{tcc/Makefile}] include \path{f\_\meta{name}.o} in \name{OBJS}
  \item[\path{tcc/filter.h}] add a declaration of the descriptor
  \item[\path{tcc/tcng.l}] parses the filter name and returns
    a suitable token
  \item[\path{tcc/tcng.y}] declares the token (in a \verb"%token"
    line), and processes the filter in the \name{filter\_name}
    rule
\end{description}


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


\subsection{Adding new meters}

In general, new metering functions are implemented using the \name{bucket}
primitive. No change to \prog{tcng} is needed for this.

The file \path{tcng/tcc/meters.tc.in} contains the
definitions of the meters which are part of the \prog{tcng} language.

\path{meters.tc.in} uses a special pseudo preprocessor directive called
\verb"#map". This directive is converted by \path{tcng/tcc/tcc\_var2fix.pl}
to a set of macros for elements with a \prog{tcng}-style parameter list.
Please consult the source code of \path{tcng/tcc/tcc\_var2fix.pl} for a
detailed description of these macros.


%==============================================================================