IPv4 Network Layer
Transcript
This podcast is going to talk about the the network layer; layer 3 if we are referring to it by OSI model layers The network layer, as I said is layer 3 the common network layer we're going to be talking about is going be talking about is IP the Internet Protocol I in this case we're going to be talking about IP version 4 which was the original version that we used until ipv6 became available We'll talk about ipv6 later on, not today, in a few weeks but IPv4 is the network layer protocol we will talk about this is where the a network layer exists in the TCP IP protocol stack
the network layer will take data from the transport layer and it will pass that data down to the data linklayer for delivery the internet protocol ipv4 was defined in RFC 791 in 1981 it was limited in scope to deliver an internet datagram from a source to a destination so it will get it from here to there, that this goal to get it to the other machine. IP is not worried about getting it to the actual program on the other side IP doesn't concern itself with the browser that it's going to
or the web server is just wants to get to get to the machine in the upper layer protocols take care delivering it to the actual process that needs it there are no mechanism to augment end to end data reliability flow control, sequencing or other services. IP makes his best effort to deliver the data it does try to figure out if the date actually made it or not, it doesn't put the data back in order it just delivers the data. IP treats each datagram as an independent entity
unrelated to any other Internet datagram so its gonna send it's going to send a chunk of data from a source to a destination if you need to get that chunk of data reassembled in the proper order IP iss not gonna do for you. there's no idea of connections or logical circuits. some a network layer protocols would create a logical circuit before it would send it's data and then all the all the datagrams would go across that logical source circuit in order. IP does not work that way
so IP is worried about end to end delivery as we see from the slide I have a computer a one side. I have a computer on the other side and I have a cloud in the middle that's how most end users think about a network. It's just some stuff that does stuff IP will get it from this computer to that computer a more realistic view is having a bunch of routers is in the middle because that's what really exists IP will send; your source workstation will want to send to the destination workstation and it will send it to a router and that router will examine it and it will decide what to do with it and it'll send it to the next router and that router will examine it and decide what to do with it and it will send it to the next router and it will keep doing that until it finally delivered. we will talk about how they actually happens The RFC defines two basic functions for IP: addressing and fragmentation. addressing: IP uses the address is carrying the internet header
the IP header to transmit internet datagrams toward their destination I paused to think about that... transimt internet datagrams toward their destinations. It doesn't say to their destination. it says toward their destinations right the IP function on any particular host or router does not know the full path that a packet or datagram will need to carry to get to its destination it just knows how I can get one step closer
all talk about that in a minute. The selection of a path for transmission is called routing. routing is a function of the network layer routing occurs based on the network layer addresses. another function of the IP protocol as defined by the RFC is fragmentation. fragmentation is the breaking up of datagrams when necessary if they need to pass through a smaller network. I your recall from our layer 2 discussions we had the idea of MTU. that is how much data can be carried
in a in one a layer 2 frame so if we are sending traffic across different types of layer 2 networks then there may come a possibility that one of the layer 2 network that our data needs to traverse has a different and smallerMTU. if that's the case then our larger datagram may not be permitted to go through or or cannot pass through that link without being broken up. We'll talk about that more in a few minutes. address the routing ipv4 addresses have 32-bits
in length. there are 2 parts to the address. the the RFC defines that as the network number and the local address I generally refer to it as a network portion and the host portion the network portion is the same for all machines on the same network and each machine will have a different a host portion or local address to uniquely identify that machine on that network. How do we figure out which part is the network portion and which part is the host portion? well we use the subnet mask
the subnet mask consists of a bunch of 1's and some 0's where there are ones determines the network portion and everything else is the host. originally IP address scheme was the defined a class full manner. there were five classes. ABCDE A B and C you use for host D you use for multicast addresses and E was reserved and the default subnet mask was determined by the class of the address so a class A had a defautl mask of eight bits which would be to 255.0.0.0
a class B had a default mask of 16 bits which was 255.255.0.0 and a class C had a default mask up 24 bits so that'd be 255.255.255.0 so back in the day that was the only options for sizes of a network you have a A a B or a C that ended up not working out too well once we got to the point where more people are trying to use the internet because we were running out addresses because we do not have any flexibility in how we could allocate those addresses. so classless was addressing was
introduced in RFC 1519. classless addressing allowed us to get away from the default masks and be able to use any link mask we want also referred to is classless inter-domain routing or CIDR as you see on the slide and we usevariable-length subnet mask or VLSM with this idea classless addressing so for example before we could have 8 16 or 24 bit network masks. well now we can have pretty much any network mask we want. we could have a 25 and 27 we have a a 18 and we'd use that based on
how many hosts we need in a particular network we can manipulate our masks to give us the actual proper size network for our needs instead of just having one giant network because that's what the specification said. Routing - as we said earlier, the routing is trying to get the datagram towards its destination so the process a routing is getting the datagram one step closer to our needs to go and we will talk about how that happens two things we're going to talk about. how a host looks at routing and how a router looks at routing usually on your host you have routes for any connected networks that exist on the host. so for example if you have more than one interface card in your host you're gonna have a connected route for two different networks you're connected to and then usually have a default route on your host which says hey if you don't know where to send this packet to
send it to the default route. if you want to look at your routing table on your host netstat -rn will do it on Windows and linux. It will show your routing table how does a host decide how to route things? Well first it looks to see if the destination is on the same network it's on if it is on the same network it sends it locally at layer 2 as we talked about last week.. in the layer 2 slides that will be direct delivery. if it is not on its local network then it will usually send it to its
to its router and its router will take care getting it the rest of the way so the router would be one hop closer towards the destination. this host does not know exactly how to get that packet delivered but it trusts that if it sends it to its a router its router will take care getting it delivered let's step back for a minute and talk a little bit more about how the the host actually decides if it want to send it locally or to its router. it's going to compare its IP address
and its subnet mask to the destination address and if the network portions between its IP address and subnet mask combination and the destination IP address and the subnet mask match up, in other words if they if they are on the same network the it will send it locally. if it's not on the same network then its gonna send it to the router sohere's an example of host routing I have 2 hosts and I have a cloud so assuming that these networks are.. this is 10.1.1.2
and this is 10.1.1.3 and the router is 10.1.1.1 if the PC at the bottom wants to send to 10.1.1.2 it's gonna say oh, hey, I'm connected to the 10.1.1 network. I'm going to send it directly It will use arp to get the mac address of this work station and send the data directly to that workstation if it wants to send traffic to 9.10.11.12 it's going to check its routing table and say oh 9.10.11.12. I'm not on that network let me send it to my gateway
which would be this router, and it's going to send the packet to 9.10.11.12 to the router and the router will then process it in the way which were in talk about in a moment so let's pause for a moment to consider what I just said. this is important there's a question on the midterm about how a host routes a packet if your answer your answer will have nothing to do with the router other than it is going to send it to the router the host is going to check the destination IP address
you compare it to its own IP address and subnet mask and determine if it is on the same network or a different network if it is on the same network calls and locally if it is on a different network it will send it to its router that's important. I've been asking a question for years now and people don't really do that well on its. so I'm telling you its on there so you have no reason not to get it right the host does not ask the router anything. some people want to say the host asks the router where to the other host is. well, the host doesn't ask the router anything the host decides on its own whether the packet is on the same network or a different network and then sends it to the router or locally to the other machine if it thinks they are on the same network. so how does a router route? well I said the host is going to send it to a to the router the first thing the router is going to do, if you remember our discussions about layer 2 just going to remove the layer 2 frame
so it only has the IP datagram left. it's going to extract the IP datagram from that... extracted the IP destination address from the datagram and it's going to compare that datagram to some things first it's gonna check to see if it to that host so if the packet is actually to the router, say you're at ssh'ing into the router it is gonna pass it up protocol stack the transport layer that's the first option. if it is for a connected network that is if it's for a a network that your router is connected directly to then it's gonna deliver that packet to the final destination because the file destination should live out there on that network and if it's for any other destination so if its not for the router and if it's not for a connected network the routers is going to check its routing table and send the packet on its way. what does that mean on its way? one step closer
to where it needs to go. so it's going to check it's routing table. How do we see the routing table well on the Cisco routers will be using in class to use the command show IP route a important command. we will use it to view the routing table on the router so is an example I have a little network here and I'm showing a routing table for the router you look at my network have 172.16.100.0/24 on the left 172.16.101.0/24 on the right the top network shows my router being connected out to
some cloud. 172.16.102.0/24 is the network out there, and then I have a routing table so let's say we want to send a packet from machine on the left network the 100 network to the 101 network Let's talk about whats going to happen. so this PC down here is going to want to send a packet to 101.2 for example its going to look at its subnet mask IP address combination, compare it to the destination and say oh hey, I'm on the 172.16.100 network this packet needs to go to the 172.16.101 network
that is different I'm gonna send it to my router. so it's going to send it to the router the routers gonna get, take the IP datagram out of the ethernet frame it's going to look at the destination address say oh, this packet need to go to 172.16.101.2 that's not let me check my routing table oh hey I have a connected route that's what the C in my routing table stands for, connected for 172.16.102.0 network wait, that's the wrong one, 101.0 network and that needs to go out interface 1 so at that point this router is going to want to send it out this interface to this host so it's going to an arp request if it does not have the arp entry in the arp cache it's going to send an arp request for 101.2 this PC will reply. it's going to say "hey, here's my mac address" and then this router is going to deliver it to that final to the host that is a example where we are connecting to 2
networks connected to the same router the next example is going to be where we want to communicate out to something on the internet so down here we have 172.16.100.2 we called it. it's going to make the same same decision in a before. hey I wanna go to this IP addresses out on the Internet we'll call it 9.10.11.12 again. I want to go to 9.10.11.12. its going to check that IP address against its own IP address/subnet mask combination say hey that's not the same network I'm on
its going to send it to the router. the router is going to pull the IP datagram out of the ethernet frame. the router will examine the destination IP address it will say hey that destination IP address is not me let me check my routing table it will check its routing table, it will be like 9.10.11.12 nope, doesn't match that one 9.10.11.12, nope doesn't match that one 9.10.11.12, nope doesn't match that one this final route down here is a static route the all zeros route is is how the
default route is represented on a router. so it's gonna say hey that 9.10.11.12 matches up to my default route. so I'm going to sendit out interface0 I screwed that up. out interface 2 and that's a picture so I can't fix it, pretend like that says 2 out interface 2 to a next hop of 172.16.102.2 so what that tells us is there some router out here in this cloud with IP address at 172.16.102.2 and we're gonna be able to send our packets to that router and that router will process them for us so if
the router knows where it needs to go to, a connected route it will send it to those hosts, if it doesn't know send it one hop closer to where it needs to go. it will send it towards the final destination we're assuming this router 172.16.102.2 knows what to do it. and it will also get one step closer until it finally delivers it to some router that is connected to the network we need to send the traffic to. in that case it will be the 9.10.11 networks. so as I said earlier we have a bunch of routers in the path across our internet and each one of them will try to get it one hop closer so we have this host 172.16.100.10 wants to send traffic to 10.1.1.11 it's going to send it to the first router, the first router will check its routing table and say hey 10.1.1.11, I need to send it to this router and this router is going to send it to that router and that router is gogint to send it to this router this router is actually connected to that network so it will
finally deliver it to the end host I think that's all I wanted to say about that So how does IP make that happen? well the IP protocol defines the IP header this is how the bits are laid out and what they mean so that the receiving hosts and routers all are playing by the same rules. right we have to know know what bit me in order to interpret them an act properly so the IP header looks like this on the header length can be between 20 and 60 bytes the first 20 bytes
are required it can be no shorter than 20 bytes, 20 bytes ges us up to the destination address we have some IP options we'll talk about a little later on that are not required which is why they are called options they can be from 0 to 40 bytes in length giving us a total length of between 60 and 20 bytes, 20 to 60 bytes the fields we have in the IP header, the version defines what version to the IP protocol we're using we're currently using ipv4 and ipv6 we're talking about IPv4 today
This is a what an IPv4 header looks like the header length defines how long the header is in 4 byte words... what the heck is a 4 byte word, well a four by word is one of these lines essentially, right there is a byte two bytes three bytes four bytes so the header link defines how long the header is in 4 byte words. so we have 1234 5. we have five in there so that means we have the minimum a size header we could have. if we have anything higher than five we have options
what is the highest value we could have in that field? well we have i'm thinking out loud about some unimportant stuff.. just ignore for now however when we look at these things a they're going written in hex so the value you are actually going to see is going to be C for the maximum I guess anyway you nor that of course that type of service it can be used for quality service we are just going to ignore that for the most part total length. this is the total length of the datagram including
header and data the ID field and the flags field and the offset field are used for fragmentation we'll talk about those later. time to live field is actually really hop now this tells us when we need to kill a packet. why might we want to kill a packet? well if we have a routing loop. say our routing protocols are not behaving nicely and we get a a loop in in our internetwork this will kill the packet eventually if there weren't some way to kill packets if we got a loop we would have packets circling around forever and the only way to kill them would be the power off all the routers that were sending the packets around in a circle and in turn back on. that's the only way to get rid of the packets get rid of the packets. so time to live field we set that when we send the packet and and when I gets to 0 the router throws it out. protocol field this is similar to the type field we had an ethernet header
this tells IP protocol what upper layer protocol need to get the data this is how we know this is TCP dataor UDP data or ICMP data this is how we know which upper layer protocol we need to give it to header check is something used rudimentary error checking to make sure that the header did not change in transit so for example it something got corrupted and the IP addresses, the destination address was supposed to be 192.168.1.2 but some bits got corrupted a the destination address actually showed up as 192.168.1.7 then the header check some would detect that and we would throw out, discard the packet a source address that is who sent the packet destination address is who the packet is to options are optional will talk about them later fragmentation. let's talk about fragmentation if we need to send data across a link that is smaller than the size of the packet well we
might need a fragmented what are some times you might want to do thatt, well PPPoE adds a PPP header on top of Ethernet, the PPP header is eight bytes so that makes our effective MTU 1492 so if our host are sending at 1500 bytes get to link that using PPPoE we can only send up 1492 bytes. we might a needed fragment those datagrams to get across. a VPN is another example of something that might require fragmentation if we're sending larger ethernet frames
1500 bytes frames and they get to a device is doing VPN well you need to add some VPN headers between the actually lots of times you add an entire new IP header and then a VPN header and then you have your old IP header and your old data well that's gonna cause some problems and that might cause fragmentation so some reasons why you might have fragmentation I said we would talk about these fields from the IP header later, the ID, the flags field and the offset field. The ID field
is a number, is a value that is used to uniquely identify datagrams we need that because if we break this datagram into three parts we need to know which three parts all go together when they get to the final destination so for example if the ID was 7 and I fragmented this packet all of the fragments would get the number 7 we have some flags. the first fla indicated by an X is not use. the second flag a indicated by D is the don't fragment flag
if for some reason you do not want your packets fragmented you can't tell them to not be fragmented you as a user will normally not do that if you were writing an application and that didn't deal well or fragmentation or you wanted to avoid fragmentation you'd probably be doing that at the application programming level it's not something you're not going to normally a see as the user we'll see in the labs were gonna give ping a command to tell it not to fragment and see what happens the M is used for the more fragments flag that a gets marked as a1 if the packet is fragmented so we can know that more fragments are coming and the offset tells where the data goes when reassembling the packet so if we get three fragments a sent we need to know once we get them how they get put back together a few rules about fragmentation a packets can get fragment more than once I want this fragment it will not be reassembled until it get to the destination host
so if we if we think about a small MTU link in the middle of a network, the router on the other side that link is not gonna wait for those fragments and try to reassemble them no other routers are gonna wait and try to reassmble them. two reasons for that it doesn't make sense to reassemble them if they might get fragmented again later on and then it's a reason is IP datagrams are not transmitted in a manner that guarantee that they will all follow the same path so
it's not really feasible to wait for all the datagrams because each router in the middle might not see all the datagrams. the only ones that thats probably the only ones gonna get all the datagrams for sure is the final destination so they'll be reassembled the final destination so here's a 20,000 foot view of what happens we have our data and IP header on it we send it across a small link, it gets broken into 2 chunks each chunk gets its own IP header and then they get delivered like
they are independent datagrams. here's a 5000 foot view of it. I have ID 10 on my first datagram on the left I have the flag fields all 0 and have the offset field of 0 it gets fragmented my new IP header on my first fragment has a idea 10 it has a more fragments bit set it has the offset of 0 that tells us that the first fragment because more fragments is 1 it has been fragmented offset is 0 it is the first fragment if we look at my second frame we have the ID of 10 again this time I have the more fragments set to 0 that means no more fragments are coming and I have the offset set to 50. why is the offset 50?
well that's where the packet needs to go when it is being reassembled that's where its data need to go when it is being reassembled and that is based on byte numbers but you are saying its 400 bytes right so this is from byte 0 to 799 if I break this up this is from byte 0 to byte 399 so byte 400 is the first bite in this in this fragment so why do I have a 50 there? well the way the fragmentation offset works you divide whatever number you have by eight so
8 will go on a four hundred and the answer will be 50 the offset is 50 why do we divide by 8? well the fragment offset field is 13 bytes in length. the total length of an IP datagram can be... is a sixteen byte field so are missing 3 did I say 16 bytes? 16 bits in length so we are missing 3 bits. so 2 to the 3rd is 8, so if we did not use that factor of 8 we would not be able to fragment all possible IP datagrams because it would be possible to send
larger datagrams that we could represent in 13 bits so on that's why we divide by 8 because the offset field is 13 bits, the total length field is 16 bits here is another example if we look at our IP header now this time we have the don't fragment bit set to 1 so whereas before we fragmented that that packet into two packets that datagram into 2 datagrams now we're not gonna fragment I drew that X to indicate that we are not fragmenting it and the router will send an ICMP error
error message back to the sending host so some rules about fragmentation. if the packet is not fragmented be more fragments field will have a zero in it and the offset field will have a 0 in it. if it is the first fragment the more fragments field will have a 1 in it and the offset field will have a 0 in it. if it is a middle fragment the more fragments field will have a1 in it and the offset will have some number in it right, some non-zero value and if it is the last
fragment the more fragments will have a 0 in it and the offset field will have a value in it, some non 0 value so that I can determine which fragment it is based on the the fields. can we identify just looking at whether it has a number not which middle fragment it is? no we would need to know the actual number of the offset to determine the actual order the fragments went in so you can't just determinate because it has a number, but if you have all the offset values you should be able to put it back together let's talk about IP options. options may appear or not appear in the datagrams which that was from the RFC that's why they're called options I guess some of the options you might see if you look in Wireshark at the end of your IP header you may see them there's an end of option list that can be used to indicate that options are over and it also serves as padding. The no operation option
that can be used as padding. the options have to start on the side of the a header. let me go back up here and show you so the options must start over here on the left side of the header. it can't start in the middle so if you had an option up here that took up 2 bytes, right? you can't start next option in the middle so you put two bytes of no operation the space that out record route this is a way the IP protocol can be used to keep track of which routers that packet goes through
there's only 40 bytes up space available so that usually not really enough space to keep track of the whole path so it's not really used a lot lots of times if you wanna know the route a packet is taking you use trace route command to find that. source routing the next two options source routing is a way you can specify in the IP options which routers you want your packets to go through and then the router try to honor that loose source route says hey I want my packets to go through
these routers you can also go through other routers but you must go through these routers and strict source routing says hey I want my packets to go through these routers and you can go through no other routers. only through these routers. a timestamp option can be used keep track of the time when a router crosses the when a packet crosses the other routers so what about errors? I said earlier there is no mechanism to augment end to end data reliability flow control sequencing or other services well if you want those things you can get that you can use a transport layer protocol to get those things for example TCP will provide reliability flow control and sequencing ICMP is used to report errors so um by using those other upper layer protocols you can you accomplish those goals that are not built in to IP so if you have any questions post to the discussion board or bring them to class

Ask anything
We've read this whole study set, so questions about it get the best answers.