개발 Dev/NETCONF, YANG

[YANG] 01. How to install sysrepo version 1.4 for YANG

BoBooBoo 2022. 1. 15. 20:54
반응형

Created: 2022. 01. 11. Wed.

Subject: #01. How to install Libyang1 for sysrepo (ver 1.4.x)

 

Previous article: 

2021.06.10 - [Dev/NETCONF, YANG] - [NETCONF/YANG] # 00. How to install Sysrepo, Netopeer2

 

[NETCONF/YANG] # 00. How to install Sysrepo, Netopeer2 for developing YANG and NETCONF

* This article was written on June 8, 2021. 1. Environment OS, Opensource for YANG and NETCONF Ubuntu 18.04 LTS on VirtualBoxUbuntu version higher than 18.04 may not work libyang (https://github.com..

boboob.tistory.com

 

In the previous article (above link), I explained how to install all the tools required for NETCONF development.

This article just explains how to install sysrepo version 1.4, a tool that can handle YANG.

 

 

After reading this article

- You can use sysrepo as a tool to use YANG.

 


What You Need (development environment)

- Oracle VM VirtualBOX 6.1.x

- Ubuntu 18.04 LTS Bionic Beaver (REQUIRED)

In Ubuntu 20.04 or higher, there is an issue and it may not work properly.

 


Contents

1. Install libyang1

2. Install sysrepo ver 1.4

 


Content

1. Install libyang1

(Caution) To use sysrepo version 1.4, you need to install libyang1.

The latest libyang master branch is libyang2. So, you need to install the library after changing branch to libyang1.

 

Install the required packages

A detailed description of each package is omitted. You will need admin permission to install the package. Use the "su" or "sudo" command.

apt install -y git gcc clang make cmake 
apt install -y doxygen graphviz cmocka-doc libcmocka-dev 
apt install -y libpcre2-dev libpcre3-dev libpcre3 bison flex pkg-config
apt install -y devscripts rpm debhelper valgrind expect shunit2

 

Check build requirement.

(1) C compiler

(2) cmake >= 2.8.12

(3) libpcre2 >= 10.21 (including devel package)

(4) (option) uncrustify >= 0.71

$ gcc --version
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0

$ cmake --version
cmake version 3.10.2

$ pcre2-config --version
10.31


how to install uncrustify (latest ver)

## I Use ~/workspace as the main directory.
$ mkdir ~/workspace
$ cd ~/workspace

## download source code at ~/workspace
$ git clone https://github.com/uncrustify/uncrustify.git
$ cd uncrustify

## build and install at ~/workspace/uncrustify/build
$ mkdir build
$ cd build
$ cmake ..
$ make && sudo make install
$ uncrustify -v
Uncrustify_d-0.74.0-104-6d5da5a0

 

 

Download source code and Build

I will download the source code to a directory called workspace (~/workspace). 

$ cd workspace

# At ~/workspace
$ git clone https://github.com/CESNET/libyang.git

$ cd libyang

 

The master branch of libyang points to the latest version source code, libyang2. To install sysrepo 1.4, we need libyang1, so check out to the origin/libyang1 branch. And build it.

## At ~/workspace/libyang
$ git branch --all
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/debian/master
  remotes/origin/devel
  remotes/origin/libyang1
...

$ git checkout -t origin/libyang1
$ git branch
* libyang1
  master

 

and Build it.

$ mkdir build
$ cd build

## At ~/workspace/libyang/build
$ cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ..
$ make && sudo make install

 

So, We can use libyang1 library to develop service related yang. All libyang functions are available via the main header:

#include <libyang/libyang.h>

 

To compile your program with libyang, it is necessary to link it with libyang using the following linker parameters:

-lyang

 


2. Install sysrepo ver 1.4

For now, we can install the sysrepo 1.4.

Download the sysrepo source code.

$ git clone https://github.com/sysrepo/sysrepo.git

$ cd sysrepo

 

 

Checkout to the sysrepo branch based on libyang1.

## At ~/workspace/sysrepo
$ git branch --all
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/debian/master
  remotes/origin/devel
  remotes/origin/legacy
  remotes/origin/libyang1
  remotes/origin/master
  
$ git checkout -t origin/libyang1
$ git branch
* libyang1
  master

 

Build it!

$ mkdir build

$ cd build

## At ~/workspace/sysrepo/build/.
$ cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ..

$ make && sudo make install

 

That it! We can use sysrepo 1.4. sysrepo.

sysrepo has sysrepoctl and sysrepocfg. Let's test it.

$ sysrepoctl --version
sysrepoctl - sysrepo YANG schema manipulation tool, compiled with libsysrepo v1.4.150 (SO v5.6.66)

$ sysrepocfg --version
sysrepocfg - sysrepo configuration manipulation tool, compiled with libsysrepo v1.4.150 (SO v5.6.66)

 

 

Reference

[1] https://github.com/uncrustify/uncrustify

[2] https://github.com/CESNET/libyang

[3] https://github.com/sysrepo/sysrepo

 

 

Thank you.

반응형