Friday, January 13, 2023

All about IP address

When we mail a post to someone, for the post to reach the intended person properly it needs an address to reach. An address will have the house number, area name, city and its code, etc. Similarly in a TCP/IP network for the the datagram to reach intended device, it requires an address. These addresses are called IP address.

IP address:
IP address is a 32 bit number, which in turn grouped as 4 octet numbers (4 bytes) e.g., 192.168.0.21. The binary of the example IP will be 11000000101010000000000000010101. After grouping as octets the binary will be 11000000.10101000.00000000.00010101. Each octet can hold a number from 0 to 255. These IP act as the identification for each machine/ device in the network. Again the IP number has two parts in it. First part belongs to the network and called as network address, second belongs to the device and called as host address. IP addresses are assigned as per the classes, explanation on classes are below. The network IP and host IP plays a vital role in identifying the class.

IP address 255.255.255.255 should not be used as host address as it is used for broadcast purpose.

Subnet mask:
Subnet mask is too a 4 octet number same as IP address. By setting all the host address bits as 0s and network bits as 1s the subnet mask separates the network address and device address from the given IP. Subnet mask especially helpful in sub-networking the larger network.

Network:
The networks can be of different size. Collection of networks interconnected between each other is called wide area network (WAN). Each network can have sub-networks. The network can be connected as per following network topologies,

1) Bus topology
2) Ring topology
3) Mesh topology
4) Tree topology
5) Star topology
6) Hybrid topology

Each topology has its own advantage and disadvantages. Explanation on the network topology will be for future.

Class:
Addressing method of the network is based on size of the network and they are classified as classes. There are five classes namely class A, class B, class C, class D and class E. Class D and E are reserved for multicast and research purposes respectively. Normal networks have to be addressed based on class A, B and C.

Class A is for a larger network which will host large number of systems. Here first octet of the IP address is the network IP and remaining three octets are host IP. The first bit of first octet in this class should be always 0 and remaining seven bits can be used for addressing. Example, consider IP address 75.168.210.145. In the above IP '102' is the network address and '168.212.145' is the host address. Subnet mask for this class is 255.0.0.0.

Class A address from 127.0.0.1 to 127.255.255.255 cannot be used by any devices as it is reserved for loopback and diagnostic functions.

This class can have 126 networks and 16777214 hosts.

Class B is for network that are not too large and not too small. Class B uses First two octets (First 16 bits) as network IP and remaining two octets as host IP. The higher order bits, i.e., first two bits of the first octet should be always 10 and remaining bits are custom. The network IP should be within the range of 128.000-191.255. In the IP 141.215.10.3, '141.215' will be considered as network IP and '10.3' will be considered as host IP. Subnet for this class is 255.255.0.0.

Class B can have 16384 networks and 65534 hosts.

Class C is for smaller network. This class can host maximum of 254 devices per network and have 2097152 networks. First three octets of the IP is the network IP and last octet is the host IP. The first octet of the IP should be between 192 to 223 since the first three bits should be always 110. Here the subnet mask will be 255.255.255.0.

Class D is reserved for multicast purpose. First four bits should be 1110, this makes the IP address range from 224.0.0.0 to 239.255.255.255.

Class E is reserved for experimental and research purpose. First four bits should be always 1111 and the IP ranges from 240.0.0.0 to 255.255.255.254.

Special address:
169.254.0.0 to 169.254.0.16 link local address
127.0.0.0 to 127.0.0.8 loopback address
0.0.0.0 to 0.0.0.8 used communicate within the current network
255.255.255.255 used for network broadcast

Summarizing the topic, IP address are the unique address for the device to communicate with other device in the network. Subnet mask are used to differentiate network address and host address from a given IP address. There are six types of network topologies (explanation of these topologies will be discussed later). Also there are five classes of IP and addressing is done based on the class.

Saturday, December 31, 2022

OSI Model

As an automation engineer it is important to know about the industrial communication protocols. When I wanted to learn protocols and networking I ended up reading about OSI model and this is the best starting point. Whoever wants to learn basic networking should end up learning the OSI model which we have overlooked during engineering course. OSI model was developed by ISO to standardize how devices can communicate data in a network. In general all text books shows below Fig(1) to explain the model, but I found it difficult to associate it with real time usage. So I am compiling from various sources which I read and will try to explain as per my understanding to fit the model with practical world. If any mistakes are there, I welcome healthy discussions and comments to correct what I have written.

Fig(1). OSI model

When a device transmits data, it is broken in to pieces and wrapped with additional data before transmitted in to the network. This will help the device on receiving end to reconstruct the message or data and process it accordingly. Each layer of the OSI model contributes at various stages. Layer wise explanation as below.

Application layer:
This layer is the direct interface between the user and network. All the protocols such as HTTP, FTP, DNS, etc. operates in this level. Example when an URL is requested from address bar of the browser, the request is converted as a http/ https request and that request message is sent to next layer. On the other end of the network the Application will interpret the request and responds accordingly.

Data in this layer is called message.

Presentation layer:
This layer is a translation layer. It performs encoding/ decoding/ compressing the application layer data before sending in to the network. On receiving end it will make meaning full message out of the data it received from below layers. This message is further displayed or processed by the application layer.

Data in this layer is called message.

Session layer:
When a device tries to connect with another device a session is created and all transaction happen between the devices will be through the corresponding session. Windows uses socket method (winsock) to establish this session. First a open connection request is sent by client. Then server sends an connection acceptance reply. And to finish connection an acknowledgment is sent again by client. If a session breaks a reset message is sent and synchronization happens again. This is the layer which manages the connectivity between the devices.

Data in this layer is called message.

Transport layer:
There is limitation on how much data can be sent over a packet, hence this layer will break the message sent by presentation layer in to pieces called segments. To identify the segment's position in the message, a sequential number will be attached with the message. On receiving end, this layer will rearrange the frames in to a complete message using the segment ID so that the presentation layer can process it. If the received data are incorrect or missing any segment, it will request a resend. If server fails to receive the acknowledgement, it will transmit the data again.

TCP and UDP operates here through ports. Every transaction happens through ports. Example TCP operates using server/ client model. The device which initiates the connectivity is called client (master) and which are being connected with are called server (slave). Server can't initiate any communication and will serve only the query sent by client. This layer will add a TCP header to the message which comprises details of source and destination port, data checksum, message length, segment number and acknowledgement number. The data correctness is checked with the help of checksum.

Data in this layer is called segment.

Network layer:
This is the layer actually responsible for routing the packets to the intended device. On receiving a packet this layer will filter and decide whether the packet is intended for that particular device, if not the packet is dropped. To decide this, the destination IP address in the packet is checked. Protocols such as ARP, RARP, IP, etc operates in this layer. The segments from the previous layer are attached with an IP header and sent out as packets. The IP header will have details such as source and destination IP address, version of the IP used (IPv4 or IPv6), length of the header, length of the actual packet, type of protocol, header checksum and actual data. When it comes for how IP addressing works, lot of other details such as subnet mask, IP class, etc comes in. Those are for other topic.

Data in this layer is called packet.

Data link layer:
Data link layer work based on actual device address (kind of permanent unique address) called MAC address. MAC address is entirely different from IP address. The IP address is a 32 bit - 4 octet number. It changes whenever the device connects to a network. But the MAC address is a permanent one and assigned by the device manufacturer. Its a 48 bit address with first 3 bytes representing manufacturer number and last 3 bytes represent that device number.

Same like network layer, this layer also accepts the frames to be processed if the frame is relevant to that particular device. Only difference is network layer uses IP address but data link layer used MAC address to filter the packets.

While receiving the frame, the frame is filtered and then the data link header is removed before sending to the network layer. Similarly while sending the packet the data link layer header is added to the packet and sent out to the network. The header have details such as source and destination MAC address. At the end of the frame a CRC checksum is attached.

Data in this layer is called frame.

Physical layer:
Physical layer is the physical medium over which the device is connected. The physical mediums can be CAT-6 cable, fiber optic cable, etc.

Data in this layer are bits.

Summary:
The OSI model is just a guideline to follow. When it comes for practical world the difference between the layers become very thin and neglected. As seen in the below Fig(2), the differentiation between application layer, presentation layer and session layer were neglected and merged. In TCP/IP model these three layers are collectively called as application layer. Similarly the datalink layer and physical layer are merged as network access layer.

Fig(2)

While sending a message to network, every layer adds a header and checksum so that it will be helpful for the receiving device to process the packet. Similarly on receiving the packets respective layers removes the associated header before sending to the next layer. Refer below fig(3) for better understanding a pictorial representation of data flow from top application layer to bottom physical layer.

Fig(3). Data flow through layers

Tuesday, December 27, 2022

Intro

I would like to start by saying why am I even writing this blog. According to me completion of a learning process is documenting of what we learnt. All are not gifted with a great memory like 'Sheldon Cooper', especially me 😄. As an absent minded person this is a must for me more than anyone else. I am starting this blog for my reference. Though this have been given to me as an assignment 😅, I would like to use this opportunity to document whichever I read and learn.

Another major reason to hold up blogging is to improve my English language through this. I used to be the favorite student of all my English masters, even one among them was a school principal. But my language proficiency went downhill since I started my career. Trust me most of the engineers are bad with their English.

As my profession is technical oriented, most of my entries will be technical obviously. Some of the entries may be non technical but still hope it will be useful. Often I will be covering topics such as microcontroller, industrial automation and networking. Apart from technical I shall be posting about my views on Indian and world politics, little of economics and Marvel/DC comics.

Expect soon from me with new topics.

All about IP address

When we mail a post to someone, for the post to reach the intended person properly it needs an address to reach. An address will have the ho...