Created
April 30, 2017 06:07
-
-
Save aweimeow/a4770fb0aa08108df89f814f17c41c97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mininet.log import setLogLevel, info | |
from mininet.net import Mininet | |
from mininet.cli import CLI | |
from mininet.opennet import Pcap | |
from mininet import ns3 | |
import ns.wifi | |
def mobile_ip_topo(): | |
" Setting wired network " | |
net = Mininet(controller = None) | |
" Switches " | |
s1 = net.addSwitch( 's1' ) | |
s2 = net.addSwitch( 's2' ) | |
s3 = net.addSwitch( 's3' ) | |
" Hosts " | |
router = net.addHost( 'router', ip='192.168.1.1/24' ) | |
ha = net.addHost( 'ha', ip='192.168.1.2/24' ) | |
mn = net.addHost( 'mn', ip='192.168.1.3/24' ) | |
cn = net.addHost( 'cn', ip='192.168.3.2/24' ) | |
" Links " | |
net.addLink( s1, router ) | |
net.addLink( s1, ha ) | |
net.addLink( s2, router ) | |
net.addLink( s3, router ) | |
net.addLink( s3, cn ) | |
" Setting mobility model " | |
mobilityHelper = ns3.createMobilityHelper( "ns3::ConstantPositionMobilityModel" ) | |
ns3.setMobilityModel( s1, mobilityHelper ) | |
ns3.setMobilityModel( s2, mobilityHelper ) | |
ns3.setMobilityModel( s3, mobilityHelper ) | |
ns3.setMobilityModel( router, mobilityHelper ) | |
ns3.setMobilityModel( ha, mobilityHelper ) | |
ns3.setMobilityModel( mn, mobilityHelper ) | |
ns3.setMobilityModel( cn, mobilityHelper ) | |
" Setting position " | |
ns3.setPosition( s1, -25.0, -25.0, 0.0 ) | |
ns3.setPosition( s2, 150.0, -25.0, 0.0 ) | |
ns3.setPosition( s3, 0.0, 25.0, 0.0 ) | |
ns3.setPosition( router, 0.0, 0.0, 0.0 ) | |
ns3.setPosition( ha, -25.0, -50.0, 0.0 ) | |
ns3.setPosition( mn, -50.0, -50.0, 0.0 ) | |
ns3.setPosition( cn, 25.0, 25.0, 0.0 ) | |
" Setting wireless network " | |
wifi = ns3.WifiSegment( standard=ns.wifi.WIFI_PHY_STANDARD_80211g ) | |
wifi.addAp( node=s1, channelNumber=1 ) | |
wifi.addAp( node=s2, channelNumber=1 ) | |
wifi.addSta( node=mn, channelNumber=1 ) | |
" Enable packet trace, pcap files can be find in /tmp/pcap " | |
pcap = Pcap() | |
pcap.enable() | |
" Start the simulation " | |
net.start() | |
ns3.start() | |
" Setting switches " | |
s1.cmdPrint( 'ovs-vsctl set-fail-mode s1 standalone' ) | |
s2.cmdPrint( 'ovs-vsctl set-fail-mode s2 standalone' ) | |
s3.cmdPrint( 'ovs-vsctl set-fail-mode s3 standalone' ) | |
" Setting router " | |
router.cmdPrint( 'ip addr add dev router-eth1 192.168.2.1/24' ) | |
router.cmdPrint( 'ip addr add dev router-eth2 192.168.3.1/24' ) | |
router.cmdPrint( 'sysctl -w net.ipv4.ip_forward=1' ) | |
" Setting route on hosts " | |
ha.cmdPrint( 'ip route add default via 192.168.1.1' ) | |
mn.cmdPrint( 'ip route add default via 192.168.1.1' ) | |
cn.cmdPrint( 'ip route add default via 192.168.3.1' ) | |
CLI( net ) | |
ns3.stop() | |
ns3.clear() | |
net.stop() | |
if __name__ == '__main__': | |
setLogLevel( 'info' ) | |
mobile_ip_topo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment