 So we're looking at what we call classless IP addressing where a 32-bit IP address is split into two parts, the network part and the host part, and the network part identifies our subnet and the host part identifies our device inside that subnet. It's called classless because in the past they defined five different classes, class A, B, C, D and E, and that the classes in the old days define where the split is between the network and host portion, but nowadays the way to define where the split is is using the subnet mask. A second IP address, a special case mask is used and tells us. For example here, the first 22 bits in the mask are one, meaning of our 32-bit IP address, the first 22 bits in the IP address are in the network portion. In the mask the last 10 bits are zero, meaning in the IP address the last 10 bits are the host portion. So take your 32 bits of your IP address, split it into two parts, network then host, where do you split, the mask tells you. So we've been going through some examples and some special case addresses. So far we've got our internet with some subnets of interest for this example and we've assigned what we call network addresses. Normally we think an IP address is for a device, but there are some special case IP addresses which are for entire subnets, groups of devices or families of devices. So for example subnet A, instead of calling it subnet A, we actually give it a specific address 1.1.0.0 slash 16, that's the network address we say, where the slash 16 means the mask has 16 ones and the rest are zeros, meaning the IP address 1.1.0.0, the first 16 bits are the network portion and the last, in this case 16 bits are the host portion. This special case network address, the way that we get it, we have the network portion and we set the host portion to all binary zeros. So the example we had last lecture was, here was our subnet or their network address 1.1.0.0 slash 16 in binary, this is the first 16 bits, the subnet mask shown here tells us to split after the 16th bit, the subnet mask of 16 ones or simply slash 16 in shorthand notation says split here, so the network address 1.1 and the last 16 bits we set to zero, that's a special case network address. All of the devices on that subnet must start with the same 16 bits, that's our rule. So we had router 2 interface zero starts with the same 16 bits and host H1 starts with the same 16 bits because both of those devices are on subnet A. So if we know that the network address for that subnet then we can allocate addresses for individual devices inside that subnet and your homework was and it's quite simple given all the subnet network addresses choose some IP addresses for the devices. I'll show you which ones I chose in a moment. But while we're looking at the special case network address, 16 bits followed by 16 zeros for the special case network address, there's another special case address which is used for a different purpose, it's called the directed broadcast address and the way that we get it is that we take the same first 16 bits and we set the last bits to all binary ones. So let's do that and then we'll explain what it's used for. It's easy to do that. So for this subnet A we can say there's a another address which I'll call the directed broadcast and for subnet A the subnet has a corresponding directed broadcast address where the 16 bits at the start are the same, the first 16 bits then we split and to get the directed broadcast address set the last bits to be all ones. So and then we can convert into dot a decimal notation if we want to have a human friendly form and in this case it will be one dot one dot eight ones is 255 in decimal and another eight ones is 255 and to be precise we'll include the mass there slash 16. This is a special case address, we call it directed broadcast. The purpose of it, this address, we'll not go through detailed examples yet, we'll see some later in the slides but the purpose is if you want to send it everyone in the subnet I don't want to just send a host h1 I want to send every host in the subnet then why I can do is create an IP datagram where the destination address is this one one two five five dot two five five. It means it has the meaning send to everyone in that subnet even if you don't know how many devices are in the subnet you can still send to all of them using the directed broadcast. Broadcast in this context means send to everyone, everyone in a subnet. Later we'll return and see an example of how it's used but for now just be aware how to derive the address. Subnet A has network address 1100 slash 16 and has directed broadcast address 1.1.255.255 slash 16. You can fill that in in this table. You've already got the network addresses, you can fill in the directed broadcast addresses for the other subnets as well. You can do that for homework we will not need it today I think. I'll just to be complete we'll write it here in brackets. So this was the network address and this broadcast 1.1.255.255. The directed broadcast we'll see there's an alternative later and the other subnets would have a corresponding directed broadcast address that have for example subnet B 2.2.0.0 slash 16 you can find the first 16 bits will be the same the last 16 bits will be all binary ones and you'll find it becomes 2.2.255.255 and you can do that for the others. So when we have a subnet when we allocate addresses to devices inside that subnet hosts and routers then the mask tells us how many possible values that we can use. A mask of slash 16 means there are in fact 16 bits in the host portion. A mask of slash 24, 24 bits in the network portion, 8 bits remaining in the host portion. So with 8 bits in the host portion on subnet C there are 2 to the power of 8, 256 possible addresses for devices in this subnet. Two of them are special cases that we cannot give to devices. We cannot give the address which has all zeros in the host portion and we cannot give the address which has all ones in the host portion. Other than that we can choose amongst the remaining 254 addresses. So H2 we can choose from 254 possible values. Router 3 interface 1 we can choose from 254 possible values except they should not overlap. They should not be the same. They should be unique between the devices. We did that for H1 and R2 interface 0. H1 we chose 1.1.1.27. The first 16 bits are the same as our subnet address. The last 16 bits we chose. I chose in that case. Router 2 interface 0, the first 16 bits are the same. The last 16 bits are different from H1. They must be different from the other devices. I chose 1.1.1.1. Which values you choose is up to the operator of the network. If it's your network you can choose whatever you like as long as it meets the rules. In some examples I'll choose easy ones to write down. So let's choose some addresses for the remaining interfaces. That is we've done H1 and R2 interface 0. But router 2 also has an interface on subnet B. Interface 1. Router 1 also on subnet B. Router 3 and router 4. So each of those need IP addresses. The network address is 2.2.0.0. So what's a possible value for, say, Router 1 interface 1? Choose a value. Maybe you've written it down as your homework. Router 1 interface 1. Someone chose 2.2.0.27. Correct. It's okay. What did you choose? 2.2.0.1. Correct. So there are 65,000 possible values you can choose from. Since you all did your homework yourself you probably chose different values. Fine. I'll choose some and we'll use them throughout but you can use your own values. The point is Router 1 interface 1 must start with the same first 16 bits. And here's a shortcut. When it's 16 bits as a subnet mask it means the split is at the second dot in the dot a decimal notation. Because the first decimal number means 8 bits. The second is another 8 bits. So 16 bits means at the second dot. In other words the first two decimal values must be the same. The last two decimal values can be different. And when it's 24 it's at the third dot. So instead of having to convert to binary and back you can maybe take a shortcut and realize that okay on subnet 4.4.1.0 slash 24 everything must have the same first 24 bits or in decimal 4.4.1. The last decimal number cannot be 0. It cannot be 255 because that's all ones. So it can be from 1 up to 254. And you can choose any value there. In other words if the subnet mask is slash 8 slash 16 or slash 24 sometimes we can do it in our heads without converting to binary to find where the split is and get the correct IP addresses. When it's slash 22 the split is not at one of the dots so we should be careful there. So I'll go through an example with that. So I'll write down some addresses that I will choose because I'll use them later. So for router 1 interface 1, 2.2. something dot something, router 2 interface 1, 2.2. something dot something else. Different from router 1 interface 1 and same with 4.0 and 3.0. Router 3 interface 1 and h2 should be 4.4.1 dot something. Here we'll have 4.4.2 dot something and on subnet e 3.3. something dot something. Subnets f and g we'll deal with in more detail. So let me write them down so we can continue. Where? Let's get rid of all of that for now. We've already written down for router 2 interface 1, interface 0 h1 so let me fill in the rest so we have them for later. So you may choose different values but that's okay. 2.2 I'll fill in the remaining missing parts in a moment. This needs to be 2.2 dot something at slash 16. So these are on the same subnet so they must start with 2.2 because they're slash 16 they're all on the same subnet if you look at the picture so the last two decimal digits must be different amongst those four and for whatever reason I've chosen 1.5 here you don't have to change yours or you can write them both down if you have your answer and then my answer just so you can follow my example as well and then we have some other values this is a slash 24 and in this case for router 3 I chose I'm going to choose 10 and 20 here is a slash 16 these three are on the same subnet 3.3.0.0 so I'll choose some different values for each of them 1.1 1.2 1.3 and to finish page 2 is on 4.4.1 and it's a slash 24 and something different a bigger number what's the maximum value I can include use here I cannot use 0 because that's a special case I could be 1 2 3 4 I cannot use 10 because it's already used and I could go up to 254 I cannot use 255 because that's equivalent to all ones so from one up to 254 as long as it's not used by another 156 something different we've got two missing I will do them in a bit more depth because they use a different mask where the split is not at the dots in the dot a decimal notation any questions on these though first in practice how do you get these IP addresses or the operator of the network can set them either manually you go to every computer and type it in or more commonly there's a protocol that can operate in the background that your computer is given an IP address from a server DHCP is the protocol that does that in most networks when your computer boots up it contacts a special server that which will allocate an address and that server will keep track of this the used and the unused addresses so that we don't have conflicts so what about R5 interface 1 and then R6 interface 1 let's focus on subnet f 3.3.28.0 slash 22 in subnet f the the network address 3.3.28.0 slash 22 that's right in binary 3.3.28 correct 16 8 4 28 0 that's our network address for subnet f and the mask slash 22 22 ones 16 22 ones in a row slash 22 followed by the remaining 10 zeros so that's our mask and that mask tells us where the split is that is the split is here between the network portion the part that identifies our subnet and the host portion the network part and the host part every device on subnet f must have the same first 22 bits the same network portion and a unique host portion our director broadcast let's do the director broadcast now it's an easy one the director broadcast for subnet f bc for broadcast the same first 22 bits the same first 22 bits and then the last 10 bits must be all ones that's our definition for director broadcast convert it to dot a decimal if you like 3.3.31.255 note that the way that the split is not at one of the dots and it's we need to be careful that don't just assume that the director broadcast always is finished with 255 here it started 3.3.28.0 for the network address the broadcast is 3.3.31.255 network address broadcast address and they are in fact the limits for this subnet we start at 3.3.28.0 as a special case and then the devices inside the subnet can use numbers larger than that 3.3.28.1 3.3.28.2.3.4 and can even go 3.3.29.1 3.3.29.2 and so on all the way up to 3.3.31.254 that could be allocated for my device 3.3.31.255 is a special case for director broadcast so they are the lower limits the network address and the higher limit the broadcast address the devices can use values inside that range so let's consider some devices let's say what have we got we've got router 5 interface 1 is on this subnet if we look at our picture so let's allocate an address we need the same first 22 bits and then the last 10 bits our mask can be any value except all zeros and except all ones let me choose a value what am i going to use easy one it's not all zeros it's not all ones so that's valid it's not used because it's the only one so far it will be 3.3.28.1 that's from our router 5 although our picture doesn't include another host let's assume all subnets have hosts we didn't draw them all so let's say there's a h3 on subnet f so when i give that an ip address it must start with the same first 22 bits then the mask tells us we change to the host portion and h3 the last 10 bits cannot be all zeros cannot be all ones and cannot be a currently used value the one we use for r5 there's a possible value which is different there were 10 bits to choose from so we actually have two to the power of 10 possible different values 1,024 possible different values except the two special cases all zeros all ones leaves us 1,022 possible values but we can't use the one we just used so choose from the other 1,021 i chose one so that's a valid address for h3 on subnet f and in dotted decimal notation you can convert 3.3. what do we get 29.1 so you have to be careful with the dotted decimal notation devices in subnet f 3.3.28.0 include 3.3.28.1 and 3.3.29.1 and the director broadcast is 3.3.31.255 so it's not as simple as when we cut at 8, 16 and 24 where it cuts at the dots what's my recommendation when you have a mask which is not 8 16 or 24 write the address down in binary and look exactly where the cut is if you have 8 16 or 24 maybe you can use a shortcut but you can use in binary if you like questions on director broadcast or how we allocate IP addresses to devices everyone got a correct value for r5 interface 1 should have been 3.3.28.29.30 or 31.something for subnet f sorry subnet g the last subnet again you can allocate addresses you need to do it in the similar manner so let me fill in our table to complete this router 5 what did i choose 3.3.28.1 slash 22 and router 6 i'm going to choose 3.3. what can it be 16 or 17 or 18 or 19 i think it can be there i'll choose 17 to be different 4 you can have other values there any questions on the IP address allocation before we move on to routing okay then let's look at our our handout and see what we've done you now we started with the network address as i gave you that you can quite easily get the director broadcast it's similar to the network but the host portion is all ones and we've just gone through the actual IP addresses for a range of devices the next thing we want to do is fill in some routing tables now devices need routing tables to know who to send to next and i've got space for routing tables for four of the routers we'll i think get one or two done today so we'll do router two first and here on the right we can do another router later so the routing table remember for a particular device to reach some destination who is the next router we send to to get there this information comes from the least cost paths if we know the least cost paths from source to destination that destination is listed as the first column and the next node or the next router in that least cost path is listed in the second column so that's our concept for a routing table we'll try and fill that in for our devices let's talk about and and the least cost paths or the routing table for some of the devices and then we'll fill it in with the details let's start with router r2 okay let's say we are router r2 when we need our routing table and for least cost paths we'll assume the the least number of hops the sort of the obvious path we'll see that is if you're at r2 and you want to reach h2 where do you think r2 should send the packet the packets at r2 we want to get it to h2 destination is h2 where should r2 send the packet to r3 interface zero be careful when we talk about a router we should be specific about the interface because r3 is actually attached to three different subnets so if we're here and we want to get to h2 send to r3 interface zero on r3 and then r3 we'll deliver it to h2 if we're at r2 and we want to get to someone maybe there's h4 on subnet g where should r2 send the data to we're at r2 we want to reach h4 on subnet g we should send r4 interface zero if we want to reach someone on subnet e we also send to r4 interface zero that's the next node in the path and someone on subnet f send to r4 interface zero on subnet d send to r3 interface zero what about if someone is on subnet a that is r2 wants to send to h1 which is the next router r2 wants to send to h1 what is the next router r2 to h1 next router is you're going to send to r4 to get to h1 there is no next router when the current node r2 is on the same subnet as the destination don't send to another router send direct to the destination there's no need to send via an intermediate router so we'll in the routing table treat that as a special case to reach h1 from r2 send direct to h1 don't send to a next router similar if we if there was h5 on subnet b from r2 we'd send direct to h5 that is any destination on the subnets we are attached to we're directly attached to subnet a and subnet b send direct to the destination there's no next router so we'll list that in our routing table what about if i want to reach subnet z where do i send to r2 wants to reach subnet z z remember at the top we have the rest of the world the internet and there's millions of other subnets out there so if i want to reach anyone else that's not in this picture i would send to r1 interface one we can think of that as a default route we have specific routes to the the destinations we can see here by default anyone else let's send to r1 interface one and hope that will get to the destination before we fill in the routing table for r2 it's the first point if i want to reach h2 we said send to r3 interface zero well in our routing table we don't say r3 interface zero we say the IP address of r3 interface zero so the next router will be listed as 2.2.1.2 so in our routing table we need two two columns to fill in destination and next router if the next router we said is r3 interface zero will enter in this next router column 2.2.1.2 so we use the IP address not the router name what about the destination let's focus on subnet c let's say there are 100 hosts on that subnet h2 h20 h21 many hosts there if r2 wants to reach h2 next router r3 interface zero if r2 wants to reach another host on subnet c h5 next router r3 interface zero want to reach a different host on subnet c it will still be r3 interface zero in other words for r2 to reach any host on subnet c send a router 3 interface zero so we don't have routes to individual hosts we have a single route saying for r2 to reach subnet c send a r3 interface zero meaning if the host or the destination is on subnet c will send to this router instead of having entries for every possible host we just have entries for each subnet and that greatly simplifies routing in the internet when we have billions of hosts we don't need entries for each of them we just need for the subnets that cover those hosts and to refer to the subnet we don't say subnet c we say subnet 4.4.1.0 slash 24 we use the network address given that let's fill in the routing table for r2 so we'll start with r2 and fill it in so first let's say we're at r2 and we want to reach the destination of subnet a which is identified subnet a is 1.1.0.0 slash 16 meaning if the destination is on this subnet then we will send to the next router well for subnet a there is no next router from r2 to subnet a we are directly attached don't send to a next router so i'll say send direct in my routing table no next router i'll just write it direct different different software will use different notation here why it won't say direct but the concept is there is no next router we are directly attached to that subnet so let's fill in for the other destinations subnet b 2.2.0.0 slash 16 we're actually also attached to that subnet so we can send direct subnet let's try subnet d and subnet c and d that is it's going back to our picture we're at r2 we want to reach 4.4.1.0 we should send to router 3 interface 0 more precisely we should send to 2.2.1.2 to reach anyone on subnet 4.4.1.0 slash 24 send to router 2.2.1.2 any problems so far with our routing table questions we've done the evaluation for the course so i can be as mean as i like for the remaining lectures maybe ask you to submit your handouts today so fill in the rest of the routing table for router r2 if there are no questions r2 we've got the two directly attached subnets we've got subnet c 4.4.1.0 so do subnet d and then think about the remaining subnets you don't need to use the entire table the space i've provided is just it's the same for all the routers you don't have to use all the rows you should have a routing table as small as possible as few rows as possible how you're going to reach subnet d we start at r2 we want to get to 4.4.2.0 we should also send to r3 interface 0 so it'd be the same next router as subnet c from r2's perspective we send the same direction to reach either c or d to reach subnet d the next router is also 2.1.2.2.1.2 so not so hard what about subnet e to reach 3.3.0.0 slash 16 r2 should send to r4 interface 0 and you look up your ip address now yours may be different so be careful but the ip address i gave r4 interface 0 was 2.2.1.3 so i'll use that in the routing table any problems one of the easier things we've done in the course okay so do for the last remaining subnet so you can do for f and g and then for the rest of the world the rest of the internet you can use a default route so i'll write down for f and g let's have a look at them first to reach f 3.3.28.0 slash 22 i r2 will also send a router 4 interface 0 similar for 3.3.16.0 slash 22 was a 28.0 slash 22 and 3.3 dot 16.0 slash 22 same next router and to reach the rest of the world anyone out on the internet i'll use a special case for any other destination send to r1 interface 1 that is anyone out here send to r1 interface 1 which i chose as 2215 everyone get that or similar if you have different ip addresses yes what is star star means in general in computing any value it's what we call a wild card in this i'm using it to mean for any other think of it for any other value for any other destination so if we don't match the previous rows for the destination then send it to 2215 we sometimes refer to that as the default route the default gateway so star i'm just using as a way to indicate any value sometimes in software you'll see it as instead of star they'll say 0.00 slash zero all right you don't have to write that one down but the that's just some way that software shows it any value that doesn't match any other value now how do we use that if we have this routing table then the way that we use it when router r2 has a ip datagram it looks at the destination address that is when we have a packet to send at r2 we look at the destination address of that packet and check in the routing table so let's consider some examples let's say the destination address is 4.4.1.156 r2 sees an ip datagram we don't care who it came from at this stage we care who we need to get it to destination is 4.4.1.156 so what r2 does is realizes that is not me i am not 4.4.1.156 therefore i will look in my routing table to see who to send it to next so what we can think of for these entries in the routing table we want to find a match where at least the first mask set of address match what do i mean compare 4.4.1.156 to 1.1.0.0 compare them in binary how many of the first bits match 4.4.1.156 in binary compared to 1.1.0.0 in binary how many of the first bits from the left match are the same 4 is what five zeros one zero zero one is seven zeros one so in fact five bits match and then we have a difference so the first five bits match so zero of zero and four but then we have a difference now what we need is the first 16 bits to match the subnet mask tells us well we need 16 bits to match which they don't so therefore we say this does not match that is the destination 4.4.1.156 is not on the subnet 1.1.0.0 and we know that because of the way that we've designed the addressing so this destination does not match the first row does it match the second row do the first 16 bits match no they don't the first eight bits there'll be a difference 4.4.1.0 4.4.1.156 to the first 24 bits match yes they will 4.4.1 those 24 bits will match the 24 bits of the destination address therefore we have a match so we will use that as the next router so that's how we check and it's quite easy conceptually find does this IP address fit on this subnet no it's not on the subnet 1.1.0.0.2 it's on the subnet 4.4.1 now there are some exceptions sometimes we have may have more than one match it's possible that we have more than one match in that case we choose the match which has the most number of bits that match the longest prefix but i think we'll not see that so in this case we compare 4.4.1.156 to 1.1.0.0 do the are there 16 bits matching no are there 16 bits matching between this IP address and 2200 no are there 24 bits matching between this and this yes what we would normally do is do them in order but in reality they are all checked do 24 bits match between this and this one no 16 bits match no we will see quite easily none of these will match only 4.4.1.0 this is a special case we'll just use that if none of them match we've got one match here so the result is that we will send to next router 2212 so router 2 has a datagram destination 4.4.1.156 checks the routing table matches the third row send a 2212 we will send a 2212 and that router will do the same thing it will compare the destination against its routing table to see who to send to next you can fill in the routing table for the other routers let's consider another case any questions on that one that's an easy one it's going to disappear any questions okay let's try a different destination we have a different ip datagram and the destination address is 3.3.29.1 let's go through the rows one by one and see which ones match or which ones don't is easy do the first 16 bits match with 1.1 no 2.2 no 4.4.1 does that match with 3.3.29 no this one no now let's consider these three do the first 16 bits 3.3 match with the first 16 bits of our destination yes they would 3.3 is the first 16 bits but in decimal and 3.3 are the same so yes this is a match what about this one to the first 22 bits of 3.3.29 match 3.3.28 can we squeeze it in 3.3 and 29.1 there's our ip address 3.3.29.1 and we're comparing with 3.3.28.0 3.3.28 and we're comparing the first 22 bits 8 16 at this point do the first 22 bits match maybe small up there you can check yes they do match it's the same first 22 bits match so in fact 3.3.29.1 matches 3.3.28.0 so matches two rows here the third one does it match 3.3.16 hands up for yes 3.3.16 and 3.3.29 to the first 22 bits match hands up for yes hands up for no 16 so the first 16 bits 3.3 were matched 16 is equivalent to 0 0 0 1 0 0 so no they would not match 16 is what 0 0 0 1 followed by 4 0s compare that with 3 0s and 3 1s they'll be different that would not match here we have two matches which one do we use well what we do is we choose the one that matches with the most number of bits and if you compare the one that matches the most number of bits so they both have at least their subnet mask worth this one matches 22 and that's 22 they're the the same here but the second one matches more than 16 bits it matches 22 bits so that one would be chosen if we have two matches choose the one with the most number of bits now that's a case we will not see very often so don't worry too much about the details but the point is in fact we don't need that second route here because 3.3.28.0 slash 22 is in fact within 3.3.0.0 slash 16 if it matches the second one 3 3 28.0 it will always match 3 3 0 0 anything that has the same first 3s followed by a 28 29 or whatever will also match 3.3 so in fact we don't need this second route this one is sufficient and the way that the subnets were designed the addressing was that 3.3.0016 includes these two .28 and .16 that I allocated and in practice what how the internet is structured is that it's like this in that we have one subnet and within that we can have sub subnets and effectively 3.3.28.0 is a as a sub subnet it's sub of the 3 3 0 0 there's a hierarchy of subnets if we look at our picture it may be easier to see the idea from router 2 if anything starts with 3.3 any destination 3.3 send a router 4 even if it's 3 3 28 3 3 16 anything that starts with 3.3 send a router 4 so instead of having three different entries in our routing table we can cut it down to one and that's the way that I chose the subnet addresses for f and g that they are a subset of 3 3 0 0 maybe that's a bit too much detail for some people but that's a practical thing that's used in the internet to simplify routing we only have a route to the larger subnet not to the individual subnets the end result we can have a simpler routing table it can be limited to just that's an even better routing table because 3.3.0.0 covers subnets f and g and we have the same next router so we don't need those other two routes if you include them you'll get the same results you'll get to the correct destination but we often try to have an optimal routing table the smallest possible and that's possible the way that I allocated f g and e in in an exam unless I asked explicitly to give the optimal one I think I would accept both answers this one or the previous one we had the two there it would be okay unless I say give the optimal routing table or other times in an exam I may say let's make it even easier let's process the routing table in order it's not done in practice but a simple way to think of the routing table is just simply do it in order what we've been doing is trying all but if you do it in order the first one that matches we use and that makes life easier as well so what's your task complete the routing tables for the other nodes specifically we're just done in r2 you can do r3 r4 do r5 there's no need to do r6 you'll see it's essentially the same as r5 there's one small difference but just save a bit of time just do r5 and also the hosts have routes the hosts need routing tables so create the routing tables for h1 and h2 that is we've done r2 you do r3 r4 and a r5 and at the bottom you'll find that very easy host h1 and h2 complete those routing tables so you know how how to create them