What is the IOS Service API?

The Cisco IOS Service API allows you to write applications that access router information and change system configurations using commands equivalent to Cisco IOS commands in config and EXEC modes.

What package must my application depend upon to use this api?

Your application must depend upon the package axp-iosapi.<platform><version>.pkg

How would I package my application with this dependency?

When you are creating your command line arguments to run the packaging script pkg_build.sh, you must include the parameter --deps '<dependency package ssid>,<dependency version>'. An example is given below. Be sure to get your dependency package ssid by using the script pkg_info.sh.

--deps '8cec8ee5-54c3-4667-b62e-d4a31805d44a,all'

Do I have to install this dependency package separately onto the AXP module?

No, you can bundle it with your application using the bundling script pkg_bundle.sh

Do I need to configure the ISR or AXP Module for this API to work?

Yes, you need to add netconf over beep protocol functionality to both components. On the ISR you'll type the commands below. Be sure to replace <port number> with your actual port number. You can also use ACLs to limit communication, but they're not shown here.

config t
sasl profile SASL_PROFILE
mechanism anonymous
netconf beep listener <port number> sasl SASL_PROFILE
netconf max-sessions 16
end
copy run start

On the AXP service module, you can either manually add the netconf over beep protocol or include it in your source code for you application. The manual steps are shown below. The 'ISR IP address' must match the ip of your ISR, and the 'port number' must also match the chosen port number specified in the net conf beep commands on your ISR.

config t
netconf beep initiator <ISR IP address> <port number>
netconf max-sessions 16
end
copy run start


Please provide a source code example of this API.

IOSTest.java
import com.cisco.aesop.apphosting.iosapi.*;
import com.cisco.aesop.apphosting.appreapi.*;
import java.io.*;

/**
*Sample IOSTest class to configure the service module and modify the router *interface. Uses the IOS Service API for
router modification and the CLI Service *API to configure the Service Module. In a production level program,the *System.out.println
commands should be replaced by logging.
*Be sure to replace the [router-ip] [port] strings in the configureSM method
*with your router IP and the matching port number you set up on the router for *netconf communication. In the modifyRouter method
be sure to replace the
*[your description] string with a new description of the interface. The *modifyRouter method also assumes that your router has an
gigabitethernet 0/0 *interface. If this interface is not present on your router please change the
*'int gig0/0' value to an interface your router has.
*/
public class IOSTest{

/**
*Constructor
*/
public IOSTest(){}

/**
* Checks if netconf is already configured on the Service Module
* @return true if netconf configured, otherwise false.
* @throws Exception
*/
public boolean isNetconfConfiguredOnSM() throws Exception{
final String cmd = "show run | include netconf";
boolean result = false;
CommonServiceImpl apiCall = new CommonServiceImpl();
AppreMessage msg = new AppreMessage();

System.out.println("Entering isNetconfConfiguredOnSM");
msg.setRequest(cmd);
if(apiCall.exec(msg) != AppreAPI.FAIL){
String response = msg.getResponse();
if(response.length()>0 && response.indexOf("netconf")!=-1){
result = true;
}
}
else{
throw new Exception("Command failed " + cmd);
}
return result;
}


/**
* Copies the running configuration to the startup configuration
* on the Service Module.
* @throws Exception
*/
public boolean saveConfigurationOnSM() throws Exception{
final String cmd = "copy run start";
boolean result = false;
CommonServiceImpl apiCall = new CommonServiceImpl();
AppreMessage msg = new AppreMessage();

System.out.println("Entering saveConfigurationOnSM");
msg.setRequest(cmd);
if(apiCall.exec(msg) != AppreAPI.FAIL){
result = true;
}
else{
throw new Exception("Command failed " + cmd);
}
return result;
}


/**
* Configures netconf over beep on the service module
* @throws Exception
*/
public boolean configureSM() throws Exception {
final String cmd = "netconf beep initiator [router-ip] [port],netconf max-sessions 16";
boolean result = false;
CommonServiceImpl apiCall = new CommonServiceImpl();
AppreMessage msg = new AppreMessage();

System.out.println("Entering configureSM");
msg.setRequest(cmd);
if(apiCall.config(msg) != AppreAPI.FAIL){
result = true;
}
else{
throw new Exception("Command failed " + cmd);
}
return result;
}


/**
* Reconfigures the router running configuration.
* @throws Exception
*/
public void modifyRouter() throws Exception {
final String cmd = "int gig0/0;description [your description]";

System.out.println("Entering modifyRouter");

IosServiceAPI iosapi = IosapiFactory.getIosApi("commonservice");
IosapiMessage msg = new IosapiMessage();
msg.setRequest(cmd);
int status = iosapi.config(msg);
if(IosServiceAPI.FAIL == status){
throw new Exception("Command Failed " + cmd + " Message: " + msg.getResponse());
}
else{
System.out.println("Status returned is:'" + status + "' Command '" + cmd + "'response is:" + msg.getResponse());
}
}


public static void main(String[] args){
boolean isSMConfigured = false;
try{
System.out.println("Starting application.");
IOSTest IOS = new IOSTest();
if(!IOS.isNetconfConfiguredOnSM()){
if(IOS.configureSM()){
IOS.saveConfigurationOnSM();
isSMConfigured=true;
}
}
else{
System.out.println("Skipping service module configuration");
isSMConfigured=true;
}
if(isSMConfigured){
IOS.modifyRouter();
}
}
catch(Exception e){
System.out.println(e.getMessage());
}
finally{
System.out.println("Application done.");
}
}

How do I compile the source code example?

To compile this java source code you'll need the jar files appreapi.jar and iosapi.jar. These jar files are provided in the AXP sdk. So to compile this code your command line would like something like:

javac -classpath appreapi.jar:iosapi.jar IOSTest.java

Do I need to include the appreapi.jar and iosapi.jar files in my package?

No. The appreapi.jar file is built into the AXP Guest OS, and the iosapi.jar file is included with your axp-iosapi.<platform><version>.pkg, and gets added to the AXP Guest OS when you install this package. In the AXP Guest OS of your application these files reside in the directory /usr/lib/java.

Where are the library files located in the sdk and Guest OS for other language support such as C, C++ and Python?

The files for support of these languages in the sdk are located in the directory axp-sdk.<version>. In the AXP module Guest OS, you'll find files supporting these languages in the /lib directory and child directories below it.

0 Attachments
4163 Views
Average (0 Votes)
The average rating is 0.0 stars out of 5.
Comments