blob: a80ac364ace372e296aed4414a2f015fc8871411 [file] [log] [blame]
HIGUCHI Yuta49cf4d22013-06-17 12:15:17 -07001package net.onrc.onos.ofcontroller.core;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08002
3import org.kohsuke.args4j.CmdLineException;
4import org.kohsuke.args4j.CmdLineParser;
5
HIGUCHI Yuta49cf4d22013-06-17 12:15:17 -07006import net.floodlightcontroller.core.IFloodlightProviderService;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08007import net.floodlightcontroller.core.internal.CmdLineSettings;
8import net.floodlightcontroller.core.module.FloodlightModuleException;
9import net.floodlightcontroller.core.module.FloodlightModuleLoader;
10import net.floodlightcontroller.core.module.IFloodlightModuleContext;
11import net.floodlightcontroller.restserver.IRestApiService;
12
13/**
HIGUCHI Yuta49cf4d22013-06-17 12:15:17 -070014 * Host for the ONOS main method
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080015 * @author alexreimers
16 */
17public 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}