Hi
In the following ryu controller,
I want to use the "dp_datapath[str(1)]" of "_packet_in_handler" in the
"switch_features_handler".
note that both of "_packet_in_handler" and "switch_features_handler" are
different functions. And "dp_datapath[str(1)]" is a variable of
"_packet_in_handler".
would you please do it for me? :)
THanks.
-Tanvir
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
class SimpleSW(app_manager.RyuApp):
OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]
_CONTEXTS = {'WSGI':WSGIApplication}
def __init__(self, *args, **kwargs):
super(SimpleSW, self).__init__(*args, **kwargs)
self.mac_to_port = {} # mac to port table
self.ip_to_mac = {} # ip to mac
self.datapaths = {}
# self.monitor_thread = hub.spawn(self._monitor)
# add the number of monitor
@set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
def switch_features_handler(self, ev):
datapath = ev.msg.datapath
dpid = datapath.id
ofp = datapath.ofproto
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
match = parser.OFPMatch(eth_src='01:00:00:00:01:00',
eth_dst='02:00:00:00:02:00')
actions = [parser.OFPActionOutput(2)]
inst = [parser.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS,actions)]
self.add_flow(datapath=datapath, priority=11, command=ofp.OFPFC_ADD,
match=match, instructions=inst)
def add_flow(self, datapath, priority, command, match, instructions):
ofproto = datapath.ofproto
ofp = datapath.ofproto
parser = datapath.ofproto_parser
flow_add = parser.OFPFlowMod(datapath=datapath, buffer_id=ofp.OFP_NO_BUFFER,
priority=priority, command=command, match=match, instructions=instructions)
datapath.send_msg(flow_add)
# the packet handled by the controller
@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
def _packet_in_handler(self, ev):
msg = ev.msg
datapath = msg.datapath
ofproto = datapath.ofproto
ofp = datapath.ofproto
parser = datapath.ofproto_parser
in_port = msg.match['in_port']
pkt = packet.Packet(msg.data)
eth = pkt.get_protocols(ethernet.ethernet)[0]
dst = eth.dst
src = eth.src
dpid = datapath.id
self.mac_to_port.setdefault(dpid, {})
self.mac_to_port[dpid][src] = in_port
datapath_dp = {}
dp_datapath = {}
dp_datapath.update({str(dpid):str(datapath).split(" ")[-1].split(">")[0]})
datapath_dp.update({str(datapath).split(" ")[-1].split(">")[0]:str(dpid)})
# self.logger.info("packet in %s %s %s %s", dpid, src, dst, in_port)
dp_datapath[str(1)]
?
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel