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()
    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
0
파일: test_ipv6.py 프로젝트: qsdj/ryu
 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()
예제 #4
0
파일: test_ipv6.py 프로젝트: qsdj/ryu
    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')
예제 #5
0
파일: test_ipv6.py 프로젝트: qsdj/ryu
 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()
예제 #6
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
예제 #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
    def test_default_args(self):
        hdr = ipv6.hop_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())
예제 #9
0
파일: test_ipv6.py 프로젝트: qsdj/ryu
    def test_default_args(self):
        hdr = ipv6.hop_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())
 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()
예제 #11
0
파일: test_ipv6.py 프로젝트: qsdj/ryu
 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()
예제 #12
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_invalid_size(self):
     ipv6.hop_opts(self.nxt, 1, self.data)
예제 #15
0
파일: test_ipv6.py 프로젝트: qsdj/ryu
 def test_invalid_size(self):
     ipv6.hop_opts(self.nxt, 1, self.data)