Hi,

> But I have also used --verbose to chek EventOFPErrorMsg
> but I could not get any EventOFPErrorMsg

Hmm,,,
Can you edit app/ofctl/service.py as follows in order to identify the cause of 
the error message?

@@ -174,6 +174,27 @@ class OfctlService(app_manager.RyuApp):
     def _handle_reply(self, ev):
         msg = ev.msg
         datapath = msg.datapath
+        ofp = datapath.ofproto
+        ofproto_parser = datapath.ofproto_parser
+        (version, msg_type, msg_len, xid) = ofproto_parser.header(msg.data)
+        self.logger.debug('EventOFPErrorMsg received.')
+        self.logger.debug(
+            'version=%s, msg_type=%s, msg_len=%s, xid=%s', hex(msg.version),
+            hex(msg.msg_type), hex(msg.msg_len), hex(msg.xid))
+        self.logger.debug(
+            ' `-- msg_type: %s', ofp.ofp_msg_type_to_str(msg.msg_type))
+        self.logger.debug(
+            "OFPErrorMsg(type=%s, code=%s, data=b'%s')", hex(msg.type),
+            hex(msg.code), utils.binary_str(msg.data))
+        self.logger.debug(
+            ' |-- type: %s', ofp.ofp_error_type_to_str(msg.type))
+        self.logger.debug(
+            ' |-- code: %s', ofp.ofp_error_code_to_str(msg.type, msg.code))
+        self.logger.debug(
+            ' `-- data: version=%s, msg_type=%s, msg_len=%s, xid=%s',
+            hex(version), hex(msg_type), hex(msg_len), hex(xid))
+        self.logger.debug(
+            '     `-- msg_type: %s', ofp.ofp_msg_type_to_str(msg_type))
         try:
             si = self._switches[datapath.id]
         except KeyError:

Or, if you want to manage dp instances, there is an other way.
The other way is to use controller/dpset.py.
I attached a sample app file to this mail that is for understanding how to use 
a part of the function of dpset.
(Note: This app is based on the simple_switch_13.py)

thanks,

On 2016年02月25日 23:18, Osman Titu wrote:
> Hi
> 
> Thanks for your reply.
> 
>>from ryu.app.ofctl.api import get_datapath
>>dp = get_datapath(self, datapath.id <http://datapath.id> )
> 
> The thing is that this code is giving me the datapath object from datapath.id 
> <http://datapath.id> but showing the error "unknown error xid"
> 
> To execute my program I am using
> #ryu-manager --observe-links
> 
> But I have also used --verbose to chek EventOFPErrorMsg
> but I could not get any EventOFPErrorMsg
> 
> BR
> Titu
> 
> On Thu, Feb 25, 2016 at 3:03 AM, Minoru TAKAHASHI 
> <[email protected] <mailto:[email protected]>> wrote:
> 
>     Hi,
> 
>     On 2016年02月24日 01:03, Osman Titu wrote:
>     > Hi
>     >
>     > For getting datapath object from datapath.id <http://datapath.id> 
> <http://datapath.id> (which is an integer) I have added this code bellow
>     >
>     > from ryu.app.ofctl.api import get_datapath
>     >
>     > dp = get_datapath(self, datapath.id <http://datapath.id> 
> <http://datapath.id>)
> 
>     Getting the datapath object is successful in my environment.
>     My sample code and the execution result is as follows.
> 
>     <sample code>
> 
>     from ryu.app.ofctl.api import get_datapath
>     ...
>             self.add_flow(datapath, 0, match, actions)
>             print "-----------------------------------------"
>             print "get_datapath(self, datapath.id <http://datapath.id>) start"
>             dp = get_datapath(self, datapath.id <http://datapath.id>)
>             print dp
>             print dp.id <http://dp.id>
>             print "get_datapath(self, datapath.id <http://datapath.id>) end"
>             print "-----------------------------------------"
> 
>     <execution result>
> 
>     $ ryu-manager ./app/sample.py --verbose
>     loading app ./app/sample.py
>     require_app: ryu.app.ofctl.service is required by sample
>     loading app ryu.app.ofctl.service
>     loading app ryu.controller.ofp_handler
>     instantiating app ryu.app.ofctl.service of OfctlService
>     ...snipped...
>     connected socket:<eventlet.greenio.GreenSocket object at 0x7f565cbd6d50> 
> address:('127.0.0.1', 35091)
>     hello ev <ryu.controller.ofp_event.EventOFPHello object at 0x7f565cbea150>
>     move onto config mode
>     EVENT ofp_event->SimpleSwitch13 EventOFPSwitchFeatures
>     EVENT ofp_event->ofctl_service EventOFPSwitchFeatures
>     switch features ev 
> version=0x4,msg_type=0x6,msg_len=0x20,xid=0xe126de9,OFPSwitchFeatures(auxiliary_id=0,capabilities=79,datapath_id=1,n_buffers=256,n_tables=254)
>     -----------------------------------------
>     get_datapath(self, datapath.id <http://datapath.id>) start
>     EVENT SimpleSwitch13->ofctl_service GetDatapathRequest
>     add dpid 1 datapath <ryu.controller.controller.Datapath object at 
> 0x7f565cbd6b10> new_info <ryu.app.ofctl.service._SwitchInfo object at 
> 0x7f565cbea690> old_info None
>     dpid 1 -> datapath <ryu.controller.controller.Datapath object at 
> 0x7f565cbd6b10>
>     <ryu.controller.controller.Datapath object at 0x7f565cbd6b10>
>     1
>     get_datapath(self, datapath.id <http://datapath.id>) end
>     -----------------------------------------
> 
>     >
>     > but I am getting this message "unknown error xid"
> 
>     Maybe, one of the following was executed.
> 
>      https://github.com/osrg/ryu/blob/master/ryu/app/ofctl/service.py#L185
>      or
>      https://github.com/osrg/ryu/blob/master/ryu/app/ofctl/service.py#L194
> 
>     And, the code is described in the handler which is for receive the 
> OFPErrorMsg.
> 
>      https://github.com/osrg/ryu/blob/master/ryu/app/ofctl/service.py#L173
> 
>     There is a possibility that you were receiving some kind of OpenFlow 
> error message.
>     FYI, it may becomes easier to find out the OFPErrorMsg for using 
> --verbose option as follows.
> 
>       # ryu-manager [app_name] --verbose
> 
>     <output example>
> 
>     EventOFPErrorMsg received.
>     version=0x4, msg_type=0x1, msg_len=0x4c, xid=0x55572dbb
>      `-- msg_type: OFPT_ERROR(1)
>     OFPErrorMsg(type=0x6, code=0x1,
>     
> data=b'\x04\x0f\x00\x40\x55\x57\x2d\xbb\x00\x00\x00\x00\x00\x00\x00\x01\x00\x30\x00\x01\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x19\x00\x10\x80\x00\x16\x04\x0a\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x02\xff\xe5\x00\x00\x00\x00\x00\x00')
>      |-- type: OFPET_GROUP_MOD_FAILED(6)
>      |-- code: OFPGMFC_INVALID_GROUP(1)
>      `-- data: version=0x4, msg_type=0xf, msg_len=0x40, xid=0x55572dbb
>          `-- msg_type: OFPT_GROUP_MOD(15)
> 
> 
>     thanks,
> 
>     >
>     > How can I fix it?
>     >
>     > BR
>     > Titu
>     >
>     >
>     >
>     >
>     > 
> ------------------------------------------------------------------------------
>     > Site24x7 APM Insight: Get Deep Visibility into Application Performance
>     > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
>     > Monitor end-to-end web transactions and take corrective actions now
>     > Troubleshoot faster and improve end-user experience. Signup Now!
>     > http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
>     >
>     >
>     >
>     > _______________________________________________
>     > Ryu-devel mailing list
>     > [email protected] <mailto:[email protected]>
>     > 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

from ryu.controller import dpset

class SimpleSwitch13(app_manager.RyuApp):
    OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]

    _CONTEXTS = {
        'dpset': dpset.DPSet
    }

    def __init__(self, *args, **kwargs):
        super(SimpleSwitch13, self).__init__(*args, **kwargs)
        self.mac_to_port = {}
        self.dpset = kwargs['dpset']

    @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)

    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)
        else:
            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):
        # 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']

        print "-------------------------"
        dpid = 1
        dp = self.dpset.get(int(dpid))
        print dp
        print dp.id
        print "-------------------------"

        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)
            # 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)
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to