Network Assurance · Topic 7 of 7

NETCONF and RESTCONF

Configure and verify NETCONF and RESTCONF on IOS XE: ports, transport, datastores, operations, HTTP methods, YANG data paths and enabling commands.

  • 5 min
  • Includes a diagram
In a nutshell
  • NETCONF uses XML over SSH on port 830. RESTCONF uses HTTPS.
  • Both use YANG data models.
  • NETCONF operations include get, get-config, edit-config, lock and commit.

What it is

NETCONF and RESTCONF are standard protocols that let software configure and read a network device using YANG data models.

The command line is made for people, and scripts that parse it break easily.

These protocols give programs a structured and predictable way to work. NETCONF is the older of the two, and it uses XML over SSH. RESTCONF gives a REST style interface over HTTPS, and it uses JSON or XML.

Scriptautomation toolNETCONF over SSH port 830RouterYANG data modelsScriptautomation toolRESTCONF over HTTPS port 443RouterYANG data models

How it works

Both protocols read and write the same data models, with different transports.

NETCONF

NETCONF is defined in RFC 6241. It runs over SSH, and the standard port is 830. The messages are XML, and the protocol is built on remote procedure calls.

A session starts with a hello exchange. Each side sends the capabilities it supports, and these include the YANG models that the device offers.

NETCONF works with named stores of configuration, called datastores.

DatastoreMeaning
RunningThe active configuration
StartupThe configuration that loads at boot, where the device supports it
CandidateA working copy that you edit and then commit, where the device supports it

The main operations are:

OperationPurpose
getRead configuration and operational data
get-configRead configuration from a datastore
edit-configChange configuration
copy-configCopy one datastore to another
delete-configDelete a datastore
lock and unlockStop others changing a datastore while you work
commitApply a candidate datastore

A change can be sent as a single transaction. When the client asks for rollback on error, a failed change is rejected as a whole, so the device is not left half configured.

Enabling NETCONF on IOS XE

Router(config)# username admin privilege 15 secret PASSWORD
Router(config)# aaa new-model
Router(config)# aaa authentication login default local
Router(config)# aaa authorization exec default local
Router(config)# netconf-yang
Router# show netconf-yang sessions

The command netconf-yang starts the NETCONF server on port 830. Authentication and authorisation are needed, since the session uses the device credentials. show netconf-yang sessions lists the active sessions.

A client connects with SSH to port 830 and asks for the netconf subsystem. Tools and libraries such as the Python library ncclient do this for you.

RESTCONF

RESTCONF is defined in RFC 8040. It maps NETCONF ideas onto HTTP. It uses HTTPS, and the device exposes the data under a path that starts with /restconf.

HTTP methodAction
GETRead data
POSTCreate a new resource
PUTReplace a resource
PATCHMerge a change into a resource
DELETERemove a resource

The data format is set by headers. The media types are application/yang-data+json and application/yang-data+xml. Use the Accept header to say what you want back, and Content-Type to say what you send.

GET /restconf/data/ietf-interfaces:interfaces HTTP/1.1
Host: 10.1.1.1
Accept: application/yang-data+json

The path names the YANG module, then the container. A reply looks like this:

{
  "ietf-interfaces:interfaces": {
    "interface": [
      {
        "name": "GigabitEthernet1",
        "type": "iana-if-type:ethernetCsmacd",
        "enabled": true
      }
    ]
  }
}
ClientHTTPS requestGET restconf data pathRouterRESTCONF server200 OK and JSON bodyClientparses the data

Enabling RESTCONF on IOS XE

Router(config)# restconf
Router(config)# ip http secure-server
Router(config)# ip http authentication local
Router# show platform software yang-management process

RESTCONF depends on the secure HTTP server, so it must be on. The user credentials are sent with HTTP basic authentication, and that is why the transport must be HTTPS. The last command shows whether the processes behind NETCONF and RESTCONF are running.

NETCONF compared with RESTCONF

An automation script reaches the same router and its YANG data models by two paths: NETCONF with XML over SSH on port 830, and RESTCONF with HTTP methods over HTTPS on port 443.

FeatureNETCONFRESTCONF
TransportSSH, port 830HTTPS, port 443
EncodingXMLJSON or XML
StyleRemote procedure callsREST, with HTTP methods
TransactionsDatastores, lock and commitEach request is its own operation
StandardRFC 6241RFC 8040

Checking the setup

If a client cannot connect, work through these checks:

  1. Is the feature enabled, and are the processes running?
  2. Does the device accept SSH or HTTPS from the client address?
  3. Do the credentials work, and does the user have privilege 15?
  4. Does the data path name a YANG module that the device supports?

What to remember for the exam

Eight facts cover most questions on this topic.

  • NETCONF uses XML over SSH on port 830. RESTCONF uses HTTPS.
  • Both use YANG data models.
  • NETCONF operations include get, get-config, edit-config, lock and commit.
  • NETCONF datastores are running, startup and candidate.
  • RESTCONF uses GET, POST, PUT, PATCH and DELETE.
  • RESTCONF data paths start with /restconf/data.
  • netconf-yang enables NETCONF on IOS XE. restconf enables RESTCONF.
  • RESTCONF needs ip http secure-server.
Exam tip

If a question mentions XML and port 830, the answer is NETCONF. If it mentions HTTP methods and JSON, the answer is RESTCONF.

Common mistakes

These four mistakes appear often.

Forgetting the secure HTTP server for RESTCONF. The restconf command alone does not give you a working HTTPS service.

Using HTTP methods with NETCONF. NETCONF uses its own operations, not GET and PUT.

Skipping authentication setup. Without a valid user, the session is refused.

Mixing up PUT and PATCH. PUT replaces a resource, and PATCH merges a change.

Watch out

Do not send credentials over plain HTTP. Use HTTPS for RESTCONF and SSH for NETCONF.

Check yourself

Work through these three questions.

  • Which port does NETCONF use, and over which transport?

    NETCONF uses port 830 over SSH.

  • Which two commands are needed on IOS XE before RESTCONF works?

    restconf and ip http secure-server, plus working authentication.

  • What is the difference between PUT and PATCH in RESTCONF?

    PUT replaces a resource, and PATCH merges a change into it.

Topic 7 of 7 in Network Assurance

Test yourself on Network Assurance

The full Cisco CCNP 350-401 ENCOR question bank has 854 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Cisco. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.