Computer Science/Computer Network

5. Routing and Addressing

  • -
728x90
반응형

Overview of Network layer

크게 network layer는 2가지 기능을 수행한다.

  1. data plane : forward datagrams from its input links to its output links
    💡
    실제로 frame을 전달하는 역할을 수행하게 된다. 이를 위해서 header 파일을 분석하여서 어디로 보내야할지 판단하게 된다.
  1. control plane : coordinate these local, per-router forwarding actions so that datagrams are ultimately transferred end-to-end, along paths of routers between source and destination hosts.
    💡
    네트워크에서 경로를 선택하고, 이 경로 정보를 각 router에게 알려주는 역할을 담당하게 된다.

Difference between network layer and transport layer

즉, transport layer는 process 사이의 logical communication을 담당하고 network layer는 host 사이의 logical communication을 담당한다는 것을 잘 기억해두어야 한다.

Example Network Layer : IPv4 Header

💡
Transport layer에 대응되는 header에는 source port number와 destination port number가 들어가 있다. 앞서 언급한 것처럼 IP address를 통해 host를 특정시키고, port number를 통해서 process를 특정시킨다고 생각해주면 된다.

Forwarding and Routing : The Data and Control planes

Forwarding

Move the packet to the appropriate output link

→ 일반적으로 매우 짧은 시간이 걸리고 거의 nanosecond 단위로 동작한다.

Routing

Determine the route or path taken by packets

→ forwarding에 비해서 긴 시간이 걸리고 second 단위로 동작한다.

Forwarding Table

Examining the value of a field in the arriving packet’s header , and then using this header value to index into the forwarding table.

💡
해당 작업은 routing algorithm에 의해서 수행되는데, 해당 algorithm은 router의 forwarding table의 내용을 결정짓는다.
💡
추가적으로 forwarding table의 내용을 기준으로 어떤 outgoing link interface 로 forwarding할 것인지 판단하게 된다.

A routing algorithm runs in each and every router and both forwarding and routing functions are contained within a router.

💡
이게 가능하려면 특정 router의 routing algorithm function은 다른 router의 routing algorithm function과 소통이 가능해야 한다. 이를 위해서 routing information이 담긴 routing message를 교환한다. (물론 이를 위한 routing protocol이 존재한다.)

Control plane : SDN Approach

💡
정확하게는 traditional 한 routing의 경우 각 router마다 forwarding 및 routing function이 있는 것이다. 이와 대비되는 개념이 SDN approach이다. Remote controller가 계산을 하고 이 결과들을 각 router의 forwarding table에 저장하는 방식이라는 점에서 차이를 보인다.
💡
The remote controller might be implemented in a remote data center with high reliability and redundancy, and might be managed by the ISP or some third party.

추가적으로 작동은 software 적으로 동작한다.

Number Ranges and Prefix Matching

앞서 살펴본 것처럼 Forwarding table에는 목적지를 기준으로 어느 outgoing link interface로 forwarding할 것인지 저장되어있다.

하지만 이와 같이 해당하는 정보를 모두 다 forwarding table에 저장하는 것은 매우 inefficient하다.

따라서 위 그림과 같이 공통 부분을 찾고 prefix 로 취급한다. 이를 거치면 다음의 결과가 나오게 된다.

이를 prefix match 라고 한다.

💡
단 주의할 점은 매칭되는 것중에 가장 긴 것 을 찾아야 한다는 것이다. 정확하게는 prefix가 더 긴 것을 만족하는 쪽을 선택한다는 것이다. (Homework3 exercise 3 b번을 참고할 것)
💡
위에서 언급된 mask는 LAB1에서 등장한 network mask 와 동일하다.
💡
추가적으로 forwarding table에 존재하는 destination은 Network address 라는 점을 주의해야 한다. 즉 다시 말해서 실제 원하는 destination을 subnet mask를 이용해서 자르고 해당 값이 destination field에 존재하는 지를 살펴보면 된다. 단, 앞서 설명한 것처럼 일치하는 것이 여러 개이면 prefix가 더 긴 것을 선택한다.
💡
Packet안에는 subnet mask에 대한 정보가 없다. routing table을 보고 해당 subnet mask를 기준으로 해당 값이 prefix랑 같은지 여부를 보고 일치하는 것 중 제일 긴 것에 대응되는 gateway로 이동하는 것이다.

Dotted-decimal Notation and Subnetworks

32bit host address는 편의때문에 일반적으로 dotted-decimal notation 으로 나타내는 경우가 많다. 즉 8bit씩 찢어서 나눠놓는 것이다.

예를 들어

11001000 00010111 00010 /21\text{11001000 00010111 00010 /21}

은 다음과 같이 나타낸다.

200.23.16.0 /21\text{200.23.16.0 /21}

앞의 200.23.16.0은 network address이다. 또한 21은 network mask이다. 이때, 21로 표현하기도 하지만 mask인 1111111 11111111 11111000 00000000를 dotted-decial notation 표현인 255.255.248.0으로 표현하기도 한다.

→ IP주소와 network mask를 XOR하게 되면 network address와 host address를 알아낼 수 있다.

💡
즉, 어디까지가 prefix인지 network mask를 통해 알 수 있는 것이다.
💡
network mask와 subnet mask는 같은 용어라고 이해해주면 된다.

Subnetworks

Definition

Device interfaces that can physically reach each other without intervening router

→ they are configured to use a common network address prefix. This allows them to communicate directly at the data link layer (Layer 2) or network layer (Layer 3) without having to go through a router.

→ they can communicate directly by sending Ethernet frames or IP packets to each other using MAC addresses or IP addresses, respectively.

💡
따라서 서로 다른 host끼리 Ethernet frame이나 IP packet를 주고 받을 때 반드시 router를 타고 가야하는 것은 아니다. 만약 동일한 subnetwork에 속해있다면 router를 거치지 않고 직접적으로 주고받을 수 있다.
  • LAN과 subnetwork 사이의 관계

    The definition of LAN can vary depending on the context and how it's being used. In a broad sense, a LAN (Local Area Network) refers to a network that connects computers and other devices in a relatively small area, such as a house, office, or group of buildings.

    However, when we dive deeper into networking concepts and start considering elements like subnets and routing, the definition becomes more nuanced.

    In these contexts:

    1. A LAN could be defined as all devices connected to the same network switch or set of interconnected switches without involving a router. This would be considered one broadcast domain where all hosts can communicate directly with each other without needing routing.
    1. Alternatively, some might define a LAN as encompassing all devices within the same subnet or IP address range regardless of whether they're connected to the same switch or not.
    1. In an even broader sense, some might consider an entire local network infrastructure (including multiple subnets and routers) as one large "LAN", especially when contrasting it with wider networks like MANs (Metropolitan Area Networks) or WANs (Wide Area Networks).

    So while it's accurate to say that devices on the same LAN can generally communicate directly without routing involved, this assumes that we're using one of the narrower definitions of "LAN". If different subnets are involved - even if they're part of what someone might consider being within one larger "LAN" - communication between those subnets will require routing.

    In summary: Networking terminology isn't always cut-and-dried; context matters greatly in understanding these concepts.

    💡
    즉 통상적으로 사용되는 정의는 굉장히 작은 network를 의미한다. 정의에 따라서 router를 통하지 않고 direct communication 가능한 영역이라고 생각할 수도 있으나 정의하기 나름이다. subnetwork는 이와 달리 정확하게 해당 내부끼리는 router를 통하지 않고 소통이 가능하다는 의미이다.
    💡
    극단적으로는 같은 공유기에 연결된 것들만 같은 LAN에 속했다고도 볼 수 있다.

IP address

  • subnet part (network address) : high order bits
  • host part : low order bits
💡
network address는 IP address에 subnet mask와 XOR를 취해주면 구할 수 있다.

만약 host 영역을 담당하는 bit가 bb bit라고 가정하자

이때, 모든 network interface는 개인만의 고유한 IP주소를 가진다. 즉 router도 IP address를 할당해주어야 한다.

단, host address를 전부 사용할 수 있는 것은 아니다. 2개를 뺴야 한다.

  1. network address : host address가 싹 다 0인 것은 subnet을 식별하는데 특별하게 사용된다.
  1. broadcast address : 각 subnetwork 별로 1개의 address는 broadcast용으로 사용된다. host address의 모든 bit에 1을 할당한다.

→ 따라서 host의 개수는 2b22^b - 2이다.

💡
데이터 패킷이 인터넷으로 전송될 때, 그 패킷은 라우터(게이트웨이)를 거쳐야 합니다. 이 과정에서 라우터는 IP 주소와 기타 정보를 기반으로 패킷을 올바른 목적지로 전달한다.

따라서 게이트웨이는 하나의 네트워크에서 다른 네트워크로의 '출입구' 역할을 하는 것으로 생각할 수 있습니다.

How can we use Internet in our home

우리가 실질적으로 어떻게 인터넷에 접근하는지를 잘 생각해보자

일단 우선은 다음과 같은 녀석들을 ethernet port라고 부른다. Ethernet port는 ethernet cable(소위 LAN선)을 꽂을 수 있는 포트를 말한다.

💡
쉽게 말해서 ethernet port는 networking을 위한 physical interface라고 생각해주면 된다.

다음과 같은 공유기도 결과적으로는 방 안에 존재하는 ethernet port와 물려있어야 한다. 즉 하늘에서 갑자기 뿅하고 인터넷과 연결되는 것이 아니다.

잘 생각해보면 집마다 여러 ethernet port개 존재한다. 이들을 묶어서 관리해주는 친구가 필요하다.

집을 잘 뒤져보면 별로 home network panel이라는 것이 존재한다. 여기에서 집에 존재하는 여러 개의 ethernet port들을 한번에 묶어서 처리해주는 역할을 수행한다. 즉 집 안에 존재하는 여러 ethernet port들은 결과적으로 집안에 존재하는 home network panel과 연결되어있다.

또한 home network panel은 아파트에 존재하는 서버실과 연결이 되어있다.

이때 유지 관리 및 보수를 위해서 각 home network panel은 다음과 같은 patch panel과 연결되어있다.

home network panel과 연결된 ethernet cable은 patch panel 뒤쪽 부분 과 연결된다. (사진에서 위에 존재하는 것이 뒤쪽 부분이다.) 연결하는 것이 궁금한 경우 다음 영상을 참고해주면 된다. (3분 55초)

What is a Patch Panel? Do You Need One?
In this video I discuss what a patch panel is, what it does, and the pros and cons of using one. It should help you decide. DIY Budget Home Network Video: https://www.youtube.com/watch?v=00UTYN9j0FE
https://youtu.be/lg2oGE02DJE?si=FBXx_8hTpZeusQ_T&t=235
💡
다시 말해서 각 가정 별로 대응되는 patch panel의 port number가 존재하는 것이다.

이후, 각 가정별로 구독한 ISP에 대응되는 switch에 연결하는 작업을 거치게 된다. 이러한 연결을 일반적으로 patch cable이라고 부른다. (짧은 ethernet cable을 path cable이라고 부른다.)

이러한 작업을 거쳐서 집에서 인터넷과 연결할 수 있게되는 것이다.

Wi-Fi Router is the only type of Router?

정답은 NO이다.

물론 WIFI router가 Routing 기능을 담당하는 것은 맞지만, 일반적으로 공유기만이 Router에 속하는 것은 아니다

다음은 core router이다. 이런 라우터는 인터넷 서비스 제공자(ISP)의 핵심 네트워크에서 사용된다. 매우 큰 양의 데이터를 처리할 수 있으며, 전 세계적인 네트워크 간에 트래픽을 전송하는 역할을 한다.

다음은 edge router이다. ISP network과 고객 네트워크 사이에 존재한다.

이거는 enterprise router이고 이외에도 엄청 많이 존재한다.

따라서 공유기만 접해봐서 공유기만이 router에 속한다고 착각하기 쉬운데, 이를 바로 잡아야 한다.

Difference between router and switch

스위치는 네트워크 내에서 데이터 패킷을 전송한다. 스위치는 연결된 각 장치의 MAC 주소를 알고 있으며, 이를 통해 특정 장치로 패킷을 정확하게 전달한다. 즉, 스위치는 같은 로컬 네트워크(LAN) 내에서 통신하는 장비들 사이에 정보를 '스위칭'하는 역할을 한다.

반면에 라우터는 서로 다른 네트워크 간에 데이터 패킷을 전송하는 역할을 한다. 라우터는 IP 주소를 사용하여 패킷의 목적지를 결정하고, 해당 패킷이 어떻게 그 목적지에 도달해야 하는지를 결정한다. 즉, 라우터가 하는 것이 바로 '라우팅'이다.

MAC(Media Access Control) 주소는 데이터 링크 계층(Layer 2)에 해당하며, 각 네트워크 인터페이스 카드(NIC)나 장치에 고유하게 할당된 물리적인 주소이다. 이 MAC 주소는 장치 제조 시점에 할당되며, 변경할 수 없다. 스위치는 이 MAC 주소를 사용하여 LAN 내의 특정 장치로 패킷을 전달한다.

반면 IP(Internet Protocol) 주소는 네트워크 계층(Layer 3)에 해당하며, 네트워크 상에서 각 장치가 통신하기 위해 사용하는 논리적인 주소이다. IP 주소는 동적으로 변경될 수 있으며, router는 이 IP 주소를 사용하여 packet의 목적지를 결정하고 패킷을 적절한 경로로 전달합니다.

💡
MAC(Media Access Control) 주소는 네트워크 인터페이스 카드(NIC)나 장치에 고유하게 할당된 물리적인 주소입니다. 이는 장치 제조 시점에 부여되며, 일반적으로 변경되지 않는다. 따라서 MAC 주소는 특정 네트워크 내에서 패킷이 정확한 장치로 전달될 수 있도록 하는 역할을 한다. 반면에 IP(Internet Protocol) 주소는 네트워크 상에서 각 장치가 통신하기 위해 사용하는 논리적인 주소이다. IP 주소는 동적으로 변경될 수 있으며, 대부분의 경우 DHCP(Dynamic Host Configuration Protocol) 서버에 의해 자동으로 할당된다. 따라서 같은 MAC주소를 가진 기기라도 위치나 연결된 네트워크 등에 따라 그것의 IP주소는 달라질 수 있는 것이다.

따라서 MAC 주소와 IP 주소 모두 필요한 이유는 다음과 같다.

  1. 스케일링: 전 세계의 모든 컴퓨터와 디바이스에 유니크한 MAC주소를 할당하는 것은 비현실적이다. 그러나 IP주소 체계를 통해 동일한 MAC주소를 가진 여러 기기들이 각각 다른 네트워크(따라서 다른 IP범위)에서 작동 가능하다
  1. 라우팅: 인터넷처럼 큰 규모의 네트워크에서 패킷을 올바르게 전달하려면, 어디서 어디로 가야 하는지 알아야 한다. 이 정보는 IP 헤더에 포함되어 있다.

결론적으로, MAC과 IP 모두 고유하지만 서로 다른 목적과 용도를 가진 식별자이기 때문에, 둘 다 필요하고 중요하다.

What technique that can allow more devices to be supported with IPv4

The technique you're referring to is Network Address Translation (NAT). NAT allows more devices to be supported with IPv4 by allowing multiple devices to share a single public IP address.

Here's how it works:

  1. Mapping: In a typical home network, for example, the router is assigned a unique public IP address. However, all of the devices connected to the router are assigned private IP addresses that are not routable on the wider internet. When these devices communicate with servers on the internet, NAT translates their private addresses into the router's public address.
  1. Translation: When packets return from servers on the internet, NAT translates them back into private addresses based on a translation table that it maintains. This table keeps track of which internal device each connection was initiated by so that return packets can be correctly addressed and routed.
  1. Port Numbers: To keep track of multiple simultaneous connections from different internal devices, NAT uses different source port numbers in the outgoing packets for each connection.

By using this method, NAT can allow many devices (each with its own private IP) to share one public IP address when communicating with servers on the internet. This has been essential in conserving IPv4 addresses and extending its lifespan despite its limitation of approximately 4 billion unique addresses.

💡
정확하게는 router에 걸린 host가 packet을 외부로 보내려고 할 때 IP주소를 자신(router)의 public IP address로 바꾸고 source port number도 변경한다. 이 정보를 통해서 해당 정보를 router에 저장해둔다. 정확히는 translation table에 저장한다. (즉, 서버 입장에서는 IP주소와 port number를 통해 router에 접근을 하고 해당 정보를 translation table을 통해 해당 router에 있는 host에 매핑을 해주게 되는 것이다.)

좀 더 구체적으로 과정을 살펴보면 다음과 같다

  1. A host in the subnetwork sends a packet to the internet : The router uses its forwarding table to decide where to send this packet next based on its destination IP address. If the router is also a NAT device, it changes (translates) the source IP address from an internal one to an external one and records this mapping in its translation table.
  1. A server outside the subnetwork sends a packet to a host in the given subnetwork : When this packet arrives at the router, it uses its forwarding table to decide where this should go based on destination IP address. If that destination is an external IP owned by a NAT device itself (which will be case if original request was sent from behind NAT), then it uses information in translation table to translate destination back into original internal host before sending it there.
💡
즉 다시 말해서 기본적으로 forwarding table을 먼저 확인한다. 그리고 private IP address와 public IP address를 변환하고 port number 또한 변환하고 싶을 때 translation table을 확인하는 것이다.
💡
애초에 host 별로 router의 port number를 다르게 설정해주었기 때문에 server입장에는 router의 IP 주소와 해당 port number만 보고 보내면 되고, 반대로 router 입장에서는 해당 port number만 가지고도 원래 host와 대응시킬 수 있는 것이다.

Routing 정리

  1. Gateway : 패킷을 전달해야 하는 다음 네트워크 장치를 가리킵니다. 이 장치는 일반적으로 라우터일 수 있으며, 해당 라우터가 최종 목적지로의 경로를 알고 있거나, 적어도 다른 라우터로 패킷을 전달할 수 있는 방법을 알고 있습니다.
    • 그렇다면 만약 보내려는 packet의 도착 subnetwork에 이미 router가 속해있는 경우에는 gateway가 어떻게 되는가?

      이 경우에는 gateway 공간을 사용하지 않는다.

    routing table에서 0.0.0.0은 주로 두 가지 상황에서 사용됩니다.

    1. Network Destination이 0.0.0.0인 경우: 이것은 디폴트 라우트를 의미합니다. 즉, 라우터가 다른 규칙에 의해 처리되지 않는 모든 트래픽을 어디로 보낼지를 지정합니다.
    1. Gateway가 0.0.0.0인 경우: 이것은 일반적으로 해당 네트워크에 직접 연결된 목적지를 나타냅니다 - 즉, 패킷을 전달할 다음 홉이 없음을 나타냅니다.

      → 따라서 Gateway 필드가 0 .0.0.0 로 설정되어 있다면, 그것은 일반적으로 해당 패킷의 목적지가 현재 라우터에 직접 연결된 네트워크(즉, 로컬 네트워크)에 있다는 것을 의미합니다.

  1. Netmask (subnetmask) : Netmask 필드는 목적지 IP 주소의 서브넷을 정의합니다. 이 넷마스크는 IP 주소가 어느 부분까지가 네트워크를, 어느 부분이 호스트를 나타내는지 구분하는 데 사용됩니다.
    💡
    제발 중간에 router가 속한 subnetwork의 netmask를 routing table에다가 적어두는게 아니라는 점을 기억해야 한다. router들끼리의 subnetwork에 대응되는 subnetmask는 매우 특이하게 router에게 정보를 보내지 않는한 사용되지 않는다.

    만약 라우팅 테이블에서 목적지(Destination)가 0.0.0.0이고 서브넷 마스크(Netmask)도 0.0.0.0인 경우, 이것은 "디폴트 라우트" 혹은 "캐치-올(catch-all)" 라우트를 의미합니다.

    디폴트 라우트는 다른 특정 라우팅 엔트리에 의해 처리되지 않은 모든 네트워크 트래픽을 처리하는 경로를 정의합니다.

    예를 들어, 다음과 같은 라우팅 테이블 엔트리가 있다고 가정해봅시다:

    
    Destination     Gateway         Netmask
    192.168.1.0     192.168.1.1   255.255.255.0
    192.168.2.0     192.168.2.1   255.255.255.0
    0.0.0.0         10.10.10.1    0.0.0.0
    

    위의 경우, 192.168.1.0와 192.168.2.0주소로 가는 패킷들은 각각 첫 번째와 두 번째 엔트리에 따라 처리됩니다.

    그러나 이것들 외의 어떤 목적지 주소로 가는 패킷들에 대해서는 세 번째 엔트리인 디폴트 라우트가 적용됩니다 - 즉 그런 패킷들은 10.10.10.1 주소를 가진 게이트웨이로 전송됩니다.

    따라서 Destination과 Netmask가 모두 0.0.0.0인 경우, 그것은 기본적으로 "모든 목적지" 혹은 "아직 매치되지 않은 모든 목적지"에 대한 경로를 정의하게 됩니다.

  1. metric : 값이 낮을수록 우선순위가 높아진다.

Minimal Subnetmask

  1. 해당 subnetmask에 속한 host의 수 계산
  1. 1번에서 구한 값에서 2를 더한다. (broadcast용 + router용)
  1. 2번에서 구한 값 이상의 2의 거듭제곱수를 구한다. (편의를 위해 2k2^k라고 하자)

    → 예를 들어 129의 경우에는 256이다.

  1. 2진수 기준으로 k승을 담당하는 숫자 이후부터는 subnetmask의 값을 1로 설정해주면 된다.

    → 앞의 예시를 그대로 사용하자면 282^8에 대응되는 자리부터 1로 다 채워주면 된다

    → 잘 생각해보면 0 ~ 2812^{8} -1까지의 개수가 282^{8}이라서 충분히 커버할 수 있다.

    → 운영체제에서 hash table 관련해서 문제푸는 것이랑 거의 유사한 느낌으로 이해할 수 있다.

ARS protocol

ARP (Address Resolution Protocol)는 네트워크에서 IP 주소를 물리적인 MAC (Media Access Control) 주소로 변환하는데 사용되는 프로토콜입니다. 이 프로토콜은 OSI 모델의 데이터 링크 계층과 네트워크 계층 사이에서 작동합니다.

ARP의 작동 방식은 다음과 같습니다:

  1. 송신자 컴퓨터가 목적지 IP 주소를 알고 있지만, 해당 IP 주소에 대응하는 MAC 주소를 모르는 경우 ARP 요청을 네트워크에 전송합니다.
  1. 이 ARP 요청은 "이 IP 주소를 가진 컴퓨터가 있다면, 당신의 MAC 주소를 알려주세요"라는 메시지입니다.이 ARP 요청은 브로드캐스트 패킷으로 전송되어, 네트워크에 연결된 모든 장치들이 이 패킷을 수신하게 됩니다.
  1. 각 장치들은 자신의 IP 주소와 ARP 요청에 포함된 목적지 IP 주소를 비교합니다. 만약 두 IP주소가 일치하면, 해당 장치는 자신의 MAC주소를 포함한 ARP 응답을 송신자에게 직접 보냅니다.
  1. 송신자 컴퓨터는 ARP 응답을 받아서 목적지 MAC주소를 알게 되고, 이 정보를 사용하여 실제 데이터 패킷을 목적지 컴퓨터에 전송할 수 있게 됩니다.
  1. 송신자 컴퓨터는 얻어낸 MAC주소 정보를 일정 시간 동안 캐시(임시 저장공간)하여 나중에 동일한 목적지로 패킷을 보낼 때 다시 ARP 요청 과정을 거칠 필요가 없도록 합니다.

따라서 ARP 프로토콜은 효율적인 데이터 전송을 위해 필수적인 역할을 하며, 로컬 네트워크에서 통신이 가능하도록 하는 기본 메커니즘 중 하나입니다.

반응형
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.