python - How to identify a specific switch in Mininet when connected to a pox controller -
i have custom topology running on mininet , has 2 switches s1, , s2. using pox controller. have written python code identify switches, correct way it? there other better methods can use? body suggest other alternatives?
code:
from pox.core import core import pox.openflow.libopenflow_01 of pox.lib.util import dpidtostr log = core.getlogger() s1_dpid=0 s2_dpid=0 def _handle_connectionup (event): global s1_dpid, s2_dpid print "connectionup: ", dpidtostr(event.connection.dpid) #remember connection dpid switch m in event.connection.features.ports: if m.name == "s1-eth1": s1_dpid = event.connection.dpid print "s1_dpid=", s1_dpid elif m.name == "s2-eth1": s2_dpid = event.connection.dpid print "s2_dpid=", s2_dpid
this link http://squarey.me/cloud-virtualization/pox-controller-learning-four.html provides examples of pox component listens connectionup events switches , dpid
1. use component script "connectiondown.py" inside pox directory:
#!/usr/bin/python pox.core import core pox.lib.util import dpid_to_str pox.lib.revent import * log = core.getlogger() class connectionup(event): def __init__(self,connection,ofp): event.__init__(self) self.connection = connection self.dpid = connection.dpid self.ofp = ofp class connectiondown(event): def __init__(self,connection,ofp): event.__init__(self) self.connection = connection self.dpid = connection.dpid class mycomponent(object): def __init__(self): core.openflow.addlisteners(self) def _handle_connectionup(self,event): connectionup(event.connection,event.ofp) log.info("switch %s has come up.",dpid_to_str(event.dpid)) def _handle_connectiondown(self,event): connectiondown(event.connection,event.dpid) log.info("switch %s has shutdown.",dpid_to_str(event.dpid)) def launch(): core.registernew(mycomponent) 2- (pox controller xterm) start pox controller custom component
mininet@mininet-vm:~/pox$ ./pox.py connectiondown pox 0.1.0 (betta) / copyright 2011-2013 james mccauley, et al. info:core:pox 0.1.0 (betta) up. 3- (mininet xterm) start mininet topology multiple switches
mininet@mininet-vm:~$ sudo mn --topo linear --mac --controller remote --switch ovsk *** creating network *** adding controller *** adding hosts: h1 h2 *** adding switches: s1 s2 *** adding links: (h1, s1) (h2, s2) (s1, s2) *** configuring hosts h1 h2 *** starting controller *** starting 2 switches s1 s2 *** starting cli: mininet> 4- pox controller xterm, here observe in pox xterm:
./pox.py connectiondown pox 0.1.0 (betta) / copyright 2011-2013 james mccauley, et al. info:core:pox 0.1.0 (betta) up. info:openflow.of_01:[00-00-00-00-00-02 2] connected info:connectiondown:switch 00-00-00-00-00-02 has come up. info:openflow.of_01:[00-00-00-00-00-01 1] connected info:connectiondown:switch 00-00-00-00-00-01 has come up. 5- s#pox should react changes rhe switches:
mininet> py s1.stop() mininet> py s1.start([c0]) mininet> 4- pox controller xterm:
mininet@mininet-vm:~/pox$ ./pox.py connectiondown pox 0.1.0 (betta) / copyright 2011-2013 james mccauley, et al. info:core:pox 0.1.0 (betta) up. info:openflow.of_01:[00-00-00-00-00-02 2] connected info:connectiondown:switch 00-00-00-00-00-02 has come up. info:openflow.of_01:[00-00-00-00-00-01 1] connected info:connectiondown:switch 00-00-00-00-00-01 has come up. info:openflow.of_01:[00-00-00-00-00-01 1] closed info:connectiondown:switch 00-00-00-00-00-01 has shutdown. info:openflow.of_01:[00-00-00-00-00-01 3] connected info:connectiondown:switch 00-00-00-00-00-01 has come up.
Comments
Post a Comment