HIGUCHI Yuta | 49cf4d2 | 2013-06-17 12:15:17 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.core; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 2 | |
| 3 | import org.kohsuke.args4j.CmdLineException; |
| 4 | import org.kohsuke.args4j.CmdLineParser; |
| 5 | |
HIGUCHI Yuta | 49cf4d2 | 2013-06-17 12:15:17 -0700 | [diff] [blame] | 6 | import net.floodlightcontroller.core.IFloodlightProviderService; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 7 | import net.floodlightcontroller.core.internal.CmdLineSettings; |
| 8 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 9 | import net.floodlightcontroller.core.module.FloodlightModuleLoader; |
| 10 | import net.floodlightcontroller.core.module.IFloodlightModuleContext; |
| 11 | import net.floodlightcontroller.restserver.IRestApiService; |
| 12 | |
| 13 | /** |
HIGUCHI Yuta | 49cf4d2 | 2013-06-17 12:15:17 -0700 | [diff] [blame] | 14 | * Host for the ONOS main method |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 15 | * @author alexreimers |
| 16 | */ |
| 17 | public class Main { |
| 18 | |
| 19 | /** |
| 20 | * Main method to load configuration and modules |
| 21 | * @param args |
| 22 | * @throws FloodlightModuleException |
| 23 | */ |
| 24 | public static void main(String[] args) throws FloodlightModuleException { |
| 25 | // Setup logger |
| 26 | System.setProperty("org.restlet.engine.loggerFacadeClass", |
| 27 | "org.restlet.ext.slf4j.Slf4jLoggerFacade"); |
| 28 | |
| 29 | CmdLineSettings settings = new CmdLineSettings(); |
| 30 | CmdLineParser parser = new CmdLineParser(settings); |
| 31 | try { |
| 32 | parser.parseArgument(args); |
| 33 | } catch (CmdLineException e) { |
| 34 | parser.printUsage(System.out); |
| 35 | System.exit(1); |
| 36 | } |
| 37 | |
| 38 | // Load modules |
| 39 | FloodlightModuleLoader fml = new FloodlightModuleLoader(); |
| 40 | IFloodlightModuleContext moduleContext = fml.loadModulesFromConfig(settings.getModuleFile()); |
| 41 | // Run REST server |
| 42 | IRestApiService restApi = moduleContext.getServiceImpl(IRestApiService.class); |
| 43 | restApi.run(); |
| 44 | // Run the main floodlight module |
| 45 | IFloodlightProviderService controller = |
| 46 | moduleContext.getServiceImpl(IFloodlightProviderService.class); |
| 47 | // This call blocks, it has to be the last line in the main |
| 48 | controller.run(); |
| 49 | } |
| 50 | } |