VPN Service Inventory Collection: Retrieve Service Config Intents and Operational Data for L2VPN and L3VPN
This example shows step-by-step NB API calls to collect VPN service inventory, including L2VPN/L3VPN configurations, operational data, health status, and underlay transport. OSS/BSS/HCO systems retrieve service data in batches until they collect all data from CNC.
This example uses the operations from the following API references.
- L2VPN Service Config Intent Retrieval API: Retrieves L2VPN service configuration intents.
- L3VPN Service Config Intent Retrieval API: Retrieves L3VPN service configuration intents.
- L2VPN Service Oper Data Retrieval API: Retrieves L2VPN service operational data, including health status and underlay transport.
- L3VPN Service Oper Data Retrieval API: Retrieves L3VPN service operational data, including health status and underlay transport.
Prerequisites
Before running the examples, ensure that the following prerequisites are met:
- Complete the Day-0 device configurations on all devices.
- Set up the device topology correctly in the CNC cluster.
- If your topology or data differs from the example input, adjust the input data accordingly. Refer to the CNC installation guide and administration guide for details on configuring day-0 devices and topology.
Collect VPN Service Inventory
Run service-inventory-collection.sh
from the example directory to retrieve L2VPN/L3VPN configurations, operational data, health status, and underlay transport in batches from offset zero.
cd ~/cnc-api-examples/service-inventory;./service-inventory-collection.sh
The script execution outputs the API execution and results to standard output and store the results in multiple files in output folder.
Output
During and after the execution of the script, the following output files are available in output directory: ~/cnc-api-examples/service-inventory/output
- l2vpn/service-config-intent-$offset-$limit.json
- l3vpn/service-config-intent-$offset-$limit.json
Note: Multiple files are generated in the specified format based on the number of requests that are executed to collect all L2VPN and L3VPN service data from the target server.
Script Details: service-inventory-collection.sh
#!/bin/bash
#
# Usecase:
# This example scenario demonstrates step by step NB API invocation with the required input
# to collect VPN service inventory that includes all vpn (L2VPN, L3VPN) service config intents
# as well as the service oper data with service health status and the discovered underlay
# transport from CNC by any OSS/BSS/HCO systems. In this scenario, API supporting the batch retrieval
# is used to retrieve the services data until the end of data reached.
#
export PRJ=$(cd `dirname $0`; pwd)
. $PRJ/../common-scripts/env
. $PRJ/../common-scripts/cnc-api-common.sh
# Retrieve all VPN services oper data consists of service health status
# and discovered underlay transport
# params: type=l2vpn|l2vpn, offset>=0, limit >0 and <=100
retrieve-all-vpn-services-health-and-transport-data() {
# STEP 1: Prepare the API with inputs for batch processing that includes offset and limit
# starting with offset=0, invoke API in a loop
# STEP 2: For each API call, process the response, if the response contains empty list or
# list items less than requested limit, end the loop or continue with the next batch
# by incrementing the offset to the next offset after offset+count(number of items returned)
svcType="$1"
declare -i offset=$2
declare -i limit=$3
echo "Retrieving All $svcType Services Health status and underlay transport data with offset=$offset, limit=$limit..."
declare -i count=-1
svcRcPath="ietf-l2vpn-ntw:l2vpn-ntw/vpn-services/vpn-service"
svcCountJqExp='."ietf-l2vpn-ntw:vpn-service" | length'
case "$svcType" in
"l3vpn")
svcRcPath="ietf-l3vpn-ntw:l3vpn-ntw/vpn-services/vpn-service"
svcCountJqExp='."ietf-l3vpn-ntw:vpn-service" | length'
;;
esac
outputDir="$PRJ/output/$svcType"
mkdir -p $outputDir
echo "Retrieved service oper data is saved to Output dir: $outputDir"
while :
do
# CNC CAT restconf api specific to service type (l2vpn or l3vpn) used for retrieving service operdata with
# query paramters content=nonconfig, offset and limit.
CNC_API_URL="$CNC_CAT_RESTCONF_CTX/data/$svcRcPath?content=nonconfig&offset=$offset&limit=$limit"
svcDataFile="service-oper-data-$offset-$limit.json"
CNC_API_OUTPUT=$outputDir/$svcDataFile
http_get $CNC_API_URL $CNC_API_OUTPUT
# the list will have one or more items. for end of data, it returns an empty {} json.
count=$(cat $CNC_API_OUTPUT | jq "$svcCountJqExp")
if [ -z "$count" ] || [ $count -lt $limit ]; then
echo "end of service oper data retrieval : $count"
break
else
echo "service oper data retrieved : $count"
offset+=count
fi
done
}
# Retrieve all VPN services config intent
# params: type=l2vpn|l2vpn, offset>=0, limit>0 and <=100
retrieve-all-vpn-services-config-intent() {
# STEP 1: prepare the API with inputs for batch processing that includes offset and limit
# starting with offset=0, invoke API in a loop
# STEP 2: on each API call, process the response, if the response contains empty list or
# list items less than requested limit, end the loop or continue with the next batch
# by incrementing the offset to the next offset after offset+count(number of items returned)
svcType="$1"
declare -i offset=$2
declare -i limit=$3
echo "Retrieving All $svcType Services Config Intent data with offset=$offset, limit=$limit ..."
declare -i count=-1
svcRcPath="ietf-l2vpn-ntw:l2vpn-ntw/vpn-services/vpn-service"
svcCountJqExp='."ietf-l2vpn-ntw:vpn-service" | length'
case "$svcType" in
"l3vpn")
svcRcPath="ietf-l3vpn-ntw:l3vpn-ntw/vpn-services/vpn-service"
svcCountJqExp='."ietf-l3vpn-ntw:vpn-service" | length'
;;
esac
outputDir="$PRJ/output/$svcType"
mkdir -p $outputDir
echo "Retrieved service config intetns will be save to Output dir: $outputDir"
while :
do
# CNC NSO RESTConf api specific to service type (l2vpn or l3vpn) used for retrieving service operdata with
# query paramters content=nonconfig, offset and limit.
CNC_API_URL="$CNC_NSO_RESTCONF_CTX/data/$svcRcPath?content=config&offset=$offset&limit=$limit"
svcDataFile="service-config-intent-$offset-$limit.json"
CNC_API_OUTPUT=$outputDir/$svcDataFile
http_get $CNC_API_URL $CNC_API_OUTPUT
# The list will have one or more items. for end of data, it returns 204 http code with empty response.
count=$(cat $CNC_API_OUTPUT | jq "$svcCountJqExp")
if [ -z "$count" ] || [ $count -lt $limit ]; then
echo "end of service config intent retrieval : $count"
break
else
echo "service config intents retrieved : $count"
offset+=count
fi
done
}
main() {
# Assume CNC JWT has been obtained prior to invoking this method by executing get-cnc-jwt.sh script
# Read from JWT file and export it as AUTH_TOKEN_HDR
export_jwt
# start the collection by collecting the l2vpn, l3vpn service config intent from nso api and and the oper-data from cat api.
start_time="$(date)"
retrieve-all-vpn-services-config-intent "l2vpn" 0 5
retrieve-all-vpn-services-config-intent "l3vpn" 0 5
retrieve-all-vpn-services-health-and-transport-data "l2vpn" 0 5
retrieve-all-vpn-services-health-and-transport-data "l3vpn" 0 5
end_time="$(date)"
echo "DONE retrieving All Service Inventory"
echo "Start Time: $start_time"
echo "End Time : $end_time"
}
main