This walk-through is under construction.
In this walk-through we will design and implement programming language independent interface for management of test instruments specified with YANG models for 2 of the 13 Interchangeable Virtual Instrument classes:
* the IVI-4.4: IviDCPwr Class
* the IVI-4.6: IviSwtch Class
and demonstrate how to write testcases in Python.
Install the yuma123 NETCONF/YANG toolchainFollow the YANG/NETCONF on a Raspberry Pi with yuma123 walk-trough in order to install the relevant client and server applications with the necessary development packages.
YANG automated transactional network test interface for Pythonapt-get -y install wget gnupg
wget -O - http://lightside-instruments.com/repos/lightside-instruments.gpg.key | apt-key add -
apt-get -y install software-properties-common
echo "deb http://lightside-instruments.com/repos/apt/debian bullseye main" >> /etc/apt/sources.list
apt-get update
apt-get upgrade
apt-get -y install python3-tntapi
or follow this section to build and install from source.
YANG model and implementation for the IVI Switch classNow that we have a running NETCONF server we need to add a YANG module for management of the Switch/Relay actuator. We also need an implementation of the module written in C. If we do not have one the configuration changes will not have corresponding effect on the GPIO pins controlling the relays.
There is a template we can use as starting point:
git clone -b lsi-ivi-switch https://github.com/vlvassilev/yuma123-netconfd-module.git lsi-ivi-switch
autoreconf -i -f
./configure CFLAGS="-g -O0" CXXFLAGS="-g -O0" --prefix=/usr
make
make install
Now we can start netconfd with the new module:
netconfd --module=lsi-ivi-switch --no-startup --superuser=$USER
Programming the deviceHere is a program in python that connects to the relay actuator and turns the switch connecting C1 and A1 channels on and off. Usage:
python switch-loop-netconf.py --config=networks.xml --loops=10
switch-loop-netconf.py:
#!/usr/bin/python
from lxml import etree
import time
import sys, os
import argparse
import tntapi
import yangrpc
from yangcli import yangcli
namespaces={"nc":"urn:ietf:params:xml:ns:netconf:base:1.0",
"nd":"urn:ietf:params:xml:ns:yang:ietf-network",
"nt":"urn:ietf:params:xml:ns:yang:ietf-network-topology"}
args=None
global args
parser = argparse.ArgumentParser()
parser.add_argument("--config", help="Path to the netconf configuration *.xml file defining the configuration according to ietf-networks, ietf-networks-topology and netconf-node models e.g. ../networks.xml")
parser.add_argument('--loops', default=[],help="Loop count.")
args = parser.parse_args()
tree=etree.parse(args.config)
network = tree.xpath('/nc:config/nd:networks/nd:network', namespaces=namespaces)[0]
conns = tntapi.network_connect(network)
yconns = tntapi.network_connect_yangrpc(network)
for node_name in yconns.keys():
ok=yangcli(yconns[node_name],"""delete /channels""").xpath('./ok')
tntapi.network_commit(conns)
for i in range(1,int(args.loops)):
for node_name in yconns.keys():
ok=yangcli(yconns[node_name],"""create /channels/channel[name='a1']/connections -- connection='c1'""").xpath('./ok')
assert(len(ok)==1)
ok=yangcli(yconns[node_name],"""create /channels/channel[name='c1']""").xpath('./ok')
assert(len(ok)==1)
tntapi.network_commit(conns)
for node_name in yconns.keys():
ok=yangcli(yconns[node_name],"""delete /channels""").xpath('./ok')
assert(len(ok)==1)
tntapi.network_commit(conns)
Comments