summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/tikzpackets/tikzPackets.tex
blob: 585550ebad6b55c94fedef764c731e9177a750a0 (plain)
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
% Copyright (c) 2020 Robert Ryszard Paciorek <rrp@opcode.eu.org>
% 
% MIT License
% 
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the "Software"), to deal
% in the Software without restriction, including without limitation the rights
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
% copies of the Software, and to permit persons to whom the Software is
% furnished to do so, subject to the following conditions:
% 
% The above copyright notice and this permission notice shall be included in all
% copies or substantial portions of the Software.
% 
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
% SOFTWARE.

\documentclass[a4paper]{article}

\usepackage{tikzPackets}
\usepackage{adjustbox,hyperref,fancyvrb-ex,fvextra}

\oddsidemargin=0pt
\textwidth=430pt

\topmargin=-30pt
\textheight=662pt

\newcommand{\pkgLink}[1]{\texttt{\href{https://ctan.org/pkg/#1}{#1}}}

\fvset{
	breaklines=true,
	breakanywhere=true,
	breakaftersymbolpre={},
	breakaftersymbolpost={\tiny\ensuremath{\ \lhook\joinrel\rightarrow\ }},
	breakanywheresymbolpre={},
	breakanywheresymbolpost={\tiny\ensuremath{\ \lhook\joinrel\rightarrow\ }}
}

\begin{document}

\title{The \texttt{tikzPackets}  package}
\author{Robert Ryszard Paciorek <rrp@opcode.eu.org>}
\date{2020-07-13}
\maketitle

This package provide command for simple build network packets illustration with \pkgLink{tikz}.
Similar functionality (with tables instead of tikz) provide package \pkgLink{bytefield}.

\section{Basic Example}

\begin{CenterExample}
\begin{tikzpicture}
    \packetsInit
    \packetsBitWidth=4.5mm
    \packetsPrintBitScale{31}
    
    \packetsPutField{16}{Source Port}
    \packetsPutField{16}{Destination Port}
    \packetsEndLine{0}{}
    
    \packetsPutField{16}{Length}
    \packetsPutField{16}{Checksum}
    \packetsEndLine{32}{}
    
    \packetsPutField[protocolsField, minimum height=1.5cm]{32}{Data}
    \packetsEndLine{64}{}
\end{tikzpicture}
\end{CenterExample}


\section{Macros description}

\subsection{packetsInit}

\Verb$\packetsInit$ is used to initialise \textit{tikzPackets} variables, counters and tikz styles.
Must be used in every \Verb$tikzpicture$ that use \textit{tikzPackets} package commands before any other \textit{tikzPackets} command.

\subsection{packetsPrintBitScale}

\Verb$\packetsPrintBitScale$ draw bits scale. It takes one argument: last bit value.

Formatting of bits scale can be adjust by redefine (after \Verb$\packetsInit$) tikz style \Verb$bitScaleInfo$, redefine \Verb$\packetsBitFont$ or \Verb$\packetsPrintBitNumber$ macro.

\subsection{packetsPutField}

\Verb$\packetsPutField$ draw packet field. It takes 4 arguments:
\begin{enumerate}
    \item (optional) node style and formatting options
    \item number of bits (width of field)
    \item (optional) node name for new created node
    \item name (text to display)
\end{enumerate}

\subsection{packetsPrintRangeOnLeft and packetsPrintRangeOnRight}

\Verb$\packetsPrintRangeOnLeft$ and \Verb$\packetsPrintRangeOnRight$ prints info (start bit number or bits range) on left or right side of current line.
Should be call after call all \Verb$\packetsPutField$ for this line. Both commands takes two arguments: first bit in line and last bit in line,
but \Verb$\packetsPrintRangeOnLeft$ ignore second argument.

Formatting of printing text can be adjust by redefine \Verb$\packetsBitFont$ macro or redefine \Verb$\packetsPrintRangeOnLeft$ / \Verb$\packetsPrintRangeOnRight$ macros.

\begin{CenterExample}
\begin{tikzpicture}
    \packetsInit
    \renewcommand{\packetsBitFont}{\scriptsize}
    \packetsPutField{4}{A} \packetsPutField{4}{B} \packetsPutField{4}{C}
    \packetsPrintRangeOnLeft{a}{b}
    \packetsPrintRangeOnRight{d}{e}
\end{tikzpicture}
\end{CenterExample}

\subsection{packetsNextLine}

\Verb$\packetsNextLine$ end current line of field and prepare to start next line of field. It don't have arguments.

\subsection{packetsEndLine}

\Verb$\packetsEndLine$ call \Verb$\packetsPrintRangeOnLeft$ and \Verb$\packetsNextLine$.
Arguments are passed to \Verb$\packetsPrintRangeOnLeft$.

\subsection{packetsLastNode and packetsFirstNodeInLastLine}

\Verb$\packetsLastNode$ hold name of last added node by \Verb$\packetsPutField$ or \Verb$\packetsPrintBitScale$ (and is used for node positioning in \Verb$\packetsPutField$ and \Verb$\packetsPrintRangeOnRight$ macros).

\Verb$\packetsFirstNodeInLastLine$ hold name of first node (added by macro \Verb$\packetsPutField$ or \Verb$\packetsPrintBitScale$) in current line (and is used in \Verb$\packetsPutField$ and \Verb$\packetsPrintRangeOnLeft$ for positioning)

Both can be use for external to reference node adding by these macros (can be captured after add node by \Verb$\edef$) or can be used to start adding nodes by \Verb$\packetsPutField$ relative to some manually added node.

\begin{CenterExample}
\begin{tikzpicture}
    \packetsInit
    \packetsPutField{4}{A}
    \packetsPutField{4}{B}
    
    \node[
        align=left, anchor=north west,
        text width=7\packetsBitWidth, node font=\footnotesize
    ] [] at (\packetsFirstNodeInLastLine.south west) {
        Some extra info about this packet. And more more info \ldots
    };
\end{tikzpicture}
\end{CenterExample}

\section{Styles and dimmensions}

Width of single bit is set by \Verb$\packetsBitWidth$ and default is 5mm. Default style for node created by \Verb$\packetsPutField$ is \Verb$protocolsField$ and it set line height to 1cm.
Package provide also \Verb$protocolsFieldBase$ style with minimal setting for node style.
Macro \Verb$\packetsBitFont$ define font settings for bits info.
All this change should be done after use \Verb$\packetsInit$.

\begin{CenterExample}
\begin{tikzpicture}
    \packetsInit
    \tikzstyle{protocolsField}=[protocolsFieldBase, draw, minimum height = 0.8cm]
    \packetsBitWidth=10mm
    \renewcommand{\packetsBitFont}{\scriptsize\it}
    
    \packetsPrintBitScale{7}
    \packetsPutField{4}{Long field names}
    \packetsPutField{4}{and low rows}
\end{tikzpicture}
\end{CenterExample}

\end{document}