36
NETWORK AUTOMATION WITH PYTHON USING GNS3 AND VIRTUAL BOXAshwin Kotwal
Department of Electronics & Communication Engineering, GGITS, Jabalpur (MP) Mr. Nirdesh Jain
Assistant Professor, GGITS, Jabalpur (MP) Ms. Surya Bazal
Assistant Professor, GGITS, Jabalpur (MP)
Abstract - The future of networking will be inheritance of Automation in it. Automation is a technique of making a process/a system to operate automatically as we intended it to operate. The goal of automation is to reduce operational cost, time, and human errors, increase operational speed, business agility etc. We all know that Enterprises are growing, and new start-ups are coming into the world of internet day by day because of this configuring and managing network devices becomes a complex task. This leads us to implement network automation. Major IT and Network companies like cisco are moving towards Software Defined Networking to automate the network. Scripting languages like Python will play an important role in Network Automation. Inheritance of programming languages into network configuration, maintenance, controlling and, monitoring networks generates Programmable networks.
Keywords:- Network Automation, Software Defined Networking, Scripting Languages, network configuration, network maintenance, network monitoring, programmable networks.
1 INTRODUCTION
1.1 Types of Networks: -
Network infrastructures can vary greatly in terms of:
1. Size of the area covered 2. Number of users connected 3. Number and types of services
available
4. Area of responsibility
The two most common types of network infrastructures:
1. Local Area Network (LAN) - A network infrastructure that provides access to users and end devices in a small geographical area, which is typically an enterprise, home, or small business network owned and managed by an individual or IT department.
2. Wide Area Network (WAN) - A network infrastructure that provides access to other networks over a wide geographical area, which is typically owned and managed by a telecommunications service provider.
Other types of networks include:
(1) Metropolitan Area Network (MAN) - A network infrastructure that spans a physical area larger than a LAN but smaller than a
WAN (e.g., a city). MANs are typically operated by a single entity such as a large organization.
(2) Wireless LAN (WLAN) –It is Similar to a LAN but wirelessly interconnects users and end points in a small geographical area.
(3) Storage Area Network (SAN) - A network infrastructure designed to support file servers and provide data storage, retrieval, and replication.
The number of devices in a network are increasing day by day, this leads to increase in complexity of the network. As the complexity of the network increases configuration and maintenance of network becomes more difficult task to do. Network automation is a solution for this.
1.2 Network automation: -
Network Automation is the process of using software to automate network, security provisioning and management of network in order to continuously maximize network efficiency and functionality.
Network automation is also helpful in Operational cost savings and in improving the time saving for configuring the network devices. Network automation has the ability to work efficiently to maintain networks at large scale. Network
37
automation can be achieved bydeployment of Software Defined Networks.
2 LITERATURE REVIEW
Paul Mihaila, Titus Balan, Radu Curpen, Florin Sandhu proposed method “Network Automation and Abstraction using Python” where they Said
Network programmability is a trend, enhanced and inspired by Software Defined Networks, that are based on scripting methods and standard programming languages used for controlling and monitoring of network elements.
This paper is illustrating some new methods in configuring network devices by using automation, reducing time for equipment configuration and easier maintenance. It also improves network security by recognizing and fixing security vulnerabilities, and it increases the network stability. These methods represent the future of networks, allowing the management of an increased number of devices in a unitary way.
Bruno Astuto A. Nunes, Marc Mendonca, Xuan-Nam Nguyen, Katia Obraczka, and Thierry Turletti in “A Survey of Software-Defined Networking:
Past, Present, and Future of Programmable Networks” they said the idea of programmable networks has recently re-gained considerable momentum due to the emergence of the Software-Defined Networking (SDN) paradigm. SDN, often referred to as a
“radical new idea in networking”, promises to dramatically simplify network management and enable innovation through network programmability.
3 PLATEFORM USED
These are some softwares required for network automation: -
(1) GNS3all-in-one-regular (Version 2.2.20)
(2) Oracle VMVirtualBox (Version 6.1.18) (3) PyCharm Community Edition
(Version 2020.3.5)
(4) WinSCP (Version 5.17.10)
3.1 Installation Process of Required Softwares
1. GNS3 all-in-one-regular
We can download GNS3 from the given link below
https://www.gns3.com/software/downlo ad. Click on download windows option (version 2.2.20), after downloading it, go to download folder left click on it, then this pop-up will come as shown below.
2. Oracle VM Virtual Box
We can download GNS3.VM.VirtualBox from the given link below-
https://www.virtualbox.org/wiki/Downlo ads From available Virtual Box platform packages click on Windows hosts and after this downloading of Virtual Box will start. Downloaded file is a zip file of type.ova, we have to extract it. I will extract it to my desktop, after this we have to install Virtual Box. Click on file name VirtualBox.exe, then we can see the pop-up as shown below.
(3) PyCharm Community Edition We can download PyCharm IDE from the link given below-
https://www.jetbrains.com/pycharm/do wnload/ there are two options to download one is Professional Edition and second one is Community Edition.
We will use Community Edition because it is Open-Source and free.
Professional Edition is a paid version of PyCharm.
Ones the file downloaded then we have to go to the download folder click on pycharm-community-2021.1 icon (2021.1 is a version name), after this installation process will be started.
38
Click on Next, then select folderwhere you want to store all the files of PyCharm IDE and then click Next.
4 WinSCP-5.17.10
We can download WinSCP version 5.17.10 from the link given below- https://winscp.net/eng/download.php Firstly, we have to accept license agreement then we have to select user interface style, here we select commander option then click on next.
4 RUNNING CISCO IOU IMAGES IN GNS3 ON WINDOWS 10
IOU means IOS on Unix and it is a modified IOS used by Cisco for CCIE labs and virtual lab pods used in Cisco Learning Center.
There are both a L3 and L2 IOU versions.IOU is resource friendly and can be run smoothly on a normal laptop or PC. They do notrequire as many resources as the normal IOS images do.
4.1 How to run Cisco IOU on GNS3 Steps for running Cisco IOU on GNS are given below –
1. Generate IOU licence on Virtual Machine- In this step we must copy licence python script using WinSCP
to Virtual Machine. First open WinSCP create new session, enter credentials (Host IP, username, and password) and then click login. After login we can see two separate windows, one is Local machine and other is virtual machine. In Local machine go to-/opt/gns3/images/
IOU/directory, drag licence-python3 file and drop it to other window (virtual machine’s window).
2. Now we have to go to virtual machine and then in virtual machine click on console-shell and type the path /opt/gns3/images/
/IOU/ and run python3 script.py.
3. The generated licence file must be copied on windows too in a file named iourc.txt.
4. Open GNS3 GUI go to Edit ->
Preferences -> IOU for Unix and paste the content of the iourc.txt file and also select the file using Browse. In GNS3 GUI go to Edit ->
Preferences -> IOU Devices, click on New and create a new template for the LOU L3 image.
Figure 1 Connecting and File Transferring to VM via WinSCP
39
Figure 2 Generate IOU Licence onGNS3 VM
Figure 3 Running Cisco IOU Image in GNS3
5 CONNECTING TO CISCO IOU IMAGES RUNNING IN GNS3 FROM WINDOWS 10
1. First step is we have to create Windows Loopback Adapter for GNS3 for that we have to go to Windows Run (by clicking window key + R) and type hdwwiz.
2. In Add Hardware Wizard select Install the hardware that we will manually select from a list.
3. Select Network Adapters, click on Next and then Microsoft and Microsoft KM-Test Loopback Adapter, click Next and Finish.
4. The new adapter appears in Control Panel -> Network and Sharing Center -> Network Connections. We will rename it GNS3 Loopback and after that we have to restart the system.
5. In this step we will set the IP address for the Loopback adapter.
6. Open GNS3 and drag & drop a device and a Cloud to the project.
Select Desktop Interface for the Cloud Server.
7. Right-click on the Cloud ->
Configure -> Ethernet Interfaces, then select Show Special Ethernet Interfaces and then Add the GNS3 Loopback Interface.
Figure 4 Creating Windows Loopback Adapter
Figure 5 Configuring IP Address to Loopback Adapter
40
Figure 6 Connecting to Cisco IOURunning in GNS3 6 PARAMIKO
6.1 What is Paramiko?
Paramiko comes from Esperanto words
“Paranoid” and “Friend”. It is entirely written in python. It is a module for Python 2.7/3.4, which is for implementation of SSH2 protocol for secure and encrypted connection to remote machine.
6.2 Process of Installing Paramiko For installing paramiko on windows 10, first we have to go in command prompt then after that write commands: -
(1) pip install paramiko
(2) python -m pip install --upgrade pip First command pip install paramiko will download and install Paramiko Automatically.
Second command python -m pip install --upgrade pipwill upgrade Paramiko to its newer version.
In pycharm IDE, we have to import paramiko library, for that go to the file option then click on settings-python interpreter-add and in the search field type Paramiko and after the search click on install package.
Process of installation of Paramiko in windows device and also in PyCharm IDE are shown in the figures below.
Figure 7 Installing paramiko via command prompt on windows 10
Device
Figure 8 Installing Paramiko Package in PyCharm IDE
6.3 Lab Environment
For our lab environment we use a simple topology which consist of one router (which is Cisco Router named as IOU1) having ip address 10.1.1.10 and subnet mask /24 (255.255.255.0) and a Cloud (named as Cloud1)in GNS3, which is infect my windows Machine.
Figure 9 Lab Environment (Paramiko) in GNS3
41
7 NETMIKONetmiko is a multi-vendor network library based on Paramiko. It runs on top of Paramiko and is used to reduce its complexity. Both Paramiko and Netmiko are alternativeto configure devices that do not support APIs. An API is a structured mode of sending and receiving structured data from network devices.
Netmiko is easier to use than Paramiko, it supports only some devices,but it supports however the most importantand used vendors. You can see a listwith all supported platforms here at this link-
https://github.com/ktbyers/netmiko/blo b/develop/PLATFORMS.md
We can see that we can use Netmiko to automate configuration tasks on Cisco, HP, Arista, Juniper or Linux.There are many other platforms supported by Netmiko, but they were limited tested. For instance- Alcadel, Dell, Huawei, or Palo Alto.
So, basically if we want to automate the network configuration using SSH and Python we can use either Paramiko or Netmiko.
If the platform supports both Netmiko and Paramiko, we can choose Netmiko because it is easier to handle, we write less code and reduce the possibility of having errors but if there is a specialdevice that is not being supported by Netmiko we could go ahead with Paramiko.
7.1 Installation Process of Netmiko in PyCharm IDE
Same as Paramiko it does not belong to the Python Standard Library, but the installation is very easy.
Figure 10 Finding Netmiko Module in PyCharm
Figure 11 Installing Netmiko Module in PyCharm
7.2 Lab Environment
For the setup of our lab,we use a simple topology which consist of one router (which is Cisco Router named as IOU1) having ip address 10.1.1.10 and subnet mask /24 (255.255.255.0) and a Cloud (named as Cloud1) in GNS3, which is infect my windows Machine.
Figure 12 Lab Environment (Netmiko) in GNS3
7.3 Connecting and Running Command on Networking Device with Netmiko Firstly, all we need is a network connection available and SSH access from the host that runs the Python scripts to the device we want to configure. Before beginning we will test the network connection between the admin host and the device that runs in GNS3. So, we are opening a terminal and pinging it.
42
Figure 13 Checking ConnectionBetween Windows Device and Virtual Machine (VM)
Figure 14 Adapter Configuration and User Login via Putty in GNS3 7.4 Automating the Backup of Multiple Cisco Devices using Netmiko
Lab Environment
In this topology, three Routers, one Switch and cloud are connected with each other. Router1(IOU1) has ip address 10.1.1.10 and subnet mask /24 (255.255.255.0), it is connected to Switch1 via ethernet1 (e0/0) portand also connected to router2 (IOU2) via e0/1 port.Router2(IOU2) has ip address 10.1.1.20 and subnet mask /24 (255.255.255.0), it is connected to Switch1 via e0/0 port, Router1 (IOU1)via e0/2 port and also connected to router3 (IOU3) via e0/1 port. Router3(IOU3) has ip address 10.1.1.30 and subnet mask /24 (255.255.255.0), it is connected to Switch1 via e0/0 port and also connected to router2 (IOU2) via e0/1 port. Switch1 is connected to Cloud1 via e1 port.
Figure 15 Lab Environment for Backup Configuration on Multiple Network
Devices using Netmiko 8 CONCLUSION
Companies can focus on repeatable changes that have a high success rate historically and apply end-to-end automation to implementation and governance processes. Companies should be moving quickly to automate critical network activities because the value proposition is strong. Costs can be reduced significantly, and people can be deployed to work on higher-value activities. Quality improves because less human intervention is required. Speed to value increases dramatically because, with automation, the management and provisioning of millions of devices can happen instantly. Enterprise solutions can be delivered seamlessly as capabilities in a platform.
Today’s highly virtualized, cloud- enabled networks also require a new security approach to address the high rate of business change and ever-evolving security threats. Automation can provide constantly updated, secure access from device to cloud.
8.1 Future Scope
All corporates and tech giants are already started moving towards automating their networks and this will increase in the future is well, because they have thousands of network devices, which are increasing day by day hence complexity of the network is also increases automatically and because of this configuring, managing network devices will become even harder.
According to ACG research, they estimate that reduction of the time to launch a new service can be reduced by
43
85%, which can be an advantage in 13%increase in revenue generation per service and 47% increase in new service revenue.
REFERENCES
1. https://www.pcwdld.com/network- automation-tools-and-software
2. https://www.cisco.com/c/dam/en/us/produ cts/collateral/cloud-systems-
management/network-services- orchestrator/acg-economic-benefits-of- network-automation.pdf
3. https://sciendo.com/downloadpdf/journals/
macro/2/1/article-p95.pdf