Reference 1. Introduction 2. Device commands and NSO CLI commands 3. Adapting an existing NED - Step One 4. Adapting an existing NED - Step Two 5. Commands and Java correlation 6. Setting up a NED-instance 7. Debugging and trouble-shooting 1. Introduction This file lists the details which is not covered in the Article-Generic-NED-Development 2. Device commands and NSO CLI commands There is a mapping between NSO CLI commands, NED JAVA code and device commands: NSO CLI NED JAVA Device command -------------------------------------------------------------------------------------------------------------------------------------------------------- Fetch config from device sync-from show curl --user name:pass -H "Content-Type: application/json" -H "Accept: application/json" --request GET --url localhost:7990/rest/api/1.0/projects/ Create a project set ... curl --user name:pass -H "Content-Type: application/json" -H "Accept: application/json" commit prepare --request POST --data '{"name": "PROJECT_NAME", "key" : "PROJECT_KEY"}' --url localhost:7990/rest/api/1.0/projects/ Delete a project delete ... curl --user name:pass -H "Content-Type: application/json" -H "Accept: application/json" commit prepare --request DELETE --url localhost:7990/rest/api/1.0/projects/PROJECT_KEY It is the device command that changes for different devices. This means that to adapt the demo-ned, the first step is to modify what it sends to the device. 3. Adapting an existing NED - Step One This step is mandatory and it replaces what the NEDs sends to the device with what the new device expects. Only the java file JVXNedGeneric needs to be modified and the methods to be modified are: public void show(NedWorker worker, int th) throws NedException, IOException { private void edit(NedWorker worker, NedEditOp[] ops, StringBuilder dryRun, int th) throws Exception { When fetching config from a device the NED command sync-from needs to be issued. Sync-from will call show. When sending commands to the device the NED command commit needs to be issued. Commit will call prepare, which in turn will call edit to fetch the command to be sent. If just printing the commands to be sent is enough then the NED command commit dry-run needs to be issued. Commit dry-run will call prepareDry, which in turn will call edit to fetch the command to be sent. The key here is to: adapt show so that it issues the device commands which lists config. adapt edit so that it issues the correct command to either create, modify or delete config. 4. Adapting an existing NED - Step Two There are two NEDs with the same functionality but different names: demo-ned and device-test-ned. Device-test-ned is demo ned after the steps described in this section has been applied. This step is essentially finding a word and replacing it with another word. Some file renaming will also be needed. In our example we will do these replacements to adapt the demo-ned: GRX: replace with devname (use devname as real device name example) JVX/jvx: replace with dn (use dn as short form of the device name) DVX: replace with Cisco (vendor's name) All the paths below are relative to the NED directory which contains: ls CHANGES load-dir private-jar shared-jar doc-internal package-meta-data.xml README.md src Overview: 2.1. Updating the Java files 2.2. Updating the YANG files 2.3. Updating the package-meta-data file 2.4. Updating the src/Makefile 2.5. Updating the build file 4.1. Updating the Java files Adapt Java directory structure & rename JVXNedGeneric.java to dnNedGeneric.java mkdir -p src/java/src/com/tailf/packages/ned/dn/namespaces mv src/java/src/com/tailf/packages/ned/jvx/*.java src/java/src/com/tailf/packages/ned/dn mv src/java/src/com/tailf/packages/ned/dn/JVXNedGeneric.java src/java/src/com/tailf/packages/ned/dn/dnNedGeneric.java rm -rf src/java/src/com/tailf/packages/ned/jvx This output of ls is expected: ls src/java/src/com/tailf/packages/ned/dn dnNedGeneric.java JsonTransformer.java JsonXmlUtils.java namespaces RESTConnection.java 4.1.1 src/java/src/com/tailf/packages/ned/dn/JsonXmlUtils.java "jvx" package com.tailf.packages.ned.jvx; 4.1.2 src/java/src/com/tailf/packages/ned/dn/RESTConnection.java "jvx" package com.tailf.packages.ned.jvx; 4.1.3 src/java/src/com/tailf/packages/ned/dn/JsonTransformer.java: "jvx" package com.tailf.packages.ned.jvx; private static String PREFIX = "jvx:"; "GRX" xml = xml.replaceAll("GRX:", ""); 4.1.4 src/java/src/com/tailf/packages/ned/dn/dnNedGeneric.java "jvx" package com.tailf.packages.ned.jvx; import com.tailf.packages.ned.jvx.namespaces.*; private static final String PREFIX = "jvx:"; "JVX" public class JVXNedGeneric extends NedGenericBase { private static Logger logger = Logger.getLogger(JVXNedGeneric.class); public JVXNedGeneric(){ logger.debug("JVXNedGeneric constructor"); public JVXNedGeneric(String deviceId, JVXNedGeneric ned = new JVXNedGeneric(deviceId, data = data.replaceAll("<" + module + ">", "<" + module + " xmlns:" + tailfJVXNedGeneric.prefix + "=\"" + tailfJVXNedGeneric.uri + "\">"); data = data.replaceAll("<", "<" + tailfJVXNedGeneric.prefix + ":"); data = data.replaceAll("<" + tailfJVXNedGeneric.prefix + ":/", "", data = data.replaceAll("", data = data.replaceAll("<" + tailfJVXNedGeneric.prefix + ":" + rootTag + "/>", data = data.replaceAll("<" + tailfJVXNedGeneric.prefix + ":\\?xml", "NED package for DVX jvx com.tailf.packages.ned.jvx.JVXNedGeneric "JVX" com.tailf.packages.ned.jvx.JVXNedGeneric "GRX" GRX GRX GRX-id:GRX "DVX" NED package for DVX jvx DVX 4.4. Updating the build file 4.4.1 src/java/build.xml: "jvx" 4.5. Updating the src/Makefile 4.5.1 src/Makefile "jvx" JAVA_PACKAGE = com.tailf.packages.ned.jvx "JVX" $(NCSC) $(JFLAGS)/tailfJVXNedGenericStats.java $@ $(NCSC) $(JFLAGS)/tailfJVXNedGeneric.java $@ $(NCSC) $(JFLAGS)/tailfJVXNedGenericId.java $@ "GRX" YANG = yang/tailf-ned-GRX.yang \ yang/tailf-ned-GRX-id.yang \ yang/tailf-ned-GRX-stats.yang FXS = $(YANG_MODULES:yang/%.yang=ncsc-out/modules/fxs/%.fxs) ../load-dir/tailf-ned-GRX-meta.fxs ncsc-out/modules/fxs/tailf-ned-GRX-stats.fxs: yang/tailf-ned-GRX-stats.yang ../load-dir/tailf-ned-GRX-meta.fxs: yang/tailf-ned-GRX-meta.yang ncsc-out/modules/fxs/tailf-ned-GRX.fxs: yang/tailf-ned-GRX.yang ncsc-out/modules/fxs/tailf-ned-GRX-id.fxs: yang/tailf-ned-GRX-id.yang After doing all the updates above your NED is now adapted to the specific device 5. Setting up a NED-instance ncs-setup --package demo-ned --dest DEMO ncs_cli -u admin admin@ncs> configure admin@ncs% set devices device d1 device-type generic ned-id devname admin@ncs% set devices device d1 address 127.0.0.1 port 7990 admin@ncs% set devices device d1 state admin-state unlocked admin@ncs% set devices authgroups group g1 default-map remote-name name remote-password pass admin@ncs% set devices device d1 authgroup g1 admin@ncs% set java-vm java-logging logger com.tailf.packages.ned.dn level level-all admin@ncs% set devices device d1 trace raw admin@ncs% commit admin@ncs% 6. Commands and Java correlation admin@ncs% request devices device d1 sync-from calls the Java method show /** * NED show hook. Loads the config into CDB and CDB-OPER * @param worker * @param th * @throws NedException * @throws IOException */ @Override public void show(NedWorker worker, int th) admin@ncs% commit calls the java method prepare /** * NED prepare hook. * Responsible for applying the config diff on the device, by sending * the appropriate REST messages. * * @param worker - NED worker thread * @param ops - Config operations * @throws NedException * @throws IOException */ @Override public void prepare(NedWorker worker, NedEditOp[] ops) admin@ncs% commit dry-run outformat native /** * NED dry-run prepare hook. * Creates the REST messages to apply the config diff without actually * sending them to the device. * @param worker - worker thread * @param ops - Config operations * @throws NedException */ @Override public void prepareDry(NedWorker worker, NedEditOp[] ops) 7. Debugging and trouble-shooting These commands enables additional log files: admin@ncs% set java-vm java-logging logger com.tailf.packages.ned.dn level level-all (note that the com.tailf.packages.ned.dn points to the path with the java files) enables NED-INSTANCE/logs/ncs-java-vm.log admin@ncs% set devices device d1 trace raw (enabled the trace log) enables NED-INSTANCE/ned-devname-d1.trace To add a log entry into the ncs-java-vm.log one need to declare the logger private static Logger logger = Logger.getLogger(dnNedGeneric.class); (dnNedGeneric is the name of the Java file) and then write one of the below depending on the level desired logger.info("LOG MESSAGE"); logger.debug("LOG MESSAGE"); logger.trace("LOG MESSAGE"); logger.warn("LOG MESSAGE"); logger.error("LOG MESSAGE");