Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.0 kB
1
Indexable
Never
from mininet.net import Mininet
from mininet.topo import Topo
from mininet.node import Node
from mininet.log import setLogLevel, info

class CustomTopology(Topo):
    def build(self):
        # Add switches
        switch1 = self.addSwitch('s1')
        switch2 = self.addSwitch('s2')

        # Add hosts
        host1 = self.addHost('h1')
        host2 = self.addHost('h2')
        host3 = self.addHost('h3')

        # Add links
        self.addLink(switch1, host1)
        self.addLink(switch1, host2)
        self.addLink(switch2, host3)
        self.addLink(switch1, switch2)

def simple_network():
    # Create Mininet object
    net = Mininet(topo=CustomTopology(), controller=None)

    # Start Mininet
    net.start()

    # Print network nodes
    info('*** Network nodes: {}\n'.format(net.nodes))

    # Test connectivity
    net.pingAll()

    # Stop Mininet
    net.stop()

if __name__ == '__main__':
    # Set Mininet log level
    setLogLevel('info')

    # Run Mininet application
    simple_network()
Leave a Comment