Junos® OS
NETCONF Java Toolkit Developer Guide
Published
2023-12-15
Juniper Networks, Inc.
1133 Innovaon Way
Sunnyvale, California 94089
USA
408-745-2000
www.juniper.net
Juniper Networks, the Juniper Networks logo, Juniper, and Junos are registered trademarks of Juniper Networks, Inc.
in the United States and other countries. All other trademarks, service marks, registered marks, or registered service
marks are the property of their respecve owners.
Juniper Networks assumes no responsibility for any inaccuracies in this document. Juniper Networks reserves the right
to change, modify, transfer, or otherwise revise this publicaon without noce.
Junos® OS NETCONF Java Toolkit Developer Guide
Copyright © 2023 Juniper Networks, Inc. All rights reserved.
The informaon in this document is current as of the date on the tle page.
YEAR 2000 NOTICE
Juniper Networks hardware and soware products are Year 2000 compliant. Junos OS has no known me-related
limitaons through the year 2038. However, the NTP applicaon is known to have some diculty in the year 2036.
END USER LICENSE AGREEMENT
The Juniper Networks product that is the subject of this technical documentaon consists of (or is intended for use
with) Juniper Networks soware. Use of such soware is subject to the terms and condions of the End User License
Agreement ("EULA") posted at hps://support.juniper.net/support/eula/. By downloading, installing or using such
soware, you agree to the terms and condions of that EULA.
ii
Table of Contents
About This Guide | v
1
Overview
NETCONF XML Management Protocol and Junos XML API Overview | 2
NETCONF Java Toolkit Overview | 3
2
Install the NETCONF Java Toolkit
Download and Install the NETCONF Java Toolkit | 7
Downloading the NETCONF Java Toolkit | 7
Installing the NETCONF Java Toolkit | 7
Sasfying Requirements for SSHv2 Connecons | 8
3
NETCONF Java Toolkit Classes
NETCONF Java Toolkit Classes | 10
NETCONF Java Toolkit Class: Device | 10
NETCONF Java Toolkit Class: NetconfSession | 12
NETCONF Java Toolkit Class: XML | 13
NETCONF Java Toolkit Class: XMLBuilder | 19
4
Create and Execute NETCONF Java Applicaons
Create and Execute a NETCONF Java Applicaon | 23
Creang a NETCONF Java Toolkit Program File | 23
Compiling and Execung a NETCONF Java Toolkit Program File | 25
Use the NETCONF Java Toolkit to Perform Operaonal Tasks | 26
Use Device Object Methods to Execute RPCs and Operaonal Commands | 26
Example: NETCONF Java Applicaon for Execung an Operaonal Request RPC | 28
Requirements | 29
Overview | 29
Conguraon | 29
iii
Vericaon | 32
Troubleshoong | 33
Example: NETCONF Java Applicaon for Execung CLI Commands | 34
Requirements | 35
Overview | 35
Conguraon | 35
Vericaon | 37
Example: NETCONF Java Applicaon for Prinng Component Temperatures | 39
Requirements | 39
Overview | 39
Conguraon | 40
Vericaon | 42
Use the NETCONF Java Toolkit to Perform Conguraon Tasks | 44
Use Device Object Methods to Load Conguraon Changes | 44
Example: NETCONF Java Applicaon for Loading and Comming a Conguraon | 46
Requirements | 47
Overview | 47
Conguraon | 48
Vericaon | 50
Troubleshoong | 51
Example: NETCONF Java Applicaon for Loading Set Conguraon Commands | 52
Requirements | 52
Overview | 52
Conguraon | 53
Vericaon | 56
Use the NETCONF Java Toolkit to Parse an RPC Reply | 58
Troubleshoot Excepon Errors in a NETCONF Java Applicaon | 61
Troubleshoong Connecon Errors: Socket Timed Out | 62
Troubleshoong Connecon Errors: No Connecon | 63
Troubleshoong Authencaon Errors | 64
Troubleshoong NETCONF Session Errors | 65
iv
About This Guide
Use this guide to create Java applicaons that use NETCONF to remotely operate, congure, and
monitor devices running Junos OS. This guide supports NETCONF Java Toolkit Release 1.0.1 and earlier.
RELATED DOCUMENTATION
NETCONF Java Toolkit Soware
Day One: Navigang the Junos XML Hierarchy
v
1
CHAPTER
Overview
NETCONF XML Management Protocol and Junos XML API Overview | 2
NETCONF Java Toolkit Overview | 3
NETCONF XML Management Protocol and Junos
XML API Overview
The NETCONF XML management protocol is an Extensible Markup Language (XML)-based protocol that
client applicaons use to manage the conguraon on roung, switching, and security devices. It uses
an XML-based data encoding for the conguraon data and remote procedure calls (RPCs). The
NETCONF protocol denes basic operaons that are equivalent to conguraon mode commands in the
CLI. Applicaons use the protocol operaons to display, edit, and commit conguraon statements
(among other operaons), just as administrators use CLI conguraon mode commands to perform
those operaons.
The Junos XML API is an XML representaon of Junos conguraon statements and operaonal mode
commands. When the client applicaon manages a Junos device, Junos XML conguraon tag elements
are the content to which the NETCONF XML protocol operaons apply. Junos XML operaonal tag
elements are equivalent in funcon to operaonal mode commands in the CLI, which administrators use
to retrieve status informaon for devices running Junos OS.
The NETCONF XML management protocol is described in RFC 6241,
Network Conguraon Protocol
(NETCONF)
, which is available at hps://tools.ie.org/html/rfc6241.
Client applicaons request informaon and change the conguraon on a switch, router, or security
device by encoding the request with tag elements from the NETCONF XML management protocol and
Junos XML API and sending it to the NETCONF server on the device. On Junos devices, the NETCONF
server is integrated into the Junos operang system and does not appear as a separate entry in process
lisngs. The NETCONF server directs the request to the appropriate soware modules within the
device, encodes the response in NETCONF and Junos XML API tag elements, and returns the result to
the client applicaon.
For example, to request informaon about the status of a device’s interfaces, a client applicaon sends
the Junos XML API <get-interface-information> request tag. The NETCONF server gathers the informaon
from the interface process and returns it in the Junos XML API <interface-information> response tag
element.
You can use the NETCONF XML management protocol and Junos XML API to congure Junos devices
or to request informaon about the device conguraon or operaon. You can write client applicaons
to interact with the NETCONF server, and you can also use the NETCONF XML protocol to build
custom end-user interfaces for conguraon and informaon retrieval and display, such as a Web
browser-based interface.
2
RELATED DOCUMENTATION
Advantages of Using the NETCONF XML Management Protocol and Junos XML API
XML and Junos OS Overview
XML Overview
NETCONF Java Toolkit Overview
IN THIS SECTION
NETCONF Java Toolkit Overview | 3
Benets of the NETCONF Java Toolkit | 5
The NETCONF Java toolkit provides an object-oriented interface for communicang with a NETCONF
server. The toolkit enables programmers familiar with the Java programming language to create Java
applicaons to easily connect to a device, open a NETCONF session, construct conguraon hierarchies
in XML, and create and execute operaonal and conguraon requests.
NETCONF Java Toolkit Overview
The NETCONF Java toolkit provides classes with methods that implement the funconality of the
NETCONF protocol operaons dened in RFC 4741. All basic protocol operaons are supported. The
NETCONF XML management protocol uses XML-based data encoding for conguraon data and
remote procedure calls. The toolkit provides classes and methods that aid in creang, modifying, and
parsing XML.
The NETCONF Java toolkit has four basic classes, which are described in Table 1 on page 4.
3
Table 1: NETCONF Java Toolkit Classes
Class Summary
Device Denes the device on which the NETCONF server runs, and represents the SSHv2 connecon
and default NETCONF session with that device.
NetconfSession Represents a NETCONF session established with the device on which the NETCONF server
runs.
XMLBuilder Creates XML-encoded data.
XML XML-encoded data that represents an operaonal or conguraon request or conguraon
data.
A
conguraon management server
is generally a PC or workstaon that is used to congure a router,
switch, or security device remotely. The communicaon between the conguraon management server
and the NETCONF server through the NETCONF Java toolkit involves:
Establishing a NETCONF session over SSHv2 between the conguraon management server and the
NETCONF server.
Creang RPCs corresponding to requests and sending these requests to the NETCONF server.
Receiving and processing the RPC replies from the NETCONF server.
To use the NETCONF Java toolkit, you must install the toolkit and add the .jar path to your CLASSPATH.
For more informaon about installing the NETCONF Java toolkit, see "Download and Install the
NETCONF Java Toolkit" on page 7.
Once the toolkit is installed, you connect to a device, create a NETCONF session, and execute
operaons by adding the associated code to a Java program le, which is then compiled and executed.
For more informaon about creang NETCONF Java toolkit programs, see "Create and Execute a
NETCONF Java Applicaon" on page 23.
NOTE: Juniper Networks devices running Junos OS Release 7.5R1 or later support the
NETCONF XML management protocol.
4
Benets of the NETCONF Java Toolkit
NETCONF Java Toolkit provides the following benets:
Enables Java applicaons to access to the Junos XML API
Enables Java programmers to quickly start using the NETCONF and Junos XML API to manage and
congure roung, switching, and security devices running Junos OS
Ability to create custom, reusable applicaons to perform and automate operaonal and
conguraon tasks
RELATED DOCUMENTATION
NETCONF Java Toolkit Classes | 10
NETCONF XML Management Protocol and Junos XML API Overview | 2
Download and Install the NETCONF Java Toolkit | 7
Create and Execute a NETCONF Java Applicaon | 23
5
2
CHAPTER
Install the NETCONF Java Toolkit
Download and Install the NETCONF Java Toolkit | 7
Download and Install the NETCONF Java Toolkit
SUMMARY
Download and install NETCONF Java Toolkit Release
1.0.1 or earlier.
IN THIS SECTION
Downloading the NETCONF Java
Toolkit | 7
Installing the NETCONF Java Toolkit | 7
Sasfying Requirements for SSHv2
Connecons | 8
A
conguraon management server
is a PC or workstaon that is used to congure a router, switch, or
security device remotely. To use the NETCONF Java toolkit, download and install the toolkit on the
conguraon management server. The toolkit contains the Netconf.jar library, which is compable with
Java Version 1.4 and later.
NOTE: The instrucons in this secon apply to NETCONF Java Toolkit Release 1.0.1 and earlier.
To install later releases, see the README.md le in the netconf-java GitHub repository.
Downloading the NETCONF Java Toolkit
To download the NETCONF Java toolkit to the conguraon management server:
1. Access the GitHub download page at hps://github.com/Juniper/netconf-java/releases .
2. Download the Netconf.jar le.
Installing the NETCONF Java Toolkit
To install the NETCONF Java toolkit on the conguraon management server:
1. Include the Netconf.jar le in the CLASSPATH of your local Java development environment.
2. Ensure SSHv2/NETCONF connecvity to the device on which the NETCONF server is running.
7
Sasfying Requirements for SSHv2 Connecons
The NETCONF server communicates with client applicaons within the context of a NETCONF session.
The server and client explicitly establish a connecon and session before exchanging data, and close the
session and connecon when they are nished.
The NETCONF Java toolkit accesses the NETCONF server using the SSH protocol and uses the standard
SSH authencaon mechanism. To establish an SSHv2 connecon with a device running Junos OS, you
must ensure that the following requirements are met:
The client applicaon has a user account and can log in to each device where a NETCONF session
will be established.
The login account used by the client applicaon has an SSH public/private key pair or a text-based
password.
The client applicaon can access the public/private keys or text-based password.
The NETCONF service over SSH is enabled on each device where a NETCONF session will be
established.
For informaon about enabling NETCONF on a device running Junos OS and sasfying the
requirements for establishing an SSH session, see the NETCONF XML Management Protocol Developer
Guide.
For informaon about NETCONF over SSH, see RFC 4742,
Using the NETCONF Conguraon Protocol
over Secure SHell (SSH)
, which is available at hp://www.ie.org/rfc/rfc4742.txt .
RELATED DOCUMENTATION
Create and Execute a NETCONF Java Applicaon | 23
NETCONF Java Toolkit Overview | 3
NETCONF XML Management Protocol and Junos XML API Overview
8
3
CHAPTER
NETCONF Java Toolkit Classes
NETCONF Java Toolkit Classes | 10
NETCONF Java Toolkit Classes
SUMMARY
NETCONF Java Toolkit classes supported in Releases
1.0.1 and earlier.
IN THIS SECTION
NETCONF Java Toolkit Class: Device | 10
NETCONF Java Toolkit Class:
NetconfSession | 12
NETCONF Java Toolkit Class: XML | 13
NETCONF Java Toolkit Class:
XMLBuilder | 19
NETCONF Java Toolkit Class: Device
A net.juniper.netconf.Device object represents an SSHv2 connecon and a default NETCONF session
between the conguraon management server and the device on which the NETCONF server resides.
When creang a Device object, you must provide the IP address or hostname and the authencaon
details to create the SSHv2 connecon. Authencaon can be user-password based or RSA/DSA key-
based. You also have the opon of specifying the port number for the SSHv2 connecon and the client
capabilies to send to the NETCONF server.
The constructor syntax is:
Device (String
hostname
, String
login
, String
password
, String
pemKeyFile
)
Device (String
hostname
, String
login
, String
password
, String
pemKeyFile
, int
port
)
Device (String
hostname
, String
login
, String
password
, String
pemKeyFile
,
ArrayList
capabilities
)
Device (String
hostname
, String
login
, String
password
, String
pemKeyFile
, int
port
,
ArrayList
capabilities
)
The constructor parameters are:
10
hostname—(Required) IP address or hostname of the device on which the NETCONF server is running
and to which to connect via SSHv2.
login—(Required) Username for the login account on the device on which the NETCONF server is
running.
password—(Required) Password for either user password-based authencaon or key-based
authencaon. If no password is required for key-based authencaon, pass this argument as null.
pemKeyFile—(Required) Path of the le containing the DSA/RSA private key in PEM format for key-
based authencaon. For user password-based authencaon, pass this argument as null.
port—(Oponal) Port number on which to establish the SSHv2 connecon. The default port is 830. If
you are connecng to a device that is congured for NETCONF over SSH on a port other than the
default port, you must specify that port number in the arguments.
capabilities—(Oponal) Client capabilies to be communicated to the NETCONF server, if the
capabilies are other than the default capabilies.
The default capabilies sent to the NETCONF server are:
urn:ietf:params:xml:ns:netconf:base:1.0
urn:ietf:params:xml:ns:netconf:base:1.0#candidate
urn:ietf:params:xml:ns:netconf:base:1.0#confirmed-commit
urn:ietf:params:xml:ns:netconf:base:1.0#validate
urn:ietf:params:xml:ns:netconf:base:1.0#url?protocol=http,ftp,file
The general syntax for creang a Device object is:
Device
device_name
= new Device (String
hostname
, String
login
, String
password
, String
pemKeyFile
, <int
port
>, <ArrayList
capabilities
>)
By default, a NetconfSession object is created when you create a new instance of Device and connect to a
NETCONF server. Once you have created a Device object, you can perform NETCONF operaons.
Examples
The following example creates a Device object with an authencated SSHv2 connecon to IP address
10.10.1.1. The connecon uses user password-based authencaon with the login name “admin” and
11
the password “PaSsWoRd”. When the connect() method is called, it connects to the device and
automacally establishes a default NETCONF session.
Device my_device = new Device("10.10.1.1", "admin", "PaSsWoRd", null);
my_device.connect();
To create a Device object with a NETCONF-over-SSH connecon on port 49000 instead of the default
port 830, add the port number to the constructor arguments.
Device my_device = new Device("10.10.1.1", "admin", "PaSsWoRd", null, 49000);
The default meout value for connecng to the device is 5000 milliseconds. To set the meout value to
a dierent interval, call the setTimeOut() method on the device object.
NETCONF Java Toolkit Class: NetconfSession
A net.juniper.netconf.NetconfSession object represents the NETCONF session between the conguraon
management server and the device on which the NETCONF server resides.
By default, a NETCONF session is created when you create a new instance of Device and connect to a
NETCONF server, so you do not need to explicitly create a NetconfSession object. You can perform the
NETCONF operaons directly from the Device object by calling the associated methods.
However, there might be mes when you need mulple NETCONF sessions on the same SSHv2
connecon. To create mulple sessions, call the createNetconfSession() method on the Device object as
shown in the following example:
Device device = new Device("10.10.1.1", "admin", "PaSsWoRd", null);
device.connect();
NetconfSession second_session = device.createNetconfSession();
Once you create an addional NETCONF session, you call the NETCONF operaon methods for the
new NetconfSession object in the same way as you call them for the Device object.
The Device and NetconfSession classes contain many idencal methods, which perform NETCONF
operaons such as execung remote procedure calls (RPCs) and performing conguraon changes.
When you call a method on the Device object, it acts on the default NETCONF session. When you call a
method on any addional NetconfSession object, it acts on that NETCONF session.
Example: Creang Mulple NETCONF Sessions
12
In the following example, the code snippet creates a new Device object. When the connect() method is
called, the program connects to the remote device and establishes a default NETCONF session. The
program creates a second NetconfSession object, second_session. Calling device.getSessionID() returns the
session ID of the default NETCONF session, and calling second_session.getSessionID() returns the session
ID of the second NETCONF session.
// Create a device object and a default NETCONF session
Device device = new Device("10.10.1.34", "admin", "PaSsWoRd", null);
device.connect();
// Create an additional NETCONF session
NetconfSession second_session = device.createNetconfSession();
// There are two independent NETCONF sessions
String default_session_id = device.getSessionID();
String second_session_id = second_session.getSessionID();
NETCONF Java Toolkit Class: XML
A net.juniper.netconf.XML object represents XML-encoded data and provides methods to modify and parse
the XML. The XML object internally maintains an org.w3c.dom.Document object, corresponding to the XML
data it represents.
It is recommended that you work with the XML object to create new conguraons, remote procedure
calls (RPCs), or any XML-based data. Using an XML object, you can easily add, delete, or modify
elements and aributes. To facilitate modicaon of XML content, the XML object maintains an ‘acve
element, which represents the hierarchy level exposed for modicaon.
To create an XML object, you rst create an XMLBuilder object and construct the inial XML hierarchy. The
XMLBuilder methods return an XML object on which you can then build. This makes it convenient to
create XML-based conguraons and RPCs and also parse the XML-based replies received from the
NETCONF server.
Example: Creang a Conguraon Hierarchy
This example creates the following sample XML conguraon hierarchy. The steps used to create the
conguraon hierarchy are outlined in Table 2 on page 14.
<configuration>
<security>
13
<policies>
<policy>
<from-zone-name>trust</from-zone-name>
<to-zone-name>untrust</to-zone-name>
<policy>
<name>my-sec-policy</name>
<match>
<source-address>any</source-address>
<destination-address>any</destinationaddress>
<application>junos-ftp</application>
<application>junos-ntp</application>
<application>junos-ssh</application>
</match>
<then>
<permit>
</permit>
</then>
</policy>
</policy>
</policies>
</security>
</configuration>
Table 2:
Creang a Conguraon Hierarchy with XMLBuilder and XML Objects
Java Code Resulng Hierarchy
// Create an XMLBuilder object and a 3-level
hierarchy
XMLBuilder builder = new XMLBuilder();
XML policy =
builder.createNewCong("security","policies","p
olicy");
<configuration>
<security>
<policies>
<policy>
</policy>
</policies>
</security>
</configuration>
14
Table 2: Creang a Conguraon Hierarchy with XMLBuilder and XML Objects
(Connued)
Java Code Resulng Hierarchy
// Append nodes at the 'policy' level
policy.append("from-zone-name","trust");
policy.append("to-zone-name","untrust");
<configuration>
<security>
<policies>
<policy>
<from-zone-name>trust</from-zone-name>
<to-zone-name>untrust</to-zone-name>
</policy>
</policies>
</security>
</configuration>
// Create a new hierarchy level for the rst
policy
XML policyOne = policy.append("policy");
policyOne.append("name","my-sec-policy");
<configuration>
<security>
<policies>
<policy>
<from-zone-name>trust</from-zone-name>
<to-zone-name>untrust</to-zone-name>
<policy>
<name>my-sec-policy</name>
</policy>
</policy>
</policies>
</security>
</configuration>
15
Table 2: Creang a Conguraon Hierarchy with XMLBuilder and XML Objects
(Connued)
Java Code Resulng Hierarchy
// Create the ’match’ hierarchy
XML match = policyOne.append("match");
// Create and append an applicaons array
// to make three nodes with the same node
name
String[] applicaons = {"junos-p","junos-
ntp","junos-ssh"};
match.append("applicaon", applicaons);
<configuration>
<security>
<policies>
<policy>
<from-zone-name>trust</from-zone-name>
<to-zone-name>untrust</to-zone-name>
<policy>
<name>my-sec-policy</name>
<match>
<application>junos-ftp</application>
<application>junos-ntp</application>
<application>junos-ssh</application>
</match>
</policy>
</policy>
</policies>
</security>
</configuration>
16
Table 2: Creang a Conguraon Hierarchy with XMLBuilder and XML Objects
(Connued)
Java Code Resulng Hierarchy
// Add elements under 'match'
match.append("source-address","any");
match.append("desnaon-address","any");
<configuration>
<security>
<policies>
<policy>
<from-zone-name>trust</from-zone-name>
<to-zone-name>untrust</to-zone-name>
<policy>
<name>my-sec-policy</name>
<match>
<application>junos-ftp</application>
<application>junos-ntp</application>
<application>junos-ssh</application>
<source-address>any</source-address>
<destination-address>
any
</destination-address>
</match>
</policy>
</policy>
</policies>
</security>
</configuration>
17
Table 2: Creang a Conguraon Hierarchy with XMLBuilder and XML Objects
(Connued)
Java Code Resulng Hierarchy
// Add the 'then' hierarchy with a child 'permit'
element
policyOne.append("then").append("permit");
<configuration>
<security>
<policies>
<policy>
<from-zone-name>trust</from-zone-name>
<to-zone-name>untrust</to-zone-name>
<policy>
<name>my-sec-policy</name>
<match>
<application>junos-ftp</application>
<application>junos-ntp</application>
<application>junos-ssh</application>
<source-address>any</source-address>
<destination-address>
any
</destination-address>
</match>
<then>
<permit/>
</then>
</policy>
</policy>
</policies>
</security>
</configuration>
18
Table 2: Creang a Conguraon Hierarchy with XMLBuilder and XML Objects
(Connued)
Java Code Resulng Hierarchy
// Complete code and nal conguraon
XMLBuilder builder = new XMLBuilder();
XML policy =
builder.createNewConfig("security","policies","
policy");
policy.append("from-zone-name","trust");
policy.append("to-zone-name","untrust");
XML policyOne = policy.append("policy");
policyOne.append("name","my-sec-policy");
XML match = policyOne.append("match");
String[] applications = {"junos-ftp","junos-
ntp","junos-ssh"};
match.append("application", applications);
match.append("source-address","any");
match.append("destination-address","any");
policyOne.append("then").append("permit");
<configuration>
<security>
<policies>
<policy>
<from-zone-name>trust</from-zone-name>
<to-zone-name>untrust</to-zone-name>
<policy>
<name>my-sec-policy</name>
<match>
<application>junos-ftp</application>
<application>junos-ntp</application>
<application>junos-ssh</application>
<source-address>any</source-address>
<destination-address>any
</destination-address>
</match>
<then>
<permit/>
</then>
</policy>
</policy>
</policies>
</security>
</configuration>
NETCONF Java Toolkit Class: XMLBuilder
In a NETCONF session, communicaon between the conguraon management server and the
NETCONF server is through XML-encoded data. The conguraon management server sends remote
procedure calls (RPCs) to the NETCONF server, and the NETCONF server processes the RPC and
returns an RPC reply. The net.juniper.netconf.XMLBuilder and net.juniper.netconf.XML objects help create and
parse XML-encoded data.
19
You use the XMLBuilder object to create a new XML object. The constructor syntax is:
XMLBuilder ()
The XMLBuilder class includes methods to create a conguraon hierarchy, an RPC, or an XML object as
XML-encoded data. Each method is overloaded to accept mulple hierarchy levels. The methods return
an XML object. For example, the methods to construct a conguraon, RPC, or XML object with a
single-er hierarchy are:
createNewCong(String
elementLevelOne
)
createNewRPC(String
elementLevelOne
)
createNewXML(String
elementLevelOne
)
The following sample code creates a new XMLBuilder object, builder. The XMLBuilder object calls the
createNewConfig() method to construct a three-er conguraon hierarchy consisng of a “security”
element, a “policies” element child tag, and a “policy” element that is a child of “policies”.
XMLBuilder builder = new XMLBuilder();
XML policy = builder.createNewConfig("security","policies","policy");
The resulng XML hierarchy is as follows.
<configuration>
<security>
<policies>
<policy>
</policy>
</policies>
</security>
</configuration>
Noce that the createNewConfig() method always encloses the hierarchy within a top-level root element
<configuration>. Similarly, the createNewRPC() method encloses the hierarchy within an <rpc> tag element.
Once you generate an XML object, you can call methods from the XML class to manipulate that object.
RELATED DOCUMENTATION
NETCONF Java Toolkit Overview | 3
20
Create and Execute a NETCONF Java Applicaon | 23
Troubleshoot Excepon Errors in a NETCONF Java Applicaon | 61
21
4
CHAPTER
Create and Execute NETCONF Java
Applicaons
Create and Execute a NETCONF Java Applicaon | 23
Use the NETCONF Java Toolkit to Perform Operaonal Tasks | 26
Use the NETCONF Java Toolkit to Perform Conguraon Tasks | 44
Use the NETCONF Java Toolkit to Parse an RPC Reply | 58
Troubleshoot Excepon Errors in a NETCONF Java Applicaon | 61
Create and Execute a NETCONF Java Applicaon
IN THIS SECTION
Creang a NETCONF Java Toolkit Program File | 23
Compiling and Execung a NETCONF Java Toolkit Program File | 25
You can use the NETCONF Java toolkit to create Java applicaons to connect to a device, open a
NETCONF session, and create and execute operaonal and conguraon requests. Aer installing the
NETCONF Java toolkit, which is described in "Download and Install the NETCONF Java Toolkit" on page
7, the general procedure is:
1. Create a Java program that includes code to connect to a device and to execute the desired
operaons or requests.
2. Compile the Java code and execute the program.
These steps are reviewed in detail in the following secons:
Creang a NETCONF Java Toolkit Program File
NETCONF Java toolkit programs have the same generic framework. To create a basic NETCONF Java
toolkit program:
1. Create a .java le.
The lename should be idencal to the class name, excluding the extension. For example, the
ShowChassis class is saved in the le ShowChassis.java.
2. Create the general boilerplate, which includes the code for import statements, the class declaraon,
and the Java method, main().
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import net.juniper.netconf.Device;
import net.juniper.netconf.NetconfException;
import net.juniper.netconf.XML;
import org.xml.sax.SAXException;
23
public class ShowChassis {
public static void main(String args[]) throws NetconfException,
ParserConfigurationException, SAXException, IOException {
}
}
3. Within main(), create a Device object and call the connect() method.
This also creates a default NETCONF session with the NETCONF server over SSHv2.
Device device = new Device("
hostname
", "
username
", "
password
", null);
device.connect();
4. Execute operaonal and conguraon requests by execung RPCs and performing NETCONF
operaons on the Device object.
For example, to execute an operaonal request to retrieve chassis inventory informaon from the
device, include the following line of code:
XML reply = device.executeRPC(“get-chassis-inventory”);
5. Add code to print, parse, or take acon on RPC replies received from the NETCONF server.
The following line of code prints the RPC reply in XML format to standard output:
System.out.println(reply.toString());
6. Close the device and release resources by calling the close() method on the Device object.
device.close();
Sample NETCONF Java Toolkit Program
The following sample code illustrates a simple NETCONF Java toolkit program, ShowChassis.java, which
connects to a device and executes an operaonal request for chassis inventory informaon:
/* ShowChassis.java */
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import net.juniper.netconf.Device;
24
import net.juniper.netconf.NetconfException;
import net.juniper.netconf.XML;
import org.xml.sax.SAXException;
public class ShowChassis {
public static void main(String args[]) throws NetconfException,
ParserConfigurationException, SAXException, IOException {
//Create the device object and establish a NETCONF session
Device device = new Device("
hostname
", "
username
", "
password
", null);
device.connect();
//Send RPC and receive RPC reply as XML
XML rpc_reply = device.executeRPC("get-chassis-inventory");
//Print the RPC reply and close the device
System.out.println(rpc_reply.toString());
device.close();
}
}
Compiling and Execung a NETCONF Java Toolkit Program File
To execute a NETCONF Java toolkit program, compile the code and run the program from the
conguraon management server. You need a Java compiler to compile the source code and to create an
executable program.
1. Compile the Java source code to create a Java class le containing Java bytecode.
For example, to compile the ShowChassis.java le using the javac compiler included in the Java
Development Kit (JDK) from Oracle Corporaon, issue the following command on the command line
of the conguraon management server:
> javac ShowChassis.java
This creates the ShowChassis.class le.
2. Execute the program.
> java ShowChassis
25
RELATED DOCUMENTATION
Troubleshoot Excepon Errors in a NETCONF Java Applicaon | 61
NETCONF Java Toolkit Class: Device | 10
NETCONF Java Toolkit Overview | 3
Use the NETCONF Java Toolkit to Perform
Operaonal Tasks
IN THIS SECTION
Use Device Object Methods to Execute RPCs and Operaonal Commands | 26
Example: NETCONF Java Applicaon for Execung an Operaonal Request RPC | 28
Example: NETCONF Java Applicaon for Execung CLI Commands | 34
Example: NETCONF Java Applicaon for Prinng Component Temperatures | 39
Use Device Object Methods to Execute RPCs and Operaonal
Commands
IN THIS SECTION
Execung RPCs | 27
Execung Operaonal Mode Commands | 27
The NETCONF Java toolkit Device object has methods to request informaon from and perform
operaonal tasks on remote devices. When appropriate, the methods are overloaded to take a number
of dierent formats.
26
Execung RPCs
To execute a remote procedure call (RPC), call the executeRPC() method on the Device object. The
executeRPC() method is overloaded to accept a String object, a net.juniper.netconf.XML object, or an
org.w3c.dom.Document object as the argument. The RPC is processed by the NETCONF server, which returns
the RPC reply as an XML object.
The method syntax is:
public XML executeRPC (String
rpcContent
)
public XML executeRPC (net.juniper.netconf.XML
rpc
)
public XML executeRPC (org.w3c.dom.Document
rpcDoc
)
The following code snippet executes the Junos XML API get-chassis-inventory RPC using a string
argument. The get-chassis-inventory RPC is equivalent to the show chassis hardware operaonal mode
command in the Junos OS command-line interface (CLI).
Device device = new Device("10.10.1.1","admin","PaSsWoRd",null);
device.connect();
try {
XML rpc_reply = device.executeRPC("get-chassis-inventory");
System.out.println(rpc_reply.toString());
}
catch (Exception e) {
System.out.println("exception: " + e.getMessage());
// additional processing for exception
}
device.close();
Execung Operaonal Mode Commands
To execute an operaonal mode command to request informaon from or perform operaonal tasks on
a device running Junos OS, call the runCliCommand() method on the Device object. The runCliCommand()
method sends a Junos OS operaonal mode command to the NETCONF server on the remote device.
The argument is a string represenng the operaonal mode command that you would enter in the Junos
OS CLI. The RPC is processed by the NETCONF server, which returns the RPC reply. Starng with Junos
OS Release 11.4, the return string is the same ASCII-formaed output that you see in the Junos OS CLI.
For devices running earlier versions of Junos OS, the return string contains Junos XML tag elements.
27
The method syntax is:
public String runCLICommand (String
command
)
The following code snippet sends the CLI operaonal mode command show chassis hardware to the
NETCONF server on a device running Junos OS:
Device device = new Device("10.10.1.1","admin","PaSsWoRd",null);
device.connect();
try {
cli_reply = device.runCliCommand("show chassis hardware");
System.out.println(cli_reply);
}
catch (Exception e) {
System.out.println("exception: " + e.getMessage());
// additional processing for exception
}
device.close();
Example: NETCONF Java Applicaon for Execung an Operaonal
Request RPC
IN THIS SECTION
Requirements | 29
Overview | 29
Conguraon | 29
Vericaon | 32
Troubleshoong | 33
This NETCONF Java toolkit program executes an RPC to obtain operaonal informaon from a device,
which is then printed to standard output. This example serves as an instruconal example for creang
and execung a basic NETCONF Java toolkit program.
28
Requirements
NETCONF Java toolkit is installed on the conguraon management server.
Client applicaon can log in to the device where the NETCONF server resides.
NETCONF service over SSH is enabled on the device where the NETCONF server resides.
Overview
You can use the NETCONF Java toolkit to request operaonal informaon from a remote device. The
following example illustrates how to create a NETCONF Java toolkit program to execute an operaonal
request from the Junos XML API on a device running Junos OS. The example also explains how to
compile the code, execute the program, and verify the results.
Conguraon
IN THIS SECTION
Creang the Java Program | 29
Compiling and Running the Java Program | 31
Creang the Java Program
Step-by-Step Procedure
To construct the Java program le that contains the code for the operaonal request:
1. Give the le a descripve name.
The lename must be the same as the class name. For this example, the le and class are named
GetChassisInventory.
2. Include the appropriate import statements, and the code for the class declaraon and the Java
method, main().
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import net.juniper.netconf.Device;
import net.juniper.netconf.NetconfException;
import net.juniper.netconf.XML;
29
import org.xml.sax.SAXException;
public class GetChassisInventory {
public static void main(String args[]) throws NetconfException,
ParserConfigurationException, SAXException, IOException {
}
}
3. Within main(), create a Device object and call the connect() method.
This creates a default NETCONF session over SSHv2 with the NETCONF server. You must update
the code with the appropriate arguments for connecon to and authencaon on your specic
device.
Device device = new Device("10.10.1.1", "admin", "PaSsWoRd", null);
device.connect();
Having established a Device object, you can perform NETCONF operaons on the device. For a
complete list of available methods corresponding to NETCONF operaons, refer to the NETCONF
Java toolkit Javadocs.
4. Call the executeRPC() method with the operaonal request RPC command as the argument.
This example uses the Junos XML API get-chassis-inventory RPC. The reply, which is returned in XML,
is stored in the rpc_reply variable.
XML rpc_reply = device.executeRPC(“get-chassis-inventory”);
5. Add code to take acon on the RPC reply.
The following code converts the NETCONF server’s reply to a string and prints it to the screen:
System.out.println(rpc_reply.toString());
6.
Close the device and release resources by calling the close() method on the device object.
device.close();
30
Results
The complete program is:
/*GetChassisInventory*/
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import net.juniper.netconf.Device;
import net.juniper.netconf.NetconfException;
import net.juniper.netconf.XML;
import org.xml.sax.SAXException;
public class GetChassisInventory {
public static void main(String args[]) throws NetconfException,
ParserConfigurationException, SAXException, IOException {
Device device = new Device("10.10.1.1","admin","PaSsWoRd",null);
device.connect();
XML rpc_reply = device.executeRPC("get-chassis-inventory");
System.out.println(rpc_reply.toString());
device.close();
}
}
Compiling and Running the Java Program
Step-by-Step Procedure
You need a Java compiler to compile the source code and to create an executable program.
To compile the code and run the program on the conguraon management server:
1. Compile the GetChassisInventory.java le.
> javac GetChassisInventory.java
2. Execute the GetChassisInventory program.
> java GetChassisInventory
31
Vericaon
IN THIS SECTION
Verifying Program Execuon | 32
Verifying Program Execuon
Purpose
Verify that the GetChassisInventory program runs correctly.
Acon
If the program executes successfully, it establishes a connecon and a creates a NETCONF session with
the specied device. The program sends the get-chassis-inventory RPC to the NETCONF server, and the
server responds with the requested operaonal informaon enclosed in the <rpc-reply> tag element. The
program prints the reply to standard out. Following is a sample RPC reply with some output omied for
brevity.
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"
xmlns:junos="http://xml.juniper.net/junos/11.2R1/junos">
<chassis-inventory xmlns="http://xml.juniper.net/junos/11.2R1/junos-chassis">
<chassis junos:style="inventory">
<name>Chassis</name>
<serial-number>12345</serial-number>
<description>M7i</description>
<chassis-module>
...output omitted...
</chassis>
</chassis-inventory>
</rpc-reply>
32
Troubleshoong
IN THIS SECTION
Troubleshoong NETCONF Excepons | 33
Troubleshoong NETCONF Excepons
Problem
A NETCONF excepon occurs, and you see the following error message:
Exception in thread "main" net.juniper.netconf.NetconfException: There was a problem while
connecting to 10.10.1.1:830
at net.juniper.netconf.Device.createNetconfSession(Device.java:344)
at net.juniper.netconf.Device.connect(Device.java:225)
at GetChassisInventory.main(GetChassisInventory.java:14)
NETCONF over SSH might not be enabled on the device where the NETCONF server resides, or it might
be enabled on a dierent port.
Soluon
Ensure that you have enabled NETCONF over SSH on the device where the NETCONF server resides.
Since the example program does not specify a specic port number in the Device arguments, the
NETCONF session is established on the default NETCONF-over-SSH port, 830. To verify whether
NETCONF over SSH is enabled on the default port for a device running Junos OS, enter the following
operaonal mode command on the remote device:
user@host> show configuration system services
ftp;
netconf {
ssh;
}
33
If the netconf conguraon hierarchy is absent, issue the following statements in conguraon mode to
enable NETCONF over SSH on the default port:
[edit]
user@host# set system services netconf ssh
user@host# commit
If the netconf conguraon hierarchy species a port other than the default port, include the new port
number in the Device object constructor arguments. For example, the following device is congured for
NETCONF over SSH on port 12345:
user@host> show configuration system services
netconf {
ssh {
port 12345;
}
}
To correct the connecon issue, include the new port number in the Device arguments.
Device device = new Device("10.10.1.1", "admin", "PaSsWoRd", null, 12345);
Example: NETCONF Java Applicaon for Execung CLI Commands
IN THIS SECTION
Requirements | 35
Overview | 35
Conguraon | 35
Vericaon | 37
34
This NETCONF Java toolkit program demonstrates the runCLICommand() method, which sends the specied
Junos OS operaonal mode command to the NETCONF server to request informaon from or perform
operaonal tasks on a device running Junos OS.
Requirements
Roung, switching, or security device running Junos OS.
NETCONF Java toolkit is installed on the conguraon management server.
Client applicaon can log in to the device where the NETCONF server resides.
NETCONF service over SSH is enabled on the device where the NETCONF server resides.
Overview
The NETCONF Java toolkit Device class contains the runCliCommand() method, which takes a Junos OS CLI
operaonal mode command and converts it to an equivalent RPC in XML that can be processed by the
NETCONF server. The runCLICommand() method takes as an argument the string represenng an
operaonal mode command that you enter in the Junos OS CLI.
The following example executes the show chassis hardware command on a device running Junos OS. The
return value for the method is a string. Starng with Junos OS Release 11.4, the return string is the same
ASCII-formaed output that you see in the Junos OS CLI. For devices running earlier versions of Junos
OS, the return string contains Junos XML tag elements.
Conguraon
IN THIS SECTION
Creang the Java program | 35
Compiling and Running the Java Program | 36
Creang the Java program
Step-by-Step Procedure
To construct the Java program le:
1. Give the le a descripve name.
35
The lename must be the same as the class name. For this example, the le and class are named
ExecuteCLICommand.
2. Add the code to the le and update the environment-specic variables such as the remote host IP
address, username, password, and <rpc-reply> tag elements.
The complete Java code for the ExecuteCLICommand.java program is presented here.
/*ExecuteCLICommand*/
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import net.juniper.netconf.Device;
import net.juniper.netconf.NetconfException;
import net.juniper.netconf.XML;
import org.xml.sax.SAXException;
public class ExecuteCLICommand {
public static void main(String args[]) throws NetconfException,
ParserConfigurationException, SAXException, IOException {
String cli = "show chassis hardware";
Device device = new Device("10.10.1.1","admin","PaSsWoRd",null);
device.connect();
try {
String cli_reply = device.runCliCommand(cli);
System.out.println(cli_reply);
}
catch (Exception e) {
System.out.println("exception: " + e.getMessage());
// additional processing for exception
}
device.close();
}
}
Compiling and Running the Java Program
Step-by-Step Procedure
You need a Java compiler to compile the source code and to create an executable program.
36
To compile the code and run the program on the conguraon management server:
1. Compile the ExecuteCLICommand.java le.
> javac ExecuteCLICommand.java
2. Execute the ExecuteCLICommand program.
> java ExecuteCLICommand
Vericaon
IN THIS SECTION
Verifying Program Execuon | 37
Verifying Program Execuon
Purpose
Verify that the ExecuteCLICommand program runs correctly.
Acon
If the program executes successfully, it establishes a connecon and creates a NETCONF session with
the specied device. The program converts the Junos OS CLI operaonal mode command show chassis
hardware to an RPC and sends the RPC to the NETCONF server. The server responds with the requested
operaonal informaon enclosed in the <rpc-reply> tag element The program parses the RPC reply and
prints the resulng chassis inventory. The following sample output is from a Juniper Networks m7i
router.
On a device running Junos OS Release 11.4 or later release, the output is in ASCII-formaed text, which
is idencal to the output in the CLI.
Hardware inventory:
Item Version Part number Serial number Description
Chassis 30010 M7I
37
Midplane REV 03 710-008761 CB3874 M7i Midplane
Power Supply 0 Rev 04 740-008537 PG10715 AC Power Supply
Routing Engine REV 07 740-009459 1000445584 RE-5.0
CFEB REV 07 750-010464 CM4612 Internet Processor II
FPC 0 E-FPC
PIC 0 REV 06 750-002971 CB0032 4x OC-3 SONET, MM
PIC 1 REV 02 750-002982 HS2878 1x Tunnel
PIC 2 REV 08 750-005724 CL9084 2x OC-3 ATM-II IQ, MM
PIC 3 REV 12 750-012838 DJ1107 4x 1GE(LAN), IQ2
Xcvr 0 REV 01 740-013111 7303405 SFP-T
Xcvr 1 REV 01 740-013111 7303391 SFP-T
Xcvr 2 REV 01 740-013111 7303350 SFP-T
Xcvr 3 REV 01 740-013111 7303420 SFP-T
FPC 1 E-FPC
PIC 2 REV 07 750-009487 CL5745 ASP - Integrated (Layer-2-3)
PIC 3 REV 07 750-009098 CB7256 2x F/E, 100 BASE-TX
Fan Tray Rear Fan Tray
On a device running Junos OS Release 11.3 or earlier release, the output contains Junos XML tag
elements.
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/11.2R1/junos">
<chassis-inventory xmlns="http://xml.juniper.net/junos/11.2R1/junos-chassis">
<chassis junos:style="inventory">
<name>Chassis</name>
<serial-number>30010</serial-number>
<description>M7I</description>
<chassis-module>
<name>Midplane</name>
<version>REV 03</version>
<part-number>710-008761</part-number>
<serial-number>CB3874</serial-number>
<description>M7i Midplane</description>
<model-number>CHAS-MP-M7i-1GE-S</model-number>
</chassis-module>
/* Output omitted for brevity */
</chassis>
</chassis-inventory>
</rpc-reply>
38
Example: NETCONF Java Applicaon for Prinng Component
Temperatures
IN THIS SECTION
Requirements | 39
Overview | 39
Conguraon | 40
Vericaon | 42
This NETCONF Java toolkit program prints the name and corresponding temperature of components on
a device running Junos OS.
Requirements
Roung, switching, or security device running Junos OS.
NETCONF Java toolkit is installed on the conguraon management server.
Client applicaon can log in to the device where the NETCONF server resides.
NETCONF service over SSH is enabled on the device where the NETCONF server resides.
Overview
The following example executes the Junos XML API get-environment-information RPC, which is the
equivalent of the show chassis environment operaonal mode command on a device running Junos OS. The
program parses the RPC reply, and for all components that list a temperature, the program prints the
component name and corresponding temperature.
The RPC reply format for the get-environment-information RPC request is:
<rpc-reply>
<environment-information>
<environment-item>
<name>
item-name
</name>
...
<temperature>
temperature
</temperature>
</environment-item>
39
<environment-item>
<name>
item-name2
</name>
...
<temperature>
temperature
</temperature>
</environment-item>
...
</environment-information>
</rpc-reply>
To parse the reply, the program uses the findNodes() method to return a list of org.w3c.dom.Node objects. For
each <environment-item> node, the program obtains a list of child nodes. If a temperature element is
present in the child node list, the program prints the name and temperature of that environment item.
Conguraon
IN THIS SECTION
Creang the Java program | 40
Compiling and Running the Java Program | 42
Creang the Java program
Step-by-Step Procedure
To construct the Java program le:
1. Give the le a descripve name.
The lename must be the same as the class name. For this example, the le and class are named
ShowTemps.
2. Add the code to the le and update the environment-specic variables such as the remote host IP
address, username, password, and <rpc-reply> tag elements.
The complete Java code for the ShowTemps.java program is presented here.
import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
40
import javax.xml.parsers.ParserConfigurationException;
import net.juniper.netconf.CommitException;
import net.juniper.netconf.Device;
import net.juniper.netconf.LoadException;
import net.juniper.netconf.NetconfException;
import net.juniper.netconf.XML;
import net.juniper.netconf.XMLBuilder;
import org.xml.sax.SAXException;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class showTemps {
public static void main(String[] args) throws LoadException,
IOException, NetconfException, ParserConfigurationException,
SAXException {
String name="", temp="";
//Create the device
Device device = new Device("10.10.1.1","admin","PaSsWoRd",null);
device.connect();
//Call executeRPC(String rpc) to send RPC and receive RPC reply
XML rpc_reply = device.executeRPC("get-environment-information");
// Parse reply and only print items that have a temperature element
List<String> list =
Arrays.asList("environment-information","environment-item");
List itemlist = rpc_reply.findNodes(list);
Iterator iter = itemlist.iterator();
while (iter.hasNext()) {
Node item_node = (Node) iter.next();
NodeList child_nodes = item_node.getChildNodes();
// child_nodes contains nodes like <name> and <temperature>
for (int i = 0; i < child_nodes.getLength(); i++) {
Node child = child_nodes.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE) {
if (child.getNodeName().equals("name"))
// Capture the text value in <name> node
name = child.getTextContent();
41
if (child.getNodeName().equals("temperature")) {
// Capture the text value in <temperature> node
temp = child.getTextContent();
System.out.println(name + ": " + temp);
}
}
}
}
device.close();
}
}
Compiling and Running the Java Program
Step-by-Step Procedure
You need a Java compiler to compile the source code and to create an executable program.
To compile the code and run the program on the conguraon management server:
1. Compile the ShowTemps.java le.
> javac ShowTemps.java
2. Execute the ShowTemps program.
> java ShowTemps
Vericaon
IN THIS SECTION
Verifying the Results | 43
42
Verifying the Results
Purpose
Verify that the ShowTemps program runs correctly.
Acon
If the program executes successfully, it establishes a connecon and a creates a NETCONF session with
the specied device. The program then executes the Junos XML API get-environment-information RPC,
parses the RPC reply, and prints all environment items that contain a child node <temperature>.
The following sample output is from a Juniper Networks m7i router:
Intake: 25 degrees C / 77 degrees F
FPC 0: 26 degrees C / 78 degrees F
Power Supplies: 28 degrees C / 82 degrees F
CFEB Intake: 22 degrees C / 71 degrees F
CFEB Exhaust: 30 degrees C / 86 degrees F
Routing Engine: 28 degrees C / 82 degrees F
Routing Engine CPU: 28 degrees C / 82 degrees F
RELATED DOCUMENTATION
NETCONF Java Toolkit Class: Device | 10
Use the NETCONF Java Toolkit to Parse an RPC Reply | 58
Troubleshoot Excepon Errors in a NETCONF Java Applicaon | 61
Use the NETCONF Java Toolkit to Perform Conguraon Tasks | 44
43
Use the NETCONF Java Toolkit to Perform
Conguraon Tasks
IN THIS SECTION
Use Device Object Methods to Load Conguraon Changes | 44
Example: NETCONF Java Applicaon for Loading and Comming a Conguraon | 46
Example: NETCONF Java Applicaon for Loading Set Conguraon Commands | 52
Use Device Object Methods to Load
Conguraon Changes
The NETCONF Java toolkit Device object has methods to help you congure remote devices. When
appropriate, the methods are overloaded to take a number of dierent formats.
To load conguraon data on a remote device, the Device object has several methods that enable you to
dene the conguraon data as a set of Junos OS conguraon mode commands, formaed ASCII text,
or Junos XML tag elements. You can supply the conguraon data in the program code, or you can
reference data les that include the desired conguraon changes.
To congure a private copy of the candidate conguraon, call the openConfiguration("private") method
with the string argument "private" on the device object before loading your conguraon changes. This
is equivalent to the configure private command in the Junos OS CLI. If you omit the call to the
openConfiguration("private") method, your conguraon changes are loaded into the global copy of the
candidate conguraon.
The method used to load the conguraon data depends on the source and the format of the data. In
the following methods, the string argument
loadType
has a value of either merge or replace, which performs
the equivalent of the conguraon mode commands load merge or load replace on a device running Junos
OS.
Junos OS conguraon mode commands
The following methods load conguraon data as a set of
Junos OS conguraon mode commands. These methods are only supported on devices running
Junos OS Release 11.4 or a later release. Junos OS executes the conguraon instrucons line by
line. For each element, you can specify the complete statement path in the command, or you can use
navigaon commands, such as edit, to move around the conguraon hierarchy as you do in CLI
conguraon mode.
44
loadSetConfiguration(String
setCommands
)—Specify the conguraon data in the program code, either
as a method argument or as a variable passed to the method.
loadSetFile(String
filePath
)—Load the conguraon data from the le specied by
lePath
.
Formaed ASCII text
The following methods load conguraon data as formaed ASCII text. Use
the standard Junos OS CLI notaons—the newline character, tabs, spaces, braces, and square
brackets—to indicate the hierarchical relaonships between conguraon statements.
loadTextConfiguration(String
textConfiguration
, String
loadType
)—Specify the conguraon data in the
program code, either as a method argument or as a variable passed to the method.
loadTextFile(String
filePath
, String
loadType
)—Load the conguraon data from the le specied by
lePath
.
Junos XML tag elements
The following methods load conguraon data as Junos XML tag
elements. Include the tag elements represenng all levels of the conguraon hierarchy under the
root, the <configuration> tag element, down to each new or changed element.
loadXMLConfiguration(String
XMLConfiguration
, String
loadType
)—Specify the conguraon data in the
program code as a net.juniper.netconf.XML object, which is passed to the method.
loadXMLFile(String
filePath
, String
loadType
)—Load the conguraon data from the le specied by
lePath
.
The following code snippet merges the ftp statement into the candidate conguraon at the [edit system
services] hierarchy level. The Java statement for each type of load conguraon method is shown. When
loading from a le, the le should contain the appropriate hierarchy in the desired format.
/*
r1-config-set.txt:
set system services ftp
r1-config-text.txt:
system {
services {
ftp;
}
}
r1-config-xml.txt:
<system>
<services>
<ftp/>
</services>
45
</system>
*/
String config_file_set = "configs/r1-config-set.txt"
String config_file_text = "configs/r1-config-text.txt"
String config_file_xml = "configs/r1-config-xml.txt"
XMLBuilder builder = new XMLBuilder();
XML ftp_config = builder.createNewConfig("system", "services", "ftp");
Device device = new Device("10.10.1.1","admin","PaSsWoRd",null);
device.connect();
//open a private copy of the candidate configuration
device.openConfiguration("private");
// load configuration data as Junos OS configuration mode commands
device.loadSetConfiguration("set system services ftp");
device.loadSetFile(config_file_set);
// load configuration data as formatted ASCII text
device.loadTextConfiguration("system { services { ftp; } }", "merge");
device.loadTextFile(config_file_text, "merge");
// load configuration data as Junos XML tag elements
device.loadXMLConfiguration(ftp_config.toString(), "merge");
device.loadXMLFile(config_file_xml, "merge");
device.commit();
device.close();
Example: NETCONF Java Applicaon for Loading and Comming a
Conguraon
IN THIS SECTION
Requirements | 47
46
Overview | 47
Conguraon | 48
Vericaon | 50
Troubleshoong | 51
The following example NETCONF Java toolkit program constructs a conguraon hierarchy, which is
then merged with the candidate conguraon on the specied device. The resulng conguraon is
then commied. The sample conguraon hierarchy is for a device running Junos OS.
Requirements
Roung, switching, or security device running Junos OS.
NETCONF Java toolkit is installed on the conguraon management server.
Client applicaon can log in to the device where the NETCONF server resides.
NETCONF service over SSH is enabled on the device where the NETCONF server resides.
Overview
The following example performs a load merge operaon to update the candidate conguraon on a device
running Junos OS and then commits the new conguraon. The XML hierarchy that will be added into
the conguraon is constructed with the XMLBuilder object and stored in the ftp_config variable.
Alternavely, you can load conguraon data as text and, for devices running Junos OS Release 11.4 or
a later release, as a set of Junos OS conguraon mode commands.
The new conguraon hierarchy, which enables FTP service on the device, is:
<configuration>
<system>
<services>
<ftp/>
</services>
</system>
</configuration>
The program code creates a new Device object and calls the connect() method. This establishes an SSHv2
connecon and a default NETCONF session with the device on which the NETCONF server runs.
47
To prevent conicts with other users who might simultaneously edit the candidate conguraon, the
code calls the lockConfig() method on the device object to lock the conguraon. If the lock fails, the
method generates an error message, and the program exits. If the lock is successful, the
loadXMLConfiguration(ftp_config.toString(), "merge") method loads the new conguraon hierarchy into the
candidate conguraon using the merge opon. Noce that, although the conguraon hierarchy is
inially constructed as XML, you must convert it to a string before passing it as an argument to the
loadXMLConfiguration() method.
Once the new conguraon hierarchy is merged with the candidate conguraon, the program aempts
to commit the conguraon. If the commit operaon is unsuccessful, the program prints the associated
error message. The program then unlocks the conguraon and closes the NETCONF session and
device connecon.
NOTE: For more informaon about the merge and replace opons for loading conguraon
hierarchies and statements into the candidate conguraon, see the CLI User Guide.
Conguraon
IN THIS SECTION
Creang the Java Program | 48
Compiling and Running the Java Program | 50
Creang the Java Program
Step-by-Step Procedure
To construct the Java program le that contains the code for the conguraon changes and requests:
1. Give the le a descripve name.
The lename must be the same as the class name. For this example, the le and class are named
EditCong.
2. Add the code to the le and update the environment-specic variables such as the remote host IP
address, username, and password.
48
The complete Java code for the EditCong program is presented here.
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import net.juniper.netconf.CommitException;
import net.juniper.netconf.Device;
import net.juniper.netconf.LoadException;
import net.juniper.netconf.NetconfException;
import net.juniper.netconf.XML;
import net.juniper.netconf.XMLBuilder;
import org.xml.sax.SAXException;
public class EditConfig {
public static void main(String[] args) throws LoadException, IOException,
NetconfException, ParserConfigurationException, SAXException {
/*Build the following XML hierarchy to add to the configuration:
* <configuration>
* <system>
* <services>
* <ftp/>
* </services>
* </system>
* </configuration>
*/
XMLBuilder builder = new XMLBuilder();
XML ftp_config = builder.createNewConfig("system", "services", "ftp");
//Create the device
Device device = new Device("10.10.1.1","admin","PaSsWoRd",null);
device.connect();
//Lock the configuration
boolean isLocked = device.lockConfig();
if(!isLocked) {
System.out.println("Could not lock configuration. Exit now.");
return;
}
//Load and commit the configuration
try {
49
device.loadXMLConfiguration(ftp_config.toString(), "merge");
device.commit();
} catch(LoadException e) {
System.out.println(e.getMessage());
return;
} catch(CommitException e) {
System.out.println(e.getMessage());
return;
}
//Unlock the configuration and close the device
device.unlockConfig();
device.close();
}
}
Compiling and Running the Java Program
Step-by-Step Procedure
You need a Java compiler to compile the source code and to create an executable program.
To compile the code and run the program on the conguraon management server:
1. Compile the EditCong.java le.
> javac EditConfig.java
2. Execute the EditCong program.
> java EditConfig
Vericaon
IN THIS SECTION
Verifying Program Execuon | 51
50
Verifying Program Execuon
Purpose
Verify that the EditCong program runs correctly.
Acon
If the program executes successfully, it establishes a connecon and a creates a NETCONF session with
the specied device. The program merges the new hierarchy with the candidate conguraon on the
device and commits the conguraon.
You can verify that the conguraon was correctly merged and commied by viewing the resulng
conguraon on the remote device. The ftp statement should now be in the acve conguraon. On a
device running Junos OS, enter the following operaonal mode command to view the [edit system
services] hierarchy:
user@host> show configuration system services
ftp;
netconf {
ssh;
}
Troubleshoong
IN THIS SECTION
Troubleshoong Error Messages | 51
Troubleshoong Error Messages
Problem
The following error message is printed to the display:
Could not lock configuration. Exit now.
51
Soluon
Another user currently has a lock on the candidate conguraon. Wait unl the lock is released and
execute the program.
Example: NETCONF Java Applicaon for Loading Set Conguraon
Commands
IN THIS SECTION
Requirements | 52
Overview | 52
Conguraon | 53
Vericaon | 56
This NETCONF Java toolkit program demonstrates the loadSetConfiguration() method, which updates the
conguraon using a set of Junos OS conguraon mode commands.
Requirements
Roung, switching, or security device running Junos OS Release 11.4 or later.
NETCONF Java toolkit is installed on the conguraon management server.
Client applicaon can log in to the device where the NETCONF server resides.
NETCONF service over SSH is enabled on the device where the NETCONF server resides.
Overview
The Device class contains the loadSetConfiguration() and loadSetFile() methods, which load conguraon
data as a set of Junos OS conguraon mode commands on devices running Junos OS Release 11.4 or a
later release. For each conguraon element, you can specify the complete statement path in the
command, or you can use navigaon commands , such as edit, to move around the conguraon
hierarchy as you do in CLI conguraon mode. The NETCONF Java toolkit converts the command set to
the equivalent RPC in XML that can be processed by the NETCONF server on devices running Junos
OS. Junos OS executes the conguraon instrucons line by line.
52
The method syntax is:
public void loadSetConfiguration (String
setCommands
)
public void loadSetFile (String
filePath
)
The loadSetConfiguration() method takes as an argument the conguraon command string that you
would enter in Junos OS CLI conguraon mode. For example, to add the ftp statement at the [edit
system services] hierarchy level, you use the set system services ftp command. The loadSetFile() method
takes as an argument the path of the le containing the set of conguraon commands.
You can also use both methods to load mulple commands. To load mulple commands using the
loadSetConfiguration() method, you can either list the commands as a single string and separate them with
the \n newline sequence, or you can execute the method separately for each command. To load mulple
commands using the loadSetFile() method, place each command on a separate line in the le.
NOTE: When using the loadSetConfiguration() method with navigaon commands, you should list
the commands as a single string and separate them with the \n newline sequence. You cannot call
the loadSetConfiguration() method with a single navigaon command such as up.
The program in this example loads two conguraon commands, which merge two statements into the
candidate conguraon on a device running Junos OS Release 11.4. The rst command, set system
services p, adds the ftp statement at the [edit system services] hierarchy level. The second command,
set interfaces ge-0/0/0 disable, adds the disable statement at the [edit interfaces ge-0/0/0] hierarchy
level. The relevant statements in the program code are:
String system_config = "set system services ftp";
String interfaces_config = "set interfaces ge-0/0/0 disable";
device.loadSetConfiguration(system_config);
device.loadSetConfiguration(interfaces_config);
Conguraon
IN THIS SECTION
Creang the Java Program | 54
Compiling and Running the Java Program | 55
53
Creang the Java Program
Step-by-Step Procedure
To construct the Java program le:
1. Give the le a descripve name.
The lename must be the same as the class name. For this example, the le and class are named
LoadSetCong.
2. Add the code to the le and update the environment-specic variables such as the remote host IP
address, username, password, and <rpc-reply> tag elements.
The complete Java code for the LoadSetCong.java program is presented here.
If you load the set of commands from a le, create a le containing the commands, and replace the
two loadSetConfiguration() method calls with a call to the loadSetFile() method.
/*LoadSetConfig*/
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import net.juniper.netconf.Device;
import net.juniper.netconf.CommitException;
import net.juniper.netconf.LoadException;
import net.juniper.netconf.NetconfException;
import net.juniper.netconf.XML;
import org.xml.sax.SAXException;
public class LoadSetConfig {
public static void main(String args[]) throws NetconfException,
ParserConfigurationException, SAXException, IOException {
String system_config = "set system services ftp";
String interfaces_config = "set interfaces ge-0/0/0 disable";
Device device = new Device("10.10.1.1","admin","PaSsWoRd",null);
try {
device.connect();
System.out.println("Connection successful.");
if (device.lockConfig()) {
System.out.println("Configuration successfully locked.");
54
try {
System.out.println("Updating configuration.");
device.loadSetConfiguration(system_config);
device.loadSetConfiguration(interfaces_config);
System.out.println("Committing configuration.");
device.commit();
}
catch (LoadException e) {
System.out.println("LoadException occurred: " + e.getMessage());
}
catch (CommitException e) {
System.out.println("CommitException occurred: " + e.getMessage());
}
device.unlockConfig();
device.close();
}
else {
System.out.println("Error - cannot lock configuration");
}
}
catch (NetconfException e) {
System.out.println("Could not connect to device: " + e.getMessage());
}
}
}
Compiling and Running the Java Program
Step-by-Step Procedure
You need a Java compiler to compile the source code and to create an executable program.
To compile the code and run the program on the conguraon management server:
1. Compile the LoadSetCong.java le.
> javac LoadSetConfig.java
55
2. Execute the LoadSetCong program.
> java LoadSetConfig
Vericaon
IN THIS SECTION
Verifying Program Execuon | 56
Verifying the Conguraon Changes | 57
Verifying the Commit | 57
To conrm that the program is working properly:
Verifying Program Execuon
Purpose
Verify that the LoadSetCong program runs correctly.
Acon
If the program executes successfully, it establishes a connecon and creates a NETCONF session with
the specied device. The program merges the new statements with the candidate conguraon on the
device and commits the conguraon.
>java LoadSetConfig
Connection successful.
Configuration successfully locked.
Updating configuration.
Committing configuration.
56
Verifying the Conguraon Changes
Purpose
You can verify that the conguraon was correctly merged and commied by viewing the resulng
conguraon on the remote device. The ftp and the disable statements should now be in the acve
conguraon. On a device running Junos OS, issue the following operaonal mode commands to view
the [edit system services] and [edit interfaces] hierarchy levels:
Acon
admin@host> show configuration system services
ftp;
netconf {
ssh;
}
admin@host> show configuration interfaces
ge-0/0/0 {
disable;
}
Verifying the Commit
Purpose
Addionally, you can review the commit log to verify that the commit was successful. On a device
running Junos OS, issue the show system commit operaonal mode command to view the commit log. In this
example, the log conrms that the user admin commied the candidate conguraon in a NETCONF
session at the given date and me.
Acon
Issue the show system commit operaonal mode command and review the commit log.
admin@host> show system commit
0 2011-09-02 14:16:44 PDT by admin via netconf
1 2011-07-08 14:33:46 PDT by root via other
57
RELATED DOCUMENTATION
NETCONF Java Toolkit Class: Device | 10
Use the NETCONF Java Toolkit to Parse an RPC Reply | 58
Troubleshoot Excepon Errors in a NETCONF Java Applicaon | 61
Use the NETCONF Java Toolkit to Perform Operaonal Tasks | 26
Use the NETCONF Java Toolkit to Parse an RPC
Reply
Aer subming an operaonal or conguraon request to the NETCONF server, the server responds
with an RPC reply. You can use several approaches to parse the RPC reply in order to extract the desired
informaon.
XML rpc_reply = device.executeRPC(“get-chassis-inventory”);
There are two approaches to parse an XML reply within the context of the NETCONF Java toolkit:
Get the org.w3c.dom.Document object and use the nave parsing methods available in the standard Java
class libraries for a Document object.
Use the findValue(List
list
) and findNodes(List
list
) methods available in the net.juniper.netconf.XML
class on the XML object.
For the rst approach, call the getOwnerDocument() method on the reply object to return the Document object.
Document doc = rpc_reply.getOwnerDocument();
You can then use methods in the standard Java libraries on the resulng Document object. This method is
useful for the exibility and opons available in terms of the standard Java library methods.
For the second approach, the net.juniper.netconf.XML class contains the findValue(List
list
) and
findNodes(List
list
) methods, which you can use to parse the XML object. You must include the “import
java.ul.*;” statement in your program code to use the funconality of the List interface or to create an
Arrays object as shown in the corresponding examples.
58
Study the following RPC reply for the get-interface-information operaonal request:
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"
xmlns:junos="http://xml.juniper.net/junos/11.3I0/junos">
<interface-information>
<physical-interface>
<name>ge-0/0/0</name>
<admin-status>up</admin-status>
<oper-status>up</oper-status>
/* hierarchy truncated for brevity */
</physical-interface>
<physical-interface>
<name>ge-0/0/1</name>
/* hierarchy truncated for brevity */
</physical-interface>
</interface-information>
</rpc-reply>
Parsing an RPC Reply Using ndValue()
You can use the findValue() method to determine the value of a given element at any level of the
hierarchy. In the example RPC reply for get-interface-information, suppose you want to determine the
value of the <admin-status> element of the physical interface ge-0/0/0. Being aware of the format of the
RPC reply, you can extract this informaon using the following code:
XML rpc_reply = device.executeRPC(“get-interface-information”);
List<String> list = Arrays.asList("interface-information","physical-interface",
"name~ge-0/0/0", “admin-status");
String admin_status = rpc_reply.findValue(list);
System.out.println(admin_status);
Note that the interface name uses a lde (~) character to idenfy the parcular element. Execuon of
this code prints “up” to standard output.
Parsing an RPC Reply Using ndNodes()
59
You can use the findNodes() method to obtain the list of all nodes under a given hierarchy as
org.w3c.dom.Node objects. The following code snippet obtains a list of all <physical-interface> nodes under
the <interface-information> element in the hierarchy:
XML rpc_reply = device.executeRPC("get-interface-information");
List<String> list = Arrays.asList("interface-information","physical-interface");
List physical_interfaces_list = rpc_reply.findNodes(list);
However, you might want to extract a specic node. The following code returns the hierarchy for the
ge-0/0/1 interface only:
XML rpc_reply = device.executeRPC("get-interface-information");
List<String> list = Arrays.asList("interface-information","physical-interface",
"name~ge-0/0/1");
List physical_interfaces_list = rpc_reply.findNodes(list);
Node ge001_node = (Node)physical_interfaces_list.get(0);
Example: Parsing an RPC Reply Using ndNodes() (Detailed)
The following example takes this approach a step further and parses through the child nodes to extract
and print the content for just the <name> elements. This sample code focuses on the poron of the
program that parses the RPC reply and does not represent a complete program.
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/* code omitted for brevity */
XML rpc_reply = device.executeRPC("get-interface-information");
// Obtain a list of list of ‘org.w3c.dom.Node’ objects
List<String> list = Arrays.asList("interface-information","physical-interface");
List physical_interfaces_list = rpc_reply.findNodes(list);
// Print the value for each of the name elements:
Iterator iter = physical_interfaces_list.iterator();
while(iter.hasNext()) {
Node node = (Node)iter.next();
60
NodeList child_nodes_of_phy_interface = node.getChildNodes();
// child_nodes_of_phy_interface contains nodes like <name> and <admin-status>
// Get each <name> node from the NodeList
for (int i = 0; i < child_nodes_of_phy_interface.getLength(); i++) {
Node child_node = child_nodes_of_phy_interface.item(i);
if (child_node.getNodeType() != Node.ELEMENT_NODE){
continue;
}
if (child_node.getNodeName().equals("name")) {
// Print the text value of the <name> node
System.out.println(child_node.getTextContent());
}
break;
}
}
RELATED DOCUMENTATION
Create and Execute a NETCONF Java Applicaon | 23
NETCONF Java Toolkit Classes | 10
Troubleshoot Excepon Errors in a NETCONF Java
Applicaon
IN THIS SECTION
Troubleshoong Connecon Errors: Socket Timed Out | 62
Troubleshoong Connecon Errors: No Connecon | 63
Troubleshoong Authencaon Errors | 64
Troubleshoong NETCONF Session Errors | 65
61
The following secons outline excepon errors that you might encounter when execung a NETCONF
Java toolkit program. These secons also present potenal causes and soluons for each error.
Troubleshoong Connecon Errors: Socket Timed Out
IN THIS SECTION
Problem | 62
Cause | 62
Soluon | 63
Problem
Descripon
A NETCONF excepon occurs, and you see the following error message:
Exception in thread "main" net.juniper.netconf.NetconfException: The connect() operation on the
socket timed out.
at net.juniper.netconf.Device.createNetconfSession(Device.java:344)
at net.juniper.netconf.Device.connect(Device.java:225)
at GetChassisInventory.main(GetChassisInventory.java:14)
Cause
Potenal causes for the socket med out error include:
The device or interface to which you are connecng is down or unavailable.
The IP address or hostname in the arguments for the Device object is incorrect.
The connecon meout value was exceeded before the connecon was established.
62
Soluon
Ensure that the device is up and running. Also verify that the IP address or hostname is correct in the
arguments of the Device constructor in your program code.
The default meout value for connecng to a device is 5000 milliseconds. To set the meout value to a
larger interval to ensure that the program has sucient me to establish the connecon, call the
setTimeOut() method on the device object. The following code sets the meout interval to 10 seconds:
Device device = new Device("10.10.1.1","admin","PaSsWoRd",null);
device.setTimeOut(10000);
device.connect();
Troubleshoong Connecon Errors: No Connecon
IN THIS SECTION
Problem | 63
Cause | 64
Soluon | 64
Problem
Descripon
An IllegalStateExcepon excepon occurs, and you see the following error message:
Exception in thread "main" java.lang.IllegalStateException: Cannot execute RPC, you need to
establish a connection first.
at net.juniper.netconf.Device.executeRPC(Device.java:498)
at GetChassisInventoryRun.main(GetChassisInventoryRun.java:15)
63
Cause
An SSHv2 connecon or NETCONF session was not established with the remote device.
Soluon
Call the connect() method on the device object to establish an SSHv2 connecon and a default
NETCONF session with the device on which the NETCONF server runs. Once the connecon and
session are established, RPC execuon should be successful.
Troubleshoong Authencaon Errors
IN THIS SECTION
Problem | 64
Cause | 65
Soluon | 65
Problem
Descripon
A NETCONF excepon occurs, and you see the following error message:
Exception in thread "main" net.juniper.netconf.NetconfException: Authentication failed.
at net.juniper.netconf.Device.createNetconfSession(Device.java:358)
at net.juniper.netconf.Device.connect(Device.java:225)
at GetChassisInventory.main(GetChassisInventory.java:14)
<!-- or -->
Could not connect to device:Authentication failed.
64
Cause
An error message for failed authencaon could have several possible causes, including the following:
The host or authencaon details passed as arguments to the Device constructor are incorrectly
entered in the program code.
The arguments for the Device object are correct, but there is no corresponding user account created
on the device to which you are connecng.
Soluon
If there is no user account on the device to which you are connecng, create the account with the
appropriate authencaon. For more informaon about conguring user accounts on a device running
Junos OS, see the Junos OS User Access and Authencaon User Guide for Roung Devices .
If the user account exists on the remote device, but the arguments for the Device constructor are entered
incorrectly in the program code, correct the arguments and recompile the program.
Troubleshoong NETCONF Session Errors
IN THIS SECTION
Problem | 65
Cause | 66
Soluon | 66
Problem
Descripon
A NETCONF excepon occurs, and you see the following error message:
Exception in thread "main" net.juniper.netconf.NetconfException: There was a problem while
connecting to 10.10.1.1:830
at net.juniper.netconf.Device.createNetconfSession(Device.java:344)
65
at net.juniper.netconf.Device.connect(Device.java:225)
at GetChassisInventory.main(GetChassisInventory.java:14)
Cause
NETCONF over SSH might not be enabled on the device where the NETCONF server resides, or it might
be enabled on a dierent port.
Soluon
Ensure that you have enabled NETCONF over SSH on the device where the NETCONF server resides. If
your NETCONF Java toolkit program does not specify a specic port number in the Device argurments,
the NETCONF session is established on the default NETCONF-over-SSH port, 830. To verify whether
NETCONF over SSH is enabled on the default port for a device running Junos OS, enter the following
operaonal mode command on the remote device:
user@host> show configuration system services
ftp;
netconf {
ssh;
}
If the netconf conguraon hierarchy is absent, issue the following statements in conguraon mode to
enable NETCONF over SSH on the default port:
[edit]
user@host# set system services netconf ssh
user@host# commit
If the netconf conguraon hierarchy species a port other than the default port, you should include the
new port number in the Device object constructor arguments. For example, the following device is
congured for NETCONF over SSH on port 12345:
user@host> show configuration system services
netconf {
ssh {
port 12345;
66
}
}
To correct the connecon issue, include the new port number in the Device arguments.
Device device = new Device("10.10.1.1", "admin", "PaSsWoRd", null, 12345);
RELATED DOCUMENTATION
Create and Execute a NETCONF Java Applicaon | 23
NETCONF Java Toolkit Class: Device | 10
NETCONF Java Toolkit Class: NetconfSession | 12
67