# Network/Message Sequence Diagram

I am looking to produce something similar (but more complex) to this diagram:

This depicts network packets between two sides of communication. I don't know if there is any specific name for it (edit: Message Sequence Diagram). It looks similar to a sequence diagram from pgf-umlsd, but there are some fundamental differences:

• the arrows are at an angle to depict the time the packet travels from sender to receiver
• there is no control passing as in the sequence diagram

Do you know what the name for this kind of diagram is? Are there any macros to accomplish this easily or is it something that can be created quickly?

Basically what I need are arrows at an angle, labels for the arrows themselves and the anchor points of the arrows, nothing else really.

-
I think msc – Draw MSC di­a­grams might help you. –  Claudio Fiandrino Feb 22 '13 at 15:37

I had some old code in my conputer. It's not exactly what you want, but I think it could be an starting point.

First the final result:

I also had to draw some link control protocol examples and decided to create some commands to draw frames (from A to B in previos figure)

\newcommand{\tramaok}[2]{%
\draw[trama,->]  #2 --++(1.5,-2) node[above right,near start] {#1};
}


lost frames

\newcommand{\tramaperduda}[2]{%
\path #2 coordinate (a)--++(1.5,-2) coordinate (b) coordinate[midway] (c);
\draw[trama,-]  (a) --(c) node[below] {#1};
\draw[trama,->]  (c) -- ++(30:.5);
}


and acknowledgments (from bottom to top)

\newcommand{\ackok}[2]{%
\draw[ack,->] {#2}--++(1.5,2) node[below right,near start] {#1};
}

\newcommand{\ackperdut}[2]{%
\path #2 coordinate (a)--++(1.5,2) coordinate (b) coordinate[midway] (c);
\draw[ack,-]  (a) --(c) node[above] {#1};
\draw[ack,->]  (c) -- ++(-30:.5);
}


All these commands have two parameters, some label, if necessary, and its starting point. Slope and distance are fixed. With these commands was easy to draw previous figure:

\tramaok{Tr0}{(0,2)}
\tramaok{Tr0}{(2.5,2)}
\tramaperduda{Tr1}{(5,2)}
\tramaok{Tr0}{(7.5,2)}
\ackok{Ack}{(1.5,0)}
\ackok{Ack}{(4,0)}
\ackok{Ack}{(9,0)}
\timeout{(0,2)}{(2.5,2)}


The complete code is:

\documentclass[tikz,border=2mm]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usetikzlibrary{calc,arrows,positioning}
\begin{document}

\tikzset{
host/.style={rectangle,rounded corners,
thick,draw=#1!60,fill=#1!15},
host/.default=blue,
trama/.style={thick,draw=#1!60,fill=#1!60},
trama/.default=purple,
ack/.style={trama=teal},
}

\newcommand{\tramaok}[2]{%
\draw[trama,->]  #2 --++(1.5,-2) node[above right,near start] {#1};
}
\newcommand{\tramaperduda}[2]{%
\path #2 coordinate (a)--++(1.5,-2) coordinate (b) coordinate[midway] (c);
\draw[trama,-]  (a) --(c) node[below] {#1};
\draw[trama,->]  (c) -- ++(30:.5);
}

\newcommand{\ackok}[2]{%
\draw[ack,->] {#2}--++(1.5,2) node[below right,near start] {#1};
}

\newcommand{\ackperdut}[2]{%
\path #2 coordinate (a)--++(1.5,2) coordinate (b) coordinate[midway] (c);
\draw[ack,-]  (a) --(c) node[above] {#1};
\draw[ack,->]  (c) -- ++(-30:.5);
}

\newcommand{\timeout}[2]{%
\draw #1 --++(0,5mm);
\draw #2 --++(0,5mm);
\begin{scope}[yshift=2.5mm]
\draw[<->] #1 -- #2 node[above,midway]{\emph{Time-out}};
\end{scope}
}

\begin{tikzpicture}[>=stealth',
font=\small\sffamily]

% S&W amb etiquetes a trames
% Tout curt. Repetició trames.
% No detecta pèrdues de trames
\draw[help lines,->] (-0.2,0) node[host,left] {B}--(11.5,0);
\draw[help lines,->] (-0.2,2) node[host,left] {A}--(11.5,2);

\tramaok{Tr0}{(0,2)}
\tramaok{Tr0}{(2.5,2)}
\tramaperduda{Tr1}{(5,2)}
\tramaok{Tr0}{(7.5,2)}
\ackok{Ack}{(1.5,0)}
\ackok{Ack}{(4,0)}
\ackok{Ack}{(9,0)}
\timeout{(0,2)}{(2.5,2)}

\end{tikzpicture}

\end{document}

-

I liked Ignasi's solution, but I decided to go with Claudio's comment and use msc - it comes with nice documentation, some nice features and works like a charm. The only problem with it is you cannot compile it straight to .pdf since it uses pstricks to draw the diagrams.

To keep the pdflatex benefits I came up with a simple workflow based on GNU make. Here's the Makefile:

all: protokol.pdf

protokol.pdf: ack1.pdf ack2.pdf ack3.pdf ack4.pdf ack5.pdf protokol.tex json/*
pdflatex protokol.tex

%.pdf: %.tex
./processDvi.sh $*  and here's the processDvi.sh: #!/bin/sh latex$1.tex
dvips $1.dvi ps2eps -l --nohires -f$1.ps
ps2pdf -dEPSCrop -dAutoRotatePages=/None -dUseFlateCompression=true \$1.eps


Basically what I do is create small .tex documents containing just the diagrams and include them in the main document. The Makefile might use some refactoring so I don't have to add every new diagram I want to create, but it works for me for now.

-
When you need pstricks you can also use xelatex instead of latex+dvips+pstopdf. Just try xelatex protocol.tex and see what happens. –  Ignasi Mar 4 '13 at 8:52