[mininet] A simple example to build your own topology in mininet

Well, first of all I want to thank my colleague to giving me an example to build myself topology. It is very simple. Everyone can modify it and do your own topology with OpenFlow Controller.
Second, due to introducing switch cluster concept in Floodlight Controller, I will provide a simple example to give switch clusters in topology.

my_topology.py


from mininet.topo import Topo class MyTopo( Topo ): "Simple topology example." def __init__( self ): "Create custom topo." # Initialize topology Topo.__init__( self ) h1 = self.addHost( 'h1' ) h2 = self.addHost( 'h2' ) h3 = self.addHost( 'h3' ) h4 = self.addHost( 'h4' ) h5 = self.addHost( 'h5' ) h6 = self.addHost( 'h6' ) s1 = self.addSwitch( 's1' ) s2 = self.addSwitch( 's2' ) s3 = self.addSwitch( 's3' ) s4 = self.addSwitch( 's4' ) s5 = self.addSwitch( 's5' ) s6 = self.addSwitch( 's6' ) s7 = self.addSwitch( 's7' ) self.addLink( s1, s2 ) self.addLink( s1, s3 ) self.addLink( s2, s3 ) self.addLink( s2, s4 ) self.addLink( s2, s5 ) self.addLink( s3, s4 ) self.addLink( s3, s5 ) self.addLink( s4, h1 ) self.addLink( s4, h2 ) self.addLink( s5, s3 ) self.addLink( s5, s4 ) self.addLink( s6, h5 ) self.addLink( s7, h6 ) topos = { 'mytopo': ( lambda: MyTopo() ) }

Testing
Use the REST API in Floodlight Controller to query the related information as follows:

> curl -s http://localhost:8080/wm/topology/switchclusters/json
{
    "00:00:00:00:00:00:00:06": [
        "00:00:00:00:00:00:00:06",
        "00:00:00:00:00:00:00:07"
    ],
    "00:00:00:00:00:00:00:01": [
        "00:00:00:00:00:00:00:05",
        "00:00:00:00:00:00:00:02",
        "00:00:00:00:00:00:00:01",
        "00:00:00:00:00:00:00:03",
        "00:00:00:00:00:00:00:04"
    ]
}

> curl -s http://localhost:8080/wm/topology/links/json
[
    {
        "src-switch": "00:00:00:00:00:00:00:05",
        "src-port": 1,
        "src-port-state": 0,
        "dst-switch": "00:00:00:00:00:00:00:02",
        "dst-port": 4,
        "dst-port-state": 0,
        "type": "internal"
    },
    {
        "src-switch": "00:00:00:00:00:00:00:02",
        "src-port": 1,
        "src-port-state": 0,
        "dst-switch": "00:00:00:00:00:00:00:01",
        "dst-port": 1,
        "dst-port-state": 0,
        "type": "internal"
    },
    {
        "src-switch": "00:00:00:00:00:00:00:04",
        "src-port": 1,
        "src-port-state": 0,
        "dst-switch": "00:00:00:00:00:00:00:02",
        "dst-port": 3,
        "dst-port-state": 0,
        "type": "internal"
    },
    {
        "src-switch": "00:00:00:00:00:00:00:05",
        "src-port": 2,
        "src-port-state": 0,
        "dst-switch": "00:00:00:00:00:00:00:03",
        "dst-port": 4,
        "dst-port-state": 0,
        "type": "internal"
    },
    {
        "src-switch": "00:00:00:00:00:00:00:02",
        "src-port": 3,
        "src-port-state": 0,
        "dst-switch": "00:00:00:00:00:00:00:04",
        "dst-port": 1,
        "dst-port-state": 0,
        "type": "internal"
    },
    {
        "src-switch": "00:00:00:00:00:00:00:06",
        "src-port": 1,
        "src-port-state": 0,
        "dst-switch": "00:00:00:00:00:00:00:07",
        "dst-port": 1,
        "dst-port-state": 0,
        "type": "internal"
    },
    {
        "src-switch": "00:00:00:00:00:00:00:07",
        "src-port": 1,
        "src-port-state": 0,
        "dst-switch": "00:00:00:00:00:00:00:06",
        "dst-port": 1,
        "dst-port-state": 0,
        "type": "internal"
    },
    {
        "src-switch": "00:00:00:00:00:00:00:03",
        "src-port": 3,
        "src-port-state": 0,
        "dst-switch": "00:00:00:00:00:00:00:04",
        "dst-port": 2,
        "dst-port-state": 0,
        "type": "internal"
    },
    {
        "src-switch": "00:00:00:00:00:00:00:03",
        "src-port": 4,
        "src-port-state": 0,
        "dst-switch": "00:00:00:00:00:00:00:05",
        "dst-port": 2,
        "dst-port-state": 0,
        "type": "internal"
    },
    {
        "src-switch": "00:00:00:00:00:00:00:03",
        "src-port": 1,
        "src-port-state": 0,
        "dst-switch": "00:00:00:00:00:00:00:01",
        "dst-port": 2,
        "dst-port-state": 0,
        "type": "internal"
    },
    {
        "src-switch": "00:00:00:00:00:00:00:03",
        "src-port": 2,
        "src-port-state": 0,
        "dst-switch": "00:00:00:00:00:00:00:02",
        "dst-port": 2,
        "dst-port-state": 0,
        "type": "internal"
    },
    {
        "src-switch": "00:00:00:00:00:00:00:02",
        "src-port": 4,
        "src-port-state": 0,
        "dst-switch": "00:00:00:00:00:00:00:05",
        "dst-port": 1,
        "dst-port-state": 0,
        "type": "internal"
    },
    {
        "src-switch": "00:00:00:00:00:00:00:04",
        "src-port": 2,
        "src-port-state": 0,
        "dst-switch": "00:00:00:00:00:00:00:03",
        "dst-port": 3,
        "dst-port-state": 0,
        "type": "internal"
    },
    {
        "src-switch": "00:00:00:00:00:00:00:02",
        "src-port": 2,
        "src-port-state": 0,
        "dst-switch": "00:00:00:00:00:00:00:03",
        "dst-port": 2,
        "dst-port-state": 0,
        "type": "internal"
    },
    {
        "src-switch": "00:00:00:00:00:00:00:01",
        "src-port": 2,
        "src-port-state": 0,
        "dst-switch": "00:00:00:00:00:00:00:03",
        "dst-port": 1,
        "dst-port-state": 0,
        "type": "internal"
    },
    {
        "src-switch": "00:00:00:00:00:00:00:01",
        "src-port": 1,
        "src-port-state": 0,
        "dst-switch": "00:00:00:00:00:00:00:02",
        "dst-port": 1,
        "dst-port-state": 0,
        "type": "internal"
    }
]

> curl -s http://localhost:8080/wm/device/
[
    {
        "entityClass": "DefaultEntityClass",
        "mac": [
            "82:da:cd:82:03:13"
        ],
        "ipv4": [
            "10.0.0.6"
        ],
        "vlan": [],
        "attachmentPoint": [
            {
                "port": 2,
                "switchDPID": "00:00:00:00:00:00:00:07",
                "errorStatus": null
            }
        ],
        "lastSeen": 1363763792481
    },
    {
        "entityClass": "DefaultEntityClass",
        "mac": [
            "62:76:b0:43:51:c7"
        ],
        "ipv4": [
            "10.0.0.1"
        ],
        "vlan": [],
        "attachmentPoint": [
            {
                "port": 3,
                "switchDPID": "00:00:00:00:00:00:00:04",
                "errorStatus": null
            }
        ],
        "lastSeen": 1363763762405
    },
    {
        "entityClass": "DefaultEntityClass",
        "mac": [
            "4a:77:dc:12:86:50"
        ],
        "ipv4": [
            "10.0.0.3"
        ],
        "vlan": [],
        "attachmentPoint": [
            {
                "port": 3,
                "switchDPID": "00:00:00:00:00:00:00:05",
                "errorStatus": null
            }
        ],
        "lastSeen": 1363763762427
    },
    {
        "entityClass": "DefaultEntityClass",
        "mac": [
            "de:42:94:b1:24:a7"
        ],
        "ipv4": [
            "10.0.0.2"
        ],
        "vlan": [],
        "attachmentPoint": [
            {
                "port": 4,
                "switchDPID": "00:00:00:00:00:00:00:04",
                "errorStatus": null
            }
        ],
        "lastSeen": 1363763762417
    },
    {
        "entityClass": "DefaultEntityClass",
        "mac": [
            "02:ee:63:f6:65:ea"
        ],
        "ipv4": [
            "10.0.0.4"
        ],
        "vlan": [],
        "attachmentPoint": [
            {
                "port": 4,
                "switchDPID": "00:00:00:00:00:00:00:05",
                "errorStatus": null
            }
        ],
        "lastSeen": 1363763767429
    },
    {
        "entityClass": "DefaultEntityClass",
        "mac": [
            "42:a4:fd:b6:62:b9"
        ],
        "ipv4": [
            "10.0.0.5"
        ],
        "vlan": [],
        "attachmentPoint": [
            {
                "port": 2,
                "switchDPID": "00:00:00:00:00:00:00:06",
                "errorStatus": null
            }
        ],
        "lastSeen": 1363763792493
    }
]


P.S: Here is a more complete example of mininet for you to refer to: http://blog.sflow.com/2013/06/flow-collisions.html
It also contains the setting of sFlow. Awesome!

Comments

Popular posts from this blog

[Open vSwitch] How to get port statistics from interface in OVS

[Quagga] How to compile and install Quagga on Ubuntu 12.04

[JSON] How to use jansson lib to generate JSON data in C