Try   HackMD

Setup Netconf Testing Environment

Install sysrepo

Prerequites

  1. gcc (>= 4.8.4)
  2. cmake (>= 2.8.12)
  3. libyang
  4. libpcre2-dev
  5. libpcre2

Installation

### 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
### install libpcre2 sudo apt-get install -y libpcre2-dev

Install Netopeer2

Prerequisite

  1. sysrepo
  2. libyang (installed in previous section)
  3. libnetconf2

Installation

### 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

### 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
sudo sysrepoctl -i my-base.yang
  • Prepare initial data
<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
sudo sysrepocfg -W create-object.xml --datastore startup --module my-base -f xml
  • Start up netopeer2-server
sudo netopeer2-server -d -v2
  • Start up netopeer2-cli and connect to server
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>