New hardware - SDN Controller
The SDN controller embedded in Cisco Packet Tracer 8.0.0 similar to existing real-world SDN Controllers like Cisco DNA Center and APIC-EM.
The Network Controller, managed using its Web GUI or using its APIs, provides a centralized dashboard to view the network’s state, allowing network administrtor to quickly identify & troubleshoot issues, and push configuration changes to all managed devices at once.
The Network Controller can be accessed from real -world applications running on the host computer, like a web browser, VScode, Python, curl, Postman, to execute network automation scripts. External access to SDN controller has to be enabled in the Cisco Packet Tracer 8.0.0 preferences before beeing able to enable it in the SDN controller device configuration tabs.
Step 1 : Enable External Access for network Controller REST API global setting
Step 2 : Enable remote access and configure HTTP port in SDN Controller configuration tab
SDN controller programming with Python, VSCode and WSL
WSL integration
The Cisco Packet Tracer 8.0 SDN Coontroller provides a REST API with enables network programmability using Python language. As the API can be accessed from the host, the network administrator can leverage the power of real worl development environment and program the Cisco Packet Tracer emulated network using Microsoft VScode IDE and Windows Subsystem Linux (WSL 1 supported for http://localhost:<port> access, access with WSL2 using http://<host ip>:<port> has not been tested yet and could encounter firewalling issues).
The Microsoft VScode and it's WSL integration extension editor can also be used to ease SDN API programmability with Python 3, leverage code quality tools such as Pylint or Sonarqube, and collaborate inside your team using GIT SCM.
Programming the SDN controller
The Cisco Packet Tracer 8.0 software defined network (SDN) controller can be programmed using it's REST API which can be accessed using the programming language of your choice. As Cisco DevNet is actively promoting Python for network programmability and providing code samples on https://developer.cisco.com/site/python/, Python 3 will be used in the following exemples.
Warning : Python code provided in Cisco Packet Tracer sample PKT files fail when used in a real world Python environment as some HTTP python libraries emulated in Packet Tracer are missing in Python3.
The following Python3 code gathers security token and lists Packet Tracer 8.0 SDN Controller network devices from the host computer :
import json
import requests
def main():
#Get security token
securityUrl = "http://localhost:58000/api/v1/ticket"
securityData = json.dumps({"username": "test","password": "test"})
securityHeader = {'Content-type': 'application/json'}
r = requests.post(securityUrl, data=securityData, headers=securityHeader)
token = r.json()["response"]["serviceTicket"]
print("token: " + token)
#Get hosts
apiAccessHeader = {}
apiAccessHeader['content-type'] = 'application/json'
apiAccessHeader['x-auth-token'] = token
r = requests.get('http://localhost:58000/api/v1/network-device', headers=apiAccessHeader);
print(json.dumps(r.json(), indent=2))
if __name__ == "__main__":
main()
The result is a JSON paylod listing all the connected devices as well as the following information :
- Platform type : ISR4300
- Serial number and IOS software version
- Interface count
- Mac Addresses, Ip Addresses and connected interfaces
- Device uptime
- ...
token: NC-34-2444786aba2d4ef787d5-nbi
{
"response": [
{
"collectionStatus": "Managed",
"connectedInterfaceName": [
"FastEthernet0/3",
"GigabitEthernet0/0/0"
],
"connectedNetworkDeviceIpAddress": [
"",
"2.1.1.2"
],
"connectedNetworkDeviceName": [
"Switch",
"Router"
],
"errorDescription": "",
"globalCredentialId": "ca8f6f2a-eef2-488e-96da-96c42eb80548",
"hostname": "Router",
"id": "FDO13025YJT-uuid",
"interfaceCount": "4",
"inventoryStatusDetail": "Managed",
"ipAddresses": [
"1.1.1.5",
"2.1.1.1"
],
"lastUpdateTime": "31",
"lastUpdated": "2020-02-14 20:18:51",
"macAddress": "000C.85AD.AB89",
"managementIpAddress": "1.1.1.5",
"platformId": "ISR4300",
"productId": "ISR4331",
"reachabilityFailureReason": "",
"reachabilityStatus": "Reachable",
"serialNumber": "FDO13025YJT-",
"softwareVersion": "15.4",
"type": "Router",
"upTime": "18 minutes, 58 seconds"
},
{
"collectionStatus": "Managed",
"connectedInterfaceName": [
"GigabitEthernet0/0/1",
"GigabitEthernet0/0/0"
],
"connectedNetworkDeviceIpAddress": [
"2.1.1.1",
"3.1.1.2"
],
"connectedNetworkDeviceName": [
"Router",
"Router"
],
"errorDescription": "",
"globalCredentialId": "ca8f6f2a-eef2-488e-96da-96c42eb80548",
"hostname": "Router",
"id": "FDO1302EP0P-uuid",
"interfaceCount": "3",
"inventoryStatusDetail": "Managed",
"ipAddresses": [
"2.1.1.2",
"3.1.1.1"
],
"lastUpdateTime": "31",
"lastUpdated": "2020-02-14 20:18:51",
"macAddress": "000C.85A6.7E56",
"managementIpAddress": "3.1.1.1",
"platformId": "ISR4300",
"productId": "ISR4321",
"reachabilityFailureReason": "",
"reachabilityStatus": "Reachable",
"serialNumber": "FDO1302EP0P-",
"softwareVersion": "15.4",
"type": "Router",
"upTime": "18 minutes, 58 seconds"
},
{
"collectionStatus": "Managed",
"connectedInterfaceName": [
"GigabitEthernet0/0/1"
],
"connectedNetworkDeviceIpAddress": [
"3.1.1.1"
],
"connectedNetworkDeviceName": [
"Router"
],
"errorDescription": "",
"globalCredentialId": "ca8f6f2a-eef2-488e-96da-96c42eb80548",
"hostname": "Router",
"id": "FDO130280QN-uuid",
"interfaceCount": "3",
"inventoryStatusDetail": "Managed",
"ipAddresses": [
"3.1.1.2"
],
"lastUpdateTime": "31",
"lastUpdated": "2020-02-14 20:18:51",
"macAddress": "0002.4A8E.036D",
"managementIpAddress": "3.1.1.2",
"platformId": "ISR4300",
"productId": "ISR4321",
"reachabilityFailureReason": "",
"reachabilityStatus": "Reachable",
"serialNumber": "FDO130280QN-",
"softwareVersion": "15.4",
"type": "Router",
"upTime": "18 minutes, 58 seconds"
},
{
"collectionStatus": "Unsupported",
"errorDescription": "",
"globalCredentialId": "ca8f6f2a-eef2-488e-96da-96c42eb80548",
"id": "FTX1524S1GF-uuid",
"interfaceCount": "3",
"inventoryStatusDetail": "Unsupported",
"ipAddresses": [
"1.1.1.10"
],
"lastUpdateTime": "31",
"lastUpdated": "2020-02-14 20:18:51",
"macAddress": "00D0.9794.E246",
"managementIpAddress": "1.1.1.10",
"platformId": "",
"productId": "",
"reachabilityFailureReason": "NOT_VALIDATED",
"reachabilityStatus": "Reachable",
"serialNumber": "",
"type": "",
"upTime": ""
},
{
"collectionStatus": "Unreachable",
"errorDescription": "",
"globalCredentialId": "ca8f6f2a-eef2-488e-96da-96c42eb80548",
"id": "uuid",
"interfaceCount": "9",
"inventoryStatusDetail": "Unreachable",
"ipAddresses": [
"1.1.1.11"
],
"lastUpdateTime": "31",
"lastUpdated": "2020-02-14 20:18:51",
"macAddress": "",
"managementIpAddress": "192.168.0.1",
"platformId": "",
"productId": "",
"reachabilityFailureReason": "Unable to ping to device. ",
"reachabilityStatus": "Unreachable",
"serialNumber": "",
"type": "",
"upTime": ""
}
],
"version": "1.0"
}