Top Banner
Juniper Extension Toolkit Developer Guide Release 1.0 Modified: 2016-07-28 Copyright © 2016, Juniper Networks, Inc.
56

Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Jun 06, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Juniper Extension Toolkit Developer Guide

Release

1.0

Modified: 2016-07-28

Copyright © 2016, Juniper Networks, Inc.

Page 2: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Juniper Networks, Inc.1133 InnovationWaySunnyvale, California 94089USA408-745-2000www.juniper.net

Copyright © 2016, Juniper Networks, Inc. All rights reserved.

Juniper Networks, Junos, Steel-Belted Radius, NetScreen, and ScreenOS are registered trademarks of Juniper Networks, Inc. in the UnitedStates and other countries. The Juniper Networks Logo, the Junos logo, and JunosE are trademarks of Juniper Networks, Inc. All othertrademarks, service marks, registered trademarks, or registered service marks are the property of their respective 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 publication without notice.

Juniper Extension Toolkit Developer Guide1.0Copyright © 2016, Juniper Networks, Inc.All rights reserved.

The information in this document is current as of the date on the title page.

YEAR 2000 NOTICE

Juniper Networks hardware and software products are Year 2000 compliant. Junos OS has no known time-related limitations through theyear 2038. However, the NTP application is known to have some difficulty in the year 2036.

ENDUSER LICENSE AGREEMENT

The Juniper Networks product that is the subject of this technical documentation consists of (or is intended for use with) Juniper Networkssoftware. Use of such software is subject to the terms and conditions of the End User License Agreement (“EULA”) posted athttp://www.juniper.net/support/eula.html. By downloading, installing or using such software, you agree to the terms and conditions ofthat EULA.

Copyright © 2016, Juniper Networks, Inc.ii

Page 3: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Table of Contents

About the Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix

Documentation and Release Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix

Supported Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix

Documentation Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix

Documentation Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi

Requesting Technical Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xii

Self-Help Online Tools and Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . xii

Opening a Case with JTAC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xii

Chapter 1 JET Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

Juniper Extension Toolkit Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

JET Interaction with Junos OS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

JET Application Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

JET Application Deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

Junos OS Automation Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

JET Developer Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

JET Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

MIB Support for JET Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Chapter 2 Developing JET Applications Using the JET VM and IDE . . . . . . . . . . . . . . . . 21

Overview of Developing a JET Application Using a VM . . . . . . . . . . . . . . . . . . . . . . 21

Setting Up the JET Virtual Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

Downloading the Packages You Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

Downloading Vagrant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

Downloading VirtualBox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

Downloading the JET Files from the Juniper Networks Download

Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

Launching the JET VM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

Updating the Build Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

Stopping the JET VM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

Juniper Extension Toolkit Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

Developing an Application Using the JET IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

Requesting the Certificate Using the JET IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

Building and Creating a Package by Using the JET IDE . . . . . . . . . . . . . . . . . . . . . . 31

JSON File Format for JET Application Packaging . . . . . . . . . . . . . . . . . . . . . . . . . . 32

Main Section Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

Mandatory Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

Optional Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

Source Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

Dependent Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

Dependent Python Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

iiiCopyright © 2016, Juniper Networks, Inc.

Page 4: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

JSON File with All Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

Chapter 3 Developing JET Applications Manually Using the JET VM . . . . . . . . . . . . . . . 39

Working Manually in the Virtual Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

Setting the PATH Environment Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

Executing the Certificate Request Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

Creating a Development Sandbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

Developing an Application by Manual Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . 43

Building and Creating a JET Application Package Without Using an IDE . . . . . . . 44

Chapter 4 Developing JET Applications Using Python . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

Overview of Developing a JET Application Using Python . . . . . . . . . . . . . . . . . . . . 47

Downloading and Installing the JET Python Client Package . . . . . . . . . . . . . . . . . 48

Developing an Application by Using the JET Python Client Package . . . . . . . . . . 49

Creating an Unsigned Package by Using the Python Packaging Tool . . . . . . . . . . . 51

Deploying a JET Python Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

Chapter 5 Developing Applications Using Other Languages . . . . . . . . . . . . . . . . . . . . . . 53

Overview of Developing a JET Application Using IDL . . . . . . . . . . . . . . . . . . . . . . . 53

Downloading and Compiling the IDL File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

Chapter 6 Debugging JET Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

Debugging Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

Debugging JET Applications on a Device Running Junos OS . . . . . . . . . . . . . . . . . 56

Copyright © 2016, Juniper Networks, Inc.iv

Juniper Extension Toolkit Developer Guide

Page 5: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

List of Figures

Chapter 1 JET Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

Figure 1: JET Request-Response and Notification Services . . . . . . . . . . . . . . . . . . . 16

Chapter 2 Developing JET Applications Using the JET VM and IDE . . . . . . . . . . . . . . . . 21

Figure 2: Developing an Application Using a VM . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

Chapter 4 Developing JET Applications Using Python . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

Figure 3: Developing a JET Application Using Python . . . . . . . . . . . . . . . . . . . . . . . 47

Chapter 5 Developing Applications Using Other Languages . . . . . . . . . . . . . . . . . . . . . . 53

Figure 4: Developing a JET Application Using IDL . . . . . . . . . . . . . . . . . . . . . . . . . . 53

vCopyright © 2016, Juniper Networks, Inc.

Page 6: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Copyright © 2016, Juniper Networks, Inc.vi

Juniper Extension Toolkit Developer Guide

Page 7: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

List of Tables

About the Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix

Table 1: Notice Icons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x

Table 2: Text and Syntax Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x

Chapter 1 JET Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

Table 3: JET Developer Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

Chapter 2 Developing JET Applications Using the JET VM and IDE . . . . . . . . . . . . . . . . 21

Table 4: Steps Involved in Developing a JET Application Using a VM . . . . . . . . . . . 22

Table 5: Juniper Extension Toolkit Menu Options . . . . . . . . . . . . . . . . . . . . . . . . . . 26

Table 6: Mandatory Attributes in the JSON File Main Section . . . . . . . . . . . . . . . . 33

Table 7: Optional Attributes in the JSON File Main Section . . . . . . . . . . . . . . . . . . 34

Table 8: Source Attributes You Can Use in a JSON File . . . . . . . . . . . . . . . . . . . . . . 35

Chapter 4 Developing JET Applications Using Python . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

Table 9: Steps Involved in Developing a JET Application Using Python . . . . . . . . 48

Chapter 5 Developing Applications Using Other Languages . . . . . . . . . . . . . . . . . . . . . . 53

Table 10: Steps Involved in Developing a JET Application Using IDL . . . . . . . . . . . 53

viiCopyright © 2016, Juniper Networks, Inc.

Page 8: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Copyright © 2016, Juniper Networks, Inc.viii

Juniper Extension Toolkit Developer Guide

Page 9: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

About the Documentation

• Documentation and Release Notes on page ix

• Supported Platforms on page ix

• Documentation Conventions on page ix

• Documentation Feedback on page xi

• Requesting Technical Support on page xii

Documentation and Release Notes

To obtain the most current version of all Juniper Networks®technical documentation,

see the product documentation page on the Juniper Networks website at

http://www.juniper.net/techpubs/.

If the information in the latest release notes differs from the information in the

documentation, follow the product Release Notes.

Juniper Networks Books publishes books by Juniper Networks engineers and subject

matter experts. These books go beyond the technical documentation to explore the

nuances of network architecture, deployment, and administration. The current list can

be viewed at http://www.juniper.net/books.

Supported Platforms

For the features described in this document, the following platforms are supported:

• MX104

• MX2010

• MX2020

• MX240

• MX480

• MX80

• MX960

Documentation Conventions

Table 1 on page x defines notice icons used in this guide.

ixCopyright © 2016, Juniper Networks, Inc.

Page 10: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Table 1: Notice Icons

DescriptionMeaningIcon

Indicates important features or instructions.Informational note

Indicates a situation that might result in loss of data or hardware damage.Caution

Alerts you to the risk of personal injury or death.Warning

Alerts you to the risk of personal injury from a laser.Laser warning

Indicates helpful information.Tip

Alerts you to a recommended use or implementation.Best practice

Table 2 on page x defines the text and syntax conventions used in this guide.

Table 2: Text and Syntax Conventions

ExamplesDescriptionConvention

To enter configuration mode, type theconfigure command:

user@host> configure

Represents text that you type.Bold text like this

user@host> show chassis alarms

No alarms currently active

Represents output that appears on theterminal screen.

Fixed-width text like this

• A policy term is a named structurethat defines match conditions andactions.

• Junos OS CLI User Guide

• RFC 1997,BGPCommunities Attribute

• Introduces or emphasizes importantnew terms.

• Identifies guide names.

• Identifies RFC and Internet draft titles.

Italic text like this

Configure themachine’s domain name:

[edit]root@# set system domain-namedomain-name

Represents variables (options for whichyou substitute a value) in commands orconfiguration statements.

Italic text like this

Copyright © 2016, Juniper Networks, Inc.x

Juniper Extension Toolkit Developer Guide

Page 11: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Table 2: Text and Syntax Conventions (continued)

ExamplesDescriptionConvention

• To configure a stub area, include thestub statement at the [edit protocolsospf area area-id] hierarchy level.

• Theconsoleport is labeledCONSOLE.

Represents names of configurationstatements, commands, files, anddirectories; configurationhierarchy levels;or labels on routing platformcomponents.

Text like this

stub <default-metricmetric>;Encloses optional keywords or variables.< > (angle brackets)

broadcast | multicast

(string1 | string2 | string3)

Indicates a choice between themutuallyexclusive keywords or variables on eitherside of the symbol. The set of choices isoften enclosed in parentheses for clarity.

| (pipe symbol)

rsvp { # Required for dynamicMPLS onlyIndicates a comment specified on thesame lineas theconfiguration statementto which it applies.

# (pound sign)

community namemembers [community-ids ]

Encloses a variable for which you cansubstitute one or more values.

[ ] (square brackets)

[edit]routing-options {static {route default {nexthop address;retain;

}}

}

Identifies a level in the configurationhierarchy.

Indention and braces ( { } )

Identifies a leaf statement at aconfiguration hierarchy level.

; (semicolon)

GUI Conventions

• In the Logical Interfaces box, selectAll Interfaces.

• To cancel the configuration, clickCancel.

Representsgraphicaluser interface(GUI)items you click or select.

Bold text like this

In the configuration editor hierarchy,select Protocols>Ospf.

Separates levels in a hierarchy of menuselections.

> (bold right angle bracket)

Documentation Feedback

We encourage you to provide feedback, comments, and suggestions so that we can

improve the documentation. You can provide feedback by using either of the following

methods:

• Online feedback rating system—On any page of the Juniper Networks TechLibrary site

athttp://www.juniper.net/techpubs/index.html, simply click the stars to rate thecontent,

and use the pop-up form to provide us with information about your experience.

Alternately, you can use the online feedback form at

http://www.juniper.net/techpubs/feedback/.

xiCopyright © 2016, Juniper Networks, Inc.

About the Documentation

Page 12: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

• E-mail—Sendyourcommentsto [email protected]. Includethedocument

or topic name, URL or page number, and software version (if applicable).

Requesting Technical Support

Technical product support is available through the JuniperNetworksTechnicalAssistance

Center (JTAC). If you are a customer with an active J-Care or Partner Support Service

support contract, or are covered under warranty, and need post-sales technical support,

you can access our tools and resources online or open a case with JTAC.

• JTAC policies—For a complete understanding of our JTAC procedures and policies,

review the JTAC User Guide located at

http://www.juniper.net/us/en/local/pdf/resource-guides/7100059-en.pdf.

• Product warranties—For product warranty information, visit

http://www.juniper.net/support/warranty/.

• JTAC hours of operation—The JTAC centers have resources available 24 hours a day,

7 days a week, 365 days a year.

Self-Help Online Tools and Resources

For quick and easy problem resolution, Juniper Networks has designed an online

self-service portal called the Customer Support Center (CSC) that provides youwith the

following features:

• Find CSC offerings: http://www.juniper.net/customers/support/

• Search for known bugs: http://www2.juniper.net/kb/

• Find product documentation: http://www.juniper.net/techpubs/

• Find solutions and answer questions using our Knowledge Base: http://kb.juniper.net/

• Download the latest versions of software and review release notes:

http://www.juniper.net/customers/csc/software/

• Search technical bulletins for relevant hardware and software notifications:

http://kb.juniper.net/InfoCenter/

• Join and participate in the Juniper Networks Community Forum:

http://www.juniper.net/company/communities/

• Open a case online in the CSC Case Management tool: http://www.juniper.net/cm/

Toverify serviceentitlementbyproduct serial number, useourSerialNumberEntitlement

(SNE) Tool: https://tools.juniper.net/SerialNumberEntitlementSearch/

Opening a Casewith JTAC

You can open a case with JTAC on theWeb or by telephone.

• Use the Case Management tool in the CSC at http://www.juniper.net/cm/.

• Call 1-888-314-JTAC (1-888-314-5822 toll-free in the USA, Canada, and Mexico).

Copyright © 2016, Juniper Networks, Inc.xii

Juniper Extension Toolkit Developer Guide

Page 13: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

For international or direct-dial options in countries without toll-free numbers, see

http://www.juniper.net/support/requesting-support.html.

xiiiCopyright © 2016, Juniper Networks, Inc.

About the Documentation

Page 14: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Copyright © 2016, Juniper Networks, Inc.xiv

Juniper Extension Toolkit Developer Guide

Page 15: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

CHAPTER 1

JET Overview

• Juniper Extension Toolkit Overview on page 15

• JET Packages on page 18

• MIB Support for JET Applications on page 19

Juniper Extension Toolkit Overview

Juniper Extension Toolkit (JET), an evolution of the Junos SDK, provides amodern,

programmatic interface for developersof third-party applications. It focusesonproviding

a standards-based interface to the Juniper Networks Junos®operating system (Junos

OS) for management and control plane functionality.

JET supports the following:

• Multiple languages for applications that run off-box

• Python for applications that run on a device running Junos OS

• Applications written in C to run on devices that do not use the JET APIs

• An event notification method that enables the applications to respond to selected

system events

JET does not use Junos OS APIs, which makes it independent of any Junos OS release.

The JET API release model supports installation of a JET service process (jsd) image

other than the base image from the Junos OS release. A corresponding JET client API

package is released for each jsd image.

JET APIs are synchronous in nature.

See the following sections for more developer overview information. For information on

configuring JET applications to run on a device running Junos OS, see the

Administration Guide for Juniper Extension Toolkit Applications.

• JET Interaction with Junos OS on page 16

• JET Application Development on page 16

• JET Application Deployment on page 17

• Junos OS Automation Tools on page 17

• JET Developer Tasks on page 18

15Copyright © 2016, Juniper Networks, Inc.

Page 16: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

JET Interaction with Junos OS

JET uses the Apache Thrift framework for cross-language services (see

http://thrift.apache.org/) as amechanism to enable request-response service. Thrift

provides an interface definition language (IDL) that enables you to define APIs. These

IDL files (with .thrift as the file extension) are compiled using the Thrift compiler to

generate source code to be used for the server and client applications. The Thrift server

is part of the JET service process (jsd), which runs on Junos OS.

For eventnotification, JETuses theMessageQueueTelemetryTransport (MQTT)protocol

(see http://mqtt.org/). Event notification is implemented through themosquitto

notification broker (see http://mosquitto.org/).

Figure 1 on page 16 illustrates the request-response and notification services.

Figure 1: JET Request-Response and Notification Services

JET Application Development

JET includesavirtualmachine (VM)packageasavagrant file that includes its ownEclipse

integrated development environment (IDE), plug-ins, and other tools and libraries. There

is also a Python client package.

This developer guide covers a few JET application development scenarios using the

supplied packages; however, JET APIs function within any framework (for example,

Twisted). You can use any programming framework that you prefer to develop

applications. You can use any IDE (such as PyCharm IDE or Eclipse) while developing

against the Python library JET supplies, or you can use your preferred editor. You can use

a text editor (such as vi) to directly write a Python file.

Copyright © 2016, Juniper Networks, Inc.16

Juniper Extension Toolkit Developer Guide

Page 17: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

This guide covers the following JET application development scenarios:

• Application development workflow using the JET VM and the IDE

• Application development workflow using the JET VMwith manual workflow

• Application development workflow using the Python client package

• Application development workflow using the interface definition language (IDL) and

the MQTT library

JET Application Deployment

The following deployments for Python applications on Junos OS are supported:

• Regular Junos OS (veriexec-enabled Junos OS)with the python configuration enabled

at the [edit system scripts language] hierarchy level. In this scenario, the systemwill

not perform veriexec checks for a Python application as long as the application is

located under the /var/db/scripts/jet directory and configured at the [edit system

extensions] hierarchy level. In this scenario, an unsigned package for a Python-only

application (a Python script with no dependencies on unsigned shared libraries) will

work. Any application in a signed package will also work.

• Regular JunosOS (veriexec-enabled JunosOS)with the python configuration disabled

at the [edit system scripts language] hierarchy level. In this environment, only those

Python scripts that are part of a signed package can be executed. Therefore, only a

signed package will work for this scenario.

NOTE: Junos OS supports using symbolic links for files in the/var/db/scripts/jet directory, but the device will only execute the script at the

target location if it is signed.

Junos OS Automation Tools

JET isoneof the JunosOSautomation tools.Other automation tools for JunosOS include

the following:

• Junos PyEZ—Amicroframework for Python that enables you to remotelymanage and

automate devices running Junos OS.

• Automation scripts (see the Automation Scripting Feature Guide).

• Commit scripts—Manage the configuration process.

• Operational scripts—Perform operational tasks and network troubleshooting.

• Event scripts and event policy—Instruct the operating system to perform actions in

response to system events.

• SNMP scripts—Support customMIBs until they are implemented in Junos OS.

17Copyright © 2016, Juniper Networks, Inc.

Chapter 1: JET Overview

Page 18: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

JET Developer Tasks

This guide describes the developer tasks necessary to produce third-party applications.

See Table 3 on page 18 for a list of the JET developer tasks and where to find details

about them in this guide.

Table 3: JET Developer Tasks

Find Details HereJET Developer Task

• Overview of Developing a JET Application Using aVM on page 21

• Overview of Developing a JET Application UsingPython on page 47

• OverviewofDevelopinga JETApplicationUsing IDLon page 53

Workflows for developing a JETapplication

• Debugging Tips on page 55

• debugging“Debugging JETApplicationsonaDeviceRunning Junos OS” on page 56

Debugging JET applications

For more information on developing applications, see Building Your First JET Application

and the following example applications in the Juniper Extension Toolkit Getting Started

Guide:

• JET Interfaces Application

• JET Firewall and Policer Application

• JET Notification Application

RelatedDocumentation

http://thrift.apache.org/•

• Junos PyEZ

• Automation Scripting Feature Guide

• JET Packages on page 18

JET Packages

Juniper Extension Toolkit (JET) packages support JET applications on the device and

provide the framework for application development.

There is a difference in packaging of client APIs between development for on-device

applications and development for off-box applications. By default, a set of JET client

packagemodules is installed on-device. Thesemodules provide a set ofwrapper Python

APIs for developing JET applications. To develop applications to run off-box, developers

need to download and install the JET client API package.

Copyright © 2016, Juniper Networks, Inc.18

Juniper Extension Toolkit Developer Guide

Page 19: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

On-device packages:

• Junos PyEZ—Amicroframework for Python that comes installed on the device. The

PyEZmicroframework enables you to remotelymanageandautomatedevices running

Junos OS. Junos PyEZ is designed to provide the capabilities that a user would have

on the Junos OS command-line interface (CLI) in an environment built for automation

tasks. For more information, see Junos PyEZ.

• jsd package—The JET service process (jsd) runs on JunosOS.On the TCPport (default

port 9090), jsd listens for and receives requests from JETapplications to executeAPIs.

Off-box packages:

• JET client API package—For every release of the jsd image, a correspondingAPI bundle

image is also released. The API bundle package naming is independent of Junos OS

so that one API bundle can be used across multiple jsd releases.

RelatedDocumentation

Junos PyEZ•

• Automation Scripting Feature Guide

MIB Support for JET Applications

In Junos OS, the SNMP functionality is implemented as a distributed agent using RFC

2741,Agent Extensibility (AgentX)Protocol Version 1. TheAgentXprotocol allowsamaster

agent to be extended by independent subagents, so you can havemany subagents, and

thecommunicationbetweenmasteragentandsubagents is through theAgentXprotocol.

In JunosOS, themaster agentprocess (snmpd) listens for external requestsonastandard

port.

An SNMPMIB is a collection of information organized hierarchically. MIBs define the

managed objects that an SNMPmanagermonitors on SNMP agent or subagents. When

anSNMPmanager requests information fromanSNMPagent, the SNMPagent retrieves

the current value of the requested information from the MIB.

Object identifiers (OIDs) uniquely identify manged objects in a MIB hierarchy.

Whenever a request for a given OID is received, the master agent forwards the request

to the connected subagent that is responsible for the given OID. For example, if a get or

get-next is received for an OID (let us say, bgpPeerLocalAddr, for example), on receiving

the request, snmpd forwards the request to the Routing process (rpd) subagent to get

the value for the OID. After receiving the value, snmpd sends the response with the

standard response protocol data unit (PDU) to the network management system.

SNMP agent functionality is supported for JET applications as well, by extension. The

JET agent application can run as a SNMP subagent, and it can register its ownMIB OIDs

with snmpd.Whenever there is a request for the application-hostedOID, the requestwill

be forwarded to the application through the AgentX protocol, and the application then

has to respond back with the value requested.

You can also create a JET subagent as an offbox agent application.

19Copyright © 2016, Juniper Networks, Inc.

Chapter 1: JET Overview

Page 20: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

NOTE:

To implementMIBhandlers, youmust followopensourcenet-snmpsubagentguidelines.

To implement a JET subagent as an offbox agent application:

1. Download the open source net-snmp from http://www.net-snmp.org/download.html.

2. Build the open source net-snmp to the required native machine.

3. Write the MIB and the subagent method handlers as per the net-snmp specification.

4. Build the application.

5. Addtheconfigurationon thedevice running JunosOStoallowexternalSNMPsubagent

connections.

usser@host# set snmp subagent tcp routing-instance default

6. Run the application to register the OIDs being served.

After the application registration is successful, the application’s registered OIDs can be

polled similar to how other Junos OS supported OIDs are polled.

RelatedDocumentation

• Juniper Extension Toolkit Overview on page 15

Copyright © 2016, Juniper Networks, Inc.20

Juniper Extension Toolkit Developer Guide

Page 21: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

CHAPTER 2

Developing JETApplicationsUsing the JETVM and IDE

• Overview of Developing a JET Application Using a VM on page 21

• Setting Up the JET Virtual Machine on page 23

• Juniper Extension Toolkit Menu on page 25

• Developing an Application Using the JET IDE on page 27

• Requesting the Certificate Using the JET IDE on page 29

• Building and Creating a Package by Using the JET IDE on page 31

• JSON File Format for JET Application Packaging on page 32

Overview of Developing a JET Application Using a VM

If an application that youwant to develop has a dependency on C or C++modules or the

application needs to be signed, then youmust use the Juniper Extension Toolkit (JET)

virtual machine (VM) for application development.

The JET VM is a 64-bit Ubuntu 12.04 long-term support release. Application developers

canuse the JET IDEprovidedwith theVMtodevelopapplications. Tosetup thedeveloper

environment, youmust download the JET bundle and client package from the Juniper

Networks download site, and then, once the VM is up, install the JET toolchain, Eclipse

integrated development environment (IDE), plug-ins, and other tools and libraries that

are required for developing on-device or off-box applications. For more details on the

installing the VM, see “Setting Up the JET Virtual Machine” on page 23.

For a diagram of the JET workflow using the JET VM, see Figure 2 on page 22.

Table 4 on page 22 provides topics relating to the workflow steps in Figure 2 on page 22.

21Copyright © 2016, Juniper Networks, Inc.

Page 22: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Figure 2: Developing an Application Using a VM

A

B

C

D

E

g043

325

WIllapplication

run on a devicerunning

Junos OS?

Develop appusing JET project

Set up signingcert keys

Create the signedpackage usingJET sandbox

Deploy applicationpackage on a device

running Junos OS

Develop appusing PvDEV project

Python apps

Use Pythonpackaging tool

to create unsignedpackage

Deploy applicationpackage on externalserver or run the app

directly from VM

External server

Linux (Ubuntu)

Downloadand set up JET VM

Veriexec Junos

NO YES

Table 4: Steps Involved in Developing a JET Application Using a VM

Link toWorkflow StepWorkflow Step

“Setting Up the JET Virtual Machine” on page 23A

“Developing an Application Using the JET IDE” on page 27B

“Requesting the Certificate Using the JET IDE” on page 29C

“Building and Creating a Package by Using the JET IDE” on page 31D

Deploying an Application Package on a Device Running Junos OSE

RelatedDocumentation

• Setting Up the JET Virtual Machine on page 23

• Overview of Developing a JET Application Using Python on page 47

• Overview of Developing a JET Application Using IDL on page 53

Copyright © 2016, Juniper Networks, Inc.22

Juniper Extension Toolkit Developer Guide

Page 23: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Setting Up the JET Virtual Machine

Three packages are used from the Juniper Networks download site to set up the JET

virtual machine (VM): a vagrant zip file, a JET bundle containing a backing sandbox and

toolchain, and the Python library client.

To be ready to use the JET VM and integrated development environment (IDE) to create

applications, complete the following tasks:

• Downloading the Packages You Need on page 23

• Launching the JET VM on page 24

• Updating the Build Environment on page 25

• Stopping the JET VM on page 25

Downloading the Packages You Need

Installing the JET VM on your development machine provides a complete development

environment with tools for building and packaging applications. It also provides the JET

IDE.

Download and install the following packages:

• Downloading Vagrant on page 23

• Downloading VirtualBox on page 23

• Downloading the JET Files from the Juniper Networks Download Site on page 24

Downloading Vagrant

Vagrant (https://www.vagrantup.com/) is a software that creates and configures virtual

development environments. You can think of it as a higher-level wrapper around

virtualization software such asVirtualBox (https://www.virtualbox.org/wiki/Downloads).

You can use Vagrant to manage the JET development virtual machine (VM).

To download Vagrant:

• Go to https://www.vagrantup.com/ and download Vagrant for your system’s platform

(Windows, Mac, or Linux).

Downloading VirtualBox

NOTE: For the JET VM, Juniper Networks supports only the VirtualBoxhypervisor.

23Copyright © 2016, Juniper Networks, Inc.

Chapter 2: Developing JET Applications Using the JET VM and IDE

Page 24: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

To download and install VirtualBox:

1. Go to https://www.virtualbox.org/wiki/Downloads.

2. Download and install the VirtualBox package for your platform and the VirtualBox

extension package.

3. Enable hardware virtualization support on your machine BIOS if it is not already

enabled.

Downloading the JET Files from the Juniper Networks Download Site

The JET VM is downloaded from the Juniper Networks download website at

http://www.juniper.net/support/downloads/?p=jet#sw in the form of three packages:

• JET sandbox and toolchain file

• Python client library file

• JET-vagrant.zip file

Launching the JET VM

The vagrant zip file is started first.

To launch the JET VM:

1. Create a jet-vagrant directory and extract the JET-vagrant.zip file you downloaded

from the Juniper Networks download site to that directory.

2. Change to the jet-vagrant directory where you have extracted the JET-vagrant.zip file.

3. Issue the vagrant up command.

If needed, use the following default login credentials:

username: vagrantpassword: vagrant

Wait for the Ubuntu desktop screen to come up in Oracle VM VirtualBox. You will see

the Eclipse icon. This is the icon you use for the JET IDE.

4. Double-click the Eclipse icon to start the JET IDE.

Next, before starting touse the JET IDE, youmust install the JETbundlecontainingbacking

sandbox and toolchain and the Python client library.

Copyright © 2016, Juniper Networks, Inc.24

Juniper Extension Toolkit Developer Guide

Page 25: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Updating the Build Environment

To download and install the Python client library, you can either use the following

procedure or extract and run install.sh script.

To update the build environment:

1. Start the JET IDE.

See the procedure “Launching the JET VM” on page 24 for details.

2. Change theperspectivebyselecting JuniperExtensionToolkit fromtheWindow>Open

perspective -> Othermenu.

3. Once the perspective is change, select Juniper Extension Toolkit > Update build

environment.

4. Point the input fields to downloaded JET bundle and client library and install them.

Stopping the JET VM

When you are done using the VM, stop and exit Vagrant.

To stop and exit Vagrant and the IDE:

1. Go to the command-line prompt for your system.

2. In the jet-vagrant directory, issue the vagrant halt command.

RelatedDocumentation

Juniper Extension Toolkit Overview on page 15•

• Juniper Extension Toolkit Menu on page 25

Juniper Extension Toolkit Menu

The Juniper Extension Toolkit menu is the integrated development environment (IDE)

menu thatprovides theoptionsyouneed tocreateprojectsandsandboxes fordeveloping

and testing your applications.

To get directions on how to open the JET IDE, see “Setting Up the JET Virtual Machine”

on page 23.

To view the Juniper Extension Toolkit options (Table 5 on page 26), open the JET IDE and

click the Juniper Extension Toolkitmenu.

The default perspective of the Juniper Extension Toolkit (JET) IDE has four panes: two

top panes and two bottom panes. The top left-side pane has two windows controlled

by tabs: the Sandbox Explorer (Sandbox) tab and the Remote Systems (Remote) tab.

By default, the Sandbox Explorer window is active.

25Copyright © 2016, Juniper Networks, Inc.

Chapter 2: Developing JET Applications Using the JET VM and IDE

Page 26: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Table 5: Juniper Extension Toolkit Menu Options

DescriptionMenu

Create a new project and sandbox for developingapplications or select an existing project.

JET Project

Launch a build of the application based on the configurationthat was provided in Build Configuration.

Build Sandbox

Compile and build the application by running themakecommand in the directory that was selected in the SandboxExplorer window.

Build Directory

Configure your build settings and launch a build for thecurrent sandbox. In the Build Configurationwindow, you canconfigure the following settings:

• Select the packages that will be included in the build.

• Select the targeted architecture.

• Select the packaging type (operating system).

Build Configuration

Launch and export a build based on the configuration youprovide in Export Configuration.

Export Application

Configure your build and export settings, build yourapplication, and export your application.

In the Export Configuration window, you can configure thefollowing settings:

• Select the directory location for the application once ithas been built.

• Select the packages to include in the build.

• Select the targeted architecture.

• Select the packaging type (operating system).

Export Configuration

Build, install, and test the application based on the settingsconfigured in Run JET Configuration.

Run JETWorkflow

Copyright © 2016, Juniper Networks, Inc.26

Juniper Extension Toolkit Developer Guide

Page 27: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Table 5: Juniper Extension Toolkit Menu Options (continued)

DescriptionMenu

Configure your build settings, configure the router setting,launch a build, and execute operational commands neededto install and test the application.

In the JET Configuration window, you can configure thefollowing:

• In the Export Configuration tab, select the packages toinclude in the build, select the targeted architecture, andselect packaging type.

• In the Device Details tab, specify the router on which youwant to test your application by entering in the routername, login ID, password, and pathnamewhere youwantto install the application.

• In the Operational Commands tab, enter operationalcommands to runon the router prior to andafter installingthe application.

• In the Device Configuration window, enter a configurationin curly bracket ({}) format to run on the router prior toand after installing the application.

Run JET Configuration

Update your JETdevelopment environment by installing JETbundle packages and JET Python Client packages that youhave downloaded.

Update Build Environment

Install a certificate, request the signing of a certificate, andgenerateacertificate request.See “Requesting theCertificateUsing the JET IDE” on page 29.

Certificate

Generate makefiles based on input entered in a JSON file.For more information on JSON files, see “JSON File Formatfor JET Application Packaging” on page 32.

Generate Build Files

“Developing an Application Using the JET IDE” on page 27 provides more information

and shows you how and when to use some of these Juniper Extension Toolkit menu

options.

RelatedDocumentation

JSON File Format for JET Application Packaging on page 32•

• Requesting the Certificate Using the JET IDE on page 29

• Developing an Application Using the JET IDE on page 27

Developing an Application Using the JET IDE

Application developers can use the integrated development environment (IDE) provided

with the Juniper Extension Toolkit (JET) virtual machine (VM) to develop applications.

27Copyright © 2016, Juniper Networks, Inc.

Chapter 2: Developing JET Applications Using the JET VM and IDE

Page 28: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

To develop an application by using the JET IDE:

1. Start the JET IDE and select Juniper Extension Toolkit > JET Project.

2. Type in a project name, select an item from the Applications List, and click Finish.

The new project name appears in the Sandbox Explorer window (top left pane). You

can expand the new project name and see several directories, including the src

directory. Expand the src directory to see several more directories, among them the

python, lib, and bin directories. These are the directories you use to create new

application components.

3. Highlight the appropriate directory for your applications files (choose from among

the python, lib, and bin directories), either select File > New > Folder or right-click and

select New> Folder, type a folder name, and click Finish.

• To develop applications in Python, create a new application directory in the python

directory and develop the application inside the newly created directory.

• To create a C/C++ library, create a new library directory in the lib directory and

develop the library inside the newly created directory.

• To create a C/C++ executable, create a new application directory in the bin directory

and develop the application inside the newly created directory.

For example, for a C/C++ application, you can put some libraries in the lib directory

and other application components in the bin directory.

4. Create files for your application code.

Highlight the appropriate subdirectory, either select File >New>File or right-click and

select New> File, type a filename, and click Finish.

5. Create the code in the application files and do one of the following to save: select File

> Save, press Ctrl+s, or click the diskette icon.

Makefiles and themanifest file are created automatically once you have created the

JSON file.

RelatedDocumentation

Juniper Extension Toolkit Menu on page 25•

• Requesting the Certificate Using the JET IDE on page 29

• Building and Creating a Package by Using the JET IDE on page 31

Copyright © 2016, Juniper Networks, Inc.28

Juniper Extension Toolkit Developer Guide

Page 29: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Requesting the Certificate Using the JET IDE

In order to develop and distribute JET applications, youmust install a package signing

certificate onto the virtual machine (VM). You do this by creating a certificate request

and sending it to Juniper Networks. When you receive the certificate, you install it in the

VM.

CAUTION: Never sendyour signingkey toanyone, including JuniperNetworks.The key enables anyone to sign applications that your router will trust.Therefore, it should be treated with the same level of security as the rootpassword for the routers. Once you obtain your signing key, save it in a fileoutside of the VM.

Before you can create a certificate request, youmust have the provider prefix—a uniquely

identifying prefix that represents the name of your organization. This prefix should have

been provided to a contact at your organization. If you do not know this prefix, you must

request it before running the jet-certificate-request command. Contact JET Certificate

Processing at [email protected].

To create a signed application, request certificates and copy them as explained in the

following procedure. This procedure is optional if you want to create an unsigned

application.

To create a certificate request using the IDE:

1. Select Juniper Extension Toolkit > Certificate > Generate Certificate.

2. Complete the fields in the Generate Certificate Request pane.

The script prompts for the following data:

• ISO Code

• State

• Municipality

• Organization Name

• Organization Provider Prefix

• User String

This is an additional specification of your choosing. It could be a string specifying

the development team or project name. The user string can consist of a lowercase

letter followed by one or more lowercase letters or numbers.

• Deployment Scope

29Copyright © 2016, Juniper Networks, Inc.

Chapter 2: Developing JET Applications Using the JET VM and IDE

Page 30: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

• Index number

This number is known as a certificate generations number. It is 1 for your initial

certificate. When a certificate expires and a new one is requested, youmust

increment the number.

• E-mail address

We recommend against using a personal e-mail address for the certificate contact.

3. Click Browse to select a directory in which to create the cert files.

This is usually the /usr/local/junos-jet/certs directory.

4. Click Finish.

To send a certificate request to Juniper Networks:

NOTE: Alternatively, you can use an existing e-mail server to send e-mail [email protected] the certificate request file attached.

1. Select Juniper Extension Toolkit > Certificate > Request Signing.

2. Set up local e-mail SMTP server details and your e-mail details.

3. Fill in the subject of the e-mail.

4. Attach the certificate request file to the e-mail.

5. Send the e-mail.

To install a certificate on the VM:

1. Select Juniper Extension Toolkit > Certificate > Install Certificate.

2. Navigate to the location where the certificate resides and click Finish.

3. Check that the certificates foo_key.pem and foo.pem are both in the directory.

RelatedDocumentation

Juniper Extension Toolkit Menu on page 25•

• Developing an Application by Using the JET Python Client Package on page 49

Copyright © 2016, Juniper Networks, Inc.30

Juniper Extension Toolkit Developer Guide

Page 31: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Building and Creating a Package by Using the JET IDE

After writing your application, write the JSON file by providing details about your

application, which the system uses to autogenerate the makefiles andmanifest file.

NOTE: If you are not using the JET IDE, write the application JSON file insideyour sandbox. For more details, see “JSON File Format for JET ApplicationPackaging” on page 32.

To create the JSON file and the JET package using the JET IDE:

1. Highlight the src directory in the Sandbox Explorer pane, either select File >New>File

or right-click and select New> File, type the filename (use the .json extension), and

click Finish.

The JSON file is placed under the python directory in the Sandbox Explorer pane, and

the JSONEditor is opened and ready for you to create the JSON file. If the JSON Editor

does not open, right-click the .json file and selectOpenWith > JSON Editor.

2. Provide the necessary information about the application and save the file.

• Application Name—Specify the path to the application's implementation directory.

If the application is a binary, the application name is treated as a binary name. The

package name created is based on the value in this field.

• Application Path—Specify the path to the application directory.

• Language—Select the language used for developing the application.

• Main scripts—This is a list attribute and is generally applicable for Python

applications. For binary applications, this item is optional.Main scripts are searched

under the application path.

Specify the filenameor filenamesof themain script or scripts that runon thedevice.

Click Add to add a filename and path. Select a file and click Remove to remove a

file.

• Application type—Select whether an application is to be a standalone program or

a daemon.

• Signed application—Select yes or no.

• Target OS—Select BSD 6 for legacy Junos OS or BSD 10 for Junos OSwith updated

FreeBSD.

• Target architecture—Specify the target architecture on which the application is to

be deployed.

• Applicationdescription—Specify abrief (one-line)descriptionabout theapplication.

This description will be displayed in the CLI show version operational command.

• Specify the list of C compiler flags, the list of C++ compiler flags, and the list of

linker flags, if any.

31Copyright © 2016, Juniper Networks, Inc.

Chapter 2: Developing JET Applications Using the JET VM and IDE

Page 32: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Use linker flags to specify additional libraries to link with or additional link-specific

flags that are required during linking,

• Source files andmodules—Select a category and click Add to add a filename and

path.

Click Preview at any point to see the JSON file format in code.

3. Do one of the following to save the JSON file: select File > Save, press Ctrl+s, or click

the diskette icon.

4. Select the JSON file and click Juniper Extension Toolkit > Generate Build Files from the

menu bar.

Themakefiles andmanifest file are generated automatically..

5. Select the project directory in the left pane and then select one of the following:

• Juniper Extension Toolkit > Build Sandbox—Build the applications using the

configuration provided in Build Configuration.

• Juniper Extension Toolkit > Build Configuration—Select which applications to build,

which targets to build for, and build once you click Finish.

• Juniper Extension Toolkit > Run JET Configuration—Specify which device to load the

application on and what commands and configurations to include.

Once the build is successful, the package is created in the project ship directory. The

ship directory is in the project directory under the junos-jet-sb-obj directory. You can

see the ship directory in the left pane once the package has been built.

RelatedDocumentation

Juniper Extension Toolkit Menu on page 25•

• JSON File Format for JET Application Packaging on page 32

• Juniper Extension Toolkit Overview on page 15

• JET Packages on page 18

JSON File Format for JET Application Packaging

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy

for humans to read and write, and also easy for machines to parse and generate. For

more details, see http://www.json.org.

After application development is complete, write the JSON file describing the content

to be built and packaged for deployment on the device. JSON files consist of a collection

of attributes. Attributes use two structures:

• A collection of key-value pairs

• An ordered list of values

These attributes are included inside a set of curly braces.

Copyright © 2016, Juniper Networks, Inc.32

Juniper Extension Toolkit Developer Guide

Page 33: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

The following subtopics describe each of the attributes contained in the JSON format

for application packaging:

• Main Section Attributes on page 33

• Source Attributes on page 35

• Dependent Libraries on page 35

• Dependent Python Modules on page 36

• JSON File with All Attributes on page 37

Main Section Attributes

The top block of the JSON file is themain section of the file. It consists ofmandatory and

optional attributes.

• Mandatory Attributes on page 33

• Optional Attributes on page 34

Mandatory Attributes

Table 6 on page 33 describes themandatory attributes that all JSON files for application

packaging must have in the main section.

Table 6: Mandatory Attributes in the JSON File Main Section

Example ValuesDescriptionAttribute

"sample_pyapp"Specify the name of the application."app-name"

"python/sample_pyapp"Specify the path to the application’s implementation directory. Allpaths should be relative to sandbox src.

"app-path"

"python", "c", "c++"Specify the language used for developing the application."language"

["foo.py", "bar.py"]This is a list attributes. Specify the filename or filenames of themainscript or scripts that run on the device (do not specify the modulehere). Themain script files will be deployed under the/var/db/scripts/jet path on the device.

"main-scripts"

"standalone" or "daemon"Specify whether an application is to be a standalone program or adaemon.

"app-type"

"yes" or "no"Indicate whether the application is to be signed or unsigned."sign"

"bsd6" or "bsd10"Specify whether the application is to be deployed on legacy JunosOS (bsd6) or Junos OSwith upgraded FreeBSD (bsd10).

"os-type"

"i386", "powerpc", "octeon","xlr", or "arm"

Specify the target architecture on which the application is to bedeployed.

"target-arch"

"Simple Python test app"Write a brief (one-line) description about the application. This willbe displayed in the show version operational command output.

"description"

33Copyright © 2016, Juniper Networks, Inc.

Chapter 2: Developing JET Applications Using the JET VM and IDE

Page 34: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

The following is an example of a simple application JSON file containing only the

mandatory attributes:

{ "app-name": "sample_pyapp", "app-path": "python/sample_pyapp", "language": "python", "main-scripts": ["foo.py", "bar.py"], "app-type": "standalone", "sign": "no", "os-type": "bsd6", "target-arch": "i386", "description": "Simple Python test app" }

Optional Attributes

Table 7 on page 34 describes the optional attributes you can include in themain section

of the JSON file for application packaging.

Table 7: Optional Attributes in the JSON File Main Section

Example ValuesDescriptionAttribute

"flag1 flag2 flag3"Specify the list of C compiler flags, if any. Compilationflags can be defined for the main section, dependentlibraries (dep-libs), or dependent Pythonmodules(dep-py-modules).

"c-compiler-flags"

"flag1 flag2 flag3"Specify the list of C++ compiler flags, if any.Compilation flags can be defined for themain section,dependent libraries (dep-libs), or dependent Pythonmodules (dep-py-modules).

"c++-compiler-flags"

"flag1 flag2 flag3"Specify the list of linker flags, if any. Use these flags tospecify additional libraries to link to or additionallink-specific flags that are required during linking, Youcan define linker-specific flags either in the mainsection or in the dep-py-modules section.

"linker-flags"

The following is an example main section with mandatory and optional attributes:

{ "app-name": "sample_pyapp", "app-path": "python/sample_pyapp", "language": "python", "main-scripts": ["foo.py", "bar.py"], "app-type": "standalone", "sign": "no", "os-type": "bsd6", "target-arch": "i386", "description": "Simple Python test app", "c-compiler-flags": "-DFOO -DBAR", "c++-compiler-flags": "-DAPP_CHECK –DSOMETHING_ON", "linker-flags": "-lstdc++ -lfoo" }

Copyright © 2016, Juniper Networks, Inc.34

Juniper Extension Toolkit Developer Guide

Page 35: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Source Attributes

Table 8 on page 35 shows two source attributes you can use to specify source files for

the application package.

Table 8: Source Attributes You Can Use in a JSON File

Example ValuesDescriptionAttribute

"srcs": {"python/sample_pyapp": ["a.py", "b.py"],"python/sample_pyapp/temp": ["temp1.py","temp2.py"]

}

Specify the list of additional source files. For Pythonapplications, these source files are the additionalmodule files. For Cor C++applications, these sourcefiles are the source files to be compiled to generatelib/binary. Each entry should be a key-value pair,where the key is the path of the source files and thevalue is an array of source filenames.

"srcs"

"extn-srcs": {This section is applicable only for Python. Specifythe list of CorC++module files tobe compiled. Each

"extn-srcs""python/sample_pyapp": ["foo.c", "bar.c"],

entry should be a key-value pair, where the key is the "python/sample_pyapp/temp": ["1.cpp", "2.cpp"]path of the source files and the value is an array ofsource filenames.

}

The following is an example Python application with additional module files to be

deployed, along with the main script file:

{ "app-name": "sample_pyapp", "app-path": "python/sample_pyapp", "language": "python", "main-scripts": ["foo.py", "bar.py"], "app-type": "standalone", "sign": "no", "os-type": "bsd6", "target-arch": "i386", "description": "Simple Python test app",

"srcs": { "python/sample_pyapp": ["a.py", "b.py"], "python/sample_pyapp/temp": ["temp1.py", "temp2.py"] },

"extn-srcs": { "python/sample_pyapp": ["foo.c", "bar.c"], "python/sample_pyapp/temp": ["1.cpp", "2.cpp"] } }

Dependent Libraries

The dependent libraries (dep-libs) section contains any dependent libraries that must

be compiled. The library generated fromthis JSONcode is packagedwith theapplication.

The dep-libs section is an array of multiple library dependencies, each composed of the

following key-name pairs:

35Copyright © 2016, Juniper Networks, Inc.

Chapter 2: Developing JET Applications Using the JET VM and IDE

Page 36: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

• "lib-name" is the name of the library.

• "lib-path" is the path of the library source code in the development sandbox.

• "srcs" is a key-value pair in which the path is the key and its value is a list of source

files.

The following is an example of a dep-libs attribute:

"dep-libs": [ { "lib-name": "xyz", "lib-path": "lib/xyz", "srcs": { "lib/xyz": ["foo.c", "bar.c"] } } ]

Dependent PythonModules

The dependent Pythonmodules (dep-py-modules) attribute is used only for Python

applications. This attribute contains any dependent Pythonmodules that need to be

compiled and packaged with the application. The dep-py-modules attribute is an array

in which you can specify multiple Pythonmodule dependencies. Each dependency is

composed of the following objects:

• "py-module-name" is the name of the Pythonmodule.

• "py-module-path" is the path of the Pythonmodule source code in the development

sandbox.

• "srcs" is a key-value pair in which the path is the key and its value is a list of source

files.

• "extn-srcs" is a key-valuepair inwhich thepath is the keyand its value is a list ofPython

extension source files.

The following is an example of a dep-py-modules attribute:

"dep-py-modules": [ { "py-module-name": "module_a", "py-module-path": "python/module_a", "srcs": { "python/module_a": ["foo.py", "bar.py"] }, "extn-srcs": { "python/module_a": ["foo.c", "bar.c"], "python/module_a/sub_mod": ["lmn.cpp"] } } ]

Copyright © 2016, Juniper Networks, Inc.36

Juniper Extension Toolkit Developer Guide

Page 37: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

JSON File with All Attributes

The following is an example of a JSON file containing all possible attributes:

{ "app-name": "sample_pyapp", "app-path": "python/sample_pyapp", "language": "python", "main-scripts": ["foo.py", "bar.py"], "app-type": "standalone", "sign": "no", "os-type": "bsd6", "target-arch": "i386", "description": "Simple Python test app", "c-compiler-flags": "-DFOO -DBAR", "c++-compiler-flags": "-DAPP_CHECK –DSOMETHING_ON", "linker-flags": "-lstdc++ -lfoo",

"srcs": { "python/sample_pyapp": ["a.py", "b.py"], "python/sample_pyapp/temp": ["temp1.py", "temp2.py"] },

"extn-srcs": { "python/sample_pyapp": ["foo.c", "bar.c"], "python/sample_pyapp/temp": ["1.cpp", "2.cpp"] },

"dep-libs": [ { "lib-name": "xyz", "lib-path": "lib/xyz", "srcs": { "lib/xyz": ["foo.c", "bar.c"] } }, { "lib-name": "bar", "lib-path": "lib/bar", "srcs": { "lib/bar": ["zoo.c", "zoom.c"], "lib/bar/temp": ["test1.c", "test2.c"] } } ], "dep-py-modules": [ { "py-module-name": "module_a", "py-module-path": "python/module_a", "srcs": { "python/module_a": ["foo.py", "bar.py"] }, "extn-srcs": { "python/module_a": ["foo.c", "bar.c"], "python/module_a/sub_mod": ["lmn.cpp"] } }, { "py-module-name": "module_b",

37Copyright © 2016, Juniper Networks, Inc.

Chapter 2: Developing JET Applications Using the JET VM and IDE

Page 38: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

"py-module-path": "python/module_b", "c-compiler-flags": "-DSOMEMACRO", "c++-compiler-flags": "-DSOMEMACRO", "linker-flags": "-lfoo", "srcs": { "python/module_b": ["yyy.py", "zoo.py"], "python/module_b/sub_mod": ["1.py", "2.py"] }, "extn-srcs": { "python/module_b": ["xyz.c", "temp.c"], "python/module_b/sub_mod": ["y.cpp", "z.cpp"] } } ] }

RelatedDocumentation

• Building and Creating a Package by Using the JET IDE on page 31

Copyright © 2016, Juniper Networks, Inc.38

Juniper Extension Toolkit Developer Guide

Page 39: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

CHAPTER 3

Developing JET Applications ManuallyUsing the JET VM

• Working Manually in the Virtual Machine on page 39

• Setting the PATH Environment Variable on page 40

• Executing the Certificate Request Script on page 41

• Creating a Development Sandbox on page 42

• Developing an Application by Manual Workflow on page 43

• Building and Creating a JET Application PackageWithout Using an IDE on page 44

WorkingManually in the Virtual Machine

For those developers who prefer to work outside of the integrated design environment

(IDE), this chapter covers how to do certain developer tasks in the terminal part of the

virtual machine (VM).

To work manually on developing JET applications, you still need to download the JET

VM. See Downloading the Packages You Need.

To access a terminal in the VM:

1. Start the JET VM.

See “Setting Up the JET Virtual Machine” on page 23.

2. On the Ubuntu Desktop, click the Dash Home icon.

39Copyright © 2016, Juniper Networks, Inc.

Page 40: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

The Dash Home icon is in the upper left corner of the Ubuntu Desktop and appears

as a circle with three dots arranged around it.

3. Click the Terminal icon.

The terminal window appears with the prompt vagrant@jet-vm:~$.

RelatedDocumentation

Setting the PATH Environment Variable on page 40•

• Downloading the Packages You Need

• Setting Up the JET Virtual Machine on page 23

Setting the PATH Environment Variable

Before setting the PATH environment variable, download the virtual machine (VM)

environment for developing applications. For details on this download, seeDownloading

the Packages You Need.

PATH is the systemvariable that youroperating systemuses to locateneededexecutables

from the command line or terminal window. Using this procedure eliminates the need to

specify the entire path to executables located in your sandbox.

To set the PATH variable:

1. Open a terminal in the VM.

2. Locate the .bashrc file in the /home/vagrant directory.

vagrant@jet-vm:~$ pwd/home/vagrant

vagrant@jet-vm:~$ ls -a

3. Add the path from /root to the /junos-jet-sb/bin directory to the PATH variable in

.bashrc.

For example:

vagrant@jet-vm:~$ echo'PATH=$PATH:/usr/local/junos-jet/16.1R1.3/junos-jet-sb/bin'>>~/.bashrc

Copyright © 2016, Juniper Networks, Inc.40

Juniper Extension Toolkit Developer Guide

Page 41: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

4. Issue the env command to ensure the PATH variable contains the directory path you

just added.

vagrant@jet-vm:~$ envPATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin: /bin:/usr/games:/usr/local/junos-jet/16.1R1.3/junos-jet-sb/bin

RelatedDocumentation

Downloading the Packages You Need•

• Executing the Certificate Request Script on page 41

Executing the Certificate Request Script

In order to develop and distribute JET applications, youmust install a package signing

certificate onto the virtualmachine (VM). You do this by executing the certificate request

script. This script assists you in creating a signing key and a certificate request for use

with JET.

CAUTION: Never sendyour signingkey toanyone, including JuniperNetworks.The key enables anyone to sign applications that your router will trust.Therefore, it should be treated with the same level of security as the rootpassword for the routers. Once you obtain your signing key, save it in a fileoutside of the VM.

Before you can run the certificate request script, youmust have the provider prefix, which

is a uniquely identifying prefix that represents the name of your organization. This prefix

should have been provided to a contact at your organization. If you do not know this

prefix, request it before running the jet-certificate-request command. Contact JET

Certificate Processing at [email protected].

Information the script asks for includes the following data:

• City, state, and country

• Your organization and unit

• Provider prefix

Obtain from JET Certificate Processing at [email protected].

• User string

This is an additional specification of your choosing. It could be a string specifying the

development team or project name. The user string can consist of a lowercase letter

followed by one or more lowercase letters or numbers.

• Deployment scope

This the string assigned by Juniper to differentiate multiple certificates for the same

partner. Leave empty if none was assigned to you.

• Index number

41Copyright © 2016, Juniper Networks, Inc.

Chapter 3: Developing JET Applications Manually Using the JET VM

Page 42: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

This number is known as a certificate generations number. It will be 1 for your initial

certificate. When a certificate expires and a new one is requested, this number will be

incremented.

• E-mail address

We recommend against using a personal e-mail address for the certificate contact.

To create a signed application, request certificates and copy them as explained in the

following procedure. This procedure is optional if you want to create an unsigned

application.

To create a certificate request manually:

1. In a VM terminal, issue the jet-certificate-request command.

The script leads you through a series of questions.

2. Answer the questions, and press Enter after each answer.

A certificate name is synthesized from this information. The certificate name appears

as the stem of the filenames for two files the script creates in the

/usr/local/junos-jet/certs directory: filename_key.pem and filename_req.pem.

3. Save the filename_key.pem file outside the VM.

Ensure that no one outside of your development organization has access to it. Do not

send this file to Juniper Networks.

4. Send the filename_req.pem file to JET Certificate Processing at [email protected].

JET Certificate Processing immediately sends your certificate to you.

To copy your certificate:

• Copy the certificate file to the /usr/local/junos-jet/certs directory.

RelatedDocumentation

Setting the PATH Environment Variable on page 40•

• Creating a Development Sandbox on page 42

Creating a Development Sandbox

The two example applications you can include in your sandbox are echoclient and

echoserver.

First, set up the virtual machine (VM) on your system. See Downloading the Packages

You Need. Once the VM is set up, the following tools are pre-installed and available for

use:

• Supporting files and libraries

• Toolchain

• JET client package

Copyright © 2016, Juniper Networks, Inc.42

Juniper Extension Toolkit Developer Guide

Page 43: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Now you are ready to create the development sandbox in the VM and start developing

applications.

To create a development sandbox:

1. In the VM, go to the /home/vagrant directory.

2. If you have not already done so, set your PATH variable.

For details, see “Setting the PATH Environment Variable” on page 40.

3. Create a sandbox by using themksb command, for example:

vagrant@jet-vm:~$ mksb -nmysandbox

%mksb -nmysandbox

wheremysandbox is the name of the sandbox.

NOTE: You can also check out an example application, for example,

vagrant@jet-vm:~$mksb -nmysandbox echoclient

whereechoclient is anexampleapplication.Thesourcecodeandmakefiles

of echoclient are also checked out.

You are now ready to start developing an application for a specific language.

RelatedDocumentation

• Downloading the Packages You Need

• Executing the Certificate Request Script on page 41

• Developing an Application by Manual Workflow on page 43

Developing an Application byManualWorkflow

To develop your application, create subdirectories in your sandbox for components of

your application. Then develop the code. Lastly, autogenerate the application makefile.

To develop an application:

NOTE: In this procedure, the sandbox directory might be referred to as $SBfor short. That is, $SB is equivalent to /home/vagrant/sandbox-name.

1. Go to the directory in which you keep your sandboxes.

vagrant@jet-vm:~$ cd /home/vagrant

2. Create subdirectories in the sandbox.

a. Use theworkon command to go into your sandbox.

vagrant@jet-vm$workon sandbox-name

43Copyright © 2016, Juniper Networks, Inc.

Chapter 3: Developing JET Applications Manually Using the JET VM

Page 44: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Theworkon command takes you directly to the $SB/src directory and sets the

sandbox correctly.

Alternatively, you can cd to the src directory of your sandbox.

b. Create subdirectories for application code in $SB/src/python or $SB/src/lib or

$SB/src/bin, based on whether you need Python, library, or bin (executable) files.

3. Develop the code.

4. Write an application JSON file.

For details, see “JSON File Format for JET Application Packaging” on page 32.

5. Autogenerate the appropriate makefiles by running the jet-pkg-gen.py command.

The jet-pkg-gen.py command takes two options:

• The -i option is followed by the path and filename of the JSON file.

• The -p option is followed by the path to the src directory of the sandbox.

For example, if you had a sandbox named demo:

vagrant@jet-vm:~/demo/src$ jet-pkg-gen.py -i /home/vagrant/demo/src/demo.json-p /home/vagrant/demo/src

This commandassumes that youhaveadded thepath to jet-pkg-gen.py to your .bashrc

file. If not, you need to include the path to jet-pkg-gen.py:

vagrant@jet-vm:~/demo/src$/usr/local/junos-jet/16.1R1.3/junos-jet-sb/src/junos/host-utils/scripts/jet-pkg-gen.py-i /home/vagrant/demo/src/demo.json -p /home/vagrant/demo/src

NOTE: The autogenerated applicationmakefile will be correct for mostcases; if there are any external library dependencies, themakefile mustbe adjusted accordingly.

RelatedDocumentation

Creating a Development Sandbox on page 42•

• Building and Creating a JET Application PackageWithout Using an IDE on page 44

Building and Creating a JET Application PackageWithout Using an IDE

After development of the application is complete and all themakefiles andmanifest file

are ready, the application can be built and packaged.

To build the JET application package:

1. In the directory in which you keep your sandboxes, use theworkon command to go

into your sandbox.

vagrant@jet-vm:~$workon sandbox-name

Copyright © 2016, Juniper Networks, Inc.44

Juniper Extension Toolkit Developer Guide

Page 45: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

2. (Optional) Test individual pieces of the application by going to subdirectories and

runningmk-i386.

3. Build the entire package.

a. Return to the src directory ($SB/src).

b. Run themk-i386package-namecommand,wherepackage-name is the "app-name"

from the JSON file.

For more on the JSON file, see “JSON File Format for JET Application Packaging”

on page 32.

4. Verify the package is in the $SB/junos-jet-sb-obj/ship/ directory.

vagrant@jet-vm:~/sandbox-name/src$cd/home/vagrant/sandbox-name/junos-jet-sb-obj/shipvagrant@jet-vm:~/sandbox-name/junos-jet-sb-obj/ship$ ls

For example, if your application is called demo, you would see the following files:

demo-16.1.R1.1.tgz demo-16.1.R1.1.tgz.sha1

RelatedDocumentation

• Developing an Application by Manual Workflow on page 43

45Copyright © 2016, Juniper Networks, Inc.

Chapter 3: Developing JET Applications Manually Using the JET VM

Page 46: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Copyright © 2016, Juniper Networks, Inc.46

Juniper Extension Toolkit Developer Guide

Page 47: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

CHAPTER 4

Developing JETApplicationsUsingPython

• Overview of Developing a JET Application Using Python on page 47

• Downloading and Installing the JET Python Client Package on page 48

• Developing an Application by Using the JET Python Client Package on page 49

• Creating an Unsigned Package by Using the Python Packaging Tool on page 51

• Deploying a JET Python Application on page 51

Overview of Developing a JET Application Using Python

You can use Python to develop an application in either of the following circumstances:

• If the application has no dependency on C or C++modules

• If the application is not required to be signed

The Juniper Extension Toolkit (JET) Python client package provides easy-to-use Python

classes andmethods that implement the JET APIs and simplifies the process of using

the Message Queue Telemetry Transport (MQTT) protocol to receive JET notifications.

We recommend that you use the Python client package for Python application

development, but it is not mandatory. You can still directly interact with the interface

definition language (IDL) APIs and use any MQTT library to develop a JET application

using Python.

Figure 3 on page 47 shows the workflow for using JET to develop Python applications.

Table 9 on page 48 links each part of the workflow in Figure 3 on page 47 to a topic in

this chapter.

Figure 3: Developing a JET Application Using Python

Deploy anapplication package

on the external server

Externalserver

DCBAUse the Pythonpackaging tool

to create anunsigned package

Developan application

by using an IDE

Downloadand install the

JET API packagefrom juniper.net

Any OSLinux, FreeBSD, etc.

g043

243

47Copyright © 2016, Juniper Networks, Inc.

Page 48: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Table 9: Steps Involved in Developing a JET Application Using Python

Link toWorkflow StepWorkflow Step

“Downloading and Installing the JET Python Client Package” on page 48A

“Developing an Application by Using the JET Python Client Package” onpage 49

B

“Creating an Unsigned Package by Using the Python Packaging Tool” onpage 51

C

“Deploying a JET Python Application” on page 51D

RelatedDocumentation

Downloading and Installing the JET Python Client Package on page 48•

• Overview of Developing a JET Application Using a VM on page 21

• Overview of Developing a JET Application Using IDL on page 53

Downloading and Installing the JET Python Client Package

Python version 2.7 should be available in the development environment.

To download and install the JET Python client package:

1. Download the JET Python client package from the Juniper Networks website at

http://www.juniper.net/support/downloads/?p=jet#sw to your developmentmachine.

2. Go to the directory where you want to install the JET Python client package.

This is the python-install-path.

3. Install the JET Python client package on the development machine.

You can install the JET Python client package in one of the following ways:

• Use the pip install command—This is the recommended way to install the JET

Python client package. For example, where jet-1.0.1.dev.tgz is the JET Python client

package name:

pip install jet-1.0.1.dev.tgz

• Use the python setup.py install command—Use this commandwhen the pip install

command is not available.

a. Extract files from the JET Python client package.

For example, where jet-1.0.1.dev.tgz is the JET Python client package name:

% tar –xvzf jet-1.0.1.dev.tgz

b. Go to the JET Python client package directory.

% cd jet-1.0.1.dev

c. Issue the python setup.py install command.

Copyright © 2016, Juniper Networks, Inc.48

Juniper Extension Toolkit Developer Guide

Page 49: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

% python setup.py install

After installing the client package, you should see the following directory structure in

the python-install-path/site-packages/jnpr/jet/ directory:

RelatedDocumentation

Developing an Application by Using the JET Python Client Package on page 49•

Developing an Application by Using the JET Python Client Package

You can choose any editor for developing the JET application. For example, you can use

thePyCharm IDEorEclipse todevelopanddebugPythonapplications, orusea texteditor

(such as vi) to write a Python file. Also, you can use any programming framework that

you prefer.

For a tutorial on building a JET application that has no dependency on C or C++modules

and does not have to be signed, see the Juniper Extension Toolkit Getting Started Guide.

Formore information on JETnotificationAPIs, see the Juniper ExtensionToolkit APIGuide.

The JET Python client package provides wrapper APIs to simplify using Thrift and the

MessageQueue Telemetry Transport (MQTT) protocol.With the JET client package, you

can interact with Python classes andmethods provided by the JET Python package.

JetHandler is the main class that you will use to interact with a device running a JET

application. The JetHandler class contains methods to establish connections with a

device running Junos OS, execute APIs, and subscribe to notifications.

When youwrite a JET application for request-response interactions using the JETPython

client package, the application typically creates one instance of the JetHandler class for

each device. The application then uses one of the following methods to connect to the

device:

• OpenRequestResponseSession() to establish a request-response connection

• OpenNotificationSession() to establish a notifications connection

Once connected in request-response service, an application can use amethod such as

OpenRequestResponseSession() to obtain objects that allow the application to make

API calls.

49Copyright © 2016, Juniper Networks, Inc.

Chapter 4: Developing JET Applications Using Python

Page 50: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Once connected in notification service, an application can use amethod such as

OpenNotificationSession() to create topics to which the application subscribes.

When the application has completed its communications with the device, it will call the

CloseRequestResponseSession() or CloseNotificationSession()method to close its

connection to the device.

For JETapplications that supportnotificationsubscription, youcanchoose theappropriate

create method and subscribe to it.

For running JET Python applications on a device running Junos OS, you can configure

command-line arguments for the file. For example, if you had the following script, you

cansupply thearguments fromthe JunosCLIusing theargumentsconfigurationstatement

at the [edit system extensions extension-service application file filename hierarchy level:

import argparse

def main():parser = argparse.ArgumentParser(description='This is a demo script.')

parser.add_argument('-arg1', required=True)parser.add_argument('-arg2', required=True)

args = parser.parse_args()

print args.arg1print args.arg2

if __name__ == '__main__':main()

To configure the arguments in the CLI:

1. Enter configuration mode.

user@device> configureEntering configurationmode[edit]user@device#

2. Configure the command-line arguments.

user@device#setsystemextensionsextension-serviceapplicationfilecmdline_args.pyargument “-arg1 foo -arg2 goo”

3. Commit.

user@device# commit

4. Start the application.

user@device# exituser@device> request extension-service start cmdline_args.pyExtension-service application 'cmdline_args.py' started with pid: 99418foogoo

Copyright © 2016, Juniper Networks, Inc.50

Juniper Extension Toolkit Developer Guide

Page 51: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

RelatedDocumentation

Building Your First JET Application•

• Creating an Unsigned Package by Using the Python Packaging Tool on page 51

Creating an Unsigned Package by Using the Python Packaging Tool

If youdonot include the languagepython statement, youcannotexecuteunsignedPython

scripts on a device running Junos OS.

To create an unsigned JET Python application package:

1. Write the script setup.py.

The setup.py file is a Python file that usually tells you that themodule or package you

are about to install has been packaged and distributed with distutils, which is the

standard way to distribute Pythonmodules.

2. Use the sdistcommand tocreateasourcedistributionand tocreatea tar gzippackage

file.

% python setup.py sdist –formats=gztar

RelatedDocumentation

Building Your First JET Application•

• Developing an Application by Using the JET Python Client Package on page 49

• Deploying a JET Python Application on page 51

• Overview of Developing a JET Application Using a VM on page 21

Deploying a JET Python Application

You can deploy Python applications on an external server or on a device running Junos

OS.

To deploy a Python JET application on an external server, we recommend that you install

the JETClient package on the server. To verify the installation, you should run the sample

applications provided in the JET Client package.

The following deployments of Python applications on devices running Junos OS are

supported:

• Regular Junos OS (veriexec-enabled Junos OS)with the python configuration enabled

at the [edit system scripts language] hierarchy level. In this scenario, the systemwill

not perform veriexec checks for a Python application as long as the application is

located under the /var/db/scripts/jet directory and configured at the [edit system

extensions] hierarchy level. In this scenario, an unsigned package for a Python-only

application (a Python script with no dependencies on unsigned shared libraries) will

work. Any application in a signed package will also work.

• Regular JunosOS (veriexec-enabled JunosOS)with the python configuration disabled

at the [edit system scripts language] hierarchy level. In this environment, only those

51Copyright © 2016, Juniper Networks, Inc.

Chapter 4: Developing JET Applications Using Python

Page 52: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Python scripts that are part of a signed package can be executed. Therefore, only a

signed package will work for this scenario.

NOTE: Junos OS supports using symbolic links for files in the/var/db/scripts/jet directory, but the device will only execute the script at the

target location if it is signed.

RelatedDocumentation

• Overview of Developing a JET Application Using Python on page 47

• Overview of Developing a JET Application Using a VM on page 21

• Overview of Developing a JET Application Using IDL on page 53

Copyright © 2016, Juniper Networks, Inc.52

Juniper Extension Toolkit Developer Guide

Page 53: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

CHAPTER 5

Developing Applications Using OtherLanguages

• Overview of Developing a JET Application Using IDL on page 53

• Downloading and Compiling the IDL File on page 54

Overview of Developing a JET Application Using IDL

To develop JET applications in languages other than Python, you need the interface

definition language (IDL)APIsandaMessageQueueTelemetryTransport (MQTT) library.

IDL is a language-agnostic way of defining APIs.

The MQTT protocol is used to notify clients about Junos OS events. MQTT is a

publish-subscribe basedmessaging protocol for use on top of the TCP/IP protocol. The

publish-subscribe messaging pattern requires a message broker. Themessage broker is

responsible for distributing messages to the interested clients based on the topic of a

message. Clients register with themessage broker and inform themessage broker about

the topics for which they are interested in receiving messages. For more details, see

http://mqtt.org/.

Figure 4: Developing a JET Application Using IDL

Table 10: Steps Involved in Developing a JET Application Using IDL

Link toWorkflow StepWorkflow Step

“Downloading and Compiling the IDL File” on page 54A and B

“Developing an Application by Using the JET Python Client Package” onpage 49

C

53Copyright © 2016, Juniper Networks, Inc.

Page 54: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Table 10: Steps Involved in Developing a JET Application UsingIDL (continued)

Link toWorkflow StepWorkflow Step

“Creating an Unsigned Package by Using the Python Packaging Tool”on page 51

D

RelatedDocumentation

Juniper Extension Toolkit Overview on page 15•

• JET Packages on page 18

• Overview of Developing a JET Application Using Python on page 47

• Overview of Developing a JET Application Using a VM on page 21

Downloading and Compiling the IDL File

For developing applications in languages other than Python, you need the interface

definition language (IDL)APIsandaMessageQueueTelemetryTransport (MQTT) library.

The application developer can use any operating system (OS), for example, Linux or

Windows, for the development environment.

Before you begin, install the Thrift compiler and dependent libraries.

NOTE: For information about installing the Thrift complier and dependentlibraries, see https://thrift.apache.org/docs/BuildingFromSource.

For the application to receive notifications, install an MQTT library for thespecific language. For more details, see http://mqtt.org/.

To download and compile the IDL file:

1. Download the IDL file from the Juniper Networks website at

www.juniper.net/support/downloads/.

2. Compile the IDL file by using the Thrift compiler.

The following is an example command that is specific for generating Java code, butthe thrift -r -gen command can be used for other languages as well:

% thrift –r –gen java RouteService.thrift

For the application to receive notifications, install an MQTT library for the specific

language. For more information, see the Juniper Extension Toolkit API Guide.

RelatedDocumentation

• Overview of Developing a JET Application Using IDL on page 53

Copyright © 2016, Juniper Networks, Inc.54

Juniper Extension Toolkit Developer Guide

Page 55: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

CHAPTER 6

Debugging JET Applications

• Debugging Tips on page 55

• Debugging JET Applications on a Device Running Junos OS on page 56

Debugging Tips

Youmustenable theextension-servicetraceoptionsonthe JunosOSdevicebeforewriting

the sample applications.

In case your application is not able to connect to the Junos service process (jsd):

1. Check whether jsd is up and running on the Junos OS device using the following

command:

ps aux | grep jsd

If not, then restart jsd.

2. If jsd is up, verify the configuration is present on the device using the following CLI

command in configuration mode:

user@device# show system services extension-service

3. If the configuration is present, verify if jsd is listening on configured port 9090:

nestat -a | grep ‘9090’

You should see amatching entry. If you do not, then restart jsd.

To eliminate any firewall issues, use an on-device application to test.

In case of notification applications, verify that your client IP source address (the address

fromwhich the connect is happening) is added to the list of allowed clients in the jsd

notification configuration.

Ensure thatdualRoutingEnginesondevices running JunosOShavemastermode running.

We do not support jsd on backup Routing Engines.

Ensure that themaximumnumberofnotificationconnectionsasconfiguredon thedevice

are not exceeded. Use the following command to see the clients:

netstat -a | grep 1883

55Copyright © 2016, Juniper Networks, Inc.

Page 56: Juniper Extension Toolkit Developer Guide · 2016-07-28 · Title: Juniper Extension Toolkit Developer Guide Author: Juniper Networks Created Date: 20160728182112Z

Debugging JET Applications on a Device Running Junos OS

For debugging applications on a device running Junos OS, you can configure the trace

file and trace option with the system extension-service statement.

For non-daemonized applications that run on the router, you can invoke the debugger at

the same time that you install the application.

To load your application along with the debugger:

1. Use the request extension-service start invoke-debugger cli command.

user@device> request extension-service start invoke-debugger cli application-name.pyExtension-service application 'application-name.py' started with pid: 71246

2. Enter help to display a list of the supported commands.

(Pdb) helpDocumented commands (type help <topic>):========================================EOF bt cont enable jump pp run unt a c continue exit l q s until alias cl d h list quit step up args clear debug help n r tbreak w b commands disable ignore next restart u whatisbreak condition down j p return unalias where Miscellaneous help topics:==========================exec pdbUndocumented commands:======================retval rv

Copyright © 2016, Juniper Networks, Inc.56

Juniper Extension Toolkit Developer Guide