def setUp_with_dst_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.dst_opts_nxt = 6
     self.dst_opts_size = 0
     self.dst_opts = ipv6.dst_opts(
         self.dst_opts_nxt, self.dst_opts_size, self.options)
     self.ext_hdrs = [self.dst_opts]
     self.payload_length += len(self.dst_opts)
     self.nxt = ipv6.dst_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.dst_opts.serialize()
Esempio n. 2
0
    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')
Esempio n. 3
0
 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()
Esempio n. 4
0
    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
    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')
Esempio n. 6
0
 def setUp_with_dst_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.dst_opts_nxt = 6
     self.dst_opts_size = 0
     self.dst_opts = ipv6.dst_opts(self.dst_opts_nxt, self.dst_opts_size,
                                   self.options)
     self.ext_hdrs = [self.dst_opts]
     self.payload_length += len(self.dst_opts)
     self.nxt = ipv6.dst_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.dst_opts.serialize()
Esempio n. 7
0
    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
Esempio n. 8
0
 def setUp(self):
     self.nxt = 60
     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.dst = ipv6.dst_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()
Esempio n. 9
0
 def setUp(self):
     self.type_ = 1
     self.len_ = 0
     self.data = None
     self.opt = ipv6.option(self.type_, self.len_, self.data)
     self.form = '!BB'
     self.buf = struct.pack(self.form, self.type_, self.len_)
 def setUp(self):
     self.type_ = 1
     self.len_ = 0
     self.data = None
     self.opt = ipv6.option(self.type_, self.len_, self.data)
     self.form = '!BB'
     self.buf = struct.pack(self.form, self.type_, self.len_)
 def setUp(self):
     self.type_ = 5
     self.data = '\x00\x00'
     self.len_ = len(self.data)
     self.opt = ipv6.option(self.type_, self.len_, self.data)
     self.form = '!BB%ds' % self.len_
     self.buf = struct.pack(self.form, self.type_, self.len_, self.data)
 def setUp(self):
     self.nxt = 60
     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.dst = ipv6.dst_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()
Esempio n. 13
0
 def setUp(self):
     self.type_ = 5
     self.data = '\x00\x00'
     self.len_ = len(self.data)
     self.opt = ipv6.option(self.type_, self.len_, self.data)
     self.form = '!BB%ds' % self.len_
     self.buf = struct.pack(self.form, self.type_, self.len_, self.data)
    def test_default_args(self):
        hdr = ipv6.dst_opts()
        buf = hdr.serialize()
        res = struct.unpack('!BB', str(buf[:2]))

        eq_(res[0], 6)
        eq_(res[1], 0)
        opt = ipv6.option(type_=1, len_=6, data='\x00\x00\x00\x00\x00\x00')
        eq_(str(buf[2:]), opt.serialize())
Esempio n. 15
0
    def test_default_args(self):
        hdr = ipv6.dst_opts()
        buf = hdr.serialize()
        res = struct.unpack('!BB', str(buf[:2]))

        eq_(res[0], 6)
        eq_(res[1], 0)
        opt = ipv6.option(type_=1, len_=4, data='\x00\x00\x00\x00')
        eq_(str(buf[2:]), opt.serialize())
Esempio n. 16
0
    def test_default_args(self):
        hdr = ipv6.hop_opts()
        buf = hdr.serialize()
        res = struct.unpack('!BB', six.binary_type(buf[:2]))

        eq_(res[0], 6)
        eq_(res[1], 0)
        opt = ipv6.option(type_=1, len_=4, data=b'\x00\x00\x00\x00')
        eq_(six.binary_type(buf[2:]), opt.serialize())
Esempio n. 17
0
    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)
        """
 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()
    def test_default_args(self):
        opt = ipv6.option()
        buf = opt.serialize()
        res = struct.unpack('!B', buf)

        eq_(res[0], 0)
Esempio n. 20
0
    def test_default_args(self):
        opt = ipv6.option()
        buf = opt.serialize()
        res = struct.unpack('!B', buf)

        eq_(res[0], 0)