{"id":491,"date":"2013-08-20T14:31:18","date_gmt":"2013-08-20T06:31:18","guid":{"rendered":"http:\/\/blog.marvelplanet.tk\/?p=491"},"modified":"2013-08-20T15:04:18","modified_gmt":"2013-08-20T07:04:18","slug":"floodlight%e7%9a%84%e6%b5%81%e9%87%8f%e6%8e%a7%e5%88%b6","status":"publish","type":"post","link":"https:\/\/marvelliu.space\/?p=491","title":{"rendered":"Floodlight\u7684\u6d41\u91cf\u63a7\u5236"},"content":{"rendered":"<p>floodlight\u5728bigswitch\u9000\u51faopendaylight\u540e\u7b97\u662f\u6d3b\u8fc7\u6765\u4e86\uff0c\u65b0\u7684\u7248\u672c\u5728\u8d1f\u8f7d\u5747\u8861\u4e2d\u52a0\u5165\u4e86\u4e00\u4e9b\u673a\u5236\uff0c\u53ef\u4ee5\u53c2\u89c1net.floodlight.loadbalancer<\/p>\n<p>\u4e0d\u8fc7\u6211\u5173\u5fc3\u7684\u662fFL\u5bf9\u6d41\u91cf\u7684\u63a7\u5236\uff0c\u7279\u522b\u662f\u5224\u65adpacket_in\u901f\u7387\u7684\u673a\u5236\uff0c\u8fd9\u4e2a\u5728\u524d\u51e0\u4e2a\u6708\u7684Floodlight\u662f\u6ca1\u6709\u7684\u3002<\/p>\n<p>\u73b0\u5728FL\u7684\u5904\u7406\u673a\u5236\u662f\u5728\u6536\u5230packet_in\u6570\u636e\u5305\u540e\uff0c\u9996\u5148\u5224\u65ad\u662f\u5426\u8d85\u8fc7\u9608\u503c\uff0c\u5728inputThrottled\u65b9\u6cd5\u4e2d\uff0c\u8ba1\u7b97\u6bcf1000\u4e2a\u6570\u636e\u5305\u6240\u82b1\u7684\u65f6\u95f4\uff0c\u5f97\u51fa\u901f\u7387\u3002\u5982\u679c\u901f\u7387\u8d85\u8fc7packetInRateThresholdHigh\u9608\u503c\uff0c\u5219\u8fdb\u5165\u76d1\u63a7\u9650\u5236\u6d41\u91cf\u6a21\u5f0f\uff08enablePacketInThrottle\uff09<\/p>\n<p>\u5728\u8be5\u6a21\u5f0f\u4e0b\uff0c\u4f9d\u6b21\u68c0\u67e5packet_in\u6570\u636e\u5305\u7684src mac\uff08\u9891\u7387\u4e3a\u6bcf50\u4e2apacket_in\u4e00\u6b21\uff09\u548cin port\uff08\u9891\u7387\u4e3a\u6bcf100\u4e2apacket_in\u4e00\u6b21\uff09\uff0c\u5982\u679c\u8fd1\u671f\uff081s\u5185\uff09\u6709\u8be5\u7c7b\u6570\u636e\u5305\u5219\u5c06\u5176\u7981\u6b62\u3002<\/p>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u7684\u521d\u8877\u5e94\u8be5\u662f\u9632\u6b62controller\u7684\u8d1f\u8f7d\u8fc7\u9ad8\uff0c\u4f8b\u5982\u7981\u6b62mac\u662f\u4e3a\u4e86\u9632\u6b62host\u53d1\u9001\u8fc7\u591a\u5305\uff0c\u7981\u6b62in port\u662f\u4e3a\u4e86\u7981\u6b62sw\u8f6c\u53d1\u8fc7\u591a\u5305\u3002\u4f46\u540e\u8005\u6709\u53ef\u80fd\u51fa\u73b0\u5728\u6076\u610fvm\u53d1\u52a8DDoS\u653b\u51fb\uff08\u4e00\u4e2ain port\uff0c\u4f46\u65e0\u6570src mac\uff09\uff0c\u5ba2\u89c2\u4e0a\u5374\u4f7f\u63a7\u5236\u5668\u514d\u53d7DDoS\u653b\u51fb\uff0c\u81ea\u7136\u4e5f\u8ba9\u57df\u5185\u7684VM\u88abDDoS\u3002<\/p>\n<p>\u8d34\u4e00\u4e0b\u4e3b\u5e72\u4ee3\u7801\uff1a<\/p>\n<pre class=\"java\" name=\"code\"> \r\n\/**\r\n     * Determine if this message should be dropped.\r\n     *\r\n     * We compute the current rate by taking a timestamp every 100 messages.\r\n     * Could change to a more complex scheme if more accuracy is needed.\r\n     *\r\n     * Enable throttling if the rate goes above packetInRateThresholdHigh\r\n     * Disable throttling when the rate drops below packetInRateThresholdLow\r\n     *\r\n     * While throttling is enabled, we do the following:\r\n     *  - Remove duplicate packetIn's mapped to the same OFMatch\r\n     *  - After filtering, if packetIn rate per host (mac) is above\r\n     *    packetInRatePerMacThreshold, push a flow mod to block mac on port\r\n     *  - After filtering, if packetIn rate per port is above\r\n     *    packetInRatePerPortThreshold, push a flow mod to block port\r\n     *  - Allow blocking flow mods have a hard timeout and expires automatically\r\n     *\r\n     * TODO: keep a history of all events related in input throttling\r\n     *\r\n     * @param ofm\r\n     * @return\r\n     *\/\r\n    @Override\r\n    public boolean inputThrottled(OFMessage ofm) {\r\n        if (ofm.getType() != OFType.PACKET_IN) {\r\n            return false;\r\n        }\r\n        ctrSwitchPktin.updateCounterNoFlush();\r\n        \/\/ Compute current packet in rate\r\n        messageCount++;\r\n        if (messageCount % 1000 == 0) {\r\n            long now = System.currentTimeMillis();\r\n            if (now != lastMessageTime) {\r\n                currentRate = (int) (1000000 \/ (now - lastMessageTime));\r\n                lastMessageTime = now;\r\n            } else {\r\n                currentRate = Integer.MAX_VALUE;\r\n            }\r\n        }\r\n        if (!packetInThrottleEnabled) {\r\n            if (currentRate <= packetInRateThresholdHigh) {\r\n                return false; \/\/ most common case\r\n            }\r\n            enablePacketInThrottle();\r\n        } else if (currentRate < packetInRateThresholdLow) {\r\n            disablePacketInThrottle();\r\n            return false;\r\n        }\r\n\r\n        \/\/ Now we are in the slow path where we need to do filtering\r\n        \/\/ First filter based on OFMatch\r\n        OFPacketIn pin = (OFPacketIn)ofm;\r\n        OFMatch match = new OFMatch();\r\n        match.loadFromPacket(pin.getPacketData(), pin.getInPort());\r\n        if (ofMatchCache.update(match)) {\r\n           ctrSwitchPktinDrops.updateCounterNoFlush();\r\n            return true;\r\n        }\r\n\r\n        \/\/ We have packet in with a distinct flow, check per mac rate\r\n        messageCountUniqueOFMatch++;\r\n        if ((messageCountUniqueOFMatch % packetInRatePerMacThreshold) == 1) {\r\n            checkPerSourceMacRate(pin);\r\n        }\r\n\r\n        \/\/ Check per port rate\r\n        if ((messageCountUniqueOFMatch % packetInRatePerPortThreshold) == 1) {\r\n            checkPerPortRate(pin);\r\n        }\r\n        return false;\r\n    }\r\n<\/pre>\n<p>\u8ba9\u6211\u4eec\u8ba1\u7b97\u4e00\u4e0b\u8fd9\u79cd\u673a\u5236\u7684\u6548\u7387\uff0c\u7531\u4e8e\u9608\u503cpacketInRateThresholdHigh\u8bbe\u7f6e\u7684\u662f1000\uff0c\u90a3\u4e48now-lastMessageTime\u5e94\u4e3a1000ms=1s\uff1b\u8003\u8651\u5230controller\u6bcf1000\u4e2apacket_in\u8fdb\u884c\u5224\u65ad\uff0c\u4e5f\u5c31\u662f\u8bf4\u5165\u5305\u7684\u6781\u9650\u662f\u6bcf\u79d21000\u4e2apacket_in\u6570\u636e\u5305\uff0c\u53731000\u6761\u65b0\u6d41\u3002\u8fd9\u4e2a\u5728\u5c0f\u8303\u56f4\u5185\u662f\u6ca1\u95ee\u9898\u7684\uff0c\u4f46Nick McKeown\u7b49\u4eba\u5728\u7ecf\u5178\u6587\u7ae0\u201cOpenFlow: Enabling Innovation in Campus Networks\u201d\u4e2d\u63d0\u5230Preliminary results suggested that an Ethane controller based on a low-cost desktop PC could process over 10,000 new \ufb02ows per second \u2014 enough for a large college campus. \u663e\u7136\u6bcf\u79d21k\u6761\u6d41\u7684\u5904\u7406\u89c4\u6a21\u8fd8\u662f\u592a\u5c0f\uff0c\u90a3\u4e48\u5355\u5355\u589e\u52a0\u9608\u503c\u4e5f\u4e0d\u80fd\u89e3\u51b3\u95ee\u9898\uff1a\u56e0\u4e3acontroller\u5e76\u4e0d\u77e5\u9053\u90a3\u4e9b\u6d41\u662f\u6b63\u5e38\u54ea\u4e9b\u662f\u5f02\u5e38\u7684\uff0c\u5f53\u524d\u573a\u666f\u662f\u5c0f\u89c4\u6a21\u7684\u8fd8\u662f\u5927\u89c4\u6a21\u7684\uff0c\u7279\u522b\u662f\u5728\u4e00\u4e9b\u7a81\u7136\u573a\u666f\u4e0b\u3002\u6240\u4ee5\u7b80\u5355\u7684\u6d41\u91cf\u63a7\u5236\u5728\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u662f\u6709\u6548\u7684\uff0c\u4f46\u4e13\u95e8\u7684\u5b89\u5168\u8bbe\u5907\u4e5f\u662f\u5fc5\u9700\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>floodlight\u5728bigswitch\u9000\u51faopendaylight\u540e\u7b97\u662f\u6d3b\u8fc7\u6765\u4e86\uff0c\u65b0\u7684\u7248\u672c\u5728\u8d1f\u8f7d\u5747\u8861\u4e2d\u52a0\u5165\u4e86\u4e00\u4e9b\u673a\u5236\uff0c\u53ef\u4ee5\u53c2\u89c1net.floodlight.loadbalancer \u4e0d\u8fc7\u6211\u5173\u5fc3\u7684\u662fFL\u5bf9\u6d41\u91cf\u7684\u63a7\u5236\uff0c\u7279\u522b\u662f\u5224\u65adpacket_in\u901f\u7387\u7684\u673a\u5236\uff0c\u8fd9\u4e2a\u5728\u524d\u51e0\u4e2a\u6708\u7684Floodlight\u662f\u6ca1\u6709\u7684\u3002 \u73b0\u5728FL\u7684\u5904\u7406\u673a\u5236\u662f\u5728\u6536\u5230packet_in\u6570\u636e\u5305\u540e\uff0c\u9996\u5148\u5224\u65ad\u662f\u5426\u8d85\u8fc7\u9608\u503c\uff0c\u5728inputThrottled\u65b9\u6cd5\u4e2d\uff0c\u8ba1\u7b97\u6bcf1000\u4e2a\u6570\u636e\u5305\u6240\u82b1\u7684\u65f6\u95f4\uff0c\u5f97\u51fa\u901f\u7387\u3002\u5982\u679c\u901f\u7387\u8d85\u8fc7packetInRateThresholdHigh\u9608\u503c\uff0c\u5219\u8fdb\u5165\u76d1\u63a7\u9650\u5236\u6d41\u91cf\u6a21\u5f0f\uff08enablePacketInThrottle\uff09 \u5728\u8be5\u6a21\u5f0f\u4e0b\uff0c\u4f9d\u6b21\u68c0\u67e5packet_in\u6570\u636e\u5305\u7684src mac\uff08\u9891\u7387\u4e3a\u6bcf50\u4e2apacket_in\u4e00\u6b21\uff09\u548cin port\uff08\u9891\u7387\u4e3a\u6bcf100\u4e2apacket_in\u4e00\u6b21\uff09\uff0c\u5982\u679c\u8fd1\u671f\uff081s\u5185\uff09\u6709\u8be5\u7c7b\u6570\u636e\u5305\u5219\u5c06\u5176\u7981\u6b62\u3002 \u8fd9\u79cd\u65b9\u6cd5\u7684\u521d\u8877\u5e94\u8be5\u662f\u9632\u6b62controller\u7684\u8d1f\u8f7d\u8fc7\u9ad8\uff0c\u4f8b\u5982\u7981\u6b62mac\u662f\u4e3a\u4e86\u9632\u6b62host\u53d1\u9001\u8fc7\u591a\u5305\uff0c\u7981\u6b62in port\u662f\u4e3a\u4e86\u7981\u6b62sw\u8f6c\u53d1\u8fc7\u591a\u5305\u3002\u4f46\u540e\u8005\u6709\u53ef\u80fd\u51fa\u73b0\u5728\u6076\u610fvm\u53d1\u52a8DDoS\u653b\u51fb\uff08\u4e00\u4e2ain port\uff0c\u4f46\u65e0\u6570src mac\uff09\uff0c\u5ba2\u89c2\u4e0a\u5374\u4f7f\u63a7\u5236\u5668\u514d\u53d7DDoS\u653b\u51fb\uff0c\u81ea\u7136\u4e5f\u8ba9\u57df\u5185\u7684VM\u88abDDoS\u3002 \u8d34\u4e00\u4e0b\u4e3b\u5e72\u4ee3\u7801\uff1a \/** * Determine if this message should be dropped. * * We compute the current rate by taking a timestamp every 100 messages. * Could change to a more complex scheme if more accuracy is needed. * * Enable throttling if the rate goes &hellip; <a href=\"https:\/\/marvelliu.space\/?p=491\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Floodlight\u7684\u6d41\u91cf\u63a7\u5236&#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":[21],"tags":[27,34],"class_list":["post-491","post","type-post","status-publish","format-standard","hentry","category-tech","tag-floodlight","tag-sdn"],"_links":{"self":[{"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/posts\/491","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=491"}],"version-history":[{"count":3,"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/posts\/491\/revisions"}],"predecessor-version":[{"id":494,"href":"https:\/\/marvelliu.space\/index.php?rest_route=\/wp\/v2\/posts\/491\/revisions\/494"}],"wp:attachment":[{"href":"https:\/\/marvelliu.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/marvelliu.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/marvelliu.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}