Part3 - Mininet Custom Topology



1. Writing Custom Topology in Mininet


mininet exposes the python API. We can create a custom topologies using the python API with few lines of code.

A. How to write Custom Topology in Mininet


Steps are below.

  1. Import the python required libraries


from mininet.topo import Topo
from mininet.net import Mininet


  1. Write the Topology definition class


 class SingleSwitchTopo(Topo):
    def build(self):
        s1 = self.addSwitch('s1')

        h1 = self.addHost('h1')
        h2 = self.addHost('h2')
        h3 = self.addHost('h3')
        h4 = self.addHost('h4')  

        self.addLink(h1, s1)
        self.addLink(h2, s1)
        self.addLink(h3, s1)
        self.addLink(h4, s1)


Important Topology definition APIs:

addSwitch
addHost
addLink


  1. Run the Topology as below,
    • Create the Topology object
    • Create the Mininet with Topology object
    • Start the Mininet


if __name__ == '__main__':
    topo = SingleSwitchTopo()
    c1 = RemoteController('c1', ip='127.0.0.1')
    net = Mininet(topo=topo, controller=c1)
    net.start()



2. How to Run


1. start the RYU SDN Controller

ryu-manager ryu.app.simple_switch_13


2. Run the Mininet topology file

sudo python <topology file name>



Continue with next part

Part4 - Testing IPv6 in Mininet