Dear Everyone,
I wrote a module which add rules to the switch proactively. The problem is
after dispatching the rule, I don't see in my monitor module, that flows
going through the new rule. They still go through the previous simple
rules. Here is my code.
###################################################################
*from ryu.base import app_manager*
*from ryu.controller import ofp_event*
*from ryu.controller.handler import CONFIG_DISPATCHER, MAIN_DISPATCHER*
*from ryu.controller.handler import set_ev_cls*
*from ryu.ofproto import ofproto_v1_3*
*from ryu.lib.packet import packet*
*from ryu.lib.packet import ethernet*
*from ryu.lib.packet import tcp*
*from ryu.lib.packet import ipv4*
*from time import sleep*
*from ryu.lib.ovs import bridge*
*from SimpleXMLRPCServer import SimpleXMLRPCServer*
*from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler*
*import logging*
*import os*
*import subprocess*
*from ryu.lib import hub*
*from ryu.ofproto import ether*
*class SimpleSwitch13(app_manager.RyuApp):*
* OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]*
* def __init__(self, *args, **kwargs):*
* super(SimpleSwitch13, self).__init__(*args, **kwargs)*
* self.mac_to_port = {}*
* self.output_qos = open( "result-qos.txt", "w" );*
* self.rpcServer = SimpleXMLRPCServer( ("131.94.128.248", 8500),
allow_none=True )*
* self.rpcServer.register_function( self._qos_receiver )*
* self.megabyte = 1000000*
* self.ip_address_match_set = {}*
* print 'Use Control-C to exit'*
* self.rcp_thread = hub.spawn(self.rpcServer.serve_forever)*
* def _qos_receiver( self, sourceAddr, sourcePort, destAddr, destPort,
mapId, jobId, reduceId ):*
* #self.output_qos.write( sourceAddr + ", " + sourcePort + ", " +
destAddr + ", " + destPort + ", " + mapId + ", " + jobId + ", " + reduceId
+ "\n" );*
* src_port = int(sourcePort)*
* dst_port = int(destPort)*
* src_ip = sourceAddr*
* dst_ip = destAddr*
* parser = self.datapathCached.ofproto_parser*
* match = parser.OFPMatch(ipv4_src=sourceAddr, ipv4_dst=destAddr,
eth_type=self.ethernetType, ip_proto=self.nwType, tcp_src=src_port,
tcp_dst=dst_port)*
* actions = [parser.OFPActionOutput(4)]*
* self.add_flow( self.datapathCached, 1, match, actions )*
* return 1*
* @set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)*
* def switch_features_handler(self, ev):*
* datapath = ev.msg.datapath*
* ofproto = datapath.ofproto*
* parser = datapath.ofproto_parser*
* self.datapathCached = datapath*
* match = parser.OFPMatch()*
* actions = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER,*
* ofproto.OFPCML_NO_BUFFER)]*
* self.add_flow(datapath, 0, match, actions)*
* def add_flow(self, datapath, priority, match, actions):*
* ofproto = datapath.ofproto*
* parser = datapath.ofproto_parser*
* inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,*
* actions)]*
* mod = parser.OFPFlowMod(datapath=datapath, priority=priority,*
* match=match, instructions=inst)*
* datapath.send_msg(mod)*
* @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)*
* def _packet_in_handler(self, ev):*
* msg = ev.msg*
* datapath = msg.datapath*
* ofproto = datapath.ofproto*
* parser = datapath.ofproto_parser*
* in_port = msg.match['in_port']*
* pkt = packet.Packet(msg.data)*
* eth = pkt.get_protocols(ethernet.ethernet)[0]*
* nw = pkt.get_protocol(ipv4.ipv4)*
* tp = None*
* if nw is not None:*
* tp = pkt.get_protocol(tcp.tcp)*
* if tp is not None:*
* self.ethernetType = eth.ethertype*
* self.nwType = nw.proto*
* self.dpid = datapath.id <http://datapath.id>*
* self.mac_to_port.setdefault(self.dpid, {})*
* self.mac_to_port[self.dpid][eth.src] = in_port*
* if eth.dst in self.mac_to_port[self.dpid]:*
* out_port = self.mac_to_port[self.dpid][eth.dst]*
* else:*
* out_port = ofproto.OFPP_FLOOD*
* actions = [parser.OFPActionOutput(out_port)]*
* #actions.append( parser.OFPActionSetQueue(7) ) *
* # install a flow to avoid packet_in next time*
* if out_port != ofproto.OFPP_FLOOD:*
* #if nw is not None:*
* match = parser.OFPMatch(in_port=in_port, eth_dst=eth.dst)*
* self.add_flow(datapath, 2, match, actions)*
* #out_port = ofproto.OFPP_FLOOD*
* data = None*
* if msg.buffer_id == ofproto.OFP_NO_BUFFER:*
* data = msg.data*
* out = parser.OFPPacketOut(datapath=datapath,
buffer_id=msg.buffer_id,*
* in_port=in_port, actions=actions,
data=data)*
* datapath.send_msg(out)*
#######################################################################
The function qos_receiver is responsible to assign the proactive rules.
Does anybody have an idea why I can't see flows going through the new rule?
Thanks
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel