Home > System Tutorial > LINUX > Use mininet to build a basic routing experiment

Use mininet to build a basic routing experiment

王林
Release: 2024-01-16 16:18:20
forward
1176 people have browsed it

Use mininet to build a simple routing experiment

The network topology is as follows:

Use mininet to build a basic routing experiment

Mininet’s topology definition code:

from mininet.topo import Topo

class Router_Topo(Topo):
    def __init__(self):
        "Create P2P topology."

        # Initialize topology
        Topo.__init__(self)

        # Add hosts and switches
        H1 = self.addHost('h1')
        H2 = self.addHost('h2')
        H3 = self.addHost('h3')
        S1 = self.addSwitch('s1')
        S2 = self.addSwitch('s2')

        # Add links
        self.addLink(H1, S1)
        self.addLink(H2, S1)
        self.addLink(H2, S2)
        self.addLink(H3, S2)

topos = {
        'router': (lambda: Router_Topo())
}
Copy after login

Use the above script to generate network topology:

sudo mn --custom /home/mininet/Router.py --topo router
mininet> net
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2 h2-eth1:s2-eth1
h3 h3-eth0:s2-eth2
s1 lo: s1-eth1:h1-eth0 s1-eth2:h2-eth0
s2 lo: s2-eth1:h2-eth1 s2-eth2:h3-eth0
Copy after login

Configure the routing function for the node:

mininet> h1 ifconfig h1-eth0 192.168.12.1 netmask 255.255.255.0
mininet> h2 ifconfig h2-eth0 192.168.12.2 netmask 255.255.255.0
mininet> h2 ifconfig h2-eth1 192.168.23.2 netmask 255.255.255.0
mininet> h3 ifconfig h3-eth0 192.168.23.3 netmask 255.255.255.0
mininet> h1 route add default gw 192.168.12.2
mininet> h3 route add default gw 192.168.23.2
mininet> h2 sysctl net.ipv4.ip_forward=1
Copy after login

h1 has pinged h3:

mininet> h1 ping -c 1 192.168.23.3
Copy after login

The above is the detailed content of Use mininet to build a basic routing experiment. For more information, please follow other related articles on the PHP Chinese website!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template