Skip to content

Instantly share code, notes, and snippets.

@AaradhyaSaxena
Last active November 27, 2023 18:11
Show Gist options
  • Save AaradhyaSaxena/ed319e405cf63bef7f2fda8e257f253e to your computer and use it in GitHub Desktop.
Save AaradhyaSaxena/ed319e405cf63bef7f2fda8e257f253e to your computer and use it in GitHub Desktop.
Computer Networking

Computer Networking

What Is a Protocol?

Think of your routine conversations. They usually follow a general pattern dictated by predefined rules. For example, most conversations start with greetings and end with goodbyes.

Formally, according to the Oxford Dictionary, a protocol is “a set of rules governing the exchange or transmission of data between devices.”

TCP

The Transmission Control Protocol (TCP) is one such protocol. It was created to allow end systems to communicate effectively. The distinguishing feature of TCP is that it ensures that data reaches the intended destination and is not corrupted along the way.

UDP

The User Datagram Protocol (UDP) is also one such key protocol. However, it does not ensure that data reaches the destination and that it remains incorrupt.

HTTP

HyperText Transfer Protocol (HTTP) is a web protocol that defines the format of messages to be exchanged between web clients, e.g., web browsers and web servers and what action is to be taken in response to the message. The World Wide Web uses this as its underlying protocol.

Packets

Computers send messages to each other that are made up of ones and zeros (bits). However, instead of sending messages of possibly trillions of bits all in one go, they’re broken down into smaller units called packets to make transmission more manageable. These smaller sizes make transmission more manageable because most links are shared by a few end-systems. Sending smaller units in succession instead of one big file all in one go makes usage of the network fairer amongst end-systems.

IP Addresses

Every device that is connected to the Internet has an address called an ‘IP Address’ which is much like a mailing address.

  • IP addresses are 32 bit numbers (in IP version 4).
  • The human readable way for looking at these numbers is the dotted decimal notation, whereby the number is considered one octet of bits (8 bits) at a time. Those octets are read out in decimals, then separated by dots.
    • Hence, each number can be from 0 to 255For example, 1.2.3.4.
  • Some IP addresses are reserved for specific functions.

Ports

Any host connected to the Internet could be running many network applications. In order to distinguish these applications, all bound to the same IP address, from one another, another form of addressing, known as port numbers, is used. Each endpoint in a communication session is identified with a unique IP address and port combination. This combination is also known as a socket. So in essence, ports help to address the packet to specific applications on hosts.

  • IP addresses identify end systems but ports identify an application on the end system.
  • Every application has a 16-bit port number. So the port number could range from 0 to 65535.
  • The ports 0−1023 are reserved for specific applications and are called well-known ports.
  • For instance, port 80 is reserved for HTTP traffic. The ports 1024−49152 are known as registered ports and they are used by specific, potentially proprietary, applications that are known but not system defined.

Network Infrastructure:

Why Layers?

Layered architectures give us modularity by allowing us to discuss specific, well-defined parts of larger systems. This makes changing implementation-level details and identifying bugs easier.

Common Models

There are several models along which computer networks are organized. The two most common ones are the Open Systems Interconnection (OSI) model and the Transmission Control Protocol/Internet Protocol (TCP/IP) model.

OSI model

Screenshot 2023-05-03 at 12 44 58 AM

Network protocols are implemented in software, hardware or a combination of both, and their hardware and software components are organized into these layers. So the main purpose of this ‘network stack’ is to understand how the components of these protocols fit into the stack and work with each other.

Application Layer

  • These applications or protocols are almost always implemented in software.
  • End-users interact with the application layer.
  • The application layer is where most end-user applications such as web browsing and email live.
  • The application layer is where an outgoing message starts its journey so it provides data for the layer below.

Presentation Layer

  • Presents data in a way that can be easily understood and displayed by the application layer.
    • Encoding is an example of such presentation. The underlying layers might use a different character encoding compared to the one used by the application layer. The presentation layer is responsible for the translation.
  • Encryption (changing the data so that it is only readable by the parties it was intended for) is also usually done at this layer.
  • Abstracts: the presentation layer assumes that a user session is being maintained by the lower layers and transforms content presentation to suit the application.
  • End-to-end Compression: The presentation layer might also implement end to end compression to reduce the traffic in the network.

Session Layer

  • The session layer’s responsibility is to take the services of the transport layer and build a service on top of it that manages user sessions.
    • As we will see shortly, the transport layer is responsible for transporting session layer messages across the network to the destination. The session layer must manage the mapping of messages delivered by the transport layer to the sessions.
  • A session is an exchange of information between local applications and remote services on other end systems.
    • For example, one session spans a customer’s interaction with an e-commerce site whereby they search, browse and select products, then make the payment and logout.
  • Abstracts: the session layer assumes that connections establishment and packet transportation is handled by the layers below it.

Transport Layer

  • The transport layer also has protocols implemented largely in software.
  • Since the application, presentation and session layers may be handing off large chunks of data, the transport layer segments it into smaller chunks.
    • These chunks are called datagrams or segments depending on the protocol used.
  • Furthermore, sometimes some additional information is required to transmit the segment/datagram reliably. The transport layer adds this information to the segment/datagram.
    • An example of this would be the checksum, which helps ensure that the message is correctly delivered to the destination, i.e. that it’s not corrupted and changed to something else on the way.
    • When additional information is added to the start of a segment/datagram, it’s called a header.
    • When additional information is appended to the end it’s called a trailer.

Network Layer

  • Network layer messages are termed as packets.
  • They facilitate the transportation of packets from one end system to another and help to determine the best routes that messages should take from one end system to another.
  • Routing protocols are applications that run on the network layer and exchange messages with each other to develop information that helps them route transport layer messages.
  • Load Balancing There are many links (copper wire, optical fiber, wireless) in a given network and one objective of the network layer is to keep them all roughly equally utilized. Otherwise, if some links are under-utilized, there will be concerns about the economic sense of deploying and managing them.

Data Link Layer

  • Allows directly connected hosts to communicate. Sometimes these hosts are the only two things on a physical medium. In that case, the challenges that this layer addresses include flow control and error detection/correction.
  • Encapsulates packets for transmission across a single link.
  • Resolves transmission conflicts i.e., when two end systems send a message at the same time across one singular link.
  • Handles addressing If the data link is a broadcast medium, addressing is another data link layer problem,
  • Multiplexing & Demultiplexing:
    • Multiple data links can be multiplexed into something that appears like one, to integrate their bandwidths.
    • Likewise, sometimes we disaggregate a single data link into virtual data links which appear like separate network interfaces.

Physical Layer

  • Consists largely of hardware.
  • Provides a solid electrical and mechanical medium to transmit the data.
  • Transmits bits. Not logical packets, datagrams, or segments.
  • Also has to deal with mechanical specifications about the makeup of the cables and the design of the connectors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment