Figure 1: Performance aware software defined networking |
Examples on this blog have used Python or node.js scripts to create demonstrations. However, while external scripts are a quick way to build prototypes, moving from prototype to production quality implementations can be a challenge.
Much of the complexity in developing external control applications involves sharing and distributing state with the analytics engine and OpenFlow controller. This complexity can be greatly reduced if the application can be embedded in the analytics software, or in the OpenFlow controller. Deciding whether to embed an application in the analytics engine, or in the controller, should be based on how tightly coupled the application is to each of these services. In the case of performance management applications, most of the interaction is with the analytics engine and so it makes most sense to embed application logic within the analytics engine.
The following example demonstrates the benefits of embedding by taking the DDoS mitigation script described in Frenetic, Pyretic and Resonance and re-implementing it as an embedded application using the recently released sFlow-RT analytics engine scripting API.
The following script implements the DDoS mitigation application:
// author: Peter // version: 1.0 // date: 9/30/2013 // description: DDoS controller script include('extras/json2.js'); var flowkeys = 'ipsource'; var value = 'frames'; var filter = 'outputifindex!=discard&direction=ingress&sourcegroup=external'; var threshold = 1000; // 1000 packets per second var groups = {'external':['0.0.0.0/0'],'internal':['10.0.0.2/32']}; var metricName = 'ddos'; var controls = {}; var enabled = true; function sendy(address,type,state) { var result = runCmd(['../pyretic/pyretic/pyresonance/sendy_json.py', '-i',address,'-e',type,'-V',state]); } function block(address) { if(!controls[address]) { sendy(address,'auth','clear'); controls[address] = 'blocked'; } } function allow(address) { if(controls[address]) { sendy(address,'auth','authenticated'); delete controls[address]; } } setGroups(groups); setFlow(metricName, {keys:flowkeys, value:value, filter:filter, n:10, t:2}); setThreshold(metricName,{metric:metricName,value:threshold,byFlow:true}); setEventHandler(function(evt) { if(!enabled) return; var address = evt.flowKey; block(address); },[metricName]); setHttpHandler(function(request) { var result = {}; try { var action = '' + request.query.action; switch(action) { case 'block': var address = request.query.address[0]; if(address) block(address); break; case 'allow': var address = request.query.address[0]; if(address) allow(address); break; case 'enable': enabled = true; break; case 'disable': enabled = false; break; } } catch(e) { result.error = e.message } result.controls = controls; result.enabled = enabled; return JSON.stringify(result); });The following command line argument loads the script on startup:
-Dscript.file=ddos.jsIn addition to providing the functionality of the original script, the embedded script also includes an HTTP interface for remotely monitoring and controlling the application. For example, manually blocking or allowing an address is accomplished with the following commands:
$ curl "http://10.0.0.54:8008/script/ddos.js/json?action=block&address=10.0.0.1" {"controls":{"10.0.0.1":"blocked"},"enabled":true} $ curl "http://10.0.0.54:8008/script/ddos.js/json?action=allow&address=10.0.0.1" {"controls":{},"enabled":true}Enabling and disabling the controller is also possible:
$ curl http://10.0.0.54:8008/script/ddos.js/json?action=enable {"controls":{},"enabled":true} $ curl http://10.0.0.54:8008/script/ddos.js/json?action=disable {"controls":{},"enabled":false}The following example uses the test bed described in Frenetic, Pyretic and Resonance to demonstrate the DDoS controller. Open a web browser to view a trend of traffic and then performing the following steps:
- disable the controller
- perform a simulated DoS attack (using a flood ping)
- enable the controller
- simulate a second DoS attack.
Figure 2: DDoS attack traffic with and without controller |
Figure 3: RESTful control of switches |
While important classes of SDN application make sense integrated within the SDN controller (e.g. network virtualization, virtual firewalls, and routers etc.), the use cases described in this article demonstrate that integrating performance aware SDN applications (e.g. load balancing, DDoS mitigation, traffic marking, multi-tenant performance isolation, etc.) within the analytics platform makes architectural sense.
Hi Peter, I try your code but i get an error like this :
ReplyDeleteinclude('extras/json2.js');
^
ReferenceError: include is not defined
...
Do you know why this error happen?
You should remove the include line from the example since the latest version of sFlow-RT has built-in JSON support (and no longer includes the extras/json2.js file).
Delete