This page describes how to generate NETCONF emulator from your own YANG.

1. Generate Netconf emulator via Netopeer2 (Commercial license unlimited)

1.1 Download NETCONF emulator template via command:

git clone -b netconf-template https://github.com/opennetworkinglab/ODTN-emulator.git && cd ODTN-emulator/emulator-oc-cassini

The directory tree is as listed:

.
├── Dockerfile
├── config
│   ├── init-components.xml
│   └── init-terminal-device.xml
├── script
│   ├── config-power.xml
│   ├── get-pip.py
│   └── push-data.sh
└── yang
    └── openconfig-odtn
        ├── iana-if-type.yang
        ├── ietf-interfaces.yang
        ├── ietf-yang-types@2013-07-15.yang
        ├── import-yangs.sh
        ├── openconfig-alarm-types.yang
        ├── openconfig-extensions.yang
        ├── openconfig-if-ethernet.yang
        ├── openconfig-interfaces.yang
        ├── openconfig-platform-linecard.yang
        ├── openconfig-platform-port.yang
        ├── openconfig-platform-transceiver.yang
        ├── openconfig-platform-types.yang
        ├── openconfig-platform.yang
        ├── openconfig-terminal-device.yang
        ├── openconfig-transport-line-common.yang
        ├── openconfig-transport-line-protection.yang
        ├── openconfig-transport-types.yang
        ├── openconfig-types.yang
        └── openconfig-yang-types.yang


1.2 Build your own Dockerfile based on the template

In Dockerfile, The software listed below are installed:

  • libssh (stable-0.8)
  • cmocka (cmocka-1.0.1)
  • libyang (v0.16-r3)
  • libnetconf2 (v0.12-r1)
  • sysrepo (v0.7.7)
  • Netopeer2 (v0.7-r1)

Then, some necessary things are listed at the bottom:

......
COPY yang /root/yang                                                     # Copy your own yang files into the image
......
    && ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key \          # Generate ssh-key for Netconf SSH connection
    && sh -c 'echo root:root | chpasswd' \                               # Set the username:password as root:root
    && cd /root/yang/openconfig-odtn && sh import-yangs.sh \             # Import your own yang files into Netconf storage
    && cd /root/script && python get-pip.py \                            # Install pip for python2.7.*
    && pip install netconf-console                                       # Install netconf-console as Netconf client
EXPOSE 830                                                               # Expose port 830 as Netconf listenning port
EXPOSE 22                                                                # (Optional) Expose port 22 as SSH remote login port
EXPOSE 8080                                                              # (Optional) Expose port 8080 as the default HTTP request port
WORKDIR /root                                                            # Set the default directory as /root
ENTRYPOINT ["sh", "/root/script/push-data.sh"]                           # Run push-data.sh when the container starts



You can put all the yang files under directory yang, which will be copied into the docker image.

1.3 Load the YANG files in script import-yangs.sh

While building the docker image, script import-yangs.sh is called to import yang models into Netconf datastore sysrepo as listed.

################################### Clean the default Yang models defined inside the sysrepo, in case of the conflictions ###################################
sysrepoctl --uninstall --module=iana-if-type --revision=2014-05-08
sysrepoctl --uninstall --module=ietf-ip revision=2014-06-16
sysrepoctl --uninstall --module=ietf-interfaces revision=2014-05-08
################################### Make some changes to skip parsing errors ###################################
cd /root/yang/openconfig-odtn
# Before importing, you need to remove the last augment block for
# "/oc-if:interfaces/oc-if:interface/oc-if:state" in openconfig-platform-transceiver.yang.
# Because it will cause parsing errors.
# line number between [481, 500]
sed -i '481,500d' openconfig-platform-transceiver.yang
################################### Install new yang files about openconfig ###################################
sysrepoctl --install --yang=ietf-interfaces.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=iana-if-type.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-extensions.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-types.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-yang-types.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-platform-types.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-transport-types.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-interfaces.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-if-ethernet.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-alarm-types.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-platform.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-platform-linecard.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-platform-port.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-platform-transceiver.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-terminal-device.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-transport-line-common.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-transport-line-protection.yang --owner=root:root --permissions=666

libyang  and sysrepo  are not very stable for YANG, and your own yang files may contains some special statements that cannot be recognized by libyang properly. You need to change some details to make your own yang files available in Netconf server.

After yang module installation, ssh into the docker container using the following command,

ssh into docker container
docker exec -it <container_name> /bin/bash

After ssh into the docker container, you can list modules as follows:


root@b2d61bf9014f:~# sysrepoctl -l
Sysrepo schema directory: /etc/sysrepo/yang/
Sysrepo data directory:   /etc/sysrepo/data/
(Do not alter contents of these directories manually)

Module Name                          | Revision   | Conformance | Data Owner          | Permissions | Submodules                    | Enabled Features
-----------------------------------------------------------------------------------------------------------------------------------------------
ietf-netconf-notifications           | 2012-02-06 | Installed   | root:root           | 666         |                               |
ietf-netconf                         | 2011-06-01 | Installed   | root:root           | 666         |                               | writable-running candidate rollback-on-error validate startup xpath url
ietf-netconf-acm                     | 2018-02-14 | Imported    |                     |             |                               |
nc-notifications                     | 2008-07-14 | Installed   | root:root           | 666         |                               |
notifications                        | 2008-07-14 | Installed   | root:root           | 666         |                               |
turing-machine                       | 2013-12-27 | Installed   | root:root           | 666         |                               |
ietf-netconf-with-defaults           | 2011-06-01 | Installed   |                     |             |                               |
ietf-netconf-monitoring              | 2010-10-04 | Installed   | root:root           | 666         |                               |
ietf-yang-library                    | 2018-01-17 | Installed   | root:root           | 666         |                               |
ietf-datastores                      | 2017-08-17 | Imported    |                     |             |                               |
ietf-interfaces                      | 2018-02-20 | Installed   | root:root           | 666         |                               |
iana-if-type                         | 2017-01-19 | Installed   |                     |             |                               |
openconfig-extensions                | 2017-04-11 | Installed   |                     |             |                               |
openconfig-types                     | 2018-05-05 | Installed   |                     |             |                               |
openconfig-yang-types                | 2018-04-24 | Installed   |                     |             |                               |
openconfig-platform-types            | 2018-05-05 | Installed   |                     |             |                               |
openconfig-transport-types           | 2018-05-16 | Installed   |                     |             |                               |
openconfig-alarm-types               | 2018-01-16 | Installed   |                     |             |                               |
openconfig-interfaces                | 2018-04-24 | Installed   | root:root           | 666         |                               |
openconfig-if-ethernet               | 2018-04-10 | Installed   |                     |             |                               |
openconfig-platform                  | 2018-06-03 | Installed   | root:root           | 666         |                               |
openconfig-platform-port             | 2018-01-20 | Installed   |                     |             |                               |
openconfig-platform-transceiver      | 2018-05-15 | Installed   |                     |             |                               |
openconfig-terminal-device           | 2017-07-08 | Installed   | root:root           | 666         |                               |
openconfig-platform-linecard         | 2017-08-03 | Installed   |                     |             |                               |
openconfig-transport-line-common     | 2017-09-08 | Installed   |                     |             |                               |
openconfig-transport-line-protection | 2017-09-08 | Installed   | root:root           | 666         |                               |


1.4 Start Netconf server in push-data.sh

In push-data.sh, you should put the data into sysrepo, and start Netconf server.

If you only want to get an available Netconf server and don't really care about the read-write permissions. We suggest strongly you use command "sed -i '/config false;/d' *.yang" to remove config-false statements, then uninstall the original modules and reinstall them. This operation could make all nodes of data tree writable. The demo is listed:

# Clean the yang space
sysrepoctl --uninstall --module=openconfig-terminal-device --revision=2017-07-08
sysrepoctl --uninstall --module=openconfig-platform-transceiver revision=2018-05-15
sysrepoctl --uninstall --module=openconfig-platform-port revision=2018-01-20
sysrepoctl --uninstall --module=openconfig-if-ethernet revision=2018-04-10
sysrepoctl --uninstall --module=openconfig-transport-line-common revision=2017-09-08
sysrepoctl --uninstall --module=openconfig-interfaces revision=2018-04-24
sysrepoctl --uninstall --module=openconfig-platform-linecard revision=2017-08-03
sysrepoctl --uninstall --module=openconfig-transport-line-protection revision=2017-09-08
sysrepoctl --uninstall --module=openconfig-platform revision=2018-06-13

cd /root/yang/openconfig-odtn
# Change a leafref to leaf with type uint32, because of parsing errors
sed -i '487,491d' openconfig-terminal-device.yang
sed -i '486a type uint32;' openconfig-terminal-device.yang
# Modify operational schema into configurable schema
sed -i '/config false;/d' openconfig-platform-transceiver.yang
sed -i '/config false;/d' openconfig-platform.yang
sed -i '/config false;/d' openconfig-terminal-device.yang

# Re-install modified yang files
# Start sysrepo
sysrepod
sysrepoctl --install --yang=openconfig-terminal-device.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-interfaces.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-if-ethernet.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-platform.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-platform-linecard.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-platform-port.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-platform-transceiver.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-transport-line-common.yang --owner=root:root --permissions=666
sysrepoctl --install --yang=openconfig-transport-line-protection.yang --owner=root:root --permissions=666


The benefit is that you don't need to develop an additional callback program to reply to the request for operational data. However, if you still want to develop it by yourself, please see https://github.com/sysrepo/sysrepo/blob/master/examples/oper_data_example.c.

In order to push data into sysrepo, you should first subscribe to the module where you plan to push to. For example, you should subscribe openconfig-platform if you want to push some data under openconfig-platform namespace:

cd /root/config
/root/sysrepo/build/examples/application_example openconfig-platform &

There are two ways to push data into sysrepo:

  • sysrepocfg: sysrepocfg is the configuration command about sysrepo, you could push init-components data via command like:
sysrepocfg --import=init-components.xml --format=xml openconfig-platform

netconf-console: netconf-console is a general Netconf client tool. We can use this command to import config-power XML data:

netconf-console --host 127.0.0.1 --port 830 -u root -p root --rpc=/root/script/config-power.xml

1.5. Testing via netconf-console

sysrepo and Netopeer2 provide some useful tools for Netconf testing, however, ouside the docker container, we still recommend netconf-console. You can find a set of examples here: PowerConfig configuration via ONOS CLI or Netconf.  The basic <get> and <edit-config> operations are executed by the files under directory emulator-test.

1.6.  Notes about modification in yang files under emulator-oc-cassini directory

You can find some notes about modification in yang files under emulator-oc-cassini yang files here in this link


  • No labels