This article recreates the demonstration using the Ryu SDN framework and emulating a network using Mininet. Install both pieces of software on a Linux server or virtual machine in order to follow this example.
Start Ryu with the simple_switch and ryu.app.ofctl_rest applications loaded:
ryu-manager ryu.app.simple_switch,ryu.app.ofctl_restNote: The simple_switch and ofctl_rest scripts are part of a standard Ryu installation.
This demonstration uses the sFlow-RT real-time analytics engine to process standard sFlow streaming telemetry from the network switches.
Download sFlow-RT:
wget https://inmon.com/products/sFlow-RT/sflow-rt.tar.gz tar -xvzf sflow-rt.tar.gzInstall the Mininet Dashboard application:
sflow-rt/get-app.sh sflow-rt mininet-dashboardThe following script, ryu.js, implements the DDoS mitigation function described in the previous article:
var ryu = '127.0.0.1'; var controls = {}; setFlow('udp_reflection', {keys:'ipdestination,udpsourceport',value:'frames'}); setThreshold('udp_reflection_attack', {metric:'udp_reflection',value:100,byFlow:true,timeout:2}); setEventHandler(function(evt) { // don't consider inter-switch links var link = topologyInterfaceToLink(evt.agent,evt.dataSource); if(link) return; // get port information var port = topologyInterfaceToPort(evt.agent,evt.dataSource); if(!port) return; // need OpenFlow info to create Ryu filtering rule if(!port.dpid || !port.ofport) return; // we already have a control for this flow if(controls[evt.flowKey]) return; var [ipdestination,udpsourceport] = evt.flowKey.split(','); var msg = { priority:40000, dpid:parseInt(port.dpid,16), match: { in_port:port.ofport, dl_type:0x800, nw_dst:ipdestination+'/32', nw_proto:17, tp_src:udpsourceport } }; var resp = http2({ url:'http://'+ryu+':8080/stats/flowentry/add', headers:{'Content-Type':'application/json','Accept':'application/json'}, operation:'post', body: JSON.stringify(msg) }); controls[evt.flowKey] = { time:Date.now(), threshold:evt.thresholdID, agent:evt.agent, metric:evt.dataSource+'.'+evt.metric, msg:msg }; logInfo("blocking " + evt.flowKey); },['udp_reflection_attack']); setIntervalHandler(function() { var now = Date.now(); for(var key in controls) { let rec = controls[key]; // keep control for at least 10 seconds if(now - rec.time < 10000) continue; // keep control if threshold still triggered if(thresholdTriggered(rec.threshold,rec.agent,rec.metric,key)) continue; var resp = http2({ url:'http://'+ryu+':8080/stats/flowentry/delete', headers:{'Content-Type':'application/json','Accept':'application/json'}, operation:'post', body: JSON.stringify(rec.msg) }); delete controls[key]; logInfo("unblocking " + key); } });Some notes on the script:
- The Ryu ryu.app.ofctl_rest is used to add/remove filters that block the DDoS traffic
- The udp_reflection flow definition is designed to detect UDP amplification attacks, e.g. DNS amplification attacks
- Controls are applied to the switch port where traffic enters the network
- The controls structure is used to keep track of state associated with deployed configuration changes so that they can be undone
- The intervalHandler() function is used to automatically release controls after 10 seconds - the timeout is short for the purposes of demonstration, in practical deployments the timeout would be much measured in hours
- For simplicity, this script is missing the error handling needed for production use.
- See Writing Applications for more information.
./sflow-rt/start.sh -Dscript.file=../ryu.jsWe are going to use hping3 to simulate a DDoS attack, so install the software using the following command:
sudo apt install hping3Next, start Mininet:
sudo mn --custom sflow-rt/extras/sflow.py --link tc,bw=10 \ --controller=remote,ip=127.0.0.1 --topo tree,depth=2,fanout=2Generate normal traffic between hosts h1 and h3:
mininet> iperf h1 h3The weathermap view shows the flow crossing the network from switch s2 to s3 via s1.
Generate an attack:
mininet> h1 hping3 --flood --udp -k -s 53 h3The weathermap view verifies that the attack has been successfully blocked since none of the traffic is seen traversing the network.
The chart at the top of this article shows the iperf test followed by the simulated attack. The top chart shows the top flows entering the network, showing the DNS amplification attack traffic in blue. The middle chart shows traffic broken out by switch port. Here, the blue line shows the attack traffic arriving at switch s2 port s2-eth1 while the red line shows that only a small amount of traffic is forwarded to switch s3 port s3-eth3 before the attack is blocked at switch s2 by the controller.
Mininet with Ryu and sFlow-RT is a great way to rapidly develop and test SDN applications, avoiding the time and expense involved in setting up a physical network. The application is easily moved from the Mininet virtual network to a physical network since it is based on the same industry standard sFlow telemetry generated by physical switches. In this case, using commodity switch hardware to cost effectively detect and filter massive (100's of Gbit/s) DDoS attacks.
Note: Northbound Networks Zodiac GX is an inexpensive gigabit switch that provides a convenient way to transition from an emulated Mininet environment to a physical network handling real traffic.