本文整理汇总了Python中ryu.lib.mac.haddr_to_str函数的典型用法代码示例。如果您正苦于以下问题:Python haddr_to_str函数的具体用法?Python haddr_to_str怎么用?Python haddr_to_str使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了haddr_to_str函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: actions_to_str
def actions_to_str(acts):
actions = []
for a in acts:
action_type = a.cls_action_type
if action_type == ofproto_v1_0.OFPAT_OUTPUT:
buf = 'OUTPUT:' + str(a.port)
elif action_type == ofproto_v1_0.OFPAT_SET_VLAN_VID:
buf = 'SET_VLAN_VID:' + str(a.vlan_vid)
elif action_type == ofproto_v1_0.OFPAT_SET_VLAN_PCP:
buf = 'SET_VLAN_PCP:' + str(a.vlan_pcp)
elif action_type == ofproto_v1_0.OFPAT_STRIP_VLAN:
buf = 'STRIP_VLAN'
elif action_type == ofproto_v1_0.OFPAT_SET_DL_SRC:
buf = 'SET_DL_SRC:' + haddr_to_str(a.dl_addr)
elif action_type == ofproto_v1_0.OFPAT_SET_DL_DST:
buf = 'SET_DL_DST:' + haddr_to_str(a.dl_addr)
elif action_type==65535:
if a.subtype==2:
buf = 'set_tunnel:'+str(a.tun_id)
else:
buf='resubmit:(,'+str(a.table)+')'
else:
buf='UNKNOWN'
actions.append(buf)
return actions
示例2: switch_configuration
def switch_configuration(self, ev):
print "Packet in: switch configuration"
msg = ev.msg
datapath = msg.datapath
ofproto = datapath.ofproto
dst, src, _eth_type = struct.unpack_from('!6s6sH', buffer(msg.data), 0)
dpid = datapath.id
self.mac2port.dpid_add(dpid)
LOG.info("Src MAC: %s; Dest MAC: %s", haddr_to_str(src), haddr_to_str(dst))
self.mac2port.port_add(dpid, msg.in_port, src)
out_port = self.mac2port.port_get(dpid, dst)
if out_port == None:
LOG.info("Output port not found")
out_port = ofproto.OFPP_FLOOD
actions = [datapath.ofproto_parser.OFPActionOutput(out_port)]
LOG.info("Input port: %s; Output port: %s", msg.in_port, out_port)
if out_port != ofproto.OFPP_FLOOD:
rule = nx_match.ClsRule()
rule.set_in_port(msg.in_port)
rule.set_dl_dst(dst)
rule.set_dl_src(src)
rule.set_nw_dscp(0)
datapath.send_flow_mod(
rule=rule, cookie=0, command=ofproto.OFPFC_ADD,
idle_timeout=0, hard_timeout=0,
priority=ofproto.OFP_DEFAULT_PRIORITY,
flags=ofproto.OFPFF_SEND_FLOW_REM, actions=actions)
datapath.send_packet_out(msg.buffer_id, msg.in_port, actions)
示例3: packet_in_handler
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']
dst, src, eth_type = struct.unpack_from('!6s6sH', buffer(msg.data), 0)
match = msg.match.fields
#for field in match:
#logger.info("FIELDS==> %s ",field.value)
logger.info("")
logger.info("----------------------------------------")
logger.info("*** PacketIn ***")
logger.info("in_port=%d, eth_type: %s", in_port, hex(eth_type))
logger.info("packet reason=%d buffer_id=%d", msg.reason, msg.buffer_id)
logger.info("packet in datapath_id=%s src=%s dst=%s",
msg.datapath.id, haddr_to_str(src), haddr_to_str(dst))
pkt = packet.Packet(msg.data) # get data of packet
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, {})
# 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)
示例4: match_eth_to_str
def match_eth_to_str(value, mask):
eth_str = mac.haddr_to_str(value)
if mask is not None:
eth_str = eth_str + '/' + mac.haddr_to_str(mask)
return eth_str
示例5: _packet_in_handler
def _packet_in_handler(self, ev):
msg = ev.msg
datapath = msg.datapath
ofproto = datapath.ofproto
dst, src, _eth_type = struct.unpack_from('!6s6sH', buffer(msg.data), 0)
dpid = datapath.id
self.mac_to_port.setdefault(dpid, {})
LOG.info("packet in %s %s %s %s",
dpid, haddr_to_str(src), haddr_to_str(dst), msg.in_port)
# learn a mac address to avoid FLOOD next time.
self.mac_to_port[dpid][src] = msg.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 = [datapath.ofproto_parser.OFPActionOutput(out_port)]
# install a flow to avoid packet_in next time
if out_port != ofproto.OFPP_FLOOD:
self.add_flow(datapath, msg.in_port, dst, actions)
out = datapath.ofproto_parser.OFPPacketOut(
datapath=datapath, buffer_id=msg.buffer_id, in_port=msg.in_port,
actions=actions)
datapath.send_msg(out)
示例6: _forward_to_nw_id
def _forward_to_nw_id(self, msg, src, dst, nw_id, out_port):
assert out_port is not None
datapath = msg.datapath
if not self.nw.same_network(datapath.id, nw_id, out_port, NW_ID_EXTERNAL):
self.logger.debug(
"packet is blocked src %s dst %s " "from %d to %d on datapath %d",
haddr_to_str(src),
haddr_to_str(dst),
msg.in_port,
out_port,
datapath.id,
)
return
self.logger.debug(
"learned dpid %s in_port %d out_port " "%d src %s dst %s",
datapath.id,
msg.in_port,
out_port,
haddr_to_str(src),
haddr_to_str(dst),
)
actions = [datapath.ofproto_parser.OFPActionOutput(out_port)]
self._modflow_and_send_packet(msg, src, dst, actions)
示例7: _packet_in_handler
def _packet_in_handler(self, ev):
msg = ev.msg
datapath = msg.datapath
ofproto = datapath.ofproto
dst, src, _eth_type = struct.unpack_from('!6s6sH', buffer(msg.data), 0)
dpid = datapath.id
print 'mac_to_port',self.mac_to_port,'\n'
self.mac_to_port.setdefault(dpid, {})
print 'mac_to_port',self.mac_to_port,'\n'
LOG.info("packet in %s %s %s %s",
dpid, haddr_to_str(src), haddr_to_str(dst), msg.in_port)
# learn a mac address to avoid FLOOD next time.
self.mac_to_port[dpid][src] = msg.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 = [datapath.ofproto_parser.OFPActionOutput(out_port)]
if out_port != ofproto.OFPP_FLOOD:
#self.add_flow(datapath, msg.in_port, dst, [datapath.ofproto_parser.OFPActionOutput(datapath.ofproto.OFPP_NORMAL)])
self.add_flow(datapath, msg.in_port, dst, actions)
#add a ipv6 flow table:
if _eth_type == ether.ETH_TYPE_IPV6:
#print _eth_type
pkt = Packet(array('B',msg.data))
for packet in pkt:
if isinstance(packet,array):
pass
else:
if packet.protocol_name=='ipv6':
ipv6_packet=packet
else:
pass
ipv6_src=self._binary_to_ipv6_format(ipv6_packet.src)
ipv6_dst=self._binary_to_ipv6_format(ipv6_packet.dst)
print ipv6_src,ipv6_dst
'''
# judge if src and dst addr is special
# eg: src [0,0,0,0] dst begin with 0xff01 or 0x ff02
if ipv6_src == [0,0,0,0] or ipv6_dst[0]&0xff010000 == 0xff010000 or ipv6_dst[0]&0xff020000 == 0xff020000:
print 'ipv6 reserved address\n'
#elif ipv6_dst[0]&0xfe800000 == 0xfe800000:
# print 'ipv6 dst address is Link-Local address'
else:
'''
rule={'ipv6_src':ipv6_src,'ipv6_dst':ipv6_dst}
self.nx_ipv6_add_flow(datapath,rule,actions)
print 'add a ipv6 flow entry'
out = datapath.ofproto_parser.OFPPacketOut(
datapath=datapath, buffer_id=msg.buffer_id, in_port=msg.in_port,
actions=actions)
datapath.send_msg(out)
示例8: _packet_in_handler
def _packet_in_handler(self, ev):
msg = ev.msg
datapath = msg.datapath
ofproto = datapath.ofproto
dst, src, _eth_type = struct.unpack_from('!6s6sH', buffer(msg.data), 0)
dpid = datapath.id
self.mac_to_port.setdefault(dpid, {})
match = msg.match
in_port = 0
#iterate through fields - parser should handle this
#packet in dpid 20015998343868 from 08:00:27:15:d4:53 to ff:ff:ff:ff:ff:ff log_port 0 phy_port 0
#Field MTInPort(header=2147483652,length=8,n_bytes=4,value=2)
#Field MTEthType(header=2147486210,length=6,n_bytes=2,value=2054)
#Field MTArpOp(header=2147494402,length=6,n_bytes=2,value=1)
#Field MTMetadata(header=2147484680,length=12,n_bytes=8,value=18446744073709551615L)
#Field MTArpSha(header=2147495942,length=10,n_bytes=6,value="\x08\x00'\x15\xd4S")
#Field MTEthDst(header=2147485190,length=10,n_bytes=6,value='\xff\xff\xff\xff\xff\xff')
#Field MTArpSpa(header=2147494916,length=8,n_bytes=4,value=167772161)
#Field MTArpTha(header=2147496454,length=10,n_bytes=6,value='\x00\x00\x00\x00\x00\x00')
for o in match.fields:
if isinstance(o, ofproto_v1_2_parser.MTInPort):
in_port = o.value
break
self.logger.info("packet in dpid %s from %s to %s log_port %s",
dpid, haddr_to_str(src), haddr_to_str(dst),
in_port)
# do we know the mac?
if src not in self.mac_to_port[dpid]:
# learn the mac address to avoid FLOOD next time.
self.mac_to_port[dpid][src] = in_port
# set a flow to table 0 to allow packets through to table 1
match = datapath.ofproto_parser.OFPMatch()
match.set_in_port(in_port)
match.set_dl_src(src)
instructions = [datapath.ofproto_parser.OFPInstructionGotoTable(1)]
self.add_flow(datapath, 0, match, instructions)
if dst in self.mac_to_port[dpid]:
out_port = self.mac_to_port[dpid][dst]
actions = [datapath.ofproto_parser.OFPActionOutput(out_port, 1500)]
match = datapath.ofproto_parser.OFPMatch()
match.set_dl_dst(dst)
instructions = [datapath.ofproto_parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS, actions)]
self.add_flow(datapath, 1, match, instructions, buffer_id=msg.buffer_id)
else:
out_port = ofproto_v1_2.OFPP_FLOOD
actions = [datapath.ofproto_parser.OFPActionOutput(out_port, 1500)]
out = datapath.ofproto_parser.OFPPacketOut(
datapath=datapath, buffer_id=msg.buffer_id, in_port=in_port,
actions=actions)
datapath.send_msg(out)
示例9: packet_in_handler
def packet_in_handler(self, ev):
msg = ev.msg
dst, src, eth_type = struct.unpack_from('!6s6sH', buffer(msg.data), 0)
in_port = msg.match.fields[0].value
LOG.info("----------------------------------------")
LOG.info("* PacketIn")
LOG.info("in_port=%d, eth_type: %s", in_port, hex(eth_type))
LOG.info("packet reason=%d buffer_id=%d", msg.reason, msg.buffer_id)
LOG.info("packet in datapath_id=%s src=%s dst=%s",
msg.datapath.id, haddr_to_str(src), haddr_to_str(dst))
示例10: match_to_str
def match_to_str(m):
return {'dl_dst': haddr_to_str(m.dl_dst),
'dl_src': haddr_to_str(m.dl_src),
'dl_type': m.dl_type,
'dl_vlan': m.dl_vlan,
'dl_vlan_pcp': m.dl_vlan_pcp,
'in_port': m.in_port,
'nw_dst': socket.inet_ntoa(struct.pack('!I', m.nw_dst)),
'nw_proto': m.nw_proto,
'nw_src': socket.inet_ntoa(struct.pack('!I', m.nw_src)),
'tp_src': m.tp_src,
'tp_dst': m.tp_dst}
示例11: _flood_to_nw_id
def _flood_to_nw_id(self, msg, src, dst, nw_id):
datapath = msg.datapath
actions = []
self.logger.debug("dpid %s in_port %d src %s dst %s ports %s",
datapath.id, msg.in_port,
haddr_to_str(src), haddr_to_str(dst),
self.nw.dpids.get(datapath.id, {}).items())
for port_no in self.nw.filter_ports(datapath.id, msg.in_port,
nw_id, NW_ID_EXTERNAL):
self.logger.debug("port_no %s", port_no)
actions.append(datapath.ofproto_parser.OFPActionOutput(port_no))
self._modflow_and_send_packet(msg, src, dst, actions)
示例12: match_to_str
def match_to_str(m):
return {'dl_dst': haddr_to_str(m.dl_dst),
'dl_src': haddr_to_str(m.dl_src),
'dl_type': m.dl_type,
'dl_vlan': m.dl_vlan,
'dl_vlan_pcp': m.dl_vlan_pcp,
'in_port': m.in_port,
'nw_dst': nw_dst_to_str(m.wildcards, m.nw_dst),
'nw_proto': m.nw_proto,
'nw_src': nw_src_to_str(m.wildcards, m.nw_src),
'tp_src': m.tp_src,
'tp_dst': m.tp_dst}
示例13: _decode_bridge_id
def _decode_bridge_id(bridge_id):
priority = (bridge_id << 12) & 0xf000
system_id_extension = (bridge_id >> 4) & 0xfff
mac_addr = (bridge_id >> 16) & 0xffffffffffff
mac_addr_list = [format((mac_addr >> (8 * i)) & 0xff, '02x')
for i in range(0, 6)]
mac_address = binascii.a2b_hex(''.join(mac_addr_list))
#TODO:
from ryu.lib import mac
print mac.haddr_to_str(mac_address)
return priority, system_id_extension, mac_address
示例14: equal_match
def equal_match(key, value, cls_name, fields):
for field in fields:
if cls_name in str(field):
if key in ['dl_src', 'dl_dst', 'arp_sha', 'arp_tha',
'eth_src', 'eth_dst']:
eth, mask = _to_match_eth(value)
str_eth = mac.haddr_to_str(eth)
str_mask = mac.haddr_to_str(mask)
str_value = mac.haddr_to_str(field.value)
for i in range(0, 17):
if str_mask[i] == 'f':
eq_(str_eth[i], str_value[i])
else:
continue
eq_(mask, field.mask)
return
elif key in ['nw_src', 'nw_dst', 'ipv4_src', 'ipv4_dst',
'arp_spa', 'arp_tpa']:
ipv4, mask = _to_match_ip(value)
eq_(ipv4, field.value)
eq_(mask, field.mask)
return
elif key in ['ipv6_src', 'ipv6_dst']:
ipv6, mask = _to_match_ipv6(value)
for i in range(0, 8):
if mask[i] == 65535:
eq_(ipv6[i], field.value[i])
else:
continue
eq_(list(mask), field.mask)
return
elif key == 'ipv6_nd_target':
ipv6, mask = _to_match_ipv6(value)
for i in range(0, 8):
if mask[i] == 65535:
eq_(ipv6[i], field.value[i])
else:
continue
return
elif key == 'ipv6_nd_sll' or key == 'ipv6_nd_tll':
eq_(mac.haddr_to_bin(value), field.value)
return
elif key == 'metadata':
eq_(int(value, 16), field.value)
return
else:
eq_(value, field.value)
return
assert False
示例15: test_to_string
def test_to_string(self):
nd_opt = icmpv6.nd_option_la(self.nd_hw_src)
nd = icmpv6.nd_neighbor(
self.res, self.dst, self.nd_type, self.nd_length, nd_opt)
ic = icmpv6.icmpv6(self.type_, self.code, self.csum, nd)
nd_opt_values = {'hw_src': haddr_to_str(self.nd_hw_src),
'data': None}
_nd_opt_str = ','.join(['%s=%s' % (k, repr(nd_opt_values[k]))
for k, v in inspect.getmembers(nd_opt)
if k in nd_opt_values])
nd_opt_str = '%s(%s)' % (icmpv6.nd_option_la.__name__, _nd_opt_str)
nd_values = {'res': repr(nd.res),
'dst': repr(ipv6_to_str(self.dst)),
'type_': repr(self.nd_type),
'length': repr(self.nd_length),
'data': nd_opt_str}
_nd_str = ','.join(['%s=%s' % (k, nd_values[k])
for k, v in inspect.getmembers(nd)
if k in nd_values])
nd_str = '%s(%s)' % (icmpv6.nd_neighbor.__name__, _nd_str)
icmp_values = {'type_': repr(self.type_),
'code': repr(self.code),
'csum': repr('0x%x' % self.csum),
'data': nd_str}
_ic_str = ','.join(['%s=%s' % (k, icmp_values[k])
for k, v in inspect.getmembers(ic)
if k in icmp_values])
ic_str = '%s(%s)' % (icmpv6.icmpv6.__name__, _ic_str)
eq_(str(ic), ic_str)
eq_(repr(ic), ic_str)