Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
simple mininet custom topology with static routing
from mininet.topo import Topo
from import Mininet
from mininet.node import Node
from mininet.log import setLogLevel, info
from mininet.cli import CLI
class LinuxRouter( Node ):
"""A Node with IP forwarding enabled.
Means that every packet that is in this node, comunicate freely with its interfaces."""
def config( self, **params ):
super( LinuxRouter, self).config( **params )
self.cmd( 'sysctl net.ipv4.ip_forward=1' )
def terminate( self ):
self.cmd( 'sysctl net.ipv4.ip_forward=0' )
super( LinuxRouter, self ).terminate()
class NetworkTopo( Topo ):
creates the following topology
+--+ +--+ +--+
def build( self, **_opts ):
self.addLink(r1,r2,params1={ 'ip' : '' },params2={ 'ip' : '' })
self.addLink(r2,r3,params1={ 'ip' : '' },params2={ 'ip' : '' })
topo = NetworkTopo()
net = Mininet( topo=topo )
#ip route add ipA via ipB dev INTERFACE
#every packet going to ipA must first go to ipB using INTERFACE
net["r1"].cmd("ip route add via dev r1-eth0")
net["r3"].cmd("ip route add via dev r3-eth0")
#this command is just to r3 ping r2 work, because it will use the correct ip
net["r3"].cmd("ip route add via dev r3-eth0")
CLI( net )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment