SDN 101: Practical example for SDN Controller
What is software-defined networking (SDN) by practical example?
Requirement:
1- HP VAN SDN Controller.
2- Mininet emulation build openflow switches
3- Python HP SDK for build routing protocol
1- How to Build Topology?
Using Mininet Emulation openflow switch:
using python for draw topology:
Topology.py
===================================
"""Custom topology example
Adding the 'topos' dict with a key/value pair to generate our newly defined
topology enables one to pass in '--topo=mytopo' from the command line.
"""
from mininet.topo import Topo
class MyTopo( Topo ):
"Simple topology example."
def __init__( self ):
"Create custom topo."
# Initialize topology
Topo.__init__( self )
h1 = self.addHost( 'h1', ip='10.10.2.1/24', defaultRoute='via 10.10.2.254' )
h2 = self.addHost( 'h2', ip='10.10.2.2/24', defaultRoute='via 10.10.2.254' )
h3 = self.addHost( 'h3', ip='10.10.2.3/24', defaultRoute='via 10.10.2.254' )
h4 = self.addHost( 'h4', ip='10.10.2.4/24', defaultRoute='via 10.10.2.254' )
h5 = self.addHost( 'h5', ip='10.10.2.5/24', defaultRoute='via 10.10.2.254' )
h6 = self.addHost( 'h6', ip='10.10.2.6/24', defaultRoute='via 10.10.2.254' )
g1 = self.addHost( 'g1', ip='10.10.2.254/24')
s1 = self.addSwitch( 's1', dpid='0000000000000001',protocols='OpenFlow13' )
s2 = self.addSwitch( 's2', dpid='0000000000000002',protocols='OpenFlow13' )
s3 = self.addSwitch( 's3', dpid='0000000000000003',protocols='OpenFlow13' )
s4 = self.addSwitch( 's4', dpid='0000000000000004',protocols='OpenFlow10' )
s5 = self.addSwitch( 's5', dpid='0000000000000005',protocols='OpenFlow13' )
s6 = self.addSwitch( 's6', dpid='0000000000000006',protocols='OpenFlow13' )
#core
self.addLink ( s1, s2 )
#distribution
self.addLink ( s1, s3 )
self.addLink ( s1, s4 )
self.addLink ( s1, s5 )
self.addLink ( s1, s6 )
self.addLink ( s2, s3 )
self.addLink ( s2, s4 )
self.addLink ( s2, s5 )
self.addLink ( s2, s6 )
#acccess
self.addLink( s3, h1 )
self.addLink( s3, h2 )
self.addLink( s4, h3 )
self.addLink( s4, h4 )
self.addLink( s5, h5 )
self.addLink( s5, h6 )
self.addLink( s6, g1)
topos = { 'mytopo': ( lambda: MyTopo() ) }
"""
#
how to run:
sudo mn --custom topology.py --topo mytopo --controller=remote,ip=10.0.0.11
"""
for example:
I need choose the best route between PC 10.10.2.254 to Server 10.10.2.1
i choose this pass as the best route:
H1(10.10.2.254) ---- S3 ---- S2----- S1-----S6 ------G1(10.10.2.1)
Write script called Route.py
=================================================
#!/usr/bin/env python
#
# traffic route between H1 TO G1 Server
# H1 ---- S3 ---- S2----- S1-----S6 ------G1
#
import hpsdnclient as hp
def main():
#initialize the api
controller = '192.168.79.131'
auth = hp.XAuthToken(user='sdn', password='skyline', server=controller)
api = hp.Api(controller=controller, auth=auth)
#create the match object
match = hp.datatypes.Match(eth_type="ipv4", ipv4_src="10.10.2.1",
ipv4_dst="10.10.2.254",ip_proto="tcp",
tcp_dst="80")
#create the action objects
output1 = hp.datatypes.Action(output=1)
output2 = hp.datatypes.Action(output=2)
output3 = hp.datatypes.Action(output=3)
output5 = hp.datatypes.Action(output=5)
#create the flows
flow1 = hp.datatypes.Flow(priority=30000, idle_timeout=300,
match=match, actions=output5)
flow2 = hp.datatypes.Flow(priority=30000, idle_timeout=300,
match=match, actions=output1)
flow3 = hp.datatypes.Flow(priority=30000, idle_timeout=300,
match=match, actions=output2)
flow6 = hp.datatypes.Flow(priority=30000, idle_timeout=300,
match=match, actions=output3)
#push the flows to the datatpaths
api.add_flows('00:00:00:00:00:00:00:03', flow3)
api.add_flows('00:00:00:00:00:00:00:02', flow2)
api.add_flows('00:00:00:00:00:00:00:01', flow1)
api.add_flows('00:00:00:00:00:00:00:06', flow6)
if __name__ == "__main__":
main()
Good Luck
Requirement:
1- HP VAN SDN Controller.
2- Mininet emulation build openflow switches
3- Python HP SDK for build routing protocol
1- How to Build Topology?
Using Mininet Emulation openflow switch:
using python for draw topology:
Topology.py
===================================
"""Custom topology example
Adding the 'topos' dict with a key/value pair to generate our newly defined
topology enables one to pass in '--topo=mytopo' from the command line.
"""
from mininet.topo import Topo
class MyTopo( Topo ):
"Simple topology example."
def __init__( self ):
"Create custom topo."
# Initialize topology
Topo.__init__( self )
h1 = self.addHost( 'h1', ip='10.10.2.1/24', defaultRoute='via 10.10.2.254' )
h2 = self.addHost( 'h2', ip='10.10.2.2/24', defaultRoute='via 10.10.2.254' )
h3 = self.addHost( 'h3', ip='10.10.2.3/24', defaultRoute='via 10.10.2.254' )
h4 = self.addHost( 'h4', ip='10.10.2.4/24', defaultRoute='via 10.10.2.254' )
h5 = self.addHost( 'h5', ip='10.10.2.5/24', defaultRoute='via 10.10.2.254' )
h6 = self.addHost( 'h6', ip='10.10.2.6/24', defaultRoute='via 10.10.2.254' )
g1 = self.addHost( 'g1', ip='10.10.2.254/24')
s1 = self.addSwitch( 's1', dpid='0000000000000001',protocols='OpenFlow13' )
s2 = self.addSwitch( 's2', dpid='0000000000000002',protocols='OpenFlow13' )
s3 = self.addSwitch( 's3', dpid='0000000000000003',protocols='OpenFlow13' )
s4 = self.addSwitch( 's4', dpid='0000000000000004',protocols='OpenFlow10' )
s5 = self.addSwitch( 's5', dpid='0000000000000005',protocols='OpenFlow13' )
s6 = self.addSwitch( 's6', dpid='0000000000000006',protocols='OpenFlow13' )
#core
self.addLink ( s1, s2 )
#distribution
self.addLink ( s1, s3 )
self.addLink ( s1, s4 )
self.addLink ( s1, s5 )
self.addLink ( s1, s6 )
self.addLink ( s2, s3 )
self.addLink ( s2, s4 )
self.addLink ( s2, s5 )
self.addLink ( s2, s6 )
#acccess
self.addLink( s3, h1 )
self.addLink( s3, h2 )
self.addLink( s4, h3 )
self.addLink( s4, h4 )
self.addLink( s5, h5 )
self.addLink( s5, h6 )
self.addLink( s6, g1)
topos = { 'mytopo': ( lambda: MyTopo() ) }
"""
#
how to run:
sudo mn --custom topology.py --topo mytopo --controller=remote,ip=10.0.0.11
"""
=============================================================
2- How to build routing protocol?for example:
I need choose the best route between PC 10.10.2.254 to Server 10.10.2.1
i choose this pass as the best route:
H1(10.10.2.254) ---- S3 ---- S2----- S1-----S6 ------G1(10.10.2.1)
Write script called Route.py
=================================================
#!/usr/bin/env python
#
# traffic route between H1 TO G1 Server
# H1 ---- S3 ---- S2----- S1-----S6 ------G1
#
import hpsdnclient as hp
def main():
#initialize the api
controller = '192.168.79.131'
auth = hp.XAuthToken(user='sdn', password='skyline', server=controller)
api = hp.Api(controller=controller, auth=auth)
#create the match object
match = hp.datatypes.Match(eth_type="ipv4", ipv4_src="10.10.2.1",
ipv4_dst="10.10.2.254",ip_proto="tcp",
tcp_dst="80")
#create the action objects
output1 = hp.datatypes.Action(output=1)
output2 = hp.datatypes.Action(output=2)
output3 = hp.datatypes.Action(output=3)
output5 = hp.datatypes.Action(output=5)
#create the flows
flow1 = hp.datatypes.Flow(priority=30000, idle_timeout=300,
match=match, actions=output5)
flow2 = hp.datatypes.Flow(priority=30000, idle_timeout=300,
match=match, actions=output1)
flow3 = hp.datatypes.Flow(priority=30000, idle_timeout=300,
match=match, actions=output2)
flow6 = hp.datatypes.Flow(priority=30000, idle_timeout=300,
match=match, actions=output3)
#push the flows to the datatpaths
api.add_flows('00:00:00:00:00:00:00:03', flow3)
api.add_flows('00:00:00:00:00:00:00:02', flow2)
api.add_flows('00:00:00:00:00:00:00:01', flow1)
api.add_flows('00:00:00:00:00:00:00:06', flow6)
if __name__ == "__main__":
main()
======================================================
After running script can be on SDN controller path as red line like above Image.Good Luck
Comments
Post a Comment