I have modified simple switch application as given below.
import logging
import struct
from ryu.base import app_manager
from ryu.controller import mac_to_port
from ryu.controller import ofp_event
from ryu.controller.handler import MAIN_DISPATCHER
from ryu.controller.handler import CONFIG_DISPATCHER
from ryu.controller.handler import set_ev_cls
from ryu.ofproto import ofproto_v1_0
from ryu.lib.mac import haddr_to_bin
from ryu.lib.packet import packet
from ryu.lib.packet import ethernet
from ryu.lib.dpid import dpid_to_str, str_to_dpid
from bulbs.titan import Graph
import ryu.topology.api
class _SwitchInfo(object):
def __init__(self, datapath):
self.datapath = datapath
self.xids = {}
self.barriers = {}
self.results = {}
class SimpleSwitch(app_manager.RyuApp):
OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION]
def __init__(self, *args, **kwargs):
super(SimpleSwitch, self).__init__(*args, **kwargs)
self.mac_to_port = {}
self.do_once = 0
self.switches =
{'state':'active','dpid':'00:00:00:00:00:00','type':'switch'}
self.g = Graph()
def add_flow(self, datapath, in_port, dst, actions):
ofproto = datapath.ofproto
match = datapath.ofproto_parser.OFPMatch(
in_port=in_port, dl_dst=haddr_to_bin(dst))
mod = datapath.ofproto_parser.OFPFlowMod(
datapath=datapath, match=match, cookie=0,
command=ofproto.OFPFC_ADD, idle_timeout=0, hard_timeout=0,
priority=ofproto.OFP_DEFAULT_PRIORITY,
flags=ofproto.OFPFF_SEND_FLOW_REM, actions=actions)
datapath.send_msg(mod)
def store_to_backend(self):
*sw_list = ryu.topology.api.get_all_switch(self)*
for index,switch in enumerate(sw_list):
print('switch {}'.format(index))
dpid_str = dpid_to_str(switch.dp.id)
dpid_str = ':'.join([dpid_str[i:i + 2] for i in range(0,
len(dpid_str), 2)])
self.logger.info('%s',dpid_str)
self.switches = {'state':'active','dpid':dpid_str,'type':'switch'}
switch =
self.g.vertices.create(type='switch',state='active',dpid=dpid_str)
def create_switch_vertex(self,dpid_str):
pass
@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
def _packet_in_handler(self, ev):
if self.do_once == 0:
self.store_to_backend()
self.do_once = 1
msg = ev.msg
datapath = msg.datapath
ofproto = datapath.ofproto
pkt = packet.Packet(msg.data)
eth = pkt.get_protocol(ethernet.ethernet)
dst = eth.dst
src = eth.src
dpid = datapath.id
self.mac_to_port.setdefault(dpid, {})
#self.logger.info("packet in %s %s %s %s", dpid, src, dst,
msg.in_port)
# learn a mac address to avoid FLOOD next time.
self.mac_to_port[dpid][src] = msg.in_port
if dst in self.mac_to_port[dpid]:
out_port = self.mac_to_port[dpid][dst]
else:
out_port = ofproto.OFPP_FLOOD
actions = [datapath.ofproto_parser.OFPActionOutput(out_port)]
# install a flow to avoid packet_in next time
if out_port != ofproto.OFPP_FLOOD:
self.add_flow(datapath, msg.in_port, dst, actions)
out = datapath.ofproto_parser.OFPPacketOut(
datapath=datapath, buffer_id=msg.buffer_id, in_port=msg.in_port,
actions=actions)
datapath.send_msg(out)
@set_ev_cls(ofp_event.EventOFPPortStatus, MAIN_DISPATCHER)
def _port_status_handler(self, ev):
msg = ev.msg
reason = msg.reason
port_no = msg.desc.port_no
ofproto = msg.datapath.ofproto
if reason == ofproto.OFPPR_ADD:
#self.logger.info("port added %s", port_no)
pass
elif reason == ofproto.OFPPR_DELETE:
#self.logger.info("port deleted %s", port_no)
pass
elif reason == ofproto.OFPPR_MODIFY:
#self.logger.info("port modified %s", port_no)
pass
else:
#self.logger.info("Illeagal port state %s %s", port_no, reason)
pass
My questions are the following.
1) The line *sw_list = ryu.topology.api.get_all_switch(self) inside
store_to_backend() function **doesn't seem to return all the switches.*
*The output of *print('switch {}'.format(index)) AND self.logger.info
('%s',dpid_str)
*that I get on the screen is the following*
*switch 000:00:00:00:00:00:02:01 switch 100:00:00:00:00:00:02:02switch
200:00:00:00:00:00:02:03 switch 300:00:00:00:00:00:02:04My topology is a
very simple mininet topology represented below. host1 ---
(eth1)switch1(eth2) --- (eth2)switch4(eth1) --- host4 host2 ---
(eth1)switch2(eth2) --- (eth2)switch5(eth1) --- host5 host3 ---
(eth1)switch3(eth2) --- (eth2)switch6(eth1) --- host6 Any thoughts on why
this is happening? Is there a time after which
'ryu.topology.api.get_all_switch()' return proper values? Thanks & Regards,
Karthik. *
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel