Python Pox Library Introduction Tutorial (Python Pox Class Library Beginner's Tutorial)
Python Pox is a class library for writing software definition network controller.This tutorial will introduce how to use Python Pox to develop its own SDN (software definition network) controller.
What is Python Pox?
Python Pox is a software -defined network controller based on Python language.It allows developers to write custom controllers to manage and control network traffic.
Install Python Pox
First, we need to install Python Pox.You can get the latest version of the installation file on Pox's official website.
Step 1: Download and install Python Pox
Go to the POX website and download the latest version of Python Pox.After downloading, install it in accordance with the instructions in the official document.
Step 2: Installation dependencies
Python Pox has some dependencies, and we need to install them in advance.These dependencies include Python, Twisted and OpenFlow.
Step 3: Configure environment variables
After the installation is completed, add the installation path of the Python Pox to the system environment variable so that the POX can be directly called in the command line.
Write the first Python Pox program
Below is a simple Python Pox program example for monitoring OpenFlow messages and printing it to the console.
python
from pox.core import core
import pox.openflow.libopenflow_01 as of
def _handle_ConnectionUp(event):
connection = event.connection
core.getLogger().info("Connection %s is up.", connection)
def _handle_PacketIn(event):
packet = event.parsed
core.getLogger().info("Packet in: %s", packet)
def launch():
core.openflow.addListenerByName("ConnectionUp", _handle_ConnectionUp)
core.openflow.addListenerByName("PacketIn", _handle_PacketIn)
This program uses the `Launch ()` function as the entrance point, and register two event monitors: `Connectionup` and` Packetin`.The `Connectionup` event was triggered when the OpenFlow was connected, and the` Packetin` event was triggered when the switch received the data packet of the unknown destination.
Run the Python Pox program
In the command line, use the following command to run the Python Pox program:
pox.py your program name
In the above command, replace the "Your Program Name" as the name of your Python Pox program file.After the above command is executed, the console will display the output of the Python Pox.
Summarize
Through this tutorial, you can learn how to use the Python Pox class library to write a custom SDN controller.The actual network programming may require more complicated code and configuration, but this simple example will help you get started and provide you with a foundation of in -depth learning Python Pox.