{"id":424,"date":"2013-06-20T10:09:18","date_gmt":"2013-06-20T02:09:18","guid":{"rendered":"http:\/\/blog.marvelplanet.tk\/?p=424"},"modified":"2013-07-01T14:33:53","modified_gmt":"2013-07-01T06:33:53","slug":"floodlight%e5%8a%a0%e8%bd%bd%e5%92%8c%e8%bf%90%e8%a1%8c%e6%a8%a1%e5%9d%97%e7%9a%84%e5%8e%9f%e7%90%86","status":"publish","type":"post","link":"https:\/\/marvelliu.space\/?p=424","title":{"rendered":"Floodlight\u52a0\u8f7d\u548c\u8fd0\u884c\u6a21\u5757\u7684\u539f\u7406"},"content":{"rendered":"<div><span style=\"font-family: 'Microsoft Yahei';\"><span style=\"font-family: 'Microsoft Yahei';\">\u8fd9\u4e24\u5929\u7b80\u5355\u770b\u4e86\u4e00\u4e0bFloodlight\u7684\u6a21\u5757\u673a\u5236\uff0c\u5927\u6982\u4e86\u89e3\u4e86\u5176\u63d2\u4ef6\u7684\u673a\u5236\u548c\u6d41 \u7a0b\uff0c\u7f16\u5199\u4e86\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u7684\u6a21\u5757\uff0c\u4e3a\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b<\/span><\/span><\/div>\n<div><span style=\"font-family: 'Microsoft Yahei'; font-size: large;\"><b>Floodlight\u52a0\u8f7d\u548c\u8fd0\u884c\u6a21\u5757\u7684\u539f\u7406<\/b><\/span><\/div>\n<div><span style=\"font-family: 'Microsoft Yahei';\">Floodlight\u7684\u5165\u53e3\u662fnet.floodlightcontroller.core.Main\uff0c \u5728\u8fd9\u4e2a\u7c7b\u7684main\u51fd\u6570\u4e2d\uff0c\u4f7f\u7528<span style=\"color: #0c2028;\">FloodlightModuleLoader\u52a0\u8f7d\u6240\u6709\u7684\u6a21\u5757\uff0c\u7136\u540e<\/span>\u518d \u8c03\u7528net.floodlightcontroller.restserver.RestApiServer\u6a21\u5757\u7684run\u65b9\u6cd5\uff0c\u542f\u52a8 rest\u670d\u52a1\u5668\uff0c\u6700\u540e\u8c03\u7528net.floodlightcontroller.core.internal.Controller\u6a21\u5757\u7684 run\u65b9\u6cd5\uff0c\u542f\u52a8\u7f51\u7edc\u63a7\u5236\u5668\u3002<\/span><\/div>\n<pre class=\"java\" name=\"code\">\u00a0\r\n \u00a0 public static void main(String[] args) throws FloodlightModuleException {\r\n\u00a0 \u00a0 \u00a0 \u00a0 ...\r\n\u00a0 \u00a0 \u00a0 \u00a0 FloodlightModuleLoader fml = new FloodlightModuleLoader();\r\n\u00a0 \u00a0 \u00a0 \u00a0 IFloodlightModuleContext moduleContext = fml.loadModulesFromConfig(settings.getModuleFile());\r\n\u00a0 \u00a0 \u00a0 \u00a0 IRestApiService restApi = moduleContext.getServiceImpl(IRestApiService.class);\r\n\u00a0 \u00a0 \u00a0 \u00a0 restApi.run();\r\n\u00a0 \u00a0 \u00a0 \u00a0 IFloodlightProviderService controller =\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 moduleContext.getServiceImpl(IFloodlightProviderService.class);\r\n\u00a0 \u00a0 \u00a0 \u00a0 controller.run();\r\n\u00a0 \u00a0 }<\/pre>\n<div><span style=\"color: #0c2028;\">\u5728\u52a0\u8f7d\u6a21\u5757\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f7f\u7528 FloodlightModuleLoader\u7c7b\u7684findAllModules\u65b9\u6cd5\u5bfb\u627e\u6240\u6709\u5728$CLASSPATH\u8def\u5f84\u4e2d\u7684<\/span><span style=\"font-family: 'Microsoft Yahei';\">\u5b9e\u73b0\u4e86\u00a0net.floodlightcontroller.core.module.IFloodlightModule\u63a5\u53e3\u7684\u6a21\u5757\uff0c\u7136\u540e\u7528initModules \u521d\u59cb\u5316\u8fd9\u4e9b\u6a21\u5757\uff0c\u6700\u540e\u7528<\/span><span style=\"color: #0c2028;\">startupModules\u542f\u52a8\u8fd9\u4e9b\u6a21\u5757\u3002<\/span><\/div>\n<div>FloodlightModuleLoad.java:303<\/div>\n<pre class=\"java\" name=\"code\">    initModules(moduleSet);\r\n    startupModules(moduleSet);<\/pre>\n<div><span style=\"color: #0c2028; font-family: 'Microsoft Yahei';\">\u4ee5MemoryStorageSource\u7c7b\u4e3a\u4f8b\uff0c\u5b83\u7ee7\u627f\u4e86 NoSqlStorageSource\u7c7b\uff0c\u540e\u8005\u53c8\u7ee7\u627f\u4e86AbstractStorageSource\u7c7b\uff0c\u800c AbstractStorageSource\u662f\u5b9e\u73b0\u4e86IFloodlightModule\u548c IStorageSourceService\u4e24\u4e2a\u63a5\u53e3\u3002<\/span><\/div>\n<div><span style=\"font-family: 'Microsoft Yahei';\">IFloodlightModule\u6709\u4e00\u4e2ainit\u65b9\u6cd5\u548c\u4e00\u4e2astartUp\u65b9\u6cd5\uff0c\u6240\u4ee5<\/span>MemoryStorageSource\u4f1a\u5206\u522b\u5b9e\u73b0\u8fd9\u4e24\u4e2a\u65b9\u6cd5\uff0c\u5e76<span style=\"color: #0c2028;\">\u5728\u521d\u59cb\u5316\u548c\u542f\u52a8\u7684\u65f6\u5019\u88ab\u8c03\u7528\u3002<\/span><\/div>\n<div><span style=\"color: #0c2028; font-family: 'Microsoft Yahei';\"><br \/>\n<\/span><\/div>\n<div><span style=\"font-family: 'Microsoft Yahei';\"><br \/>\n<\/span><\/div>\n<div><span style=\"font-family: 'Microsoft Yahei';\"><br \/>\n<\/span><\/div>\n<div><span style=\"font-family: 'Microsoft Yahei'; font-size: large;\"><b>\u4e00\u4e2a\u6a21\u5757\u7684\u7b80\u5355\u5b9e\u4f8b<\/b><\/span><\/div>\n<div><span style=\"font-family: 'Microsoft Yahei';\">\u4e0b\u9762\u7b80\u5355\u4ecb\u7ecd\u5982\u4f55\u65b0\u5efa\u4e00\u4e2a\u6a21\u5757\u7684\u8fc7\u7a0b\uff0c\u4ee5\u4e00\u4e2aIDSController\u4e3a\u4f8b\uff0c\u73b0\u5728 \u53ea\u5b9e\u73b0\u5b9a\u65f6\u6253\u5370\u65e5\u5fd7\u7684\u529f\u80fd\uff1a<\/span><\/div>\n<div><b><span style=\"font-family: 'Microsoft Yahei';\">1 \u5b9a\u4e49\u670d\u52a1com.nsfocus.ids.IIntrusionDetectionService:<\/span><\/b><\/div>\n<div>\n<pre class=\"java\" name=\"code\">\u00a0\r\npublic interface IIntrusionDetectionService \u00a0extends IFloodlightService {\r\n}<\/pre>\n<div><b><span style=\"font-family: 'Microsoft Yahei';\">2 \u65b0\u5efa\u4e00\u4e2a\u5b9e\u73b0IFloodlightModule\u63a5\u53e3\u7684\u7c7bcom.nsfocus.ids.IDSController\uff1a<\/span><\/b><\/div>\n<div><span style=\"font-family: 'Microsoft Yahei';\">\u5206\u522b\u5b9e\u73b0\u63a5\u53e3IFloodlightModule\u7684 getModuleServices\u3001getServiceImpls\u3001getModuleDependencies\u7b49\u65b9\u6cd5\uff0c\u8fd9\u4e09\u4e2a\u65b9\u6cd5 \u4e3b\u8981\u7528\u4e8e\u521d\u59cb\u5316\u6a21\u5757<\/span><\/div>\n<div><span style=\"font-family: 'Microsoft Yahei';\">\u7cfb\u7edf\u8fd0\u884c ServiceLoader.load(IFloodlightModule.class, cl)\u540e\u4f1a\u5c06IDSController\u52a0\u8f7d\u5230\u652f\u6301IFloodlightModule\u6a21\u5757\u7684\u5217\u8868\u4e2d\u3002<\/span><\/div>\n<div><span style=\"font-family: 'Microsoft Yahei';\"><br \/>\n<\/span><\/div>\n<div><b><span style=\"font-family: 'Microsoft Yahei';\">3 \u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0\u65b0\u6a21\u5757\uff1a<\/span><\/b><\/div>\n<div><span style=\"font-family: 'Microsoft Yahei';\">\u5728target\\bin\\floodlightdefault.properties\u6dfb\u52a0\uff1a<\/span><\/div>\n<blockquote><p>net.floodlightcontroller.perfmon.PktInProcessingTime,\\<br \/>\nnet.floodlightcontroller.ui.web.StaticWebRoutable<b>,\\<br \/>\ncom.nsfocus.ids.IDSController<br \/>\nnet.floodlightcontroller.restserver.RestApiServer.port = 8080 <\/b><\/p><\/blockquote>\n<div><span style=\"font-family: 'Microsoft Yahei';\"><br \/>\n<\/span><\/div>\n<div><span style=\"font-family: 'Microsoft Yahei';\">\u8fd9\u6837\u65b0\u6a21\u5757\u5728\u52a0\u8f7d\u65f6\u5c31\u88ab\u6dfb\u52a0\u5230\u96c6\u5408configMods\u4e2d<\/span><\/div>\n<div><\/div>\n<div>\u6b64\u5916\uff0c\u8981\u5728bin\\META-INF\\services\\net.floodlightcontroller.core.module.ISecurityControllerModule\u4e2d\u6dfb\u52a0\u4e00\u884c<\/div>\n<div>\u00a0\u00a0\u00a0 <b>com.nsfocus.ids.IDSController<\/b><\/div>\n<div>\u4ee3\u7801\u5728\u8fd0\u884c\u5230FloodlightModuleLoader.findAllModules\u7684ServiceLoader.load\u65b9\u6cd5\u65f6\uff0c\u4f1a\u52a0\u8f7d\u7b2c\u4e8c\u4e2a\u6587\u4ef6\u4e2d\u6240\u5217\u7684\u6240\u6709\u6a21\u5757\uff0c\u5982\u679c\u53ea\u5728\u7b2c\u4e00\u4e2a\u6587\u4ef6\u4e2d\u5217\u51fa\u6765\uff0c\u800c\u6ca1\u6709\u5728\u7b2c\u4e8c\u4e2a\u6587\u4ef6\u4e2d\u6a21\u5757\u5217\u51fa\u6765\u7684\u8bdd\uff0c\u4f1a\u629b\u51faSecurityControllerModuleException\u7684\u5f02\u5e38\u3002\u6240\u4ee5\u4e00\u5b9a\u8981\u5728\u4e24\u4e2a\u6587\u4ef6\u4e2d\u90fd\u6dfb\u52a0\u8be5\u6a21\u5757\u3002<\/div>\n<div><\/div>\n<div><span style=\"font-family: 'Microsoft Yahei';\"><br \/>\n<\/span><\/div>\n<div><b><span style=\"font-family: 'Microsoft Yahei';\">4 \u5728IDSController\u4e2d\u6dfb\u52a0\u76f8\u5e94\u7684\u529f\u80fd<\/span><\/b><\/div>\n<div><span style=\"font-family: 'Microsoft Yahei';\">4.1 \u6dfb\u52a0\u521d\u59cb\u5316\u4ee3\u7801<\/span><\/div>\n<div><span style=\"font-family: 'Microsoft Yahei';\"><br \/>\n<\/span><\/div>\n<pre class=\"java\" name=\"code\">@Override\r\npublic void init(FloodlightModuleContext context) throws FloodlightModuleException {\r\n    threadPool = context.getServiceImpl(IThreadPoolService.class);\r\n    Map&lt;String, String&gt; configOptions = context.getConfigParams(this); \r\n\u00a0 \u00a0 try {\r\n\u00a0 \u00a0 \u00a0 \u00a0 String detectTimeout = configOptions.get(\"detecttimeout\");\r\n  \u00a0 \u00a0 \u00a0 if (detectTimeout != null) {\r\n   \u00a0 \u00a0 \u00a0 \u00a0\u00a0 DETECT_TASK_INTERVAL = Short.parseShort(detectTimeout);\r\n\u00a0 \u00a0 \u00a0 \u00a0 }\r\n \u00a0 \u00a0 } catch (NumberFormatException e) {\r\n\u00a0 \u00a0 \u00a0 \u00a0 log.warn(\"Error parsing detecting timeout, \" +\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0\"using default of {} seconds\",\r\n  \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0DETECT_TASK_INTERVAL);\r\n \u00a0 \u00a0 }\r\n     log.debug(\"NSFOCUS IDS controller initialized\");\r\n}<\/pre>\n<div><span style=\"font-family: 'Microsoft Yahei';\"><br \/>\n<\/span><\/div>\n<div><span style=\"font-family: 'Microsoft Yahei';\">4.2 \u6dfb\u52a0\u542f\u52a8\u4ee3\u7801<\/span><\/div>\n<pre class=\"java\" name=\"code\">@Override\r\npublic void startUp(FloodlightModuleContext context) {\r\n    log.debug(\"NSFOCUS IDS controller started\");\r\n    ScheduledExecutorService ses = threadPool.getScheduledExecutor();\r\n    detectTask = new SingletonTask(ses, new Runnable() {\r\n\u00a0 \u00a0 \u00a0 \u00a0 @Override\r\n        public void run() {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 try {\r\n         \u00a0 \u00a0 \u00a0\u00a0 detect();\r\n                detectTask.reschedule(DETECT_TASK_INTERVAL, TimeUnit.SECONDS);\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } catch (Exception e) {\r\n  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 log.error(\"Exception in IDS detector\", e);\r\n  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } finally {\r\n            }\r\n \u00a0 \u00a0    }\r\n     });\r\n    detectTask.reschedule(DETECT_TASK_INTERVAL, TimeUnit.SECONDS);\r\n}\r\npublic void detect(){\r\n \u00a0 log.debug(\"Detecting...\");\r\n}<\/pre>\n<div><span style=\"font-family: 'Microsoft Yahei';\"><br \/>\n<\/span><\/div>\n<div><span style=\"font-family: 'Microsoft Yahei';\">\u8fd9\u6837\uff0cfloodlight\u5728\u521d\u59cb\u5316\u65f6\u81ea\u52a8\u8c03\u7528IDSController\u7684 init\u65b9\u6cd5\uff0c\u968f\u540e\u5728\u542f\u52a8\u65f6\u4f1a\u81ea\u52a8\u8c03\u7528IDSController\u7684startUp\u65b9\u6cd5\uff0c\u4e0a\u9762\u4ee3\u7801\u4f7f\u7528\u4e86\u5b9a\u65f6\u5668\uff0c\u5b9e\u73b0\u5b9a\u65f6\u89e6\u53d1\u7684\u529f\u80fd\u3002<\/span><\/div>\n<div><span style=\"font-family: 'Microsoft Yahei';\"><br \/>\n<\/span><\/div>\n<div>\u4e0b\u9762\u662f\u90e8\u5206<span style=\"font-family: 'Microsoft Yahei';\">\u542f\u52a8\u65e5\u5fd7\uff1a<\/span><\/div>\n<p>&nbsp;<\/p>\n<div><span style=\"font-family: 'Microsoft Yahei';\"><br \/>\n<\/span><\/div>\n<div>\n<div>16:02:51.242 [main] DEBUG n.f.core.internal.Controller &#8211; OFListeners for PACKET_IN: linkdiscovery,topology,devicemanager,firewall,forwarding,<\/div>\n<div>16:02:51.302 [main] INFO \u00a0n.f.core.internal.Controller &#8211; Listening for switch connections on 0.0.0.0\/0.0.0.0:6633<\/div>\n<div>16:02:53.611 [debugserver-main] INFO \u00a0n.f.jython.JythonServer &#8211; Starting DebugServer on port 6655<\/div>\n<div>16:02:55.095 [pool-3-thread-15] DEBUG com.nsfocus.ids.IDSController &#8211; Detecting&#8230;<\/div>\n<div>16:02:59.096 [pool-3-thread-11] DEBUG com.nsfocus.ids.IDSController &#8211; Detecting&#8230;<\/div>\n<\/div>\n<p>P.S. \u5176\u4ed6\u6210\u5458\u53d8\u91cf\u58f0\u660e\u4e3a\uff1a<\/p>\n<pre class=\"java\" name=\"code\">    protected static Logger log = LoggerFactory.getLogger(IDSController.class);\r\n    protected SingletonTask detectTask;\r\n    protected int DETECT_TASK_INTERVAL = 2;\r\n    protected IThreadPoolService threadPool;<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u4e24\u5929\u7b80\u5355\u770b\u4e86\u4e00\u4e0bFloodlight\u7684\u6a21\u5757\u673a\u5236\uff0c\u5927\u6982\u4e86\u89e3\u4e86\u5176\u63d2\u4ef6\u7684\u673a\u5236\u548c\u6d41 \u7a0b\uff0c\u7f16\u5199\u4e86\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u7684\u6a21\u5757\uff0c\u4e3a\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b Floodlight\u52a0\u8f7d\u548c\u8fd0\u884c\u6a21\u5757\u7684\u539f\u7406 Floodlight\u7684\u5165\u53e3\u662fnet.floodlightcontroller.core.Main\uff0c \u5728\u8fd9\u4e2a\u7c7b\u7684main\u51fd\u6570\u4e2d\uff0c\u4f7f\u7528FloodlightModuleLoader\u52a0\u8f7d\u6240\u6709\u7684\u6a21\u5757\uff0c\u7136\u540e\u518d \u8c03\u7528net.floodlightcontroller.restserver.RestApiServer\u6a21\u5757\u7684run\u65b9\u6cd5\uff0c\u542f\u52a8 rest\u670d\u52a1\u5668\uff0c\u6700\u540e\u8c03\u7528net.floodlightcontroller.core.internal.Controller\u6a21\u5757\u7684 run\u65b9\u6cd5\uff0c\u542f\u52a8\u7f51\u7edc\u63a7\u5236\u5668\u3002 \u00a0 \u00a0 public static void main(String[] args) throws FloodlightModuleException { \u00a0 \u00a0 \u00a0 \u00a0 &#8230; \u00a0 \u00a0 \u00a0 \u00a0 FloodlightModuleLoader fml = new FloodlightModuleLoader(); \u00a0 \u00a0 \u00a0 \u00a0 IFloodlightModuleContext moduleContext = fml.loadModulesFromConfig(settings.getModuleFile()); \u00a0 \u00a0 \u00a0 \u00a0 IRestApiService restApi = moduleContext.getServiceImpl(IRestApiService.class); \u00a0 \u00a0 \u00a0 \u00a0 restApi.run(); \u00a0 \u00a0 &hellip; <a href=\"https:\/\/marvelliu.space\/?p=424\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Floodlight\u52a0\u8f7d\u548c\u8fd0\u884c\u6a21\u5757\u7684\u539f\u7406&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[27,34],"class_list":["post-424","post","type-post","status-publish","format-standard","hentry","category-sdn","tag-floodlight","tag-sdn"],"_links":{"self":[{"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/posts\/424","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/marvelliu.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=424"}],"version-history":[{"count":19,"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/posts\/424\/revisions"}],"predecessor-version":[{"id":479,"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/posts\/424\/revisions\/479"}],"wp:attachment":[{"href":"https:\/\/marvelliu.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/marvelliu.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/marvelliu.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}