Advertisement
Advanced Time: 4–5 weeks IT & Networking

Software-Defined Networking with OpenFlow

Build a software-defined network using OpenFlow protocol, Mininet emulator, and ONOS controller with custom packet routing policies.

SDNOpenFlowMininetONOSOpenDaylightNetwork Automation
DifficultyAdvanced
Duration4–5 weeks
Components10 items
Steps3 steps

Introduction

Build a software-defined network using OpenFlow protocol, Mininet emulator, and ONOS controller with custom packet routing policies. This comprehensive guide covers everything from design through implementation, testing, and deployment.

Theory & Background

Traditional networking: control plane (routing decisions) and data plane (packet forwarding) embedded in each device — distributed intelligence. SDN: decouple control from forwarding. Centralized Controller programs all switches via OpenFlow protocol. Data plane: 'dumb' switches forward packets based on flow tables programmed by controller. Advantages: global network view enables better optimization, programmatic control (deploy new routing policies via code instantly), hardware independence (commodity switches with OpenFlow). Disadvantages: controller is single point of failure (redundancy needed), higher latency for first packet of new flow.

Advertisement

Components & Requirements

10 components required for this project.

#ComponentPurposeQty
1Mininet network emulatorVirtual SDN network simulationx1
2ONOS SDN ControllerCentralized network controllerx1
3OpenFlow 1.3 switches (virtual)Programmatic packet forwardingx1
4Python (Ryu framework)Custom SDN application developmentx1
5Wireshark with OpenFlow dissectorOpenFlow message analysisx1
6Ubuntu 20.04 (Mininet compatible)Host OSx1
7iperf3Network performance measurementx1
8ONOS REST APINetwork policy programmingx1
9OpenVSwitch (OVS)OpenFlow-capable virtual switchx1
10GNS3 (alternative)Network simulation with real router imagesx1

Step-by-Step Implementation

Follow these 3 steps carefully.

1
SDN Architecture Concepts

Traditional networking: control plane (routing decisions) and data plane (packet forwarding) embedded in each device — distributed intelligence. SDN: decouple control from forwarding. Centralized Controller programs all switches via OpenFlow protocol. Data plane: 'dumb' switches forward packets based on flow tables programmed by controller. Advantages: global network view enables better optimization, programmatic control (deploy new routing policies via code instantly), hardware independence (commodity switches with OpenFlow). Disadvantages: controller is single point of failure (redundancy needed), higher latency for first packet of new flow.

2
Mininet Network Emulation

Mininet creates a virtual network with real kernel networking stack. mn --topo tree,depth=3,fanout=3 creates a tree topology with 27 hosts and 13 switches. Custom topology in Python: class MyTopo(Topo): define hosts and switches, add links with bandwidth/delay parameters. Connect to Ryu controller: mn --controller=remote,ip=127.0.0.1,port=6653. Test connectivity: mininet> pingall. Measure throughput: mininet> iperf h1 h27. Mininet runs all hosts/switches on one Linux machine using network namespaces.

3
Ryu OpenFlow Application

Ryu is a Python-based SDN framework. OpenFlow application inherits from RyuApp. Event handlers: @set_ev_cls(ofp_event.EventOFPSwitchFeatures): called when switch connects, install initial flow rules. @set_ev_cls(ofp_event.EventOFPPacketIn): called when switch receives packet not matching any flow table entry. Handler: learn source MAC, look up destination MAC, if known install flow rule (avoiding future PacketIn events for this flow), otherwise flood.

Code & Implementation

Core code for sdn_controller.py:

sdn_controller.py Python
from ryu.base import app_manager from ryu.controller import ofp_event from ryu.controller.handler import CONFIG_DISPATCHER, MAIN_DISPATCHER, set_ev_cls from ryu.ofproto import ofproto_v1_3 from ryu.lib.packet import packet, ethernet  class L2Switch(app_manager.RyuApp):     OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]      def __init__(self, *args, **kwargs):         super().__init__(*args, **kwargs)         self.mac_to_port = {}  # {dpid: {mac: port}}      @set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)     def switch_connected(self, ev):         """Install table-miss flow: send all unknown packets to controller"""         dp = ev.msg.datapath         ofp = dp.ofproto; parser = dp.ofproto_parser         # Match: all packets. Action: send to controller         match = parser.OFPMatch()         actions = [parser.OFPActionOutput(ofp.OFPP_CONTROLLER)]         inst = [parser.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, actions)]         dp.send_msg(parser.OFPFlowMod(dp, priority=0, match=match, instructions=inst))      @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)     def packet_in(self, ev):         msg = ev.msg; dp = msg.datapath         ofp = dp.ofproto; parser = dp.ofproto_parser         pkt = packet.Packet(msg.data)         eth = pkt.get_protocol(ethernet.ethernet)         dpid = dp.id; in_port = msg.match['in_port']         # Learn source MAC         self.mac_to_port.setdefault(dpid, {})         self.mac_to_port[dpid][eth.src] = in_port         # Forward or flood         out_port = self.mac_to_port[dpid].get(eth.dst, ofp.OFPP_FLOOD)         # Install flow rule if destination known (avoid future PacketIn)         if out_port != ofp.OFPP_FLOOD:             match = parser.OFPMatch(in_port=in_port, eth_dst=eth.dst)             actions = [parser.OFPActionOutput(out_port)]             inst = [parser.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, actions)]             dp.send_msg(parser.OFPFlowMod(dp, priority=1, match=match, instructions=inst))         # Forward this packet         dp.send_msg(parser.OFPPacketOut(dp, msg.buffer_id, in_port, [parser.OFPActionOutput(out_port)], msg.data))

Testing & Troubleshooting

Test Software-Defined Networking with OpenFlow by verifying each subsystem individually before full integration.

!
Troubleshooting Tips

Verify power voltages, check ground connections, use serial monitor for debug.

Real-World Applications

*Data center fabric optimization
*WAN traffic engineering
*Cloud virtual networking
*Campus network automation
*Security enforcement with granular flow rules
*Network slicing for 5G (SDN core)
*Research and experimentation network
*Network function virtualization (NFV) control

Extensions & Next Steps

  • Implement QoS using DiffServ with OpenFlow marking
  • Build a network-wide intrusion detection system using flow analytics
  • Implement ECMP load balancing across multiple paths
  • Create network topology visualization using ONOS northbound API
  • Build intent-based networking where policies are expressed in high-level language

Interactive Playground

Coming Soon

An interactive simulator will be available here — simulate circuits and run code in-browser without hardware.

Frequently Asked Questions

Is SDN used in real production networks?
Yes, widely. Google's B4 WAN uses OpenFlow-based SDN to manage the entire backbone connecting their data centers — achieving near-100% link utilization vs 30–40% in traditional networks by globally optimizing traffic. Facebook (Meta) uses similar OpenDaylight-based SDN for data center networking. Microsoft Azure and AWS use SDN extensively for virtual networking (VPCs, security groups programmed as flow rules). SD-WAN (Software-Defined WAN) is a commercial application of SDN principles now used by enterprises for WAN cost optimization.
Advertisement