4. Síťová vrstva Studijní cíl Představíme si funkci síťové vrstvy a jednotlivé protokoly.
Doba nutná k nastudování
3 hodiny
Síťová vrstva Síťová vrstva zajišťuje směrování a poskytuje jediné síťové rozhraní pro protokoly vyšších vrstev. Samotná Síťová vrstva využívá protokol IP. Od transportní vrstvy obdrží datové segmenty s požadavkem na odeslání. K segmentům připojí vlastní hlavičku – zapouzdří a vytvoří IP paket. V hlavičce IP paketu je především IP adresa příjemce a odesílatele. Internetová vrstva (IP Layer) vytváří datagramy, adresuje je a směruje na místo určení. Zajišťuje tak zvané doručení s největším úsilím (best-effort delivery), což znamená, že vrstva IP se snaží doručit poslaná data nejvhodnější cestou. Pokud dojde ke ztrátě dat (výpadek linky, přeplněné fronty na směrovačích), vysílající uzel je o ztrátě datagramu informován, nicméně musí sám zajistit opětovné přenesení dat. Internetová vrstva kromě přenosového protokolu IP (Internet Protocol) používá protokoly ARP (Address Resolution Protocol) a RARP (Reverse ARP), které slouží k mapování IP adres na MAC adresy. Dále jsou to protokoly ICMP (Internet Control Message Protocol) pro řízení toku a detekci nedosažitelných uzlů a protokol IGMP (Inter-net Group Management Protocol) pro přihlašování se do multicastových skupin. Tyto protokoly musí být součástí implementace modulu IP v operačním systému. Bez těchto protokolu nebude komunikace na sítové vrstvě korektně pracovat. IP protokol je tvořen několika dílčími protokoly: • • • •
vlastní protokol IP, služební protokol ICMP, služební protokol IGMP, služební protokol ARP, RARP.
V protokolu IP má každé rozhraní (network interface) IP adresu (IPv4 = 4B, IPv6=16B). Základním prvkem WAN je směrovač (router), který propojuje
Počítačové sítě I.
1 (6)
KST/IPS1
jednotlivé LAN do rozlehlé sítě (WAN). Jako směrovač může sloužit běžný počítač s více síťovými rozhraními nebo specializovaná skříňka (box).
Obrázek 1 Linková adresa a linková vrstva Schopnost předávat datové pakety mezi síťovými rozhraními směrovače se nazývá předávání - forwarding. Proč dva protokoly? Linkový a IP? Linkový protokol (Ethernet) slouží k dopravě dat v rámci LAN. Tedy k dopravě k nejbližšímu směrovači. Směrovač linkový rámec vybalí a přebalí do jiného linkového rámce (i když se použije stejný linkový protokol). Linkový rámec má po přebalení jiné fyzické adresy. Směrovač nemění obsah IP datagramu.
Obrázek 2Struktura protokolu IPv4 Ukázka protokolu IP verze 4 je na obrázku 1.Na internetové vrstvě modelu TCP/IP se používá adresování pomocí 32-bitové IP adresy. Délku datagramu (Total Length) obsahuje 16-bitová hodnota v hlavičce protokolu, proto
Počítačové sítě I.
2 (6)
KST/IPS1
maximální délka datagramu IPv4 včetne hlavičky je 216 −1 = 65535 bytu (64 kB). V praxi se maximální délka nepoužívá, protože na nižší vrstvě, Ethernetu, je délka dat v rámci omezena na 1 500 bytů. V případě delších IP datagramů by docházelo k fragmentaci na lokálních sítích. Proto se i délka IP datagramu volí kratší. Při průchodu IP datagramu uzlem sítě se hodnota kontrolního součtu hlavičky (Header Checksum) musí znovu přepočítat, z důvodů dekrementace hodnoty TTL (Time To Live). K přepočítání dochází také při použití privátních adres a překladu adres NAT Mezi základní operace vrstvy IP patří • definice datagramu a způsobu adresování, • přenos dat mezi internetovou vrstvou a fyzickým rozhraním, • směrování datagramu na vzdálený počítač. IP vrstva neprovádí žádné kontroly správnosti přenosu ani opravu poškozených dat. Proto se protokol IP někdy nazývá nespolehlivý protokol. Kontrolu obsahu a opravy chyb je nutné provádet na vyšších vrstvách modelu TCP/IP. Internetová vrstva využívá také linkový protokol ARP, který je implementován přímo nad Ethernetem nebo jinou lokální sítí (ARCNET, Frame Relay, LocalTalk, FDDI apod.). ARP slouží k překladu fyzických adres na IP adresy a obráceně.
Počítačové sítě I.
3 (6)
KST/IPS1
Dalším protokolem, který je součástí vrstvy IP, který a musí být implementován v každém modulu IP, je protokol ICMP. ICMP je ve skutečnosti součástí protokolu IP, který v poli hlavičky Protocol obsahuje hodnotu 1. ICMP slouží k řízení a kontrole toku dat na síťové úrovni.[2]
Obrázek 3 ICMP paket
Počítačové sítě I.
4 (6)
KST/IPS1
Echo Je jednoduchý nástroj protokolu ICMP, kterým můžeme testovat dosažitelnost jednotlivých uzlů v Internetu. Žadatel vysílá ICMP-paket “Žádost o echo” a cílový uzel je povinen odpovědět ICMP-paketem „Echo”. Všechny operační systémy podporující protokol TCP/IP obsahují program ping, kterým uživatel může na cílový uzel odeslat žádost o echo. Program ping pak zobrazuje odpověď. Význam pole identifikátor v záhlaví ICMP-paketu spočívá ve spárování žádosti s odpovědí (aby se dalo zjistit ke které žádosti paří příslušná odpověď). Nedoručitelný IP-datagram Nemůže-li být IP-datagram předán dále směrem k adresátovi, pak je zahozen a odesilatel je protokolem ICMP o tom uvědomen zprávou „Nedoručitelný IPdatagram”. Sniž rychlost odesílání Jestliže je síť mezi odesílatelem a příjemcem v některém místě přetížena, pak směrovač, který není schopen předávat dále všechny IPdatagramy signalizuje odesilateli „Sniž rychlost odesílání”. Odesilatel pak v případě, že používá protokol TCP snižuje rychlost odesílání TCP segmentů. V případě protokolu UDP se zprávy “Sniž rychlost odesílání” ignorují. Změň směrování (Redirect) Pomocí tohoto ICMP-paketu se provádí dynamické změny ve směrovací tabulce. Žádost o směrování Pomocí žádosti o směrování nemusíme do směrovací tabulky počítačů na LAN ručně konfigurovat vůbec žádnou položku default. Počítač po svém startu vyšle oběžníkem “Žádost o směrování” a směrovač mu odpoví ICMP-paketem „Odpověď na žádost o směrování”, která obsahuje: počet adres směrovače, délku adresy a pak dvojice IP-adresa a preference. Z odpovědi může počítač automaticky vygenerovat položku default. Čas vypršel (time exceeded) Tento typ zahrnuje dva velmi odlišné případy. Pro kód=0 signalizuje, že položka TTL by byla na směrovači snížena na nulu, tj. že je podezření, že IP-datagram v Internetu zabloudil, proto bude zlikvidován. Pro kód=1 signalizuje, že počítač adresáta není schopen v daném čase sestavit z fragmentů celý IP-datagram.
Počítačové sítě I.
5 (6)
KST/IPS1
Žádost o masku Tímto ICMP-paketem může bezdisková stanice žádat o masku své sítě poté co protokolem RARP obdržela svou IP-adresu. Časová synchronizace Tímto ICMP-paketem se žádá cílový počítač o čas. Shrnutí kapitoly V této kapitole byla představena funkce síťové vrstvy. Byly popsány jednotlivé protokoly. Podrobně byly vysvětleny parametry protokolu ICMP.
Otázky na procvičení: 1. Který protokol se používá pro odesílání zpráv o nedosažitelnosti cíle? 2. Jakým příkazem ověříme dosažitelnost uzlu? 3. Vysvětlete funkci protokolu ARP? 4. Vysvětlete význam parametru TTL?
Literatura [1]
Cisco Systems, Inc [online]. 2012 [cit. 2012-04-26]. Dostupné z: http://www.cisco.com/.
[2]
BIGELOW, Stephen J. Mistrovství v počítačových sítích: Správa, konfigurace, diagnostika a řešení problémů. Petr Matějů. Brno: Computer Press, 2004, 992 s. Mistrovství. ISBN 80-251-0178-9.
Počítačové sítě I.
6 (6)
KST/IPS1