wiki:EsperimentiTopologieMininet

Version 1 (modified by monga, 10 years ago) ( diff )

--

Esempio di topologia pura

from mininet.topo import Topo

class MyTopo(Topo):
    def __init__(self):
        Topo.__init__(self)
        s1 = self.addSwitch('s1')
        s2 = self.addSwitch('s2')

        h = []
        for i in xrange(4):
            h.append(self.addHost('h' + str(i+1)))

        self.addLink(s1, h[0])
        self.addLink(s1, h[1])
        self.addLink(s2, h[2])
        self.addLink(s2, h[3])
        self.addLink(s1, s2)


topos = { 'prova' : (lambda : MyTopo()) }

Se il file si chiama lab/mytopo.py, da eseguire con

sudo mn --custom lab/mytopo.py --topo prova

Esempio con IP e parametri del link variati

from mininet.topo import Topo
from mininet.net import Mininet
from mininet.link import TCLink
from mininet.cli import CLI

class MyTopo(Topo):
    def __init__(self):
        Topo.__init__(self)
        s1 = self.addSwitch('s1')
        s2 = self.addSwitch('s2')

        h = []
        for i in xrange(4):
            h.append(self.addHost('h' + str(i+1)))

        self.addLink(s1, h[0])
        self.addLink(s1, h[1])
        self.addLink(s2, h[2])
        self.addLink(s2, h[3])
        self.addLink(s1, s2, bw=10)


if __name__ == '__main__':
    net = Mininet(topo=MyTopo(), link=TCLink)
    h1, h2 = net.get('h1','h2')
    h1.setIP('192.168.1.10/24')
    h2.setIP('192.168.1.20/24')

    h3, h4 = net.get('h3','h4')
    h3.setIP('192.168.2.100/24')
    h4.setIP('192.168.2.200/24')

    net.start()
    CLI(net)
    net.stop()

Se il file si chiama lab/mytopo.py, da eseguire con

sudo python lab/mytopo.py
Note: See TracWiki for help on using the wiki.