YANG for NSO

NSO 및 환경설정

  • Netsim
    • 시뮬레이션 장치로 NSO 패키지를 쉽게 테스트가 가능하다.
  • Yang Data 모델 다운
    mkdir ./tmp
    cp ${NCS_DIR}/src/ncs/yang/ietf-interfaces.yang  ${NCS_DIR}/src/ncs/yang/ietf-ip.yang ./tmp  
    curl -L https://raw.githubusercontent.com/YangModels/yang/main/standard/iana/iana-if-type%402023-01-26.yang > ./tmp/iana-if-type.yang
    ncs-make-package  --no-java --no-python --netconf-ned ./tmp  --dest ${NCS_RUN_DIR}/packages/interfaces  --build interfaces
  • 만약 NSO 패키지가 있으면 Netsim 장치 생성 가능
    ncs-netsim --dir ${NCS_RUN_DIR}/netsim create-network ${NCS_RUN_DIR}/packages/interfaces/ 1 ifs
  • 인스턴스 런타임 폴더 생성
    ncs-setup --dest ${NCS_RUN_DIR} --netsim-dir ${NCS_RUN_DIR}/netsim
  • 랩 환경 시작

    ncs-netsim --dir ${NCS_RUN_DIR}/netsim start
    ncs --cd ${NCS_RUN_DIR}

  • 초기 설정
    인터페이스 구성 만들기
    ncs-netsim --dir ${NCS_RUN_DIR}/netsim cli-c ifs0
    config
    interfaces interface GigabitEthernet1 enabled type ethernetCsmacd description "to port6.sandbox-backend" ipv4 address 10.10.20.175 netmask 255.255.255.0
    interfaces interface GigabitEthernet2 enabled type ethernetCsmacd description "to port6.sandbox-backend" ipv4 address 172.16.252.21 netmask 255.255.255.0
    interfaces interface GigabitEthernet3 enabled type ethernetCsmacd description "to port6.sandbox-backend" ipv4 address 172.16.252.25 netmask 255.255.255.0
    interfaces interface GigabitEthernet4 enabled type ethernetCsmacd description "to port6.sandbox-backend" ipv4 address 172.16.252.2 netmask 255.255.255.0
    interfaces interface GigabitEthernet5 enabled type ethernetCsmacd description "to port6.sandbox-backend" ipv4 address 172.16.252.10 netmask 255.255.255.0
    interfaces interface GigabitEthernet6 enabled type ethernetCsmacd description "to port6.sandbox-backend" ipv4 address 172.16.252.17 netmask 255.255.255.0
    interfaces interface Loopback0 disabled type softwareLoopback
    commit
    end
    exit 

CLI에서 API로

  • CLI 배경
    • 네트워킹 초창기에는 장치별 수동 구성 프로세스에 집중 및 수동 구성의 관리 편이성
    • 인간이 읽고 해석하기 편함을 추구
  • CLI 스크립팅의 단점
    • 트랜잭션 관리 부족
    • 체계적인 오류 관리 부족
    • 변화하는 명령구조 및 구문 등에 대한 한계
    • CLI를 이용해 Netsim을 확인할 때 과정의 복잡 ex) 올바른 위치, 소프트웨어 업데이트 등으로 인한 CLI 출력 변경 
  • SNMP(Simple Network Management Protocl)
    • 장치의 변경 및 기계 중심적인 상호작용을 가능하게 함
    • 성능 및 어플리케이션에서 사용
    • UDP 프로토콜 사용과 검색기능이 존재하지 않음
  • API란?
    • 기기의 기능을 외부에 노출하고 두 소프트웨어가 서로 통신하는 인터페이스
    • API를 통해 정보 제공 및 작업 수행이 가능
  • API 특징
    • 양쪽에서 모두 이해할 수 잇는 형식으로 인코딩
    • 장치 간에 전송되는 데이터의 정확한 구조와 의미를 정의
    • 데이터는 안정적이고 보안된 방식으로 장치 간에 전송
  • 부호화
    • 자유형 텍스트를 기기가 이해할 수 있는 XML, JSON 형식으로 변경
    • XML 형식의 출력을 위한 코드
      태그 검색이 가능
      show running-config interfaces interface Loopback0 | display xml | nomore
  • 데이터 모델
    • 기계가 이해하기 위해선 어떤 데이터를 인코딩해야 하는가?의 규칙을 정하기 위해 나옴
    • "무언가"를 설명하는 잘 이해되고 합의된 방법
    • 데이터 속성 정의 및 질문
      • 유효한 VLAN ID의 범위는 무엇입니까?
      • VLAN 이름에 공백이 들어갈 수 있나요?
      • 값을 열거하고 관리자 상태에 대해 "위" 또는 "아래"만 지원해야 합니까?
      • 값은 문자열이어야 하나요, 아니면 정수여야 하나요?

표준화된 솔루션

  • NETCONF
    • SOAP, REST, JSON-RPC 등을 통해 인터페이스 자동화가 가능했지만 통신규약이 필요
    • SNMP를 대체하고 SNMP 단점 보완
    • 네트워크 장치 관리, 구성데이터 검색 등을 수행하는 구성관리 프로토콜
    • 보안 통신을 위해 SSH 사용, 데이터는 XML 인코딩
    • NETCONF를 사용한 인터페이스 구성 데이터 읽기
      netconf-console --user admin --password admin --host 127.0.0.1 --port 12022 --get -x "/interfaces/interface[name='GigabitEthernet1']"
    • NETCONF NSO에서 사용
      1. cli 접속 및 장치 동기화
        ncs_cli -C -u admin
        devices device ifs0 sync-from
        exit
      2. NETCONF를 사용해 장치구성 엑세스
        netconf-console --user admin --password admin --host 127.0.0.1 --port 2022 --get -x "/devices/device[name='ifs0']/config/interfaces/interface[name='GigabitEthernet1']"
  • Yang
    • 데이터 모델링 언어로 데이터를 정의하기 위해 사용
    • 구성 및 상태 데이터 모델을 생성하는데 사용되며, 사람이 읽을 수 있는 구조화된 형식
    • 이더넷 인터페이스 설명
  • RESTCONF
    • 초기 NETCONF를 이용하려 했지만 IT 산업 전반에 REST가 인기를 얻으며 표준화됨
    • Yang 언어로 작동
    • 사용예시
      GigabitEthernet1 인터페이스 검색 (JSON, XML 둘 다 가능)
      curl -X "GET" -H "Accept: application/yang-data+xml" -u "admin:admin" "http:/localhost:8080/restconf/data/tailf-ncs:devices/device=ifs0/config/ietf-interfaces:interfaces/interface=GigabitEthernet1"
  • NETCONF와 RESTCONF를 사용한 루프백 인터페이스 생성 및 삭제
    • NETCONF 인터페이스 구성
      netconf-console --user admin --password admin --host 127.0.0.1 --port 12022 --db=candidate --edit-config=- << EOF
      <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
        <interface>
          <name>Loopback100</name>
          <description>Configured by NETCONF</description>
          <type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:softwareLoopback</type>
          <enabled>true</enabled>
        </interface>
      </interfaces>
      EOF
      netconf-console --user admin --password admin --host 127.0.0.1 --port 12022 --commit
      CLI를 통한 장치 구성 확인
      ncs-netsim --dir ${NCS_RUN_DIR}/netsim cli-c ifs0
      show running-config interfaces interface Loopback100
      exit
    • RESTCONF 인터페이스 구성
      RESTCONF 사용을 위한 CLI 접속 및 NSO 장치 동기화
      ncs_cli -C -u admin
      devices device ifs0 sync-from
      exit
      loopback101 인터페이스 구성
      curl -k -X POST "http:/localhost:8080/restconf/data/tailf-ncs:devices/device=ifs0/config/ietf-interfaces:interfaces/" \
      -H "Content-Type: application/yang-data+json" -u "admin:admin" \
      -d @- << 'EOF'
      {
        "ietf-interfaces:interface": {
          "name": "Loopback101",
          "description": "Configured by RESTCONF",
          "type": "iana-if-type:softwareLoopback",
          "enabled": true
        }
      }
      EOF



NSO에 YANG 모델 추가

  • 기본적으로 NSO 시스템에는 다양한 YANG 모델이 포함되어 있으며, 사용자 정의 패키지를 추가해 시스템 더욱 확장 가능
  • NSO 인터페이스 패키지 추가
    git clone https://github.com/CiscoDevNet/nso-lab-files.git ${NCS_RUN_DIR}/lab-files
  • NSO는 기본적으로 $(NCS_RUN_DIR)의 하위 디렉토리에서 패키지를 로드
    cp -a ${NCS_RUN_DIR}/lab-files/yang-nso-101/custom-yang-package ${NCS_RUN_DIR}/packages/
    이를 사용하기 위해 바이너리 형태로 컴파일
    make -C ${NCS_RUN_DIR}/packages/custom-yang-package/src/ all
    NSO 인스턴스 재시작을 통해 적용
    ncs --cd ${NCS_RUN_DIR} --stop
    ncs --cd ${NCS_RUN_DIR} --with-package-reload