Jonathan Hart | edd6a44 | 2013-02-20 15:22:06 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.mastership; |
| 2 | |
| 3 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 4 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 5 | import net.floodlightcontroller.mastership.IMastershipService.MastershipCallback; |
| 6 | |
| 7 | import org.openflow.util.HexString; |
| 8 | import org.slf4j.Logger; |
| 9 | import org.slf4j.LoggerFactory; |
| 10 | |
| 11 | /** |
| 12 | * Used for lightweight testing of the mastership module without having |
| 13 | * to load up the entire ONOS. |
| 14 | * @author jono |
| 15 | * |
| 16 | */ |
| 17 | public class MastershipRunner { |
| 18 | protected static Logger log = LoggerFactory.getLogger(MastershipRunner.class); |
| 19 | |
| 20 | public static void main(String args[]){ |
| 21 | FloodlightModuleContext fmc = new FloodlightModuleContext(); |
| 22 | MastershipManager mm = new MastershipManager(); |
| 23 | |
| 24 | String id = null; |
| 25 | if (args.length > 0){ |
| 26 | id = args[0]; |
| 27 | log.info("Using unique id: {}", id); |
| 28 | } |
| 29 | |
| 30 | try { |
| 31 | mm.init(fmc); |
| 32 | mm.startUp(fmc); |
| 33 | |
| 34 | if (id != null){ |
| 35 | mm.setMastershipId(id); |
| 36 | } |
| 37 | |
| 38 | mm.acquireMastership(1L, |
| 39 | new MastershipCallback(){ |
| 40 | @Override |
| 41 | public void changeCallback(long dpid, boolean isMaster) { |
| 42 | if (isMaster){ |
| 43 | log.debug("Callback for becoming master for {}", HexString.toHexString(dpid)); |
| 44 | } |
| 45 | else { |
| 46 | log.debug("Callback for losing mastership for {}", HexString.toHexString(dpid)); |
| 47 | } |
| 48 | } |
| 49 | }); |
| 50 | |
| 51 | mm.registerController(id); |
| 52 | |
| 53 | Thread.sleep(5000); |
| 54 | |
| 55 | //"Server" loop |
| 56 | while (true) { |
| 57 | Thread.sleep(60000); |
| 58 | } |
| 59 | |
| 60 | } catch (FloodlightModuleException e) { |
| 61 | e.printStackTrace(); |
| 62 | } catch (InterruptedException e) { |
| 63 | e.printStackTrace(); |
| 64 | } catch (Exception e) { |
| 65 | e.printStackTrace(); |
| 66 | } |
| 67 | |
| 68 | log.debug("is master: {}", mm.amMaster(1L)); |
| 69 | } |
| 70 | } |