Best Regards, Ramzah Rehman
---------- Forwarded message --------- From: Ramzah Rehman <ramzahreh...@gmail.com> Date: Thu, Jan 3, 2019 at 7:20 PM Subject: Re: [Ryu-devel] Cannot add Group Entry in OVS Switch To: <ma...@163.com> This is my code: # 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. import datetime from ryu.app.simple_switch_15 import SimpleSwitch15 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_5 from ryu.lib.packet import packet from ryu.lib.packet import ethernet from ryu.lib.packet import ether_types class SimpleSwitch15(app_manager.RyuApp): OFP_VERSIONS = [ofproto_v1_5.OFP_VERSION] def __init__(self, *args, **kwargs): super(SimpleSwitch15, self).__init__(*args, **kwargs) self.mac_to_port = {} print("\n##########__init__") @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() actions = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER, ofproto.OFPCML_NO_BUFFER)] self.add_flow(datapath, 0, match, actions) print("\n##########switch_features_handler") 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) print("\n##########add_flow") @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] if eth.ethertype == ether_types.ETH_TYPE_LLDP: # ignore lldp packet return 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, 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_dst=dst) self.add_flow(datapath, 1, match, actions) data = None if msg.buffer_id == ofproto.OFP_NO_BUFFER: data = msg.data match = parser.OFPMatch(in_port=in_port) out = parser.OFPPacketOut(datapath=datapath, buffer_id=msg.buffer_id, match=match, actions=actions, data=data) datapath.send_msg(out) *self.send_group_mod(datapath)* print("\n##########_packet_in_handler") *def send_group_mod(self, datapath):* ofp = datapath.ofproto ofp_parser = datapath.ofproto_parser port = 1 max_len = 2000 actions = [ofp_parser.OFPActionOutput(port, max_len)] weight = 100 watch_port = 0 watch_group = 0 buckets = [ofp_parser.OFPBucket(weight, watch_port, watch_group, actions)] group_id = 1 command_bucket_id = 1 req = ofp_parser.OFPGroupMod(datapath, ofp.OFPGC_ADD, ofp.OFPGT_SELECT, group_id, command_bucket_id, buckets) datapath.send_msg(req) On Thu, Jan 3, 2019 at 7:16 PM <ma...@163.com> wrote: > Hi, please attach your code,and you can finde this code in ofproto13.py > > 发自我的 iPhone > > 在 2019年1月3日,20:58,Ramzah Rehman <ramzahreh...@gmail.com> 写道: > > eth2* > > Best Regards, > Ramzah Rehman > > > On Thu, Jan 3, 2019 at 5:56 PM Ramzah Rehman <ramzahreh...@gmail.com> > wrote: > >> Hello. I have ovs 2.8.6. I have RYU Controller. I am trying to add a >> Group Entry in my switch via RYU controller. I found send_group_mod >> <https://ryu.readthedocs.io/en/latest/ofproto_v1_5_ref.html> function >> here. I copy pasted the exact code ( I called this function when >> EventOFPPacketIn was triggered i.e. in _packet_in_handler function) to >> check if it's working but got this error: >> >> OFPErrorMsg(type=0x6, code=0xc, >> data=b'\x06\x0f\x00\x20\x4c\x6d\x56\x22\x00\x00\x01\x00\x00\x00\x00\x01\x00\x08\x00\x00\x00\x00\x00\x01\x00\x08\x00\x00\x00\x00\x00\x64') >> |-- type: OFPET_GROUP_MOD_FAILED(6) >> |-- code: OFPGMFC_BAD_BUCKET(12) >> `-- data: version=0x6, msg_type=0xf, msg_len=0x20, xid=0x4c6d5622 >> `-- msg_type: OFPT_GROUP_MOD(15) >> >> Please let me know what I am doing wrong. I have eth0 connected to my >> switch on OpenFlow port 1. >> >> #ovs-vsctl show >> Bridge "br0" >> Controller "tcp:10.0.0.6:6633" >> is_connected: true >> Port "eth2" >> Interface "eth2" >> Port "br0" >> Interface "br0" >> type: internal >> ovs_version: "2.8.6" >> >> >> Best Regards, >> Ramzah Rehman >> > > _______________________________________________ > Ryu-devel mailing list > Ryu-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/ryu-devel > >
_______________________________________________ Ryu-devel mailing list Ryu-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ryu-devel