how to use python scripts or (.py files) in mininet? -
i new mininet , python. want execute python script in mininet, don't know how can run python scripts in mininet , store .py files in order call mininet.
any idea please?
here how it. copy , paste bellow code or download file: simple_pkt_topo.py.
__author__ = 'ehsan' mininet.node import cpulimitedhost mininet.topo import topo mininet.net import mininet mininet.log import setloglevel, info mininet.node import remotecontroller mininet.cli import cli """ instructions run topo: 1. go directory fil is. 2. run: sudo -e python simple_pkt_topo.py.py topo has 4 switches , 4 hosts. connected in star shape. """ class simplepktswitch(topo): """simple topology example.""" def __init__(self, **opts): """create custom topo.""" # initialize topology # uses constructor topo cloass super(simplepktswitch, self).__init__(**opts) # add hosts , switches h1 = self.addhost('h1') h2 = self.addhost('h2') h3 = self.addhost('h3') h4 = self.addhost('h4') # adding switches s1 = self.addswitch('s1', dpid="0000000000000001") s2 = self.addswitch('s2', dpid="0000000000000002") s3 = self.addswitch('s3', dpid="0000000000000003") s4 = self.addswitch('s4', dpid="0000000000000004") # add links self.addlink(h1, s1) self.addlink(h2, s2) self.addlink(h3, s3) self.addlink(h4, s4) self.addlink(s1, s2) self.addlink(s1, s3) self.addlink(s1, s4) def run(): c = remotecontroller('c', '0.0.0.0', 6633) net = mininet(topo=simplepktswitch(), host=cpulimitedhost, controller=none) net.addcontroller(c) net.start() cli(net) net.stop() # if script run directly (sudo custom/optical.py): if __name__ == '__main__': setloglevel('info') run()
then can run topo using
sudo -e python <nameofthefile>
now, use sudo -e python simple_pkt_topo.py
start mininet.
here tutorial link.
note need controller. let me know if need instructions on that.
hope helps.
Comments
Post a Comment