전공/데이터 통신

[8-1강] Basics on Data Link Layer(Mac ,Nodes and Links, Three Types of addresses, ARP)

뜨거운 개발자 2024. 5. 3. 13:20

시작하면서

그동안 physical layer만 공부했지만 이번에는 data link layer를 공부하겠습니다.

3계층 4계층에 대한 지식이 있다면 더 깊게 이해가 가능하기 때문에 기본적인 설명을 하면서 진행하겠습니다. (더 깊은 내용은 네트워크 통신에서 배웁니다.)

  • Data link layer
  • Network layer: IP
  • Transport layer: TCP & UDP

이렇게 배우도록 하겠습니다.

Data link Layer에서 통신

직접적으로 wifi에 연결 할 때 사용하는 layer 가 physical layer와 data link layer 입니다.

1,2 계층 같은 경우 직접적으로 디바이스가 전기적 신호를 주고 받습니다.

서로 다른 디바이스여도 서로 통신이 가능한 이유는 라우터가 서로 통신을 연결해주기 때문입니다.

  • 직접 연결할 때는 경로의 관련이 없는데, 여러 개의 경로를 선택하는 건 3계층에서 선택합니다.
  • 다만 소실이 발생할 때 보안하기 위해서 TCP 가 등장했습니다.

Nodes and Links

data link layer에서 통신은 node-to-node 방식입니다. (직접 통신) (wife 는 wife, 5G 면 5G 등등)

중간에 라우터를 거쳐서 통신합니다.

노드와 링크는 직접적으로 연결 된다는 것을 볼 수 있습니다.

Services

  • 낮은 layer가 높은 layer로 services를 해준다.
  • Data-link layer of a node (host or router) is responsible for delivering a datagram to next node

송신 : encapsulate

  • Data-link layer of sending node needs to encapsulate the datagram received from the network in a frame

수신 : decapsulate

  • Data-link layer of receiving node needs to decapsulate the datagram from the frame

중간에 거치는 라우터(intermediate node)는 encapsulate과 decapsulate 모두 일어남

  • Each intermediate node needs to both encapsulate and decapsulate
  • Each link may be using a different protocol with a different frame format
  • 둘 사이 같은 프로토콜을 사용한다고 해도 encapuslation 과 decapsulation은 필요하다

서비스

라우터를 거쳐서 가는 그림입니다.

Data link Layer에서 제공하는 서비스

1. Framing

2계층 포멧을 만드는 것입니다.

encapsulate the datagram : datagram→ frame

A packet at the data-link layer is normally called a frame.

Frame은 header and a trailer를 가지고 있다.

  • Different data link layers have different formats for framing.

2. Flow Control

rate of produced frames is higher than the rate of consumed frames

컴퓨터의 성능의 차이 때문에 너무 빨리 보내면 처리하지 못하기 때문에 속도를 조절해야 할 수 있다. : Ask it to stop or slow down

Different data link layer protocols use different strategies for flow control.

3. Error Control

정상적으로 잘 받았다고 ack를 보내게 됩니다.

They are an issue in every layer

Error detection and correction을 합니다.

4. Congestion Control

동시에 패킷을 여러개 보내게 되면 충돌이 날 수 있는데, 이런 경우를 컨트롤 합니다.

  • 유선에서는 잘 안 납니다. 무선에서는 하게됩니다.
  • most data link layer protocols do not directly use a congestion control to alleviate congestion

Two Categories of Links

Data link layer controls how the medium is used

  • Point-to-point link

 The link is dedicated to the two devices

 예시 : 링 토폴로지, traditional home phones

  • Broadcast link

 The link is shared between several pairs of devices

 예시 : 버스 토폴로지 cellular phones, which are using a broadcast link

 (the air is shared among many cell phone users)

Two Sublayers

  • Data link control (DLC) sublayer
  • Media access control (MAC) sublayer
  • 보통 2개를 묶어서 MAC이라고 부릅니다. (프로토콜 당 부르는게 다릅니다.)

Link Layer Addressing

어디로 보낼 것인지를 정하는 것이 Addressing입니다.

  • 디바이스간 통신을 할 때는 48bit 주소는 unique 합니다.

이 주소를 physical address또는 MAC address라고 부르기도 합니다.

  • connectionless internetwork에서 데이터 그램을 IP 주소만을 사용해서는 원하는 목적지에 도달하지 못한다.

 such as the Internet we cannot make a datagram reach its destination using only IP addresses

  • IP주소만을 가지고는 어디를 거쳐서 이동하도록 정의하지 못합니다.
  • A link-layer address는 link address, physical address,MAC address 라고 불린다.
  • datagram이 network layer에서 data-link layer로 이동할 때 datagram은 frame안으로 encapsulated 됩니다. 그리고 MAC주소가 2개 만들어지는데 이것들은 frame header에 붙혀집니다.

Link Layer Addressing

보내는 곳 Mac 주소, 받는 곳 MAC 주소 이렇게 적어줘서 계속 바뀌는 것을 볼 수 있습니다.

라우터는 여러개의 MAC주소를 가질 수 있다는 것을 볼 수 있습니다.

N1은 IP 주소, L1은 MAC주소

Three Types of addresses

  1. Unicast Addres

 하나의 단말끼리 통신할 때를 말합니다.

 Each host or each interface of a router is assigned a unicast address.

 unicast link-layer addresses는 LAN과 Ethernet을 말합니다.

 48 bits (six bytes) that are presented as 12 hexadecimal digits separated by colons

 유니캐스트 주소의 경우 2번째 자릿수가 짝수여야 합니다.

 A2:34:45:11:92:F1

  1. 특정 그룹에 보내게 되는 경우 Multicast Address

 Multicasting means one-to-many communication.

 However, the jurisdiction(관할권) is local (inside the link)

 second digit 이 홀수여야만 한다.

  1. 모든 사용자에게 보낸다. Broadcast Address

 Broadcasting means one-to-all communication.

Address Resolution Protocol (ARP)

실제로 인터넷에 뭔가를 보낼 때 mac주소를 생각하지 않고 IP주소만 생각합니다.

실제로 도메인 이름을 기억하지 IP주소를 기억하지도 않습니다.

실제로 IP만을 알면 되지만 IP는 logical address이기 때문에 실질적인 인접한 divice와 통신하기 위해서는 Mac address가 필요합니다.

네이버까지 가기 위해서는 AP의 mac주소를 알면 되는데 사실 그것을 기억하지 않아도 됩니다.

왜냐하면 IP를 지정하면 어떤 AP의 주소를 보면 되는지 알려주는 프로토콜이 있는데, 그게 바로 ARP 프로토콜 입니다.

기본적으로 ARP 프로토콜을 layer3 프로토콜입니다.

즉 ARP 프로토콜은 IP 주소만 가지고 통신을 할 수 있도록 돕는 프로토콜이다.

위의 그림을 보면 System A가 N1이라는 IP주소와 L1이라는 Mac주소를 사용한다고 알리는 것 이다.

여기서 매핑테이블의 개념이 나오는데 항상 IP와 Mac주소에 해당하는 매핑테이블을 관리합니다.

 따라서 통신하기 전에 매핑 테이블을 먼저 살펴보고 없으면 ARP 요청을 보내는 식으로 동작합니다.

 통신을 할 때 broadcast를 해서 모든 곳으로 가는데 목적지가 아닌 호스트들은 그 신호를 무시합니다.

 보낼때와 받을 때 전부 매핑 테이블이 업데이트 됩니다.

ARP accepts an IP address from the IP protocol, maps the address to the corresponding link-layer address, and passes it to the data-link layer.

ARP Packet Format

ARP packet is encapsulated directly into a data-link frame

The frame needs to have a field to show that the payload belongs to the ARP and not to the network-layer datagram

이 그림에서 하드웨어는 layer2,

  • protocol type은 layer3 를 의미합니다.
  • Hardware legth는 L2 주소의 길이를 의미하고 이것은 48bit이므로 6byte이므로 6을 적어줍니다.
  • protocol length 같은 경우 IP 주소는 보통 32bit이므로 4바이트여서 4가 들어갑니다.
  • Operation 같은 경우 request이므로 1을 보냅니다.
  • 그리고 source hardware address 는 출발지의 Mac address를 의미합니다.
  • source protocol address는 출발지의 IP address에 해당됩니다.
  • Destination hardware address를 알 수 없어서 빈 채로 보냅니다.
  • Destination의 protocol address는 목적지의 IP 주소에 해당합니다.

보내기 예시

이렇게 브로드 캐스팅을 해주면 payload에 저렇게 들어가는 것 입니다.

destination이 먼저 나오는 것이 전통적입니다. (하드웨어로 구현하는 예시)

다만 layer2는 이렇지만 layer3이상에서는 src를 먼저쓰고 dest를 나중에 써줍니다.

  • 이걸 보면 처음부터 소프트웨어적으로 구현되었다는 것을 알 수 있다.

예시 2

Na와 NB가 IP주소이다.

  • 송신측

 뭔가를 보내려면 일단 어디로 보내야 합니다. (어디로 이동할꺼면 지하철 역으로 먼저 이동하는 것을 예시로)

 따라서 이 그림에서 alice는 R1의 라우터로 보내야만 하는데, 그게 어디있냐면 Forwarding Table에 적혀있습니다.

 여기서 Forwarding table은 누가 알려주느냐? 라우팅 알고리즘이 알려줍니다.

 따라서 여기서는 R1으로 가야하는데 Fowarding table은 layer3 이기 때문에 IP 주소만을 알려줍니다.

 그래서 ARP 프로토콜을 여기서 동작 시킵니다. → Mac address를 얻기 위해서.!

 아래 그림을 보면, datagrame이 Frame이 되는 것을 볼 수 있습니다.

  • 이동측 (R1에서 R2로 가는 상황)

 IP주소 즉 Data gram 내부의 IP주소는 변화하지 않는 것을 볼 수가 있습니다.

 오직 layer2의 주소만 계속해서 변화합니다.

  • 수신측

 
728x90