本文整理匯總了Python中ryu.lib.packet.packet.Packet方法的典型用法代碼示例。如果您正苦於以下問題:Python packet.Packet方法的具體用法?Python packet.Packet怎麽用?Python packet.Packet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ryu.lib.packet.packet
的用法示例。
在下文中一共展示了packet.Packet方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: internal_host_route_handler
# 需要導入模塊: from ryu.lib.packet import packet [as 別名]
# 或者: from ryu.lib.packet.packet import Packet [as 別名]
def internal_host_route_handler(self, ev):
'''
Handle internal network host routing
'''
msg = ev.msg
dp = msg.datapath
dpid = dp.id
ofproto = dp.ofproto
pkt = packet.Packet(msg.data)
ipv4_header = pkt.get_protocol(ipv4.ipv4)
src_ip = ipv4_header.src
dst_ip = ipv4_header.dst
if not self.cfg_mgr.is_internal_host(dst_ip):
return
self.install_internal_host_path(dst_ip)
示例2: packet_print
# 需要導入模塊: from ryu.lib.packet import packet [as 別名]
# 或者: from ryu.lib.packet.packet import Packet [as 別名]
def packet_print(self, pkt):
pkt = packet.Packet(array.array('B', pkt))
eth = pkt.get_protocol(ethernet.ethernet)
_ipv4 = pkt.get_protocol(ipv4.ipv4)
_icmp = pkt.get_protocol(icmp.icmp)
if _icmp:
self.logger.info("%r", _icmp)
if _ipv4:
self.logger.info("%r", _ipv4)
if eth:
self.logger.info("%r", eth)
# for p in pkt.protocols:
# if hasattr(p, 'protocol_name') is False:
# break
# print('p: %s' % p.protocol_name)
示例3: switch_features_handler
# 需要導入模塊: from ryu.lib.packet import packet [as 別名]
# 或者: from ryu.lib.packet.packet import Packet [as 別名]
def switch_features_handler(self, ev):
datapath = ev.msg.datapath
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
# install table-miss flow entry
#
# We specify NO BUFFER to max_len of the output action due to
# OVS bug. At this moment, if we specify a lesser number, e.g.,
# 128, OVS will send Packet-In with invalid buffer_id and
# truncated packet data. In that case, we cannot output packets
# correctly.
match = parser.OFPMatch()
actions = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER,
ofproto.OFPCML_NO_BUFFER)]
self.add_flow(datapath, 0, match, actions)
示例4: switch_features_handler
# 需要導入模塊: from ryu.lib.packet import packet [as 別名]
# 或者: from ryu.lib.packet.packet import Packet [as 別名]
def switch_features_handler(self, ev):
datapath = ev.msg.datapath
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
# install table-miss flow entry
#
# We specify NO BUFFER to max_len of the output action due to
# OVS bug. At this moment, if we specify a lesser number, e.g.,
# 128, OVS will send Packet-In with invalid buffer_id and
# truncated packet data. In that case, we cannot output packets
# correctly. The bug has been fixed in OVS v2.1.0.
match = parser.OFPMatch()
actions = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER,
ofproto.OFPCML_NO_BUFFER)]
self.add_flow(datapath, 0, match, actions)
示例5: packet_in_handler
# 需要導入模塊: from ryu.lib.packet import packet [as 別名]
# 或者: from ryu.lib.packet.packet import Packet [as 別名]
def packet_in_handler(self, msg):
pkt = packet.Packet(msg.data)
# TODO: Packet library convert to string
# self.logger.debug('Packet in = %s', str(pkt), self.sw_id)
header_list = dict((p.protocol_name, p)
for p in pkt.protocols if type(p) != str)
if header_list:
# Check vlan-tag
vlan_id = VLANID_NONE
if VLAN in header_list:
vlan_id = header_list[VLAN].vid
# Event dispatch
if vlan_id in self:
self[vlan_id].packet_in_handler(msg, header_list)
else:
self.logger.debug('Drop unknown vlan packet. [vlan_id=%d]',
vlan_id, extra=self.sw_id)
示例6: _arp_reply_packet
# 需要導入模塊: from ryu.lib.packet import packet [as 別名]
# 或者: from ryu.lib.packet.packet import Packet [as 別名]
def _arp_reply_packet(self, arp_req_sha, arp_req_spa, arp_req_tpa):
if not (arp_req_tpa in self.config.ip_addresses or
arp_req_tpa == self.config.primary_ip_address):
return None
src_mac = vrrp.vrrp_ipv4_src_mac_address(self.config.vrid)
e = ethernet.ethernet(arp_req_sha, src_mac, ether.ETH_TYPE_ARP)
a = arp.arp_ip(arp.ARP_REPLY, src_mac, arp_req_tpa,
arp_req_sha, arp_req_spa)
p = packet.Packet()
p.add_protocol(e)
utils.may_add_vlan(p, self.interface.vlan_id)
p.add_protocol(a)
p.serialize()
self._transmit(p.data)
示例7: test_serialize
# 需要導入模塊: from ryu.lib.packet import packet [as 別名]
# 或者: from ryu.lib.packet.packet import Packet [as 別名]
def test_serialize(self):
pkt = packet.Packet()
eth_pkt = ethernet.ethernet('b0:a8:6e:18:b8:08', '64:87:88:e9:cb:c8')
pkt.add_protocol(eth_pkt)
ip_pkt = ipv4.ipv4(src='172.28.3.1', dst='172.28.3.2', tos=192,
identification=26697, proto=inet.IPPROTO_UDP)
pkt.add_protocol(ip_pkt)
udp_pkt = udp.udp(49152, 3784)
pkt.add_protocol(udp_pkt)
bfd_pkt = bfd.bfd(ver=1, diag=bfd.BFD_DIAG_CTRL_DETECT_TIME_EXPIRED,
state=bfd.BFD_STATE_UP, detect_mult=3, my_discr=6,
your_discr=7, desired_min_tx_interval=60000,
required_min_rx_interval=60000,
required_min_echo_rx_interval=0)
pkt.add_protocol(bfd_pkt)
eq_(len(pkt.protocols), 4)
pkt.serialize()
eq_(pkt.data, self.data)
示例8: test_serialize
# 需要導入模塊: from ryu.lib.packet import packet [as 別名]
# 或者: from ryu.lib.packet.packet import Packet [as 別名]
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)
示例9: _build_igmp
# 需要導入模塊: from ryu.lib.packet import packet [as 別名]
# 或者: from ryu.lib.packet.packet import Packet [as 別名]
def _build_igmp(self):
dl_dst = '11:22:33:44:55:66'
dl_src = 'aa:bb:cc:dd:ee:ff'
dl_type = ether.ETH_TYPE_IP
e = ethernet(dl_dst, dl_src, dl_type)
total_length = len(ipv4()) + len(self.g)
nw_proto = inet.IPPROTO_IGMP
nw_dst = '11.22.33.44'
nw_src = '55.66.77.88'
i = ipv4(total_length=total_length, src=nw_src, dst=nw_dst,
proto=nw_proto, ttl=1)
p = Packet()
p.add_protocol(e)
p.add_protocol(i)
p.add_protocol(self.g)
p.serialize()
return p
示例10: _generate_tcn_bpdu
# 需要導入模塊: from ryu.lib.packet import packet [as 別名]
# 或者: from ryu.lib.packet.packet import Packet [as 別名]
def _generate_tcn_bpdu(self):
src_mac = self.ofport.hw_addr
dst_mac = bpdu.BRIDGE_GROUP_ADDRESS
length = (bpdu.bpdu._PACK_LEN
+ bpdu.TopologyChangeNotificationBPDUs.PACK_LEN
+ llc.llc._PACK_LEN + llc.ControlFormatU._PACK_LEN)
e = ethernet.ethernet(dst_mac, src_mac, length)
l = llc.llc(llc.SAP_BPDU, llc.SAP_BPDU, llc.ControlFormatU())
b = bpdu.TopologyChangeNotificationBPDUs()
pkt = packet.Packet()
pkt.add_protocol(e)
pkt.add_protocol(l)
pkt.add_protocol(b)
pkt.serialize()
return pkt.data
示例11: bfd_parse
# 需要導入模塊: from ryu.lib.packet import packet [as 別名]
# 或者: from ryu.lib.packet.packet import Packet [as 別名]
def bfd_parse(data):
"""
Parse raw packet and return BFD class from packet library.
"""
pkt = packet.Packet(data)
i = iter(pkt)
eth_pkt = next(i)
assert type(eth_pkt) == ethernet.ethernet
ipv4_pkt = next(i)
assert type(ipv4_pkt) == ipv4.ipv4
udp_pkt = i.next()
assert type(udp_pkt) == udp.udp
udp_payload = next(i)
return bfd.bfd.parser(udp_payload)[0]
示例12: arp_parse
# 需要導入模塊: from ryu.lib.packet import packet [as 別名]
# 或者: from ryu.lib.packet.packet import Packet [as 別名]
def arp_parse(data):
"""
Parse ARP packet, return ARP class from packet library.
"""
# Iteratize pkt
pkt = packet.Packet(data)
i = iter(pkt)
eth_pkt = next(i)
# Ensure it's an ethernet frame.
assert type(eth_pkt) == ethernet.ethernet
arp_pkt = next(i)
if type(arp_pkt) != arp.arp:
raise ARPPacket.ARPUnknownFormat()
if arp_pkt.opcode not in (ARP_REQUEST, ARP_REPLY):
raise ARPPacket.ARPUnknownFormat(
msg='unsupported opcode %d' % arp_pkt.opcode)
if arp_pkt.proto != ETH_TYPE_IP:
raise ARPPacket.ARPUnknownFormat(
msg='unsupported arp ethtype 0x%04x' % arp_pkt.proto)
return arp_pkt
示例13: packet_in_handler
# 需要導入模塊: from ryu.lib.packet import packet [as 別名]
# 或者: from ryu.lib.packet.packet import Packet [as 別名]
def packet_in_handler(self, ev):
msg = ev.msg
datapath = msg.datapath
ofproto = datapath.ofproto
inPort = msg.match['in_port']
packet = Packet(msg.data)
etherFrame = packet.get_protocol(ethernet)
if etherFrame.ethertype == ether.ETH_TYPE_ARP:
self.receive_arp(datapath, packet, etherFrame, inPort)
elif etherFrame.ethertype == ether.ETH_TYPE_IP:
self.receive_ip(datapath, packet, etherFrame, inPort)
else:
LOG.debug("receive Unknown packet %s => %s (port%d)"
%(etherFrame.src, etherFrame.dst, inPort))
self.print_etherFrame(etherFrame)
LOG.debug("Drop packet")
return 1
return 0
示例14: send_icmp
# 需要導入模塊: from ryu.lib.packet import packet [as 別名]
# 或者: from ryu.lib.packet.packet import Packet [as 別名]
def send_icmp(self, datapath, srcMac, srcIp, dstMac, dstIp, outPort, seq, data, id=1, type=8, ttl=64):
e = ethernet(dstMac, srcMac, ether.ETH_TYPE_IP)
iph = ipv4(4, 5, 0, 0, 0, 2, 0, ttl, 1, 0, srcIp, dstIp)
echo = icmp.echo(id, seq, data)
icmph = icmp.icmp(type, 0, 0, echo)
p = Packet()
p.add_protocol(e)
p.add_protocol(iph)
p.add_protocol(icmph)
p.serialize()
actions = [datapath.ofproto_parser.OFPActionOutput(outPort, 0)]
out = datapath.ofproto_parser.OFPPacketOut(
datapath=datapath,
buffer_id=0xffffffff,
in_port=datapath.ofproto.OFPP_CONTROLLER,
actions=actions,
data=p.data)
datapath.send_msg(out)
return 0
示例15: packet_in_handler
# 需要導入模塊: from ryu.lib.packet import packet [as 別名]
# 或者: from ryu.lib.packet.packet import Packet [as 別名]
def packet_in_handler(self, ev):
msg = ev.msg
datapath = msg.datapath
ofproto = datapath.ofproto
inPort = msg.match['in_port']
packet = Packet(msg.data)
etherFrame = packet.get_protocol(ethernet)
if etherFrame.ethertype == ether.ETH_TYPE_ARP:
self.receive_arp(datapath, packet, etherFrame, inPort)
elif etherFrame.ethertype == ether.ETH_TYPE_IP:
self.receive_ip(datapath, packet, etherFrame, inPort)
else:
LOG.debug("receive Unknown packet %s => %s (port%d)"
%(etherFrame.src, etherFrame.dst, inPort))
self.print_etherFrame(etherFrame)
LOG.debug("Drop packet")
return 0