mirror of
https://github.com/Wojtek242/route0.git
synced 2024-11-22 07:05:25 +01:00
Move router class to its own file
This commit is contained in:
parent
41b1af10c4
commit
a3e6b4f0c0
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
logs/
|
logs/
|
||||||
|
*.pyc
|
27
router.py
Normal file
27
router.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
from mininet.node import Switch, Node
|
||||||
|
|
||||||
|
|
||||||
|
class Router(Switch):
|
||||||
|
"""Defines a new router that is inside a network namespace so that the
|
||||||
|
individual routing entries don't collide.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
ID = 0
|
||||||
|
|
||||||
|
def __init__(self, name, **kwargs):
|
||||||
|
|
||||||
|
kwargs['inNamespace'] = True
|
||||||
|
Switch.__init__(self, name, **kwargs)
|
||||||
|
|
||||||
|
Router.ID += 1
|
||||||
|
self.switch_id = Router.ID
|
||||||
|
|
||||||
|
def start(self, controllers):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def defaultIntf(self):
|
||||||
|
if hasattr(self, "controlIntf") and self.controlIntf:
|
||||||
|
return self.controlIntf
|
||||||
|
|
||||||
|
return Node.defaultIntf(self)
|
@ -1,64 +1,41 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
from mininet.topo import Topo
|
from mininet.topo import Topo
|
||||||
from mininet.net import Mininet
|
from mininet.net import Mininet
|
||||||
from mininet.cli import CLI
|
from mininet.cli import CLI
|
||||||
from mininet.node import Switch, Node
|
|
||||||
|
|
||||||
import os
|
sys.path.append(os.path.join(
|
||||||
|
os.path.dirname(os.path.realpath(__file__)),
|
||||||
class Router(Switch):
|
'..'))
|
||||||
"""Defines a new router that is inside a network namespace so that the
|
from router import Router
|
||||||
individual routing entries don't collide.
|
|
||||||
"""
|
|
||||||
ID = 0
|
|
||||||
def __init__(self, name, **kwargs):
|
|
||||||
kwargs['inNamespace'] = True
|
|
||||||
Switch.__init__(self, name, **kwargs)
|
|
||||||
Router.ID += 1
|
|
||||||
self.switch_id = Router.ID
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def setup():
|
|
||||||
return
|
|
||||||
|
|
||||||
def defaultIntf( self ):
|
|
||||||
if hasattr(self, "controlIntf") and self.controlIntf:
|
|
||||||
return self.controlIntf
|
|
||||||
else:
|
|
||||||
return Node.defaultIntf(self)
|
|
||||||
|
|
||||||
def start(self, controllers):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def stop(self):
|
|
||||||
self.deleteIntfs()
|
|
||||||
|
|
||||||
|
|
||||||
class NetTopo(Topo):
|
class NetTopo(Topo):
|
||||||
"""The network topology.
|
"""The network topology.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Add default members to class.
|
# Add default members to class.
|
||||||
super(NetTopo, self).__init__()
|
super(NetTopo, self).__init__()
|
||||||
|
|
||||||
# The topology has one router per AS
|
# The topology has one router per AS
|
||||||
routers = [
|
r_1 = self.addSwitch('R1')
|
||||||
self.addSwitch('R1'),
|
r_2 = self.addSwitch('R2')
|
||||||
self.addSwitch('R2'),
|
|
||||||
]
|
|
||||||
hosts = []
|
|
||||||
|
|
||||||
# Setup the links as follows:
|
# Setup the links as follows:
|
||||||
#
|
#
|
||||||
# R1 --- R2
|
# R1 --- R2
|
||||||
#
|
#
|
||||||
self.addLink('R1', 'R2')
|
self.addLink(r_1, r_2)
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def scenario():
|
||||||
|
"""Start the network scenario.
|
||||||
|
"""
|
||||||
|
|
||||||
os.system("rm -f /tmp/R*.log /tmp/R*.pid logs/*")
|
os.system("rm -f /tmp/R*.log /tmp/R*.pid logs/*")
|
||||||
os.system("mn -c >/dev/null 2>&1")
|
os.system("mn -c >/dev/null 2>&1")
|
||||||
os.system("killall -9 zebra > /dev/null 2>&1")
|
os.system("killall -9 zebra > /dev/null 2>&1")
|
||||||
@ -71,7 +48,12 @@ def main():
|
|||||||
router.waitOutput()
|
router.waitOutput()
|
||||||
|
|
||||||
# Start Zebra (routing table daemon)
|
# Start Zebra (routing table daemon)
|
||||||
router.cmd("/usr/lib/frr/zebra -f conf/zebra-%s.conf -d -i /tmp/zebra-%s.pid > logs/%s-zebra-stdout 2>&1" % (router.name, router.name, router.name))
|
router.cmd("/usr/lib/frr/zebra"
|
||||||
|
" -f conf/zebra-%s.conf"
|
||||||
|
" -d"
|
||||||
|
" -i /tmp/zebra-%s.pid"
|
||||||
|
" > logs/%s-zebra-stdout 2>&1"
|
||||||
|
% (router.name, router.name, router.name))
|
||||||
router.waitOutput()
|
router.waitOutput()
|
||||||
|
|
||||||
# Delete spare loopback address for convenience
|
# Delete spare loopback address for convenience
|
||||||
@ -84,4 +66,4 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
scenario()
|
||||||
|
Loading…
Reference in New Issue
Block a user