Tuesday, November 30, 2010

Lesson 31 - What is a Router?

We take a lot of things for granted. When it comes to technologies it is not necessarily the best idea. The point is to understand. That is why I am going to start my routing section with fundamentals. Knowing them will allow you to learn more advanced topics on your own later. Make sure you are familiar with my previous posts related to binary numbers and IP addressing before you read this and upcoming ones.

Probably the most appropriate question to start with would be ...

What is a router?
A router is a specialized computer which can connect multiple networks to allow exchange of packets between them. Since a router uses IP header information (layer 3 protocol data unit), to transmit the packets between networks, this ability makes it a layer 3 device. Like switches, routers build a special database which serves as the source of information on what to do with incoming packets. This database is formally called Routing Information Base (RIB). But most often people call it a routing table. How a router constructs a routing table and maintains information in it, will be the topics of quite a few upcoming posts.

A router is in many ways similar to a regular PC. It has RAM and ROM memory chips as well as CPU and motherboard etc. But instead of using hard drive, it uses a flash memory to store files such as the operating system (IOS). Also, what makes it distinct, the operating system and hardware are optimized for fast packet transmissions. Typically the router uses at least two interfaces but more often than not, it has a greater number of them. Cisco operating system is called Internetwork Operating System (IOS). The same name is given to OS used by many Cisco Catalyst switches. Although some of them may also use CatOS.

There is a great variety of interfaces routers can use. For instance, they can connect few Ethernet networks together, but also Ethernet with Wide Area Networks (WANs) such as ATM, Frame-Relay, X.25, ISDN, Broadband etc.

Router Functions
In order for the routers to connect multiple layer 3 networks together, they must be able to do the following:
  • Learn which networks/subnets are available
  • In case there are multiple paths, choose the the best one
  • Keep (routing table) must be up-to-date
  • Translate layer 2 headers (disparate network connections)
  • Keep loop-free paths
  • Make forwarding decisions based on layer 3 headers
Routing is primarily based on hop-by-hop paradigm. This means that if there are multiple routers in the path, a router must find the outbound interface and forward the packet to a next hop router. A router could not care less as to what happens to the packet after it has been expedited.

In order to find the outgoing interface an IP destination address of a packet and a routing table are used. The process whereby destination IP address is the key information to find the outbound interface for a packet is called destination-based routing. However, it is possible to influence that decision making process and choose other criteria such as source of IP transmission, size of the packet, importance of the packet in relation to others or some other parameters rather than destination IP address. When used it is referred to as the traffic engineering. For now though, I am going to focus in on the default behavior.

Before I describe the router's principles of operation, I must make sure we are on the same page with the fundamentals related to the traffic flow.

Let's recall what happens with the packets sent between computers residing in different networks. I will use a simple topology (pic. 1) to review a few facts. Please, get familiar with the picture below first. Pay a special attention to the three headers depicted and numbers in green circles. The numbers refer to the steps below. Of course, this is only a ten thousand foot view of what happens here. Before we jump into the deep water we need to warm up a bit by looking at the process from a high perspective.

Pic. 1 - Traffic Flow and Layer 2/layer 3 Encapsulation/De-encapsulation
Icons designed by: Andrzej Szoblik - http://www.newo.pl

The numbers in green circles mark the important points of the traffic sent from PC1 (left hand side) to the PC2 (on the right side of the picture).

In the explanation presented below I assume that SW1 and SW2 have populated their CAM tables (learned all MAC addresses on the appropriate ports). Here's how it goes.

Step1 
PC1 sends a packet destined to PC2. Since, PC1 has the IP address 192.168.1.1/24, it realizes that the first 24 bits of the destination IP address are different than its own (source: 192.168.1.1, destination: 192.168.3.1). Conclusion: PC2 is NOT in the same layer 3 network, so default gateway (192.168.1.254) must be used to forward the packet to PC2. Knowing it, the IP header is going to use:
  • Src IP = 192.168.1.1
  • Dst IP = 192.168.3.1
  • TTL = 32 (ttl is set by the application, here I use 32 as an example)
IP packet is encapsulation in Ethernet (layer 2) header in order to be put onto the wire. Ethernet header contains source MAC address of the sender, and destination MAC address of R1's F1/0 interface obtained from the computer's arp cache (if not found in the arp cache, arp request is sent):
  • Src MAC: 0000.1111.1111
  • Dst MAC: 0000.2222.2222
Step 2
SW1 receives the frame on its port F0/1. It locates the outbound port (f0/2) for destination 0000.2222.2222. It sends the frame out towards F1/0 port of R1. Neither of layer 2 or layer 3 headers presented in the pic. 1 change during this transmission (parameters depicted).

Step 3
R1 receives frame on F1/0 port. Layer 2 header is inspected by R1. Since the destination MAC address (0000.2222.2222) is the address of F1/0, R1 concludes it is the destination for the frame. Layer 2 header is removed and the content of the message (packet) is processed by the router. R1 processes IP header, reads the destination IP address (192.168.3.1) and compares it with the entries in its routing table trying to find the longest match. More on this in the upcoming post. Once the best path has been found, the routing table points to the outbound interface (F1/1) and the next-hop router's IP address (192.168.2.2) that should be used to expedite the packet.

Step 4
The packet is moved to F1/1 port and the TTL number is decremented by 1 (now TTL=31). Then, the packet is encapsulated in the layer 2 header.The following source and destination MAC addresses are used now:
  • Scr MAC: 0000.3333.3333
  • Dst MAC: 0000.44444.4444
The destination MAC address is obtained from R1's arp cache. If R1 does not know the MAC address for 192.168.2.2 (next-hop router), arp request is sent asking for its MAC address.

Step 5
R2 receives the frame on F1/0 port. It performs the same job R1 has done. It reads the destination MAC address. Since it is the recipient (0000.4444.4444), it dumps the layer 2 frame and processes IP header. It performs layer 3 lookup in its routing table and finds the outbound interface for destination 192.168.3.1. In our example it turns out that the destination network is connected directly to F1/1 interface. In such case, R2 checks arp cache for MAC address of the destination (192.168.3.1) if one is not found, arp request is sent (who's 192.16.8.3.1 ?, I need you MAC address!).

Step 6
The packet is moved to F1/1 interface and before it gets encapsulated, the TTL number is decremented by 1 (TTL=30). The packet is encapsulated in an Ethernet frame header using the following addresses:
  • Src MAC: 0000.5555.55555
  • Dst MAC: 0000.6666.66666
The frame is sent out F1/1 interface.

Step 7
SW2 receives the frame and finds the outbound interface for the MAC address: 0000.6666.6666 int its MAC address table. It is port is F0/2.

Step 8
The frame is sent out F0/2 towards PC2. Fields in the layer 2 and layer 3’s headers remain the same.

The above is just a quick review in case you've forgotten that.

The interesting bit for us now is the router's process of finding the outgoing interface and layer 2 addresses of the next hop device. I'm going to elaborate on this in my next post. Now, let me quickly present the routing table components that are essential in this traffic flow.

Pic. 2 - Routing Table Components.
Components of Routing Table:

  • C and S - point how a router obtained the information (C = connected, S=static route)
  • 192.168.3.0/24 - Example of prefix (destination network/subnet)
  • [1/0] - square brackets show two numbers. First (1) is Administrative Distance, second (0) is Metric
  • via 192.168.2. - the next-hop-router address
How router populates the routing table, what these terms in red mean and how router uses these parameters to pick the longest match and as a result of that the best path, are going to be the main topics of my next post.

Saturday, November 27, 2010

Lesson 30 - IPv4 Subnetting - Practice

In the previous post, I showed you three major rules used in calculating subnets. This knowledge can only be verified in practice though. Let me show you a few examples related to subnet calculations. I hope that looking at this topic from different angles is going to help you understand the concept better and feel confident when planning your IP addressing scheme. The first four questions are merely appetizers for a bigger dish: VLSM.

I am going to refer to my previous post's rules while answering the questions (rule 1, rule 2 and rule 3).

If you still do not remember the weights of all bits, you may consider using this little aid presented below (pic. 1) while calculating subnets, and converting binary network masks into decimal values.

Pic. 1- Subnet Calculation Aid.

This tool is useful before you remember all the weights from left to right and right to left.

Pic. 2 - Example of Subnet Binary-to-Decimal Conversion.

Question 1
Given the prefix 192.168.1.0/24, what should be the length of subnet mask allowing up to 9 subnets?

Answer 1
The address belongs to the class C and uses its default network mask. That leaves us with 8 bits to play with (the last byte). Before we change anything, our address and network mask converted into the binary notation look like shown below (pic. 3).

Pic. 3 - 192.168.1.0/24 in Binary.

In order to create 9 subnets we must extend the existing length of the network mask by 4 bits which allows up to 16 subnets (use calculation aid in pic. 1). If I tried to extend it by 3 bits only, the maximum subnets allowed would be only 8 subnets (rule 2 in lesson 29). So, I must use 4 bits and the result is: 192.168.1.0/28 (192.168.1.0 255.255.255.240).

Pic. 4 - The Answer to Question 1
Question 2
Given the host address 192.168.1.177/29, what are the subnet and broadcast addresses?

Answer 2
In order to determine the subnet and broadcast address of the subnet of this host address, we must look at the length of the network mask first. It is 29 bits (24+5). This tells us that the last byte of the address has 5 bits masked (subnet bits) and 3 bits unmasked (host bits). It is a good idea to look at the the last byte of the address (177) with its network mask using binary notation. Pic. 5 below shows you this clearly.

Pic. 5 - 192.168.1.177/29 in Binary.
Since we must determine the the subnet in which the host resides (177 = 10110001), the host portion of the prefix (host bits reside in the last byte) must all be set to '0'. The byte value with the host zeroed is the address of the subnet (rule 1 pkt.1 in lesson 29). This is the result:

Pic. 6 - Host Bits Zeroed = Subnet Address.

The second part of the question relates to the broadcast address of the subnet. As you remember, in order to obtain the broadcast address, you must put '1' on all host bits of the subnet/network. The subnet has already been determined (pic. 6), so let's put '1' on all bits of the host portion:
.10110111
.10110000 = 176 <- subnet address
..00000111 = 7 <- host bits set to '1'

In decimal it is: 176 + 7 = 183
The broadcast address is: 183.

The below picture illustrates it using binary numbers.

Pic. 7 - Host Bits Set to '1' = Broadcast Address.

Question 3
Given the  prefix 172.16.0.0/17, how many subnets can you create?

Answer3
This is a bit tricky isn't it? In order to answer this question, you don't need any calculator, paper or pen. You must trust the rule 2 in lesson 29. The address and its network mask (called prefix) converted into binary look like presented below:

Pic. 8 - The Number of Subnets for 172.16.0.0/17

As you see the number of bits we have extended the class B address is: 1. So, the number of subnets we can create with it is: 2 subnets, since this subnet bit can be either 1 or 0.

Pic. 9 - Questions 3 Answer

Question 4
What length of network mask would be the most optimal for router's point-to-point connection?

Answer 4
The key to this question is to understand that point-to-point connection needs only 2 host addresses (two points that are connected together). Knowing this, the rest is a piece of cake. We use rule 3 in lesson 29 to determine the length of the network mask that allows 2 host addresses. Check out the picture 10.

Pic. 10 - Calculating Point-to-Point Connection Host Addresses.
If you count ones above the optimal network mask for point-to-point connection is /30. The decimal value is: 255.255.255.252.

Question 5 - Variable Length Subnet Masking (VLSM)
It's time for a big one. Given the topology (pic. 11), calculate IP addresses for each subnet trying to optimize them according the host address requirements. The IP address you should use to create subnets is: 192.168.1.0/24. The number of host addresses in the subnets are as follows:
Subnet 1 = 46 host addresses
Subnet 2 = 16 host addresses
Subnet 3 = 10 host addresses
Subnet 4 = 2 host addresses
Subnet 5 = 2 host addresses

Pic. 11 - VLSM Topology.

Icons designed by: Andrzej Szoblik - http://www.newo.pl

As always, if you know the rules and the method, it is going to be easy thing to do. The rules have been discussed in lesson 29, so let me go about this kind of task now.


NOTICE!
If your design looks similar to mine (optimizing addresses to the number of host required) you must start the calculation with the largest number of host addresses requirement and work your way down to the least number of host addresses.


This is one of the many methods available. It helps quickly calculate all subnet ranges without using calculator (pen and a piece of paper should do).

Step 1
Determine the length of the network mask for each subnet in question. Keep in mind we focus in on the last byte of IP address 192.168.1.0 (8 bits).
The first three bytes do not change!

Subnet 1 = 46 Host Addresses

In order to allocate 46 addresses we must use 6 host bits. Why? 5 bits will not be enough as 2 raised to the power of 5 is 32. Also, we must decrement two addresses for subnet and broadcast addresses. So using 5 bits would give you only 30 host addresses. Here we go with 6 bits then:

Pic. 12 - Subnet 1 in Binary.
Subnet 2 = 16 Host Addresses

We must repeat the same math for the remaining subnets.  How many host bits to allocate for 16 hosts (subnet 2)? We must use 5 bits. In case we wanted to use only 4 host bits, the maximum number of hosts is 14 (16 - 2).
Pic. 13 - Subnet 2 in Binary
Subnet 3 = 10 Host Addresses

We continue using the same logic.

Pic. 14 - Subnet 3 in Binary.
 Subnet 4 and 5 = 2 Host Addresses Each

On point-to-point links only 2 host addresses area needed. The most optimal network mask is /30 (30 bits).

Pic. 15 - Subnet 4 and 5 in Binary.
Step 2
Now, that we know the length of network mask for each subnet, we can start calculating the IP address ranges. 

The subnet 1 address is: 192.168.1.0/26.

The value of the lowest bit in the network mask is going to be our increment used to calculate the next available subnet address. With /26 the increment value is 64 (pic. 16).
So, if we add the increment to the last byte, we get the number of our next available subnet address:
192.168.1.0 + 64 = 192.168.1.64.

From there, this next subnet address (value) - 1 is the broadcast of our current subnet:
192.168.1.64 - 1 = 192.168.1.63 (current broadcast address)

Current subnet value + 1 = the first host address:
192.168.1.0 + 1 = 192.168.1.1 (first host address of current subnet)

Current broadcast address - 1 = the last host's address:
192.168.1.63 - 1 = 192.168.1.62 (last host address of current subnet).

Look at the below pictures which illustrate this method.

Pic. 16 - Subnet 1 - IP addresses


Pic. 17 - Subnet 2 - IP addresses

Pic. 18 - Subnet 3 - IP addresses

 Pic. 19 - Subnet 4 - IP addresses

Pic. 20 - Subnet 5 - IP addresses

Now, we're ready to start talking about routing. In my next post, I will talk about a router, its functions,and  basic operation. From there, we'll start exploring routing protocols.

Wednesday, November 24, 2010

Lesson 29 - IPv4 Subnetting - The Rules

Now, that we have already learned a few things such as conversions between binary and decimal, how to recognize classes of IP addresses based on the 'first octet rule', and what is the purpose of the network mask, we can tackle IP subnetting.
A natural (default) network mask is used with class C of IP addresses quite often. But it is very uncommon to use class A and class B IP addresses with their natural netmask. They are often sub-netted (broken down into multiple smaller networks). This is accomplished by increasing the length of the default (natural) network mask.


 Incidently, the network IP addresses that use their natural (default) network mask are called Classful Networks.


But why do we create subnets to begin with?

There are many reasons why we decide to use subnets rather than classful networks. But the most important is that we want to use IP addresses efficiently since they are a scarce resource these days.

Imagine that you have a huge network to support. It uses class B network address: 172.16.0.0/16. Since the number of bits in the host portion of this address is 16 (the last two bytes are not masked), we can place 65534 hosts in a single network. Even if you used 2000 hosts still it is too much to keep them in one broadcast domain. Can you imagine that many computers sending and receiving broadcasts such as ARP requests? Well, I can imagine that, but it does not mean its efficient. In fact, broadcast traffic would pretty much kill this network. Even with thousand computers that would be way too much broadcast traffic to receive.

If we divide this huge network into multiple subnets with fewer hosts per subnet, we improve the efficiency of the system. A router will connect those subnets to allow unicast communication, but broadcasts will not be propagated between subnets as routers do not forward them. For instance: 172.16.1.0/24 subnet allows only 254 hosts in it. The broadcast will be propagated between this number of hosts rather than among one or two thousands of hosts.

Another reason for using subnets is about relates to public IP addresses that are leased to customers. ISPs do not easily give out whole classes of IP addresses (classful) to companies but rather portions of these (subnets).

Other reasons may be related to security of your hosts. Network divided into chunks with routers as gateways, give you more control as to who can 'talk' to whom.

I use terms such as broadcast or unicast. If you are not sure what these terms mean, let me present brief definitions.

Transmissions:
  • Unicast - a single source host sending to a single destination host.
    Example: Src=192.168.1.1, Dst=192.168.1.2
  • Broadcast - a single source host sending to all hosts in the network/subnet. Example: Src=192.168.1.1, Dst=192.168.1.255 (more on this address later in the post)
  • Multicast - a single host sending to a single group of hosts (IP class D)
    Example: Src=192.168.1.1, Dst=224.10.10.10.
There are three things I would like you to remember before we delve into subnetting.

Rule 1
  1. If the host bits in a given IP address are all set to '0', this is the network or subnet address.
  2. If the host bits in a given IP address are all set to '1', this is the broadcast address (all hosts in the subnet/network are destination).
Rule 2
The formula used to calculate the number of available subnets given the specific length of network mask.

Pic. 1 - Number of Subnet Calculation  - Formula.

Rule 3
The formula used to calculate the number of available hosts per subnet or network given the specific network mask.

Pic. 2 - Number of Hosts Per Network/ Subnet - Formula.

Before we start using the above rules, let me show you a few examples of network, subnet and broadcast addresses based on what we have discussed in the last three posts including this one. If you do not remember the 'first octet rule', which determines the class and the default network mask of an IP address, use the following table as the reference. The number ranges of the first byte determine the classes as shown in pic. 3.

Pic. 3 - Classful Address Table.

Pic. 4 - Network (classful) Addresses and Subnet Addresses (classless).

In order to determine the number of subnet bits to use them as the exponent in the above formula (pic. 1), you must first know what is the default network mask of the IP address according to its class (pic. 3). Then, you must count the bits that were added to this default network mask. These bits allow a number of subnets to be created as per formula in pic. 1. Check out the below example.

Pic. 5 - Number of Subnet Bits (Example).
In the example (pic. 5), IP address belongs to class C since the first byte value is 192 (compare it with pic. 3). Class C uses first three bytes (24 bits) to denote the network portion of the address. Today we can say that its default network mask has the length of 24 bits (255.255.255.0). Since our network mask length is /28, we have extended the default network mask by 4 bits (bits in the green color). Thus, we get 4 subnet bits that must be used in our formula presented in pic. 1.

Pic. 6 - Number of Subnets Available - Calculation.
Using the same example: 192.168.1.0/28, how many host addresses per subnet can we use?

Pic. 5 shows us that with /28 we have 4 bits left for host (total number of bits = 32). In order to calculate the available number of host addresses we must resort to formula presented in pic. 2.

Pic. 7 - Number of Hosts Available - Calculation.
Make sure you understand how the three rules presented here work. In my next post, I'm going to show you how to use them to calculate the subnets based on different criteria such as:

  • Number of subnets per IP address
  • Number of hosts required in the subnet
  • Number of desired host per subnet - Variable Length Subnet Masking (VLSM)

Sunday, November 21, 2010

Lesson 28 - IPv4 Address Dissected - Part 2

In my previous post I have talked about the hierarchy in IPv4 address. It is the network mask that tell us which bits form a network address and which ones denote the host in the network. But there is more to it ...

You already know that IP address and its network mask create a unique layer 3 identifier of a host. This allows devices to communicate. When a computer sends a packet, it will put the address of the recipient in the IP header as the destination. It also puts its own address (sender), so the recipient knows who sent the packet and to whom a reply should be sent.

After reading my previous post it may seem clear what a network and a host in the network are. But you may still ask: "What is a network anyway?". As strange as it sounds, the answer to the question may not be as simple as one might think.

We tend to divide our networks into multiple pieces that are uniquely identified with the network portion of the address (masked by network mask bits set to 1). Individual hosts placed in those networks will also have unique host portion of the IP address (network mask bits set to 0). They are unique in their network.

Why do we break down the company's infrastructure into multiple chunks called networks?

There are many reasons we do it.  Larger networks are harder to maintain and become very inefficient as the hosts receive too many broadcast transmissions (broadcast=one packet to everyone). Also, it is easier to control traffic and tighten the security when dealing with multiple networks rather than doing so in one single organism. So, we separate hosts using layer 3 devices called routers and address them uniquely, thus creating multiple interconnected networks. The routers that connect networks become the gateways between them allowing unicast communication (one-to-one). At the same time they do not allow broadcast traffic (one-to-everyone) to go through. They also are equipped with many mechanisms to control the traffic traversing through them.

How we divide our system into multiple networks may be depended on numerous factors. For instance, a network in the building can be divided based on the floors. First floor is the first network, second floor is the second network etc. Other division could be made based on the departments in the corporation. HR is going to be one network, Legal Dept. another etc. Either way, computers will belong to one of these networks, but all of them together will still belong to the same company.

So, what is a network? A network is a group of devices that share the same network portion of the address. That portion is dictated by the length of the network mask. These bits mask the corresponding bits in the address. But this you already know. However, there are a few more things you need to know.

Consider this picture.

Pic. 1 - IP Networks.
Icons designed by: Andrzej Szoblik - http://www.newo.pl

What do we see in the picture?

In the middle sits a layer 3 device called a router (R1). I will devote a whole post on what it is and what its functions are. Meanwhile, let's carry on with our description.

The router (R1) connects two different networks. It becomes the gateway between them. This means it allows communication between them (unicast by default). The two networks in the picture have the following addresses:
  1. The network on the left-hand side has the address of 192.168.1.0/24.
  2. The network on the right-hand side has the address of 192.168.2.0/24.
The switches (SW1 and SW2) are transparent in terms of layer 3 communication. Remember? They are layer 2 devices, and do not have a clue what IP addresses are.

Finally we have two computers. PC1 belongs to the network 192.168.1.0/24, PC2 belongs to the network 192.168.2.0/24. Both have the same host identifier in the last byte of their IP address: 1. But their network portion of IP address is different. As a result of that the belong to two different networks. Just like two Mr. Smiths who live in two different houses on two different streets of the same town.

PC1: 192.168.1.1/24
PC2: 192.168.2.1/24

Have you noticed that the third octed (from the left) has different number? That makes the network portions of these two addresses unique.

What does this /24 mean in the address?

As you already know the netmask separates a network from a host portion of the address. Both IP addresses and their network mask are presented in the decimal notation with the length of network mask (/24). Yes, the shortcut /24 means, that the network mask is twenty four bits in length. This in turn, means that the first twenty four bits of the IP address is the network portion. The remaing eight bits are the host address in the network. Check it out below.

Pic. 2 - PC1 address with the netmask 24 bits (/24).



Looking at the binary, we see that /24 = 255.255.255.0.
If we convert 255.255.255.0 into binary we get twenty four 1s in the network mask, giving us three bytes of the network address. The remaining eight bits in the network mask are all 0s. This way, the last byte (8 bits) becomes the host identifier int the network 192.168.1.0.

Interestingly enough, many moons ago, there were no networks mask in use. So, how on Earth, did the devices know which bits of IP address were network bits and which were the host bits? The designers of IP addresses divided IP addresses into five different classes. The first byte of any IP address (on the left) determined which class an IP belonged to and how many bits of the address were network bits. Today, this is known as the first octet rule.

IP Address Classes
The value of the first byte in the IP address determines its class (the first byte on the left-hand side).
  • Class A - values 0 through 127
  • Class B - values 128 through 191
  • Class C - values 192 through 223
  • Class D - (multicast) - values 224 through 239
  • Class E - (experimental) - values 240 through 255
This stems from the fact that some assumptions have been made regarding the most significant bits in the first octet (byte). The below table shows (in red) these bit reservations. They are fixed in the class and cannot be changed.

Pic. 3 - IP Address Classes.
As the result of such reservations in class A, class B and class C, one two and three bits respectively, the decimal values of the first octet are as follows (pic. 4).

Pic. 4 - IP Adress Classes and First Octet Rule.

This way, devices could easily determine which class of IP address the deal with by looking at its first byte (Pic. 4). Knowing which class the IP address belonged to help them determine which bits described network address, and which bits denoted a host in the network (Pic. 3 highlighted in green).

Fast forward to the present day. We still use the concept of IP address classes. And as such we refer to the so called: natural network mask (length).
  • Class A - Natural network mask length = 8 bits (/8) or, 255.0.0.0
  • Class B - Natural network mask length = 16 bits (/16) or, 255.255.0.0
  • Class C - Natural network mask length = 24bits (/24) or, 255.255.255.0
I would like to finish this post with one last observation. If your IP address uses the natural network mask length given the class (A, B, or C), we call this address a network address.

If your IP address uses the network mask length longer than the natural network mask used by this class, we call this IP address a subnet.

In my next post, I will show you how you can create subnets and how to calculate those given the host requirements.

Saturday, November 13, 2010

Lesson 27 - IPv4 Address Dissected - Part 1

If you already feel comfortable with binary-to-decimal and decimal-to-binary conversions you're up to this post's challenge: learning more about IP version 4 address (IPv4). If you need to brush upon the numeral conversions, check my previous post.

In one of the earlier posts on TCP/IP traffic flow, I briefly described the importance of the addresses. In order for devices to communicate they must be uniquely identified in the network after all. There are typically three such identifiers we use to distinguish between devices:
  1. Names - These are used by humans. Applications use addresses not names. Hence, DNS services out there (DNS service is used to resolve names-to-ip, and ip-to-names).
  2. Layer 3 addresses - logical and hierarchical unique identifiers of devices in the network. All layer 3 protocols such as IPX, Apple-Talk, IP etc. use different forms of layer 3 addresses. 
  3. Layer 2 addresses - flat and most often fixed identifiers of devices (see lesson 6).
DNS Names
Names are used to simplify communication between devices for people. Instead of typing something like this in your web browser: http://72.163.4.161/, which will open the Cisco web server's main page, you prefer to type something like that: http://www.cisco.com/, don't you? If you do the latter, before your web browser sends the request to the Cisco's web server, it will need to ask your local DNS server about the IP address that is associated with the name www.cisco.com. 

Layer 2 addresses 
Since the communication between computers is loosely based on well known OSI model (TCP/IP model is based on it which I described in lesson 4), all upper layers are ultimately encapsulated in a layer 2 header which uses flat form of the address. Such addresses are Ethernet MAC addresses, Frame-Relay DLCI numbers, ATM VCI/VPI pair of numbers etc. What these are depends on what layer 2 technology you use.

Layer 3 addresses
Layer 3 addresses are logical and hierarchical. This post is about IP addresses, but keep in mind that in the past we used to use other routed protocols as well (such as Apple-Talk, IPX and others). These other protocols also used layer 3 addresses that were logical and hierarchical.

IP address (which in OSI terminology is an example of layer 3 address ) is logical. This means, that you can easily change it either manually or using dynamic address assignment (DHCP) service. Consider your private laptop that you use at home. It, most likely, gets an IP address from the DHCP server configured on your broadband router. Then, the following day you take it to work with you. The moment you hook it up to your corporate network its current IP address will be replaced by a new one provided by the corporate DHCP server. It is almost for sure going to be different than IP address your computer uses at home. So the word: logical, describes the volatile nature of the address. The same device can use a different layer 3 address (identifier in the network) depending which network it resides on.

IP address is hierarchical. It is a bit similar to a telephone number as it has a structure. In telephony we use similar concept of hierarchy. Consider this phone number:
001 201 555 1234.

The structure of this phone number has the hierarchy which looks as follows:
00 - the number identifying an international call
1 - the prefix denoting country. Here: it is USA.
201 - number denoting the state in the US. Here: it is New Jersey.
555 - number of the telephone exchange in New Jersey (here it is a fictitious one)
1234 - number of the subscriber connected to this fictitious exchange. 

The reason I show you this, is that what seems to be a simple and flat 13-digit phone number, in fact has a hierarchy built in it. The numbers carry special meaning. The same is true about layer 3 addresses in computer networks.

IP address structure consists of two components:
  1. Network or subnet address (identifier).
  2. Host address (identifier) in the network or subnet.
Let us dissect both components using your computer's IP address as an example. Open the command line window and type in the following command:

in Microsoft Windows:
c:\ipconfig

in Linux/Unix/Mac OS:
$ifconfig eth0

Look at my computer's address below.

Pic. 1 - Output of 'ifconfig eth0' command.

Can you find MAC address, IP address and Netmask in the above output?

MAC address: 00:1e:4f:b0:b2:fc
IP address: 192.168.1.2
Netmask: 255.255.255.0

An IP address uses four numbers and dots as the delimiter. Each number is a one byte number which means that it must be in the range of 0 through 255 using decimal notation.

IP address uses another four byte number that follows it called: network mask (aka netmask). It is the netmask that creates the hierarchy in the IP address. It separates the bits in the address to tell us which ones denote the address of the network/subnet and which ones denote the host address in the network/subnet. In order to see that, check my IP address in the pic. 2 below. The first three bytes (24 bits) denote the address of the network, and the remaining byte (8 bits) denotes the host address in the network.

Pic. 2 - IP address in decimal notation.

In order to actually see the hierarchy presented in pic. 2, let us convert the IP address into binary first.

Pic. 3 - IP address decimal-to-binary conversion.

Now, convert the decimal netmask we use in the example (255.255.255.0) into its binary equivalent. What is it going to be?

 Pic. 4 - Network mask decimal-to-binary conversion.


Network mask bits correspond to the IP address bits. The bits in the IP address which are masked by the network mask bits (1s) denote the network portion of the address. The bits in the IP address that are not masked (corresponding bits in the netmask are 0s), are denoting the host address in the network. Let us combine the IP address bits with the netmask bits to see the hierarchy now.

Pic. 5 - IP address and the network mask create hierarchy.


Clearly, the first three bytes (192.168.1) in the IP address are masked (255.255.255). Those twenty four bits are the NETWORK bits, the remaining eight bits in the address (2) are not masked (netmask bits are all 0) and become the HOST bits in the address.

The hierarchy in my computer's IP address could be depicted like this:

Pic. 6 - IP address Hierarchy.


There is a bit more we need to know about IP addresses.

In my next post I will continue on explaining what IP address classes are and how they are used today. Also, I will describe the concept of network and subnet and the difference between them. I will finish IP address description by telling you about certain reservations in the IP address range we must be aware of. This and the next post will be the pre-requisites for the upcoming lesson about calculating subnets.

Lesson 26 - Binary World

The routing world awaits. But before we plunge into its depths, it is imperative that we become fluent with conversions between decimal and binary numeral systems. Why? Because all electronic devices such as our beloved computers and routers use binary numbers. On the other hand, we humans tend to use decimal notations almost all the time.

Believe it or not but the binary numeral system is easier to understand than the decimal one. But our problem is that we have been using the decimal notation for so long that looking at anything different feels very awkward.

It is good to know that all numeral systems (binary, octal, decimal, hexadecimal, the-one-you-may-want-to-create) are based on the same foundations. There are two major components of a numeral system: the base and the exponent.

Pic. 1 - Numeral System Components - The Formula.


I almost hear your thought: 'Eh... what?' Fear not. It's easy to understand if you remember the math at the elementary level.

The base in the above formula is determined based on how many digits (or characters) we use to denote the number. Consider the decimal system. We have exactly 10 digits to express the volume: 0,1,2,3,4,5,6,7,8,9. So, the in decimal numeral system the base = 10 (ten digits available). What happens when we have more of something than 9?

It is simple we engage a new column of numbers on the left and zero the number on the right: 10. This way we get ten. The first column denotes the number of 10s and the next column, denotes the units. As soon as we run out of numbers in the unit columns, we increase the number in the columns of tens. For instance: 17, 18, 19... 20.

What happens when we run out of the number of the column of tens? We add one more column on the left, which is the columns of 100s and zero all other columns on the right. For instance: 97, 98, 99... 100.

We know that in the four column number: 1048 the first column (1) on the left denotes thousands, the next to the right (0) denotes hundreds, the one next to it (4) denotes tens, and the last one (8) describes units. The column in each and every numeral system has the weight.

Check the picture below to see this in more detail.

Pic. 2 - Decimal Numbers - Formula.


Using the formula you calculate the numbers in decimal as shown in the next picture (pic. 3). Each number in the column must be multiplied by the corresponding weight of the column. These in turn, must be added together to give you the number. Pic. 3 shows that in more detail. Make sure that you understand it before you proceed with your reading.

Pic. 3 - Example of Decimal Numbers According to the Formula.
In exact same way we create others such as the binary numeral system. Here, our base is going to use only two digits: 1 or 0 called bits. Thus, our base = 2 (only two digits available). Since, we most often cluster 8 bits together to form a byte, our colums and weights are going to look as in the picture below (pic. 4).

Pic. 4 - Binary Numbers - Formula.



NOTICE!
Cisco expects their engineers to be able to do the binary-to-decimal and decimal-to-binary conversions WITHOUT using a calculator (using a paper and pen only).


Binary-to-Decimal Conversion

In order to convert the binary number to its decimal equivalent, you must follow the exact same rules explained for decimal system. You multiply the number in the column by its weight in every columns. The products of these multiplications must be added together.Take a look at the example in the pic. 5.

Pic. 5 - Examples of Binary-to-Decimal Conversion.


In order to practice those try to quickly convert the following binary to decimal (DO NOT USE A CALCULATOR):
Ex1: 11011010 (calculated above)
Ex2: 10011101 (calculated above)
Ex3: 11001011
Ex4: 00100101
Ex5: 01010101
Ex6: 11111010
Ex7: 01101101.

It should not take you more than a few seconds per example. Check your results using a calculator.

When it comes to opposite conversion it is a bit more difficult, but still at the elementary math level.

Decimal-to-Binary Conversion
The best way to learn how to do the conversion is actually do it and analyse every step of the way.

Example1: the decimal value of 172, to be converted into the binary.

The following table is going to come in handy.

Pic. 6 - Decimal-to-Binary Conversion.




Step 1
Find the closest weight value in the binary table that does NOT exceed the value you convert.

In the example1, the closest weight is: 128. The weight of the next column (here, non-existent column 9) would exceed the value of 172, since the weight of it is 256.


Step 2
In our handy table, write in ‘1’ in the column you have chosen.

Pic. 7 - Decimal-to-Binary Conversion.





Step 3
From the initial decimal number take away the weight you have used (the ‘1’ you put in the table takes away the weight from the number you are converting).

In the example1, the decimal number we have is: 172 and the weight we just used by putting a ‘1’ in our table is: 128. So, our calculation looks like the one below:

172 – 128 = 44


Step 4
Check if the number you have left (in our example the value left is: 44) is larger or smaller than the weight of the next column on the right-hand side in our table.


a) If the number you have left is larger than the weight in the next column to the right, put in ‘1’ in the next column and subtract its weight from the number you have left.

b) If the number you have left is smaller than the weight in the next column to the right, put in ‘0’ in the next column and perform the same check against the next column (step 4a). You have to do it until the check in step 4a is true.

In the example1, the value we have left is: 44. We check it against the weight in the next column on the right. The number (44) is smaller than the weight in the next column to the right (64). Since 44 < 64, we follow the instructions in the step 4b.

Pic. 8 - Decimal-to-Binary Conversion.


The next check against step 4a is true! Since 44 > 32, we put in a ‘1’ in the next column and take away the weight (32) from the number we have left (44).

Pic. 9 - Decimal-to-Binary Conversion.


44 – 32 = 12


We go back to the step 4.

The number we are left with (12) is smaller than the weight of the next column to the right (16). Since 12 < 16, we proceed to the step 4b.

Pic. 10 - Decimal-to-Binary Conversion.



The next check against step 4a is true! Because 12 > 8 we put in a ‘1’ in the next available column on the right and take away its weight (8) from the number we are left with now (12).

Pic. 11 - Decimal-to-Binary Conversion.


12 - 8 = 4

The difference is: 4. I hope you already know what is going to happen. Step 4a is true, so we put in a ‘1’ in the column and take away the weight from the number.

Pic. 12 - Decimal-to-Binary Conversion.


4 - 4 = 0 

The difference now reaches 0, so we fill in the remaining columns with 0.

Pic. 13 - Decimal-to-Binary Conversion.


In order to practice those try to quickly convert the following binary to decimal (DO NOT USE A CALCULATOR):
Ex1: 172 (calculated above)
Ex2: 67
Ex3: 124
Ex4: 168
Ex5: 215
Ex6: 237

It should not take you more than a few seconds per example. Check your results using a calculator.

Understanding and fluency with the conversion is the pre-requisite to calculating IP subnets, maximizing the addresses per subnets etc.

In my next post, we will take a look at IP address and play with subnet calculations.

Cisco Is Easy - Main

  Cisco Basics (CCNA level)  Lessons: Watch Video Tutorials on Youtube 01 - Connecting to Cisco Console Port with MINICOM 02 - Navigatin...