CSCI 3500: Studio 23

Network Layer

The network layer is responsible for routing messages between separate physical machines. The most common network-layer protocol is the famous Internet Protocol (IP). The familiar IP address imposes a structure on how to route packets through an IP network.

In this studio, you will:

  1. Learn to split an IP address into a network address and host identifier
  2. Use the CIDR system to specify groups of IP addresses called subnets
  3. Compute IP address / subnet inclusion
  4. Route packets based on the longest matching network address rule

Please complete the required exercises below, as well as any optional enrichment exercises that you wish to complete.

As you work through these exercises, please record your answers in a text file. When finished, submit your work via the git repository.

Make sure that the name of each person who worked on these exercises is listed in the first answer, and make sure you number each of your responses so it is easy to match your responses with each exercise.

Required Exercises

  1. As the answer to the first exercise, list the names of the people who worked together on this studio.

  2. In IP routing it is useful to subdivide the IP address space into logical subdivisions called subnets. An example of a subnet might be the set of all addresses from to, which specifies a subnet containing 256 addresses. Recall that an IPv4 address is a 32-bit number comprised of four 8-bit integers. Which bits are constant and which bits vary in the above subnet range?

  3. A compact way of specifying subnets (called CIDR notation or slash notation) is to specify the number of bits that are fixed and the number of bits that are allowed to vary. For example, specifies a subnet defined by the twelve most significant bits of the address. These twelve leftmost bits (0011 0011 0011) are called the network address and the remaining twenty bits are called the host identifier, meaning they specify a particular host in the subnet.

    Specify the subnet from Exercise 2 using CIDR notation.

  4. Write the network address and the host identifier, in binary, for the IP address

  5. Subnets are also how the IANA (Internet Assigned Numbers Authority) allocates blocks of IP addresses to businesses and organizations. St. Louis University has its own allocation. Give the CIDR notation for SLU's IPv4 allocation given on this webpage.

  6. How many bits are in SLU's host identifier? How many IP addresses have been assigned to SLU?

  7. Subnets are extremely useful for routing because they allow you to route packets to a whole subnet rather than to a specific computer. This way, a router in New York doesn't have to keep track of each individual computer in a subnet in Los Angeles. It only needs to keep track of how to route a packet to their aggregate network address. To make this kind of routing decision you need to be able to tell whether a desired IP address belongs to a subnet. Which of the IP addresses below belong to the subnet (Hint: You need to compare the binary representations of the network addresses, not the decimal.).


  8. Notice that a single IP address can match multiple network addresses. For example, the IP address matches as well as and Which of the following subnets match the IP address (Hint: You need to compare the binary representations of the network addresses, not the decimal.)

  9. As above, subnets are useful because they allow us to make routing decisions easily. Recall that a router makes routing decisions by comparing the destination IP address of a waiting packet with all of possible destinations in its routing table and selecting the "closest" matching destination. We can now specify exactly what is meant by finding the "closest" matching router table entry: the closest entry is the one with the longest matching network address. For example, the IP address matches both and Which subnet is the longer match?

  10. Suppose a router has the following routing table:

    Destination Interface Cost Ethernet0 300 Ethernet1 600 Ethernet2 1 Ethernet3 1 Ethernet5 1000

    Suppose some packets come into the router with the following destination IP addresses. Which interface are they sent out on? (Which router table entry has the longest matching network address?)


Optional Enrichment Exercises

  1. An alternative system to using CIDR addresses is to use a network mask. This system allows you to specify which individual bits of an IP address should be considered the network address rather than the host specifier. A network mask is given as a 32-bit number in IP address format, and each bit that is a one in the binary representation is considered part of the network address. For example, the CIDR address is equivalent to the address with a network mask of In this case, the network mask would be:

    11111111 11111111 00000000 00000000

    The network address approach is strictly more flexible and allows you to specify some truly complex routing rules. For example, the CIDR system is incapable of specifying the mask, which would give a mask of:

    11111111 00000000 11111111 00000000

    However, such network rules are typically not used in practice.