本文整理汇总了Python中ryu.lib.dpid.str_to_dpid函数的典型用法代码示例。如果您正苦于以下问题:Python str_to_dpid函数的具体用法?Python str_to_dpid怎么用?Python str_to_dpid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了str_to_dpid函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:daolicloud,项目名称:daolinet-openstack,代码行数:33,代码来源:group.py
示例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)
开发者ID:netgroup,项目名称:dreamer-ryu,代码行数:35,代码来源:rest_topology.py
示例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))
开发者ID:att,项目名称:ryu,代码行数:57,代码来源:inception_dhcp.py
示例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))
开发者ID:changbl,项目名称:ryu,代码行数:56,代码来源:inception_dhcp.py
示例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)
开发者ID:janieltec,项目名称:ryu-python,代码行数:10,代码来源:simple_switch_stp_13.py
示例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)
开发者ID:09zwcbupt,项目名称:ryu,代码行数:10,代码来源:rest_tunnel.py
示例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)
开发者ID:09zwcbupt,项目名称:ryu,代码行数:10,代码来源:rest_tunnel.py
示例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
开发者ID:Jasonlyt,项目名称:ryu,代码行数:53,代码来源:switches.py
示例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)
开发者ID:hyqdvd,项目名称:ryuCode,代码行数:13,代码来源:simple_switch_13_stp.py
示例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])
开发者ID:09beeihaq,项目名称:Coursera-SDN-Assignments,代码行数:15,代码来源:simple_switch_lacp.py
示例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)
开发者ID:ahonda1972,项目名称:ofuro,代码行数:28,代码来源:rest_controller.py
示例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)
开发者ID:bjlee72,项目名称:ryu-test-project,代码行数:7,代码来源:controller.py
示例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)
开发者ID:linuxxunil,项目名称:ys-ryu,代码行数:7,代码来源:ys_rest_topology.py
示例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)
开发者ID:powerist,项目名称:ryu,代码行数:25,代码来源:inception_util.py
示例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)
开发者ID:istarli,项目名称:mobile_vlan,代码行数:35,代码来源:rest_admin.py
示例16: __init__
def __init__(self, *args, **kwargs):
super(Valve, self).__init__(*args, **kwargs)
self.mac_to_port = {}
self._snoop = kwargs['igmplib']
# if you want a switch to operate as a querier,
# set up as follows:
self._snoop.set_querier_mode(
dpid=str_to_dpid('0000000000000001'), server_port=2)
# dpid the datapath id that will operate as a querier.
# server_port a port number which connect to the multicast
# server.
#
# NOTE: you can set up only the one querier.
# when you called this method several times,
# only the last one becomes effective.
# Read in config file
self.portdb = None
self.vlandb = {}
with open('valve.yaml', 'r') as stream:
self.portdb = yaml.load(stream)
for port in self.portdb:
vlans = self.portdb[port]['vlans']
ptype = self.portdb[port]['type']
if type(vlans) is list:
for vlan in vlans:
if vlan not in self.vlandb:
self.vlandb[vlan] = {'tagged': [], 'untagged': []}
self.vlandb[vlan][ptype].append(port)
else:
if vlans not in self.vlandb:
self.vlandb[vlans] = {'tagged': [], 'untagged': []}
self.vlandb[vlans][ptype].append(port)
开发者ID:zubair1234,项目名称:Assignment,代码行数:35,代码来源:multicast_vlan.py
示例17: _add_arp_entry
def _add_arp_entry(self, req, dpid, **kwargs):
logging.info('[REST_API : ARP 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('[** ARP ADD REQUEST : ERROR] OFSW Not Found')
return wsgi.Response(status=400)
new_arp_entry =eval(req.body)
# ret = self.check_arp_entry(ofsw, new_arp_entry)
# if ret != "":
# logging.info('[** ARP ADD REQUEST : ERROR] Same Entry Found :SW_IP %s', ret)
# return wsgi.Response(status=400)
logging.info("ARP DATA = %s", new_arp_entry)
try:
entry = Add_Arp_Entry(ofsw, new_arp_entry)
content_body = json.dumps(entry, indent=4)
return wsgi.Response(status=200, body=content_body, headers=self.headers)
except:
logging.info('[** ARP ADD REQUEST : ERROR] ENTRY Can not set')
return wsgi.Response(status=400)
开发者ID:ahonda1972,项目名称:ofuro,代码行数:27,代码来源:rest_controller.py
示例18: _links
def _links(self, req, **kwargs):
dpid = None
if 'dpid' in kwargs:
dpid = dpid_lib.str_to_dpid(kwargs['dpid'])
links = get_link(self.topology_api_app, dpid)
body = json.dumps([link.to_dict() for link in links])
return Response(content_type='application/json', body=body)
开发者ID:linuxxunil,项目名称:ys-ryu,代码行数:7,代码来源:ys_rest_topology.py
示例19: send_arp_reply
def send_arp_reply(self, src_ip, src_mac, dst_ip, dst_mac):
"""
Construct an arp reply given the specific arguments
and send it through switch connecting dst_mac
"""
pos = self.vm_manager.get_position(dst_mac)
if pos is not None:
# If I know to whom to forward back this ARP reply
_, dst_dpid, dst_port = pos
# Forward ARP reply
packet_reply = self.create_arp_packet(src_mac, dst_mac, dst_ip,
src_ip, arp.ARP_REPLY)
dst_datapath = self.dpset.get(str_to_dpid(dst_dpid))
dst_ofproto_parser = dst_datapath.ofproto_parser
dst_ofproto = dst_datapath.ofproto
actions_out = [dst_ofproto_parser.OFPActionOutput(int(dst_port))]
dst_datapath.send_msg(
dst_ofproto_parser.OFPPacketOut(
datapath=dst_datapath,
buffer_id=0xffffffff,
in_port=dst_ofproto.OFPP_LOCAL,
data=packet_reply.data,
actions=actions_out))
LOGGER.info("Send ARP reply of (ip=%s) to (ip=%s): ",
src_ip, dst_ip)
开发者ID:powerist,项目名称:ryu,代码行数:25,代码来源:inception_arp.py
示例20: lldp_parse
def lldp_parse(data):
pkt = packet.Packet(data)
i = iter(pkt)
eth_pkt = six.next(i)
assert type(eth_pkt) == ethernet.ethernet
lldp_pkt = six.next(i)
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.decode('utf-8')
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)
return src_dpid, src_port_no
开发者ID:AsmaSwapna,项目名称:ryu,代码行数:31,代码来源:switches.py
注:本文中的ryu.lib.dpid.str_to_dpid函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论