Chapter 19 Network Layer: Logical Addressing - Kasetsart University

Transcription

Chapter 19Network Layer:Logical Addressing19.1Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

19--1 IPv19IPv44 ADDRESSESAn IPv4IPv4 address is a 3232--bit address that uniquely anduniversally defines the connection of a device (forexample, a computer or a router) to the InternetInternet.Topics discussed in this section:Address SpacepNotationsClassful AddressingCl l AddClasslessAddressingiNetwork Address Translation (NAT)19.2

NoteA IPAnIPv44 addressddisi 32 bitsbit long.l19.3

NoteThe IPv4 addresses are uniqueandd universal.il19.4

NoteThe address space of IPv4 is232 or 4,294,967,296.4 294 967 29619.5

Figure 19.1 Dotted-decimal notation and binary notation for an IPv4 address19.6

NoteNumbering systems are reviewed inAAppendixdi B.B19.7

Example 19.1Change the following IPv4 addresses from binarynotation to dotted-decimal notation.SolutionWe replace each group of 8 bits with its equivalentdecimal number (see Appendix B) and add dots forseparation.separation19.8

Example 19.2Change the following IPv4 addresses from dotted-decimalnotation to binary notation.SolutionSl iWe replace each decimal number with its binaryequivalenti l( Appendix(seeAdi B).B)19.9

Example 19.3Find the error, if any, in the following IPv4 addresses.Solutiona. ThereThmustt beb no leadingl di zero (045).(045)b. There can be no more than four numbers.c. EachE h numberb needsd tto beb lessl thanth or equall tot 255.255d. A mixture of binary notation and dotted-decimalnotationt ti isi nott allowed.lld19.10

NoteIn classful addressing, the addressspace isi divideddi id d intoi t fivefi classes:lA, B, C, D, and E.19.11

Figure 19.2 Finding the classes in binary and dotted-decimal notation19.12

Example 19.4Find the class of each address.a. 00000001 00001011 00001011 11101111b. 11000001 10000011 00011011 11111111c. 14.23.120.8d. 252.5.15.111Solutiona. TheTh firstfi t bit isi 0.0 ThisThi isi a classl A address.ddb. The first 2 bits are 1; the third bit is 0. This is a class Caddress.ddc. The first byte is 14; the class is A.d Thed.Th firstfi t byteb t isi 252;252 theth classlisi E.E19.13

Table 19.1 Number of blocks and block size in classful IPv4 addressing19.14

NoteIn classful addressing, a large part of theavailableil bl addressesddwere wasted.t d19.15

Table 19.2 Defaultfmasks forf classfulf addressingg19.16

NoteClassful addressing, which is almostobsolete,b l t isi replacedld withith classlesslladdressing.19.17

Example 19.5Figure 19.3 shows a block of addresses, in both binaryand dotted-decimal notation, granted to a small businessthat needs 16 addresses.We can see that the restrictions are applied to this block.Theh addressesddare contiguous.iTheh numberb off addressesddis a power of 2 (16 24), and the first address is divisibleb 16.by16 TheTh firstfiaddress,ddwhenh convertedd to a decimald i lnumber, is 3,440,387,360, which when divided by 16resultsl ini 215,024,210.215 024 21019.18

Figure 19.3 A block of 16 addresses granted to a small organization19.19

NoteIn IPv4 addressing, a block ofaddressesddcan bbe ddefinedfi d asx.y.z.t /nin which x.y.z.t defines one of theaddresses and the /n defines the mask.19.20

NoteThe first address in the block can beffoundd byb settingtti theth rightmosti htt32 n bits to 0s.19.21

Example 19.6A block of addresses is granted to a small organization.We know that one of the addresses is 205.16.37.39/28.What is the first address in the block?SolutionTheh binarybirepresentationi off theh giveniaddressddiis11001101 00010000 00100101 00100111If we set 32 2832 28 rightmosti hbibits to 0,0 we get11001101 00010000 00100101 0010000or205.16.37.32.Thi iis actuallyThisll theh blblockk shownhiin FiFigure 19.3.19 319.22

NoteThe last address in the block can beffoundd byb settingtti theth rightmosti htt32 n bits to 1s.19.23

Example 19.7Find the last address for the block in Example 19.6.SolutionTheh bibinary representationi off theh giveniaddressddisi11001101 00010000 00100101 00100111Iff we set 32 28 rightmosti hbibits to 1,1 we get11001101 00010000 00100101 00101111or205.16.37.47Thi iis actuallyThisll theh blblockk shownhiin FiFigure 19.3.19 319.24

NoteThe number of addresses in the blockcan beb foundfd byb usingi theth formulafl232 n.19.25

Example 19.8Find the number of addresses in Example 19.6.SolutionThe value of n is 28, which means that numberof addresses is 2 32 28 or 16.19.26

Example 19.9Another way to find the first address, the last address, andthe number of addresses is to represent the mask as a 3232bit binary (or 8-digit hexadecimal) number. This isparticularly useful when we are writing a program to findthese pieces of information. In Example 19.5 the /28 canbe represented as11111111 11111111 11111111 11110000(twenty-eight(twentyeight 1s and four 0s).Finda. The first addressb. Thee last addaddressessc. The number of addresses.19.27

Example 19.9 (continued)Solutiona. The first address can be found by ANDing the givenaddresses with the mask. ANDingg here is done bit byybit. The result of ANDing 2 bits is 1 if both bits are 1s;the result is 0 otherwise.19.28

Example 19.9 (continued)b. The last address can be found by ORing the givenaddresses with the complement of the mask. ORinghere is done bit by bit. The result of ORing 2 bits is 0 ifb h bitsbothbi are 0s; theh resultl isi 1 otherwise.h iThehcomplement of a number is found by changing each 1to 0 andd eachh 0 to 1.119.29

Example 19.9 (continued)c. The number off addresses can be ffound byycomplementing the mask, interpreting it as a decimalnumber,, and addingg 1 to it.19.30

Figure 19.4 A network configuration for the block 205.16.37.32/2819.31

NoteThe first address in a block isnormallyll nott assignedid tot any device;d iit is used as the network address thatrepresents the organizationto the rest of the world.19.32

Figure 19.5 Two levels of hierarchy in an IPv4 address19.33

Figure 19.6 A frame in a character-oriented protocol19.34

NoteEach address in the block can beconsidered as a two-levelhierarchical strstructure:ct rethe leftmost n bits (prefix) definethe network;g32 n bits definethe rightmostthe host.19.35

Figure 19.7 Configuration and addresses in a subnetted network19.36

Figure 19.8 Three-level hierarchy in an IPv4 address19.37

Example 19.10An ISP is granted a block of addresses starting with190.100.0.0/16 (65,536 addresses). The ISP needs todistribute these addresses to three groups of customers asf llfollows:a. The first group has 64 customers; each needs 256addresses.ddb. The second group has 128 customers; each needs 128addresses.ddc. The third group has 128 customers; each needs 64addresses.ddDesign the subblocks and find out how many addressesare stillill availableil bl afterf thesehallocations.lli19.38

Example 19.10 (continued)SolutionFigure 19.9 shows the situation.Group 1For this group, each customer needs 256 addresses. Thismeans that 8 (log2 256) bits are needed to define eachhost. The prefix length is then 32 8 24. The addressesare19.39

Example 19.10 (continued)Groupp 2For this group, each customer needs 128 addresses. Thismeans that 7 ((log2g 128)) bits are needed to definefeachhost. The prefix length is then 32 7 25. The addressesare19.40

Example 19.10 (continued)Group 3For this ggroup,p each customer needs 64 addresses. Thismeans that 6 (log264) bits are needed to each host. Theprefixpf lengthg is then 32 6 26. The addresses areNumber of granted addresses to the ISP: 65,53665 536Number of allocated addresses by the ISP: 40,960Number of available addresses: 24,57624 57619.41

Figure 19.9 An example of address allocation and distribution by an ISP19.42

Table 19.3 Addresses for private networks19.43

Figure 19.10 A NAT implementation19.44

Figure 19.11 Addresses in a NAT19.45

Figure 19.12 NAT address translation19.46

Table 19.4 Five-column translation table19.47

Figure 19.13 An ISP and NAT19.48

19--2 IPv19IPv66 ADDRESSESD it allDespitell shortshorth t-termtsolutions,l tiaddressddd l tidepletioniisstill a longlong--term problem for the InternetInternet. This andotherth problemsbli theinth IP protocolt l itselfit lf havehbbeenththemotivation for IPvIPv66.Topics discussed in this section:StructureAddress Spacep19.49

NoteAn IPv6 address is 128 bits long.19.50

Figure 19.14 IPv6 address in binary and hexadecimal colon notation19.51

Figure 19.15 Abbreviated IPv6 addresses19.52

Example 19.11Expand the address 0:15::1:12:1213 to its original.SolutionWe fifirstst needeed to aligalign tthee left side of tthee double colocolon tothe left of the original pattern and the right side of thedouble colon to the rightg off the originalgppattern to ffindhow many 0s we need to replace the double colon.This means that the original address is.19.53

Table 19.5 Type prefixes for IPv6 addresses19.54

Table 19.5 Type prefixes for IPv6 addresses (continued)19.55

Figure 19.16 Prefixes for provider-based unicast address19.56

Figure 19.17 Multicast address in IPv619.57

Figure 19.18 Reserved addresses in IPv619.58

Figure 19.19 Local addresses in IPv619.59

In classful addressing, a large part of the avail bl dd t dilable addresses were wasted. 19.15. Table 19.2 Deffff gault . Note Classful addressing, which is almost oblt i l dithl lbsolete, is replaced with classless addressing. 19.17. Example 19.5 Figure 19.3 shows a block of addresses, in both binary and dotted-decimal notation, granted to a .