Hi, I just tried to modify the code simple_switch_13.py in app folder of ryu.
When packet in happens, I tried to modify the eth_src of the packet coming from port 1 with the value "02:a3:33:b2:2d:21". It is working for me. Please, find attached the code and screen shot of Ryu output. [image: Inline images 1] Thanks Gandhimathi On 14 August 2015 at 17:47, A Sydney <asydney...@gmail.com> wrote: > Oops.. Looks like I inadvertently dropped ryu-devel from the thread.. > > So below was correspondence between Gandhimathi and I (Ali). Feel free to > provide feedback... > > > ### Gandhimathi ### > > Have you tried with set_field()? > page 167 from https://media.readthedocs.org/pdf/ryu/latest/ryu.pdf > > > > ### Ali ### > > I've tried the following which works fine: > > match = parser.OFPMatch(eth_dst="02:a3:33:b2:2d:21") > > However, for my particular test case, I've got match conditions stored in > a config file and when a switch starts up, I read the config file and > install flows in the switch. Now my config file has things like: > > inport = 1 > eth_src = "None" > eth_dst = "02:a3:33:b2:2d:21" > > And in my ryu application, I do something like (pseudo code): > > match = parser.OFPMatch() > > if inport != "None": > match.append_field(ofproto.OXM_OF_IN_PORT, inport) > > if eth_src != "None": > match.append_field(ofproto.OXM_OF_ETH_SRC, eth_src) > > if eth_dst != "None": > match.append_field(ofproto.OXM_OF_ETH_SRC, eth_dst) > > print "match:", match > > match: 1, 02:a3:33:b2:2d:21 > > So if I don't have a value for a match condition (such as eth_src), I > insert "None" in the config file. Then when I create my match, if "None" > shows up for this parameter (like for eth_src), I don't add it to the match > condition. The the point here is that I append fields (inport, eth_src etc) > to the match condition iteratively. Hence, I can't use the form"match = > parser.OFPMatch(eth_dst="02:a3:33:b2:2d:21"" > > ### Gandhimathi ### > > I understand what you are trying to do. May be the syntax you are using > with match. append_field() is not correct? could you please, refer here: > https://github.com/FlowForwarding/LINC-Switch/commit/4c9aa3ad5ad1250f8357e04a65773b409fbe4b4c. > They used pointer data type to pass in append_field() method. > > > > ### Ali ### > > Per your suggest, below is what I attempted: > > match = parser.OFPMatch() > > test=[(ofproto.OXM_OF_IN_PORT,4),(ofproto.OXM_OF_ETH_SRC,"02:a3:33:b2:2d:21")] > for a in test: > match.append_field(*a) > print "matching:", match > > matching: OFPMatch(oxm_fields={'eth_src': '30:32:3a:61:33:3a', 'in_port': > 4}) > > As shown, the mac address still has the same weird format as before > > I also tried the following: > > match = parser.OFPMatch() > match.set_in_port(4) > match.set_dl_src("02:a3:33:b2:2d:21") > print "matching:", match > > matching: OFPMatch(oxm_fields={}) > > But as shown, the output is empty > > REF: > https://github.com/osrg/ryu/blob/master/ryu/app/rest_router.py#L1722 > > On Fri, Aug 14, 2015 at 2:13 PM, A Sydney <asydney...@gmail.com> wrote: > >> Any feedback? >> >> On Wed, Aug 12, 2015 at 5:29 PM, A Sydney <asydney...@gmail.com> wrote: >> >>> Hi Ryu folks, >>> This may be a trivial question... >>> >>> I'm using ryu 3.23.2 on CentOS 6.6 (OF 1.3). As shown below, when I >>> insert a mac address (02:a3:33:b2:2d:21), "appends_fields" seem to do >>> something smart that results in "30:32:3a:61:33:3a" in "match" (as opposed >>> to "02:a3:33:b2:2d:21"). >>> >>> # Ryu app >>> match = parser.OFPMatch() >>> match.append_field(ofproto.OXM_OF_ETH_SRC, "02:a3:33:b2:2d:21") >>> print match >>> >>> # Output >>> OFPMatch(oxm_fields={'eth_src': '30:32:3a:61:33:3a'}) >>> >>> How do I get the original mac address (02:a3:33:b2:2d:21) inserted in >>> "match"? >>> >>> Thanks, >>> Ali >>> >> >> > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Ryu-devel mailing list > Ryu-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/ryu-devel > >
# Copyright (C) 2011 Nippon Telegraph and Telephone Corporation. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # implied. # See the License for the specific language governing permissions and # limitations under the License. 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 ether_types 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 = {} @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 # install table-miss flow entry # # We specify NO BUFFER to max_len of the output action due to # OVS bug. At this moment, if we specify a lesser number, e.g., # 128, OVS will send Packet-In with invalid buffer_id and # truncated packet data. In that case, we cannot output packets # correctly. The bug has been fixed in OVS v2.1.0. match = parser.OFPMatch() print "matching:", match 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, buffer_id=None): ofproto = datapath.ofproto parser = datapath.ofproto_parser inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS, actions)] if buffer_id: mod = parser.OFPFlowMod(datapath=datapath, buffer_id=buffer_id, priority=priority, match=match, instructions=inst) print match else: mod = parser.OFPFlowMod(datapath=datapath, priority=priority, match=match, instructions=inst) #print match datapath.send_msg(mod) @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER) def _packet_in_handler(self, ev): # If you hit this you might want to increase # the "miss_send_length" of your switch if ev.msg.msg_len < ev.msg.total_len: self.logger.debug("packet truncated: only %s of %s bytes", ev.msg.msg_len, ev.msg.total_len) 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] if eth.ethertype == ether_types.ETH_TYPE_LLDP: # ignore lldp packet return dst = eth.dst if in_port == 1: src ="02:a3:33:b2:2d:21" else: src = eth.src dpid = datapath.id self.mac_to_port.setdefault(dpid, {}) self.logger.info("packet in %s %s %s %s", dpid, src, dst, in_port) # learn a mac address to avoid FLOOD next time. self.mac_to_port[dpid][src] = 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 = [parser.OFPActionOutput(out_port)] # install a flow to avoid packet_in next time if out_port != ofproto.OFPP_FLOOD: match = parser.OFPMatch(in_port=in_port, eth_src=src,eth_dst=dst) # verify if we have a valid buffer_id, if yes avoid to send both # flow_mod & packet_out if msg.buffer_id != ofproto.OFP_NO_BUFFER: self.add_flow(datapath, 1, match, actions, msg.buffer_id) return else: self.add_flow(datapath, 1, match, actions) 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)
------------------------------------------------------------------------------
_______________________________________________ Ryu-devel mailing list Ryu-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ryu-devel