Daily Learning: Computer Networks – Casting & Subnet & Subnet Mask

Casting

Sending some data from one host to another host is called casting. There are three type of casting –

  1. Unicast – When we are sending message from one host to one host. The packet consist of | data | Source Address | Destination Address |
  2. Broadcasting –
    1. Limited Broadcasting – When a host want to send a packet to everyone in the same network then it use Limited Broadcasting. The packet consist of | data | Source Address | 255.255.255.255 |
    2. Direct Broadcasting – When we are sending a message from one host of one network to all the host of other network then we use Directed Broadcasting. The packet consist of | data | Source Address | 20.255.255.255 |
  3. Multicast – Transmitting data from one source host to a particular group of hosts that are interested in receiving the data is called Multicast. It is also called one to many transmissions.

Subnet

When a bigger network is divided into sub network to maintain security is called subnetting.
In order to divide the network into two parts you need select 1 bit from 8 bit of the host ID part.

The above network is class C network and the NID is 193.1.2.0 and we divide the network into two parts. Subnet 1 = we get the range 193.1.2.00000000(193.1.2.0) – 193.1.2.01111111(193.1.2.127). Here the 193.1.2.0 is the subnet ID and 193.1.2.127 is the Direct Broadcasting address. Subnet 2 = we get the range 193.1.2.10000000(193.1.2.128) – 193.1.2.11111111(193.1.2.255). Here the 193.1.2.128 is the subnet ID and 193.1.2.255 is the Direct Broadcasting address.

Subnet Mask

Suppose we divide a Class C network with 4 subnets. So in order to identify which packet belongs to which network we use subnet mask. It is a 32 bit number consist of 0 & 1. 1 = Network ID & Subnet ID 0 = Host ID So, for a IP address 200.1.2.30 the Subnet Mask is –

11111111.11111111.11111111.11000000 
or
255.255.255.192

So, to identify which IP belongs to which subnet use use bitwise and operation on the subnet mask and the IP address.

    11111111.11111111.11111111.11000000
&&  11001000.00000001.00000010.00011110
-----------------------------------------------------
    11001000.00000001.00000010.00000000

The address belongs to subnet 1.

11001000.00000001.00000010.00000000 
or
200.1.2.0

Internally there is a routing table which helps forward the packet.

Note: Some cases NID match with two entries, in that case the interface having longest subnet mask(More 1’s) is selected.

Daily Learning: Computer Networks – IP Address & DNS

IP Address

When we type google.com in our web browser it is converted into IP addresses and then it reach to the desired google network and host and specific port to get the web page.

An IP address consists of two part –

  1. Network ID
  2. Host ID

The size of IP address is 32 bit.

Generation

  • 1st Gen – In 1980 the IP address was divided into 8 bit or Network ID and 24 bit of Host ID but as people starts using computer more the requirement got more.
  • Classful System – We have divided the IP address into various classes –

Class A we take the first bit, Class B we take the first 2 bit, similarly in Class C we take the first 3 bit and so on till Class E.

ClassStarts WithNetwork BitHost BitTotal NetworksHost per NetworkNetwork Range
Class A01 + 72412816M1-126
Class B102 + 141616K65K128-191
Class C1103 + 21820M256192-223
Class D1110Reserved For MulticastN/AN/AN/A224-239
Class E11111Reserved For ExperimentN/AN/AN/A240-255

What is dotted decimal representation?

If we divide the IP address in four parts(8 bits) and we convert the 8 bit into decimal and we put “.” in between it is called dotted decimal representation. e.g. – 127.0.0.1

Note : We can configure total (number of host – 2) per network.

  • suppose we have a network 11.0.0.0, 14.0.0.0. Whenever there is all 0 in the host ID it represents the network itself. That’s why we don’t use first IP address as a valid IP address for a host.
  • 255.255.255.255 is assigned as Limited Broadcast Address. So it can’t be assigned to any host.
  • 255 as host ID is assigned as Direct Broadcasting Address. So it can’t be assigned to any host. e.g – (NID).255.255.255

DNS

What is DNS overhead?

For converting the domain name into IP address we go to DNS(Domain Name Service) Server of the ISP(Internet Service Provider) and if it doesn’t know the IP then there are three hierarchy servers that helps –

  1. Root Server
  2. TLD Server(Top Level Domain)
  3. Name Server

Actually we don’t do it every time we visit a website after conversion we store the IP address locally in our computer.

Daily Learning: Computer Networks – NAT(Network Address Translation)

In the past we used to use IPv4 which has limited number of host that can be given the IP addresses. For that we use NAT to solve the problem.

Let’s see how it works –

  • First ISP gives you a valid public IP address and that is being setup in the router.
  • The router assign a new private IP address to the new hosts that joins the network.
  • The private IP addresses are reserved so no one else can connect to you.
  • When you send a Ethernet packet to the outside of the world then you first send the packet to the router then it translate the private IP to public IP then sends the packet.
  • When a packet comes from outside world then it first comes to the router then router translate the public IP to private IP then it uni cast the packet to the host in the LAN.

Note – Your neighbor router connected devices could have the same private IP addresses but that won’t effect you network because the IP are all private.

Daily Learning: Computer Networks – ARP & DHCP

ARP (Address Resolution Protocol)

How a computer gets another computer’s MAC address in a LAN?

If there is two computer in a LAN suppose Computer A and Computer B and A wants to sends some data to the computer B over the LAN then it needs computer B’s MAC address to send the data. Let’s see how it works –

  • Computer A sends ARP(Address Resolution Protocol) request to all the machines in a LAN with the IP address of computer B.
  • Computer B respond on the ARP and sends back the MAC address.

DHCP (Dynamic Host Control Protocol)

Ever imagined when you connect to any wifi and it gives you a unique IP address automatically, How?

It is the protocol which gives IP addresses to host that joins a network and also manage the given IP addresses to the hosts.

There are four part of any DHCP system

  1. DHCP Discover – When a new machine joins a LAN network it sends a broadcast message to to network to know the addresses of the DHCP server.
  2. DHCP offer – After it gets a DHCP discover request from a host it sends a DHCP offer to the host with one IP address from it’s pull.
  3. DHCP request – If the host accept the DHCP offer then it sends back a DHCP request back to the server.
  4. DHCP Acknowledgement – Once the DHCP server gets the DHCP request it gives back a acknowledgement to the host and store the information.

E.G. – A typical example is our home router.

DHCP Relay – So big techs wants a specific DHCP server rather than the router in that case the router works as a DHCP relay and forwards the DHCP requests to the DHCP server knowing the destination IP address.

Daily Learning: Computer Networks – TCP/IP Model

TCP/IP model stands for Transmission Control Protocol and Internet Protocol.

The TCP/IP model consists of five layers: the application layer, transport layer, network layer, data link layer and physical layer.

The first four layers provide physical standards, network interface, internetworking, and transport functions that correspond to the first four layers of the OSI model and these four layers are represented in TCP/IP model by a single layer called the application layer.

TCP/IP is a hierarchical protocol made up of interactive modules, and each of them provides specific functionality.

Below there is a table with all layers given with their individual task.

Layer 4ApplicationAllow access to network resources
Layer 3TransportProvides process to process message delivery and error handling
Layer 2InternetMove packets from source to destination
Layer 1Link/Network InterfaceResponsible for transmission of data between two devices in a same network.

Here below a visual difference between OSI and TCP/IP protocol.

Note : The higher you go up in the model the headers are stripped away until you have the main data left for your application.

Internet Layer

This layer is consist of different protocol like TCP or UDP. It has a thing called headers and the headers has certain properties as well –

  • Version – It describes the IP address type IPV4 or IPV6
  • Header Length – It specifies the size of the header. Usually it is 32 bit.
  • Differentiated Services Code Point (DSCP) – It contains data of bandwidth sensitive application like VOIP.
  • Time To Live (TTL) – Some time error happens and a Ip packets travels through the routers infinitely and to prevent we use this.
    • Protocol – It specifies the protocol type. E.G. – TCP or UDP.

Intro to GraphQL & How it differs from REST APIs

What is GraphQL?

It is a query language for the API in simple term. But what actually means and how it helps is a whole bunch of talk.

GraphQL is a syntax that describes how to ask for data, and is generally used to load data from a server to a client. GraphQL has three main characteristics:

  • It lets the client specify exactly what data it needs.
  • It makes it easier to aggregate data from multiple sources.
  • It uses a type system to describe data.

With GraphQL a user an make a single request and take all the data from the back-end rather than making a lot of request and it drastically reduce the server requests and improve performance. Below a sample query and the response.

# Query
{
  hero {
    name
  }
}

# Response
{
  "data": {
    "hero": {
      "name": "R2-D2"
    }
  }
}

Difference between GraphQL and REST API

For the past few decades we are using REST APIs and it was completely fine. But let’s see how it works.

In REST API there are specific endpoints for every resource that it needs and a client sometime have to make several requests to get a the actual data and also the data is sometime overloaded and sometime under loaded.

And the data is also store in different tables so you have to make different queries for different tables.

E.G. –

  1. The YouTube page there are whole bunch of videos that comes up and in a REST architecture the YouTube make a request to the server to get all the IDs.
  2. And then it again request back to get all the information about all the ID.
  3. So for a million user the REST architecture is sending 2 request for this simple task.

But in a GraphQL architecture the data will comeback in a single request and there will also be specific.

The GraphQL has only one endpoint “/graphql”.

Daily Learning: Computer Networks – OSI Model

OSI stands for Open System Interconnection is a reference model that describes how information from a software application in one computer moves through a physical medium to the software application in another computer.

OSI consists of seven layers, and each layer performs a particular network function.

OSI model divides the whole task into seven smaller and manageable tasks. Each layer is assigned a particular task.

Each layer is self-contained, so that task assigned to each layer can be performed independently.

Below there is a table with all layers given with their individual task.

Layer 7ApplicationNetwork services provided to end-user applications such as a web browser.
Layer 6PresentationThe presentation layer formats or translates data for the application layer based on the syntax or semantics that the application accepts.
Layer 5SessionThe session layer controls synchronization of communication between different computers.
Layer 4TransportBreaks the data in chunk and Transfer the data between systems and hosts.
Layer 3NetworkDelivering frames to their intended destinations among based on the addresses contained inside the frame.
Layer 2Data LinkDirectly connected nodes are used to perform node-to-node data transfer where data is packaged into frames. Also corrects Error.
Layer 1PhysicalTransmitting electrically or optically raw data from sender to receiver

Below I am going to give some idea about important terminologies regarding OSI model –

  • MAC Address (Media Access Control) – It is built into all the network devices.
    • It is a 48 bit address represented in hexadecimal form.
    • Each hex character contains 4 bit.
    • There are 12 hex characters
    • E.G. – 00–40–05–60–7D–49
    • The first six digit represents the NIC manufactures. Last six digit refers to the unique ID of each NIC.
  • Frames – The data transfer in network happens in frames.
    • Different network have different frame size.
    • All NIC in a same network must have same frame size.
    • Generally the frame size is 1500 bytes

Data Transmission in Hub – When a specific NIC sends the data to a specific host in a network it just sends the data to the hub and the hub sends the data to all the connected host and the host with the matching MAC address will receive and others will discard it.

Data Transmission in Switch – Later we use switch which filter the MAC address and sends the data to only the destination address.

FCS – It is 4 byte long.

  • Data Link Layer parts –
    • LLC(Logical Link Control) – NIC that talks to the system’s operating system (usually via device drivers). The LLC handles multiple network protocols and provides flow control.
    • MAC Address – which is discussed above.
  • Network Layer –

Here it gives a logical address called IP address. It is a 32 bit address and represented as dotted decimal. There is a device called router which sends data though IP address.

Daily Learning: Computer Networks – Network Topology

In real life there are many ways the hosts in a network is connected. Upon which the efficiency and other parameters depends and discussed topologies are been developed through the decades.

Bus & Ring Topology

  • A bus topology use a connection line that connects all computers.
  • Ring topology connects all the computer on a network with a ring of cable.
    In ring topology the data gets transferred in uni direction (clockwise or anti clockwise )

Problems – Both suffered from same problem with cable break down.

Star Topology

Here all machines are connected to a central node.

Pros – It is robust and if one connection goes down then entire network don’t get affected.

Cons – If the central node goes down then the entire network goes down.

Mesh Topology

In wireless network every machine is connected to every network then it is a mesh topology. There are mainly two type of topology is there-

  • Fully Mesh – All machines are connected to all other machines.
  • Total number of Links – n * (n – 1) / 2
  • Partial Mesh – At least two machines are not connected.

Hybrid Topology

Here in the central box all the machines are connected to a internal bus. It is often known as star-bus topology.

All the hosts are connected to a central node but inside the box every connection is actually bus topology.

Daily Learning: Computer Networks – Internet & Data Communication

Internet

It is a distributed vast network that connect all type of devices together.

Data Communication

There are total 5 fundamental parts of any data communication –

  • Message – For a data communication one of the most important thing is message or the data.
  • Sender – The second thing is sender there must be a person or application which is sending the data.
  • Receiver – The third part obviously is the receiver there also must be a receiver in order to receive the data.
  • Transmission Medium – It is the way by which the data is going to be transferred. It can be many types for example – Wire, wireless etc.
  • Protocol – It is similar to human conversation some device send some message/request to another machine and it sends back reply as another message/request. In general protocol is a set of rule upon which devices communicate with each other.