IP (Internet Protocol)

임승섭·2023년 6월 4일
0

Computer Network

목록 보기
16/27

IP

  • a network layer protocol
  • 목적 : packet을 송신자에서 수신자까지 문제 없이 전달해주는 것
  • Host와 router들끼리 연결된 시스템이나 data link의 protocol들이 각자 다 다르다
    (WiFi로 연결 or 이더넷으로 연결 or PPP로 연결 (point to point protocol) )
  • 어찌됐든, 이 과정에서 데이터가 잘 전달되도록 한다

Packet flow without Network layer

  • 서로 직접적으로 연결된 host들끼리의 communication만 가능하다

Packet flow with Network layer

  • router들을 이용해서 "Multi-hop" communication이 가능해진다
    (직접 연결되지 않아도 router를 거쳐서 갈 수 있다)

Hourglass model

  • 파란색 : layer 1, 2 (physical, data link)
  • 보라색 : layer 4 (transport)
  • 초록색 : layer 5 (application)
  • 다양한 프로토콜들이 존재한다.
    하지만, Network layer에서는 통일된 프로토콜 IP 밖에 없다.

Service model

  • IP가 위에 있는 layer(transport) 쪽으로 어떤 서비스를 제공해주는가
    • Connectionless : 송신자와 수신자 간 connection을 만들지는 않는다
    • Best-effort : 최선을 다하지만, 문제가 생겨도 보장하지 않는다. 어쩔 수 없다 (unreliable)
      • Packets may get lost (없어질 수 있어)
      • Packets can be delivered out-of-order (순서가 뒤바뀔 수 있어)
      • Duplicate copies may be delivered (패킷이 복제될 수 있어)
      • Packets can be delayed for a long time (한참 있다 도착할 수 있어)
  • Global Addressing Scheme (통일된 address scheme을 사용하게 한다)

Packet Format

  • Header
    • 한 줄이 32bit
    • 다섯 줄은 무조건 있어야 한다 (20byte는 꼭 있어야 해)
    • Option 최대 40 byte
  • Data
    • 위에서 내려온거 (TCP, UDP)

VER

  • IPv4(0100) or IPv6(0110)

HLEN

  • length of the header
  • 0000 ~ 1111 (0 ~ 15). 근데 위에서 보면 header는 최대 60byte
  • 그래서 단위가 4byte
  • header가 20 bytes면, HLEN = 5
  • 4를 곱해서 계산해라

Service

  • packet이 어떤 traffic인가를 알려준다 (router가 참고해서 우선순위, 처리 방식 등을 결정)
  • 앞에 3비트 : Precedence
    • 우선순위를 의미한다 (0 ~ 7)
    • 7 : the highest priority
    • router에 버퍼가 가득 차서 packet을 drop할 때, priority가 가장 낮은 packet을 drop한다
  • 뒤에 4비트 : TOS bits
    • type of service
    • 모두 0이거나, 4개 중에 하나만 1이어야 한다

Total length

  • packet의 total length (header + data)
  • 16bit (0 ~ 65,535)
  • 단위 : byte. -> **IP packet의 최대 크기 : 65,535 bytes)

Identification

Flags

Fragmentation offset

Time to live

  • packet의 수명
  • 단위 : number of hops
    • 다음 router 도착 -> -1
  • TTL이 0이 되면, 더 이상 다음 router로 전달되지 않고 drop
  • 무한 loop 돌고 있을 때, TTL 덕분에 어느 순간에 drop이 된다.

Protocol

  • 상위 layer(upper layer)의 protocol
    • 1, 2, 89는 상위라고 보긴 어렵지만,
      이러한 프로토콜들도 패킷을 보낼 때는 IP를 이용해서 보낸다.
      어떠한 프로토콜들이 사용하고 있는 패킷인지 명시를 해둔다
    • 비율로 보면 6, 17이 가장 많겠

Header checksum

  • for error detection
  • header에 다른 부분들에 의해 값이 결정된다.

Source IP address & Destination IP address

  • 32 bits
  • 중간에 있는 router들이, 이게 A에서 온거고 B로 가고 있다는 걸 알아야 한다
  • 중간에 router에서 drop이 되면, source에게 알려줘야 한다
  • destination도 source를 알아야 나중에 ACK을 보낼 때나 등등 이용한다

Option

  • HLEN이 5면 option 없고, 5 이상이면 option이 있다

Exercise

Q. The initial 8 bits of an IPv4 packet was the following
01000010
The router drops the packet since it is an errorneous packet. Why?

A. 앞에 4bit : VER (0100 = 4)
뒤에 4bit : HLEN(0010 = 2) => 8 byte.
but, length는 최소 20byte가 되어야 한다.

Q. HLEN value of an IPv4 packet is 1000 (in binary).
What is the length of option fields in its IP header?

A. 8 * 4 = 32 bytes

  • 20 = 12 bytes

Q. HLEN of a packet is 5, and the total length field has the value 0x0028.
What is the length of data in this IP packet?

A. HLEN = 5 -> 20bytes
total length = 40bytes
=> data = 20bytes

Q. The initial part of an IPv4 packet is like the following :
0x45000028000100000102
What is the time-to-live of this packet?

A. 16진수이므로 1개에 4 bit, 2개에 1 byte. 8개에 1줄.
3번째 줄의 첫 8bit가 TTL이므로, 01


MTU (Maximum Transfer Unit)

  • data link layer에 지정된 MTU라는 값이 있다.
    data link가 어떤 프로토콜(와이파이, 이더넷)을 쓰냐에 따라 값이 다르다.
    e.g. Ethernet : 1500 bytes
  • upper limit of IP packet
  • network layer에서 data link layer로 내려보내면,
    앞에 header 뒤에 trailer를 붙이는데 이거 제외하고
    가운데 애가 MTU의 제약을 받는다.

  • Different protocols have different MTUs

Fragmentation

  • 만약 IP packet의 size가 MTU보다 더 크다면, packet은 여러 packet들로 fragmented되어야 한다
  • The IP header is attaced to each fragment (각 fragment별로 header가 붙는다)
    • fragment할 때 header size도 고려해야 한다!!
    • packet size = 4000 byte. MTU = 1420 bytes. header size = 20 bytes
  • 1개의 packet을 3개로 나눴다. router 입장에서는 그냥 따로따로 보내주면 되지만,
    목적지에서는 얘네를 다시 하나로 조립해야 한다. 그래서 조립하는 순서를 알아야 한다
    -> offset : 단위가 8 byte라서 8로 나눠줘라

Identification

  • fragment를 했을 때, 같은 fragment 소속이라는 것을 알려주기 위함
  • All fragments of the same packet has the same identification number

Flag

  • 맨 앞은 안써
  • 두 번째 'D' (Do not fragment)
    • D = 1 : this packet should NOT be fragmented. (fragment시키지 마라)
      (MTU보다 크면, 그냥 버려라)
  • 세 번째 'M' (More fragments)
    • 내 뒤에 fragment가 더 있다. (there are more fragments after this)
    • M = 0 : this is the last fragment or the only fragment(fragment 안되었을 때)

Fragmentation offset

  • 단위 : 8 bytes
  • The position of this fragment in the original packet
  • only considers data bytes (header를 고려하지 않는다)

Example

  • identification number가 동일
  • 세번째 fragment의 More fragment = 0
  • 다음 router에서는 MTU가 더 작아질 수가 있다.
    • identification number는 그대로 유지. 뒤에는 계속 fragment 있으니까 M = 1

Fragmentation & Reassembly

  • fragmentation은 router 중간에 어느 node에서든 나타날 수 있다.
  • reassembly(조립)final destiation에서만 일어난다
  • 만약 fragment 중에 하나라도 destination에 도착하지 않으면 전체 packet을 버린다

Exercise

Q. A packet has arrived, and its 'M' bits is 0.
What is the meaning of this?

A. either of the following :

  • This packet is NOT fragmented
  • This packet is fragmented, and this fragment is the last one

Q. A packet has arrived, and its 'M' bits is 1.
What is the meaning of this?

A. This packet is fragmented, and this fragment is NOT the last one

Q. A packet has arrived, and its 'M' bits is 1, and the fragmentation offset is 0. What is the meaning of this?

A. This packet is fragmented, and this is the first fragment.
(There are more fragments after me)

Q. A packet has arrived, and its fragmetation offset is 100.
What is the meaning of this?

A. This packet is fragmented, and the position of this fragment is 800 bytes.
(only counting data bytes)

Q. A packet has arrived. Its fragmentation offset is 100, HLEN is 5, and the total length is 100. What is the first and last position of this fragment in the original packet? (the first and the last bytes)

A. the first byte : 100 * 8 = byte #800
the last byte

  • total length = 100 bytes, header length = 20 bytes
    => data length = 100 - 20 = 80 bytes
    => the last byte is the byte #879

Q. Assume IP header is always 20 bytes. An IP packet has a size of 5140 bytes (includeing header). If dat link layer MTU is 1500 bytes, then how should the packet be fragmented?

A. 총 data = 5120, data 들어갈 수 있는거 : 1480.
=> 0 ~ 1479, 1480 ~ 2959, 2960 ~ 4439, 4440 ~ 5119
=> 1480, 1480, 1480, 680 (bytes)

0개의 댓글