本文整理汇总了Python中ryu.lib.dpid.str_to_dpid函数的典型用法代码示例。如果您正苦于以下问题:Python str_to_dpid函数的具体用法?Python str_to_dpid怎么用?Python str_to_dpid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了str_to_dpid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
def run(self, src, src_gateway, dst, dst_gateway, **kwargs):
sdp_id = dpid_lib.str_to_dpid(src_gateway["datapath_id"])
ddp_id = dpid_lib.str_to_dpid(dst_gateway["datapath_id"])
if self.ryuapp.dps.has_key(sdp_id):
sdp = self.ryuapp.dps[sdp_id]
sofp, sofp_parser, sofp_set, sofp_out = self.ofp_get(sdp)
sport = self.port_get(sdp, src.devname)
if sport:
smatch = sofp_parser.OFPMatch(
in_port=sport.port_no,
eth_type=ether.ETH_TYPE_IP,
eth_src=src.mac_address,
ipv4_src=src.address,
ipv4_dst=dst.address,
)
self.delete_flow(sdp, smatch)
if self.ryuapp.dps.has_key(ddp_id):
ddp = self.ryuapp.dps[ddp_id]
dofp, dofp_parser, dofp_set, dofp_out = self.ofp_get(ddp)
dport = self.port_get(ddp, dst.devname)
if dport:
dmatch = dofp_parser.OFPMatch(
in_port=dport.port_no,
eth_type=ether.ETH_TYPE_IP,
eth_src=dst.mac_address,
ipv4_src=dst.address,
ipv4_dst=src.address,
)
self.delete_flow(ddp, dmatch)
示例2: _route
def _route(self, req, **kwargs):
srcdpid=dpid_lib.str_to_dpid(kwargs['srcdpid'])
srcport=port_no_lib.str_to_port_no(kwargs['srcport'])
dstdpid=dpid_lib.str_to_dpid(kwargs['dstdpid'])
dstport=port_no_lib.str_to_port_no(kwargs['dstport'])
links = get_link(self.topology_api_app, None)
topology = nx.MultiDiGraph()
for link in links:
print link
topology.add_edge(link.src.dpid, link.dst.dpid, src_port=link.src.port_no, dst_port=link.dst.port_no)
try:
shortest_path = nx.shortest_path(topology, srcdpid, dstdpid)
except (nx.NetworkXError, nx.NetworkXNoPath):
body = json.dumps([])
print "Error"
return Response(content_type='application/json', body=body)
ingressPort = NodePortTuple(srcdpid, srcport)
egressPort = NodePortTuple(dstdpid, dstport)
route = []
route.append(ingressPort)
for i in range(0, len(shortest_path)-1):
link = topology[shortest_path[i]][shortest_path[i+1]]
index = randrange(len(link))
dstPort = NodePortTuple(shortest_path[i], link[index]['src_port'])
srcPort = NodePortTuple(shortest_path[i+1], link[index]['dst_port'])
route.append(dstPort)
route.append(srcPort)
route.append(egressPort)
body = json.dumps([hop.to_dict() for hop in route])
return Response(content_type='application/json', body=body)
示例3: handle
def handle(self, dhcp_header, raw_data, txn):
# Process DHCP packet
LOGGER.info("Handle DHCP packet")
if self.switch_dpid is None or self.switch_port is None:
LOGGER.warning("No DHCP server has been found!")
return
# Do ARP learning on a DHCP ACK message
for option in dhcp_header.options.option_list:
if option.tag == dhcp.DHCP_MESSAGE_TYPE_OPT:
option_value = ord(option.value)
if option_value == dhcp.DHCP_ACK:
ip_addr = dhcp_header.yiaddr
mac_addr = dhcp_header.chaddr
if not self.arp_manager.mapping_exist(ip_addr):
self.arp_manager.learn_arp_mapping(ip_addr, mac_addr)
icp_rpc = self.inception.inception_rpc
rpc_func_name = icp_rpc.update_arp_mapping.__name__
rpc_args = (ip_addr, mac_addr)
self.rpc_manager.do_rpc(rpc_func_name, rpc_args)
self.zk_manager.log_arp_mapping(ip_addr, mac_addr, txn)
break
# A packet received from client. Find out the switch connected
# to dhcp server and forward the packet
if dhcp_header.op == dhcp.DHCP_BOOT_REQUEST:
LOGGER.info("Forward DHCP message to server at (switch=%s) "
"(port=%s)", self.switch_dpid, self.switch_port)
datapath = self.dpset.get(str_to_dpid(self.switch_dpid))
action_out = [
datapath.ofproto_parser.OFPActionOutput(
int(self.switch_port))]
datapath.send_msg(
datapath.ofproto_parser.OFPPacketOut(
datapath=datapath,
buffer_id=0xffffffff,
in_port=datapath.ofproto.OFPP_LOCAL,
data=raw_data,
actions=action_out))
# A packet received from server. Find out the mac address of
# the client and forward the packet to it.
elif dhcp_header.op == dhcp.DHCP_BOOT_REPLY:
_, dpid, port = self.vm_manager.get_position(dhcp_header.chaddr)
LOGGER.info("Forward DHCP message to client (mac=%s) at "
"(switch=%s, port=%s)",
dhcp_header.chaddr, dpid, port)
datapath = self.dpset.get(str_to_dpid(dpid))
action_out = [datapath.ofproto_parser.OFPActionOutput(int(port))]
datapath.send_msg(
datapath.ofproto_parser.OFPPacketOut(
datapath=datapath,
buffer_id=0xffffffff,
in_port=datapath.ofproto.OFPP_LOCAL,
data=raw_data,
actions=action_out))
示例4: handle
def handle(self, dhcp_header, raw_data):
# Process DHCP packet
LOGGER.info("Handle DHCP packet")
if self.switch_dpid is None or self.switch_port is None:
LOGGER.warning("No DHCP server has been found!")
return
# Do ARP learning on a DHCP ACK message
for option in dhcp_header.options.option_list:
if option.tag == dhcp.DHCP_MESSAGE_TYPE_OPT:
option_value = ord(option.value)
if option_value == dhcp.DHCP_ACK:
ip_addr = dhcp_header.yiaddr
mac_addr = dhcp_header.chaddr
if ip_addr not in self.ip_to_mac:
self.ip_to_mac[ip_addr] = mac_addr
self.mac_to_ip[mac_addr] = ip_addr
if CONF.zookeeper_storage:
zk_path = os.path.join(i_conf.IP_TO_MAC, ip_addr)
self.inception.zk.create(zk_path, mac_addr)
break
# A packet received from client. Find out the switch connected
# to dhcp server and forward the packet
if dhcp_header.op == dhcp.DHCP_BOOT_REQUEST:
LOGGER.info("Forward DHCP message to server at (switch=%s) "
"(port=%s)", self.switch_dpid, self.switch_port)
datapath = self.dpset.get(str_to_dpid(self.switch_dpid))
action_out = [
datapath.ofproto_parser.OFPActionOutput(
int(self.switch_port))]
datapath.send_msg(
datapath.ofproto_parser.OFPPacketOut(
datapath=datapath,
buffer_id=0xffffffff,
in_port=datapath.ofproto.OFPP_LOCAL,
data=raw_data,
actions=action_out))
# A packet received from server. Find out the mac address of
# the client and forward the packet to it.
elif dhcp_header.op == dhcp.DHCP_BOOT_REPLY:
_, dpid, port, _ = self.mac_to_position[dhcp_header.chaddr]
LOGGER.info("Forward DHCP message to client (mac=%s) at "
"(switch=%s, port=%s)",
dhcp_header.chaddr, dpid, port)
datapath = self.dpset.get(str_to_dpid(dpid))
action_out = [datapath.ofproto_parser.OFPActionOutput(int(port))]
datapath.send_msg(
datapath.ofproto_parser.OFPPacketOut(
datapath=datapath,
buffer_id=0xffffffff,
in_port=datapath.ofproto.OFPP_LOCAL,
data=raw_data,
actions=action_out))
示例5: __init__
def __init__(self, *args, **kwargs):
super(SimpleSwitch13, self).__init__(*args, **kwargs)
self.mac_to_port = {}
self.stp = kwargs['stplib']
config = {dpid_lib.str_to_dpid('0000000000000001'): {'bridge': {'priority':0x8000}},
dpid_lib.str_to_dpid('0000000000000002'): {'bridge': {'priority':0x9000}},
dpid_lib.str_to_dpid('0000000000000003'): {'bridge': {'priority':0xa000}}}
self.stp.set_config(config)
示例6: update
def update(self, _req, dpid, port_id, remote_dpid, **_kwargs):
dpid = dpid_lib.str_to_dpid(dpid)
port_id = int(port_id)
remote_dpid = dpid_lib.str_to_dpid(remote_dpid)
try:
self.tunnels.update_port(dpid, port_id, remote_dpid)
except tunnels.RemoteDPIDAlreadyExist:
return Response(status=409)
return Response(status=200)
示例7: create
def create(self, _req, dpid, port_id, remote_dpid, **_kwargs):
dpid = dpid_lib.str_to_dpid(dpid)
port_id = int(port_id)
remote_dpid = dpid_lib.str_to_dpid(remote_dpid)
try:
self.tunnels.register_port(dpid, port_id, remote_dpid)
except ryu_exc.PortAlreadyExist:
return Response(status=409)
return Response(status=200)
示例8: oxp_lldp_parse
def oxp_lldp_parse(data):
pkt = packet.Packet(data)
i = iter(pkt)
eth_pkt = i.next()
assert type(eth_pkt) == ethernet.ethernet
lldp_pkt = i.next()
if type(lldp_pkt) != lldp.lldp:
raise LLDPPacket.LLDPUnknownFormat()
tlv_chassis_id = lldp_pkt.tlvs[0]
if tlv_chassis_id.subtype != lldp.ChassisID.SUB_LOCALLY_ASSIGNED:
raise LLDPPacket.LLDPUnknownFormat(
msg='unknown chassis id subtype %d' % tlv_chassis_id.subtype)
chassis_id = tlv_chassis_id.chassis_id
if not chassis_id.startswith(LLDPPacket.CHASSIS_ID_PREFIX):
raise LLDPPacket.LLDPUnknownFormat(
msg='unknown chassis id format %s' % chassis_id)
src_dpid = str_to_dpid(chassis_id[LLDPPacket.CHASSIS_ID_PREFIX_LEN:])
tlv_port_id = lldp_pkt.tlvs[1]
if tlv_port_id.subtype != lldp.PortID.SUB_PORT_COMPONENT:
raise LLDPPacket.LLDPUnknownFormat(
msg='unknown port id subtype %d' % tlv_port_id.subtype)
port_id = tlv_port_id.port_id
if len(port_id) != LLDPPacket.PORT_ID_SIZE:
raise LLDPPacket.LLDPUnknownFormat(
msg='unknown port id %d' % port_id)
(src_port_no, ) = struct.unpack(LLDPPacket.PORT_ID_STR, port_id)
# oxp related.
tlv_domain_id = lldp_pkt.tlvs[3]
if tlv_domain_id.subtype != lldp.DomainID.SUB_LOCALLY_ASSIGNED:
raise LLDPPacket.LLDPUnknownFormat(
msg='unknown domain id subtype %d' % tlv_domain_id.subtype)
domain_id = tlv_domain_id.domain_id
if not domain_id.startswith(LLDPPacket.DOMAIN_ID_PREFIX):
raise LLDPPacket.LLDPUnknownFormat(
msg='unknown domain id format %s' % domain_id)
src_domain_id = str_to_dpid(domain_id[
LLDPPacket.DOMAIN_ID_PREFIX_LEN:])
tlv_vport_id = lldp_pkt.tlvs[4]
if tlv_vport_id.subtype != lldp.VPortID.SUB_PORT_COMPONENT:
raise LLDPPacket.LLDPUnknownFormat(
msg='unknown vport id subtype %d' % tlv_vport_id.subtype)
vport_id = tlv_vport_id.vport_id
if len(vport_id) != LLDPPacket.VPORT_ID_SIZE:
raise LLDPPacket.LLDPUnknownFormat(
msg='unknown vport id %d' % vport_id)
(src_vport_no, ) = struct.unpack(LLDPPacket.VPORT_ID_STR, vport_id)
return src_dpid, src_port_no, src_domain_id, src_vport_no
示例9: __init__
def __init__(self, *args, **kwargs):
super(SimpleSwitchStp13, self).__init__(*args, **kwargs)
self.mac_to_port = {}
self.stp = kwargs['stplib']
#sample of stplib config
# please refer to stplib.Stp.set_config() for detail.
config = {dpid_lib.str_to_dpid('000000000000001'): {'bridge': {'priority': 0x8000}},
dpid_lib.str_to_dpid('000000000000002'): {'bridge': {'priority': 0x9000}},
dpid_lib.str_to_dpid('000000000000003'): {'bridge': {'priority': 0xa000}}}
self.stp.set_config(config)
示例10: __init__
def __init__(self, *args, **kwargs):
super(SimpleSwitchLacp, self).__init__(*args, **kwargs)
self.mac_to_port = {}
self._lacp = kwargs['lacplib']
# in this sample application, bonding i/fs of the switchs
# shall be set up as follows:
# - the port 1 and 2 of the datapath 1 face the slave i/fs.
# - the port 3, 4 and 5 of the datapath 1 face the others.
# - the port 1 and 2 of the datapath 2 face the others.
self._lacp.add(
dpid=str_to_dpid('0000000000000001'), ports=[1, 2])
self._lacp.add(
dpid=str_to_dpid('0000000000000001'), ports=[3, 4, 5])
self._lacp.add(
dpid=str_to_dpid('0000000000000002'), ports=[1, 2])
示例11: _add_nat_entry
def _add_nat_entry(self, req, dpid, **kwargs):
logging.info('[REST_API : NAT ENTRY ADD] Calling')
dp_id = dpid_lib.str_to_dpid(dpid)
if dp_id in self.ofuro_spp._OFSW_LIST.keys():
ofsw = self.ofuro_spp._OFSW_LIST[dp_id]
else:
logging.info('[** NAT ADD REQUEST : ERROR] OFSW Not Found')
return wsgi.Response(status=400)
new_nat_entry =eval(req.body)
ret = self.check_entry(ofsw, new_nat_entry)
if ret != "":
logging.info('[** NAT ADD REQUEST : ERROR] Same Entry Found :SW_IP %s', ret)
return wsgi.Response(status=400)
try:
entry_uuid = Nat_Ready(ofsw, "NULL", new_nat_entry)
nat_entry = ofsw.ofuro_data.get_nat_entry(entry_uuid)
content_body = json.dumps(nat_entry, indent=4)
return wsgi.Response(status=200, body=content_body, headers=self.headers)
except:
logging.info('[** NAT ADD REQUEST : ERROR] ENTRY Can not set')
return wsgi.Response(status=400)
示例12: create_vxlan_tunnel
def create_vxlan_tunnel(self, req, **kwargs):
app = self.cluster_controller_app
dpid = libdpid.str_to_dpid(kwargs['dpid'])
tunnel_name = kwargs['tunnel_name']
port_number = kwargs['port_number']
peer_ip = kwargs['peer_ip']
app.create_vxlan_tunnel(dpid, tunnel_name, port_number, peer_ip)
示例13: _switches
def _switches(self, req, **kwargs):
dpid = None
if 'dpid' in kwargs:
dpid = dpid_lib.str_to_dpid(kwargs['dpid'])
switches = get_switch(self.topology_api_app, dpid)
body = json.dumps([switch.to_dict() for switch in switches])
return Response(content_type='application/json', body=body)
示例14: set_gateway_bounce_flow
def set_gateway_bounce_flow(self, dpid, vmac_new, vmac_old, topology):
"""Set up a flow at gateway towards local dpid_old
during live migration to prevent
unnecessary multi-datacenter traffic"""
dpid_gws = topology.get_gateways()
for dpid_gw in dpid_gws:
gw_fwd_port = topology.get_fwd_port(dpid_gw, dpid)
datapath_gw = self.dpset.get(str_to_dpid(dpid_gw))
ofproto = datapath_gw.ofproto
ofproto_parser = datapath_gw.ofproto_parser
actions = [ofproto_parser.OFPActionSetField(eth_dst=vmac_new),
ofproto_parser.OFPActionOutput(int(gw_fwd_port))]
instructions = [
datapath_gw.ofproto_parser.OFPInstructionActions(
ofproto.OFPIT_APPLY_ACTIONS,
actions)]
match_gw = ofproto_parser.OFPMatch(eth_dst=vmac_old)
self.set_flow(datapath=datapath_gw,
match=match_gw,
table_id=FlowManager.PRIMARY_TABLE,
priority=i_priority.DATA_FWD_LOCAL,
flags=ofproto.OFPFF_SEND_FLOW_REM,
hard_timeout=CONF.arp_timeout,
command=ofproto.OFPFC_ADD,
instructions=instructions)
示例15: _hosts
def _hosts(self, req, **kwargs):
body = None
db = database(DB_PATH)
if 'dpid' in kwargs:
dpid = dpid_lib.str_to_dpid(kwargs['dpid'])
rcd_dpid = selectDPID(dpid=dpid)
host_of_dpid = []
tmp = {'mac':'a', 'port':0,'ip':'a', 'slave':1}
for x in rcd_dpid:
tmp['mac'], tmp['port'], tmp['ip'], tmp['slave'] = x[0].encode('utf-8'), x[1], x[2].encode('utf-8'), x[3]
hosts_of_dpid.append(dict(tmp))
body = json.dumps(hosts_of_dpid)
else:
rcd_dev = db.selectDEVICE()
hosts = []
tmp = {'user_id':0, 'dpid':0,'mac':'a', 'vlan':0, 'ip': 'a', 'port':0}
#add gateway
tmp['mac'] = db.selectGATEWAY()[0][0].encode('utf-8')
tmp['ip'] = db.selectGATEWAY()[0][1].encode('utf-8')
gw_dpid = db.getDPIDBySlave(mac_addr=tmp['mac'])
if None != gw_dpid:
tmp['port'] = db.findDPIDByX(gw_dpid,'MAC_ADDR',tmp['mac'])[0][0]
tmp['dpid'] = dpid_lib.dpid_to_str(gw_dpid)
hosts.append(dict(tmp))
#add host
for dev in rcd_dev:
tmp['mac'], tmp['vlan'], tmp['user_id'] = dev[0].encode('utf-8'), dev[1], dev[2]
dpid = db.getDPIDBySlave(mac_addr=tmp['mac'])
tmp['dpid'] = dpid_lib.dpid_to_str(dpid)
rcd_host = db.findDPIDByX(dpid,'MAC_ADDR',tmp['mac'])
tmp['port'], tmp['ip'] = rcd_host[0][0], rcd_host[0][1].encode('utf-8')
hosts.append(dict(tmp))
body = json.dumps(hosts)
return Response(content_type='application/json', body=body)