---
# System prepended metadata

title: Setup Netconf Testing Environment

---

# Setup Netconf Testing Environment

[TOC]

## Install sysrepo

### Prerequites
1. gcc (>= 4.8.4)
2. [cmake](https://cmake.org/download/) (>= 2.8.12)
3. [libyang](https://github.com/CESNET/libyang)
4. libpcre2-dev
5. libpcre2

### Installation

```shell=
### clone git repo
git clone https://github.com/sysrepo/sysrepo.git
### build sysrepo
mkdir sysrepo/build && cd sysrepo/build
cmake ..
make
sudo make install
### load shared library object
sudo ldconfig
```

```shell=
### install libpcre2
sudo apt-get install -y libpcre2-dev
```

## Install Netopeer2

### Prerequisite

1. sysrepo
2. libyang (installed in previous section)
3. [libnetconf2](https://github.com/CESNET/libnetconf2)

### Installation

```shell=
### clone git repo
git clone https://github.com/CESNET/netopeer2.git
### build & install
cd netopeer2; mkdir build; cd build
cmake ..
make 
sudo make install
### load library
sudo ldconfig
```

## Test

### Start netconf server

```shell=
### one terminal
sudo netopeer2-server -d -v2
### another terminal
sudo netopeer2-cli
> connect --host localhost --login <user> --port 830
### if login succeed
> get-config --source running
```

### Create Custom YANG Module
* create a YANG module
```
module my-base {
    yang-version 1.1;
    namespace "http://chih-hsi-chen.com.tw/ns/yang/my-base";
    prefix mb;

    organization "National Yang Ming Chiao Tung University";
    contact "Hello Yang";
    description "This yang module is for testing and a basic example";

    typedef phonenumber {
        type string {
            pattern "[0-9]{5}";
        }
        description "Phone Number";
    }

    container people {
        config true;
        leaf name {
            type string;
            mandatory true;

        }
        leaf phone {
            type phonenumber;
            mandatory true;
        }
    }
}
```
* Install module by `sysrepoctl`
```shell=
sudo sysrepoctl -i my-base.yang
```
* Prepare initial data
```xml=
<people xmlns="http://chih-hsi-chen.com.tw/ns/yang/my-base">
    <name>Jack</name>
    <phone>01234</phone>
</people>
```
Here, we create a .xml file named `create-object.xml`

* Apply config to `startup datastore` by `sysrepocfg`
```shell=
sudo sysrepocfg -W create-object.xml --datastore startup --module my-base -f xml
```

* Start up netopeer2-server
```shell=
sudo netopeer2-server -d -v2
```
* Start up netopeer2-cli and connect to server
```shell=
netopeer2-cli
### port option can be ignored
> connect --host localhost --login root [--port 830]
> get-config --source running
```
You should see the output will be:
```
<data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  ...
  <people xmlns="http://chih-hsi-chen.com.tw/ns/yang/my-base">
    <name>Jack</name>
    <phone>01234</phone>
  </people>
</data>
```