TikZ Examples

This page contains several TikZ examples. Most of the examples are related to computer networks. All the code is licensed under the public domain. Please send feedback to Picture.

Index

  1. Network Protocol Stack
  2. Network Communication
  3. Protocol Header

Network Protocol Stack

Preview

Protocol Stack

Code

\begin{tikzpicture}[node distance=0 cm,outer sep = 0pt,inner sep = 2pt]
	\tikzset{field/.style={align=center,shape=rectangle,minimum height=0.5cm,minimum width=9mm,draw}}
	\tikzset{largefield/.style={align=center,shape=rectangle,minimum height=0.5cm,minimum width=27mm,draw}}

	\node [field] (tor) {Tor};
	\node [field,right=of tor] (vpn) {VPN};
	\node [field,right=of vpn] {\dots};

	\node [largefield,below=of vpn] (socks) {SOCKS};
	\node [largefield,below=of socks,fill=gray!30] (scramblesuit) {\textbf{\pt{}}};
	\node [largefield,below=of scramblesuit] (tcp) {TCP};
	\node [largefield,below=of tcp] {IP};
\end{tikzpicture}

Network Communication

Preview

Network Communication

Code

\begin{tikzpicture}
	\draw (0,0) -- (0,3);
	\draw (8,0) -- (8,3);

	\draw [arrows={-triangle 45}]
	(0, 3) -- (8, 2.5) node [midway, fill=white, text centered]
	{ $X\ ||\ P_{C}\ ||\ M_{C}\ ||\ \textsf{MAC}_{k_{B}}(X||P_{C}||E)$ };

	\draw [arrows={triangle 45-}]
	(0, 1.5) -- (8, 2) node [midway, fill=white, text centered]
	{ $Y\ ||\ P_{S}\ ||\ M_{S}\ ||\ \textsf{MAC}_{k_{B}}(Y||P_{S}||E)$ };

	\draw [arrows={-triangle 45}]
	(8, 1.5) -- node [midway, fill=white, text centered]
	{ $\textsf{Enc}_{k_{t}}(k_{t+1}\ ||\ \mathcal{T}_{t+1})$ } (0, 1);

	\draw [arrows={triangle 45-triangle 45}]
	(0, 0.5) -- node [midway, fill=white]
	{ $\textsf{Enc}_{k_{t}}$(Data) } (8, 0.5);

	\node at (0,3.5) {Client};
	\node at (8,3.5) {Server};
\end{tikzpicture}

Protocol Header

Preview

Protocol Header

Code

\begin{tikzpicture}[node distance=0 cm,outer sep = 0pt,
		inner sep = 2pt,font=\scriptsize]
	\tikzset{field/.style={align=center,shape=rectangle,
	minimum height=0.7cm,draw}}
	\tikzset{darkfield/.style={fill=gray!10,align=center,shape=rectangle,
	minimum height=0.7cm,draw}}

	\node [field]                      (mac)     {16-byte\\MAC};
	\node [darkfield,right=of mac]     (tlen)    {2-byte\\Total length};
	\node [darkfield,right=of tlen]    (plen)    {2-byte\\Payload length};
	\node [darkfield,right=of plen]    (flags)   {1-byte\\Flags};
	\node [darkfield,right=of flags]   (payload) {(optional)\\Payload};
	\node [darkfield,right=of payload] (padding) {(optional)\\Padding};

	\draw [latex-latex] ($ (mac.south west) - (0,0.2) $) -- node [auto,swap]
	{Plain} ($ (mac.south east) - (0,0.2) $);
	\draw [latex-latex] ($ (tlen.south west) - (0,0.2) $) -- node [auto,swap]
	{Encrypted and authenticated} ($ (padding.south east) - (0,0.2) $);
\end{tikzpicture}