• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python ofproto_parser.header函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中ryu.ofproto.ofproto_parser.header函数的典型用法代码示例。如果您正苦于以下问题:Python header函数的具体用法?Python header怎么用?Python header使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了header函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _test_msg

    def _test_msg(self, name, wire_msg, json_str):
        json_dict = json.loads(json_str)
        # on-wire -> OFPxxx -> json
        (version, msg_type, msg_len, xid) = ofproto_parser.header(wire_msg)
        try:
            has_parser, has_serializer = implemented[version][msg_type]
        except KeyError:
            has_parser = True
            has_serializer = True

        dp = DummyDatapath(*self._ofp_versions[version])
        if has_parser:
            msg = ofproto_parser.msg(dp, version, msg_type, msg_len, xid,
                                     wire_msg)
            json_dict2 = self._msg_to_jsondict(msg)
            # XXXdebug code
            open(('/tmp/%s.json' % name), 'wb').write(json.dumps(json_dict2))
            eq_(json_dict, json_dict2)

        # json -> OFPxxx -> json
        msg2 = self._jsondict_to_msg(dp, json_dict)
        if has_serializer:
            msg2.serialize()
            eq_(self._msg_to_jsondict(msg2), json_dict)
            eq_(wire_msg, msg2.buf)
开发者ID:rnudechu,项目名称:ryu,代码行数:25,代码来源:test_parser.py


示例2: _on_header

 def _on_header(self, data):
     assert len(data) == ofproto_common.OFP_HEADER_SIZE
     self._msg_header = data
     (version, msg_type, msg_len, xid) = ofproto_parser.header(data)
     assert msg_len >= ofproto_common.OFP_HEADER_SIZE
     if not self.stream.closed():
         self.stream.read_bytes(msg_len-ofproto_common.OFP_HEADER_SIZE, stack_context.wrap(self._on_message))
开发者ID:hkwi,项目名称:hkwi_seeds,代码行数:7,代码来源:ryu_tornado.py


示例3: SBP_handler

    def SBP_handler(self, ev):
        # Parser the msg and raise an event.
        # Handle event in service or app.
        msg = ev.msg
        domain = msg.domain
        data = msg.data

        if domain.sbp_proto_type == oxproto_v1_0.OXPS_OPENFLOW:
            buf = bytearray()
            required_len = ofproto_common.OFP_HEADER_SIZE

            if len(data) == 0:
                return
            buf += data
            while len(buf) >= required_len:
                (version, msg_type, msg_len, xid) = ofproto_parser.header(buf)
                self.logger.debug('ofp msg %s cls %s', msg, msg.__class__)
                required_len = msg_len
                if len(buf) < required_len:
                    break

                msg = ofproto_parser.msg(self.fake_datapath,
                                         version, msg_type, msg_len, xid, buf)
                if msg:
                    ev = oxp_event.sbp_to_oxp_msg_to_ev(msg)
                    ev.domain = domain
                    self.send_event_to_observers(ev, MAIN_DISPATCHER)

                buf = buf[required_len:]
                required_len = ofproto_common.OFP_HEADER_SIZE
开发者ID:Jasonlyt,项目名称:ryu,代码行数:30,代码来源:oxp_server_handler.py


示例4: blocking_read_sdn_message

    def blocking_read_sdn_message(self,block_read_written=False):
        '''
        @returns an SDN message
        '''
        reader_method = self._sdn_socket.blocking_read
        if block_read_written:
            reader_method = self._sdn_socket.blocking_read_written
        
        # first read openflow header
        msg_buffer = reader_method(OFP_HEADER_SIZE)
        while len(msg_buffer) != OFP_HEADER_SIZE:
            diff = OFP_HEADER_SIZE - len(msg_buffer)
            msg_buffer.extend(reader_method(diff))

        # based on size of openflow header, decide how much more to
        # read
        (version, msg_type, msg_len, xid) = ofproto_parser.header(msg_buffer)

        while len(msg_buffer) != msg_len:
            diff = msg_len - len(msg_buffer)
            msg_buffer.extend(reader_method(diff))
        
        msg = ofproto_parser.msg(
            _OF_1_0_DATAPATH, version, msg_type, msg_len,
            xid, str(msg_buffer))

        msg.original_buffer = msg_buffer
        return msg
开发者ID:bmistree,项目名称:sdn_fuzz,代码行数:28,代码来源:sdn_message_reader.py


示例5: error_msg_handler

 def error_msg_handler(self, ev):
     msg = ev.msg
     ofp = msg.datapath.ofproto
     self.logger.debug(
         "EventOFPErrorMsg received.\n"
         "version=%s, msg_type=%s, msg_len=%s, xid=%s\n"
         " `-- msg_type: %s\n"
         "OFPErrorMsg(type=%s, code=%s, data=b'%s')\n"
         " |-- type: %s\n"
         " |-- code: %s",
         hex(msg.version), hex(msg.msg_type), hex(msg.msg_len),
         hex(msg.xid), ofp.ofp_msg_type_to_str(msg.msg_type),
         hex(msg.type), hex(msg.code), utils.binary_str(msg.data),
         ofp.ofp_error_type_to_str(msg.type),
         ofp.ofp_error_code_to_str(msg.type, msg.code))
     if len(msg.data) >= ofp.OFP_HEADER_SIZE:
         (version, msg_type, msg_len, xid) = ofproto_parser.header(msg.data)
         self.logger.debug(
             " `-- data: version=%s, msg_type=%s, msg_len=%s, xid=%s\n"
             "     `-- msg_type: %s",
             hex(version), hex(msg_type), hex(msg_len), hex(xid),
             ofp.ofp_msg_type_to_str(msg_type))
     else:
         self.logger.warning(
             "The data field sent from the switch is too short: "
             "len(msg.data) < OFP_HEADER_SIZE\n"
             "The OpenFlow Spec says that the data field should contain "
             "at least 64 bytes of the failed request.\n"
             "Please check the settings or implementation of your switch.")
开发者ID:Aries-Sushi,项目名称:ryu,代码行数:29,代码来源:ofp_handler.py


示例6: handle

 def handle(self):
     desc = ofproto_protocol.ProtocolDesc()
     residue = b''
     while True:
         if residue:
             data = residue
             residue = b''
         else:
             data = self.request.recv(1024)
             if data == b'':
                 break
         if self.verbose:
             print(data)
         h = ofproto_parser.header(data)
         if self.verbose:
             print(h)
         version, msg_type, msg_len, xid = h
         residue = data[msg_len:]
         desc.set_version(version=version)
         if msg_type == desc.ofproto.OFPT_HELLO:
             hello = desc.ofproto_parser.OFPHello(desc)
             hello.serialize()
             self.request.send(hello.buf)
         elif msg_type == desc.ofproto.OFPT_FLOW_MOD:
             buf.append(data[:msg_len])
         elif msg_type == desc.ofproto.OFPT_BARRIER_REQUEST:
             brep = desc.ofproto_parser.OFPBarrierReply(desc)
             brep.xid = xid
             brep.serialize()
             self.request.send(brep.buf)
             break
开发者ID:John-Lin,项目名称:ryu,代码行数:31,代码来源:gen.py


示例7: _recv_loop

    def _recv_loop(self):
        buf = bytearray()
        required_len = ofproto_common.OFP_HEADER_SIZE

        count = 0
        while self.is_active:
            ret = self.socket.recv(required_len)
            if len(ret) == 0:
                self.is_active = False
                break
            buf += ret
            while len(buf) >= required_len:
                (version, msg_type, msg_len, xid) = ofproto_parser.header(buf)
                required_len = msg_len
                if len(buf) < required_len:
                    break

                msg = ofproto_parser.msg(self,
                                         version, msg_type, msg_len, xid, buf)
                # LOG.debug('queue msg %s cls %s', msg, msg.__class__)
                if msg:
                    self.principal_connection.receive_principal_message(msg)

                buf = buf[required_len:]
                required_len = ofproto_common.OFP_HEADER_SIZE

                # We need to schedule other greenlets. Otherwise, ryu
                # can't accept new switches or handle the existing
                # switches. The limit is arbitrary. We need the better
                # approach in the future.
                count += 1
                if count > 2048:
                    count = 0
                    hub.sleep(0)
开发者ID:bmistree,项目名称:pluribus,代码行数:34,代码来源:principal_datapath.py


示例8: handle_event

    def handle_event(self, header, msg):
        #required_len = self.ofp.OFP_HEADER_SIZE
        ret = bytearray(msg)
        (version, msg_type, msg_len, xid) = ofproto_parser.header(ret)
        self.netide_xid = header[NetIDEOps.NetIDE_header['XID']]
        msg = ofproto_parser.msg(self, version, msg_type, msg_len, xid, ret)

        if msg:
            ev = ofp_event.ofp_msg_to_ev(msg)
            event_observers = self.ofp_brick.get_observers(ev,self.state)
            module_id = header[NetIDEOps.NetIDE_header['MOD_ID']]
            for key, value in self.channel.running_modules.iteritems():
                if value == module_id and key in event_observers:
                    module_brick = ryu.base.app_manager.lookup_service_brick(key)
                    module_brick_handlers = module_brick.get_handlers(ev)
                    for handler in module_brick_handlers:
                        handler(ev)
                    break

            # Sending the FENCE message to the Core only if self.netide_xid is not 0
            if self.netide_xid is not 0:
                msg_to_send = NetIDEOps.netIDE_encode('NETIDE_FENCE', self.netide_xid, module_id, 0, "")
                self.channel.socket.send(msg_to_send)

            dispatchers = lambda x: x.callers[ev.__class__].dispatchers
            handlers = [handler for handler in
                        self.ofp_brick.get_handlers(ev) if
                        self.state in dispatchers(handler)]

            for handler in handlers:
                handler(ev)

            # Resetting netide_xid to zero
            self.netide_xid = 0
开发者ID:fp7-netide,项目名称:Engine,代码行数:34,代码来源:ryu-backend.py


示例9: SBP_handler

    def SBP_handler(self, ev):
        # parser the msg and handle the SBP message.
        # raise the event.
        # finish it in service or app.
        msg = ev.msg
        domain = msg.domain
        data = msg.data

        if CONF.sbp_proto_type == oxproto_v1_0.OXPS_OPENFLOW:
            buf = bytearray()
            required_len = ofproto_common.OFP_HEADER_SIZE

            if len(data) == 0:
                return
            buf += data
            while len(buf) >= required_len:
                (version, msg_type, msg_len, xid) = ofproto_parser.header(buf)

                required_len = msg_len
                if len(buf) < required_len:
                    break

                msg = ofproto_parser.msg(self.network_aware.fake_datapath,
                                         version, msg_type, msg_len, xid, buf)
                if msg:
                    ev = oxp_event.sbp_to_oxp_msg_to_ev(msg)
                    ev.domain = domain
                    self.send_event_to_observers(ev, MAIN_DISPATCHER)

                buf = buf[required_len:]
                required_len = ofproto_common.OFP_HEADER_SIZE
开发者ID:Jasonlyt,项目名称:ryu,代码行数:31,代码来源:oxp_client_handler.py


示例10: _on_message

 def _on_message(self, data):
     (version, msg_type, msg_len, xid) = ofproto_parser.header(self._msg_header)
     assert len(data) == msg_len - ofproto_common.OFP_HEADER_SIZE
     msg = ofproto_parser.msg(self, version, msg_type, msg_len, xid, self._msg_header+data)
     logging.getLogger("openflow").debug("RECV %s %s" % (self.address, msg))
     self.dispatch(msg)
     if not self.stream.closed():
         self.stream.read_bytes(ofproto_common.OFP_HEADER_SIZE, stack_context.wrap(self._on_header))
开发者ID:hkwi,项目名称:hkwi_seeds,代码行数:8,代码来源:ryu_tornado.py


示例11: testHello

 def testHello(self):
     (version,
      msg_type,
      msg_len,
      xid) = ofproto_parser.header(self.bufHello)
     eq_(version, 1)
     eq_(msg_type, 0)
     eq_(msg_len, 8)
     eq_(xid, 1)
开发者ID:09beeihaq,项目名称:Coursera-SDN-Assignments,代码行数:9,代码来源:test_ofproto_parser.py


示例12: _recv_loop

    def _recv_loop(self):
        buf = bytearray()
        required_len = ofproto_common.OFP_HEADER_SIZE

        count = 0
        while self.state != DEAD_DISPATCHER:
            ret = ""

            try:
                ret = self.socket.recv(required_len)
            except SocketTimeout:
                continue
            except ssl.SSLError:
                # eventlet throws SSLError (which is a subclass of IOError)
                # on SSL socket read timeout; re-try the loop in this case.
                continue
            except (EOFError, IOError):
                break

            if len(ret) == 0:
                break

            buf += ret
            while len(buf) >= required_len:
                (version, msg_type, msg_len, xid) = ofproto_parser.header(buf)
                required_len = msg_len
                if len(buf) < required_len:
                    break

                msg = ofproto_parser.msg(
                    self, version, msg_type, msg_len, xid, buf[:msg_len])
                # LOG.debug('queue msg %s cls %s', msg, msg.__class__)
                if msg:
                    ev = ofp_event.ofp_msg_to_ev(msg)
                    self.ofp_brick.send_event_to_observers(ev, self.state)

                    dispatchers = lambda x: x.callers[ev.__class__].dispatchers
                    handlers = [handler for handler in
                                self.ofp_brick.get_handlers(ev) if
                                self.state in dispatchers(handler)]
                    for handler in handlers:
                        handler(ev)

                buf = buf[required_len:]
                required_len = ofproto_common.OFP_HEADER_SIZE

                # We need to schedule other greenlets. Otherwise, ryu
                # can't accept new switches or handle the existing
                # switches. The limit is arbitrary. We need the better
                # approach in the future.
                count += 1
                if count > 2048:
                    count = 0
                    hub.sleep(0)
开发者ID:KooDongSoo,项目名称:ryu,代码行数:54,代码来源:controller.py


示例13: _recv_loop

    def _recv_loop(self):
        buf = bytearray()
        required_len = ofproto_common.OFP_HEADER_SIZE

        count = 0
        while True:
            ret = ""

            try:
                ret = self.socket.recv(required_len)
            except:
                # Hit socket timeout; decide what to do.
                if self.close_requested:
                    pass
                else:
                    continue

            if (len(ret) == 0) or (self.close_requested):
                self.socket.close()
                break

            buf += ret
            while len(buf) >= required_len:
                (version, msg_type, msg_len, xid) = ofproto_parser.header(buf)
                required_len = msg_len
                if len(buf) < required_len:
                    break

                msg = ofproto_parser.msg(
                    self, version, msg_type, msg_len, xid, buf[:msg_len])
                # LOG.debug('queue msg %s cls %s', msg, msg.__class__)
                if msg:
                    ev = ofp_event.ofp_msg_to_ev(msg)
                    self.ofp_brick.send_event_to_observers(ev, self.state)

                    dispatchers = lambda x: x.callers[ev.__class__].dispatchers
                    handlers = [handler for handler in
                                self.ofp_brick.get_handlers(ev) if
                                self.state in dispatchers(handler)]
                    for handler in handlers:
                        handler(ev)

                buf = buf[required_len:]
                required_len = ofproto_common.OFP_HEADER_SIZE

                # We need to schedule other greenlets. Otherwise, ryu
                # can't accept new switches or handle the existing
                # switches. The limit is arbitrary. We need the better
                # approach in the future.
                count += 1
                if count > 2048:
                    count = 0
                    hub.sleep(0)
开发者ID:alexgpg,项目名称:ryu,代码行数:53,代码来源:controller.py


示例14: test_check_msg_parser

    def test_check_msg_parser(self):
        (version,
         msg_type,
         msg_len,
         xid) = ofproto_parser.header(self.bufPacketIn)

        version = 0xff
        ofproto_parser.msg(self,
                           version,
                           msg_type,
                           msg_len,
                           xid,
                           self.bufPacketIn)
开发者ID:09beeihaq,项目名称:Coursera-SDN-Assignments,代码行数:13,代码来源:test_ofproto_parser.py


示例15: error_msg_handler

 def error_msg_handler(self, ev):
     err_msg = ev.msg
     #self.logger.info('OFPErrorMsg received: type=0x%02x code=0x%02x message=%s', msg.type, msg.code, utils.hex_array(msg.data))
     if err_msg.type == ofproto_v1_3.OFPET_FLOW_MOD_FAILED and err_msg.code == ofproto_v1_3.OFPFMFC_TABLE_FULL:
         print 'caputred full table error message'
         self.rand_remove(err_msg.datapath)
         #parser = err_msg.datapath.ofproto_parser
         (version,msg_type,msg_len,xid)= ofproto_parser.header(err_msg.data)
         print 'version %s, msg_type %s, msg_len %s, xid %s, len %s' % (version, msg_type, msg_len, xid, len(err_msg.data))
         msg = ofproto_parser.msg(err_msg.datapath, version,msg_type,msg_len,xid,err_msg.data)
         #controller will assign a new xid
         msg.xid=None
         error_msg.datapath.send_msg(msg)
开发者ID:JunanDang,项目名称:CAB_SDN_HELPER,代码行数:13,代码来源:table_overflow.py


示例16: recv_ofp

    def recv_ofp(self):
        logging.debug("%s", binascii.hexlify(self.data))

        self.recv(ofproto_common.OFP_HEADER_SIZE)
        version, msg_type, msg_len, xid = ofproto_parser.header(self.data)

        self.recv(msg_len)

        msg = ofproto_parser.msg(self,
                                 version, msg_type, msg_len, xid, self.data[:msg_len])

        self.data = self.data[msg_len:]

        return msg
开发者ID:1514louluo,项目名称:lagopus,代码行数:14,代码来源:ofp_datapath.py


示例17: testPacketIn

    def testPacketIn(self):
        (version,
         msg_type,
         msg_len,
         xid) = ofproto_parser.header(self.bufPacketIn)

        msg = ofproto_parser.msg(self,
                                 version,
                                 msg_type,
                                 msg_len,
                                 xid,
                                 self.bufPacketIn)
        LOG.debug(msg)
        ok_(isinstance(msg, ofproto_v1_0_parser.OFPPacketIn))
开发者ID:09beeihaq,项目名称:Coursera-SDN-Assignments,代码行数:14,代码来源:test_ofproto_parser.py


示例18: _test_msg

    def _test_msg(self, name, wire_msg, json_str):
        json_dict = json.loads(json_str)
        # on-wire -> OFPxxx -> json
        (version, msg_type, msg_len, xid) = ofproto_parser.header(wire_msg)
        try:
            has_parser, has_serializer = implemented[version][msg_type]
        except KeyError:
            has_parser = True
            has_serializer = True

        dp = DummyDatapath(*self._ofp_versions[version])
        if has_parser:
            msg = ofproto_parser.msg(dp, version, msg_type, msg_len, xid,
                                     wire_msg)
            json_dict2 = self._msg_to_jsondict(msg)
            # XXXdebug code
            open(('/tmp/%s.json' % name), 'wb').write(json.dumps(json_dict2))
            eq_(json_dict, json_dict2)

        # json -> OFPxxx -> json
        msg2 = self._jsondict_to_msg(dp, json_dict)
        if has_serializer:
            msg2.serialize()
            eq_(self._msg_to_jsondict(msg2), json_dict)
            eq_(wire_msg, msg2.buf)

            # check if "len" "length" fields can be omitted

            def _remove(d, names):
                f = lambda x: _remove(x, names)
                if isinstance(d, list):
                    return map(f, d)
                if isinstance(d, dict):
                    d2 = {}
                    for k, v in d.iteritems():
                        if k in names:
                            continue
                        d2[k] = f(v)
                    return d2
                return d

            json_dict3 = _remove(json_dict, ['len', 'length'])
            msg3 = self._jsondict_to_msg(dp, json_dict3)
            msg3.serialize()
            eq_(wire_msg, msg3.buf)

            msg2.serialize()
            eq_(wire_msg, msg2.buf)
开发者ID:aryantaheri,项目名称:ryu,代码行数:48,代码来源:test_parser.py


示例19: testFeaturesReply

    def testFeaturesReply(self):
        (version,
         msg_type,
         msg_len,
         xid) = ofproto_parser.header(self.bufFeaturesReply)

        msg = ofproto_parser.msg(self,
                                 version,
                                 msg_type,
                                 msg_len,
                                 xid,
                                 self.bufFeaturesReply)
        LOG.debug(msg)

        ok_(isinstance(msg, ofproto_v1_0_parser.OFPSwitchFeatures))
        LOG.debug(msg.ports[65534])
        ok_(isinstance(msg.ports[1], ofproto_v1_0_parser.OFPPhyPort))
        ok_(isinstance(msg.ports[2], ofproto_v1_0_parser.OFPPhyPort))
        ok_(isinstance(msg.ports[65534], ofproto_v1_0_parser.OFPPhyPort))
开发者ID:09beeihaq,项目名称:Coursera-SDN-Assignments,代码行数:19,代码来源:test_ofproto_parser.py


示例20: handle_event

    def handle_event(self, header, msg, of_proto):
        #required_len = self.ofp.OFP_HEADER_SIZE
        ret = bytearray(msg)
        (version, msg_type, msg_len, xid) = ofproto_parser.header(ret)
        self.netide_xid = header[NetIDEOps.NetIDE_header['XID']]
        msg = ofproto_parser.msg(self, version, msg_type, msg_len, xid, ret)

        if msg:
            ev = ofp_event.ofp_msg_to_ev(msg)
            event_observers = self.ofp_brick.get_observers(ev,self.state)
            module_id = header[NetIDEOps.NetIDE_header['MOD_ID']]
            for key, value in self.channel.running_modules.iteritems():
                if value == module_id and key in event_observers:
                    module_brick = ryu.base.app_manager.lookup_service_brick(key)
                    module_brick_handlers = module_brick.get_handlers(ev)
                    for handler in module_brick_handlers:
                        handler(ev)
                    break

            # Sending the FENCE message to the Core only if self.netide_xid is not 0
            if self.netide_xid is not 0:
                msg_to_send = NetIDEOps.netIDE_encode('NETIDE_FENCE', self.netide_xid, module_id, 0, "")
                self.channel.socket.send(msg_to_send)

            dispatchers = lambda x: x.callers[ev.__class__].dispatchers
            handlers = [handler for handler in
                        self.ofp_brick.get_handlers(ev) if
                        self.state in dispatchers(handler)]

            for handler in handlers:
                # we record that we received a feature reply from that specific device
                if msg_type == of_proto.OFPT_FEATURES_REPLY:
                    self.datapath_init[msg.datapath.id] = True

                # we do not allow multipart messages until the feature_reply has been received (needed for OF1.3 or higher)
                if of_proto.OFP_VERSION >= 0x04:
                    if msg_type == of_proto.OFPT_MULTIPART_REPLY and msg.datapath.id not in self.datapath_init:
                        break

                handler(ev)

            # Resetting netide_xid to zero
            self.netide_xid = 0
开发者ID:fp7-netide,项目名称:Engine,代码行数:43,代码来源:ryu-backend.py



注:本文中的ryu.ofproto.ofproto_parser.header函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ofproto_parser.msg函数代码示例发布时间:2022-05-27
下一篇:
Python slow.lacp函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap