本文整理汇总了Python中ryu.lib.packet.lldp.lldp函数的典型用法代码示例。如果您正苦于以下问题:Python lldp函数的具体用法?Python lldp怎么用?Python lldp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了lldp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_lldp_packet
def send_lldp_packet(self, datapath, port_no, hw_addr):
ofp = datapath.ofproto
pkt = packet.Packet()
pkt.add_protocol(ethernet.ethernet(ethertype=ether_types.ETH_TYPE_LLDP, src=hw_addr, dst=lldp.LLDP_MAC_NEAREST_BRIDGE))
tlv_chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_LOCALLY_ASSIGNED, chassis_id=self.format_dpid(str(datapath.id)))
tlv_port_id = lldp.PortID(subtype=lldp.PortID.SUB_LOCALLY_ASSIGNED, port_id=self.format_port(str(port_no)))
tlv_ttl = lldp.TTL(ttl=10)
tlv_sysname = lldp.SystemName(system_name=self.SYSTEM_NAME)
tlv_end = lldp.End()
tlvs = (tlv_chassis_id, tlv_port_id, tlv_ttl, tlv_sysname, tlv_end)
pkt.add_protocol(lldp.lldp(tlvs))
pkt.serialize()
data = pkt.data
parser = datapath.ofproto_parser
actions = []
dpid = self.format_dpid(str(datapath.id))
for src in self.mac_to_port[dpid]:
actions.append(parser.OFPActionSetField(eth_src="00:00:00:00:00:"+self.mac_to_port[dpid][src][-2:]))
actions.append(parser.OFPActionOutput(port=int(self.mac_to_port[dpid][src])))
out = parser.OFPPacketOut(datapath=datapath, buffer_id=ofp.OFP_NO_BUFFER, in_port=ofp.OFPP_CONTROLLER, actions=actions, data=data)
datapath.send_msg(out)
示例2: lldp_packet
def lldp_packet(dpid, port_no, dl_addr, ttl):
pkt = packet.Packet()
dst = lldp.LLDP_MAC_NEAREST_BRIDGE
src = dl_addr
ethertype = ETH_TYPE_LLDP
eth_pkt = ethernet.ethernet(dst, src, ethertype)
pkt.add_protocol(eth_pkt)
tlv_chassis_id = lldp.ChassisID(
subtype=lldp.ChassisID.SUB_LOCALLY_ASSIGNED,
chassis_id=(LLDPPacket.CHASSIS_ID_FMT %
dpid_to_str(dpid)).encode('ascii'))
tlv_port_id = lldp.PortID(subtype=lldp.PortID.SUB_PORT_COMPONENT,
port_id=struct.pack(
LLDPPacket.PORT_ID_STR,
port_no))
tlv_ttl = lldp.TTL(ttl=ttl)
tlv_end = lldp.End()
tlvs = (tlv_chassis_id, tlv_port_id, tlv_ttl, tlv_end)
lldp_pkt = lldp.lldp(tlvs)
pkt.add_protocol(lldp_pkt)
pkt.serialize()
return pkt.data
示例3: test_serialize
def test_serialize(self):
pkt = packet.Packet()
dst = lldp.LLDP_MAC_NEAREST_BRIDGE
src = '00:04:96:1f:a7:26'
ethertype = ether.ETH_TYPE_LLDP
eth_pkt = ethernet.ethernet(dst, src, ethertype)
pkt.add_protocol(eth_pkt)
tlv_chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
chassis_id=addrconv.mac.
text_to_bin(src))
tlv_port_id = lldp.PortID(subtype=lldp.PortID.SUB_INTERFACE_NAME,
port_id=b'1/3')
tlv_ttl = lldp.TTL(ttl=120)
tlv_end = lldp.End()
tlvs = (tlv_chassis_id, tlv_port_id, tlv_ttl, tlv_end)
lldp_pkt = lldp.lldp(tlvs)
pkt.add_protocol(lldp_pkt)
eq_(len(pkt.protocols), 2)
pkt.serialize()
# Note: If ethernet frame is less than 60 bytes length,
# ethernet.ethernet() appends padding to the payload.
# So, we splits the serialized data to compare.
data_len = len(self.data)
pkt_data_lldp = pkt.data[:data_len]
pkt_data_pad = pkt.data[data_len:]
eq_(b'\x00' * (60 - data_len), pkt_data_pad)
eq_(self.data, pkt_data_lldp)
示例4: send_lldp_packet
def send_lldp_packet(self, datapath, port_no, hw_addr):
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
pkt = packet.Packet()
pkt.add_protocol(ethernet.ethernet(ethertype = ether_types.ETH_TYPE_LLDP, src = hw_addr, dst = lldp.LLDP_MAC_NEAREST_BRIDGE))
tlv_chassis_id = lldp.ChassisID(subtype = self.LLDP_FORMAT['chassis_subtype'], chassis_id = str(datapath.id))
tlv_port_id = lldp.PortID(subtype = self.LLDP_FORMAT['port_subtype'], port_id = str(port_no))
#tlv_port_id = lldp.PortID(subtype = self.LLDP_FORMAT['port_subtype'], port_id = '0')
tlv_ttl = lldp.TTL(ttl = 10)
tlv_sysname = lldp.SystemName(system_name = self.SYSTEM_NAME)
tlv_end = lldp.End()
tlvs = (tlv_chassis_id, tlv_port_id, tlv_ttl, tlv_sysname, tlv_end)
pkt.add_protocol(lldp.lldp(tlvs))
pkt.serialize()
actions = []
#actions = [parser.OFPActionOutput(port=ofproto.OFPP_FLOOD)]
for src in self.mac_to_port[str(datapath.id)]:
actions.append(parser.OFPActionSetField(eth_src=src))
actions.append(parser.OFPActionOutput(port=int(self.mac_to_port[str(datapath.id)][src])))
#actions.append(parser.OFPActionOutput(port = ofproto.OFPP_FLOOD))
#actions = [parser.OFPActionOutput(port=port_no)]
out = parser.OFPPacketOut(datapath = datapath, buffer_id = ofproto.OFP_NO_BUFFER, in_port = ofproto.OFPP_CONTROLLER, actions = actions, data = pkt.data)
datapath.send_msg(out)
示例5: test_to_string
def test_to_string(self):
chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
chassis_id=b'\x00\x04\x96\x1f\xa7\x26')
port_id = lldp.PortID(subtype=lldp.PortID.SUB_INTERFACE_NAME,
port_id='1/3')
ttl = lldp.TTL(ttl=120)
end = lldp.End()
tlvs = (chassis_id, port_id, ttl, end)
lldp_pkt = lldp.lldp(tlvs)
chassis_id_values = {'subtype': lldp.ChassisID.SUB_MAC_ADDRESS,
'chassis_id': b'\x00\x04\x96\x1f\xa7\x26',
'len': chassis_id.len,
'typelen': chassis_id.typelen}
_ch_id_str = ','.join(['%s=%s' % (k, repr(chassis_id_values[k]))
for k, v in inspect.getmembers(chassis_id)
if k in chassis_id_values])
tlv_chassis_id_str = '%s(%s)' % (lldp.ChassisID.__name__, _ch_id_str)
port_id_values = {'subtype': port_id.subtype,
'port_id': port_id.port_id,
'len': port_id.len,
'typelen': port_id.typelen}
_port_id_str = ','.join(['%s=%s' % (k, repr(port_id_values[k]))
for k, v in inspect.getmembers(port_id)
if k in port_id_values])
tlv_port_id_str = '%s(%s)' % (lldp.PortID.__name__, _port_id_str)
ttl_values = {'ttl': ttl.ttl,
'len': ttl.len,
'typelen': ttl.typelen}
_ttl_str = ','.join(['%s=%s' % (k, repr(ttl_values[k]))
for k, v in inspect.getmembers(ttl)
if k in ttl_values])
tlv_ttl_str = '%s(%s)' % (lldp.TTL.__name__, _ttl_str)
end_values = {'len': end.len,
'typelen': end.typelen}
_end_str = ','.join(['%s=%s' % (k, repr(end_values[k]))
for k, v in inspect.getmembers(end)
if k in end_values])
tlv_end_str = '%s(%s)' % (lldp.End.__name__, _end_str)
_tlvs_str = '(%s, %s, %s, %s)'
tlvs_str = _tlvs_str % (tlv_chassis_id_str,
tlv_port_id_str,
tlv_ttl_str,
tlv_end_str)
_lldp_str = '%s(tlvs=%s)'
lldp_str = _lldp_str % (lldp.lldp.__name__,
tlvs_str)
eq_(str(lldp_pkt), lldp_str)
eq_(repr(lldp_pkt), lldp_str)
示例6: create_lldp
def create_lldp(dpid, port_no=1):
'''
Creates an LLDP broadcast packet
:param dpid: 64bit switch id
:type dpid: int
:param port_no: port number
:type port_no: int
:returns: binary representation of LLDP packet
:rtype: `bytearray`
'''
pkt = packet.Packet()
dst = 'FF:FF:FF:FF:FF:FF'
ethertype = ether.ETH_TYPE_LLDP
eth_pkt = ethernet.ethernet(dst, dpid, ethertype)
pkt.add_protocol(eth_pkt)
tlv_chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
chassis_id=haddr_to_bin(dpid))
tlv_port_id = lldp.PortID(subtype=lldp.PortID.SUB_INTERFACE_NAME,
port_id=str(port_no))
tlv_ttl = lldp.TTL(ttl=2)
tlv_end = lldp.End()
tlvs = (tlv_chassis_id, tlv_port_id, tlv_ttl, tlv_end)
lldp_pkt = lldp.lldp(tlvs)
pkt.add_protocol(lldp_pkt)
pkt.serialize()
data = pkt.data
return data
示例7: create_lldp
def create_lldp(dpid, port_no=ofp.OFPP_FLOOD):
'''
Create an LLDP broadcast packet.
:param dpid: 64bit switch id
:type dpid: int
:param port_no: port number
:type port_no: int
:returns: binary representation of LLDP packet
:rtype: `bytearray`
'''
pkt = packet.Packet() # creating empty pkt
dst = lldp.LLDP_MAC_NEAREST_BRIDGE # Singlehop LLDP multicast
src = flows.int_to_mac(dpid)
ethertype = ethertypes.ETH_TYPE_LLDP
eth_pkt = ethernet.ethernet(dst, src, ethertype)
pkt.add_protocol(eth_pkt) # Adding Ethernet
tlvs = (lldp.ChassisID(subtype=lldp.ChassisID.SUB_LOCALLY_ASSIGNED,
chassis_id=hex(dpid)),
lldp.PortID(subtype=lldp.PortID.SUB_INTERFACE_NAME,
port_id=hex(port_no)),
lldp.TTL(ttl=1),
lldp.End())
lldp_pkt = lldp.lldp(tlvs)
pkt.add_protocol(lldp_pkt) # Adding llDP
pkt.serialize()
return pkt.data
示例8: test_json
def test_json(self):
chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
chassis_id=b'\x00\x01\x30\xf9\xad\xa0')
port_id = lldp.PortID(subtype=lldp.PortID.SUB_INTERFACE_NAME,
port_id='1/1')
ttl = lldp.TTL(ttl=120)
port_desc = lldp.PortDescription(
port_description=b'Summit300-48-Port 1001\x00')
sys_name = lldp.SystemName(system_name=b'Summit300-48\x00')
sys_desc = lldp.SystemDescription(
system_description=b'Summit300-48 - Version 7.4e.1 (Build 5) '
+ b'by Release_Master 05/27/05 04:53:11\x00')
sys_cap = lldp.SystemCapabilities(
subtype=lldp.ChassisID.SUB_CHASSIS_COMPONENT,
system_cap=0x14,
enabled_cap=0x14)
man_addr = lldp.ManagementAddress(
addr_subtype=0x06, addr=b'\x00\x01\x30\xf9\xad\xa0',
intf_subtype=0x02, intf_num=1001,
oid='')
org_spec = lldp.OrganizationallySpecific(
oui=b'\x00\x12\x0f', subtype=0x02, info=b'\x07\x01\x00')
end = lldp.End()
tlvs = (chassis_id, port_id, ttl, port_desc, sys_name,
sys_desc, sys_cap, man_addr, org_spec, end)
lldp1 = lldp.lldp(tlvs)
jsondict = lldp1.to_jsondict()
lldp2 = lldp.lldp.from_jsondict(jsondict['lldp'])
eq_(str(lldp1), str(lldp2))
示例9: test_serialize_without_ethernet
def test_serialize_without_ethernet(self):
tlv_chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
chassis_id=b'\x00\x04\x96\x1f\xa7\x26')
tlv_port_id = lldp.PortID(subtype=lldp.PortID.SUB_INTERFACE_NAME,
port_id='1/3')
tlv_ttl = lldp.TTL(ttl=120)
tlv_end = lldp.End()
tlvs = (tlv_chassis_id, tlv_port_id, tlv_ttl, tlv_end)
lldp_pkt = lldp.lldp(tlvs)
eq_(lldp_pkt.serialize(None, None),
self.data[ethernet.ethernet._MIN_LEN:])
示例10: test_serialize
def test_serialize(self):
pkt = packet.Packet()
dst = lldp.LLDP_MAC_NEAREST_BRIDGE
src = '00:01:30:f9:ad:a0'
ethertype = ether.ETH_TYPE_LLDP
eth_pkt = ethernet.ethernet(dst, src, ethertype)
pkt.add_protocol(eth_pkt)
tlv_chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
chassis_id=addrconv.mac.
text_to_bin(src))
tlv_port_id = lldp.PortID(subtype=lldp.PortID.SUB_INTERFACE_NAME,
port_id='1/1')
tlv_ttl = lldp.TTL(ttl=120)
tlv_port_description = lldp.PortDescription(
port_description=b'Summit300-48-Port 1001\x00')
tlv_system_name = lldp.SystemName(system_name=b'Summit300-48\x00')
tlv_system_description = lldp.SystemDescription(
system_description=b'Summit300-48 - Version 7.4e.1 (Build 5) '
+ b'by Release_Master 05/27/05 04:53:11\x00')
tlv_system_capabilities = lldp.SystemCapabilities(
subtype=lldp.ChassisID.SUB_CHASSIS_COMPONENT,
system_cap=0x14,
enabled_cap=0x14)
tlv_management_address = lldp.ManagementAddress(
addr_subtype=0x06, addr=b'\x00\x01\x30\xf9\xad\xa0',
intf_subtype=0x02, intf_num=1001,
oid='')
tlv_organizationally_specific = lldp.OrganizationallySpecific(
oui=b'\x00\x12\x0f', subtype=0x02, info=b'\x07\x01\x00')
tlv_end = lldp.End()
tlvs = (tlv_chassis_id, tlv_port_id, tlv_ttl, tlv_port_description,
tlv_system_name, tlv_system_description,
tlv_system_capabilities, tlv_management_address,
tlv_organizationally_specific, tlv_end)
lldp_pkt = lldp.lldp(tlvs)
pkt.add_protocol(lldp_pkt)
eq_(len(pkt.protocols), 2)
pkt.serialize()
# self.data has many organizationally specific TLVs
data = str(pkt.data[:-2])
eq_(data, self.data[:len(data)])
示例11: send_lldp_packet
def send_lldp_packet(self, datapath, port_no, hw_addr):
ofp = datapath.ofproto
pkt = packet.Packet()
pkt.add_protocol(ethernet.ethernet(ethertype=ether_types.ETH_TYPE_LLDP,src=hw_addr ,dst=lldp.LLDP_MAC_NEAREST_BRIDGE))
tlv_chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_LOCALLY_ASSIGNED, chassis_id=str(datapath.id))
tlv_port_id = lldp.PortID(subtype=lldp.PortID.SUB_LOCALLY_ASSIGNED, port_id=str(port_no))
tlv_ttl = lldp.TTL(ttl=10)
tlv_end = lldp.End()
tlvs = (tlv_chassis_id, tlv_port_id, tlv_ttl, tlv_end)
pkt.add_protocol(lldp.lldp(tlvs))
pkt.serialize()
data = pkt.data
parser = datapath.ofproto_parser
actions = [parser.OFPActionOutput(port=port_no)]
out = parser.OFPPacketOut(datapath=datapath, buffer_id=ofp.OFP_NO_BUFFER, in_port=ofp.OFPP_CONTROLLER, actions=actions, data=data)
datapath.send_msg(out)
示例12: send_lldp_out
def send_lldp_out(self,p,port_no):
e=eth.ethernet(dst=lldp.LLDP_MAC_NEAREST_BRIDGE,src=lldp.LLDP_MAC_NEAREST_BRIDGE,ethertype=ether_types.ETH_TYPE_LLDP)
pkt=packet.Packet()
pkt.add_protocol(e)
l=lldp.lldp(tlvs=[
lldp.ChassisID(subtype=lldp.ChassisID.SUB_LOCALLY_ASSIGNED,
chassis_id=str(p.id)),
lldp.PortID(subtype=lldp.PortID.SUB_LOCALLY_ASSIGNED,
port_id=str(port_no)),
lldp.TTL(ttl=5),
lldp.End()
])
pkt.add_protocol(l)
pkt.serialize()
data=pkt.data
print "Sednd LLdp:",p.id,port_no
out=parser13.OFPPacketOut(datapath=p,buffer_id=ofp13.OFP_NO_BUFFER,in_port=ofp13.OFPP_CONTROLLER,actions=[parser13.OFPActionOutput(port_no)],data=data)
p.send_msg(out)
示例13: lldp_packet
def lldp_packet(dpid, port_no,
dl_addr, ttl, vport_no=ofproto_v1_0.OFPP_NONE):
pkt = packet.Packet()
dst = lldp.LLDP_MAC_NEAREST_BRIDGE
src = dl_addr
ethertype = ETH_TYPE_LLDP
eth_pkt = ethernet.ethernet(dst, src, ethertype)
pkt.add_protocol(eth_pkt)
tlv_chassis_id = lldp.ChassisID(
subtype=lldp.ChassisID.SUB_LOCALLY_ASSIGNED,
chassis_id=LLDPPacket.CHASSIS_ID_FMT %
dpid_to_str(dpid))
tlv_port_id = lldp.PortID(subtype=lldp.PortID.SUB_PORT_COMPONENT,
port_id=struct.pack(
LLDPPacket.PORT_ID_STR,
port_no))
tlv_ttl = lldp.TTL(ttl=ttl)
tlv_end = lldp.End()
tlvs = (tlv_chassis_id, tlv_port_id, tlv_ttl, tlv_end)
# Add LLDPDU for OXP.
if CONF.oxp_role is not None:
tlv_domain_id = lldp.DomainID(
subtype=lldp.DomainID.SUB_LOCALLY_ASSIGNED,
domain_id=LLDPPacket.DOMAIN_ID_FMT %
dpid_to_str(CONF.oxp_domain_id))
tlv_vport_id = lldp.VPortID(
subtype=lldp.VPortID.SUB_PORT_COMPONENT,
vport_id=struct.pack(
LLDPPacket.VPORT_ID_STR, vport_no))
tlvs = (tlv_chassis_id, tlv_port_id, tlv_ttl,
tlv_domain_id, tlv_vport_id, tlv_end)
lldp_pkt = lldp.lldp(tlvs)
pkt.add_protocol(lldp_pkt)
pkt.serialize()
return pkt.data
示例14: lldp_beacon
def lldp_beacon(eth_src, chassis_id, port_id, ttl, org_tlvs=None,
system_name=None, port_descr=None):
"""Return an LLDP frame suitable for a host/access port.
Args:
eth_src (str): source Ethernet MAC address.
chassis_id (str): Chassis ID.
port_id (int): port ID,
TTL (int): TTL for payload.
org_tlvs (list): list of tuples of (OUI, subtype, info).
Returns:
ryu.lib.packet.ethernet: Ethernet packet with header.
"""
pkt = build_pkt_header(
None, eth_src, lldp.LLDP_MAC_NEAREST_BRIDGE, valve_of.ether.ETH_TYPE_LLDP)
tlvs = [
lldp.ChassisID(
subtype=lldp.ChassisID.SUB_MAC_ADDRESS,
chassis_id=addrconv.mac.text_to_bin(chassis_id)),
lldp.PortID(
subtype=lldp.PortID.SUB_INTERFACE_NAME,
port_id=str(port_id).encode('utf-8')),
lldp.TTL(
ttl=ttl)
]
for tlv, info_name, info in (
(lldp.SystemName, 'system_name', system_name),
(lldp.PortDescription, 'port_description', port_descr)):
if info is not None:
info_args = {info_name: info.encode('UTF-8')}
tlvs.append(tlv(**info_args))
if org_tlvs is not None:
for tlv_oui, tlv_subtype, tlv_info in org_tlvs:
tlvs.append(
lldp.OrganizationallySpecific(
oui=tlv_oui,
subtype=tlv_subtype,
info=tlv_info))
tlvs.append(lldp.End())
lldp_pkt = lldp.lldp(tlvs)
pkt.add_protocol(lldp_pkt)
pkt.serialize()
return pkt
示例15: lldp_packet
def lldp_packet(dpid, port_no, dl_addr, ttl, vlan_vid):
# by jesse : add vlan
if vlan_vid != VLANID_NONE:
ether_proto = ETH_TYPE_8021Q
pcp = 0
cfi = 0
vlan_ether = ETH_TYPE_LLDP
v = vlan.vlan(pcp, cfi, vlan_vid, vlan_ether)
dst = lldp.LLDP_MAC_NEAREST_BRIDGE
src = dl_addr
pkt = packet.Packet()
e = ethernet.ethernet(dst, src, ether_proto)
pkt.add_protocol(e)
pkt.add_protocol(v)
else:
pkt = packet.Packet()
dst = lldp.LLDP_MAC_NEAREST_BRIDGE
src = dl_addr
ethertype = ETH_TYPE_LLDP
eth_pkt = ethernet.ethernet(dst, src, ethertype)
pkt.add_protocol(eth_pkt)
tlv_chassis_id = lldp.ChassisID(
subtype=lldp.ChassisID.SUB_LOCALLY_ASSIGNED,
chassis_id=LLDPPacket.CHASSIS_ID_FMT %
dpid_to_str(dpid))
tlv_port_id = lldp.PortID(subtype=lldp.PortID.SUB_PORT_COMPONENT,
port_id=struct.pack(
LLDPPacket.PORT_ID_STR,
port_no))
tlv_ttl = lldp.TTL(ttl=ttl)
tlv_end = lldp.End()
tlvs = (tlv_chassis_id, tlv_port_id, tlv_ttl, tlv_end)
lldp_pkt = lldp.lldp(tlvs)
pkt.add_protocol(lldp_pkt)
pkt.serialize()
return pkt.data