Salta al contenuto
Note per Studenti Formulario · Internet and Security Report

FormularioInternet and Security: definizioni, teoremi e formule delle note, in ordine di capitolo

In questa pagina 7

I. Fundamentals and Performance

Network Types and Topologies

Formula (links in a complete mesh). With nn nodes, n(n−1)2\frac{n(n-1)}{2} physical links are needed (full duplex).

Grafico interattivo: Number of links versus number of nodes n: the star grows linearly (n - 1), the complete mesh with the square (n(n - 1)/2); for n = 5 they are 4 and 10, for n = 10 they are 9 and 45

Circuit Switching and Packet Switching

Formula (delivery time in CS). With NN links (hops) between sender and receiver, propagation time tpt_p per link, switching time tst_s per node, a message of MM bits and bitrate RR: TCS=3 N tp+N ts+MR.T_{CS}=3\,N\,t_p+N\,t_s+\frac MR.

Formula (delivery time in datagram PS). A message of MM bits split into KK packets, each with a header of HH bits (so packets of M/K+HM/K+H bits), NN equal links of bitrate RR and propagation tpt_p, no queues or processing: TPS=N tp+(N+K−1) M/K+HR.T_{PS}=N\,t_p+(N+K-1)\,\frac{M/K+H}{R}.

Formula (optimal number of packets). Expanding, (N+K−1)(M/K+H)=M+(N−1)MK+(N−1)H+KH(N+K-1)(M/K+H)=M+(N-1)\frac MK+(N-1)H+KH; differentiating with respect to KK and setting to zero: −(N−1)MK2+H=0-(N-1)\frac M{K^2}+H=0, hence Kopt=(N−1) MH.K_{opt}=\sqrt{\frac{(N-1)\,M}{H}}.

Grafico interattivo: Delivery time T_PS (seconds) versus number of packets K, with N = 4, M = 1 Mbit, H = 400 bit, R = 10 Mbit/s, tp = 1 ms: minimum near K = 87 (about 0.111 s); at K = 1 it is 0.404 s

Network Performance Analysis

Formula (end-to-end delay). The time to deliver a message to the destination, from the instant the first bit leaves the source, is the sum of four contributions: dtot=dproc+dqueue+dtrans+dprop.d_{tot}=d_{proc}+d_{queue}+d_{trans}+d_{prop}.

Formula (transmission delay). To put all bits of a packet of length LL on the line (one bit after the other) at bitrate RR: dtrans=LR.d_{trans}=\frac{L}{R}.

Formula (propagation delay). Time for a bit to go from one end of the medium to the other, at speed vv over distance dd: dprop=dv.d_{prop}=\frac{d}{v}. In vacuum v=c=3⋅108v=c=3\cdot10^{8} m/s; in cables v≈2⋅108v\approx2\cdot10^{8} m/s (copper and fibre: light in the medium goes at c/nc/n with refractive index n≈1.5n\approx1.5).

Introduction to Queueing Theory

Formula (distribution and mean number in the system, M/M/1). The number of customers in the system is geometric: px(n)=(1−ρ)ρ n,n=0,1,2,…p_x(n)=(1-\rho)\rho^{\,n},\qquad n=0,1,2,\dots E[x]=ρ1−ρ,Var(x)=ρ(1−ρ)2.E[x]=\frac\rho{1-\rho},\qquad\mathrm{Var}(x)=\frac\rho{(1-\rho)^2}.

Grafico interattivo: Distribution of the number of customers in the M/M/1 system with rho = 0.8: p(n) = 0.2*0.8^n, decreasing geometric (p(0) = 0.2 = 1 - rho, p(1) = 0.16, p(2) = 0.128); the mean is rho/(1-rho) = 4

Formula (queue and times, M/M/1). Removing the number in service (ρ\rho) from the number in the system: E[q]=E[x]−ρ=ρ21−ρ.E[q]=E[x]-\rho=\frac{\rho^2}{1-\rho}. With Little: E[s]=E[x]λ=1/μ1−ρ,E[w]=E[s]−1μ=ρ/μ1−ρ.E[s]=\frac{E[x]}\lambda=\frac{1/\mu}{1-\rho},\qquad E[w]=E[s]-\frac1\mu=\frac{\rho/\mu}{1-\rho}.

Formula (M/G/1 with constant service). E[x]=ρ+ρ22(1−ρ),E[w]=ρ2μ(1−ρ),E[s]=E[x]λ=1μ(1+ρ2(1−ρ)).E[x]=\rho+\frac{\rho^2}{2(1-\rho)},\qquad E[w]=\frac{\rho}{2\mu(1-\rho)},\qquad E[s]=\frac{E[x]}\lambda=\frac1\mu\left(1+\frac{\rho}{2(1-\rho)}\right).

Grafico interattivo: Normalized mean system time E[s]*mu versus load factor rho: M/M/1 (1/(1-rho)) and constant service (1 + rho/(2(1-rho))). Both diverge as rho tends to 1

II. Link Layer

Multiple Access Protocols - ALOHA and CSMA

Formula (minimum frame duration in CSMA/CD). To be sure a transmission succeeded, tF ≥ 2 τp,tF=FR ⟹ F ≥ 2 τp R.t_F\ \ge\ 2\,\tau_p,\qquad t_F=\frac FR\ \Longrightarrow\ F\ \ge\ 2\,\tau_p\,R.

Grafico interattivo: Space-time diagram of the CSMA/CD worst case (position on the x axis from A at 0 to B at 1; time on the y axis in units of tau_p): A starts at t = 0, B starts at t = tau_p, just before sensing A; the collision reaches A at t = 2 tau_p, so A must still be transmitting

Performance of Multiple Access Protocols

Formula (throughput of pure ALOHA). S=G PS=G e−2G.S=G\,P_S=G\,e^{-2G}.

Formula (mean delay of pure ALOHA). E[T]=tF+τp+(e2G−1)(tF+2τp+E[tb]).E[T]=t_F+\tau_p+(e^{2G}-1)(t_F+2\tau_p+E[t_b]).

Formula (throughput of slotted ALOHA). S=G PS=G e−G,dSdG=e−G(1−G)=0 ⇒ G=1,Smax=1e≃0.37.S=G\,P_S=G\,e^{-G},\qquad\frac{dS}{dG}=e^{-G}(1-G)=0\ \Rightarrow\ G=1,\quad S_{max}=\frac1e\simeq0.37.

Grafico interattivo: Throughput S versus offered load G: pure ALOHA S = G e^(-2G) (maximum 0.18 at G = 0.5) and slotted ALOHA S = G e^(-G) (maximum 0.37 at G = 1)

Formula (throughput of non-persistent CSMA). The throughput is the mean useful time per cycle over the mean cycle duration mB+mIm_B+m_I: S=mUmB+mI=tFe−aGtF(1+2a−1−e−aGG)+tFG=G e−aGG(1+2a)+e−aG.S=\frac{m_U}{m_B+m_I}=\frac{t_Fe^{-aG}}{t_F\left(1+2a-\frac{1-e^{-aG}}G\right)+\frac{t_F}G}=\frac{G\,e^{-aG}}{G(1+2a)+e^{-aG}}.

Grafico interattivo: Normalized throughput of non-persistent CSMA for different normalized propagation delays a = tau_p/t_F, compared with slotted ALOHA (G axis in log scale)

Formula (mean delay of non-persistent CSMA). E[T]=E[W]+tF+τp+(GS−1)(E[W]+tF+2τp+E[tb]).E[T]=E[W]+t_F+\tau_p+\left(\frac GS-1\right)\big(E[W]+t_F+2\tau_p+E[t_b]\big).

Formula (mean delay of TDMA). E[T]=NutF2+SNutF2(1−S)+tF+τp=tF(Nu2+SNu2(1−S)+1+a).E[T]=\frac{N_ut_F}2+\frac{SN_ut_F}{2(1-S)}+t_F+\tau_p=t_F\left(\frac{N_u}2+\frac{SN_u}{2(1-S)}+1+a\right).

Formula (mean delay of FDMA). E[T]=NutF+NutFS2(1−S)+τp=tF(Nu+SNu2(1−S)+a).E[T]=N_ut_F+\frac{N_ut_FS}{2(1-S)}+\tau_p=t_F\left(N_u+\frac{SN_u}{2(1-S)}+a\right).

LAN - Ethernet and Wi-Fi

Formula (minimum frame size). A frame of size SS with bitrate CC lasts Tfr=S/CT_{fr}=S/C. To detect the collision it must hold Tfr≥2TpT_{fr}\ge2T_p, i.e. S ≥ C⋅2Tp.S\ \ge\ C\cdot2T_p.

ARQ Protocols - Stop-and-Wait, Go-Back-N and Selective Repeat

Formula (Stop-and-Wait). ρSW=tFE[tT]=tF(1−p)tF+2τp+tA=tF(1−p)tG,ηSW=ρSWIF.\rho_{SW}=\frac{t_F}{E[t_T]}=\frac{t_F(1-p)}{t_F+2\tau_p+t_A}=\frac{t_F(1-p)}{t_G},\qquad \eta_{SW}=\rho_{SW}\frac IF.

Formula (Go-Back-N, window N≥tG/tFN\ge t_G/t_F). ρGBN=tFE[tT]=1−p1+(N−1) p,ηGBN=ρGBNIF=I(1−p)F[(N−1)p+1].\rho_{GBN}=\frac{t_F}{E[t_T]}=\frac{1-p}{1+(N-1)\,p},\qquad \eta_{GBN}=\rho_{GBN}\frac IF=\frac{I(1-p)}{F[(N-1)p+1]}.

Formula (Selective Repeat). ρSR=tFE[tT]=1−p,ηSR=ρSRIF=I(1−p)F.\rho_{SR}=\frac{t_F}{E[t_T]}=1-p,\qquad \eta_{SR}=\rho_{SR}\frac IF=\frac{I(1-p)}{F}.

Formula (goodput of Selective Repeat as a function of xx). g(x)=RLL η(x)=RLL x−ox (1−p)=RLL x−ox (1−Pb)x.g(x)=R_{LL}\,\eta(x)=R_{LL}\,\frac{x-o}{x}\,(1-p)=R_{LL}\,\frac{x-o}{x}\,(1-P_b)^x.

Formula (optimal frame size). xopt=o+o2−4oln⁡(1−Pb)2 ≃ o2+oPb(Pb≪1).x_{opt}=\frac{o+\sqrt{o^2-\dfrac{4o}{\ln(1-P_b)}}}{2}\ \simeq\ \frac o2+\sqrt{\frac o{P_b}}\quad(P_b\ll1).

Grafico interattivo: Selective Repeat efficiency eta(x) = (x - o)/x * (1 - Pb)^x with overhead o = 50 bit: maximum 0.62 at x = 250 bit for Pb = 0.001 and 0.18 at x = 100 bit for Pb = 0.01

III. Network Layer

Network Layer and IPv4 Addressing

Formula (CIDR block a.b.c.d/na.b.c.d/n). N=232−nN=2^{32-n} addresses; network address = first nn bits unchanged and the rest set to 0; broadcast = first nn bits unchanged and the rest set to 1; usable hosts N−2N-2.

Formula. N=NOT(M)+1N=\text{NOT}(M)+1, network =IP AND M=\text{IP}\ \text{AND}\ M, broadcast =IP OR NOT(M)=\text{IP}\ \text{OR}\ \text{NOT}(M). An address XX belongs to the network with address RR and mask MM if and only if X AND M=RX\ \text{AND}\ M=R.

IPv4 Datagram and Fragmentation

Formula (checksum). Sum all 16-bit header words (checksum field set to 0), add any carry beyond 16 bits back to the result (one's complement), and take the bitwise NOT. At the receiver the sum of all words, checksum included, must be FFFF\texttt{FFFF}.

Formula. With total length LL, header hh (usually 20) and MTU mm: payload P=L−hP=L-h; maximum payload per fragment pmax⁡=8⌊m−h8⌋p_{\max}=8\left\lfloor\dfrac{m-h}{8}\right\rfloor; number of fragments ⌈P/pmax⁡⌉\lceil P/p_{\max}\rceil; offset of fragment ii (from 0) =i pmax⁡8=\dfrac{i\,p_{\max}}{8}.

Subnetting, VLSM and Supernetting

Formula. From a network with prefix nn, borrowing ss bits for the SubnetID gives new prefix n′=n+sn'=n+s, 2s2^s subnets, each with 232−n′2^{32-n'} addresses, i.e. 232−n′−22^{32-n'}-2 usable hosts.

Formula. M=2⌈log⁡2(H+2)⌉M=2^{\lceil\log_2(H+2)\rceil},  n=32−log⁡2M\ n=32-\log_2M,  broadcast=network+M−1\ \text{broadcast}=\text{network}+M-1.

Routing Algorithms - Link State and Distance Vector

Formula (Bellman-Ford update). Node AA receives from neighbour YY the estimates dY,wd_{Y,w}. For every destination ww: DA,w=min⁡{DA,w, DA,Y+dY,w}.D_{A,w}=\min\{D_{A,w},\ D_{A,Y}+d_{Y,w}\}. If the path through YY is shorter, store the new cost and next hop =Y=Y. DA,YD_{A,Y} is the direct link cost to YY.

ICMP, Ping and Traceroute

Formula (ICMP checksum). As for IP: one's complement of the one's complement sum of the 16-bit words, with the checksum field set to 0.

IV. Transport Layer

UDP - User Datagram Protocol

Formula. data=UDP length−8\text{data}=\text{UDP length}-8. Example: length 12 carries 12−8=412-8=4 bytes.

Formula. Sum all 16-bit words of pseudo-header, header (checksum field =0=0) and data (pad with a zero byte if the data length is odd), fold the carry back (one's complement), and take the bitwise NOT. The receiver sums everything, checksum included: with no error the result is FFFF\texttt{FFFF}.

TCP - Connection, Reliability and Flow Control

Formula. MSS=MTU−IP header−TCP header=MTU−40\text{MSS}=\text{MTU}-\text{IP header}-\text{TCP header}=\text{MTU}-40 (20-byte headers).

Formula. swnd=min⁡(rwnd,cwnd)\text{swnd}=\min(\text{rwnd},\text{cwnd}); a new byte can be sent if last sent−last acknowledged≤swnd\text{last sent}-\text{last acknowledged}\le\text{swnd}. rwnd depends on the receiver, cwnd on the network.

Formula. rwnd=buffer size−bytes waiting to be read by the process\text{rwnd}=\text{buffer size}-\text{bytes waiting to be read by the process}.

Formula (maximum throughput). throughput≤MSS⋅Wmax⁡RTT.\text{throughput}\le\frac{\text{MSS}\cdot W_{\max}}{\text{RTT}}.

TCP Congestion Control

Formula (Jain fairness index). For NN flows with rates x1,…,xNx_1,\dots,x_N: FI=(∑i=1Nxi)2N∑i=1Nxi2,1N≤FI≤1.\text{FI}=\frac{\left(\sum_{i=1}^{N}x_i\right)^2}{N\sum_{i=1}^{N}x_i^2},\qquad\frac1N\le\text{FI}\le1. It is 1 if all rates are equal and 1/N1/N if one flow uses everything.

Formula. W=min⁡(cwnd,rwnd)W=\min(\text{cwnd},\text{rwnd}).

Formula. With nn blocks the option length is 8n+28n+2 bytes. Options are at most 40 bytes, so n≤4n\le4 (8⋅4+2=348\cdot4+2=34); with the timestamp option (12 bytes) only 28 bytes remain and n≤3n\le3.

TCP Retransmission Timeout Estimation

Formula (SRTT). SRTTi=(1−α) SRTTi−1+α⋅rtti,α=18.\text{SRTT}_i=(1-\alpha)\,\text{SRTT}_{i-1}+\alpha\cdot\text{rtt}_i,\qquad\alpha=\frac18.

Formula (MAD). MADi=(1−ρ) MADi−1+ρ ∣rtti−SRTTi−1∣,ρ=14.\text{MAD}_i=(1-\rho)\,\text{MAD}_{i-1}+\rho\,\big|\text{rtt}_i-\text{SRTT}_{i-1}\big|,\qquad\rho=\frac14.

Formula (RTO). RTOi=SRTTi+4⋅MADi,T0=max⁡{RTO, 1 s}.\text{RTO}_i=\text{SRTT}_i+4\cdot\text{MAD}_i,\qquad T_0=\max\{\text{RTO},\,1\text{ s}\}.

Analytical Model of TCP Send Rate

Formula. B=E[Y]E[A].B=\frac{E[Y]}{E[A]}.

Formula (mean window). E[W]=2−3b3b+(3b−23b)2+8(1−p)3bp → p→0  83bp.E[W]=\frac{2-3b}{3b}+\sqrt{\left(\frac{3b-2}{3b}\right)^2+\frac{8(1-p)}{3bp}}\ \xrightarrow{\,p\to0\,}\ \sqrt{\frac{8}{3bp}}.

Formula (mean duration). E[A]=(E[X]+1) RTT≃RTT2b3pE[A]=(E[X]+1)\,\text{RTT}\simeq\text{RTT}\sqrt{\dfrac{2b}{3p}}.

Formula (square root). B(p,b,RTT)=1RTT32bp.(7)B(p,b,\text{RTT})=\frac1{\text{RTT}}\sqrt{\frac{3}{2bp}}.\tag{7}

Formula (general form). B=E[Y]+Q E[R]E[A]+Q E[ZTO].(8)B=\frac{E[Y]+Q\,E[R]}{E[A]+Q\,E[Z^{TO}]}.\tag{8}

Formula. Q^(w)=min⁡{1, 1−(1−p)31−(1−p)w[1+(1−p)3(1−(1−p)w−3)]} → p→0  min⁡{1,3w}.\hat Q(w)=\min\left\{1,\ \frac{1-(1-p)^3}{1-(1-p)^w}\Big[1+(1-p)^3\big(1-(1-p)^{w-3}\big)\Big]\right\}\ \xrightarrow{\,p\to0\,}\ \min\left\{1,\frac3w\right\}.

Formula (full model). B(p,b,RTT,T0)=1−pp+E[W]+Q^(E[W])11−pRTT(b2E[W]+b+1)+Q^(E[W]) T0 f(p)1−p.(9)B(p,b,\text{RTT},T_0)=\frac{\dfrac{1-p}{p}+E[W]+\hat Q(E[W])\dfrac1{1-p}}{\text{RTT}\left(\dfrac b2E[W]+b+1\right)+\hat Q(E[W])\,\dfrac{T_0\,f(p)}{1-p}}.\tag{9}

Formula (approximate model). B≃1RTT2bp3+T0min⁡{1, 33bp8}p (1+2p+4p2)[seg/s].(10)B\simeq\frac1{\text{RTT}\sqrt{\dfrac{2bp}3}+T_0\min\left\{1,\,3\sqrt{\dfrac{3bp}8}\right\}p\,(1+2p+4p^2)}\quad[\text{seg/s}].\tag{10}

Formula (window cap). BWmax⁡=min⁡{Wmax⁡RTT, B(p,b,RTT,T0)}[packets/s].(11)B^{W_{\max}}=\min\left\{\frac{W_{\max}}{\text{RTT}},\ B(p,b,\text{RTT},T_0)\right\}\quad[\text{packets/s}].\tag{11}

V. Application Layer

DNS - Domain Name System

Formula (resolution time with empty cache). Each question-answer pair costs one RTT with its partner (DNS messages are tiny, so RTT ≈2τp\approx2\tau_p): T=RTThost-local+RTTroot+RTTTLD+RTTauthoritativeT=\text{RTT}_{\text{host-local}}+\text{RTT}_{\text{root}}+\text{RTT}_{\text{TLD}}+\text{RTT}_{\text{authoritative}}. With a fraction hh of requests answered from the local DNS cache, Tˉ=h RTThost-local+(1−h) T\bar T=h\,\text{RTT}_{\text{host-local}}+(1-h)\,T.

HTTP and the Web

Formula (page with NN embedded objects, N+1N+1 objects in all, transmission times neglected).

  • non-persistent: T=2(N+1) RTTT=2(N+1)\,\text{RTT};
  • persistent without pipelining: T=(2+N) RTTT=(2+N)\,\text{RTT};
  • persistent with pipelining: T=3 RTTT=3\,\text{RTT}.

Formula (mean time with a cache). With hit ratio hh: Tˉ=h Thit+(1−h) Tmiss\bar T=h\,T_{\text{hit}}+(1-h)\,T_{\text{miss}}, where Tmiss=Thit+ToriginT_{\text{miss}}=T_{\text{hit}}+T_{\text{origin}} (the cache is always crossed).

VI. Network Security

Hash Functions and Symmetric Cryptography

Formula (Diffie-Hellman). Alice and Bob agree on a large prime pp (e.g. 2048 bits) and a generator gg (small). A picks x<px<p and sends L=gx mod pL=g^x\bmod p; B picks y<py<p and sends M=gy mod pM=g^y\bmod p. A computes K=Mx mod pK=M^x\bmod p, B computes K′=Ly mod pK'=L^y\bmod p, and K=K′=gxy mod pK=K'=g^{xy}\bmod p.

Formula (HMAC). With BB the hash block size (usually 64 bytes) and KK padded with zeros to BB: HMACK(m)=H((K⊕opad) ∥ H((K⊕ipad) ∥ m)),\text{HMAC}_K(m)=H\big((K\oplus\text{opad})\,\|\,H\big((K\oplus\text{ipad})\,\|\,m\big)\big), with ipad=0x36\text{ipad}=\texttt{0x36} and opad=0x5c\text{opad}=\texttt{0x5c} repeated BB times. Two hashes are used because with Merkle-Damgård hashes, knowing H(K ∥ m)H(K\,\|\,m) allows computing the hash of K ∥ m ∥ padding ∥ m′K\,\|\,m\,\|\,\text{padding}\,\|\,m' without KK (length extension); the outer hash prevents it.

Public-Key Cryptography, RSA and TLS

Formula (RSA key generation).

  1. Choose two large primes pp and qq.
  2. N=p qN=p\,q.
  3. φ(N)=(p−1)(q−1)\varphi(N)=(p-1)(q-1).
  4. Choose e<φ(N)e<\varphi(N) with gcd⁡(e,φ(N))=1\gcd(e,\varphi(N))=1.
  5. d=e−1 mod φ(N)d=e^{-1}\bmod\varphi(N), so d e≡1(modφ(N))d\,e\equiv1\pmod{\varphi(N)}.

Public key PK=(N,e)PK=(N,e); secret key SK=(N,d)SK=(N,d); the secrets (p,q,d,φ(N))(p,q,d,\varphi(N)) are never shared.

Formula (encryption and decryption). For m<Nm<N: c=me mod Nc=m^e\bmod N, m=cd mod Nm=c^d\bmod N.

VII. Katharà Laboratory

Emulating Networks with Katharà

Formula. ifconfig <interface> <address> netmask <mask> broadcast <broadcast address> [mtu <bytes>] up, equivalent to ifconfig eth0 <address>/<length> up.

Static Routing and Diagnostic Tools in Katharà

Formula. route add -net <network>/<prefix> gw <next hop> dev <interface>: "the network is reached through the next hop leaving from the interface". The next hop must be in a network directly connected to that interface.

RIP and Advanced Routing in Katharà

Formula (RIP metric). The metric is the number of routers crossed to reach the network: 11 for connected networks, plus 11 at each router forwarding the advertisement; 1616 means unreachable. The administrative distance of RIP is 120120.

Cisco Routers

Formula. ip route <network> <mask> <next hop>: "to reach <network>/<mask> send to <next hop>", with the mask in full. The default route is network 0.0.0.0 with mask 0.0.0.0.

Firewall Configuration with iptables in Katharà

Formula (filter rule). iptables --table filter --append CHAIN [criteria] --jump TARGET: adds at the end of the chain a rule applying the target to packets satisfying all the criteria.