本文整理汇总了Python中ryu.utils.hex_array函数的典型用法代码示例。如果您正苦于以下问题:Python hex_array函数的具体用法?Python hex_array怎么用?Python hex_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hex_array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: error_msg_handler
def error_msg_handler(self, ev):
"""
A switch has sent us an error event
"""
msg = ev.msg
datapath = msg.datapath
dpid = datapath.id
if msg.type == 0x03 and msg.code == 0x00:
self.logger.error('event=OFPErrorMsg_received: dpid=%s '
'type=Flow_Table_Full(0x03) code=0x%02x message=%s',
dpid, msg.code, utils.hex_array(msg.data))
else:
self.logger.error('event=OFPErrorMsg_received: dpid=%s '
'type=0x%02x code=0x%02x message=%s',
dpid, msg.type, msg.code, utils.hex_array(msg.data))
示例2: error_msg_handler
def error_msg_handler(self, ev):
msg = ev.msg
print "OFPErrorMsg received: type=0x%02x code=0x%02x 'message=%s'" % (
msg.type,
msg.code,
utils.hex_array(msg.data),
)
示例3: packet_in_handler
def packet_in_handler(self, ev):
msg = ev.msg
dp = msg.datapath
ofp = dp.ofproto
if msg.reason == ofp.OFPR_NO_MATCH:
reason = 'NO MATCH'
elif msg.reason == ofp.OFPR_ACTION:
reason = 'ACTION'
elif msg.reason == ofp.OFPR_INVALID_TTL:
reason = 'INVALID TTL'
else:
reason = 'unknown'
self.logger.debug('OFPPacketIn received: '
'buffer_id=%x total_len=%d reason=%s '
'table_id=%d cookie=%d match=%s data=%s',
msg.buffer_id, msg.total_len, reason,
msg.table_id, msg.cookie, msg.match,
utils.hex_array(msg.data))
pkt = packet.packet.Packet(array.array('B', ev.msg.data))
for p in pkt.protocols:
print(p)
if p.protocol_name == 'ipv4':
print(p.src)
示例4: test_hex_array_bytearray
def test_hex_array_bytearray(self):
"""
Test hex_array() with bytearray type.
"""
expected_result = '0x01 0x02 0x03 0x04'
data = bytearray(b'\x01\x02\x03\x04')
eq_(expected_result, utils.hex_array(data))
示例5: test_hex_array_string
def test_hex_array_string(self):
"""
Test hex_array() with str type.
"""
expected_result = '0x01 0x02 0x03 0x04'
data = b'\x01\x02\x03\x04'
eq_(expected_result, utils.hex_array(data))
示例6: openflow_error
def openflow_error(self, ev):
"""
Print Error Received. Useful for troubleshooting, specially with Brocade
"""
msg = ev.msg
print ('OFPErrorMsg received: type=0x%02x code=0x%02x message=%s' %
(msg.type, msg.code, utils.hex_array(msg.data)))
示例7: msg
def msg(datapath, version, msg_type, msg_len, xid, buf):
exp = None
try:
assert len(buf) >= msg_len
except AssertionError as e:
exp = e
msg_parser = _MSG_PARSERS.get(version)
if msg_parser is None:
raise exception.OFPUnknownVersion(version=version)
try:
msg = msg_parser(datapath, version, msg_type, msg_len, xid, buf)
except exception.OFPTruncatedMessage as e:
raise e
except:
LOG.exception(
'Encountered an error while parsing OpenFlow packet from switch. '
'This implies the switch sent a malformed OpenFlow packet. '
'version 0x%02x msg_type %d msg_len %d xid %d buf %s',
version, msg_type, msg_len, xid, utils.hex_array(buf))
msg = None
if exp:
raise exp
return msg
示例8: test_hex_array_bytes
def test_hex_array_bytes(self):
"""
Test hex_array() with bytes type. (Python3 only)
"""
if six.PY2:
return
expected_result = '0x01 0x02 0x03 0x04'
data = bytes(b'\x01\x02\x03\x04')
eq_(expected_result, utils.hex_array(data))
示例9: error_msg_handler
def error_msg_handler(self, ev):
"""
A switch has sent us an error event
"""
msg = ev.msg
datapath = msg.datapath
dpid = datapath.id
self.logger.error('event=OFPErrorMsg_received: dpid=%s '
'type=%s code=%s message=%s',
dpid, msg.type, msg.code, utils.hex_array(msg.data))
#*** Log human-friendly decodes for the error type and code:
type1, type2, code1, code2 = of_error_decode.decode(msg.type, msg.code)
self.logger.error('error_type=%s %s error_code=%s %s', type1, type2,
code1, code2)
示例10: msg
def msg(datapath, version, msg_type, msg_len, xid, buf):
assert len(buf) >= msg_len
msg_parser = _MSG_PARSERS.get(version)
if msg_parser is None:
raise exception.OFPUnknownVersion(version=version)
try:
return msg_parser(datapath, version, msg_type, msg_len, xid, buf)
except:
LOG.exception(
'Encounter an error during parsing OpenFlow packet from switch.'
'This implies switch sending a malformed OpenFlow packet.'
'version 0x%02x msg_type %d msg_len %d xid %d buf %s',
version, msg_type, msg_len, xid, utils.hex_array(buf))
return None
示例11: _badWeb_Potect
def _badWeb_Potect(self, datapath, msg):
print "in _badWeb_Potect"
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
pkt = packet.Packet(msg.data)
hdata = utils.hex_array(msg.data)
hdata = hdata.split(' ')
hex_data = ''
for hexdata in hdata:
cc = hexdata.replace('0x', '')
if len(cc) == 1:
cc = '0%s' % cc
hex_data = hex_data + cc
# print "hex_data", hex_data
# print 'pkt:', pkt
hex_dnsdata = hex_data[84:]
# print "dns hex data", hex_dnsdata
dns_binary = binascii.unhexlify(hex_dnsdata)
dns = DNSRecord.parse(dns_binary)
# print 'dns:', dns
dns
web_name = dns.questions[0].get_qname().label
web_name = ".".join(list(web_name))
# print web_name
try:
conn = MySQLdb.connect(
host='localhost', user='root', passwd='123456', db='web', port=3306)
cur = conn.cursor()
select = 'select * from WEB_lacklist where name="%s"' % web_name
if(cur.execute(select)):
print ' ilegal web "%s", it`s dangerous! you can`t to access it.' % web_name
cur.close()
conn.close()
return
else:
print 'legal web "%s",you can access it.' % web_name
cur.close()
conn.close()
self._forwarding(datapath, msg)
except MySQLdb.Error, e:
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
示例12: msg
def msg(datapath, version, msg_type, msg_len, xid, buf):
assert len(buf) >= msg_len
msg_parser = _MSG_PARSERS.get(version)
if msg_parser is None:
raise exception.OFPUnknownVersion(version=version)
try:
return msg_parser(datapath, version, msg_type, msg_len, xid, buf)
except:
LOG.exception(
"Encountered an error while parsing OpenFlow packet from switch. "
"This implies the switch sent a malformed OpenFlow packet. "
"version 0x%02x msg_type %d msg_len %d xid %d buf %s",
version,
msg_type,
msg_len,
xid,
utils.hex_array(buf),
)
return None
示例13: error_msg_handler
def error_msg_handler(self, ev):
msg = ev.msg
self.logger.error('OFPErrorMsg received: type=0x%02x code=0x%02x '
'message=%s',
msg.type, msg.code, utils.hex_array(msg.data)
)
示例14: error_msg_handler
def error_msg_handler(self, ev):
msg = ev.msg
self.logger.debug('error msg ev %s type 0x%x code 0x%x %s',
msg, msg.type, msg.code, utils.hex_array(msg.data))
示例15: _error_handler
def _error_handler(self,ev):
msg = ev.msg
print 'type=0x%02x code=0x%02x msg : %s'%(msg.type,msg.code,hex_array(msg.data))