本文整理汇总了Python中ryu.lib.packet.lldp.lldp函数的典型用法代码示例。如果您正苦于以下问题:Python lldp函数的具体用法?Python lldp怎么用?Python lldp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了lldp函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:nike1000,项目名称:Lab_code,代码行数:26,代码来源:RYU_APP_v2.py
示例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
开发者ID:AsmaSwapna,项目名称:ryu,代码行数:28,代码来源:switches.py
示例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)
开发者ID:5g-empower,项目名称:empower-ryu,代码行数:33,代码来源:test_lldp.py
示例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)
开发者ID:nike1000,项目名称:Lab_code,代码行数:28,代码来源:Generic_Agent_CHT.py
示例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)
开发者ID:StephenKing,项目名称:summerschool-2015-ryu,代码行数:55,代码来源:test_lldp.py
示例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
开发者ID:nooruddin,项目名称:sdn-fabric,代码行数:32,代码来源:packet.py
示例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
开发者ID:illotum,项目名称:sdn-fabric,代码行数:30,代码来源:packet.py
示例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))
开发者ID:StephenKing,项目名称:summerschool-2015-ryu,代码行数:29,代码来源:test_lldp.py
示例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:])
开发者ID:StephenKing,项目名称:summerschool-2015-ryu,代码行数:12,代码来源:test_lldp.py
示例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)])
开发者ID:StephenKing,项目名称:summerschool-2015-ryu,代码行数:46,代码来源:test_lldp.py
示例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)
开发者ID:nike1000,项目名称:Lab_code,代码行数:18,代码来源:hw3_ryuapp.py
示例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)
开发者ID:gu9,项目名称:mycontroller,代码行数:18,代码来源:saini2.py
示例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
开发者ID:Jasonlyt,项目名称:ryu,代码行数:44,代码来源:switches.py
示例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
开发者ID:trungdtbk,项目名称:faucet,代码行数:43,代码来源:valve_packet.py
示例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
开发者ID:linuxxunil,项目名称:ys-ryu,代码行数:42,代码来源:ys_switches.py
示例16: create_discovery_packet
def create_discovery_packet (self, dpid, port_no, dl_addr):
"""
Build discovery packet
"""
CHASSIS_ID_PREFIX = 'dpid:'
#CHASSIS_ID_PREFIX_LEN = len(CHASSIS_ID_PREFIX)
CHASSIS_ID_FMT = CHASSIS_ID_PREFIX + '%s'
PORT_ID_STR = '!I' # uint32_t
pkt = packet.Packet()
dst = lldp.LLDP_MAC_NEAREST_BRIDGE
src = dl_addr
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_LOCALLY_ASSIGNED,
chassis_id=CHASSIS_ID_FMT %
dpid_to_str(dpid))
tlv_port_id = lldp.PortID(subtype=lldp.PortID.SUB_PORT_COMPONENT,
port_id=struct.pack(
PORT_ID_STR,
port_no))
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)
pkt.serialize()
return pkt.data
开发者ID:ChristosKon,项目名称:pyretic-IPv6,代码行数:41,代码来源:ryu_shim.py
示例17: test_serialize
def test_serialize(self):
pkt = packet.Packet()
dst = lldp.LLDP_MAC_NEAREST_BRIDGE
src = '\x00\x04\x96\x1f\xa7\x26'
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=src)
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)
pkt.add_protocol(lldp_pkt)
eq_(len(pkt.protocols), 2)
pkt.serialize()
eq_(pkt.data, self.data)
开发者ID:watanabefumitaka,项目名称:src,代码行数:23,代码来源:test_lldp.py
示例18: 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()
eq_(pkt.data, self.data)
开发者ID:Aries-Sushi,项目名称:ryu,代码行数:24,代码来源:test_lldp.py
示例19: create_discovery_packet
def create_discovery_packet (self, dpid, port_num, port_addr):
"""
Build discovery packet
"""
pkt = packet.Packet()
print "create_discovery_packet"
chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_LOCALLY_ASSIGNED, chassis_id = bytes('dpid:' + hex(long(dpid))[2:-1]))
#chassis_id.chassis_id = bytes('dpid:' + hex(long(dpid))[2:-1])
print "create_discovery_packet - chassis_id" , chassis_id
port_id = lldp.PortID(subtype=lldp.PortID.SUB_LOCALLY_ASSIGNED, port_id=str(port_num))
print "create_discovery_packet - port_id" , port_id
ttl = lldp.TTL(ttl = 120)
print "create_discovery_packet - ttl" , ttl
tlvs = (chassis_id, port_id, ttl, lldp.End())
lldp_pkt = lldp.lldp(tlvs)
pkt.add_protocol(lldp_pkt)
print "create_discovery_packet: discovery_packet", lldp_pkt
dst = lldp.LLDP_MAC_NEAREST_BRIDGE
src = port_addr
ethertype = ether.ETH_TYPE_LLDP
eth_pkt = ethernet.ethernet(dst, src, ethertype)
pkt.add_protocol(eth_pkt)
pkt.serialize()
datapath = self.switches[dpid]['connection']
print "datapath.id", datapath.id
print "datapath.ofproto", datapath.ofproto.OFP_VERSION
po_actions = [datapath.ofproto_parser.OFPActionOutput(port_num)]
print "po_actions", po_actions
# TODO: the returned pkt_out is NULL. We need to investigate why.
pkt_out = datapath.ofproto_parser.OFPPacketOut(datapath=datapath, in_port=datapath.ofproto.OFPP_CONTROLLER, buffer_id=datapath.ofproto.OFP_NO_BUFFER,
actions=po_actions, data=pkt.data)
return pkt_out
开发者ID:fp7-netide,项目名称:Usecases,代码行数:36,代码来源:ryu_client.py
示例20: build_OFP_payload
def build_OFP_payload(desc,msg_type,port_no=0,switch=None,dpid=None,data=None,packet=None,buffer_id=None):
#openflow hello
ofproto = desc.ofproto
parser = desc.ofproto_parser
if msg_type == ofproto.OFPT_HELLO:
#print 'ofp hello'
payload = parser.OFPHello(desc)
#openflow echo
if msg_type == ofproto.OFPT_ECHO_REQUEST:
#print 'ofp echo reply'
payload = parser.OFPEchoReply(desc,data='hello')
#openflow flow mod
if msg_type == ofproto.OFPT_FLOW_MOD:
#print 'ofp flow mod'
match = parser.OFPMatch()
#openflow1.3
actions = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER,ofproto.OFPCML_NO_BUFFER)]
#openflow1.0
#actions = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER)]
#openflow1.3
inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,actions)]
payload = parser.OFPFlowMod(desc,priority=0,match=match,instructions=inst)
#openflow1.0
#payload = parser.OFPFlowMod(desc,priority=0,match=match,actions=actions)
if msg_type == ADD_LLDP_RULE:
match = parser.OFPMatch(eth_type=ether_types.ETH_TYPE_LLDP)
actions = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER,
ofproto.OFPCML_NO_BUFFER)]
inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
actions)]
payload = parser.OFPFlowMod(desc,priority=65535,match=match,instructions=inst)
#openflow feature request
if msg_type == ofproto.OFPT_FEATURES_REQUEST:
#print 'ofp feature request'
payload = parser.OFPFeaturesRequest(desc)
if msg_type == ofproto.OFPT_MULTIPART_REQUEST:
#print 'OFPT_MULTIPART_REQUEST'
payload = parser.OFPPortDescStatsRequest(desc)
if msg_type == SEND_LLDP_PACKET:
pkt = packet.Packet()
pkt.add_protocol(ethernet.ethernet(ethertype=ether_types.ETH_TYPE_LLDP, src=switch['port'][port_no][0], dst=lldp.LLDP_MAC_NEAREST_BRIDGE))
tlv_chassis_id = lldp.ChassisID(subtype=lldp.ChassisID.SUB_LOCALLY_ASSIGNED, chassis_id=dpid)
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
actions=[parser.OFPActionOutput(port=port_no)]
payload = parser.OFPPacketOut(datapath=desc, buffer_id=ofproto.OFP_NO_BUFFER,
in_port=ofproto.OFPP_CONTROLLER, actions=actions, data=data)
if msg_type == SEND_PACKET_OUT:
actions = [parser.OFPActionOutput(port=port_no)]
payload = parser.OFPPacketOut(datapath=desc, buffer_id=ofproto.OFP_NO_BUFFER,
in_port=ofproto.OFPP_CONTROLLER, actions=actions, data=data)
if msg_type == ARP_DROP_PACKET:
eth = packet.get_protocols(ethernet.ethernet)[0]
pkt_arp = packet.get_protocols(arp.arp)[0]
match = parser.OFPMatch(eth_src=eth.src,eth_type=ether_types.ETH_TYPE_ARP,arp_op=arp.ARP_REQUEST,arp_tpa=pkt_arp.dst_ip)
inst = [parser.OFPInstructionActions(ofproto.OFPIT_CLEAR_ACTIONS, [])]
payload = parser.OFPFlowMod(desc,priority=1,match=match,instructions=inst)
if msg_type == ARP_HIGH_PRIO:
eth = packet.get_protocols(ethernet.ethernet)[0]
pkt_arp = packet.get_protocols(arp.arp)[0]
match = parser.OFPMatch(eth_src=eth.src,eth_type=ether_types.ETH_TYPE_ARP,arp_op=arp.ARP_REQUEST,arp_tpa=pkt_arp.dst_ip,in_port=port_no)
actions = [parser.OFPActionOutput(ofproto.OFPP_ALL,ofproto.OFPCML_NO_BUFFER)]
inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
actions)]
payload = parser.OFPFlowMod(desc,priority=4,match=match,instructions=inst)
if msg_type == ARP_REPLY:
eth = packet.get_protocols(ethernet.ethernet)[0]
pkt_arp = packet.get_protocols(arp.arp)[0]
match = parser.OFPMatch(eth_dst=eth.src,eth_type=ether_types.ETH_TYPE_ARP,arp_op=arp.ARP_REPLY)
actions = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER,ofproto.OFPCML_NO_BUFFER),
parser.OFPActionOutput(port_no,ofproto.OFPCML_NO_BUFFER)]
inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
actions)]
payload = parser.OFPFlowMod(desc,priority=3,match=match,instructions=inst)
if msg_type == ARP_REMOVE:
eth = packet.get_protocols(ethernet.ethernet)[0]
pkt_arp = packet.get_protocols(arp.arp)[0]
match = parser.OFPMatch(eth_dst=eth.src,eth_type=ether_types.ETH_TYPE_ARP,arp_op=arp.ARP_REPLY)
actions = []
inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
#.........这里部分代码省略.........
开发者ID:jsjhan,项目名称:test,代码行数:101,代码来源:a.py
注:本文中的ryu.lib.packet.lldp.lldp函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论