Routing

데이터 패킷이 출발지에서 목적지까지 가장 효율적인 경로로 전달되도록 하는 과정.
네트워크 계층(3계층)에서 이루어지는 핵심 기능으로, 라우터가 패킷의 목적지 IP 주소를 확인하고 최적의 경로를 결정한다.

주요 특징

  1. 경로 결정: 라우팅 테이블을 참조하여 최적의 경로를 선택한다.
  2. 네트워크 연결: 서로 다른 네트워크를 연결하여 통신을 가능하게 한다.
  3. 패킷 전달: 선택된 경로를 통해 패킷을 다음 홉으로 전달한다.

중요성

  • 효율적인 데이터 전송을 가능하게 한다.
  • 네트워크의 안정성과 확장성을 향상시킨다.
  • 트래픽 관리와 로드 밸런싱에 기여한다.

라우팅 방식

  1. 정적 라우팅: 관리자가 수동으로 라우팅 테이블을 구성한다.

    • 장점: 간단하고 보안성이 높음
    • 단점: 네트워크 변화에 대응이 어려움
  2. 동적 라우팅: 라우팅 프로토콜을 사용하여 자동으로 경로를 업데이트한다.

    • 장점: 네트워크 변화에 유연하게 대응
    • 단점: 라우터에 부하를 줄 수 있음

라우팅의 핵심 요소들

  1. 라우팅 테이블
    라우터가 보유한 경로 정보 데이터베이스.
    다음과 같은 정보를 포함한다:

    1
    2
    3
    
    목적지 네트워크 | 다음 홉(Next Hop) | 인터페이스 | 메트릭(비용)
    192.168.1.0/24  | 10.0.0.1         | eth0       | 10
    172.16.0.0/16   | 10.0.0.2         | eth1       | 20
    
  2. 라우팅 프로토콜
    라우터들이 서로 경로 정보를 교환하는 방식을 정의한다.
    주요 프로토콜은 다음과 같다:

    • 내부 게이트웨이 프로토콜(IGP):
    • RIP (Routing Information Protocol)
      • 홉 카운트 기반의 간단한 프로토콜
      • 최대 15홉까지만 지원
      • 소규모 네트워크에 적합
    • OSPF (Open Shortest Path First)
      • 링크 상태 기반 프로토콜
      • Dijkstra 알고리즘 사용
      • 대규모 네트워크에 적합
  • 외부 게이트웨이 프로토콜(EGP):
    • BGP (Border Gateway Protocol)
      • 인터넷의 기반이 되는 프로토콜
      • 자율 시스템(AS) 간의 라우팅
      • 정책 기반 라우팅 지원

라우팅 알고리즘의 작동 방식

  1. 거리 벡터 알고리즘

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    
    def distance_vector_update(router, neighbors):
        for destination in all_networks:
            min_cost = float('inf')
            best_next_hop = None
    
            for neighbor in neighbors:
                cost = neighbor.distance_to(destination) + link_cost[router][neighbor]
                if cost < min_cost:
                    min_cost = cost
                    best_next_hop = neighbor
    
            routing_table[destination] = (best_next_hop, min_cost)
    
  2. 링크 상태 알고리즘

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    
    def dijkstra_shortest_path(graph, source):
        distances = {node: float('inf') for node in graph}
        distances[source] = 0
        pq = [(0, source)]
        previous = {node: None for node in graph}
    
        while pq:
            current_distance, current_node = heapq.heappop(pq)
    
            if current_distance > distances[current_node]:
                continue
    
            for neighbor, weight in graph[current_node].items():
                distance = current_distance + weight
    
                if distance < distances[neighbor]:
                    distances[neighbor] = distance
                    previous[neighbor] = current_node
                    heapq.heappush(pq, (distance, neighbor))
    
        return distances, previous
    

라우팅의 고급 개념들

  1. 정책 기반 라우팅
    특정 조건에 따라 다른 라우팅 결정을 내리는 방식:

    1
    2
    3
    4
    5
    
    def policy_based_routing(packet, policies):
        for policy in policies:
            if matches_policy(packet, policy):
                return policy.get_route()
        return default_route
    
  2. QoS 라우팅
    서비스 품질을 고려한 라우팅:

    1
    2
    3
    4
    5
    6
    7
    
    def qos_routing(packet, network_state):
        if packet.is_realtime():
            return find_lowest_latency_path()
        elif packet.requires_bandwidth():
            return find_highest_bandwidth_path()
        else:
            return find_default_path()
    

라우팅의 실제 구현 사례

  1. 엔터프라이즈 네트워크

    1
    2
    3
    4
    5
    
    # OSPF 구성 예시
    router ospf 1
     network 192.168.1.0 0.0.0.255 area 0
     network 172.16.0.0 0.0.255.255 area 1
     default-information originate
    
  2. 인터넷 서비스 제공자(ISP)

    1
    2
    3
    4
    5
    
    # BGP 구성 예시
    router bgp 65000
     neighbor 200.1.1.1 remote-as 65001
     neighbor 200.1.1.1 prefix-list CUSTOMER-IN in
     neighbor 200.1.1.1 prefix-list CUSTOMER-OUT out
    

최신 라우팅 트렌드

  1. SDN(Software-Defined Networking)
    중앙 집중식 컨트롤러를 통한 라우팅 제어:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    class SDNController:
        def update_flow_table(self, switch, flow_rules):
            for rule in flow_rules:
                switch.add_flow_rule(rule)
    
        def optimize_network_paths(self):
            current_state = self.get_network_state()
            optimal_paths = self.calculate_optimal_paths(current_state)
            self.update_network_paths(optimal_paths)
    
  2. 세그먼트 라우팅
    MPLS와 IPv6을 결합한 새로운 라우팅 패러다임:

    1
    2
    3
    4
    
    def segment_routing_encapsulation(packet, segment_list):
        for segment in reversed(segment_list):
            packet = add_segment_header(packet, segment)
        return packet
    

라우팅 문제 해결과 최적화

  1. 루프 방지

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    def prevent_routing_loops():
        # Split Horizon
        def advertise_routes(router, interface):
            routes = get_routes()
            return [r for r in routes if r.learned_from != interface]
    
        # Poison Reverse
        def poison_reverse(router, bad_route):
            advertise_route(bad_route, metric=INFINITY)
    
  2. 경로 최적화

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    
    def optimize_routing_paths(network):
        # 토폴로지 분석
        topology = analyze_network_topology(network)
    
        # 부하 분산
        load_balance = calculate_load_distribution(topology)
    
        # 경로 최적화
        optimal_paths = calculate_optimal_paths(topology, load_balance)
    
        return optimal_paths
    

용어 정리

용어설명

참고 및 출처