本文整理汇总了Python中ryu.lib.packet.ipv6.hop_opts函数的典型用法代码示例。如果您正苦于以下问题:Python hop_opts函数的具体用法?Python hop_opts怎么用?Python hop_opts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hop_opts函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp_with_hop_opts
def setUp_with_hop_opts(self):
self.opt1_type = 5
self.opt1_len = 2
self.opt1_data = '\x00\x00'
self.opt2_type = 1
self.opt2_len = 0
self.opt2_data = None
self.options = [
ipv6.option(self.opt1_type, self.opt1_len, self.opt1_data),
ipv6.option(self.opt2_type, self.opt2_len, self.opt2_data),
]
self.hop_opts_nxt = 6
self.hop_opts_size = 0
self.hop_opts = ipv6.hop_opts(
self.hop_opts_nxt, self.hop_opts_size, self.options)
self.ext_hdrs = [self.hop_opts]
self.payload_length += len(self.hop_opts)
self.nxt = ipv6.hop_opts.TYPE
self.ip = ipv6.ipv6(
self.version, self.traffic_class, self.flow_label,
self.payload_length, self.nxt, self.hop_limit, self.src,
self.dst, self.ext_hdrs)
self.buf = struct.pack(
ipv6.ipv6._PACK_STR, self.v_tc_flow,
self.payload_length, self.nxt, self.hop_limit,
addrconv.ipv6.text_to_bin(self.src),
addrconv.ipv6.text_to_bin(self.dst))
self.buf += self.hop_opts.serialize()
示例2: test_default_args
def test_default_args(self):
ip = ipv6.ipv6()
buf = ip.serialize(bytearray(), None)
res = struct.unpack(ipv6.ipv6._PACK_STR, str(buf))
eq_(res[0], 6 << 28)
eq_(res[1], 0)
eq_(res[2], 6)
eq_(res[3], 255)
eq_(res[4], addrconv.ipv6.text_to_bin('::'))
eq_(res[5], addrconv.ipv6.text_to_bin('::'))
# with extension header
ip = ipv6.ipv6(
nxt=0, ext_hdrs=[
ipv6.hop_opts(58, 0, [
ipv6.option(5, 2, '\x00\x00'),
ipv6.option(1, 0, None)])])
buf = ip.serialize(bytearray(), None)
res = struct.unpack(ipv6.ipv6._PACK_STR + '8s', str(buf))
eq_(res[0], 6 << 28)
eq_(res[1], 8)
eq_(res[2], 0)
eq_(res[3], 255)
eq_(res[4], addrconv.ipv6.text_to_bin('::'))
eq_(res[5], addrconv.ipv6.text_to_bin('::'))
eq_(res[6], '\x3a\x00\x05\x02\x00\x00\x01\x00')
示例3: create_packet
def create_packet(self, src, dst, srcip, dstip, mld):
self.logger.debug("")
# ETHER
eth = ethernet.ethernet(
# ethertype=ether.ETH_TYPE_8021Q, dst=dst, src=src)
ethertype=ether.ETH_TYPE_IPV6, dst=dst, src=src)
# TODO
"""
# VLAN
vln = vlan.vlan(vid=100, ethertype=ether.ETH_TYPE_IPV6)
"""
# IPV6 with Hop-By-Hop
ext_headers = [ipv6.hop_opts(nxt=inet.IPPROTO_ICMPV6,
data=[ipv6.option(type_=5, len_=2, data="\x00\x00"),
ipv6.option(type_=1, len_=0)])]
ip6 = ipv6.ipv6(src=srcip, dst=dstip, hop_limit=1,
nxt=inet.IPPROTO_HOPOPTS, ext_hdrs=ext_headers)
# MLDV2
if type(mld) == icmpv6.mldv2_query:
icmp6 = icmpv6_extend(
type_=icmpv6.MLD_LISTENER_QUERY, data=mld)
elif type(mld) == icmpv6.mldv2_report:
icmp6 = icmpv6_extend(
type_=icmpv6.MLDV2_LISTENER_REPORT, data=mld)
# ether - vlan - ipv6 - icmpv6 ( - mldv2 )
# sendpkt = eth / vln / ip6 / icmp6
sendpkt = eth / ip6 / icmp6
sendpkt.serialize()
self.logger.debug("created packet(ryu) : %s", str(sendpkt))
return sendpkt
示例4: create_packet
def create_packet(self, vid, mld):
self.logger.debug("")
# VLAN
vln = vlan.vlan(vid=vid, ethertype=ether.ETH_TYPE_IPV6)
# Hop-By-Hop
ext_headers = [ipv6.hop_opts(nxt=inet.IPPROTO_ICMPV6, data=[
ipv6.option(type_=5, len_=2, data="\x00\x00"),
ipv6.option(type_=1, len_=0)])]
# MLDV2_Query
if type(mld) == icmpv6.mldv2_query:
eth_dst = self.QUERY_DST
ip_dst = self.QUERY_DST_IP
if mld.address != "::":
ip_str = netaddr.ip.IPAddress(mld.address).\
format(netaddr.ipv6_verbose())
eth_dst = "33:33:" + ip_str[30:32] + ":" + \
ip_str[32:34] + ":" + ip_str[35:37] + ":" + ip_str[37:39]
ip_dst = mld.address
# ETHER
eth = ethernet.ethernet(
ethertype=ether.ETH_TYPE_8021Q,
src=self.ifinfo[self.IF_KEY_MAC], dst=eth_dst)
# IPV6 with ExtensionHeader
ip6 = ipv6.ipv6(
src=self.ifinfo[self.IF_KEY_IP6], dst=ip_dst,
hop_limit=1, nxt=inet.IPPROTO_HOPOPTS, ext_hdrs=ext_headers)
# MLD Query
icmp6 = icmpv6_extend(
type_=icmpv6.MLD_LISTENER_QUERY, data=mld)
# MLDV2_Report
elif type(mld) == icmpv6.mldv2_report:
# ETHER
eth = ethernet.ethernet(
ethertype=ether.ETH_TYPE_8021Q,
src=self.ifinfo[self.IF_KEY_MAC], dst=self.REPORT_DST)
# IPV6 with ExtensionHeader
ip6 = ipv6.ipv6(
src=self.ifinfo[self.IF_KEY_IP6], dst=self.REPORT_DST_IP,
hop_limit=1, nxt=inet.IPPROTO_HOPOPTS, ext_hdrs=ext_headers)
# MLD Report
icmp6 = icmpv6_extend(
type_=icmpv6.MLDV2_LISTENER_REPORT, data=mld)
# ether - vlan - ipv6 - icmpv6 ( - mldv2 )
sendpkt = eth / vln / ip6 / icmp6
sendpkt.serialize()
self.logger.debug("created packet(ryu) : %s", str(sendpkt))
return sendpkt
示例5: setUp
def setUp(self):
self.nxt = 0
self.size = 8
self.data = [
ipv6.option(5, 2, '\x00\x00'),
ipv6.option(1, 0, None),
ipv6.option(0xc2, 4, '\x00\x01\x00\x00'),
ipv6.option(1, 0, None),
]
self.hop = ipv6.hop_opts(self.nxt, self.size, self.data)
self.form = '!BB'
self.buf = struct.pack(self.form, self.nxt, self.size) \
+ self.data[0].serialize() \
+ self.data[1].serialize() \
+ self.data[2].serialize() \
+ self.data[3].serialize()
示例6: test_create_packet
def test_create_packet(self):
addressinfo = ["00:11:22:33:44:55", "66:55:44:33:22:11",
"1111::2222", "9999::8888"]
eth = ethernet.ethernet(
ethertype=ether.ETH_TYPE_IPV6,
src=addressinfo[0], dst=addressinfo[1])
ext_headers = [ipv6.hop_opts(nxt=inet.IPPROTO_ICMPV6,
data=[ipv6.option(type_=5, len_=2, data="\x00\x00"),
ipv6.option(type_=1, len_=0)])]
ip6 = ipv6.ipv6(src=addressinfo[2], dst=addressinfo[3],
hop_limit=1, nxt=inet.IPPROTO_HOPOPTS,
ext_hdrs=ext_headers)
mld = icmpv6.mldv2_query(address="1234::6789",
srcs=["9876::4321"])
icmp6 = icmpv6_extend(
type_=icmpv6.MLD_LISTENER_QUERY, data=mld)
expect = eth / ip6 / icmp6
expect.serialize()
actual = self.mld_proc.create_packet(addressinfo, mld)
exp_eth = expect.get_protocols(ethernet.ethernet)
exp_ip6 = expect.get_protocols(ipv6.ipv6)
exp_extend = exp_ip6[0]
exp_icmp6 = expect.get_protocols(icmpv6.icmpv6)
exp_mld = exp_icmp6[0].data
act_eth = actual.get_protocols(ethernet.ethernet)
act_ip6 = actual.get_protocols(ipv6.ipv6)
act_extend = act_ip6[0].ext_hdrs
act_icmp6 = actual.get_protocols(icmpv6.icmpv6)
act_mld = act_icmp6[0].data
# TODO 確認方法
eq_(expect.data, actual.data)
"""
示例7: setUp_with_multi_headers
def setUp_with_multi_headers(self):
self.opt1_type = 5
self.opt1_len = 2
self.opt1_data = '\x00\x00'
self.opt2_type = 1
self.opt2_len = 0
self.opt2_data = None
self.options = [
ipv6.option(self.opt1_type, self.opt1_len, self.opt1_data),
ipv6.option(self.opt2_type, self.opt2_len, self.opt2_data),
]
self.hop_opts_nxt = ipv6.auth.TYPE
self.hop_opts_size = 0
self.hop_opts = ipv6.hop_opts(
self.hop_opts_nxt, self.hop_opts_size, self.options)
self.auth_nxt = 6
self.auth_size = 4
self.auth_spi = 256
self.auth_seq = 1
self.auth_data = '\xa0\xe7\xf8\xab\xf9\x69\x1a\x8b\xf3\x9f\x7c\xae'
self.auth = ipv6.auth(
self.auth_nxt, self.auth_size, self.auth_spi, self.auth_seq,
self.auth_data)
self.ext_hdrs = [self.hop_opts, self.auth]
self.payload_length += len(self.hop_opts) + len(self.auth)
self.nxt = ipv6.hop_opts.TYPE
self.ip = ipv6.ipv6(
self.version, self.traffic_class, self.flow_label,
self.payload_length, self.nxt, self.hop_limit, self.src,
self.dst, self.ext_hdrs)
self.buf = struct.pack(
ipv6.ipv6._PACK_STR, self.v_tc_flow,
self.payload_length, self.nxt, self.hop_limit,
addrconv.ipv6.text_to_bin(self.src),
addrconv.ipv6.text_to_bin(self.dst))
self.buf += self.hop_opts.serialize()
self.buf += self.auth.serialize()
示例8: test_invalid_size
def test_invalid_size(self):
ipv6.hop_opts(self.nxt, 1, self.data)