0% found this document useful (0 votes)
27 views15 pages

mySDN Lab6

Uploaded by

Sudesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views15 pages

mySDN Lab6

Uploaded by

Sudesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Lab 6 (FlowVisor)

• Flowvisor creates rich slices of network


resources and delegates control of each slice
to each slice to a different controller.

. a low bandwidth path via switch s2


. a high bandwidth path via switch s3
Controlled by flowvisor_lab1_upper

Controlled by flowvisor_lab1_lower
#!/usr/bin/python # Add switch links
self.addLink('s1', 's2', **http_link_config)
from mininet.topo import Topo self.addLink('s2', 's4', **http_link_config)
self.addLink('s1', 's3', **video_link_config)
class FVTopo(Topo): self.addLink('s3', 's4', **video_link_config)

def __init__(self): # Add host links


# Initialize topology self.addLink('h1', 's1', **host_link_config)
Topo.__init__(self) self.addLink('h2', 's1', **host_link_config)
self.addLink('h3', 's4', **host_link_config)
# Create template host, switch, and link self.addLink('h4', 's4', **host_link_config)
hconfig = {'inNamespace':True}
http_link_config = {'bw': 1} topos = { 'fvtopo': ( lambda: FVTopo() ) }
video_link_config = {'bw': 10}
host_link_config = {} flowvisor_topo.py

# Create switch nodes


for i in range(4):
sconfig = {'dpid': "%016x" % (i+1)}
self.addSwitch('s%d' % (i+1), **sconfig)

# Create host nodes


for i in range(4):
self.addHost('h%d' % (i+1), **hconfig)
from pox.core import core flowvisor_lab1_upper.py
import pox.openflow.libopenflow_01 as of Put this file under ~/pox/ext
from pox.lib.util import dpidToStr
from pox.openflow.of_json import *
from pox.lib.recoco import Timer

log = core.getLogger()

s1_dpid=0
s2_dpid=0
s3_dpid=0
s4_dpid=0

def _timer_func():
for connection in core.openflow._connections.values():
connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
print "Sent %i port stats request(s)" % (len(core.openflow._connections))

def _handle_portstats_received(event):
#stats=flow_stats_to_list(event.stats)
#print "PortStatsReceived from %s: %s" % (dpidToStr(event.connection.dpid), stats)
for f in event.stats:
if int(f.port_no)<65534:
print "PortNo:", f.port_no, " dpid:", event.connection.dpid
def _handle_ConnectionUp (event): def _handle_PacketIn (event):
global s1_dpid, s2_dpid, s3_dpid, s4_dpid global s1_dpid, s2_dpid, s3_dpid, s4_dpid
print "ConnectionUp: ", print "PacketIn: ", dpidToStr(event.connection.dpid)
dpidToStr(event.connection.dpid)
if event.connection.dpid==s1_dpid:
#remember the connection dpid for switch msg = of.ofp_flow_mod()
for m in event.connection.features.ports: msg.priority =1
if m.name == "s1-eth1": msg.idle_timeout = 0
s1_dpid = event.connection.dpid msg.hard_timeout = 0
print "s1_dpid=", s1_dpid msg.match.in_port =3
elif m.name == "s2-eth1": msg.actions.append(of.ofp_action_output(port = 1))
s2_dpid = event.connection.dpid event.connection.send(msg)
print "s2_dpid=", s2_dpid
elif m.name == "s3-eth1": msg = of.ofp_flow_mod()
s3_dpid = event.connection.dpid msg.priority =1
print "s3_dpid=", s3_dpid msg.idle_timeout = 0
elif m.name == "s4-eth1": msg.hard_timeout = 0
s4_dpid = event.connection.dpid msg.match.in_port =1
print "s4_dpid=", s4_dpid msg.actions.append(of.ofp_action_output(port = 3))
event.connection.send(msg)
elif event.connection.dpid==s2_dpid: elif event.connection.dpid==s4_dpid:
msg = of.ofp_flow_mod() msg = of.ofp_flow_mod()
msg.priority =1 msg.priority =1
msg.idle_timeout = 0 msg.idle_timeout = 0
msg.hard_timeout = 0 msg.hard_timeout = 0
msg.match.in_port =1 msg.match.in_port =1
msg.actions.append(of.ofp_action_output(port = 2)) msg.actions.append(of.ofp_action_output(port = 3))
event.connection.send(msg) event.connection.send(msg)

msg = of.ofp_flow_mod() msg = of.ofp_flow_mod()


msg.priority =1 msg.priority =1
msg.idle_timeout = 0 msg.idle_timeout = 0
msg.hard_timeout = 0 msg.hard_timeout = 0
msg.match.in_port =2 msg.match.in_port =3
msg.actions.append(of.ofp_action_output(port = 1)) msg.actions.append(of.ofp_action_output(port = 1))
event.connection.send(msg) event.connection.send(msg)

def launch ():


core.openflow.addListenerByName("ConnectionUp", _handle_ConnectionUp)
core.openflow.addListenerByName("PacketIn", _handle_PacketIn)
core.openflow.addListenerByName("PortStatsReceived",
_handle_portstats_received)

Timer(5, _timer_func, recurring=True)


from pox.core import core flowvisor_lab1_lower.py
import pox.openflow.libopenflow_01 as of Put this file under ~/pox/ext
from pox.lib.util import dpidToStr
from pox.openflow.of_json import *
from pox.lib.recoco import Timer

log = core.getLogger()

s1_dpid=0
s2_dpid=0
s3_dpid=0
s4_dpid=0

def _timer_func():
for connection in core.openflow._connections.values():
connection.send(of.ofp_stats_request(body=of.ofp_port_stats_request()))
print "Sent %i port stats request(s)" % (len(core.openflow._connections))

def _handle_portstats_received(event):
#stats=flow_stats_to_list(event.stats)
#print "PortStatsReceived from %s: %s" % (dpidToStr(event.connection.dpid), stats)
for f in event.stats:
if int(f.port_no)<65534:
print "PortNo:", f.port_no, " dpid:", event.connection.dpid
def _handle_ConnectionUp (event): def _handle_PacketIn (event):
global s1_dpid, s2_dpid, s3_dpid, s4_dpid global s1_dpid, s2_dpid, s3_dpid, s4_dpid
print "ConnectionUp: ", print "PacketIn: ", dpidToStr(event.connection.dpid)
dpidToStr(event.connection.dpid)
if event.connection.dpid==s1_dpid:
#remember the connection dpid for switch msg = of.ofp_flow_mod()
for m in event.connection.features.ports: msg.priority =1
if m.name == "s1-eth2": msg.idle_timeout = 0
s1_dpid = event.connection.dpid msg.hard_timeout = 0
print "s1_dpid=", s1_dpid msg.match.in_port =4
elif m.name == "s2-eth1": msg.actions.append(of.ofp_action_output(port = 2))
s2_dpid = event.connection.dpid event.connection.send(msg)
print "s2_dpid=", s2_dpid
elif m.name == "s3-eth1": msg = of.ofp_flow_mod()
s3_dpid = event.connection.dpid msg.priority =1
print "s3_dpid=", s3_dpid msg.idle_timeout = 0
elif m.name == "s4-eth2": msg.hard_timeout = 0
s4_dpid = event.connection.dpid msg.match.in_port =2
print "s4_dpid=", s4_dpid msg.actions.append(of.ofp_action_output(port = 4))
event.connection.send(msg)
elif event.connection.dpid==s3_dpid: elif event.connection.dpid==s4_dpid:
msg = of.ofp_flow_mod() msg = of.ofp_flow_mod()
msg.priority =1 msg.priority =1
msg.idle_timeout = 0 msg.idle_timeout = 0
msg.hard_timeout = 0 msg.hard_timeout = 0
msg.match.in_port =1 msg.match.in_port =2
msg.actions.append(of.ofp_action_output(port = 2)) msg.actions.append(of.ofp_action_output(port = 4))
event.connection.send(msg) event.connection.send(msg)

msg = of.ofp_flow_mod() msg = of.ofp_flow_mod()


msg.priority =1 msg.priority =1
msg.idle_timeout = 0 msg.idle_timeout = 0
msg.hard_timeout = 0 msg.hard_timeout = 0
msg.match.in_port =2 msg.match.in_port =4
msg.actions.append(of.ofp_action_output(port = 1)) msg.actions.append(of.ofp_action_output(port = 2))
event.connection.send(msg) event.connection.send(msg)

def launch ():


core.openflow.addListenerByName("ConnectionUp", _handle_ConnectionUp)
core.openflow.addListenerByName("PacketIn", _handle_PacketIn)
core.openflow.addListenerByName("PortStatsReceived",
_handle_portstats_received)

Timer(5, _timer_func, recurring=True)


Run Diamond Topology

Start FlowVisor
Create Slices

Create Flowspaces for upper


Create Flowspaces for lower

Start flowvisor_lab1_upper controller Only s1, s2, and s4 can be seen


Start flowvisor_lab1_lower controller
Only s1, s3, and s4 can be seen
Test Connectivity h1 can ping h3

H2 can ping h4
References
• Installation from Binary,
https://github.com/OPENNETWORKINGLAB/flowvisor/
wiki/Installation-from-Binary

• Flowvisor Exercise,
https://github.com/onstutorial/onstutorial/wiki/Flowvi
sor-Exercise

• POX Wiki,
https://openflow.stanford.edu/display/ONL/POX+Wiki

You might also like