本文整理汇总了Python中ryu.ofproto.ofproto_parser.msg函数的典型用法代码示例。如果您正苦于以下问题:Python msg函数的具体用法?Python msg怎么用?Python msg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了msg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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)
示例2: 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
示例3: _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)
示例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
示例5: _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)
示例6: 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
示例7: 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
示例8: _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))
示例9: _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)
示例10: _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)
示例11: 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)
示例12: 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))
示例13: 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
示例14: _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)
示例15: 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))