本文整理汇总了Python中ryu.lib.packet.ethernet.ethernet方法的典型用法代码示例。如果您正苦于以下问题:Python ethernet.ethernet方法的具体用法?Python ethernet.ethernet怎么用?Python ethernet.ethernet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ryu.lib.packet.ethernet
的用法示例。
在下文中一共展示了ethernet.ethernet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: packet_print
# 需要导入模块: from ryu.lib.packet import ethernet [as 别名]
# 或者: from ryu.lib.packet.ethernet import ethernet [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)
示例2: _arp_reply_packet
# 需要导入模块: from ryu.lib.packet import ethernet [as 别名]
# 或者: from ryu.lib.packet.ethernet import ethernet [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)
示例3: test_serialize
# 需要导入模块: from ryu.lib.packet import ethernet [as 别名]
# 或者: from ryu.lib.packet.ethernet import ethernet [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)
示例4: test_build_sctp
# 需要导入模块: from ryu.lib.packet import ethernet [as 别名]
# 或者: from ryu.lib.packet.ethernet import ethernet [as 别名]
def test_build_sctp(self):
eth = ethernet.ethernet('00:aa:aa:aa:aa:aa', '00:bb:bb:bb:bb:bb',
ether.ETH_TYPE_IP)
ip4 = ipv4.ipv4(4, 5, 16, 0, 0, 2, 0, 64, inet.IPPROTO_SCTP, 0,
'192.168.1.1', '10.144.1.1')
pkt = eth / ip4 / self.sc
eth = pkt.get_protocol(ethernet.ethernet)
ok_(eth)
eq_(eth.ethertype, ether.ETH_TYPE_IP)
ip4 = pkt.get_protocol(ipv4.ipv4)
ok_(ip4)
eq_(ip4.proto, inet.IPPROTO_SCTP)
sc = pkt.get_protocol(sctp.sctp)
ok_(sc)
eq_(sc, self.sc)
示例5: test_build_arp_vlan
# 需要导入模块: from ryu.lib.packet import ethernet [as 别名]
# 或者: from ryu.lib.packet.ethernet import ethernet [as 别名]
def test_build_arp_vlan(self):
p = self._build_arp(True)
e = self.find_protocol(p, "ethernet")
ok_(e)
eq_(e.ethertype, ether.ETH_TYPE_8021Q)
v = self.find_protocol(p, "vlan")
ok_(v)
eq_(v.ethertype, ether.ETH_TYPE_ARP)
a = self.find_protocol(p, "arp")
ok_(a)
eq_(a.hwtype, self.hwtype)
eq_(a.proto, self.proto)
eq_(a.hlen, self.hlen)
eq_(a.plen, self.plen)
eq_(a.opcode, self.opcode)
eq_(a.src_mac, self.src_mac)
eq_(a.src_ip, self.src_ip)
eq_(a.dst_mac, self.dst_mac)
eq_(a.dst_ip, self.dst_ip)
示例6: test_build_arp_novlan
# 需要导入模块: from ryu.lib.packet import ethernet [as 别名]
# 或者: from ryu.lib.packet.ethernet import ethernet [as 别名]
def test_build_arp_novlan(self):
p = self._build_arp(False)
e = self.find_protocol(p, "ethernet")
ok_(e)
eq_(e.ethertype, ether.ETH_TYPE_ARP)
a = self.find_protocol(p, "arp")
ok_(a)
eq_(a.hwtype, self.hwtype)
eq_(a.proto, self.proto)
eq_(a.hlen, self.hlen)
eq_(a.plen, self.plen)
eq_(a.opcode, self.opcode)
eq_(a.src_mac, self.src_mac)
eq_(a.src_ip, self.src_ip)
eq_(a.dst_mac, self.dst_mac)
eq_(a.dst_ip, self.dst_ip)
示例7: test_build_mldv2_report
# 需要导入模块: from ryu.lib.packet import ethernet [as 别名]
# 或者: from ryu.lib.packet.ethernet import ethernet [as 别名]
def test_build_mldv2_report(self):
p = self._build_mldv2_report()
e = self.find_protocol(p, "ethernet")
ok_(e)
eq_(e.ethertype, ether.ETH_TYPE_IPV6)
i = self.find_protocol(p, "ipv6")
ok_(i)
eq_(i.nxt, inet.IPPROTO_ICMPV6)
ic = self.find_protocol(p, "icmpv6")
ok_(ic)
eq_(ic.type_, icmpv6.MLDV2_LISTENER_REPORT)
eq_(ic.data.record_num, self.record_num)
eq_(ic.data.records, self.records)
示例8: test_parse_without_ethernet
# 需要导入模块: from ryu.lib.packet import ethernet [as 别名]
# 或者: from ryu.lib.packet.ethernet import ethernet [as 别名]
def test_parse_without_ethernet(self):
buf = self.data[ethernet.ethernet._MIN_LEN:]
(lldp_pkt, cls, rest_buf) = lldp.lldp.parser(buf)
eq_(len(rest_buf), 0)
tlvs = lldp_pkt.tlvs
eq_(tlvs[0].tlv_type, lldp.LLDP_TLV_CHASSIS_ID)
eq_(tlvs[0].len, 7)
eq_(tlvs[0].subtype, lldp.ChassisID.SUB_MAC_ADDRESS)
eq_(tlvs[0].chassis_id, b'\x00\x04\x96\x1f\xa7\x26')
eq_(tlvs[1].tlv_type, lldp.LLDP_TLV_PORT_ID)
eq_(tlvs[1].len, 4)
eq_(tlvs[1].subtype, lldp.PortID.SUB_INTERFACE_NAME)
eq_(tlvs[1].port_id, b'1/3')
eq_(tlvs[2].tlv_type, lldp.LLDP_TLV_TTL)
eq_(tlvs[2].len, 2)
eq_(tlvs[2].ttl, 120)
eq_(tlvs[3].tlv_type, lldp.LLDP_TLV_END)
示例9: test_build_svlan
# 需要导入模块: from ryu.lib.packet import ethernet [as 别名]
# 或者: from ryu.lib.packet.ethernet import ethernet [as 别名]
def test_build_svlan(self):
p = self._build_svlan()
e = self.find_protocol(p, "ethernet")
ok_(e)
eq_(e.ethertype, ether.ETH_TYPE_8021AD)
sv = self.find_protocol(p, "svlan")
ok_(sv)
eq_(sv.ethertype, ether.ETH_TYPE_8021Q)
v = self.find_protocol(p, "vlan")
ok_(v)
eq_(v.ethertype, ether.ETH_TYPE_IP)
ip = self.find_protocol(p, "ipv4")
ok_(ip)
eq_(sv.pcp, self.pcp)
eq_(sv.cfi, self.cfi)
eq_(sv.vid, self.vid)
eq_(sv.ethertype, self.ethertype)
示例10: _build_igmp
# 需要导入模块: from ryu.lib.packet import ethernet [as 别名]
# 或者: from ryu.lib.packet.ethernet import ethernet [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 = 20 + igmp._MIN_LEN
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)
p = Packet()
p.add_protocol(e)
p.add_protocol(i)
p.add_protocol(self.g)
p.serialize()
return p
示例11: test_build_igmp
# 需要导入模块: from ryu.lib.packet import ethernet [as 别名]
# 或者: from ryu.lib.packet.ethernet import ethernet [as 别名]
def test_build_igmp(self):
p = self._build_igmp()
e = self.find_protocol(p, "ethernet")
ok_(e)
eq_(e.ethertype, ether.ETH_TYPE_IP)
i = self.find_protocol(p, "ipv4")
ok_(i)
eq_(i.proto, inet.IPPROTO_IGMP)
g = self.find_protocol(p, "igmp")
ok_(g)
eq_(g.msgtype, self.msgtype)
eq_(g.maxresp, self.maxresp)
eq_(g.csum, checksum(self.buf))
eq_(g.address, self.address)
示例12: _generate_tcn_bpdu
# 需要导入模块: from ryu.lib.packet import ethernet [as 别名]
# 或者: from ryu.lib.packet.ethernet import ethernet [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
示例13: arp_parse
# 需要导入模块: from ryu.lib.packet import ethernet [as 别名]
# 或者: from ryu.lib.packet.ethernet import ethernet [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
示例14: packet_in_handler
# 需要导入模块: from ryu.lib.packet import ethernet [as 别名]
# 或者: from ryu.lib.packet.ethernet import ethernet [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
示例15: send_icmp
# 需要导入模块: from ryu.lib.packet import ethernet [as 别名]
# 或者: from ryu.lib.packet.ethernet import ethernet [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