CAN201 Introduction to Networking - Lab 7 Building Network Topology with Mininet
Lab 7 (Week 8) Building Network Topologywith Mininet
CAN201 Dr. Wenjun Fan
Outline • Introduction to Mininet • Mininet CLI commands • Build Custom Network Topology in Mininet • Lab Task (3 points) • Demo
Introduction to Mininet • Mininet: a virtual testbed used for testing network tools and protocols.
Attention: Mininet will be used in CW Part II !
• Mininet offers the following features: o Fast prototyping for new networking protocols. o Simplified testing for complex topologies without the need of buying expensive hardware. o Realistic execution as it runs real code on the Unix and Linux kernels. o Open source environment backed by a large community contributing extensive documentation.
Introduction to Mininet • Install Mininet in Ubuntu: o $ sudo apt-get install mininet
• Test if it is installed successfully o $ sudo mn
Introduction to Mininet • The default minimal network topology
Mininet CLI commands • Command line interface: mininet>
• Command “help” shows the list of Mininet CLI commands and examples on their usage: Mininet> help
Mininet CLI commands • To display the available nodes, type the following command mininet> nodes
• To display the links to understand the topology, type the command mininet> net
Mininet CLI commands • Mininet allows you to execute commands on a specific device. To issue a command for a specific node, you must specify the device first, followed by the command. mininet> h1 ifconfig
Mininet CLI commands • Other Mininet CLI commands • To turn on a terminal of a node Mininet> xterm h1
• To exit from the command line interface Mininet> exit
• Other Host shell commands • To clean up the Mininet network configuration $sudo mn -c
• To start the network with all terminals open $sudo mn -x
Build Custom Network Topology in Mininet • Mininet supports custom network topologies. • You can create a flexible topology (in Python) with just a few lines of code). Build Custom Network Topology in Mininet • Prepare the network topology python file on Linux $ vim myTopo_Lab7.py
Note: Press ‘i’ to enter INSERT mode. Add required content to the file. Press ‘esc’ to enter NORMAL mode. Use ‘ZZ’ to write your changes and exit vim.
Build Custom Network Topology in Mininet • Import Mininet Python library
#/usr/bin/python
from mininet.net import Mininet
from mininet.cli import CLI
from mininet.node import Host
from mininet.node import OVSKernelSwitch
from mininet.log import setLogLevel, info
Build Custom Network Topology in Mininet • Define a function myTopo() to constitute all the nodes and links. • The Mininet class returns an empty network object to which we add hosts, switches etc.
def myTopo():
net = Mininet( topo=None, autoSetMacs=True, build=False, ipBase='10.0.1.0/24')
Build Custom Network Topology in Mininet • Add hosts and switch
h1 = net.addHost( 'h1', cls=Host, defaultRoute=None)
h2 = net.addHost( 'h2', cls=Host, defaultRoute=None)
h3 = net.addHost( 'h3', cls=Host, defaultRoute=None)
s1 = net.addSwitch( 's1', cls=OVSKernelSwitch, failMode='standalone')
Build Custom Network Topology in Mininet • Add links
net.addLink(h1, s1)
net.addLink(h2, s1)
net.addLink(h3, s1)
Build Custom Network Topology in Mininet • Assign IP addresses to interfaces of hosts
h1.setIP(intf=“h1-eth0”,ip=‘10.0.1.2/24’)
h2.setIP(intf=“h2-eth0”,ip=‘10.0.1.3/24’)
h3.setIP(intf=“h3-eth0”,ip=‘10.0.1.4/24’)
Build Custom Network Topology in Mininet • Network build and start net.build() net.start()
• CLI mode running CLI(net) net.stop()
Build Custom Network Topology in Mininet • Add the main function to the python program if name == ‘main’: setLogLevel( ‘info’ ) myTopo()
Build Custom Network Topology in Mininet • Save the python file and quite vim • Run the network topology python file $sudo python3 myTopo_lab7.py
Lab 7 Task (3 points, DDL Nov.8th Tues. 23:59)
- Walk through this lab, in particular, learn how to customize network topology with Mininet in Python.
- Create network topology python file in terms of the following figure. Host 2 10.0.0.3/24
Host 1 Switch 1
10.0.0.2/24
Host 3
10.0.0.4/24
- Name the python file: myTopo_lab7.py, and submit it to the assignment on LMO.
Demo