コード例 #1
0
ファイル: test323.py プロジェクト: ronyjah/tcc_ronaldo
class Test323a:
    def __init__(self, config, app):
        self.__app = app
        self.__queue_wan = Queue()
        self.__queue_lan = Queue()
        self.__config = config
        self.__interface = None
        self.__pkt = None
        self.__local_addr_ceRouter = None
        self.__sendmsgs = SendMsgs(self.__config)
        self.__config_setup1_1 = ConfigSetup1_1(self.__config)
        #self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config)
        self.__wan_device_tr1 = self.__config.get('wan', 'device_wan_tr1')
        self.__lan_device = self.__config.get('lan', 'lan_device')
        self.__wan_mac_tr1 = self.__config.get('wan', 'wan_mac_tr1')
        self.__link_local_addr = self.__config.get('wan', 'link_local_addr')
        self.__all_nodes_addr = self.__config.get('multicast',
                                                  'all_nodes_addr')
        self.__test_desc = self.__config.get('tests', '3.2.3a')
        self.__t_lan = None
        self.__finish_wan = False
        self.part2_lan_start = False
        self.__dhcp_renew_done = False
        self.stop_ping_OK = False
        self.msg = self.__config.get('tests', '3.2.3a')
        self.msg_lan = self.__config.get('tests', '3.2.3a')
        self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config,
                                                     self.__lan_device)

    def set_flags(self):
        self.__config_setup1_1.set_flag_M(
            self.__config.get('t3.2.3a', 'flag_m'))
        self.__config_setup1_1.set_flag_0(
            self.__config.get('t3.2.3a', 'flag_o'))
        self.__config_setup1_1.set_flag_chlim(
            self.__config.get('t3.2.3a', 'flag_chlim'))
        self.__config_setup1_1.set_flag_L(
            self.__config.get('t3.2.3a', 'flag_l'))
        self.__config_setup1_1.set_flag_A(
            self.__config.get('t3.2.3a', 'flag_a'))
        self.__config_setup1_1.set_flag_R(
            self.__config.get('t3.2.3a', 'flag_r'))
        self.__config_setup1_1.set_flag_prf(
            self.__config.get('t3.2.3a', 'flag_prf'))
        self.__config_setup1_1.set_validlifetime(
            self.__config.get('t3.2.3a', 'validlifetime'))
        self.__config_setup1_1.set_preferredlifetime(
            self.__config.get('t3.2.3a', 'preferredlifetime'))
        self.__config_setup1_1.set_routerlifetime(
            self.__config.get('t3.2.3a', 'routerlifetime'))
        self.__config_setup1_1.set_reachabletime(
            self.__config.get('t3.2.3a', 'reach_time'))
        self.__config_setup1_1.set_retranstimer(
            self.__config.get('t3.2.3a', 'retrans_time'))
        self.__config_setup1_1.set_intervalo(
            self.__config.get('t1.6.6b', 'intervalo'))
        self.__config_setup1_1.set_prefix_addr(
            self.__config.get('setup1-1_advertise', 'ia_pd_address'))
        self.__config_setup1_1.set_dhcp_t1(
            self.__config.get('t3.2.3a', 'dhcp_t1'))
        self.__config_setup1_1.set_dhcp_t2(
            self.__config.get('t3.2.3a', 'dhcp_t2'))
        self.__config_setup1_1.set_dhcp_preflft(
            self.__config.get('t3.2.3a', 'dhcp_preflft'))
        self.__config_setup1_1.set_dhcp_validlft(
            self.__config.get('t3.2.3a', 'dhcp_validlft'))
        self.__config_setup1_1.set_dhcp_plen(
            self.__config.get('t3.2.3a', 'dhcp_plen'))

    def set_flags_lan(self):
        self.__config_setup_lan.set_elapsetime(
            self.__config.get('solicitlan', 'elapsetime'))
        self.__config_setup_lan.set_xid(self.__config.get('solicitlan', 'xid'))
        self.__config_setup_lan.set_fdqn(
            self.__config.get('solicitlan', 'clientfqdn'))
        self.__config_setup_lan.set_vendor_class(
            self.__config.get('solicitlan', 'vendorclass'))

        self.__config_setup_lan.set_enterprise(
            self.__config.get('solicitlan', 'enterpriseid'))
        self.__config_setup_lan.set_client_duid(
            self.__config.get('solicitlan', 'duid'))
        self.__config_setup_lan.set_iaid(
            self.__config.get('solicitlan', 'iaid'))

    def ping_tn3(self):
        if self.__config_setup1_1.get_mac_ceRouter() != None:
            #print('6')
            self.__config_setup_lan.set_ipv6_src(
                self.__config.get('lan', 'global_wan_addr'))
            self.__config_setup_lan.set_ether_src(
                self.__config.get('lan', 'mac'))
            self.__config_setup_lan.set_ether_dst(
                self.__config_setup_lan.get_mac_ceRouter())
            self.__config_setup_lan.set_ipv6_dst(
                self.__config.get('t3.2.3a', 'tn3_ip'))
            self.__sendmsgs.send_echo_request_lan(self.__config_setup_lan)

    def set_status_lan(self, v):
        self.msg_lan = v

    def get_status_lan(self):
        return self.msg_lan

    def set_status(self, v):
        self.msg = v

    def get_status(self):
        return self.msg

    def run_Lan(self):

        t_test = 0
        t_test1 = 0
        time_p = 0
        sent_reconfigure = False
        time_over = False
        send_ra = False
        send_na_lan = False
        reset_test1 = False
        self.set_flags_lan()
        self.__config_setup_lan.set_setup_lan_start()
        cache_lan = []

        @self.__app.route("/LAN", methods=['GET'])
        def envia_lan():
            return self.get_status_lan()

        while not self.__queue_lan.full():
            if self.__queue_lan.empty():
                if t_test < 30:

                    time.sleep(1)
                    t_test = t_test + 1
                    if t_test % 5 == 0:

                        self.__config_setup_lan.set_ipv6_src(
                            self.__config.get('lan', 'lan_local_addr'))
                        self.__config_setup_lan.set_ether_src(
                            self.__config.get('lan', 'mac_address'))
                        self.__config_setup_lan.set_ether_dst(
                            '33:33:00:01:00:02')
                        self.__config_setup_lan.set_ipv6_dst(
                            self.__config.get('multicast', 'all_routers_addr'))
                        self.__config_setup_lan.set_xid(
                            self.__config.get('informationlan', 'xid'))

                        self.__config_setup_lan.set_elapsetime(
                            self.__config.get('informationlan', 'elapsetime'))
                        self.__config_setup_lan.set_vendor_class(
                            self.__config.get('informationlan', 'vendorclass'))
                        self.__sendmsgs.send_dhcp_information(
                            self.__config_setup_lan)

                        self.__config_setup_lan.set_ipv6_src(
                            self.__config.get('lan', 'lan_local_addr'))
                        self.__config_setup_lan.set_ether_src(
                            self.__config.get('lan', 'mac_address'))
                        self.__config_setup_lan.set_ether_dst(
                            self.__config.get('multicast', 'all_mac_routers'))
                        self.__config_setup_lan.set_ipv6_dst(
                            self.__config.get('general',
                                              'all_routers_address'))
                        self.__config_setup_lan.set_lla(
                            self.__config.get('lan', 'mac_address'))
                        self.__sendmsgs.send_icmp_rs(self.__config_setup_lan)

                    time.sleep(1)
                else:
                    time_over = True

            else:

                pkt = self.__queue_lan.get()
                cache_lan.append(pkt)
                wrpcap("lan-3.2.3.cap", cache_lan)
                if pkt.haslayer(ICMPv6ND_RA):
                    self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)

                if pkt.haslayer(ICMPv6MLReport2):
                    self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)

                if pkt.haslayer(DHCP6_Reply):
                    self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)

                if pkt[Ether].src == self.__config.get('lan', 'mac_address'):
                    continue

                if pkt.haslayer(ICMPv6ND_NS):

                    if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                            'lan', 'global_wan_addr'):
                        self.__config_setup_lan.set_ipv6_src(
                            self.__config.get('lan', 'global_wan_addr'))
                        self.__config_setup_lan.set_ether_src(
                            self.__config.get('lan', 'mac_address'))
                        self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
                        self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                        self.__config_setup_lan.set_tgt(
                            self.__config.get('lan', 'global_wan_addr'))
                        self.__config_setup_lan.set_lla(
                            self.__config.get('lan', 'mac_address'))
                        self.__config_setup_lan.set_mac_ceRouter(
                            pkt[Ether].src)
                        self.__sendmsgs.send_icmp_na_lan(
                            self.__config_setup_lan)
                    print('AQUI-9')
                    if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                            'lan', 'lan_local_addr'):

                        self.__config_setup_lan.set_ipv6_src(
                            self.__config.get('lan', 'lan_local_addr'))
                        self.__config_setup_lan.set_ether_src(
                            self.__config.get('lan', 'mac_address'))
                        self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
                        self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                        self.__config_setup_lan.set_tgt(
                            self.__config.get('lan', 'lan_local_addr'))
                        self.__config_setup_lan.set_lla(
                            self.__config.get('lan', 'mac_address'))
                        self.__config_setup_lan.set_mac_ceRouter(
                            pkt[Ether].src)
                        self.__sendmsgs.send_icmp_na_lan(
                            self.__config_setup_lan)

            if self.__config_setup1_1.get_setup1_1_OK():
                if pkt[Ether].src == self.__config.get('lan', 'mac_address'):
                    continue

                if pkt.haslayer(ICMPv6EchoRequest):

                    logging.info(
                        'Reprovado Teste 2.7.3b - Recebeu ICMPv6EchoRequest de um endereço inalcançavel'
                    )
                    self.__packet_sniffer_wan.stop()
                    self.__packet_sniffer_lan.stop()
                    self.__finish_wan = True
                    self.__fail_test = False
                    return False

                if pkt.haslayer(ICMPv6ND_NS):

                    if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                            'lan', 'global_wan_addr'):
                        self.__config_setup_lan.set_ipv6_src(
                            self.__config.get('lan', 'global_wan_addr'))
                        self.__config_setup_lan.set_ether_src(
                            self.__config.get('lan', 'mac_address'))
                        self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
                        self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                        self.__config_setup_lan.set_tgt(
                            self.__config.get('lan', 'global_wan_addr'))
                        self.__config_setup_lan.set_lla(
                            self.__config.get('lan', 'mac_address'))
                        self.__config_setup_lan.set_mac_ceRouter(
                            pkt[Ether].src)
                        self.__sendmsgs.send_icmp_na_lan(
                            self.__config_setup_lan)

                    if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                            'lan', 'lan_local_addr'):

                        self.__config_setup_lan.set_ipv6_src(
                            self.__config.get('lan', 'lan_local_addr'))
                        self.__config_setup_lan.set_ether_src(
                            self.__config.get('lan', 'mac_address'))
                        self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
                        self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                        self.__config_setup_lan.set_tgt(
                            self.__config.get('lan', 'lan_local_addr'))
                        self.__config_setup_lan.set_lla(
                            self.__config.get('lan', 'mac_address'))
                        self.__config_setup_lan.set_mac_ceRouter(
                            pkt[Ether].src)
                        self.__sendmsgs.send_icmp_na_lan(
                            self.__config_setup_lan)
                else:
                    self.stop_ping_OK = True
            if self.part2_lan_start and not reset_test1:
                t_test1 = 0
                reset_test1 = True

    def rourter_advertise(self):
        self.__config_setup1_1.set_ether_src(self.__config.get(
            'wan', 'ra_mac'))
        self.__config_setup1_1.set_ether_dst(
            self.__config.get('multicast', 'all_mac_nodes'))
        self.__config_setup1_1.set_ipv6_src(
            self.__config.get('wan', 'ra_address'))
        self.__config_setup1_1.set_ipv6_dst(
            self.__config.get('multicast', 'all_nodes_addr'))
        self.__sendmsgs.send_tr1_RA2(self.__config_setup1_1)

    def ping(self):
        if self.__config_setup1_1.get_mac_ceRouter() != None:
            #print('6')
            self.__config_setup1_1.set_ipv6_src(
                self.__config.get('wan', 'global_wan_addr'))
            self.__config_setup1_1.set_ether_src(
                self.__config.get('wan', 'wan_mac_tr1'))
            self.__config_setup1_1.set_ether_dst(
                self.__config_setup1_1.get_mac_ceRouter())
            self.__config_setup1_1.set_ipv6_dst(
                self.__config.get('t3.2.2a', 'unreachable_ip'))
            self.__sendmsgs.send_echo_request(self.__config_setup1_1)

    def neighbor_advertise_local(self, pkt):
        self.__config_setup1_1.set_ipv6_src(
            self.__config.get('wan', 'link_local_addr'))
        self.__config_setup1_1.set_ether_src(
            self.__config.get('wan', 'wan_mac_tr1'))
        self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
        self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup1_1.set_tgt(
            self.__config.get('wan', 'link_local_addr'))
        self.__config_setup1_1.set_lla(self.__config.get('wan', 'wan_mac_tr1'))
        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na(self.__config_setup1_1)

    def neighbor_advertise_global(self, pkt):
        self.__config_setup1_1.set_ipv6_src(
            self.__config.get('wan', 'global_wan_addr'))
        self.__config_setup1_1.set_ether_src(
            self.__config.get('wan', 'wan_mac_tr1'))
        self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
        self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup1_1.set_tgt(
            self.__config.get('wan', 'global_wan_addr'))
        self.__config_setup1_1.set_lla(self.__config.get('wan', 'wan_mac_tr1'))
        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na(self.__config_setup1_1)

    def neighbor_advertise_global_tn3(self, pkt):
        self.__config_setup1_1.set_ipv6_src(
            self.__config.get('t3.2.3a', 'tn3_ip'))
        self.__config_setup1_1.set_ether_src(
            self.__config.get('t3.2.3a', 'tn3_mac'))
        self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
        self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup1_1.set_tgt(self.__config.get('t3.2.3a', 'tn3_ip'))
        self.__config_setup1_1.set_lla(self.__config.get('t3.2.3a', 'tn3_mac'))
        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na(self.__config_setup1_1)

    def run(self):
        #self.__t_lan =  Thread(target=self.run_Lan,name='LAN_Thread')
        #self.__t_lan.start()
        @self.__app.route("/WAN", methods=['GET'])
        def enviawan():
            return self.get_status()

        self.__packet_sniffer_wan = PacketSniffer('Test273b-WAN',
                                                  self.__queue_wan, self,
                                                  self.__config,
                                                  self.__wan_device_tr1)
        self.__packet_sniffer_wan.start()

        self.__packet_sniffer_lan = PacketSniffer('Test273b-LAN',
                                                  self.__queue_lan, self,
                                                  self.__config,
                                                  self.__lan_device)
        #test_lan = self.__packet_sniffer_lan.start()
        self.__config_setup1_1.set_ra2()
        self.set_flags()
        logging.info(self.__test_desc)
        t_test = 0
        time1 = 0
        sent_reconfigure = False
        time_over = False
        start_time_count = False
        finish_wan = False
        part1_OK = False
        cache_wan = []
        self.__config_setup1_1.set_pd_prefixlen(
            self.__config.get('t3.2.3a', 'pd_prefixlen'))
        self.__config_setup1_1.set_routerlifetime(
            self.__config.get('t3.2.3a', 'routerlifetime'))
        while not self.__queue_wan.full():
            if self.__queue_wan.empty():
                if t_test <= 300:
                    time.sleep(1)
                    t_test = t_test + 1
                    if t_test % 10 == 0:
                        self.rourter_advertise()
                        #self.ping()

                    if start_time_count:
                        if time1 < 600:
                            time1 = time1 + 1
                            # print('imprimindo relogio')
                            # print(time1)
                            #if time1 % 5 == 0:
                            #self.ping()

                else:
                    time_over = True
            else:
                pkt = self.__queue_wan.get()
                cache_wan.append(pkt)
                wrpcap("WAN-3.2.4.cap", cache_wan)
                if not self.__config_setup1_1.get_ND_local_OK():

                    if pkt[Ether].src == self.__config.get(
                            'wan', 'link_local_mac'):
                        print('ND_LOCAL,continue')
                        continue

                    if pkt[Ether].src == self.__config.get('wan', 'ra_mac'):
                        print('ND_LOCAL-A,continue')
                        continue

                    if pkt.haslayer(ICMPv6ND_RS):

                        if pkt[Ether].src == self.__config.get(
                                'wan', 'link_local_mac'):
                            print('RS,continue')
                            continue

                        if pkt[Ether].src == self.__config.get(
                                'wan', 'ra_mac'):
                            print('RS-A,continue')
                            continue

                        self.__config_setup1_1.set_local_addr_ceRouter(
                            pkt[IPv6].src)
                        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
                        #self.__config_setup1_1.set_ND_local_OK()

                    if pkt.haslayer(DHCP6_Solicit):
                        if pkt[Ether].src == self.__config.get(
                                'wan', 'link_local_mac'):
                            print('solicit,continue')
                            continue

                        if pkt[Ether].src == self.__config.get(
                                'wan', 'ra_mac'):
                            print('solicitA,continue')
                            continue
                        self.__config_setup1_1.set_local_addr_ceRouter(
                            pkt[IPv6].src)
                        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
                        #self.__config_setup1_1.set_ND_local_OK()

                if pkt.haslayer(ICMPv6ND_NS):

                    if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                            'wan', 'global_wan_addr'):
                        self.neighbor_advertise_global(pkt)

                    if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                            'wan', 'link_local_addr'):
                        self.neighbor_advertise_local(pkt)

                #pkt = self.__queue_wan.get()
                if not self.__config_setup1_1.get_setup1_1_OK():
                    print('test1')
                    if not self.__config_setup1_1.get_disapproved():
                        print('test2')
                        self.__config_setup1_1.run_setup1_1(pkt)
                        print('test3')
                        if pkt.haslayer(ICMPv6ND_RS):

                            if pkt[Ether].src == self.__config.get(
                                    'wan', 'link_local_mac'):
                                print('RS-2,continue')
                                continue
                            if pkt[Ether].src == self.__config.get(
                                    'wan', 'ra_mac'):
                                print('RS-2A,continue')
                                continue
                            print('test4')
                            #self.__config_setup1_1.set_ND_local_OK()
                            self.__config_setup1_1.set_local_addr_ceRouter(
                                pkt[IPv6].src)
                            self.__config_setup1_1.set_mac_ceRouter(
                                pkt[Ether].src)
                            self.__config_setup1_1.set_ether_src(
                                self.__config.get('wan', 'ra_mac'))
                            self.__config_setup1_1.set_ether_dst(
                                self.__config.get('multicast',
                                                  'all_mac_nodes'))
                            self.__config_setup1_1.set_ipv6_src(
                                self.__config.get('wan', 'ra_address'))
                            self.__config_setup1_1.set_ipv6_dst(
                                self.__config.get('multicast',
                                                  'all_nodes_addr'))
                            self.__sendmsgs.send_tr1_RA2(
                                self.__config_setup1_1)

                    else:
                        logging.info(
                            'Reprovado Teste 2.7.3b - Falha em completar o Common Setup 1.1 da RFC'
                        )
                        self.__packet_sniffer_wan.stop()
                        return False

                else:

                    if not self.__finish_wan:
                        start_time_count = True
                        if time1 < 50:
                            self.ping()

                            if pkt.haslayer(ICMPv6ND_NS):
                                if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                                        'wan', 'global_wan_addr'):
                                    print('glboal')
                                    self.neighbor_advertise_global(pkt)

                                if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                                        'wan', 'ra_address'):
                                    print('local')
                                    self.__config_setup1_1.set_ipv6_src(
                                        self.__config.get('wan', 'ra_address'))
                                    self.__config_setup1_1.set_ether_src(
                                        self.__config.get('wan', 'ra_mac'))
                                    self.__config_setup1_1.set_ether_dst(
                                        pkt[Ether].src)
                                    self.__config_setup1_1.set_ipv6_dst(
                                        pkt[IPv6].src)
                                    self.__config_setup1_1.set_tgt(
                                        self.__config.get('wan', 'ra_address'))
                                    self.__config_setup1_1.set_lla(
                                        self.__config.get('wan', 'ra_mac'))
                                    self.__config_setup1_1.set_mac_ceRouter(
                                        pkt[Ether].src)
                                    self.__sendmsgs.send_icmp_na(
                                        self.__config_setup1_1)

                            if pkt.haslayer(ICMPv6DestUnreach):
                                self.__packet_sniffer_wan.stop()
                                self.__packet_sniffer_lan.stop()
                                logging.info(
                                    'Teste 3.7.2a - APROVADO. Não passou pacotes da LAN para WAN devido ao RouterLife time estar zerado'
                                )
                                return True

                            #if time1 % 5 == 0:
                            #self.ping()
                            # if part1_OK == False:
                            #     if pkt.haslayer(ICMPv6EchoRequest):

                            #     #logging.info('Reprovado Teste 2.7.3a - Recebido ICMPv6EchoRequest na WAN sendo que Routerlifime anunciado é zero')
                            #         part1_OK = True

                            # if self.part2_lan_start:
                            #     if pkt.haslayer(ICMPv6EchoRequest):
                            #         logging.info('Reprovado Teste 2.7.3a - Recebido ICMPv6EchoRequest na WAN sendo que Routerlifime anunciado é zero')
                            #         self.__packet_sniffer_wan.stop()
                            #         self.__packet_sniffer_lan.stop()
                            #         self.__finish_wan = True
                            #         self.__fail_test = False
                            #         return False
                            # if part1_OK and not self.part2_lan_start:
                            #     print('enviado1')
                            #     self.__config_setup1_1.set_routerlifetime('0')
                            #     self.__config_setup1_1.set_reachabletime('0')
                            #     self.__config_setup1_1.set_retranstimer('0')

                            #     self.__sendmsgs.send_tr1_RA2(self.__config_setup1_1)
                            #     print('limpando')
                            #     while not self.stop_ping_OK:
                            #         time.sleep(1)
                            #         print('aguardando terminar')

                            #     time.sleep(10)
                            #     while not self.__queue_wan.empty():
                            #         self.__queue_wan.get()

                            #     print('enviando 3')
                            #     for x in range(3):
                            #         time.sleep(1)
                            #         x = x+1
                            #         self.__sendmsgs.send_tr1_RA2(self.__config_setup1_1)
                            #     self.part2_lan_start = True

                            # if pkt.haslayer(ICMPv6ND_NS):
                            #     if pkt[ICMPv6ND_NS].tgt == self.__config.get('t3.2.3a','tn3_ip'):
                            #         print('glboal')
                            #         self.neighbor_advertise_global_tn3(pkt)

                            #     if pkt[ICMPv6ND_NS].tgt == self.__config.get('wan','ra_address'):
                            #         print('local')
                            #         self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','ra_address'))
                            #         self.__config_setup1_1.set_ether_src(self.__config.get('wan','ra_mac'))
                            #         self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
                            #         self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
                            #         self.__config_setup1_1.set_tgt(self.__config.get('wan','ra_address'))
                            #         self.__config_setup1_1.set_lla(self.__config.get('wan','ra_mac'))
                            #         self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
                            #         self.__sendmsgs.send_icmp_na(self.__config_setup1_1)

                        else:
                            self.__packet_sniffer_wan.stop()
                            self.__packet_sniffer_lan.stop()
                            logging.info(
                                'Teste 3.7.3 - Reprovado. Time out sem mensagem Unreacheable'
                            )
                            return True
                    else:
                        self.__packet_sniffer_wan.stop()
                        if self.__fail_test:
                            return False
                        else:
                            return True
        self.__packet_sniffer_wan.stop()
        return False
コード例 #2
0
ファイル: test321a.py プロジェクト: ronyjah/rfc
class Test321a:
    def __init__(self, config):
        self.__queue_wan = Queue()
        self.__queue_lan = Queue()
        self.__config = config
        self.__interface = None
        self.__pkt = None
        self.__local_addr_ceRouter = None
        self.__sendmsgs = SendMsgs(self.__config)
        self.__config_setup1_1 = ConfigSetup1_1(self.__config)
        #self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config)
        self.__wan_device_tr1 = self.__config.get('wan', 'device_wan_tr1')
        self.__lan_device = self.__config.get('lan', 'lan_device')
        self.__wan_mac_tr1 = self.__config.get('wan', 'wan_mac_tr1')
        self.__link_local_addr = self.__config.get('wan', 'link_local_addr')
        self.__all_nodes_addr = self.__config.get('multicast',
                                                  'all_nodes_addr')
        self.__test_desc = self.__config.get('tests', '3.2.1a')
        self.__t_lan = None
        self.__finish_wan = False
        self.__dhcp_renew_done = False
        self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config,
                                                     self.__lan_device)

    def set_flags(self):
        self.__config_setup1_1.set_flag_M(
            self.__config.get('t3.2.1a', 'flag_m'))
        self.__config_setup1_1.set_flag_0(
            self.__config.get('t3.2.1a', 'flag_o'))
        self.__config_setup1_1.set_flag_chlim(
            self.__config.get('t3.2.1a', 'flag_chlim'))
        self.__config_setup1_1.set_flag_L(
            self.__config.get('t3.2.1a', 'flag_l'))
        self.__config_setup1_1.set_flag_A(
            self.__config.get('t3.2.1a', 'flag_a'))
        self.__config_setup1_1.set_flag_R(
            self.__config.get('t3.2.1a', 'flag_r'))
        self.__config_setup1_1.set_flag_prf(
            self.__config.get('t3.2.1a', 'flag_prf'))
        self.__config_setup1_1.set_validlifetime(
            self.__config.get('t3.2.1a', 'validlifetime'))
        self.__config_setup1_1.set_preferredlifetime(
            self.__config.get('t3.2.1a', 'preferredlifetime'))
        self.__config_setup1_1.set_routerlifetime(
            self.__config.get('t3.2.1a', 'routerlifetime'))
        self.__config_setup1_1.set_reachabletime(
            self.__config.get('t3.2.1a', 'reach_time'))
        self.__config_setup1_1.set_retranstimer(
            self.__config.get('t3.2.1a', 'retrans_time'))
        self.__config_setup1_1.set_intervalo(
            self.__config.get('t1.6.6b', 'intervalo'))
        self.__config_setup1_1.set_prefix_addr(
            self.__config.get('setup1-1_advertise', 'ia_pd_address'))
        self.__config_setup1_1.set_dhcp_t1(
            self.__config.get('t3.2.1a', 'dhcp_t1'))
        self.__config_setup1_1.set_dhcp_t2(
            self.__config.get('t3.2.1a', 'dhcp_t2'))
        self.__config_setup1_1.set_dhcp_preflft(
            self.__config.get('t3.2.1a', 'dhcp_preflft'))
        self.__config_setup1_1.set_dhcp_validlft(
            self.__config.get('t3.2.1a', 'dhcp_validlft'))
        self.__config_setup1_1.set_dhcp_plen(
            self.__config.get('t3.2.1a', 'dhcp_plen'))

    def set_flags_lan(self):
        self.__config_setup_lan.set_elapsetime(
            self.__config.get('solicitlan', 'elapsetime'))
        self.__config_setup_lan.set_xid(self.__config.get('solicitlan', 'xid'))
        self.__config_setup_lan.set_fdqn(
            self.__config.get('solicitlan', 'clientfqdn'))
        self.__config_setup_lan.set_vendor_class(
            self.__config.get('solicitlan', 'vendorclass'))

        self.__config_setup_lan.set_enterprise(
            self.__config.get('solicitlan', 'enterpriseid'))
        self.__config_setup_lan.set_client_duid(
            self.__config.get('solicitlan', 'duid'))
        self.__config_setup_lan.set_iaid(
            self.__config.get('solicitlan', 'iaid'))

    def run_Lan(self):
        #self.__config_setup_lan_.flags_partA()
        logging.info('Thread da LAN inicio')
        t_test = 0
        t_test1 = 0
        time_p = 0
        sent_reconfigure = False
        time_over = False
        send_ra = False
        send_na_lan = False
        self.set_flags_lan()
        self.__config_setup_lan.set_setup_lan_start()
        while not self.__queue_lan.full():
            if self.__queue_lan.empty():
                if t_test < 60:

                    time.sleep(1)
                    t_test = t_test + 1
                    if t_test % 5 == 0:
                        #print('0')
                        #print('ENVIO RS - 1 LAN')
                        self.__config_setup_lan.set_ipv6_src(
                            self.__config.get('lan', 'lan_local_addr'))
                        self.__config_setup_lan.set_ether_src(
                            self.__config.get('lan', 'mac_address'))
                        self.__config_setup_lan.set_ether_dst(
                            '33:33:00:01:00:02')
                        self.__config_setup_lan.set_ipv6_dst(
                            self.__config.get('multicast', 'all_routers_addr'))
                        self.__config_setup_lan.set_xid(
                            self.__config.get('informationlan', 'xid'))
                        #self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
                        self.__config_setup_lan.set_elapsetime(
                            self.__config.get('informationlan', 'elapsetime'))
                        self.__config_setup_lan.set_vendor_class(
                            self.__config.get('informationlan', 'vendorclass'))
                        self.__sendmsgs.send_dhcp_information(
                            self.__config_setup_lan)

                        #self.__config_setup_lan.set_setup_lan_start()
                        self.__config_setup_lan.set_ipv6_src(
                            self.__config.get('lan', 'lan_local_addr'))
                        self.__config_setup_lan.set_ether_src(
                            self.__config.get('lan', 'mac_address'))
                        self.__config_setup_lan.set_ether_dst(
                            self.__config.get('multicast', 'all_mac_routers'))
                        self.__config_setup_lan.set_ipv6_dst(
                            self.__config.get('general',
                                              'all_routers_address'))
                        self.__config_setup_lan.set_lla(
                            self.__config.get('lan', 'mac_address'))
                        self.__sendmsgs.send_icmp_rs(self.__config_setup_lan)

                        if self.__config_setup_lan.get_mac_ceRouter() != None:
                            #print('6')
                            self.__config_setup_lan.set_ipv6_src(
                                self.__config.get('lan', 'global_wan_addr'))
                            self.__config_setup_lan.set_ether_src(
                                self.__config.get('lan', 'mac_address'))
                            self.__config_setup_lan.set_ether_dst(
                                self.__config_setup_lan.get_mac_ceRouter())
                            self.__config_setup_lan.set_ipv6_dst(
                                self.__config.get('wan', 'global_wan_addr'))
                            self.__sendmsgs.send_echo_request_lan(
                                self.__config_setup_lan)

                        # self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
                        # self.__config_setup_lan.set_ipv6_dst(self.__config.get('multicast','all_nodes_addr'))
                        # self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                        # self.__config_setup_lan.set_ether_dst(self.__config.get('multicast','all_mac_nodes'))
                        # #self.set_tgt(self.get_local_addr_ceRouter())

                        # self.__config_setup_lan.set_tgt(self.__config.get('wan','link_local_addr'))
                        # #self.__sendmsgssetup1_1.send_echo_request(self)
                        # self.__config_setup_lan.set_lla(self.__config.get('wan','link_local_mac'))
                        # self.__sendmsgs.send_icmp_ns_lan(self.__config_setup_lan)
                        #print('1')

                    logging.info('Thread da LAN time')
                    time.sleep(1)
                else:
                    time_over = True

#                    t_test = t_test + 1
#                   if self.__config_setup1_1.get_recvd_dhcp_renew():
#pkt = self.__queue_lan.get()
            else:
                #print('AQUI-1')
                pkt = self.__queue_lan.get()
                #print('AQUI-2')
                if not time_over:
                    if pkt.haslayer(ICMPv6EchoReply):
                        #print('AQUI-2.0')
                        self.__packet_sniffer_lan.stop()
                        self.__finish_wan = True
                        self.__fail_test = True
                        return False

                    #print('AQUI-2.1')
                    if pkt.haslayer(ICMPv6ND_RA):
                        #print('AQUI-3')
                        self.__config_setup_lan.set_mac_ceRouter(
                            pkt[Ether].src)
                        #print('AQUI-4')
                    if pkt.haslayer(ICMPv6MLReport2):
                        self.__config_setup_lan.set_mac_ceRouter(
                            pkt[Ether].src)
                        #print('AQUI-5')
                    if pkt.haslayer(DHCP6_Reply):
                        self.__config_setup_lan.set_mac_ceRouter(
                            pkt[Ether].src)
                        #print('AQUI-6')

                    #print('AQUI-2.2')
                    if pkt[Ether].src == self.__config.get(
                            'lan', 'mac_address'):
                        #print('AQUI-7')
                        #logging.info(' TEM PACOTE ========continue====== 1')
                        continue

                    if pkt.haslayer(ICMPv6ND_NS):
                        #print('AQUI-8')
                        if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                                'lan', 'global_wan_addr'):
                            #print('AQUI-9')
                            #print('LOOP NS')
                            #print(pkt[ICMPv6ND_NS].tgt)
                            #if not send_na_lan:
                            self.__config_setup_lan.set_ipv6_src(
                                self.__config.get('lan', 'global_wan_addr'))
                            self.__config_setup_lan.set_ether_src(
                                self.__config.get('lan', 'mac_address'))
                            self.__config_setup_lan.set_ether_dst(
                                pkt[Ether].dst)
                            self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                            self.__config_setup_lan.set_tgt(
                                self.__config.get('lan', 'global_wan_addr'))
                            self.__config_setup_lan.set_lla(
                                self.__config.get('lan', 'mac_address'))
                            #send_na_lan = True
                            self.__config_setup_lan.set_mac_ceRouter(
                                pkt[Ether].src)
                            self.__sendmsgs.send_icmp_na_lan(
                                self.__config_setup_lan)

                        if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                                'lan', 'lan_local_addr'):
                            #print('AQUI-10')

                            #print('LOOP NS')
                            #print(pkt[ICMPv6ND_NS].tgt)
                            #if not send_na_lan:
                            self.__config_setup_lan.set_ipv6_src(
                                self.__config.get('lan', 'lan_local_addr'))
                            self.__config_setup_lan.set_ether_src(
                                self.__config.get('lan', 'mac_address'))
                            self.__config_setup_lan.set_ether_dst(
                                pkt[Ether].dst)
                            self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                            self.__config_setup_lan.set_tgt(
                                self.__config.get('lan', 'lan_local_addr'))
                            self.__config_setup_lan.set_lla(
                                self.__config.get('lan', 'mac_address'))
                            #send_na_lan = True
                            self.__config_setup_lan.set_mac_ceRouter(
                                pkt[Ether].src)
                            self.__sendmsgs.send_icmp_na_lan(
                                self.__config_setup_lan)

                #self.__config_setup_lan.run_setup1_1(pkt)
            #if not self.__config_setup_lan.get_global_ping_OK():
            #print('SETUP 1.1 ')
            #if not self.__config_setup_lan.get_disapproved():
                if self.__config_setup1_1.get_setup1_1_OK():
                    #logging.info('SETUP 1.1 CONCLUIDO===============')
                    if pkt[Ether].src == self.__config.get(
                            'lan', 'mac_address'):
                        #print('AQUI-7')
                        #logging.info(' TEM PACOTE ========continue====== 1')
                        continue

                    if self.__config_setup_lan.get_mac_ceRouter() != None:
                        #print('6')
                        self.__config_setup_lan.set_ipv6_src(
                            self.__config.get('lan', 'global_wan_addr'))
                        self.__config_setup_lan.set_ether_src(
                            self.__config.get('lan', 'mac_address'))
                        self.__config_setup_lan.set_ether_dst(
                            self.__config_setup_lan.get_mac_ceRouter())
                        self.__config_setup_lan.set_ipv6_dst(
                            self.__config.get('wan', 'global_wan_addr'))
                        self.__sendmsgs.send_echo_request_lan(
                            self.__config_setup_lan)

                    if pkt.haslayer(ICMPv6ND_NS):
                        if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                                'lan', 'global_wan_addr'):
                            #print('LOOP NS')
                            #print(pkt[ICMPv6ND_NS].tgt)
                            #if not send_na_lan:
                            self.__config_setup_lan.set_ipv6_src(
                                self.__config.get('lan', 'global_wan_addr'))
                            self.__config_setup_lan.set_ether_src(
                                self.__config.get('lan', 'mac_address'))
                            self.__config_setup_lan.set_ether_dst(
                                pkt[Ether].src)
                            self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                            self.__config_setup_lan.set_tgt(
                                self.__config.get('lan', 'global_wan_addr'))
                            self.__config_setup_lan.set_lla(
                                self.__config.get('lan', 'mac_address'))
                            #send_na_lan = True
                            self.__sendmsgs.send_icmp_na_lan(
                                self.__config_setup_lan)
                        #else:
                        # self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
                        # self.__config_setup_lan.set_global_addr_ceRouter(pkt[IPv6].src)
                        # #print('DADOS GLOBAIS')
                        # #print(self.__config_setup_lan.get_mac_ceRouter())
                        # #print(self.__config_setup_lan.get_global_addr_ceRouter())
                # else:
                #     logging.info('Reprovado Teste 3.2.1a - Falha em completar o Common Setup 1.1 da RFC')
                #     self.__packet_sniffer_lan.stop()
                #     self.__finish_wan = True
                #     return False

                # if pkt.haslayer(ICMPv6ND_NS):
                #     if pkt[ICMPv6ND_NS].tgt == self.__config.get('lan','global_wan_addr'):
                #         #print('LOOP NS')
                #         #print(pkt[ICMPv6ND_NS].tgt)
                #         if not send_na_lan:
                #             self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))
                #             self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                #             self.__config_setup_lan.set_ether_dst(self.__config_setup_lan.get_mac_ceRouter())
                #             self.__config_setup_lan.set_ipv6_dst(self.__config_setup_lan.get__addr_ceRouter())
                #             self.__config_setup_lan.set_tgt(self.__config.get('lan','global_wan_addr'))
                #             self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
                #             send_na_lan = True
                #             self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)

                #if self.__config_setup_lan.get_ND_local_OK():
                #     #print('ENVIO REQUEST 1 LAN')
                # if self.__config_setup_lan.get_mac_ceRouter() != None:
                #     mac = self.__config_setup_lan.get_mac_ceRouter()

                #     ip = self.__config_setup_lan.get_local_addr_ceRouter()
                #     self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))
                #     self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                #     self.__config_setup_lan.set_ether_dst(mac)
                #     self.__config_setup_lan.set_ipv6_dst(self.__config.get('wan','global_wan_addr'))
                #     self.__sendmsgs.send_echo_request_lan(self.__config_setup_lan)
                # else:
                #     logging.info('Não foi possível enviar Echo Request na LAN. MAC CeRouter NULL')

                # if pkt.haslayer(ICMPv6EchoReply):
                #     self.__packet_sniffer_lan.stop()
                #     self.__finish_wan = True
                #     self.__fail_test = True
                #     return False
                # else:
                #     if self.__config_setup_lan.get_ND_local_OK():
                #         #print('ENVIO REQUEST LAN')
                #         if self.__config_setup_lan.get_mac_ceRouter() != None:
                #             mac = self.__config_setup_lan.get_mac_ceRouter()
                #             ip = self.__config_setup_lan.get_local_addr_ceRouter()
                #             self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))
                #             self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                #             self.__config_setup_lan.set_ether_dst(mac)
                #             self.__config_setup_lan.set_ipv6_dst(self.__config.get('wan','global_wan_addr'))
                #             self.__sendmsgs.send_echo_request_lan(self.__config_setup_lan)
                #             if pkt.haslayer(ICMPv6EchoReply):
                #                 self.__packet_sniffer_lan.stop()
                #                 self.__finish_wan = True
                #                 self.__fail_test = False
                #                 return True
                #         else:
                #             logging.info('Não foi possível enviar Echo Request na LAN. MAC CeRouter NULL')

                # #self.__config_setup_lan.set_setup_lan_start()
                # #print('#print ENVIO INFORMATION LAN')

            # pkt = self.__queue_lan.get()
            # if not self.__config_setup_lan.get_global_ping_OK():
            #     #print('LOOP PRINCIPAL')
            #     if not self.__config_setup_lan.get_disapproved():
            #         self.__config_setup_lan.run_setup1_1(pkt)
            #     else:
            #         logging.info('Reprovado Teste 3.2.1a - Falha em completar o Common Setup 1.1 da RFC')
            #         self.__packet_sniffer_lan.stop()
            #         self.__finish_wan = True
            #         return False
            # else:

            #     #print('LOOP FINAL  ENVIO REQUEST')
            #     mac_global = self.__config_setup_lan.get_global_mac_ceRouter()
            #     ip_global = self.__config_setup_lan.get_global_addr_ceRouter()
            #     self.__config_setup_lan.set_ipv6_src(self.__config.get('t3.2.1a','source_to_ping_tn1'))
            #     self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
            #     self.__config_setup_lan.set_ether_dst(mac_global)
            #     self.__config_setup_lan.set_ipv6_dst(self.__config.get('wan','global_wan_addr'))
            #     self.__sendmsgs.send_echo_request_lan(self.__config_setup_lan)

            #     #print('LOOP FINAL')
            #     if pkt[Ether].src == self.__config.get('lan','mac_address'):
            #         continue
            #     #print('LOOP ECHO REPLY')
            #     if pkt.haslayer(ICMPv6EchoReply):
            #         self.__packet_sniffer_lan.stop()
            #         self.__finish_wan = True
            #         self.__fail_test = True
            #         return False
            #     #print('LOOP FINAL  NS')
            #     if pkt.haslayer(ICMPv6ND_NS):
            #         if pkt[ICMPv6ND_NS].tgt == self.__config.get('t3.2.1a','source_to_ping_tn1'):
            #             #print('LOOP FINAL  CEROUTER INVIO NS PARA O PING TN1')
            #             #print(pkt[ICMPv6ND_NS].tgt)
            #             if not send_na_lan:
            #                 self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))
            #                 self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
            #                 self.__config_setup_lan.set_ether_dst(self.__config_setup_lan.get_global_mac_ceRouter())
            #                 self.__config_setup_lan.set_ipv6_dst(self.__config_setup_lan.get_global_addr_ceRouter())
            #                 self.__config_setup_lan.set_tgt(self.__config.get('t3.2.1a','source_to_ping_tn1'))
            #                 self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
            #                 send_na_lan = True
            #                 self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)
            #     #print('LOOP FINAL  INALCANCAVEL')
            #     if pkt.haslayer(ICMPv6DestUnreach):
            #         #print('LOOP FINAL  INALCANCAVEL DENTRO')
            #         logging.info(' Teste 3.2.1a: destino TN1 inalcançável.')
            #         logging.info('Aprovado Teste3.2.1a.')
            #         self.__packet_sniffer_lan.stop()
            #         self.__finish_wan = True
            #         self.__fail_test = False
            #         return True

            # if self.__dhcp_renew_done :
            #     #print('DONE CONCLUIDO- VALIDANDO MENSAGEM RA')
            #     if t_test1 < 60:
            #         #print('DONE CONCLUIDO- VALIDANDO MENSAGEM RA TEMPO')
            #         time.sleep(1)
            #         t_test1 = t_test1 + 1
            #         #if t_test1 % 10 == 0:
            #             #self.__config_setup_lan.set_setup_lan_start()
            #         self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
            #         self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
            #         self.__config_setup_lan.set_ether_dst(self.__config.get('multicast','all_mac_routers'))
            #         self.__config_setup_lan.set_ipv6_dst(self.__config.get('general','all_routers_address'))
            #         self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
            #         self.__sendmsgs.send_icmp_rs(self.__config_setup_lan)

            #         if pkt.haslayer(ICMPv6ND_RA):
            #             #print('DONE CONCLUIDO- VALIDANDO MENSAGEM MENSAGEM RA')
            #             if pkt.haslayer(ICMPv6NDOptRouteInfo):
            #                 if pkt[ICMPv6NDOptRouteInfo].plen != 60:
            #                     logging.info(' Teste3.2.1a: Reprovado. Tamanho do prefixo diferente do anunciado no DHCP Reconfigure')
            #                     logging.info(pkt[ICMPv6NDOptPrefixInfo].prefixlen)
            #                     logging.info(pkt[ICMPv6NDOptRouteInfo].plen)

            #                     self.__packet_sniffer_lan.stop()
            #                     self.__finish_wan = True
            #                     self.__fail_test = True
            #                     return False
            #                 else: #self.__validlifetime_CeRouter == pkt[ICMPv6NDOptPrefixInfo].validlifetime
            #                     logging.info(' Teste 3.2.1a:Tamanho do prefixo igual ao anunciado na mensagem DHCP Reconfigure.')
            #                     logging.info('Aprovado Teste3.2.1a.')
            #                     self.__packet_sniffer_lan.stop()
            #                     self.__finish_wan = True
            #                     self.__fail_test = False
            #                     return True
            #             else: #print('DONE CONCLUIDO- SEM PREFIX INFO RA')
            # logging.info('Setup LAN  Concluido')
            # if self.__config_setup_lan.get_recvd_dhcp_srcladdr():
            #     logging.info(' Teste 3.2.1a: Recebido Recursive DNS OK.')
            #     logging.info('Aprovado Teste3.2.1a.')
            #     self.__packet_sniffer_lan.stop()
            #     self.__finish_wan = True
            #     self.__fail_test = False
            #     return True

            # else:
            #     logging.info(' Teste3.2.1a: Reprovado. Não foi recebido')
            #     #logging.info(routerlifetime)
            #     self.__packet_sniffer_lan.stop()
            #     self.__finish_wan = True
            #     self.__fail_test = True
            #     return False

    def run(self):
        self.__t_lan = Thread(target=self.run_Lan, name='LAN_Thread')
        self.__t_lan.start()

        self.__packet_sniffer_wan = PacketSniffer('Test273b-WAN',
                                                  self.__queue_wan, self,
                                                  self.__config,
                                                  self.__wan_device_tr1)
        self.__packet_sniffer_wan.start()

        self.__packet_sniffer_lan = PacketSniffer('Test273b-LAN',
                                                  self.__queue_lan, self,
                                                  self.__config,
                                                  self.__lan_device)
        test_lan = self.__packet_sniffer_lan.start()
        self.__config_setup1_1.set_ra2()
        self.set_flags()
        logging.info(self.__test_desc)
        t_test = 0
        sent_reconfigure = False
        time_over = False
        #time.sleep(11111)
        finish_wan = True
        self.__config_setup1_1.set_pd_prefixlen(
            self.__config.get('t3.2.1a', 'pd_prefixlen'))
        self.__config_setup1_1.set_routerlifetime(
            self.__config.get('t3.2.1a', 'routerlifetime'))
        #self.__config_setup1_1.active_DHCP_no_IA_PD()
        while not self.__queue_wan.full():
            if self.__queue_wan.empty():
                if t_test <= 30:

                    time.sleep(1)
                    t_test = t_test + 1
                    #logging.info(' 0 Thread da WAN NOT OK')
                    if t_test % 15 == 0:
                        #logging.info('1 - ENVIA RA')
                        self.__config_setup1_1.set_ether_src(
                            self.__config.get('wan', 'ra_mac'))
                        self.__config_setup1_1.set_ether_dst(
                            self.__config.get('multicast', 'all_mac_nodes'))
                        self.__config_setup1_1.set_ipv6_src(
                            self.__config.get('wan', 'ra_address'))
                        self.__config_setup1_1.set_ipv6_dst(
                            self.__config.get('multicast', 'all_nodes_addr'))
                        self.__sendmsgs.send_tr1_RA(self.__config_setup1_1)

                else:
                    #logging.info(' 2 Time Over')
                    time_over = True
            else:
                pkt = self.__queue_wan.get()
                logging.info(' TEM PACOTE')

                if pkt.haslayer(ICMPv6ND_RS):
                    if pkt[Ether].src == self.__config.get(
                            'wan', 'link_local_mac'):
                        logging.info(' TEM PACOTE continue 1')
                        continue

                    if pkt[Ether].src == self.__config.get('wan', 'ra_mac'):
                        logging.info(' TEM PACOTE continue ')
                        continue
                    logging.info('MAC E ADDR COLETADO')
                    #print(pkt[IPv6].src)
                    #print(pkt[Ether].src)
                    self.__config_setup1_1.set_local_addr_ceRouter(
                        pkt[IPv6].src)
                    self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
                    self.__config_setup1_1.set_ND_local_OK()
                if not time_over:
                    if pkt.haslayer(ICMPv6EchoRequest):
                        self.__packet_sniffer_wan.stop()
                        self.__finish_wan = True
                        self.__fail_test = True
                        return False
                if pkt.haslayer(DHCP6_Solicit):
                    #print(pkt[IPv6].src)
                    #print(pkt[Ether].src)
                    self.__config_setup1_1.set_local_addr_ceRouter(
                        pkt[IPv6].src)
                    self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
                    self.__config_setup1_1.set_ND_local_OK()
                if time_over:
                    #logging.info('FIM DA ESPERA')
                    #time_over = True
                    pkt = self.__queue_wan.get()
                    #logging.info('FIM DA ESPERA')
                    if not self.__config_setup1_1.get_setup1_1_OK():

                        if not self.__config_setup1_1.get_disapproved():
                            self.__config_setup1_1.run_setup1_1(pkt)
                            if pkt.haslayer(ICMPv6ND_RS):

                                if pkt[Ether].src == self.__config.get(
                                        'wan', 'link_local_mac'):
                                    continue
                                if pkt[Ether].src == self.__config.get(
                                        'wan', 'ra_mac'):
                                    continue
                                self.__config_setup1_1.set_ND_local_OK()
                                #if self.__local_ping_OK:
                                #print(pkt[IPv6].src)
                                self.__config_setup1_1.set_local_addr_ceRouter(
                                    pkt[IPv6].src)
                                #print(pkt[Ether].src)
                                self.__config_setup1_1.set_mac_ceRouter(
                                    pkt[Ether].src)

                                self.__config_setup1_1.set_ether_src(
                                    self.__config.get('wan', 'ra_mac'))
                                self.__config_setup1_1.set_ether_dst(
                                    self.__config.get('multicast',
                                                      'all_mac_nodes'))
                                self.__config_setup1_1.set_ipv6_src(
                                    self.__config.get('wan', 'ra_address'))
                                self.__config_setup1_1.set_ipv6_dst(
                                    self.__config.get('multicast',
                                                      'all_nodes_addr'))
                                #               if not self.__active_RA_no_IA_PD:
                                #self.set_lla(self.__config.get('wan','ra_mac'))
                                logging.info('SEND TR1 NA MAIN')
                                self.__sendmsgs.send_tr1_RA(
                                    self.__config_setup1_1)

                        else:
                            logging.info(
                                'Reprovado Teste 2.7.3a - Falha em completar o Common Setup 1.1 da RFC'
                            )
                            self.__packet_sniffer_wan.stop()
                            return False

                    else:
                        if not self.__finish_wan:

                            if pkt.haslayer(ICMPv6EchoRequest):
                                self.__packet_sniffer_wan.stop()
                                self.__packet_sniffer_lan.stop()
                                self.__finish_wan = True
                                self.__fail_test = False
                                logging.info(
                                    'T3.2.1a - Recebido ICMP Request somente após IA_PD '
                                )
                                return True

                            if pkt.haslayer(ICMPv6ND_NS):
                                if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                                        'wan', 'global_wan_addr'):
                                    ##print('LOOP NS')
                                    ##print(pkt[ICMPv6ND_NS].tgt)
                                    #if not send_na_lan:
                                    self.__config_setup1_1.set_ipv6_src(
                                        self.__config.get(
                                            'wan', 'global_wan_addr'))
                                    self.__config_setup1_1.set_ether_src(
                                        self.__config.get(
                                            'wan', 'wan_mac_tr1'))
                                    self.__config_setup1_1.set_ether_dst(
                                        pkt[Ether].src)
                                    self.__config_setup1_1.set_ipv6_dst(
                                        pkt[IPv6].src)
                                    self.__config_setup1_1.set_tgt(
                                        self.__config.get(
                                            'wan', 'global_wan_addr'))
                                    self.__config_setup1_1.set_lla(
                                        self.__config.get(
                                            'wan', 'wan_mac_tr1'))
                                    #send_na_lan = True
                                    self.__sendmsgs.send_icmp_na(
                                        self.__config_setup1_1)

                            ##print('WAN - Concluido')
                            ##print('LAN RESULT')

    #                 if not sent_reconfigure:
    #                     time.sleep(25)
    #                     #print('aqui7')
    #                     self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','link_local_addr'))
    #                     #print('aqui8')
    #                     self.__config_setup1_1.set_ipv6_dst(self.__config_setup1_1.get_local_addr_ceRouter())
    #                     #print('aqui10')
    #                     self.__config_setup1_1.set_ether_src(self.__config.get('wan','link_local_mac'))
    #                     #print('aqui11')
    #                     self.__config_setup1_1.set_ether_dst(self.__config_setup1_1.get_mac_ceRouter())
    #                     #print('aqui12')
    #                     self.__config_setup1_1.set_dhcp_reconf_type(self.__config.get('t1.6.3','msg_type'))
    #                     #print('aqui13')
    #                     self.__config_setup1_1.set_udp_sport('547')
    #                     self.__config_setup1_1.set_udp_dport('546')
    #                     self.__sendmsgs.send_dhcp_reconfigure(self.__config_setup1_1)
    #                     #print('aqui14')
    #                     sent_reconfigure = True

    #                 if pkt.haslayer(DHCP6_Renew):
    #                     if not self.__dhcp_renew_done:
    # #                        if self.__active_renew_dhcp:
    #                         self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
    #                         self.__config_setup1_1.set_local_addr_ceRouter(pkt[IPv6].src)
    #                         self.__config_setup1_1.set_xid(pkt[DHCP6_Renew].trid)
    #                         self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','link_local_addr'))
    #                         self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
    #                         self.__config_setup1_1.set_ether_src(self.__config.get('wan','link_local_mac'))
    #                         self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
    #                         self.__config_setup1_1.set_dhcp_preflft('100')
    #                         self.__config_setup1_1.set_dhcp_validlft('200')
    #                         self.__config_setup1_1.set_dhcp_plen('60')
    #                         self.__config_setup1_1.set_prefix_addr(self.__config.get('setup1-1_advertise','ia_pd_address'))
    #                         self.__sendmsgs.send_dhcp_reply_v3(self.__config_setup1_1)
    #                         #self.__dhcp_ok = True
    #                         self.__dhcp_renew_done = True
                        else:
                            self.__packet_sniffer_wan.stop()
                            if self.__fail_test:
                                return False
                            else:
                                return True
        self.__packet_sniffer_wan.stop()
        return False
コード例 #3
0
class Test321a:

    def __init__(self,config,app):
        self.__app = app
        self.__queue_wan = Queue()
        self.__queue_lan = Queue()
        self.__config = config
        self.__interface = None
        self.__pkt = None
        self.__local_addr_ceRouter =None
        self.__sendmsgs = SendMsgs(self.__config)
        self.__config_setup1_1 = ConfigSetup1_1(self.__config)
        #self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config)
        self.__wan_device_tr1 = self.__config.get('wan','device_wan_tr1')
        self.__lan_device = self.__config.get('lan','lan_device')
        self.__wan_mac_tr1 = self.__config.get('wan','wan_mac_tr1')
        self.__link_local_addr = self.__config.get('wan','link_local_addr')
        self.__all_nodes_addr = self.__config.get('multicast','all_nodes_addr')
        self.__test_desc = self.__config.get('tests','3.2.1a')
        self.__t_lan = None
        self.__finish_wan = False
        self.__dhcp_renew_done = False
        self.msg = self.__config.get('tests','3.2.1a')
        self.msg_lan =self.__config.get('tests','3.2.1a')
        self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config,self.__lan_device)



    def set_flags(self):
        self.__config_setup1_1.set_flag_M(self.__config.get('t3.2.1a','flag_m'))
        self.__config_setup1_1.set_flag_0(self.__config.get('t3.2.1a','flag_o'))
        self.__config_setup1_1.set_flag_chlim(self.__config.get('t3.2.1a','flag_chlim'))
        self.__config_setup1_1.set_flag_L(self.__config.get('t3.2.1a','flag_l'))
        self.__config_setup1_1.set_flag_A(self.__config.get('t3.2.1a','flag_a'))
        self.__config_setup1_1.set_flag_R(self.__config.get('t3.2.1a','flag_r'))
        self.__config_setup1_1.set_flag_prf(self.__config.get('t3.2.1a','flag_prf'))
        self.__config_setup1_1.set_validlifetime(self.__config.get('t3.2.1a','validlifetime'))
        self.__config_setup1_1.set_preferredlifetime(self.__config.get('t3.2.1a','preferredlifetime'))
        self.__config_setup1_1.set_routerlifetime(self.__config.get('t3.2.1a','routerlifetime'))
        self.__config_setup1_1.set_reachabletime(self.__config.get('t3.2.1a','reach_time'))
        self.__config_setup1_1.set_retranstimer(self.__config.get('t3.2.1a','retrans_time'))        
        self.__config_setup1_1.set_intervalo(self.__config.get('t1.6.6b','intervalo'))
        self.__config_setup1_1.set_prefix_addr(self.__config.get('setup1-1_advertise','ia_pd_address'))
        self.__config_setup1_1.set_dhcp_t1(self.__config.get('t3.2.1a','dhcp_t1'))
        self.__config_setup1_1.set_dhcp_t2(self.__config.get('t3.2.1a','dhcp_t2'))
        self.__config_setup1_1.set_dhcp_preflft(self.__config.get('t3.2.1a','dhcp_preflft'))
        self.__config_setup1_1.set_dhcp_validlft(self.__config.get('t3.2.1a','dhcp_validlft'))
        self.__config_setup1_1.set_dhcp_plen(self.__config.get('t3.2.1a','dhcp_plen'))
   
    def set_flags_lan(self):
        self.__config_setup_lan.set_elapsetime(self.__config.get('solicitlan','elapsetime'))
        self.__config_setup_lan.set_xid(self.__config.get('solicitlan','xid'))
        self.__config_setup_lan.set_fdqn(self.__config.get('solicitlan','clientfqdn'))
        self.__config_setup_lan.set_vendor_class(self.__config.get('solicitlan','vendorclass'))

        self.__config_setup_lan.set_enterprise(self.__config.get('solicitlan','enterpriseid'))
        self.__config_setup_lan.set_client_duid(self.__config.get('solicitlan','duid'))
        self.__config_setup_lan.set_iaid(self.__config.get('solicitlan','iaid'))

    def set_status_lan(self,v):
        self.msg_lan = v

    def get_status_lan(self):
        return self.msg_lan


    def set_status(self,v):
        self.msg = v

    def get_status(self):
        return self.msg

    def dhcp_information_lan(self):
        self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_ether_dst('33:33:00:01:00:02')
        self.__config_setup_lan.set_ipv6_dst(self.__config.get('multicast','all_routers_addr'))
        self.__config_setup_lan.set_xid(self.__config.get('informationlan','xid'))
        self.__config_setup_lan.set_elapsetime(self.__config.get('informationlan','elapsetime'))
        self.__config_setup_lan.set_vendor_class(self.__config.get('informationlan','vendorclass'))
        self.__sendmsgs.send_dhcp_information(self.__config_setup_lan)
        
    def run_Lan(self):
        #self.__config_setup_lan_.flags_partA()

        t_test = 0
        t_test1= 0
        time_p = 0
        sent_reconfigure = False
        time_over = False
        send_ra = False
        send_na_lan = False
        self.set_flags_lan()
        self.__config_setup_lan.set_setup_lan_start()
        cache_lan = []

        @self.__app.route("/LAN",methods=['GET'])
        def envia_lan():
            return self.get_status_lan()

        while not self.__queue_lan.full():
            if self.__queue_lan.empty():
                if t_test < 50:
 
                    time.sleep(1)
                    t_test = t_test + 1
                    if t_test % 5 ==0:
                        #print('0')
                        #print('ENVIO RS - 1 LAN')
                        self.set_status_lan('LAN: Enviando DHCP information e RS periódico - MELHORAR O TESTE')
                        logging.info('LAN: Enviando DHCP information e RS periódico')
                        self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
                        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                        self.__config_setup_lan.set_ether_dst('33:33:00:01:00:02')
                        self.__config_setup_lan.set_ipv6_dst(self.__config.get('multicast','all_routers_addr'))
                        self.__config_setup_lan.set_xid(self.__config.get('informationlan','xid'))
                        #self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
                        self.__config_setup_lan.set_elapsetime(self.__config.get('informationlan','elapsetime'))
                        self.__config_setup_lan.set_vendor_class(self.__config.get('informationlan','vendorclass'))
                        self.__sendmsgs.send_dhcp_information(self.__config_setup_lan)
                        

                        #self.__config_setup_lan.set_setup_lan_start()
                        self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
                        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                        self.__config_setup_lan.set_ether_dst(self.__config.get('multicast','all_mac_routers'))
                        self.__config_setup_lan.set_ipv6_dst(self.__config.get('general','all_routers_address'))
                        self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
                        self.__sendmsgs.send_icmp_rs(self.__config_setup_lan)

                        if self.__config_setup_lan.get_mac_ceRouter() != None:
                            #print('6')
                            self.set_status_lan('LAN: Enviando Echo Request para o TN1')
                            logging.info('LAN: Enviando Echo Request para o TN1')
                            self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))
                            self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                            self.__config_setup_lan.set_ether_dst(self.__config_setup_lan.get_mac_ceRouter())
                            self.__config_setup_lan.set_ipv6_dst(self.__config.get('wan','global_wan_addr'))
                            self.__sendmsgs.send_echo_request_lan(self.__config_setup_lan)
                         

                    
                else:
                    time_over = True


            else:

                pkt = self.__queue_lan.get()
                cache_lan.append(pkt)
                wrpcap("LAN-3.2.1a.cap",cache_lan)
                if not time_over:
                    if pkt.haslayer(ICMPv6EchoReply):
                        self.set_status_lan('LAN Teste 3.2.1a - APROVADO. TN1 Respondeu ao echo request do TN2 por IP global')
                        time.sleep(2)
                        self.set_status_lan('APROVADO') # Mensagem padrão para o frontEnd atualizar Status
                        logging.info('Teste 3.2.1a - APROVADO. TN1 Respondeu ao Echo request do TN2 por IP global')

                        self.__packet_sniffer_lan.stop()
                        self.__finish_wan = True 
                        self.__fail_test = True
                        return False

                    if pkt.haslayer(ICMPv6ND_RA):

                        self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)

                    if pkt.haslayer(ICMPv6MLReport2):
                        self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)

                    if pkt.haslayer(DHCP6_Reply):
                        self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)


                    if pkt[Ether].src == self.__config.get('lan','mac_address'):

                        continue

                    if pkt.haslayer(ICMPv6ND_NS):

                        if pkt[ICMPv6ND_NS].tgt == self.__config.get('lan','global_wan_addr'):

                            self.set_status_lan('LAN: Respondendo ao NS com NA global')
                            logging.info('LAN: Respondendo ao NS com NA global')

                            self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))
                            self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                            self.__config_setup_lan.set_ether_dst(pkt[Ether].dst)
                            self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                            self.__config_setup_lan.set_tgt(self.__config.get('lan','global_wan_addr'))
                            self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))

                            self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
                            self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)
                            
                        if pkt[ICMPv6ND_NS].tgt == self.__config.get('lan','lan_local_addr'):
                            self.set_status_lan('LAN: Respondendo ao NS com NA local')
                            logging.info('LAN: Respondendo ao NS com NA local')
                            self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
                            self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                            self.__config_setup_lan.set_ether_dst(pkt[Ether].dst)
                            self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                            self.__config_setup_lan.set_tgt(self.__config.get('lan','lan_local_addr'))
                            self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))

                            self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
                            self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)

                if self.__config_setup1_1.get_setup1_1_OK():

                    if pkt[Ether].src == self.__config.get('lan','mac_address'):

                        continue

                    if self.__config_setup_lan.get_mac_ceRouter() != None:


                        self.set_status_lan('Setup 1.1 Concluido. Enviando Echo Request para TN1')
                        logging.info('Setup 1.1 Concluido. Enviando Echo Request para TN1')

                        self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))
                        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                        self.__config_setup_lan.set_ether_dst(self.__config_setup_lan.get_mac_ceRouter())
                        self.__config_setup_lan.set_ipv6_dst(self.__config.get('wan','global_wan_addr'))
                        self.__sendmsgs.send_echo_request_lan(self.__config_setup_lan)

                    if pkt.haslayer(ICMPv6ND_NS):
                        if pkt[ICMPv6ND_NS].tgt == self.__config.get('lan','global_wan_addr'):
                            self.set_status_lan('Setup 1.1 Concluido. Respondendo ao NS do CeRouter com NA global')
                            logging.info('Setup 1.1 Concluido. Respondendo ao NS do CeRouter com NA global')

                            self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))
                            self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                            self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
                            self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                            self.__config_setup_lan.set_tgt(self.__config.get('lan','global_wan_addr'))
                            self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))

                            self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)

    def run(self):
        @self.__app.route("/WAN",methods=['GET'])
        def enviawan():
            return self.get_status()
        self.__t_lan =  Thread(target=self.run_Lan,name='LAN_Thread')
        self.__t_lan.start()
        
        self.__packet_sniffer_wan = PacketSniffer('Test321a-WAN',self.__queue_wan,self,self.__config,self.__wan_device_tr1)
        self.__packet_sniffer_wan.start()
        
        self.__packet_sniffer_lan = PacketSniffer('Test321a-LAN',self.__queue_lan,self,self.__config,self.__lan_device)
        test_lan = self.__packet_sniffer_lan.start()
        self.__config_setup1_1.set_ra2()
        self.set_flags()
        logging.info(self.__test_desc)
        t_test = 0
        sent_reconfigure = False
        time_over = False
        cache_wan = []

        finish_wan = False
        self.__config_setup1_1.set_pd_prefixlen(self.__config.get('t3.2.1a','pd_prefixlen')) 
        self.__config_setup1_1.set_routerlifetime(self.__config.get('t3.2.1a','routerlifetime')) 
        while not self.__queue_wan.full():
            if self.__queue_wan.empty():
                if t_test <= 30:

                    time.sleep(1)
                    t_test = t_test + 1

                    if t_test % 15 ==0:
                        self.set_status('WAN: Enviando ICMP RA periódico')
                        logging.info('WAN: Enviando ICMP RA periódico')
                        self.__config_setup1_1.set_ether_src(self.__config.get('wan','ra_mac'))
                        self.__config_setup1_1.set_ether_dst(self.__config.get('multicast','all_mac_nodes'))
                        self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','ra_address'))
                        self.__config_setup1_1.set_ipv6_dst(self.__config.get('multicast','all_nodes_addr'))
                        self.__sendmsgs.send_tr1_RA(self.__config_setup1_1)

                else:
                    #logging.info(' 2 Time Over')
                    time_over = True      
            else:
                pkt = self.__queue_wan.get()
                cache_wan.append(pkt)
                wrpcap("WAN-3.2.1a.cap",cache_wan)

                if pkt.haslayer(ICMPv6ND_RS):
                    if pkt[Ether].src == self.__config.get('wan','link_local_mac'):
                        #logging.info(' TEM PACOTE continue 1')
                        continue
                                    
                    if pkt[Ether].src == self.__config.get('wan','ra_mac'):
                        l#ogging.info(' TEM PACOTE continue ')
                        continue
                    #logging.info('MAC E ADDR COLETADO')   
                    #print(pkt[IPv6].src)
                    #print(pkt[Ether].src)
                    self.__config_setup1_1.set_local_addr_ceRouter(pkt[IPv6].src)
                    self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)    
                    self.__config_setup1_1.set_ND_local_OK()
                if not time_over :
                    if pkt.haslayer(ICMPv6EchoRequest):
                        self.__packet_sniffer_wan.stop()
                        self.__finish_wan = True 
                        self.__fail_test = True
                        return False
                if pkt.haslayer(DHCP6_Solicit):
                    #print(pkt[IPv6].src)
                    #print(pkt[Ether].src)
                    self.__config_setup1_1.set_local_addr_ceRouter(pkt[IPv6].src)
                    self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
                    self.__config_setup1_1.set_ND_local_OK()   
                if time_over:
                    #logging.info('FIM DA ESPERA')
                    #time_over = True
                    pkt = self.__queue_wan.get()
                    #logging.info('FIM DA ESPERA')
                    if not self.__config_setup1_1.get_setup1_1_OK():
                        self.set_status('WAN: Setup 1.1 em execução')
                        logging.info('WAN: Setup 1.1 em execução')
                        if not self.__config_setup1_1.get_disapproved():
                            self.__config_setup1_1.run_setup1_1(pkt)
                            if pkt.haslayer(ICMPv6ND_RS):


                                if pkt[Ether].src == self.__config.get('wan','link_local_mac'):
                                    continue
                                if pkt[Ether].src == self.__config.get('wan','ra_mac'):
                                    continue
                                self.__config_setup1_1.set_ND_local_OK()
                                #if self.__local_ping_OK:
                                #print(pkt[IPv6].src)
                                self.__config_setup1_1.set_local_addr_ceRouter(pkt[IPv6].src)
                                #print(pkt[Ether].src)
                                self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src) 
                                
                                self.__config_setup1_1.set_ether_src(self.__config.get('wan','ra_mac'))
                                self.__config_setup1_1.set_ether_dst(self.__config.get('multicast','all_mac_nodes'))
                                self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','ra_address'))
                                self.__config_setup1_1.set_ipv6_dst(self.__config.get('multicast','all_nodes_addr'))
                #               if not self.__active_RA_no_IA_PD:
                                #self.set_lla(self.__config.get('wan','ra_mac'))
                                #logging.info('SEND TR1 NA MAIN')
                                self.__sendmsgs.send_tr1_RA(self.__config_setup1_1)


                        else:
                            logging.info('Reprovado Teste 3.2.1a - Falha em completar o Common Setup 1.1 da RFC')
                            self.__packet_sniffer_wan.stop() 
                            return False

                    else:
                        if not self.__finish_wan:

                            if pkt.haslayer(ICMPv6EchoRequest):

                                self.__packet_sniffer_wan.stop()
                                self.__packet_sniffer_lan.stop()


                                self.set_status('Teste 3.2.1a - Recebido ICMP Request somente após IA_PD')
                                time.sleep(2)
                                self.set_status('APROVADO') # Mensagem padrão para o frontEnd atualizar Status
                                logging.info('Teste 3.2.1a - Recebido ICMP Request somente após IA_PD')

                                self.__finish_wan = True 
                                self.__fail_test = False
                                return True
                        
                            if pkt.haslayer(ICMPv6ND_NS):
                                if pkt[ICMPv6ND_NS].tgt == self.__config.get('wan','global_wan_addr'):
                                    ##print('LOOP NS')
                                    ##print(pkt[ICMPv6ND_NS].tgt)
                                    #if not send_na_lan:
                                    self.set_status('WAN: Enviando resposta ao NS com ICMP NA global')
                                    logging.info('WAN: Enviando resposta ao NS com ICMP NA global')

                                    self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','global_wan_addr'))
                                    self.__config_setup1_1.set_ether_src(self.__config.get('wan','wan_mac_tr1'))
                                    self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
                                    self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
                                    self.__config_setup1_1.set_tgt(self.__config.get('wan','global_wan_addr'))
                                    self.__config_setup1_1.set_lla(self.__config.get('wan','wan_mac_tr1'))
                                    #send_na_lan = True
                                    self.__sendmsgs.send_icmp_na(self.__config_setup1_1)




                        else:
                            self.__packet_sniffer_wan.stop()
                            if self.__fail_test:
                                return False
                            else:
                                return True
        self.__packet_sniffer_wan.stop()
        return False
     
        
コード例 #4
0
ファイル: test321b.py プロジェクト: ronyjah/rfc
class Test321b:

    def __init__(self,config):
        self.__queue_wan = Queue()
        self.__queue_lan = Queue()
        self.__config = config
        self.__interface = None
        self.__pkt = None
        self.__local_addr_ceRouter =None
        self.__sendmsgs = SendMsgs(self.__config)
        self.__config_setup1_1 = ConfigSetup1_1(self.__config)
        #self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config)
        self.__wan_device_tr1 = self.__config.get('wan','device_wan_tr1')
        self.__lan_device = self.__config.get('lan','lan_device')
        self.__wan_mac_tr1 = self.__config.get('wan','wan_mac_tr1')
        self.__link_local_addr = self.__config.get('wan','link_local_addr')
        self.__all_nodes_addr = self.__config.get('multicast','all_nodes_addr')
        self.__test_desc = self.__config.get('tests','3.2.1b')
        self.__t_lan = None
        self.__finish_wan = False
        self.__dhcp_renew_done = False
        self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config,self.__lan_device)



    def set_flags(self):
        self.__config_setup1_1.set_flag_M(self.__config.get('t3.2.1b','flag_m'))
        self.__config_setup1_1.set_flag_0(self.__config.get('t3.2.1b','flag_o'))
        self.__config_setup1_1.set_flag_chlim(self.__config.get('t3.2.1b','flag_chlim'))
        self.__config_setup1_1.set_flag_L(self.__config.get('t3.2.1b','flag_l'))
        self.__config_setup1_1.set_flag_A(self.__config.get('t3.2.1b','flag_a'))
        self.__config_setup1_1.set_flag_R(self.__config.get('t3.2.1b','flag_r'))
        self.__config_setup1_1.set_flag_prf(self.__config.get('t3.2.1b','flag_prf'))
        self.__config_setup1_1.set_validlifetime(self.__config.get('t3.2.1b','validlifetime'))
        self.__config_setup1_1.set_preferredlifetime(self.__config.get('t3.2.1b','preferredlifetime'))
        self.__config_setup1_1.set_routerlifetime(self.__config.get('t3.2.1b','routerlifetime'))
        self.__config_setup1_1.set_reachabletime(self.__config.get('t3.2.1b','reach_time'))
        self.__config_setup1_1.set_retranstimer(self.__config.get('t3.2.1b','retrans_time'))        
        self.__config_setup1_1.set_intervalo(self.__config.get('t1.6.6b','intervalo'))
        self.__config_setup1_1.set_prefix_addr(self.__config.get('setup1-1_advertise','ia_pd_address'))
        self.__config_setup1_1.set_dhcp_t1(self.__config.get('t3.2.1b','dhcp_t1'))
        self.__config_setup1_1.set_dhcp_t2(self.__config.get('t3.2.1b','dhcp_t2'))
        self.__config_setup1_1.set_dhcp_preflft(self.__config.get('t3.2.1b','dhcp_preflft'))
        self.__config_setup1_1.set_dhcp_validlft(self.__config.get('t3.2.1b','dhcp_validlft'))
        self.__config_setup1_1.set_dhcp_plen(self.__config.get('t3.2.1b','dhcp_plen'))
   
    def set_flags_lan(self):
        self.__config_setup_lan.set_elapsetime(self.__config.get('solicitlan','elapsetime'))
        self.__config_setup_lan.set_xid(self.__config.get('solicitlan','xid'))
        self.__config_setup_lan.set_fdqn(self.__config.get('solicitlan','clientfqdn'))
        self.__config_setup_lan.set_vendor_class(self.__config.get('solicitlan','vendorclass'))

        self.__config_setup_lan.set_enterprise(self.__config.get('solicitlan','enterpriseid'))
        self.__config_setup_lan.set_client_duid(self.__config.get('solicitlan','duid'))
        self.__config_setup_lan.set_iaid(self.__config.get('solicitlan','iaid'))


        
    def run_Lan(self):
        #self.__config_setup_lan_.flags_partA()
        logging.info('Thread da LAN inicio')
        t_test = 0
        t_test1= 0
        time_p = 0
        sent_reconfigure = False
        time_over = False
        send_ra = False
        send_na_lan = False
        self.set_flags_lan()
        self.__config_setup_lan.set_setup_lan_start()
        while not self.__queue_lan.full():
            if self.__queue_lan.empty():
                if t_test < 30:
 





 
                    time.sleep(1)
                    t_test = t_test + 1
                    if t_test % 5 ==0:
                        #print('0')
                        #print('ENVIO RS - 1 LAN')
                        self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
                        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                        self.__config_setup_lan.set_ether_dst('33:33:00:01:00:02')
                        self.__config_setup_lan.set_ipv6_dst(self.__config.get('multicast','all_routers_addr'))
                        self.__config_setup_lan.set_xid(self.__config.get('informationlan','xid'))
                        #self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
                        self.__config_setup_lan.set_elapsetime(self.__config.get('informationlan','elapsetime'))
                        self.__config_setup_lan.set_vendor_class(self.__config.get('informationlan','vendorclass'))
                        self.__sendmsgs.send_dhcp_information(self.__config_setup_lan)
                        

                        #self.__config_setup_lan.set_setup_lan_start()
                        self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
                        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                        self.__config_setup_lan.set_ether_dst(self.__config.get('multicast','all_mac_routers'))
                        self.__config_setup_lan.set_ipv6_dst(self.__config.get('general','all_routers_address'))
                        self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
                        self.__sendmsgs.send_icmp_rs(self.__config_setup_lan)

                        # if self.__config_setup_lan.get_mac_ceRouter() != None:
                        #     #print('6')
                        #     self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))
                        #     self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                        #     self.__config_setup_lan.set_ether_dst(self.__config_setup_lan.get_mac_ceRouter())
                        #     self.__config_setup_lan.set_ipv6_dst(self.__config.get('wan','global_wan_addr'))
                        #     self.__sendmsgs.send_echo_request_lan(self.__config_setup_lan)
                            
                        # self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
                        # self.__config_setup_lan.set_ipv6_dst(self.__config.get('multicast','all_nodes_addr'))
                        # self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                        # self.__config_setup_lan.set_ether_dst(self.__config.get('multicast','all_mac_nodes'))
                        # #self.set_tgt(self.get_local_addr_ceRouter())
                        
                        # self.__config_setup_lan.set_tgt(self.__config.get('wan','link_local_addr'))
                        # #self.__sendmsgssetup1_1.send_echo_request(self)
                        # self.__config_setup_lan.set_lla(self.__config.get('wan','link_local_mac'))
                        # self.__sendmsgs.send_icmp_ns_lan(self.__config_setup_lan)
                        #print('1')

                    logging.info('Thread da LAN time')
                    time.sleep(1)
                else:
                    time_over = True

#                    t_test = t_test + 1
 #                   if self.__config_setup1_1.get_recvd_dhcp_renew():
                #pkt = self.__queue_lan.get()
            else:
                print('AQUI-1')
                pkt = self.__queue_lan.get()
                print('AQUI-2')
                if not time_over:
                    if pkt.haslayer(ICMPv6EchoRequest):
                        print('AQUI-2.0')
                        self.__packet_sniffer_lan.stop()
                        self.__finish_wan = True 
                        self.__fail_test = True
                        return False
                    print('AQUI-3')
                    if pkt.haslayer(ICMPv6ND_RA):
                        self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
                    print('AQUI-4')
                    if pkt.haslayer(ICMPv6MLReport2):
                        self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
                    print('AQUI-5')
                    if pkt.haslayer(DHCP6_Reply):
                        self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)

                    if pkt[Ether].src == self.__config.get('lan','mac_address'):
                        continue
                    print('AQUI-6')
                    if pkt.haslayer(ICMPv6ND_NS):
                        print('AQUI-7')

                        if pkt.haslayer(ICMPv6EchoRequest):

                            logging.info('Reprovado Teste 2.7.3b - Recebeu ICMPv6EchoRequest antes do IP_PD ser fornecido à porta WAN do roteador')
                            self.__packet_sniffer_wan.stop() 
                            return False
                            #print('AQUI-2.0')
                            self.__packet_sniffer_lan.stop()
                            self.__finish_wan = True 
                            self.__fail_test = False
                            return False


                        print('AQUI-8')
                        if pkt[ICMPv6ND_NS].tgt == self.__config.get('lan','global_wan_addr'):
                            self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))
                            self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                            self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
                            self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                            self.__config_setup_lan.set_tgt(self.__config.get('lan','global_wan_addr'))
                            self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
                            self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
                            self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)
                        print('AQUI-9')
                        if pkt[ICMPv6ND_NS].tgt == self.__config.get('lan','lan_local_addr'):

                            self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
                            self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                            self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
                            self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                            self.__config_setup_lan.set_tgt(self.__config.get('lan','lan_local_addr'))
                            self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
                            self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
                            self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)
                            
                if self.__config_setup1_1.get_setup1_1_OK():
                    if pkt[Ether].src == self.__config.get('lan','mac_address'):
                        continue

                    if pkt.haslayer(ICMPv6EchoRequest):

                        logging.info('Aprovado Teste 2.7.3b - Recebeu ICMPv6EchoRequest Apos do IP_PD ser fornecido à porta WAN do roteador')
                        self.__packet_sniffer_wan.stop() 
                        return False
                        #print('AQUI-2.0')
                        self.__packet_sniffer_lan.stop()
                        self.__finish_wan = True 
                        self.__fail_test = False
                        return False



                    if pkt.haslayer(ICMPv6ND_NS):

                        if pkt[ICMPv6ND_NS].tgt == self.__config.get('lan','global_wan_addr'):
                            self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))
                            self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                            self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
                            self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                            self.__config_setup_lan.set_tgt(self.__config.get('lan','global_wan_addr'))
                            self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
                            self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
                            self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)
                            
                        if pkt[ICMPv6ND_NS].tgt == self.__config.get('lan','lan_local_addr'):

                            self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
                            self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                            self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
                            self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                            self.__config_setup_lan.set_tgt(self.__config.get('lan','lan_local_addr'))
                            self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
                            self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
                            self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)



    def rourter_advertise(self):
        self.__config_setup1_1.set_ether_src(self.__config.get('wan','ra_mac'))
        self.__config_setup1_1.set_ether_dst(self.__config.get('multicast','all_mac_nodes'))
        self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','ra_address'))
        self.__config_setup1_1.set_ipv6_dst(self.__config.get('multicast','all_nodes_addr'))
        self.__sendmsgs.send_tr1_RA(self.__config_setup1_1)
    
    def ping(self):
        if self.__config_setup1_1.get_mac_ceRouter() != None:
            #print('6')
            self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','global_wan_addr'))
            self.__config_setup1_1.set_ether_src(self.__config.get('wan','wan_mac_tr1'))
            self.__config_setup1_1.set_ether_dst(self.__config_setup1_1.get_mac_ceRouter())
            self.__config_setup1_1.set_ipv6_dst(self.__config.get('lan','global_wan_addr'))
            self.__sendmsgs.send_echo_request(self.__config_setup1_1)

    def neighbor_advertise_local(self,pkt):
        self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','link_local_addr'))
        self.__config_setup1_1.set_ether_src(self.__config.get('wan','wan_mac_tr1'))
        self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
        self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup1_1.set_tgt(self.__config.get('wan','link_local_addr'))
        self.__config_setup1_1.set_lla(self.__config.get('wan','wan_mac_tr1'))
        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na(self.__config_setup1_1)

    def neighbor_advertise_global(self,pkt):
        self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','global_wan_addr'))
        self.__config_setup1_1.set_ether_src(self.__config.get('wan','wan_mac_tr1'))
        self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
        self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup1_1.set_tgt(self.__config.get('wan','global_wan_addr'))
        self.__config_setup1_1.set_lla(self.__config.get('wan','wan_mac_tr1'))
        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na(self.__config_setup1_1)


    def run(self):
        self.__t_lan =  Thread(target=self.run_Lan,name='LAN_Thread')
        self.__t_lan.start()
        
        self.__packet_sniffer_wan = PacketSniffer('Test273b-WAN',self.__queue_wan,self,self.__config,self.__wan_device_tr1)
        self.__packet_sniffer_wan.start()
        
        self.__packet_sniffer_lan = PacketSniffer('Test273b-LAN',self.__queue_lan,self,self.__config,self.__lan_device)
        test_lan = self.__packet_sniffer_lan.start()
        self.__config_setup1_1.set_ra2()
        self.set_flags()
        logging.info(self.__test_desc)
        t_test = 0
        time1 = 0
        sent_reconfigure = False
        time_over = False

        finish_wan = True
        self.__config_setup1_1.set_pd_prefixlen(self.__config.get('t3.2.1b','pd_prefixlen')) 
        self.__config_setup1_1.set_routerlifetime(self.__config.get('t3.2.1b','routerlifetime')) 
        while not self.__queue_wan.full():
            if self.__queue_wan.empty():
                if t_test <= 50:
                    time.sleep(1)
                    t_test = t_test + 1
                    if t_test % 10 == 0:
                        #self.rourter_advertise()
                        self.ping()
                        
                else:
                    time_over = True      
            else:
                pkt = self.__queue_wan.get()

                if not self.__config_setup1_1.get_ND_local_OK():

                    if pkt[Ether].src == self.__config.get('wan','link_local_mac'):
                        print('ND_LOCAL,continue')
                        continue

                    if pkt[Ether].src == self.__config.get('wan','ra_mac'):
                        print('ND_LOCAL-A,continue')                        
                        continue


                    if pkt.haslayer(ICMPv6ND_RS):
                  
                        if pkt[Ether].src == self.__config.get('wan','link_local_mac'):
                            print('RS,continue')         
                            continue

                        if pkt[Ether].src == self.__config.get('wan','ra_mac'):
                            print('RS-A,continue')                                     
                            continue

                        self.__config_setup1_1.set_local_addr_ceRouter(pkt[IPv6].src)
                        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)    
                        #self.__config_setup1_1.set_ND_local_OK()

                    if pkt.haslayer(DHCP6_Solicit):
                        if pkt[Ether].src == self.__config.get('wan','link_local_mac'):
                            print('solicit,continue')
                            continue

                        if pkt[Ether].src == self.__config.get('wan','ra_mac'):
                            print('solicitA,continue')
                            continue
                        self.__config_setup1_1.set_local_addr_ceRouter(pkt[IPv6].src)
                        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
                        #self.__config_setup1_1.set_ND_local_OK()  

                if pkt.haslayer(ICMPv6ND_NS):

                    if pkt[ICMPv6ND_NS].tgt == self.__config.get('wan','global_wan_addr'):
                        self.neighbor_advertise_global(pkt)
                        
                    if pkt[ICMPv6ND_NS].tgt == self.__config.get('wan','link_local_addr'):
                        self.neighbor_advertise_local(pkt)

                if time_over:
                    print('time-over')
                    #pkt = self.__queue_wan.get()
                    if not self.__config_setup1_1.get_setup1_1_OK():
                        print('test1')
                        if not self.__config_setup1_1.get_disapproved():
                            print('test2')
                            self.__config_setup1_1.run_setup1_1(pkt)
                            print('test3')
                            if pkt.haslayer(ICMPv6ND_RS):

                                if pkt[Ether].src == self.__config.get('wan','link_local_mac'):
                                    print('RS-2,continue')         
                                    continue
                                if pkt[Ether].src == self.__config.get('wan','ra_mac'):
                                    print('RS-2A,continue')
                                    continue
                                print('test4')
                                #self.__config_setup1_1.set_ND_local_OK()
                                self.__config_setup1_1.set_local_addr_ceRouter(pkt[IPv6].src)
                                self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)                                 
                                self.__config_setup1_1.set_ether_src(self.__config.get('wan','ra_mac'))
                                self.__config_setup1_1.set_ether_dst(self.__config.get('multicast','all_mac_nodes'))
                                self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','ra_address'))
                                self.__config_setup1_1.set_ipv6_dst(self.__config.get('multicast','all_nodes_addr'))
                                self.__sendmsgs.send_tr1_RA(self.__config_setup1_1)

                        else:
                            logging.info('Reprovado Teste 2.7.3b - Falha em completar o Common Setup 1.1 da RFC')
                            self.__packet_sniffer_wan.stop() 
                            return False

                    else:
                        if not self.__finish_wan:
                            if time1 < 30:
                                time1 = time1 + 1
                                if time1 % 5 == 0: 
                                    self.ping()
                                    

                            if pkt.haslayer(ICMPv6ND_NS):
                                if pkt[ICMPv6ND_NS].tgt == self.__config.get('wan','global_wan_addr'):
                                    print('glboal')
                                    self.neighbor_advertise_global(pkt)

                                if pkt[ICMPv6ND_NS].tgt == self.__config.get('wan','ra_address'):
                                    print('local')
                                    self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','ra_address'))
                                    self.__config_setup1_1.set_ether_src(self.__config.get('wan','ra_mac'))
                                    self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
                                    self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
                                    self.__config_setup1_1.set_tgt(self.__config.get('wan','ra_address'))
                                    self.__config_setup1_1.set_lla(self.__config.get('wan','ra_mac'))
                                    self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
                                    self.__sendmsgs.send_icmp_na(self.__config_setup1_1)
                                    ##print('LOOP NS')
                                    # ##print(pkt[ICMPv6ND_NS].tgt)
                                    # self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','global_wan_addr'))
                                    # self.__config_setup1_1.set_ether_src(self.__config.get('wan','wan_mac_tr1'))
                                    # self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
                                    # self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
                                    # self.__config_setup1_1.set_tgt(self.__config.get('wan','global_wan_addr'))
                                    # self.__config_setup1_1.set_lla(self.__config.get('wan','wan_mac_tr1'))
                                    # self.__sendmsgs.send_icmp_na(self.__config_setup1_1)
                        else:
                            self.__packet_sniffer_wan.stop()
                            if self.__fail_test:
                                return False
                            else:
                                return True
        self.__packet_sniffer_wan.stop()
        return False
     
        
コード例 #5
0
class Test322b:

    def __init__(self,config,app):
        self.__app = app
        self.__queue_wan = Queue()
        self.__queue_lan = Queue()
        self.__config = config
        self.__interface = None
        self.__pkt = None
        self.__local_addr_ceRouter =None
        self.__sendmsgs = SendMsgs(self.__config)
        self.__config_setup1_1 = ConfigSetup1_1(self.__config)
        #self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config)
        self.__wan_device_tr1 = self.__config.get('wan','device_wan_tr1')
        self.__lan_device = self.__config.get('lan','lan_device')
        self.__wan_mac_tr1 = self.__config.get('wan','wan_mac_tr1')
        self.__link_local_addr = self.__config.get('wan','link_local_addr')
        self.__all_nodes_addr = self.__config.get('multicast','all_nodes_addr')
        self.__test_desc = self.__config.get('tests','3.2.2b')
        self.__t_lan = None
        self.__finish_wan = False
        self.part2_lan_start = False
        self.__dhcp_renew_done = False
        self.stop_ping_OK = False
        self.msg = self.__config.get('tests','3.2.2b')
        self.msg_lan =self.__config.get('tests','3.2.2b')
        self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config,self.__lan_device)



    def set_flags(self):
        self.__config_setup1_1.set_flag_M(self.__config.get('t3.2.2b','flag_m'))
        self.__config_setup1_1.set_flag_0(self.__config.get('t3.2.2b','flag_o'))
        self.__config_setup1_1.set_flag_chlim(self.__config.get('t3.2.2b','flag_chlim'))
        self.__config_setup1_1.set_flag_L(self.__config.get('t3.2.2b','flag_l'))
        self.__config_setup1_1.set_flag_A(self.__config.get('t3.2.2b','flag_a'))
        self.__config_setup1_1.set_flag_R(self.__config.get('t3.2.2b','flag_r'))
        self.__config_setup1_1.set_flag_prf(self.__config.get('t3.2.2b','flag_prf'))
        self.__config_setup1_1.set_validlifetime(self.__config.get('t3.2.2b','validlifetime'))
        self.__config_setup1_1.set_preferredlifetime(self.__config.get('t3.2.2b','preferredlifetime'))
        self.__config_setup1_1.set_routerlifetime(self.__config.get('t3.2.2b','routerlifetime'))
        self.__config_setup1_1.set_reachabletime(self.__config.get('t3.2.2b','reach_time'))
        self.__config_setup1_1.set_retranstimer(self.__config.get('t3.2.2b','retrans_time'))        
        self.__config_setup1_1.set_intervalo(self.__config.get('t1.6.6b','intervalo'))
        self.__config_setup1_1.set_prefix_addr(self.__config.get('setup1-1_advertise','ia_pd_address'))
        self.__config_setup1_1.set_dhcp_t1(self.__config.get('t3.2.2b','dhcp_t1'))
        self.__config_setup1_1.set_dhcp_t2(self.__config.get('t3.2.2b','dhcp_t2'))
        self.__config_setup1_1.set_dhcp_preflft(self.__config.get('t3.2.2b','dhcp_preflft'))
        self.__config_setup1_1.set_dhcp_validlft(self.__config.get('t3.2.2b','dhcp_validlft'))
        self.__config_setup1_1.set_dhcp_plen(self.__config.get('t3.2.2b','dhcp_plen'))
   
    def set_flags_lan(self):
        self.__config_setup_lan.set_elapsetime(self.__config.get('solicitlan','elapsetime'))
        self.__config_setup_lan.set_xid(self.__config.get('solicitlan','xid'))
        self.__config_setup_lan.set_fdqn(self.__config.get('solicitlan','clientfqdn'))
        self.__config_setup_lan.set_vendor_class(self.__config.get('solicitlan','vendorclass'))

        self.__config_setup_lan.set_enterprise(self.__config.get('solicitlan','enterpriseid'))
        self.__config_setup_lan.set_client_duid(self.__config.get('solicitlan','duid'))
        self.__config_setup_lan.set_iaid(self.__config.get('solicitlan','iaid'))

    def set_status_lan(self,v):
        self.msg_lan = v

    def get_status_lan(self):
        return self.msg_lan


    def set_status(self,v):
        self.msg = v

    def get_status(self):
        return self.msg

    def rourter_advertise(self):
        self.__config_setup1_1.set_ether_src(self.__config.get('wan','ra_mac'))
        self.__config_setup1_1.set_ether_dst(self.__config.get('multicast','all_mac_nodes'))
        self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','ra_address'))
        self.__config_setup1_1.set_ipv6_dst(self.__config.get('multicast','all_nodes_addr'))
        self.__sendmsgs.send_tr1_RA2(self.__config_setup1_1)
    
    def ping(self):
        if self.__config_setup1_1.get_mac_ceRouter() != None:
            self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','global_wan_addr'))
            self.__config_setup1_1.set_ether_src(self.__config.get('wan','wan_mac_tr1'))
            self.__config_setup1_1.set_ether_dst(self.__config_setup1_1.get_mac_ceRouter())
            self.__config_setup1_1.set_ipv6_dst(self.__config.get('lan','global_wan_addr'))
            self.__sendmsgs.send_echo_request(self.__config_setup1_1)

    def neighbor_advertise_local(self,pkt):
        self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','link_local_addr'))
        self.__config_setup1_1.set_ether_src(self.__config.get('wan','wan_mac_tr1'))
        self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
        self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup1_1.set_tgt(self.__config.get('wan','link_local_addr'))
        self.__config_setup1_1.set_lla(self.__config.get('wan','wan_mac_tr1'))
        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na(self.__config_setup1_1)

    def neighbor_advertise_global(self,pkt):
        self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','global_wan_addr'))
        self.__config_setup1_1.set_ether_src(self.__config.get('wan','wan_mac_tr1'))
        self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
        self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup1_1.set_tgt(self.__config.get('wan','global_wan_addr'))
        self.__config_setup1_1.set_lla(self.__config.get('wan','wan_mac_tr1'))
        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na(self.__config_setup1_1)
    def neighbor_advertise_global_tn3(self,pkt):
        self.__config_setup1_1.set_ipv6_src(self.__config.get('t3.2.2b','tn3_ip'))
        self.__config_setup1_1.set_ether_src(self.__config.get('t3.2.2b','tn3_mac'))
        self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
        self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup1_1.set_tgt(self.__config.get('t3.2.2b','tn3_ip'))
        self.__config_setup1_1.set_lla(self.__config.get('t3.2.2b','tn3_mac'))
        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na(self.__config_setup1_1)

    def ping_tn3(self):
        if self.__config_setup1_1.get_mac_ceRouter() != None:
            #print('6')
            self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))
            self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac'))
            self.__config_setup_lan.set_ether_dst(self.__config_setup_lan.get_mac_ceRouter())
            self.__config_setup_lan.set_ipv6_dst(self.__config.get('t3.2.2b','tn3_ip'))
            self.__sendmsgs.send_echo_request_lan(self.__config_setup_lan)

    def dhcp_information_lan(self):
        self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_ether_dst('33:33:00:01:00:02')
        self.__config_setup_lan.set_ipv6_dst(self.__config.get('multicast','all_routers_addr'))
        self.__config_setup_lan.set_xid(self.__config.get('informationlan','xid'))
        self.__config_setup_lan.set_elapsetime(self.__config.get('informationlan','elapsetime'))
        self.__config_setup_lan.set_vendor_class(self.__config.get('informationlan','vendorclass'))
        self.__sendmsgs.send_dhcp_information(self.__config_setup_lan)

    def icmp_rs_lan(self):
        self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_ether_dst(self.__config.get('multicast','all_mac_routers'))
        self.__config_setup_lan.set_ipv6_dst(self.__config.get('general','all_routers_address'))
        self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
        self.__sendmsgs.send_icmp_rs(self.__config_setup_lan)

    def icmp_na_global_lan(self,pkt):
        self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))
        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
        self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup_lan.set_tgt(self.__config.get('lan','global_wan_addr'))
        self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)

    def icmp_na_local_lan(self,pkt):
        self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
        self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup_lan.set_tgt(self.__config.get('lan','lan_local_addr'))
        self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)

    def run_Lan(self):
        #self.__config_setup_lan_.flags_partA()

        t_test = 0
        t_test1= 0
        time_p = 0
        sent_reconfigure = False
        time_over = False
        send_ra = False
        send_na_lan = False
        reset_test1 = False
        self.set_flags_lan()
        self.__config_setup_lan.set_setup_lan_start()
        cache_lan = []
        @self.__app.route("/LAN",methods=['GET'])
        def envia_lan():
            return self.get_status_lan()
        while not self.__queue_lan.full():
            if self.__queue_lan.empty():
                if t_test < 30:
 
                    time.sleep(1)
                    t_test = t_test + 1
                    if t_test % 5 ==0:
                        self.set_status_lan('LAN: Transmissões de RS e DHCP information por 30 s a cada 5 seg.')
                        logging.info('LAN: Inicio das transmissões de RS e DHCP information por 30 s.')
                        self.dhcp_information_lan() 
                        self.icmp_rs_lan()
                    time.sleep(1)
                else:
                    time_over = True

            else:

                pkt = self.__queue_lan.get()
                cache_lan.append(pkt)
                wrpcap("lan-3.2.2b.cap",cache_lan)
                if pkt.haslayer(ICMPv6ND_RA):
                    self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)

                if pkt.haslayer(ICMPv6MLReport2):
                    self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)

                if pkt.haslayer(DHCP6_Reply):
                    self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)

                if pkt[Ether].src == self.__config.get('lan','mac_address'):
                    continue

                if pkt.haslayer(ICMPv6ND_NS):
                    if pkt[ICMPv6ND_NS].tgt == self.__config.get('lan','global_wan_addr'):
                        self.set_status_lan('LAN: Respondendo ao NS com NA global')
                        logging.info('LAN: Respondendo ao NS com NA global')
                        self.icmp_na_global_lan(pkt)

                    if pkt[ICMPv6ND_NS].tgt == self.__config.get('lan','lan_local_addr'):
                        self.set_status_lan('LAN: Respondendo ao NS com NA local')
                        logging.info('LAN: Respondendo ao NS com NA local')                        
                        self.icmp_na_local_lan(pkt)

            if self.__config_setup1_1.get_setup1_1_OK():
                if pkt[Ether].src == self.__config.get('lan','mac_address'):
                    continue
                if t_test1 < 30:
                    t_test1 = t_test1 + 1
                    if t_test1 % 5 == 0: 
                        self.ping_tn3()
                        self.set_status_lan('LAN: Enviando ping TN3')
                        logging.info('LAN: Enviando ping TN3')
                    if pkt.haslayer(ICMPv6ND_NS):

                        if pkt[ICMPv6ND_NS].tgt == self.__config.get('lan','global_wan_addr'):
                            self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))
                            self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                            self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
                            self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                            self.__config_setup_lan.set_tgt(self.__config.get('lan','global_wan_addr'))
                            self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
                            self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
                            self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)
                            
                        if pkt[ICMPv6ND_NS].tgt == self.__config.get('lan','lan_local_addr'):

                            self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
                            self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                            self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
                            self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                            self.__config_setup_lan.set_tgt(self.__config.get('lan','lan_local_addr'))
                            self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
                            self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
                            self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)
                else: 
                    self.stop_ping_OK = True    
            if  self.part2_lan_start and not reset_test1:
                t_test1 = 0
                reset_test1 = True
                





    def run(self):
        @self.__app.route("/WAN",methods=['GET'])
        def enviawan():
            return self.get_status()
        self.__t_lan =  Thread(target=self.run_Lan,name='LAN_Thread')
        self.__t_lan.start()
        
        self.__packet_sniffer_wan = PacketSniffer('Test322b-WAN',self.__queue_wan,self,self.__config,self.__wan_device_tr1)
        self.__packet_sniffer_wan.start()
        
        self.__packet_sniffer_lan = PacketSniffer('Test322b-LAN',self.__queue_lan,self,self.__config,self.__lan_device)
        test_lan = self.__packet_sniffer_lan.start()
        self.__config_setup1_1.set_ra2()
        self.set_flags()
        logging.info(self.__test_desc)
        t_test = 0
        time1 = 0
        sent_reconfigure = False
        time_over = False
        start_time_count = False
        finish_wan = False
        part1_OK = False
        cache_wan = []
        self.__config_setup1_1.set_pd_prefixlen(self.__config.get('t3.2.2b','pd_prefixlen')) 
        self.__config_setup1_1.set_routerlifetime(self.__config.get('t3.2.2b','routerlifetime')) 
        while not self.__queue_wan.full():
            if self.__queue_wan.empty():
                if t_test <= 300:
                    time.sleep(1)
                    t_test = t_test + 1
                    if t_test % 10 == 0:
                        self.set_status('WAN: Enviando ICMP RA periódico')
                        logging.info('WAN: Enviando ICMP RA periódico')
                        self.rourter_advertise()
                    
                    if start_time_count:
                        if time1 < 600:
                            time1 = time1 + 1

                else:
                    time_over = True      
            else:
                pkt = self.__queue_wan.get()
                cache_wan.append(pkt)
                wrpcap("WAN-3.2.2b.cap",cache_wan)
                if not self.__config_setup1_1.get_ND_local_OK():
                    if pkt[Ether].src == self.__config.get('wan','link_local_mac'):
                        continue

                    if pkt[Ether].src == self.__config.get('wan','ra_mac'):
                        continue

                    if pkt.haslayer(ICMPv6ND_RS):            
                        if pkt[Ether].src == self.__config.get('wan','link_local_mac'):       
                            continue

                        if pkt[Ether].src == self.__config.get('wan','ra_mac'):                                    
                            continue

                        self.__config_setup1_1.set_local_addr_ceRouter(pkt[IPv6].src)
                        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)    

                    if pkt.haslayer(DHCP6_Solicit):
                        if pkt[Ether].src == self.__config.get('wan','link_local_mac'):
                            continue

                        if pkt[Ether].src == self.__config.get('wan','ra_mac'):
                            continue
                        self.__config_setup1_1.set_local_addr_ceRouter(pkt[IPv6].src)
                        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
 

                if pkt.haslayer(ICMPv6ND_NS):
                    if pkt[ICMPv6ND_NS].tgt == self.__config.get('wan','global_wan_addr'):
                        self.set_status('WAN: Enviando resposta ao NS com ICMP NA global')
                        logging.info('WAN: Enviando resposta ao NS com ICMP NA global')
                        self.neighbor_advertise_global(pkt)
                        
                    if pkt[ICMPv6ND_NS].tgt == self.__config.get('wan','link_local_addr'):
                        self.set_status('WAN: Enviando resposta ao NS com ICMP NA local')
                        logging.info('WAN: Enviando resposta ao NS com ICMP NA local')
                        self.neighbor_advertise_local(pkt)

                if not self.__config_setup1_1.get_setup1_1_OK():
                    self.set_status('WAN: Setup 1.1 em execução')
                    logging.info('WAN: Setup 1.1 em execução')
                    if not self.__config_setup1_1.get_disapproved():

                        self.__config_setup1_1.run_setup1_1(pkt)

                        if pkt.haslayer(ICMPv6ND_RS):

                            if pkt[Ether].src == self.__config.get('wan','link_local_mac'):
        
                                continue
                            if pkt[Ether].src == self.__config.get('wan','ra_mac'):

                                continue
                            self.set_status('WAN: Enviando ICMP RA com Routerlifetime maior que zero')
                            logging.info('WAN: Enviando ICMP RA com Routerlifetime maior que zero')
                            self.__config_setup1_1.set_local_addr_ceRouter(pkt[IPv6].src)
                            self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)                                 
                            self.__config_setup1_1.set_ether_src(self.__config.get('wan','ra_mac'))
                            self.__config_setup1_1.set_ether_dst(self.__config.get('multicast','all_mac_nodes'))
                            self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','ra_address'))
                            self.__config_setup1_1.set_ipv6_dst(self.__config.get('multicast','all_nodes_addr'))
                            self.__sendmsgs.send_tr1_RA2(self.__config_setup1_1)

                    else:
                        logging.info('Reprovado Teste 3.2.2b - Falha em completar o Common Setup 1.1 da RFC')
                        self.__packet_sniffer_wan.stop() 
                        return False

                else:

                    if not self.__finish_wan:
                        start_time_count = True
                        if time1 < 50:

                            if part1_OK == False:
                                if pkt.haslayer(ICMPv6EchoRequest):
                                    self.set_status('WAN: Parte 1 concluida com quando Router Lifetime Maior que zero')
                                    logging.info('WAN: Parte 1 concluida com quando Router Lifetime Maior que zero')
                                
                                    part1_OK = True

                            if self.part2_lan_start:
                                if pkt.haslayer(ICMPv6EchoRequest):
                                    self.set_status('Reprovado Teste 3.2.2b - Recebido ICMPv6EchoRequest na WAN sendo que Routerlifime anunciado é zero')
                                    time.sleep(2)
                                    self.set_status('REPROVADO') # Mensagem padrão para o frontEnd atualizar Status
                                    logging.info('Reprovado Teste 3.2.2b - Recebido ICMPv6EchoRequest na WAN sendo que Routerlifime anunciado é zero')
                                    self.__packet_sniffer_wan.stop() 
                                    self.__packet_sniffer_lan.stop()
                                    self.__finish_wan = True 
                                    self.__fail_test = False
                                    return False

                            if part1_OK and not self.part2_lan_start:
                                #print('enviado1')
                                
                                self.__config_setup1_1.set_routerlifetime('0')
                                self.__config_setup1_1.set_reachabletime('0')
                                self.__config_setup1_1.set_retranstimer('0') 

                                self.__sendmsgs.send_tr1_RA2(self.__config_setup1_1)
                                #print('limpando')
                                while not self.stop_ping_OK:
                                    time.sleep(1)
                                    #print('aguardando terminar')
                                logging.info('WAN: Aguardando cessar mensagens Echo Request na LAN para iniciar Captura da parte 2 de ICMP RA com Router Lifetime igual zero')
                                
                                self.set_status('WAN: Aguardando cessar mensagens Echo Request na LAN para iniciar Captura da parte 2 de ICMP RA com Router Lifetime igual zero')
                                time.sleep(10)
                                while not self.__queue_wan.empty():
                                    self.__queue_wan.get()
                                
                                #print('enviando 3')
                                logging.info('WAN: Enviando ICMP RA com Router Lifetime igual a zero')
                                self.set_status('WAN: Enviando ICMP RA com Router Lifetime igual a zero')
                                for x in range(3):
                                    time.sleep(1)
                                    x = x+1
                                    self.__sendmsgs.send_tr1_RA2(self.__config_setup1_1)
                                self.part2_lan_start = True

                            if pkt.haslayer(ICMPv6ND_NS):
                                if pkt[ICMPv6ND_NS].tgt == self.__config.get('t3.2.2b','tn3_ip'):
                                    #print('glboal')
                                    logging.info('WAN: Solicitado NS com target TN3. Enviado NA do TN3')
                                    self.set_status('WAN: Solicitado NS com target TN3. Enviado NA do TN3')
                                    self.neighbor_advertise_global_tn3(pkt)

                                if pkt[ICMPv6ND_NS].tgt == self.__config.get('wan','ra_address'):
                                    #print('local')
                                    logging.info('WAN: Recebido ICMP NS do TN1. Enviando Resposta ICMP NA do TN1')
                                    self.set_status('WAN: Recebido ICMP NS do TN1. Enviando Resposta ICMP NA do TN1')
                                    self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','ra_address'))
                                    self.__config_setup1_1.set_ether_src(self.__config.get('wan','ra_mac'))
                                    self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
                                    self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
                                    self.__config_setup1_1.set_tgt(self.__config.get('wan','ra_address'))
                                    self.__config_setup1_1.set_lla(self.__config.get('wan','ra_mac'))
                                    self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
                                    self.__sendmsgs.send_icmp_na(self.__config_setup1_1)
                                    
                        else:            
                            self.__packet_sniffer_wan.stop() 
                            self.__packet_sniffer_lan.stop()
                            self.set_status('Teste 3.2.2b - APROVADO. Não passou pacotes da LAN para WAN após envio do RouterLifetime igual a zero')
                            time.sleep(2)
                            self.set_status('APROVADO')
                            logging.info('Teste 3.2.2b - APROVADO. Não passou pacotes da LAN para WAN após reconfiguração do RouterLifetime zero')
                            return True        
                    else:
                        self.__packet_sniffer_wan.stop()
                        if self.__fail_test:
                            return False
                        else:
                                return True
        self.__packet_sniffer_wan.stop()
        return False
     
        
コード例 #6
0
ファイル: test323a.py プロジェクト: ronyjah/tcc_ronaldo
class Test323a:
    def __init__(self, config, app):
        self.__app = app
        self.__queue_wan = Queue()
        self.__queue_lan = Queue()
        self.__config = config
        self.__interface = None
        self.__pkt = None
        self.__local_addr_ceRouter = None
        self.__sendmsgs = SendMsgs(self.__config)
        self.__config_setup1_1 = ConfigSetup1_1(self.__config)
        self.__wan_device_tr1 = self.__config.get('wan', 'device_wan_tr1')
        self.__lan_device = self.__config.get('lan', 'lan_device')
        self.__wan_mac_tr1 = self.__config.get('wan', 'wan_mac_tr1')
        self.__link_local_addr = self.__config.get('wan', 'link_local_addr')
        self.__all_nodes_addr = self.__config.get('multicast',
                                                  'all_nodes_addr')
        self.__test_desc = self.__config.get('tests', '3.2.3a')
        self.__t_lan = None
        self.__finish_wan = False
        self.part2_lan_start = False
        self.__dhcp_renew_done = False
        self.stop_ping_OK = False
        self.msg_lan = self.__config.get('tests', '3.2.3a')
        self.msg = self.__config.get('tests', '3.2.3a')
        self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config,
                                                     self.__lan_device)

    def set_flags(self):
        self.__config_setup1_1.set_flag_M(
            self.__config.get('t3.2.3a', 'flag_m'))
        self.__config_setup1_1.set_flag_0(
            self.__config.get('t3.2.3a', 'flag_o'))
        self.__config_setup1_1.set_flag_chlim(
            self.__config.get('t3.2.3a', 'flag_chlim'))
        self.__config_setup1_1.set_flag_L(
            self.__config.get('t3.2.3a', 'flag_l'))
        self.__config_setup1_1.set_flag_A(
            self.__config.get('t3.2.3a', 'flag_a'))
        self.__config_setup1_1.set_flag_R(
            self.__config.get('t3.2.3a', 'flag_r'))
        self.__config_setup1_1.set_flag_prf(
            self.__config.get('t3.2.3a', 'flag_prf'))
        self.__config_setup1_1.set_validlifetime(
            self.__config.get('t3.2.3a', 'validlifetime'))
        self.__config_setup1_1.set_preferredlifetime(
            self.__config.get('t3.2.3a', 'preferredlifetime'))
        self.__config_setup1_1.set_routerlifetime(
            self.__config.get('t3.2.3a', 'routerlifetime'))
        self.__config_setup1_1.set_reachabletime(
            self.__config.get('t3.2.3a', 'reach_time'))
        self.__config_setup1_1.set_retranstimer(
            self.__config.get('t3.2.3a', 'retrans_time'))
        self.__config_setup1_1.set_intervalo(
            self.__config.get('t1.6.6b', 'intervalo'))
        self.__config_setup1_1.set_prefix_addr(
            self.__config.get('setup1-1_advertise', 'ia_pd_address'))
        self.__config_setup1_1.set_dhcp_t1(
            self.__config.get('t3.2.3a', 'dhcp_t1'))
        self.__config_setup1_1.set_dhcp_t2(
            self.__config.get('t3.2.3a', 'dhcp_t2'))
        self.__config_setup1_1.set_dhcp_preflft(
            self.__config.get('t3.2.3a', 'dhcp_preflft'))
        self.__config_setup1_1.set_dhcp_validlft(
            self.__config.get('t3.2.3a', 'dhcp_validlft'))
        self.__config_setup1_1.set_dhcp_plen(
            self.__config.get('t3.2.3a', 'dhcp_plen'))

    def set_flags_lan(self):
        self.__config_setup_lan.set_elapsetime(
            self.__config.get('solicitlan', 'elapsetime'))
        self.__config_setup_lan.set_xid(self.__config.get('solicitlan', 'xid'))
        self.__config_setup_lan.set_fdqn(
            self.__config.get('solicitlan', 'clientfqdn'))
        self.__config_setup_lan.set_vendor_class(
            self.__config.get('solicitlan', 'vendorclass'))

        self.__config_setup_lan.set_enterprise(
            self.__config.get('solicitlan', 'enterpriseid'))
        self.__config_setup_lan.set_client_duid(
            self.__config.get('solicitlan', 'duid'))
        self.__config_setup_lan.set_iaid(
            self.__config.get('solicitlan', 'iaid'))

    def ping_unreac_ip(self):
        if self.__config_setup1_1.get_mac_ceRouter() != None:
            #print('6')
            self.__config_setup_lan.set_ipv6_src(
                self.__config.get('lan', 'global_wan_addr'))
            self.__config_setup_lan.set_ether_src(
                self.__config.get('lan', 'mac'))
            self.__config_setup_lan.set_ether_dst(
                self.__config_setup_lan.get_mac_ceRouter())
            self.__config_setup_lan.set_ipv6_dst(
                self.__config.get('t3.2.3a', 'unreachable_ip'))
            self.__sendmsgs.send_echo_request_lan(self.__config_setup_lan)

    def set_status_lan(self, v):
        self.msg_lan = v

    def get_status_lan(self):
        return self.msg_lan

    def set_status(self, v):
        self.msg = v

    def get_status(self):
        return self.msg

    def dhcp_information_lan(self):
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'lan_local_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst('33:33:00:01:00:02')
        self.__config_setup_lan.set_ipv6_dst(
            self.__config.get('multicast', 'all_routers_addr'))
        self.__config_setup_lan.set_xid(
            self.__config.get('informationlan', 'xid'))
        self.__config_setup_lan.set_elapsetime(
            self.__config.get('informationlan', 'elapsetime'))
        self.__config_setup_lan.set_vendor_class(
            self.__config.get('informationlan', 'vendorclass'))
        self.__sendmsgs.send_dhcp_information(self.__config_setup_lan)

    def icmp_rs_lan(self):
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'lan_local_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(
            self.__config.get('multicast', 'all_mac_routers'))
        self.__config_setup_lan.set_ipv6_dst(
            self.__config.get('general', 'all_routers_address'))
        self.__config_setup_lan.set_lla(self.__config.get(
            'lan', 'mac_address'))
        self.__sendmsgs.send_icmp_rs(self.__config_setup_lan)

    def icmp_na_global_lan(self, pkt):
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'global_wan_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
        self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup_lan.set_tgt(
            self.__config.get('lan', 'global_wan_addr'))
        self.__config_setup_lan.set_lla(self.__config.get(
            'lan', 'mac_address'))
        self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)

    def icmp_na_local_lan(self, pkt):
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'lan_local_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
        self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup_lan.set_tgt(
            self.__config.get('lan', 'lan_local_addr'))
        self.__config_setup_lan.set_lla(self.__config.get(
            'lan', 'mac_address'))
        self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)

    def rourter_advertise(self):
        self.__config_setup1_1.set_ether_src(self.__config.get(
            'wan', 'ra_mac'))
        self.__config_setup1_1.set_ether_dst(
            self.__config.get('multicast', 'all_mac_nodes'))
        self.__config_setup1_1.set_ipv6_src(
            self.__config.get('wan', 'ra_address'))
        self.__config_setup1_1.set_ipv6_dst(
            self.__config.get('multicast', 'all_nodes_addr'))
        self.__sendmsgs.send_tr1_RA2(self.__config_setup1_1)

    def ping(self):
        if self.__config_setup1_1.get_mac_ceRouter() != None:
            self.__config_setup1_1.set_ipv6_src(
                self.__config.get('wan', 'global_wan_addr'))
            self.__config_setup1_1.set_ether_src(
                self.__config.get('wan', 'wan_mac_tr1'))
            self.__config_setup1_1.set_ether_dst(
                self.__config_setup1_1.get_mac_ceRouter())
            self.__config_setup1_1.set_ipv6_dst(
                self.__config.get('t3.2.3a', 'unreachable_ip'))
            self.__sendmsgs.send_echo_request(self.__config_setup1_1)

    def neighbor_advertise_local(self, pkt):
        self.__config_setup1_1.set_ipv6_src(
            self.__config.get('wan', 'link_local_addr'))
        self.__config_setup1_1.set_ether_src(
            self.__config.get('wan', 'wan_mac_tr1'))
        self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
        self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup1_1.set_tgt(
            self.__config.get('wan', 'link_local_addr'))
        self.__config_setup1_1.set_lla(self.__config.get('wan', 'wan_mac_tr1'))
        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na(self.__config_setup1_1)

    def neighbor_advertise_global(self, pkt):
        self.__config_setup1_1.set_ipv6_src(
            self.__config.get('wan', 'global_wan_addr'))
        self.__config_setup1_1.set_ether_src(
            self.__config.get('wan', 'wan_mac_tr1'))
        self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
        self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup1_1.set_tgt(
            self.__config.get('wan', 'global_wan_addr'))
        self.__config_setup1_1.set_lla(self.__config.get('wan', 'wan_mac_tr1'))
        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na(self.__config_setup1_1)

    def neighbor_advertise_global_tn3(self, pkt):
        self.__config_setup1_1.set_ipv6_src(
            self.__config.get('t3.2.3a', 'tn3_ip'))
        self.__config_setup1_1.set_ether_src(
            self.__config.get('t3.2.3a', 'tn3_mac'))
        self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
        self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup1_1.set_tgt(self.__config.get('t3.2.3a', 'tn3_ip'))
        self.__config_setup1_1.set_lla(self.__config.get('t3.2.3a', 'tn3_mac'))
        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na(self.__config_setup1_1)

    def run_Lan(self):
        #self.__config_setup_lan_.flags_partA()
        t_test = 0
        t_test1 = 0
        time_p = 0
        sent_reconfigure = False
        time_over = False
        send_ra = False
        send_na_lan = False
        reset_test1 = False
        cache_lan = []
        self.set_flags_lan()
        self.__config_setup_lan.set_setup_lan_start()

        @self.__app.route("/LAN", methods=['GET'])
        def envia_lan():
            return self.get_status_lan()

        while not self.__queue_lan.full():
            if self.__queue_lan.empty():
                if t_test < 30:

                    time.sleep(1)
                    t_test = t_test + 1
                    if t_test % 5 == 0:
                        self.set_status_lan(
                            'LAN: Transmissões de RS e DHCP information por 30 s a cada 5 seg.'
                        )
                        logging.info(
                            'LAN: Inicio das transmissões de RS e DHCP information por 30 s.'
                        )
                        self.dhcp_information_lan()
                        self.icmp_rs_lan()
                    time.sleep(1)
                else:
                    time_over = True
            else:

                pkt = self.__queue_lan.get()
                cache_lan.append(pkt)
                wrpcap("lan-3.2.3a.cap", cache_lan)

                if pkt.haslayer(ICMPv6ND_RA):
                    self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)

                if pkt.haslayer(ICMPv6MLReport2):
                    self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)

                if pkt.haslayer(DHCP6_Reply):
                    self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)

                if pkt[Ether].src == self.__config.get('lan', 'mac_address'):
                    continue

                if pkt.haslayer(ICMPv6ND_NS):
                    if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                            'lan', 'global_wan_addr'):
                        self.icmp_na_global_lan(pkt)

                    if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                            'lan', 'lan_local_addr'):
                        self.icmp_na_local_lan(pkt)

            if self.__config_setup1_1.get_setup1_1_OK():
                self.set_status_lan(
                    'LAN: Setup1.1 concluido. Contador de 30 para transmissão de ICMPv6 Echo Request de acordo com o Teste 3.2.2 part A'
                )
                logging.info(
                    'LAN: Setup1.1 concluido. Contador de 30 s para transmissão de ICMPv6 Echo Request de acordo com o Teste 3.2.2 part A'
                )

                if pkt[Ether].src == self.__config.get('lan', 'mac_address'):
                    continue
                if t_test1 < 30:
                    t_test1 = t_test1 + 1
                    if t_test1 % 5 == 0:
                        self.set_status_lan(
                            'WAN: Transmissão por TN2(LAN) de ICMP Echo request a um endereço na LAN com prefixo menor do que foi delegado pelo Roteador'
                        )
                        logging.info(
                            'WAN: Transmissão por TN2(LAN) de ICMP Echo request a um endereço com prefixo menor do que foi delegado pelo Roteador'
                        )

                        self.ping_unreac_ip()

                    if pkt.haslayer(ICMPv6DestUnreach):
                        self.__packet_sniffer_wan.stop()
                        self.__packet_sniffer_lan.stop()
                        self.set_status_lan(
                            'Teste 3.2.3a - APROVADO. Não passou pacotes da LAN para WAN ou TR1 e enviou Destino Inalcançavel ao TN2(LAN)'
                        )
                        time.sleep(2)
                        self.set_status_lan('APROVADO')

                        logging.info(
                            'Teste 3.2.3a - APROVADO. Não passou pacotes da LAN para WAN ou TR1 e enviou Destino Inalcançavel ao TN2(LAN)'
                        )
                        return True

                    if pkt.haslayer(ICMPv6ND_NS):

                        if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                                'lan', 'global_wan_addr'):
                            logging.info(
                                'LAN: Recebido ICMP NS Global. Enviado ICMP NA Global'
                            )
                            self.set_status_lan(
                                'LAN: Recebido ICMP NS Global. Enviado ICMP NA Global'
                            )
                            self.icmp_na_global_lan(pkt)

                        if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                                'lan', 'lan_local_addr'):
                            logging.info(
                                'LAN: Recebido ICMP NS local. Enviando ICMP NA Local'
                            )
                            self.set_status_lan(
                                'LAN: Recebido ICMP NS local. Enviado ICMP NA local'
                            )
                            self.icmp_na_local_lan(pkt)

                else:

                    self.set_status_lan(
                        'Reprovado Teste 3.2.3a - Timeout e não recebeu ICMPv6 Destino Unreachable'
                    )
                    time.sleep(2)
                    self.set_status_lan('REPROVADO')
                    logging.info(
                        'Reprovado Teste 3.2.3a - Timeout e não recebeu ICMPv6 Destino Unreachable'
                    )
                    self.__packet_sniffer_wan.stop()
                    self.__packet_sniffer_lan.stop()
                    self.__finish_wan = True
                    self.__fail_test = False
                    return False

    def run(self):
        @self.__app.route("/WAN", methods=['GET'])
        def enviawan():
            return self.get_status()

        self.__t_lan = Thread(target=self.run_Lan, name='LAN_Thread')
        self.__t_lan.start()

        self.__packet_sniffer_wan = PacketSniffer('Test323b-WAN',
                                                  self.__queue_wan, self,
                                                  self.__config,
                                                  self.__wan_device_tr1)
        self.__packet_sniffer_wan.start()

        self.__packet_sniffer_lan = PacketSniffer('Test323b-LAN',
                                                  self.__queue_lan, self,
                                                  self.__config,
                                                  self.__lan_device)
        test_lan = self.__packet_sniffer_lan.start()
        self.__config_setup1_1.set_ra2()
        self.set_flags()
        logging.info(self.__test_desc)
        t_test = 0
        time1 = 0
        sent_reconfigure = False
        time_over = False
        start_time_count = False
        finish_wan = False
        part1_OK = False
        cache_wan = []
        self.__config_setup1_1.set_pd_prefixlen(
            self.__config.get('t3.2.3a', 'pd_prefixlen'))
        self.__config_setup1_1.set_routerlifetime(
            self.__config.get('t3.2.3a', 'routerlifetime'))
        self.set_status('WAN: Tráfego Iniciado')
        while not self.__queue_wan.full():
            if self.__queue_wan.empty():
                if t_test <= 300:
                    time.sleep(1)
                    t_test = t_test + 1
                    if t_test % 10 == 0:
                        self.set_status(
                            'WAN: Transmissão de ICMP RA periódico')
                        logging.info('WAN: Transmissão de ICMP RA periódico')
                        self.rourter_advertise()

                    if start_time_count:
                        time1 = time1 + 1

                else:
                    time_over = True
            else:
                pkt = self.__queue_wan.get()
                cache_wan.append(pkt)
                wrpcap("WAN-3.2.3a.cap", cache_wan)
                if not self.__config_setup1_1.get_ND_local_OK():

                    if pkt[Ether].src == self.__config.get(
                            'wan', 'link_local_mac'):
                        continue

                    if pkt[Ether].src == self.__config.get('wan', 'ra_mac'):
                        continue

                    if pkt.haslayer(ICMPv6ND_RS):

                        if pkt[Ether].src == self.__config.get(
                                'wan', 'link_local_mac'):
                            continue

                        if pkt[Ether].src == self.__config.get(
                                'wan', 'ra_mac'):
                            continue

                        self.__config_setup1_1.set_local_addr_ceRouter(
                            pkt[IPv6].src)
                        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)

                    if pkt.haslayer(DHCP6_Solicit):
                        if pkt[Ether].src == self.__config.get(
                                'wan', 'link_local_mac'):
                            continue

                        if pkt[Ether].src == self.__config.get(
                                'wan', 'ra_mac'):
                            continue

                        self.__config_setup1_1.set_local_addr_ceRouter(
                            pkt[IPv6].src)
                        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)

                if pkt.haslayer(ICMPv6ND_NS):
                    self.set_status(
                        'WAN: Respondendo ao ICMP NS local. Enviado ICMP NA Global'
                    )
                    if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                            'wan', 'global_wan_addr'):
                        self.neighbor_advertise_global(pkt)

                    if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                            'wan', 'link_local_addr'):
                        self.set_status(
                            'WAN: Respondendo ao ICMP NS local. Enviado ICMP NA local'
                        )
                        self.neighbor_advertise_local(pkt)

                if not self.__config_setup1_1.get_setup1_1_OK():
                    self.set_status('WAN: Setup 1.1 em execução')
                    if not self.__config_setup1_1.get_disapproved():
                        self.__config_setup1_1.run_setup1_1(pkt)
                        if pkt.haslayer(ICMPv6ND_RS):

                            if pkt[Ether].src == self.__config.get(
                                    'wan', 'link_local_mac'):
                                continued

                            if pkt[Ether].src == self.__config.get(
                                    'wan', 'ra_mac'):
                                continue

                            self.__config_setup1_1.set_local_addr_ceRouter(
                                pkt[IPv6].src)
                            self.__config_setup1_1.set_mac_ceRouter(
                                pkt[Ether].src)
                            self.__config_setup1_1.set_ether_src(
                                self.__config.get('wan', 'ra_mac'))
                            self.__config_setup1_1.set_ether_dst(
                                self.__config.get('multicast',
                                                  'all_mac_nodes'))
                            self.__config_setup1_1.set_ipv6_src(
                                self.__config.get('wan', 'ra_address'))
                            self.__config_setup1_1.set_ipv6_dst(
                                self.__config.get('multicast',
                                                  'all_nodes_addr'))
                            self.__sendmsgs.send_tr1_RA2(
                                self.__config_setup1_1)

                    else:
                        self.set_status(
                            'Reprovado Teste 3.2.3a - Falha em completar o Common Setup 1.1 da RFC'
                        )
                        time.sleep(2)
                        self.set_status('REPROVADO')

                        logging.info(
                            'Reprovado Teste 3.2.3a - Falha em completar o Common Setup 1.1 da RFC'
                        )
                        self.__packet_sniffer_wan.stop()
                        return False

                else:

                    if not self.__finish_wan:
                        start_time_count = True
                        if time1 < 50:

                            if pkt.haslayer(ICMPv6EchoRequest):
                                self.set_status(
                                    'Reprovado Teste 3.2.3a - Recebeu ICMPv6EchoRequest na LAN de um endereço não designado a LAN pelo roteador'
                                )
                                time.sleep(2)
                                self.set_status('REPROVADO')
                                logging.info(
                                    'Reprovado Teste 3.2.3a - Recebeu ICMPv6EchoRequest na LAN de um endereço não designado a LAN pelo roteador'
                                )
                                self.__packet_sniffer_wan.stop()
                                self.__packet_sniffer_lan.stop()
                                self.__finish_wan = True
                                self.__fail_test = False
                                return False

                            if pkt.haslayer(ICMPv6ND_NS):
                                if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                                        'wan', 'global_wan_addr'):
                                    self.neighbor_advertise_global(pkt)

                                if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                                        'wan', 'ra_address'):

                                    self.__config_setup1_1.set_ipv6_src(
                                        self.__config.get('wan', 'ra_address'))
                                    self.__config_setup1_1.set_ether_src(
                                        self.__config.get('wan', 'ra_mac'))
                                    self.__config_setup1_1.set_ether_dst(
                                        pkt[Ether].src)
                                    self.__config_setup1_1.set_ipv6_dst(
                                        pkt[IPv6].src)
                                    self.__config_setup1_1.set_tgt(
                                        self.__config.get('wan', 'ra_address'))
                                    self.__config_setup1_1.set_lla(
                                        self.__config.get('wan', 'ra_mac'))
                                    self.__config_setup1_1.set_mac_ceRouter(
                                        pkt[Ether].src)
                                    self.__sendmsgs.send_icmp_na(
                                        self.__config_setup1_1)
                        else:
                            self.__packet_sniffer_wan.stop()
                            self.__packet_sniffer_lan.stop()

                            self.set_status(
                                'Teste 3.2.3a - Reprovado. Time out sem mensagem Unreacheable'
                            )
                            time.sleep(2)
                            self.set_status('REPROVADO')
                            logging.info(
                                'Teste 3.2.3a - Reprovado. Time out sem mensagem Unreacheable'
                            )
                            return True
                    else:
                        self.__packet_sniffer_wan.stop()
                        if self.__fail_test:
                            return False
                        else:
                            return True
        self.__packet_sniffer_wan.stop()
        return False
コード例 #7
0
ファイル: test321b.py プロジェクト: ronyjah/tcc_ronaldo
class Test321b:
    def __init__(self, config, app):
        self.__app = app
        self.__queue_wan = Queue()
        self.__queue_lan = Queue()
        self.__config = config
        self.__interface = None
        self.__pkt = None
        self.__local_addr_ceRouter = None
        self.__sendmsgs = SendMsgs(self.__config)
        self.__config_setup1_1 = ConfigSetup1_1(self.__config)
        #self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config)
        self.__wan_device_tr1 = self.__config.get('wan', 'device_wan_tr1')
        self.__lan_device = self.__config.get('lan', 'lan_device')
        self.__wan_mac_tr1 = self.__config.get('wan', 'wan_mac_tr1')
        self.__link_local_addr = self.__config.get('wan', 'link_local_addr')
        self.__all_nodes_addr = self.__config.get('multicast',
                                                  'all_nodes_addr')
        self.__test_desc = self.__config.get('tests', '3.2.1b')
        self.__t_lan = None
        self.__finish_wan = False
        self.__dhcp_renew_done = False
        self.msg = self.__config.get('tests', '3.2.1b')
        self.msg_lan = self.__config.get('tests', '3.2.1b')
        self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config,
                                                     self.__lan_device)

    def set_flags(self):
        self.__config_setup1_1.set_flag_M(
            self.__config.get('t3.2.1b', 'flag_m'))
        self.__config_setup1_1.set_flag_0(
            self.__config.get('t3.2.1b', 'flag_o'))
        self.__config_setup1_1.set_flag_chlim(
            self.__config.get('t3.2.1b', 'flag_chlim'))
        self.__config_setup1_1.set_flag_L(
            self.__config.get('t3.2.1b', 'flag_l'))
        self.__config_setup1_1.set_flag_A(
            self.__config.get('t3.2.1b', 'flag_a'))
        self.__config_setup1_1.set_flag_R(
            self.__config.get('t3.2.1b', 'flag_r'))
        self.__config_setup1_1.set_flag_prf(
            self.__config.get('t3.2.1b', 'flag_prf'))
        self.__config_setup1_1.set_validlifetime(
            self.__config.get('t3.2.1b', 'validlifetime'))
        self.__config_setup1_1.set_preferredlifetime(
            self.__config.get('t3.2.1b', 'preferredlifetime'))
        self.__config_setup1_1.set_routerlifetime(
            self.__config.get('t3.2.1b', 'routerlifetime'))
        self.__config_setup1_1.set_reachabletime(
            self.__config.get('t3.2.1b', 'reach_time'))
        self.__config_setup1_1.set_retranstimer(
            self.__config.get('t3.2.1b', 'retrans_time'))
        self.__config_setup1_1.set_intervalo(
            self.__config.get('t1.6.6b', 'intervalo'))
        self.__config_setup1_1.set_prefix_addr(
            self.__config.get('setup1-1_advertise', 'ia_pd_address'))
        self.__config_setup1_1.set_dhcp_t1(
            self.__config.get('t3.2.1b', 'dhcp_t1'))
        self.__config_setup1_1.set_dhcp_t2(
            self.__config.get('t3.2.1b', 'dhcp_t2'))
        self.__config_setup1_1.set_dhcp_preflft(
            self.__config.get('t3.2.1b', 'dhcp_preflft'))
        self.__config_setup1_1.set_dhcp_validlft(
            self.__config.get('t3.2.1b', 'dhcp_validlft'))
        self.__config_setup1_1.set_dhcp_plen(
            self.__config.get('t3.2.1b', 'dhcp_plen'))

    def set_flags_lan(self):
        self.__config_setup_lan.set_elapsetime(
            self.__config.get('solicitlan', 'elapsetime'))
        self.__config_setup_lan.set_xid(self.__config.get('solicitlan', 'xid'))
        self.__config_setup_lan.set_fdqn(
            self.__config.get('solicitlan', 'clientfqdn'))
        self.__config_setup_lan.set_vendor_class(
            self.__config.get('solicitlan', 'vendorclass'))

        self.__config_setup_lan.set_enterprise(
            self.__config.get('solicitlan', 'enterpriseid'))
        self.__config_setup_lan.set_client_duid(
            self.__config.get('solicitlan', 'duid'))
        self.__config_setup_lan.set_iaid(
            self.__config.get('solicitlan', 'iaid'))

    def set_status_lan(self, v):
        self.msg_lan = v

    def get_status_lan(self):
        return self.msg_lan

    def set_status(self, v):
        self.msg = v

    def get_status(self):
        return self.msg

    def rourter_advertise(self):
        self.__config_setup1_1.set_ether_src(self.__config.get(
            'wan', 'ra_mac'))
        self.__config_setup1_1.set_ether_dst(
            self.__config.get('multicast', 'all_mac_nodes'))
        self.__config_setup1_1.set_ipv6_src(
            self.__config.get('wan', 'ra_address'))
        self.__config_setup1_1.set_ipv6_dst(
            self.__config.get('multicast', 'all_nodes_addr'))
        self.__sendmsgs.send_tr1_RA(self.__config_setup1_1)

    def ping(self):
        if self.__config_setup1_1.get_mac_ceRouter() != None:
            #print('6')
            self.__config_setup1_1.set_ipv6_src(
                self.__config.get('wan', 'global_wan_addr'))
            self.__config_setup1_1.set_ether_src(
                self.__config.get('wan', 'wan_mac_tr1'))
            self.__config_setup1_1.set_ether_dst(
                self.__config_setup1_1.get_mac_ceRouter())
            self.__config_setup1_1.set_ipv6_dst(
                self.__config.get('lan', 'global_wan_addr'))
            self.__sendmsgs.send_echo_request(self.__config_setup1_1)

    def neighbor_advertise_local(self, pkt):
        self.__config_setup1_1.set_ipv6_src(
            self.__config.get('wan', 'link_local_addr'))
        self.__config_setup1_1.set_ether_src(
            self.__config.get('wan', 'wan_mac_tr1'))
        self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
        self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup1_1.set_tgt(
            self.__config.get('wan', 'link_local_addr'))
        self.__config_setup1_1.set_lla(self.__config.get('wan', 'wan_mac_tr1'))
        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na(self.__config_setup1_1)

    def neighbor_advertise_global(self, pkt):
        self.__config_setup1_1.set_ipv6_src(
            self.__config.get('wan', 'global_wan_addr'))
        self.__config_setup1_1.set_ether_src(
            self.__config.get('wan', 'wan_mac_tr1'))
        self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
        self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup1_1.set_tgt(
            self.__config.get('wan', 'global_wan_addr'))
        self.__config_setup1_1.set_lla(self.__config.get('wan', 'wan_mac_tr1'))
        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na(self.__config_setup1_1)

    def dhcp_information_lan(self):
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'lan_local_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst('33:33:00:01:00:02')
        self.__config_setup_lan.set_ipv6_dst(
            self.__config.get('multicast', 'all_routers_addr'))
        self.__config_setup_lan.set_xid(
            self.__config.get('informationlan', 'xid'))
        self.__config_setup_lan.set_elapsetime(
            self.__config.get('informationlan', 'elapsetime'))
        self.__config_setup_lan.set_vendor_class(
            self.__config.get('informationlan', 'vendorclass'))
        self.__sendmsgs.send_dhcp_information(self.__config_setup_lan)

    def icmp_rs_lan(self):
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'lan_local_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(
            self.__config.get('multicast', 'all_mac_routers'))
        self.__config_setup_lan.set_ipv6_dst(
            self.__config.get('general', 'all_routers_address'))
        self.__config_setup_lan.set_lla(self.__config.get(
            'lan', 'mac_address'))
        self.__sendmsgs.send_icmp_rs(self.__config_setup_lan)

    def icmp_na_global_lan(self, pkt):
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'global_wan_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
        self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup_lan.set_tgt(
            self.__config.get('lan', 'global_wan_addr'))
        self.__config_setup_lan.set_lla(self.__config.get(
            'lan', 'mac_address'))
        self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)

    def icmp_na_local_lan(self, pkt):
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'lan_local_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
        self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup_lan.set_tgt(
            self.__config.get('lan', 'lan_local_addr'))
        self.__config_setup_lan.set_lla(self.__config.get(
            'lan', 'mac_address'))
        self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)

    def run_Lan(self):

        t_test = 0
        t_test1 = 0
        time_p = 0
        sent_reconfigure = False
        time_over = False
        send_ra = False
        send_na_lan = False
        self.set_flags_lan()
        self.__config_setup_lan.set_setup_lan_start()
        cache_lan = []

        @self.__app.route("/LAN", methods=['GET'])
        def envia_lan():
            return self.get_status_lan()

        while not self.__queue_lan.full():
            if self.__queue_lan.empty():
                if t_test < 30:
                    time.sleep(1)
                    t_test = t_test + 1
                    if t_test % 5 == 0:
                        self.set_status_lan(
                            'LAN: Transmissões de RS e DHCP information por 30 s a cada 5 seg. EXECUTAR APOS ROTEADOR REINICIADO'
                        )
                        logging.info(
                            'LAN: Inicio das transmissões de RS e DHCP information por 30 s.'
                        )
                        self.dhcp_information_lan()
                        self.icmp_rs_lan()

                else:
                    time_over = True

            else:

                pkt = self.__queue_lan.get()
                cache_lan.append(pkt)
                wrpcap("lan-3.2.1b.cap", cache_lan)
                if not time_over:
                    if pkt.haslayer(ICMPv6EchoRequest):
                        self.set_status_lan(
                            'Reprovado Teste 3.2.1b - Recebeu ICMPv6EchoRequest na LAN antes do IP_PD ser fornecido à porta WAN do roteador'
                        )
                        time.sleep(2)
                        self.set_status_lan(
                            'REPROVADO'
                        )  # Mensagem padrão para o frontEnd atualizar Status
                        logging.info(
                            'Reprovado Teste 3.2.1b - Recebeu ICMPv6EchoRequest antes do IP_PD ser fornecido à porta WAN do roteador'
                        )

                        self.__packet_sniffer_lan.stop()
                        self.__finish_wan = True
                        self.__fail_test = True
                        return False

                    if pkt.haslayer(ICMPv6ND_RA):
                        self.__config_setup_lan.set_mac_ceRouter(
                            pkt[Ether].src)

                    if pkt.haslayer(ICMPv6MLReport2):
                        self.__config_setup_lan.set_mac_ceRouter(
                            pkt[Ether].src)

                    if pkt.haslayer(DHCP6_Reply):
                        self.__config_setup_lan.set_mac_ceRouter(
                            pkt[Ether].src)

                    if pkt[Ether].src == self.__config.get(
                            'lan', 'mac_address'):
                        continue

                    if pkt.haslayer(ICMPv6ND_NS):

                        if pkt.haslayer(ICMPv6EchoRequest):
                            self.set_status_lan(
                                'Reprovado Teste 3.2.1b - Recebeu ICMPv6EchoRequest na LAN antes do IP_PD ser fornecido à porta WAN do roteador'
                            )
                            time.sleep(2)
                            self.set_status_lan(
                                'REPROVADO'
                            )  # Mensagem padrão para o frontEnd atualizar Status
                            logging.info(
                                'Reprovado Teste 3.2.1b - Recebeu ICMPv6EchoRequest antes do IP_PD ser fornecido à porta WAN do roteador'
                            )
                            self.__packet_sniffer_lan.stop()
                            self.__finish_wan = True
                            self.__fail_test = True
                            return False

                        if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                                'lan', 'global_wan_addr'):
                            self.__config_setup_lan.set_ipv6_src(
                                self.__config.get('lan', 'global_wan_addr'))
                            self.__config_setup_lan.set_ether_src(
                                self.__config.get('lan', 'mac_address'))
                            self.__config_setup_lan.set_ether_dst(
                                pkt[Ether].src)
                            self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                            self.__config_setup_lan.set_tgt(
                                self.__config.get('lan', 'global_wan_addr'))
                            self.__config_setup_lan.set_lla(
                                self.__config.get('lan', 'mac_address'))
                            self.__config_setup_lan.set_mac_ceRouter(
                                pkt[Ether].src)
                            self.__sendmsgs.send_icmp_na_lan(
                                self.__config_setup_lan)

                        if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                                'lan', 'lan_local_addr'):

                            self.__config_setup_lan.set_ipv6_src(
                                self.__config.get('lan', 'lan_local_addr'))
                            self.__config_setup_lan.set_ether_src(
                                self.__config.get('lan', 'mac_address'))
                            self.__config_setup_lan.set_ether_dst(
                                pkt[Ether].src)
                            self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                            self.__config_setup_lan.set_tgt(
                                self.__config.get('lan', 'lan_local_addr'))
                            self.__config_setup_lan.set_lla(
                                self.__config.get('lan', 'mac_address'))
                            self.__config_setup_lan.set_mac_ceRouter(
                                pkt[Ether].src)
                            self.__sendmsgs.send_icmp_na_lan(
                                self.__config_setup_lan)

                if self.__config_setup1_1.get_setup1_1_OK():

                    if pkt[Ether].src == self.__config.get(
                            'lan', 'mac_address'):
                        continue

                    if pkt.haslayer(ICMPv6EchoRequest):

                        self.set_status_lan(
                            'Aprovado Teste 3.2.1b - Recebeu ICMPv6EchoRequest somente Apos do IP_PD ser fornecido à porta WAN do roteador'
                        )
                        time.sleep(2)
                        self.set_status_lan(
                            'APROVADO'
                        )  # Mensagem padrão para o frontEnd atualizar Status

                        logging.info(
                            'Aprovado Teste 3.2.1b - Recebeu ICMPv6EchoRequest somente Apos do IP_PD ser fornecido à porta WAN do roteador'
                        )
                        self.__packet_sniffer_wan.stop()
                        return False
                        #print('AQUI-2.0')
                        self.__packet_sniffer_lan.stop()
                        self.__finish_wan = True
                        self.__fail_test = False
                        return False

                    if pkt.haslayer(ICMPv6ND_NS):

                        if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                                'lan', 'global_wan_addr'):
                            self.set_status_lan(
                                'LAN: Setup 1.1 Concluido. Respondendo ao NS Global com NA global'
                            )
                            logging.info(
                                'LAN: Setup 1.1 Concluido. Respondendo ao NS Global com NA global'
                            )
                            self.__config_setup_lan.set_ipv6_src(
                                self.__config.get('lan', 'global_wan_addr'))
                            self.__config_setup_lan.set_ether_src(
                                self.__config.get('lan', 'mac_address'))
                            self.__config_setup_lan.set_ether_dst(
                                pkt[Ether].src)
                            self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                            self.__config_setup_lan.set_tgt(
                                self.__config.get('lan', 'global_wan_addr'))
                            self.__config_setup_lan.set_lla(
                                self.__config.get('lan', 'mac_address'))
                            self.__config_setup_lan.set_mac_ceRouter(
                                pkt[Ether].src)
                            self.__sendmsgs.send_icmp_na_lan(
                                self.__config_setup_lan)

                        if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                                'lan', 'lan_local_addr'):
                            self.set_status_lan(
                                'LAN: Setup 1.1 Concluido. Respondendo ao NS local com NA local'
                            )
                            logging.info(
                                'LAN: Setup 1.1 Concluido. Respondendo ao NS local com NA local'
                            )
                            self.__config_setup_lan.set_ipv6_src(
                                self.__config.get('lan', 'lan_local_addr'))
                            self.__config_setup_lan.set_ether_src(
                                self.__config.get('lan', 'mac_address'))
                            self.__config_setup_lan.set_ether_dst(
                                pkt[Ether].src)
                            self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                            self.__config_setup_lan.set_tgt(
                                self.__config.get('lan', 'lan_local_addr'))
                            self.__config_setup_lan.set_lla(
                                self.__config.get('lan', 'mac_address'))
                            self.__config_setup_lan.set_mac_ceRouter(
                                pkt[Ether].src)
                            self.__sendmsgs.send_icmp_na_lan(
                                self.__config_setup_lan)

    def run(self):
        @self.__app.route("/WAN", methods=['GET'])
        def enviawan():
            return self.get_status()

        self.__t_lan = Thread(target=self.run_Lan, name='LAN_Thread')
        self.__t_lan.start()

        self.__packet_sniffer_wan = PacketSniffer('Test273b-WAN',
                                                  self.__queue_wan, self,
                                                  self.__config,
                                                  self.__wan_device_tr1)
        self.__packet_sniffer_wan.start()

        self.__packet_sniffer_lan = PacketSniffer('Test273b-LAN',
                                                  self.__queue_lan, self,
                                                  self.__config,
                                                  self.__lan_device)
        test_lan = self.__packet_sniffer_lan.start()
        self.__config_setup1_1.set_ra2()
        self.set_flags()
        logging.info(self.__test_desc)
        t_test = 0
        time1 = 0
        sent_reconfigure = False
        time_over = False
        cache_wan = []

        finish_wan = True
        self.__config_setup1_1.set_pd_prefixlen(
            self.__config.get('t3.2.1b', 'pd_prefixlen'))
        self.__config_setup1_1.set_routerlifetime(
            self.__config.get('t3.2.1b', 'routerlifetime'))
        while not self.__queue_wan.full():
            if self.__queue_wan.empty():
                if t_test <= 50:
                    time.sleep(1)
                    t_test = t_test + 1
                    if t_test % 10 == 0:
                        #self.rourter_advertise()
                        self.ping()
                        self.set_status('LAN: Enviando ping Para TN2')
                        logging.info('LAN: Enviando ping TN2')
                else:
                    time_over = True
            else:
                pkt = self.__queue_wan.get()
                cache_wan.append(pkt)
                wrpcap("WAN-3.2.1b.cap", cache_wan)
                if not self.__config_setup1_1.get_ND_local_OK():

                    if pkt[Ether].src == self.__config.get(
                            'wan', 'link_local_mac'):
                        continue

                    if pkt[Ether].src == self.__config.get('wan', 'ra_mac'):
                        continue

                    if pkt.haslayer(ICMPv6ND_RS):
                        if pkt[Ether].src == self.__config.get(
                                'wan', 'link_local_mac'):
                            continue

                        if pkt[Ether].src == self.__config.get(
                                'wan', 'ra_mac'):
                            continue

                        self.__config_setup1_1.set_local_addr_ceRouter(
                            pkt[IPv6].src)
                        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)

                    if pkt.haslayer(DHCP6_Solicit):
                        if pkt[Ether].src == self.__config.get(
                                'wan', 'link_local_mac'):
                            continue

                        if pkt[Ether].src == self.__config.get(
                                'wan', 'ra_mac'):
                            continue
                        self.__config_setup1_1.set_local_addr_ceRouter(
                            pkt[IPv6].src)
                        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)

                if pkt.haslayer(ICMPv6ND_NS):

                    if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                            'wan', 'global_wan_addr'):
                        self.neighbor_advertise_global(pkt)

                    if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                            'wan', 'link_local_addr'):
                        self.neighbor_advertise_local(pkt)

                if time_over:
                    if not self.__config_setup1_1.get_setup1_1_OK():
                        self.set_status('WAN: Setup 1.1 em execução')
                        logging.info('WAN: Setup 1.1 em execução')

                        if not self.__config_setup1_1.get_disapproved():
                            self.__config_setup1_1.run_setup1_1(pkt)
                            if pkt.haslayer(ICMPv6ND_RS):
                                if pkt[Ether].src == self.__config.get(
                                        'wan', 'link_local_mac'):
                                    continue
                                if pkt[Ether].src == self.__config.get(
                                        'wan', 'ra_mac'):
                                    continue

                                self.set_status('WAN: Enviando ICMP RA')
                                logging.info('WAN: Enviando ICMP RA')

                                self.__config_setup1_1.set_local_addr_ceRouter(
                                    pkt[IPv6].src)
                                self.__config_setup1_1.set_mac_ceRouter(
                                    pkt[Ether].src)
                                self.__config_setup1_1.set_ether_src(
                                    self.__config.get('wan', 'ra_mac'))
                                self.__config_setup1_1.set_ether_dst(
                                    self.__config.get('multicast',
                                                      'all_mac_nodes'))
                                self.__config_setup1_1.set_ipv6_src(
                                    self.__config.get('wan', 'ra_address'))
                                self.__config_setup1_1.set_ipv6_dst(
                                    self.__config.get('multicast',
                                                      'all_nodes_addr'))
                                self.__sendmsgs.send_tr1_RA(
                                    self.__config_setup1_1)

                        else:
                            self.set_status(
                                'Reprovado Teste 3.2.1b - Falha em completar o Common Setup 1.1 da RFC'
                            )
                            time.sleep(2)
                            self.set_status(
                                'REPROVADO'
                            )  # Mensagem padrão para o frontEnd atualizar Status

                            logging.info(
                                'Reprovado Teste 3.2.1b - Falha em completar o Common Setup 1.1 da RFC'
                            )
                            self.__packet_sniffer_wan.stop()
                            return False

                    else:
                        if not self.__finish_wan:
                            if time1 < 30:
                                time1 = time1 + 1
                                if time1 % 5 == 0:
                                    self.ping()
                                    self.set_status(
                                        'WAN: Setup 1.1 Concluido Enviando Echo Request'
                                    )
                                    logging.info(
                                        'WAN: Setup 1.1 Concluido Enviando Echo Request'
                                    )
                            if pkt.haslayer(ICMPv6ND_NS):
                                if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                                        'wan', 'global_wan_addr'):
                                    self.neighbor_advertise_global(pkt)
                                if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                                        'wan', 'ra_address'):
                                    self.__config_setup1_1.set_ipv6_src(
                                        self.__config.get('wan', 'ra_address'))
                                    self.__config_setup1_1.set_ether_src(
                                        self.__config.get('wan', 'ra_mac'))
                                    self.__config_setup1_1.set_ether_dst(
                                        pkt[Ether].src)
                                    self.__config_setup1_1.set_ipv6_dst(
                                        pkt[IPv6].src)
                                    self.__config_setup1_1.set_tgt(
                                        self.__config.get('wan', 'ra_address'))
                                    self.__config_setup1_1.set_lla(
                                        self.__config.get('wan', 'ra_mac'))
                                    self.__config_setup1_1.set_mac_ceRouter(
                                        pkt[Ether].src)
                                    self.__sendmsgs.send_icmp_na(
                                        self.__config_setup1_1)

                        else:
                            self.__packet_sniffer_wan.stop()
                            if self.__fail_test:
                                return False
                            else:
                                return True
        self.__packet_sniffer_wan.stop()
        return False
コード例 #8
0
class Test273c:

    def __init__(self,config,app):
        self.__app = app
        self.__queue_wan = Queue()
        self.__queue_lan = Queue()
        self.__config = config
        self.__interface = None
        self.__pkt = None
        self.__local_addr_ceRouter =None
        self.__sendmsgs = SendMsgs(self.__config)
        self.__config_setup1_1 = ConfigSetup1_1(self.__config)
        #self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config)
        self.__wan_device_tr1 = self.__config.get('wan','device_wan_tr1')
        self.__lan_device = self.__config.get('lan','lan_device')
        self.__wan_mac_tr1 = self.__config.get('wan','wan_mac_tr1')
        self.__link_local_addr = self.__config.get('wan','link_local_addr')
        self.__all_nodes_addr = self.__config.get('multicast','all_nodes_addr')
        self.__test_desc = self.__config.get('tests','2.7.3c')
        self.__t_lan = None
        self.__finish_wan = False
        self.__fail_test = False
        self.msg = self.__config.get('tests','2.7.3c')
        self.msg_lan =self.__config.get('tests','2.7.3c')
        self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config,self.__lan_device)



    def set_flags(self):
        self.__config_setup1_1.set_flag_M(self.__config.get('t1.6.6b','flag_m'))
        self.__config_setup1_1.set_flag_0(self.__config.get('t1.6.6b','flag_o'))
        self.__config_setup1_1.set_flag_chlim(self.__config.get('t1.6.6b','flag_chlim'))
        self.__config_setup1_1.set_flag_L(self.__config.get('t1.6.6b','flag_l'))
        self.__config_setup1_1.set_flag_A(self.__config.get('t1.6.6b','flag_a'))
        self.__config_setup1_1.set_flag_R(self.__config.get('t1.6.6b','flag_r'))
        self.__config_setup1_1.set_flag_prf(self.__config.get('t1.6.6b','flag_prf'))
        self.__config_setup1_1.set_validlifetime(self.__config.get('t2.7.3c','validlifetime'))
        self.__config_setup1_1.set_preferredlifetime(self.__config.get('t2.7.3c','preferredlifetime'))
        self.__config_setup1_1.set_routerlifetime(self.__config.get('t2.7.3c','routerlifetime'))
        self.__config_setup1_1.set_intervalo(self.__config.get('t1.6.6b','intervalo'))

        self.__config_setup1_1.set_dhcp_t1(self.__config.get('t2.7.3c','dhcp_t1'))
        self.__config_setup1_1.set_dhcp_t2(self.__config.get('t2.7.3c','dhcp_t2'))
        self.__config_setup1_1.set_dhcp_preflft(self.__config.get('t2.7.3c','dhcp_preflft'))
        self.__config_setup1_1.set_dhcp_validlft(self.__config.get('t2.7.3c','dhcp_validlft'))
        self.__config_setup1_1.set_dhcp_plen(self.__config.get('t2.7.3c','dhcp_plen'))
   
    def set_flags_lan(self):
        self.__config_setup_lan.set_elapsetime(self.__config.get('solicitlan','elapsetime'))
        self.__config_setup_lan.set_xid(self.__config.get('solicitlan','xid'))
        self.__config_setup_lan.set_fdqn(self.__config.get('solicitlan','clientfqdn'))
        self.__config_setup_lan.set_vendor_class(self.__config.get('solicitlan','vendorclass'))

        self.__config_setup_lan.set_enterprise(self.__config.get('solicitlan','enterpriseid'))
        self.__config_setup_lan.set_client_duid(self.__config.get('solicitlan','duid'))
        self.__config_setup_lan.set_iaid(self.__config.get('solicitlan','iaid'))

    def set_status_lan(self,v):
        self.msg_lan = v

    def get_status_lan(self):
        return self.msg_lan


    def set_status(self,v):
        self.msg = v

    def get_status(self):
        return self.msg

        self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_ether_dst(self.__config.get('multicast','all_mac_routers'))
        self.__config_setup_lan.set_ipv6_dst(self.__config.get('general','all_routers_address'))
        self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
        self.__sendmsgs.send_icmp_rs(self.__config_setup_lan)
        
    def echo_request_lan(self):
        #print('ENVIO REQUEST 1 LAN')

        mac_global = self.__config_setup_lan.get_global_mac_ceRouter()
        ip_global = self.__config_setup_lan.get_global_addr_ceRouter()
        self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))
        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_ether_dst(mac_global)
        self.__config_setup_lan.set_ipv6_dst(ip_global)
        self.__sendmsgs.send_echo_request_lan(self.__config_setup_lan)

    def echo_request_lan_wrong_prefix(self):
        #print('ENVIO REQUEST 1 LAN')
        mac_global = self.__config_setup_lan.get_global_mac_ceRouter()
        ip_global = self.__config_setup_lan.get_global_addr_ceRouter()
        self.__config_setup_lan.set_ipv6_src(self.__config.get('t2.7.6','source_to_ping_tn1'))
        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_ether_dst(mac_global)
        self.__config_setup_lan.set_ipv6_dst(self.__config.get('wan','global_wan_addr'))
        self.__sendmsgs.send_echo_request_lan(self.__config_setup_lan)

    def icmp_na_wrong_prefix(self):
        self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))
        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_ether_dst(self.__config_setup_lan.get_global_mac_ceRouter())
        self.__config_setup_lan.set_ipv6_dst(self.__config_setup_lan.get_global_addr_ceRouter())
        self.__config_setup_lan.set_tgt(self.__config.get('t2.7.6','source_to_ping_tn1'))
        self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
        self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)

    def dhcp_information_lan(self):
        #self.__config_setup_lan.set_setup_lan_start()
        #print('#print ENVIO INFORMATION LAN')
        self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_ether_dst(self.__config.get('multicast','all_mac_routers'))
        self.__config_setup_lan.set_ipv6_dst(self.__config.get('multicast','all_routers_addr'))
        self.__config_setup_lan.set_xid(self.__config.get('informationlan','xid'))
        #self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_elapsetime(self.__config.get('informationlan','elapsetime'))
        self.__config_setup_lan.set_vendor_class(self.__config.get('informationlan','vendorclass'))
        self.__sendmsgs.send_dhcp_information(self.__config_setup_lan)


    def ra_wan(self):
        self.__config_setup1_1.set_ether_src(self.__config.get('wan','ra_mac'))
        self.__config_setup1_1.set_ether_dst(self.__config.get('multicast','all_mac_nodes'))
        self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','ra_address'))
        self.__config_setup1_1.set_ipv6_dst(self.__config.get('multicast','all_nodes_addr'))
        self.__sendmsgs.send_tr1_RA(self.__config_setup1_1)

    def dhcp_reconf(self):
        self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','link_local_addr'))
        self.__config_setup1_1.set_ipv6_dst(self.__config_setup1_1.get_local_addr_ceRouter())
        self.__config_setup1_1.set_ether_src(self.__config.get('wan','link_local_mac'))
        self.__config_setup1_1.set_ether_dst(self.__config_setup1_1.get_mac_ceRouter())
        self.__config_setup1_1.set_dhcp_reconf_type(self.__config.get('t2.7.5d','msg_type'))
        self.__config_setup1_1.set_udp_sport('547')
        self.__config_setup1_1.set_udp_dport('546')
        self.__sendmsgs.send_dhcp_reconfigure(self.__config_setup1_1)


    def icmp_na_global_lan(self,pkt):
        self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))
        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
        self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup_lan.set_tgt(self.__config.get('lan','global_wan_addr'))
        self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)

    def rs_lan(self):

        self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_ether_dst(self.__config.get('multicast','all_mac_routers'))
        self.__config_setup_lan.set_ipv6_dst(self.__config.get('general','all_routers_address'))
        self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
        self.__sendmsgs.send_icmp_rs(self.__config_setup_lan)
    def run_Lan(self):
        @self.__app.route("/LAN",methods=['GET'])
        def envia_lan():
            return self.get_status_lan()
        #self.__config_setup_lan_.flags_partA()

        t_test = 0
        sent_reconfigure = False
        time_over = False
        self.set_flags_lan()
        cache_lan = []
        temporizador = 0
        test_max_time_lan = 300
        while not self.__queue_lan.full():
            time.sleep(1)
            temporizador = temporizador + 1
            while self.__queue_lan.empty():
                

                time.sleep(1)
                if self.__config_setup1_1.get_setup1_1_OK():
                    if temporizador < test_max_time_lan:
                        temporizador = temporizador + 1
                    else:
                        self.set_status_lan('LAN: Reprovado. Timeout')
                        time.sleep(2)
                        self.set_status_lan('REPROVADO')
                        logging.info('LAN: Reprovado. Timeout')
                        #logging.info(routerlifetime)
                        self.__finish_wan = True 
                        self.__fail_test = True
                        self.__packet_sniffer_lan.stop()
                        return False


                    if temporizador % 20 == 0:
                        logging.info('LAN: Tempo limite do teste: '+str(test_max_time_lan)+' segundos. Tempo: ' +str(temporizador))
                        self.set_status_lan('LAN: Tempo limite do teste: '+str(test_max_time_lan)+' segundos. Tempo: ' +str(temporizador))


                    if self.__config_setup1_1.get_recvd_dhcp_renew():
                #pkt = self.__queue_lan.get()
                        self.set_status_lan('LAN: Transmissão periódica de ICMP RS Apos o recebimento da mensagem DHCP Renew')
                        logging.info('LAN: Transmissão periódica de ICMP RS  Apos o recebimento da mensagem DHCP Renew')             
                        self.__config_setup_lan.set_setup_lan_start()
                        self.rs_lan()

                        
            pkt = self.__queue_lan.get()
            cache_lan.append(pkt)
            wrpcap("lan-2.7.3c.cap",cache_lan)

            if not self.__config_setup_lan.get_setup_OK():
                if not self.__config_setup_lan.get_disapproved():
                    self.__config_setup_lan.run_setup1_1(pkt)
                else:
                    
                    logging.info('LAN: Reprovado Teste 2.7.4a - Falha em completar o setup 1.1')
                    self.set_status_lan('Reprovado Teste 2.7.4a - Falha em completar o setup 1.1')
                    time.sleep(2)
                    self.set_status_lan('REPROVADO') # Mensagem padrão para o frontEnd atualizar Status
                    self.__packet_sniffer_lan.stop()
                    self.__finish_wan = True 
                    self.__fail_test = True
                    return False 
            else:
                logging.info('Setup LAN concluido. Verificando o valor de routerlifetime ')
                self.set_status_lan('Setup LAN concluido. o valor de  routerlifetime')
                routerlifetime = self.__config_setup_lan.get_routerlifetime_CeRouter()
                if routerlifetime == 0:
                    logging.info(' APROVADO  Teste 2.7.3c: routerlifetime OK. routerlifetime  igual a 0')
                    self.set_status_lan('APROVADO  Teste 2.7.3c: routerlifetime OK. routerlifetime  igual a 0')
                    time.sleep(2)
                    self.set_status_lan('APROVADO') # Mensagem padrão para o frontEnd atualizar Status
                    
                    self.__packet_sniffer_lan.stop()
                    self.__finish_wan = True
                    self.__fail_test = False 
                    return True         
                else:                     
                    logging.info(' REPROVADO  Teste 2.7.3c: routerlifetime. routerlifetime  acima de 0')
                    self.set_status_lan('REPROVADO  Teste 2.7.3c: routerlifetime. routerlifetime  acima de 0')
                    time.sleep(2)
                    self.set_status_lan('REPROVADO') # Mensagem padrão para o frontEnd atualizar Status
                    self.__packet_sniffer_lan.stop()
                    self.__finish_wan = True
                    self.__fail_test = False 
                    return True         
                
    def run(self):
        @self.__app.route("/WAN",methods=['GET'])
        def enviawan():
            return self.get_status()
        self.__t_lan =  Thread(target=self.run_Lan,name='LAN_Thread')
        self.__t_lan.start()
        
        self.__packet_sniffer_wan = PacketSniffer('Test273b-WAN',self.__queue_wan,self,self.__config,self.__wan_device_tr1)
        self.__packet_sniffer_wan.start()
        
        self.__packet_sniffer_lan = PacketSniffer('Test273b-LAN',self.__queue_lan,self,self.__config,self.__lan_device)
        test_lan = self.__packet_sniffer_lan.start()
        cache_wan = []
        self.set_flags()
        logging.info(self.__test_desc)
        t_test = 0
        sent_reconfigure = False
        time_over = False
        #time.sleep(11111)

        self.__config_setup1_1.set_pd_prefixlen(self.__config.get('t2.7.3c','pd_prefixlen')) 
        self.__config_setup1_1.set_routerlifetime(self.__config.get('t2.7.3c','routerlifetime')) 
        test_max_time = 300
        temporizador = 0 
        #self.__config_setup1_1.active_DHCP_no_IA_PD()
        while not self.__queue_wan.full():
            while self.__queue_wan.empty():
                time.sleep(1)
                if temporizador < test_max_time:
                    temporizador = temporizador + 1
                else:
                    self.set_status('WAN: Reprovado. Timeout')
                    time.sleep(2)
                    self.set_status('REPROVADO')
                    logging.info('WAN: Reprovado. Timeout')
                    #logging.info(routerlifetime)
                    self.__packet_sniffer_lan.stop()
                    self.__packet_sniffer_wan.stop()
                    return False 
                if temporizador % 5 ==0:
                    logging.info('WAN: Envio de RA periódico')
                    self.set_status('WAN: Envio de RA periódico')                        
                    self.ra_wan()

            pkt = self.__queue_wan.get()

            cache_wan.append(pkt)
            wrpcap("WAN-2.7.3c.cap",cache_wan)

            if not self.__config_setup1_1.get_setup1_1_OK():
                logging.info('WAN: Setup 1.1 em execução')
                self.set_status('WAN: Setup 1.1 em execução') 
                if not self.__config_setup1_1.get_disapproved():
                    self.__config_setup1_1.run_setup1_1(pkt)
                else:
                    logging.info('WAN: Reprovado Teste 2.7.4a - Falha em completar o setup 1.1')
                    self.set_status('WAN: Reprovado Teste 2.7.4a - Falha em completar o setup 1.1')
                    time.sleep(2)
                    self.set_status('REPROVADO') # Mensagem padrão para o frontEnd atualizar Status
                    self.__packet_sniffer_lan.stop()
                    self.__finish_wan = True
                    self.__fail_test = True
            else: 
                logging.info('WAN: Checando o recebimento de Renew')
                self.set_status('WAN: Checando o recebimento de Renew')
                self.__config_setup1_1.check_layers(pkt)

                if self.__finish_wan: 
                    self.__packet_sniffer_wan.stop()
                    if self.__fail_test:
                        return False
                    else:
                        return True

        self.__packet_sniffer_wan.stop()
        return False
     
        
コード例 #9
0
class Test275c:
    def __init__(self, config, app):
        self.__app = app
        self.__queue_wan = Queue()
        self.__queue_lan = Queue()
        self.__config = config
        self.__interface = None
        self.__pkt = None
        self.__local_addr_ceRouter = None
        self.__sendmsgs = SendMsgs(self.__config)
        self.__config_setup1_1 = ConfigSetup1_1(self.__config)
        #self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config)
        self.__wan_device_tr1 = self.__config.get('wan', 'device_wan_tr1')
        self.__lan_device = self.__config.get('lan', 'lan_device')
        self.__wan_mac_tr1 = self.__config.get('wan', 'wan_mac_tr1')
        self.__link_local_addr = self.__config.get('wan', 'link_local_addr')
        self.__all_nodes_addr = self.__config.get('multicast',
                                                  'all_nodes_addr')
        self.__test_desc = self.__config.get('tests', '2.7.5c')
        self.__t_lan = None
        self.__finish_wan = False
        self.__fail_test = False
        self.__dhcp_renew_done = False

        self.msg = self.__config.get('tests', '2.7.5c')
        self.msg_lan = self.__config.get('tests', '2.7.5c')
        self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config,
                                                     self.__lan_device)

    def set_flags(self):
        self.__config_setup1_1.set_flag_M(
            self.__config.get('t1.6.6b', 'flag_m'))
        self.__config_setup1_1.set_flag_0(
            self.__config.get('t1.6.6b', 'flag_o'))
        self.__config_setup1_1.set_flag_chlim(
            self.__config.get('t1.6.6b', 'flag_chlim'))
        self.__config_setup1_1.set_flag_L(
            self.__config.get('t1.6.6b', 'flag_l'))
        self.__config_setup1_1.set_flag_A(
            self.__config.get('t1.6.6b', 'flag_a'))
        self.__config_setup1_1.set_flag_R(
            self.__config.get('t1.6.6b', 'flag_r'))
        self.__config_setup1_1.set_flag_prf(
            self.__config.get('t1.6.6b', 'flag_prf'))
        self.__config_setup1_1.set_validlifetime(
            self.__config.get('t2.7.5c', 'validlifetime'))
        self.__config_setup1_1.set_preferredlifetime(
            self.__config.get('t2.7.5c', 'preferredlifetime'))
        self.__config_setup1_1.set_routerlifetime(
            self.__config.get('t2.7.5c', 'routerlifetime'))
        self.__config_setup1_1.set_intervalo(
            self.__config.get('t1.6.6b', 'intervalo'))
        self.__config_setup1_1.set_prefix_addr(
            self.__config.get('setup1-1_advertise', 'ia_pd_address'))
        self.__config_setup1_1.set_dhcp_t1(
            self.__config.get('t2.7.5c', 'dhcp_t1'))
        self.__config_setup1_1.set_dhcp_t2(
            self.__config.get('t2.7.5c', 'dhcp_t2'))
        self.__config_setup1_1.set_dhcp_preflft(
            self.__config.get('t2.7.5c', 'dhcp_preflft'))
        self.__config_setup1_1.set_dhcp_validlft(
            self.__config.get('t2.7.5c', 'dhcp_validlft'))
        self.__config_setup1_1.set_dhcp_plen(
            self.__config.get('t2.7.5c', 'dhcp_plen'))

    def set_flags_lan(self):
        self.__config_setup_lan.set_elapsetime(
            self.__config.get('solicitlan', 'elapsetime'))
        self.__config_setup_lan.set_xid(self.__config.get('solicitlan', 'xid'))
        self.__config_setup_lan.set_fdqn(
            self.__config.get('solicitlan', 'clientfqdn'))
        self.__config_setup_lan.set_vendor_class(
            self.__config.get('solicitlan', 'vendorclass'))

        self.__config_setup_lan.set_enterprise(
            self.__config.get('solicitlan', 'enterpriseid'))
        self.__config_setup_lan.set_client_duid(
            self.__config.get('solicitlan', 'duid'))
        self.__config_setup_lan.set_iaid(
            self.__config.get('solicitlan', 'iaid'))

    def set_status_lan(self, v):
        self.msg_lan = v

    def get_status_lan(self):
        return self.msg_lan

    def set_status(self, v):
        self.msg = v

    def get_status(self):
        return self.msg

    def rs_lan(self):

        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'lan_local_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(
            self.__config.get('multicast', 'all_mac_routers'))
        self.__config_setup_lan.set_ipv6_dst(
            self.__config.get('general', 'all_routers_address'))
        self.__config_setup_lan.set_lla(self.__config.get(
            'lan', 'mac_address'))
        self.__sendmsgs.send_icmp_rs(self.__config_setup_lan)

    def echo_request_lan(self):
        #print('ENVIO REQUEST 1 LAN')

        mac_global = self.__config_setup_lan.get_global_mac_ceRouter()
        ip_global = self.__config_setup_lan.get_global_addr_ceRouter()
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'global_wan_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(mac_global)
        self.__config_setup_lan.set_ipv6_dst(ip_global)
        self.__sendmsgs.send_echo_request_lan(self.__config_setup_lan)

    def echo_request_lan_wrong_prefix(self):
        #print('ENVIO REQUEST 1 LAN')
        mac_global = self.__config_setup_lan.get_global_mac_ceRouter()
        ip_global = self.__config_setup_lan.get_global_addr_ceRouter()
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('t2.7.6', 'source_to_ping_tn1'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(mac_global)
        self.__config_setup_lan.set_ipv6_dst(
            self.__config.get('wan', 'global_wan_addr'))
        self.__sendmsgs.send_echo_request_lan(self.__config_setup_lan)

    def icmp_na_wrong_prefix(self):
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'global_wan_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(
            self.__config_setup_lan.get_global_mac_ceRouter())
        self.__config_setup_lan.set_ipv6_dst(
            self.__config_setup_lan.get_global_addr_ceRouter())
        self.__config_setup_lan.set_tgt(
            self.__config.get('t2.7.6', 'source_to_ping_tn1'))
        self.__config_setup_lan.set_lla(self.__config.get(
            'lan', 'mac_address'))
        self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)

    def dhcp_information_lan(self):
        #self.__config_setup_lan.set_setup_lan_start()
        #print('#print ENVIO INFORMATION LAN')
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'lan_local_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(
            self.__config.get('multicast', 'all_mac_routers'))
        self.__config_setup_lan.set_ipv6_dst(
            self.__config.get('multicast', 'all_routers_addr'))
        self.__config_setup_lan.set_xid(
            self.__config.get('informationlan', 'xid'))
        #self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_elapsetime(
            self.__config.get('informationlan', 'elapsetime'))
        self.__config_setup_lan.set_vendor_class(
            self.__config.get('informationlan', 'vendorclass'))
        self.__sendmsgs.send_dhcp_information(self.__config_setup_lan)

    def ra_wan(self):
        self.__config_setup1_1.set_ether_src(self.__config.get(
            'wan', 'ra_mac'))
        self.__config_setup1_1.set_ether_dst(
            self.__config.get('multicast', 'all_mac_nodes'))
        self.__config_setup1_1.set_ipv6_src(
            self.__config.get('wan', 'ra_address'))
        self.__config_setup1_1.set_ipv6_dst(
            self.__config.get('multicast', 'all_nodes_addr'))
        self.__sendmsgs.send_tr1_RA(self.__config_setup1_1)

    def dhcp_reconf(self):
        self.__config_setup1_1.set_ipv6_src(
            self.__config.get('wan', 'link_local_addr'))
        self.__config_setup1_1.set_ipv6_dst(
            self.__config_setup1_1.get_local_addr_ceRouter())
        self.__config_setup1_1.set_ether_src(
            self.__config.get('wan', 'link_local_mac'))
        self.__config_setup1_1.set_ether_dst(
            self.__config_setup1_1.get_mac_ceRouter())
        self.__config_setup1_1.set_dhcp_reconf_type(
            self.__config.get('t2.7.5d', 'msg_type'))
        self.__config_setup1_1.set_udp_sport('547')
        self.__config_setup1_1.set_udp_dport('546')
        self.__sendmsgs.send_dhcp_reconfigure(self.__config_setup1_1)

    def dhcp_reply(self, pkt):
        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
        self.__config_setup1_1.set_local_addr_ceRouter(pkt[IPv6].src)
        self.__config_setup1_1.set_xid(pkt[DHCP6_Renew].trid)
        self.__config_setup1_1.set_ipv6_src(
            self.__config.get('wan', 'link_local_addr'))
        self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup1_1.set_ether_src(
            self.__config.get('wan', 'link_local_mac'))
        self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
        self.__config_setup1_1.set_dhcp_preflft('100')
        self.__config_setup1_1.set_dhcp_validlft('200')
        self.__config_setup1_1.set_dhcp_plen('60')
        self.__config_setup1_1.set_prefix_addr(
            self.__config.get('setup1-1_advertise', 'ia_pd_address'))
        self.__sendmsgs.send_dhcp_reply_v3(self.__config_setup1_1)

    def icmp_na_global_lan(self, pkt):
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'global_wan_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
        self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup_lan.set_tgt(
            self.__config.get('lan', 'global_wan_addr'))
        self.__config_setup_lan.set_lla(self.__config.get(
            'lan', 'mac_address'))
        self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)

    def run_Lan(self):
        @self.__app.route("/LAN", methods=['GET'])
        def envia_lan():
            return self.get_status_lan()

        #self.__config_setup_lan_.flags_partA()
        logging.info('Thread da LAN inicio')
        t_test = 0
        t_test1 = 0
        sent_reconfigure = False
        time_over = False
        send_ra = False
        self.set_flags_lan()
        self.__config_setup_lan.set_setup_lan_start()
        cache_lan = []
        temporizador = 0
        test_max_time_lan = 300
        rs_sent = False
        while not self.__queue_lan.full():
            time.sleep(1)
            temporizador = temporizador + 1
            while self.__queue_lan.empty():
                time.sleep(1)
                if self.__config_setup1_1.get_setup1_1_OK():

                    if temporizador < test_max_time_lan:
                        temporizador = temporizador + 1
                    else:
                        self.set_status_lan('LAN: Reprovado. Timeout')
                        time.sleep(2)
                        self.set_status_lan('REPROVADO')
                        logging.info('LAN: Reprovado. Timeout')
                        #logging.info(routerlifetime)
                        self.__finish_wan = True
                        self.__fail_test = True
                        self.__packet_sniffer_lan.stop()

                        return False
                    if temporizador % 20 == 0:

                        logging.info('LAN: Tempo limite do teste: ' +
                                     str(test_max_time_lan) +
                                     ' segundos. Tempo: ' + str(temporizador))
                        self.set_status_lan('LAN: Tempo limite do teste: ' +
                                            str(test_max_time_lan) +
                                            ' segundos. Tempo: ' +
                                            str(temporizador))

                    if temporizador % 8 == 0:
                        self.set_status_lan(
                            'LAN: Transmissão periódica de ICMP RS e DHCP information'
                        )
                        logging.info(
                            'LAN: Transmissão periódica de ICMP RS e DHCP information'
                        )
                        self.rs_lan()
                        #self.dhcp_information_lan()

                    if temporizador % 5 == 0:
                        if self.__config_setup_lan.get_ND_global_OK(
                        ) and not self.__config_setup_lan.get_global_ping_OK():
                            self.set_status_lan(
                                'LAN: Transmissão Echo Request IP global do roteador'
                            )
                            logging.info(
                                'LAN: Transmissão Echo Request IP global do roteador'
                            )
                            self.echo_request_lan()

            pkt = self.__queue_lan.get()

            cache_lan.append(pkt)
            wrpcap("lan-2.7.5c.cap", cache_lan)

            if not self.__config_setup_lan.get_global_ping_OK():
                if not self.__config_setup_lan.get_disapproved():
                    self.__config_setup_lan.run_setup1_1(pkt)
                else:
                    logging.info(
                        'LAN: Reprovado Teste 2.7.5c - Falha em completar o setup 1.1'
                    )
                    self.set_status_lan(
                        'Reprovado Teste 2.7.5c - Falha em completar o setup 1.1'
                    )
                    time.sleep(2)
                    self.set_status_lan(
                        'REPROVADO'
                    )  # Mensagem padrão para o frontEnd atualizar Status

                    self.__packet_sniffer_lan.stop()
                    self.__finish_wan = True
                    self.__fail_test = True
                    return False
            else:
                if self.__dhcp_renew_done:
                    logging.info('LAN: DHCP Renew concluido')
                    self.set_status_lan('LAN: DHCP Renew concluido')
                    if temporizador < test_max_time_lan:
                        #if t_test1 % 10 == 0:
                        #self.__config_setup_lan.set_setup_lan_start()
                        self.set_status_lan(
                            'LAN: DHCP Renew concluido. Enviando RS')
                        logging.info('LAN: DHCP Renew concluido. Enviado RS')
                        if temporizador % 10 == 0:
                            while not self.__queue_lan.empty():

                                self.__queue_lan.get()

                            self.rs_lan()
                            rs_sent = True
                        if rs_sent:
                            if pkt.haslayer(ICMPv6ND_RA):

                                if pkt.haslayer(ICMPv6NDOptPrefixInfo):
                                    if pkt[ICMPv6NDOptPrefixInfo].prefix != self.__config.get(
                                            'setup1-1_advertise',
                                            'ia_pd_address2'):
                                        logging.info(
                                            ' Teste2.7.5c: Reprovado. Não Recebeu o Prefixo atualizado'
                                        )
                                        logging.info(
                                            pkt[ICMPv6NDOptPrefixInfo].prefix)
                                        self.set_status_lan(
                                            '  Teste2.7.5c: Reprovado. Não Recebeu o Prefixo atualizado'
                                        )
                                        time.sleep(2)
                                        self.set_status_lan(
                                            'REPROVADO'
                                        )  # Mensagem padrão para o frontEnd atualizar Status

                                        self.__packet_sniffer_lan.stop()
                                        self.__finish_wan = True
                                        self.__fail_test = True
                                        return False
                                    else:  #self.__validlifetime_CeRouter == pkt[ICMPv6NDOptPrefixInfo].validlifetime

                                        logging.info(
                                            ' APROVADO Teste 2.7.5c: Recebeu o Prefixo atualizado.'
                                        )

                                        self.set_status(
                                            ' APROVADO Teste 2.7.5c: Recebeu o Prefixo atualizado.'
                                        )
                                        time.sleep(2)
                                        self.set_status(
                                            'APROVADO'
                                        )  # Mensagem padrão para o frontEnd atualizar Status

                                        self.__packet_sniffer_lan.stop()
                                        self.__finish_wan = True
                                        self.__fail_test = False
                                        return True
                                else:
                                    logging.info(
                                        ' Teste2.7.5c: Reprovado. Não Recebeu o Prefixo'
                                    )
                                    logging.info(
                                        pkt[ICMPv6NDOptPrefixInfo].prefix)
                                    self.set_status_lan(
                                        'Teste2.7.5c: Reprovado. Não Recebeu o Prefixo'
                                    )
                                    time.sleep(2)
                                    self.set_status_lan(
                                        'REPROVADO'
                                    )  # Mensagem padrão para o frontEnd atualizar Status

                                    self.__packet_sniffer_lan.stop()
                                    self.__finish_wan = True
                                    self.__fail_test = True

    def dhcp_reconfigure(self):
        self.__config_setup1_1.set_ipv6_src(
            self.__config.get('wan', 'link_local_addr'))

        self.__config_setup1_1.set_ipv6_dst(
            self.__config_setup1_1.get_local_addr_ceRouter())

        self.__config_setup1_1.set_ether_src(
            self.__config.get('wan', 'link_local_mac'))

        self.__config_setup1_1.set_ether_dst(
            self.__config_setup1_1.get_mac_ceRouter())

        self.__config_setup1_1.set_dhcp_reconf_type(
            self.__config.get('t1.6.3', 'msg_type'))

        self.__config_setup1_1.set_udp_sport('547')
        self.__config_setup1_1.set_udp_dport('546')
        self.__sendmsgs.send_dhcp_reconfigure(self.__config_setup1_1)

    def dhcp_renew(self, pkt):
        #                        if self.__active_renew_dhcp:
        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
        self.__config_setup1_1.set_local_addr_ceRouter(pkt[IPv6].src)
        self.__config_setup1_1.set_xid(pkt[DHCP6_Renew].trid)
        self.__config_setup1_1.set_ipv6_src(
            self.__config.get('wan', 'link_local_addr'))
        self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup1_1.set_ether_src(
            self.__config.get('wan', 'link_local_mac'))
        self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
        self.__config_setup1_1.set_dhcp_preflft('0')
        self.__config_setup1_1.set_dhcp_validlft('0')
        self.__config_setup1_1.set_dhcp_plen('64')
        #self.__config_setup1_1.set_prefix_addr(self.__config.get('setup1-1_advertise','ia_pd_address2'))
        self.__sendmsgs.send_dhcp_reply_v2(self.__config_setup1_1)
        #self.__dhcp_ok = True

    def run(self):
        @self.__app.route("/WAN", methods=['GET'])
        def enviawan():
            return self.get_status()

        self.__t_lan = Thread(target=self.run_Lan, name='LAN_Thread')
        self.__t_lan.start()

        self.__packet_sniffer_wan = PacketSniffer('Test273b-WAN',
                                                  self.__queue_wan, self,
                                                  self.__config,
                                                  self.__wan_device_tr1)
        self.__packet_sniffer_wan.start()

        self.__packet_sniffer_lan = PacketSniffer('Test273b-LAN',
                                                  self.__queue_lan, self,
                                                  self.__config,
                                                  self.__lan_device)
        self.__packet_sniffer_lan.start()
        cache_wan = []
        self.set_flags()
        logging.info(self.__test_desc)
        t_test = 0
        sent_reconfigure = False
        time_over = False
        #time.sleep(11111)

        self.__config_setup1_1.set_pd_prefixlen(
            self.__config.get('t2.7.5c', 'pd_prefixlen'))
        self.__config_setup1_1.set_routerlifetime(
            self.__config.get('t2.7.5c', 'routerlifetime'))
        test_max_time = 300
        temporizador = 0
        #self.__config_setup1_1.active_DHCP_no_IA_PD()
        while not self.__queue_wan.full():
            while self.__queue_wan.empty():
                time.sleep(1)
                if temporizador < test_max_time:
                    temporizador = temporizador + 1
                else:
                    self.set_status('WAN: Reprovado. Timeout')
                    time.sleep(2)
                    self.set_status('REPROVADO')
                    logging.info('WAN: Reprovado. Timeout')
                    #logging.info(routerlifetime)
                    self.__packet_sniffer_lan.stop()
                    self.__packet_sniffer_wan.stop()
                    return False

                if temporizador % 10 == 0:
                    logging.info('WAN: Envio de RA periódico')
                    self.set_status('WAN: Envio de RA periódico')
                    self.ra_wan()

            pkt = self.__queue_wan.get()

            cache_wan.append(pkt)
            wrpcap("WAN-2.7.5c.cap", cache_wan)

            if not self.__config_setup1_1.get_setup1_1_OK():
                logging.info('WAN: Setup 1.1 em execução')
                self.set_status('WAN: Setup 1.1 em execução')
                if not self.__config_setup1_1.get_disapproved():
                    self.__config_setup1_1.run_setup1_1(pkt)
                else:
                    logging.info(
                        'WAN: Reprovado Teste 2.7.5c - Falha em completar o setup 1.1'
                    )
                    self.set_status(
                        'WAN: Reprovado Teste 2.7.5c - Falha em completar o setup 1.1'
                    )
                    time.sleep(2)
                    self.set_status(
                        'REPROVADO'
                    )  # Mensagem padrão para o frontEnd atualizar Status
                    self.__packet_sniffer_lan.stop()
                    self.__finish_wan = True
                    self.__fail_test = True
                    return False
            else:
                if not self.__finish_wan:

                    if not sent_reconfigure:
                        logging.info(
                            'WAN: Aguardando 25 segundos para enviar o DHCP Reconfigure'
                        )
                        self.set_status(
                            'WAN: Aguardando 25 segundos para enviar o DHCP Reconfigure'
                        )
                        time.sleep(25)

                        self.dhcp_reconfigure()

                        sent_reconfigure = True
                        logging.info('WAN:  DHCP Reconfigure Enviado')
                        self.set_status('WAN:  Reconfigure Enviado')

                    if pkt.haslayer(DHCP6_Renew):
                        logging.info('WAN:   Enviando DHCP REPLY')
                        self.set_status('WAN:  Enviando DHCP REPLy')
                        if not self.__dhcp_renew_done:
                            self.dhcp_renew(pkt)
                            self.__dhcp_renew_done = True
                else:
                    self.__packet_sniffer_wan.stop()
                    if self.__fail_test:
                        return False
                    else:
                        return True
        self.__packet_sniffer_wan.stop()
        return False
コード例 #10
0
class ConfigSetup1_1_Lan:
    def __init__(self, config, interface):
        self.__config = config
        self.__interface = None
        self.__pkt = None
        self.__valid = False
        self.__result = None
        self.__device_lan_tn1 = None
        self.__lan_mac_tn1 = None
        self.__ceRouter_mac_addr = None
        self.__flag_M = None
        self.__flag_O = None
        self.__flag_chlim = None
        self.__flag_L = None
        self.__flag_A = None
        self.__flag_R = None
        self.__validlifetime = None
        self.__preferredlifetime = None
        self.__interval = None
        self.__routerlifetime = None
        self.__ipv6_dst = None
        self.__ipv6_src = None
        self.__ether_src = None
        self.__ether_dst = None
        self.__xid = None
        self.__server_duid = None
        self.__client_duid = None
        self.__ND_local_OK = False
        self.__setup1_1_OK = False
        self.__local_ping_OK = False
        self.__global_ns_ok = False
        self.__dhcp_ok = False
        self.__iaid = None
        self.__flag_prf = None
        self.__prefixaddr_CeRouter = None
        self.__l_CeRouter = None
        self.__A_CeRouter = None
        self.__R_CeRouter = None
        self.__validlifetime_CeRouter = None
        self.__preferredlifetime_CeRouter = None
        self.__prefixlen_CeRouter = None
        self.__r_prefixaddr_CeRouter = None
        self.__r_plen_CeRouter = None
        self.__r_prf_CeRouter = None
        self.__r_rtlifetime_CeRouter = None
        self.__rdnss_dns_CeRouter = None
        self.__rdnss_lifetime_CeRouter = None
        self.__domainname = None
        self.__domainname_lifetime_CeRouter = None
        self.__linklayer_CeRouter = None
        self.__setup_lan_start = None
        self.__lla = None
        self.__routerlifetime_CeRouter = None
        self.__disapproved = False
        self.__dhcp_reconf_type = None
        self.__local_addr_ceRouter = None
        self.__recvd_dhcp_srcladdr = False
        self.__recvd_dhcp_rdnss = False
        self.__ND_global_OK = False
        self.__global_addr_ceRouter = None
        self.__global_mac_cerouter = None
        self.__ping_global = False
        self.__mac_cerouter = None
        self.__sendmsgssetup1_1 = SendMsgs(self.__config)
        self.__wan_device_tr1 = self.__config.get('wan', 'device_wan_tr1')
        self.__lan_device = self.__config.get('lan', 'lan_device')
        self.__wan_mac_tr1 = self.__config.get('wan', 'wan_mac_tr1')
        self.__link_local_addr = self.__config.get('wan', 'link_local_addr')
        self.__all_nodes_addr = self.__config.get('multicast',
                                                  'all_nodes_addr')
        self.__test_desc = self.__config.get('tests', '1.6.2b')
        self.__elapsetime = None
        self.__fdqn = None
        self.__vendor_class = None
        self.__enterprise = None
        self.opt_req = None
        self.send_solicit = False

    def send_icmpv6_ra(self, pkt):
        et = Ether(src=self.__wan_mac_tr1)

        ip = IPv6(src=self.__link_local_addr,\
                  dst=self.__all_nodes_addr)
        icmp_ra = ICMPv6ND_RA()
        sendp(et / ip / icmp_ra, iface=self.__wan_device_tr1)

    def send_echo_request_lan(self):
        et = Ether(src=self.__wan_mac_tr1,\
                   dst=self.__ceRouter_mac_addr)
        ip = IPv6(src=self.__link_local_addr,\
                  dst=self.__all_nodes_addr)
        icmp_ra = ICMPv6EchoRequest()
        sendp(et / ip / icmp_ra, iface=self.__wan_device_tr1)

    def flags_partA(self):
        self.__flag_M = self.__config.get('t1.6.2_flags_part_a', 'flag_m')
        self.__flag_O = self.__config.get('t1.6.2_flags_part_a', 'flag_o')
        self.__flag_chlim = self.__config.get('t1.6.2_flags_part_a',
                                              'flag_chlim')
        self.__flag_L = self.__config.get('t1.6.2_flags_part_a', 'flag_l')
        self.__flag_A = self.__config.get('t1.6.2_flags_part_a', 'flag_a')
        self.__flag_R = self.__config.get('t1.6.2_flags_part_a', 'flag_r')
        self.__validlifetime = self.__config.get('t1.6.2_flags_part_a',
                                                 'validlifetime')
        self.__preferredlifetime = self.__config.get('t1.6.2_flags_part_a',
                                                     'preferredlifetime')
        self.__routerlifetime = self.__config.get('t1.6.2_flags_part_a',
                                                  'routerlifetime')
        self.__intervalo = self.__config.get('t1.6.2_flags_part_a',
                                             'intervalo')

    def flags_partB(self):
        self.__flag_M = self.__config.get('t1.6.2_flags_part_b', 'flag_m')
        self.__flag_O = self.__config.get('t1.6.2_flags_part_b', 'flag_o')
        self.__flag_chlim = self.__config.get('t1.6.2_flags_part_b',
                                              'flag_chlim')
        self.__flag_L = self.__config.get('t1.6.2_flags_part_b', 'flag_l')
        self.__flag_A = self.__config.get('t1.6.2_flags_part_b', 'flag_a')
        self.__flag_R = self.__config.get('t1.6.2_flags_part_b', 'flag_r')
        self.__validlifetime = self.__config.get('t1.6.2_flags_part_b',
                                                 'validlifetime')
        self.__preferredlifetime = self.__config.get('t1.6.2_flags_part_b',
                                                     'preferredlifetime')
        self.__routerlifetime = self.__config.get('t1.6.2_flags_part_b',
                                                  'routerlifetime')
        self.__intervalo = self.__config.get('t1.6.2_flags_part_b',
                                             'intervalo')

#===========LAN======================

    def get_prefixaddr_CeRouter(self):
        return self.__prefixaddr_CeRouter

    def get_l_CeRouter(self):
        return self.__l_CeRouter

    def get_A_CeRouter(self):
        return self.__A_CeRouter

    def get_R_CeRouter(self):
        return self.__R_CeRouter

    def get_validlifetime_CeRouter(self):
        return self.__validlifetime_CeRouter

    def get_preferredlifetime_CeRouter(self):
        return self.__preferredlifetime_CeRouter

    def get_routerlifetime_CeRouter(self):
        return self.__routerlifetime_CeRouter

    def get_prefixlen_CeRouter(self):
        return self.__prefixlen_CeRouter

    def get_r_prefixaddr_CeRouter(self):
        return self.__r_prefixaddr_CeRouter

    def get_r_plen_CeRouter(self):
        return self.__r_plen_CeRouter

    def get_r_prf_CeRouter(self):
        return self.__r_prf_CeRouter

    def get_r_lifetime_CeRouter(self):
        return self.__r_rtlifetime_CeRouter

    def get_rdnss_dns_CeRouter(self):
        return self.__rdnss_dns_CeRouter

    def get_rdnss_lifetime_CeRouter(self):
        return self.__rdnss_lifetime_CeRouter

    def get_domainname(self):
        return self.__domainname

    def get_domainname_lifetime_CeRouter(self):
        return self.__domainname_lifetime_CeRouter

    def get_linklayer_CeRouter(self):
        return self.__linklayer_CeRouter

    def get_lan_device(self):
        return self.__lan_device

    def get_setup_OK(self):
        return self.__setup1_1_OK

    def get_elapsetime(self):
        return int(self.__elapsetime)

    def set_elapsetime(self, valor):
        self.__elapsetime = valor

    def get_fdqn(self):
        return self.__fdqn

    def set_fdqn(self, valor):
        self.__fdqn = valor

    def get_vendor_class(self):
        return self.__vendor_class

    def set_vendor_class(self, valor):
        self.__vendor_class = valor

    def get_enterprise(self):
        return int(self.__enterprise)

    def set_enterprise(self, valor):
        self.__enterprise = valor

    def get_opt_req(self):
        return self.opt_req

    def set_opt_req(self, valor):
        self.opt_req = valor

#=========== WAN/LAN===================

    def set_result(self, valor):
        self.__result = valor

    def get_result(self):
        return self.__result

    def get_flag_M(self):
        return int(self.__flag_M)

    def set_flag_M(self, valor):
        self.__flag_M = valor

    def get_flag_O(self):
        return int(self.__flag_O)

    def get_flag_prf(self):
        return int(self.__flag_prf)

    def set_flag_prf(self, valor):
        self.__flag_prf = valor

    def set_flag_0(self, valor):
        self.__flag_O = valor

    def set_routerlifetime(self, valor):
        self.__routerlifetime = valor

    def set_flag_L(self, valor):
        self.__flag_L = valor

    def set_flag_A(self, valor):
        self.__flag_A = valor

    def set_flag_R(self, valor):
        self.__flag_R = valor

    def set_validlifetime(self, valor):
        self.__validlifetime = valor

    def set_preferredlifetime(self, valor):
        self.__preferredlifetime = valor

    def set_intervalo(self, valor):
        self.__intervalo = valor

    def set_flag_chlim(self, valor):
        self.__flag_chlim = valor

    def get_flag_chlim(self):
        return int(self.__flag_chlim)

    def get_flag_L(self):
        return int(self.__flag_L)

    def get_flag_A(self):
        return int(self.__flag_A)

    def get_flag_R(self):
        return int(self.__flag_R)

    def get_validlifetime(self):
        return int(self.__validlifetime)

    def get_preferredlifetime(self):
        return int(self.__preferredlifetime)

    def get_interval(self):
        return int(self.__intervalo)

    def get_routerlifetime(self):
        return int(self.__routerlifetime)

    def set_ipv6_dst(self, valor):
        self.__ipv6_dst = valor

    def get_ipv6_dst(self):
        return self.__ipv6_dst

    def set_ipv6_src(self, valor):
        self.__ipv6_src = valor

    def get_ipv6_src(self):
        return self.__ipv6_src

    def set_ether_dst(self, valor):
        self.__ether_dst = valor

    def get_ether_dst(self):
        return self.__ether_dst

    def set_ether_src(self, valor):
        self.__ether_src = valor

    def get_ether_src(self):
        return self.__ether_src

    def set_local_addr_ceRouter(self, valor):
        self.__local_addr_ceRouter = valor

    def get_local_addr_ceRouter(self):
        return self.__local_addr_ceRouter

    def get_global_addr_ceRouter(self):
        return self.__global_addr_ceRouter

    def set_tgt(self, valor):
        self.__tgt = valor

    def get_tgt(self):
        return self.__tgt

    def set_xid(self, valor):
        self.__xid = valor

    def get_xid(self):
        return self.__xid

    def set_client_duid(self, valor):
        self.__client_duid = valor

    def get_recvd_dhcp_rdnss(self):
        return self.__recvd_dhcp_rdnss

    def get_recvd_dhcp_srcladdr(self):
        return self.__recvd_dhcp_srcladdr

    def get_client_duid(self):
        return self.__client_duid

    def set_server_duid(self, valor):
        self.__server_duid = valor

    def get_server_duid(self):
        return self.__server_duid

    def set_iaid(self, valor):
        self.__iaid = valor

    def get_iaid(self):
        return int(self.__iaid, 16)

    def get_local_ping(self):
        return self.__local_ping_OK

    def get_ND_local_OK(self):
        return self.__ND_local_OK

    def get_ND_global_OK(self):
        return self.__ND_global_OK

    def get_global_ping_OK(self):
        return self.__ping_global

    def get_dhcp_reconf_type(self):
        return self.__dhcp_reconf_type

    def set_dhcp_reconf_type(self, valor):
        self.__dhcp_reconf_type = valor

    def set_mac_ceRouter(self, valor):
        self.__mac_cerouter = valor

    def get_mac_ceRouter(self):
        return self.__mac_cerouter

    def get_global_mac_ceRouter(self):
        return self.__global_mac_cerouter

    def get_disapproved(self):
        return self.__disapproved

    def get_lla(self):
        return self.__lla

    def set_lla(self, valor):
        self.__lla = valor

    def set_setup_lan_start(self):
        self.__setup_lan_start = True

    def run_setup1_1(self, pkt):

        if not self.__setup_lan_start:
            return
        if self.__disapproved:
            return False
        if pkt[Ether].src == self.__config.get('lan', 'mac_address'):
            return
        if pkt[Ether].src == self.__config.get('lan', 'mac'):
            return
        if self.__disapproved:
            return False

        if not pkt.haslayer(ICMPv6NDOptPrefixInfo):
            pass

        if pkt.haslayer(ICMPv6EchoReply):
            if pkt[IPv6].src == self.__global_addr_ceRouter:
                self.__ping_global = True

        if pkt.haslayer(ICMPv6ND_NS):

            prefix = pkt[ICMPv6ND_NS].tgt
            if prefix[:4] == 'fe80':
                self.__local_addr_ceRouter = (pkt[ICMPv6ND_NS].tgt)
                self.__mac_cerouter = (pkt[Ether].src)
                self.__ND_local_OK = True

            if prefix[:4] == (self.__config.get('wan', 'global_wan_addr'))[:4]:

                if prefix != self.__config.get('lan', 'global_wan_addr'):
                    self.__global_addr_ceRouter = (pkt[ICMPv6ND_NS].tgt)
                    self.__global_mac_cerouter = (pkt[Ether].src)
                    self.__ND_global_OK = True

            if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                    'lan', 'global_wan_addr'):
                self.set_ipv6_src(self.__config.get('lan', 'global_wan_addr'))
                self.set_ether_src(self.__config.get('lan', 'mac_address'))
                self.set_ether_dst(pkt[Ether].src)
                self.set_ipv6_dst(pkt[IPv6].src)
                self.set_tgt(self.__config.get('lan', 'global_wan_addr'))
                self.set_lla(self.__config.get('lan', 'mac_address'))
                self.__sendmsgssetup1_1.send_icmp_na_lan(self)

        if pkt.haslayer(ICMPv6ND_RA):
            self.__routerlifetime_CeRouter = pkt[ICMPv6ND_RA].routerlifetime
            if pkt.haslayer(ICMPv6NDOptPrefixInfo):
                self.__prefixaddr_CeRouter = pkt[ICMPv6NDOptPrefixInfo].prefix
                self.__l_CeRouter = pkt[ICMPv6NDOptPrefixInfo].L
                self.__A_CeRouter = pkt[ICMPv6NDOptPrefixInfo].A
                self.__R_CeRouter = pkt[ICMPv6NDOptPrefixInfo].R
                self.__validlifetime_CeRouter = pkt[
                    ICMPv6NDOptPrefixInfo].validlifetime
                self.__preferredlifetime_CeRouter = pkt[
                    ICMPv6NDOptPrefixInfo].preferredlifetime
                self.__prefixlen_CeRouter = pkt[
                    ICMPv6NDOptPrefixInfo].prefixlen
                self.send_solicit = True
                self.__setup1_1_OK = True
                #return
            print('CHegou RA na LAN')
            if pkt.haslayer(ICMPv6NDOptRouteInfo):
                self.__r_prefixaddr_CeRouter = pkt[ICMPv6NDOptRouteInfo].prefix
                self.__r_plen_CeRouter = pkt[ICMPv6NDOptRouteInfo].plen
                self.__r_prf_CeRouter = pkt[ICMPv6NDOptRouteInfo].prf
                self.__r_rtlifetime_CeRouter = pkt[
                    ICMPv6NDOptRouteInfo].rtlifetime

            if pkt.haslayer(ICMPv6NDOptRDNSS):
                self.__rdnss_dns_CeRouter = pkt[ICMPv6NDOptRDNSS].dns
                self.__rdnss_lifetime_CeRouter = pkt[ICMPv6NDOptRDNSS].lifetime
                self.__recvd_dhcp_rdnss = True

            if pkt.haslayer(ICMPv6NDOptDNSSL):
                self.__domainname = pkt[ICMPv6NDOptDNSSL].searchlist
                self.__domainname_lifetime_CeRouter = pkt[
                    ICMPv6NDOptDNSSL].lifetime
                self.__recvd_dhcp_srcladdr = True

            if pkt.haslayer(ICMPv6NDOptSrcLLAddr):
                self.__linklayer_CeRouter = pkt[ICMPv6NDOptSrcLLAddr].lladdr
コード例 #11
0
class Test276:
    def __init__(self, config, app):
        self.__app = app
        self.__queue_wan = Queue()
        self.__queue_lan = Queue()
        self.__config = config
        self.__interface = None
        self.__pkt = None
        self.__local_addr_ceRouter = None
        self.__sendmsgs = SendMsgs(self.__config)
        self.__config_setup1_1 = ConfigSetup1_1(self.__config)
        #self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config)
        self.__wan_device_tr1 = self.__config.get('wan', 'device_wan_tr1')
        self.__lan_device = self.__config.get('lan', 'lan_device')
        self.__wan_mac_tr1 = self.__config.get('wan', 'wan_mac_tr1')
        self.__link_local_addr = self.__config.get('wan', 'link_local_addr')
        self.__all_nodes_addr = self.__config.get('multicast',
                                                  'all_nodes_addr')
        self.__test_desc = self.__config.get('tests', '2.7.6')
        self.__t_lan = None
        self.__finish_wan = False
        self.__dhcp_renew_done = False
        self.msg = self.__config.get('tests', '2.7.6')
        self.msg_lan = self.__config.get('tests', '2.7.6')
        self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config,
                                                     self.__lan_device)

    def set_flags(self):
        self.__config_setup1_1.set_flag_M(self.__config.get(
            't2.7.6', 'flag_m'))
        self.__config_setup1_1.set_flag_0(self.__config.get(
            't2.7.6', 'flag_o'))
        self.__config_setup1_1.set_flag_chlim(
            self.__config.get('t2.7.6', 'flag_chlim'))
        self.__config_setup1_1.set_flag_L(self.__config.get(
            't2.7.6', 'flag_l'))
        self.__config_setup1_1.set_flag_A(self.__config.get(
            't2.7.6', 'flag_a'))
        self.__config_setup1_1.set_flag_R(self.__config.get(
            't2.7.6', 'flag_r'))
        self.__config_setup1_1.set_flag_prf(
            self.__config.get('t2.7.6', 'flag_prf'))
        self.__config_setup1_1.set_validlifetime(
            self.__config.get('t2.7.6', 'validlifetime'))
        self.__config_setup1_1.set_preferredlifetime(
            self.__config.get('t2.7.6', 'preferredlifetime'))
        self.__config_setup1_1.set_routerlifetime(
            self.__config.get('t2.7.6', 'routerlifetime'))
        self.__config_setup1_1.set_intervalo(
            self.__config.get('t1.6.6b', 'intervalo'))
        self.__config_setup1_1.set_prefix_addr(
            self.__config.get('setup1-1_advertise', 'ia_pd_address'))
        self.__config_setup1_1.set_dhcp_t1(
            self.__config.get('t2.7.6', 'dhcp_t1'))
        self.__config_setup1_1.set_dhcp_t2(
            self.__config.get('t2.7.6', 'dhcp_t2'))
        self.__config_setup1_1.set_dhcp_preflft(
            self.__config.get('t2.7.6', 'dhcp_preflft'))
        self.__config_setup1_1.set_dhcp_validlft(
            self.__config.get('t2.7.6', 'dhcp_validlft'))
        self.__config_setup1_1.set_dhcp_plen(
            self.__config.get('t2.7.6', 'dhcp_plen'))

    def set_flags_lan(self):
        self.__config_setup_lan.set_elapsetime(
            self.__config.get('solicitlan', 'elapsetime'))
        self.__config_setup_lan.set_xid(self.__config.get('solicitlan', 'xid'))
        self.__config_setup_lan.set_fdqn(
            self.__config.get('solicitlan', 'clientfqdn'))
        self.__config_setup_lan.set_vendor_class(
            self.__config.get('solicitlan', 'vendorclass'))

        self.__config_setup_lan.set_enterprise(
            self.__config.get('solicitlan', 'enterpriseid'))
        self.__config_setup_lan.set_client_duid(
            self.__config.get('solicitlan', 'duid'))
        self.__config_setup_lan.set_iaid(
            self.__config.get('solicitlan', 'iaid'))

    def set_status_lan(self, v):
        self.msg_lan = v

    def get_status_lan(self):
        return self.msg_lan

    def set_status(self, v):
        self.msg = v

    def get_status(self):
        return self.msg

    def rs_lan(self):

        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'lan_local_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(
            self.__config.get('multicast', 'all_mac_routers'))
        self.__config_setup_lan.set_ipv6_dst(
            self.__config.get('general', 'all_routers_address'))
        self.__config_setup_lan.set_lla(self.__config.get(
            'lan', 'mac_address'))
        self.__sendmsgs.send_icmp_rs(self.__config_setup_lan)

    def echo_request_lan(self):
        #print('ENVIO REQUEST 1 LAN')

        mac_global = self.__config_setup_lan.get_global_mac_ceRouter()
        ip_global = self.__config_setup_lan.get_global_addr_ceRouter()
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'global_wan_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(mac_global)
        self.__config_setup_lan.set_ipv6_dst(ip_global)
        self.__sendmsgs.send_echo_request_lan(self.__config_setup_lan)

    def echo_request_lan_wrong_prefix(self):
        #print('ENVIO REQUEST 1 LAN')
        mac_global = self.__config_setup_lan.get_global_mac_ceRouter()
        ip_global = self.__config_setup_lan.get_global_addr_ceRouter()
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('t2.7.6', 'source_to_ping_tn1'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(mac_global)
        self.__config_setup_lan.set_ipv6_dst(
            self.__config.get('wan', 'global_wan_addr'))
        self.__sendmsgs.send_echo_request_lan(self.__config_setup_lan)

    def icmp_na_wrong_prefix(self):
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'global_wan_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(
            self.__config_setup_lan.get_global_mac_ceRouter())
        self.__config_setup_lan.set_ipv6_dst(
            self.__config_setup_lan.get_global_addr_ceRouter())
        self.__config_setup_lan.set_tgt(
            self.__config.get('t2.7.6', 'source_to_ping_tn1'))
        self.__config_setup_lan.set_lla(self.__config.get(
            'lan', 'mac_address'))
        self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)

    def dhcp_information_lan(self):
        #self.__config_setup_lan.set_setup_lan_start()
        #print('#print ENVIO INFORMATION LAN')
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'lan_local_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(
            self.__config.get('multicast', 'all_mac_routers'))
        self.__config_setup_lan.set_ipv6_dst(
            self.__config.get('multicast', 'all_routers_addr'))
        self.__config_setup_lan.set_xid(
            self.__config.get('informationlan', 'xid'))
        #self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_elapsetime(
            self.__config.get('informationlan', 'elapsetime'))
        self.__config_setup_lan.set_vendor_class(
            self.__config.get('informationlan', 'vendorclass'))
        self.__sendmsgs.send_dhcp_information(self.__config_setup_lan)

    def ra_wan(self):
        self.__config_setup1_1.set_ether_src(self.__config.get(
            'wan', 'ra_mac'))
        self.__config_setup1_1.set_ether_dst(
            self.__config.get('multicast', 'all_mac_nodes'))
        self.__config_setup1_1.set_ipv6_src(
            self.__config.get('wan', 'ra_address'))
        self.__config_setup1_1.set_ipv6_dst(
            self.__config.get('multicast', 'all_nodes_addr'))
        self.__sendmsgs.send_tr1_RA(self.__config_setup1_1)

    def run_Lan(self):
        @self.__app.route("/LAN", methods=['GET'])
        def envia_lan():
            return self.get_status_lan()

        #self.__config_setup_lan_.flags_partA()
        logging.info('Thread da LAN inicio')
        t_test = 0
        t_test1 = 0
        sent_reconfigure = False
        time_over = False
        send_ra = False
        send_na_lan = False
        self.set_flags_lan()
        self.__config_setup_lan.set_setup_lan_start()
        cache_lan = []
        temporizador_lan = 0
        test_max_time_lan = 300
        temporizador_ping = 0
        while not self.__queue_lan.full():
            while self.__queue_lan.empty():

                time.sleep(1)
                temporizador_ping = temporizador_ping + 1
                if self.__config_setup1_1.get_setup1_1_OK():
                    time.sleep(1)
                    if temporizador_lan < test_max_time_lan:
                        temporizador_lan = temporizador_lan + 1
                    else:
                        self.set_status_lan('LAN: Reprovado. Timeout')
                        time.sleep(2)
                        self.set_status_lan('REPROVADO')
                        logging.info('LAN: Reprovado. Timeout')
                        #logging.info(routerlifetime)
                        self.__packet_sniffer_lan.stop()
                        self.__finish_wan = True
                        self.__fail = True
                        return False
                    if temporizador_lan % 20 == 0:
                        logging.info('LAN: Tempo limite do teste: ' +
                                     str(test_max_time_lan) +
                                     ' segundos. Tempo: ' +
                                     str(temporizador_lan))
                        self.set_status_lan('LAN: Tempo limite do teste: ' +
                                            str(test_max_time_lan) +
                                            ' segundos. Tempo: ' +
                                            str(temporizador_lan))

                    if temporizador_lan % 5 == 0:
                        self.set_status_lan(
                            'LAN: Transmissão periódica de ICMP RS e DHCP information'
                        )
                        logging.info(
                            'LAN: Transmissão periódica de ICMP RS e DHCP information'
                        )
                        self.rs_lan()
                        self.dhcp_information_lan()

                        if self.__config_setup_lan.get_ND_global_OK(
                        ) and not self.__config_setup_lan.get_global_ping_OK():
                            self.set_status_lan(
                                'LAN: Transmissão Echo Request IP global do roteador'
                            )
                            logging.info(
                                'LAN: Transmissão Echo Request IP global do roteador'
                            )
                            self.echo_request_lan()

            pkt = self.__queue_lan.get()

            cache_lan.append(pkt)
            wrpcap("lan-2.7.6.cap", cache_lan)

            if not self.__config_setup_lan.get_global_ping_OK():

                if not self.__config_setup_lan.get_disapproved():
                    self.__config_setup_lan.run_setup1_1(pkt)
                else:
                    logging.info(
                        'LAN: Reprovado Teste 2.7.6 - Falha em completar o setup 1.1'
                    )
                    self.set_status_lan(
                        'Reprovado Teste 2.7.6 - Falha em completar o setup 1.1'
                    )
                    time.sleep(2)
                    self.set_status_lan(
                        'REPROVADO'
                    )  # Mensagem padrão para o frontEnd atualizar Status

                    self.__packet_sniffer_lan.stop()
                    self.__finish_wan = True
                    self.__fail = True
                    return False
            else:
                temporizador_ping = temporizador_ping + 1

                if temporizador_ping % 5 == 0:

                    print(temporizador_ping)

                    self.set_status_lan(
                        'LAN: Transmissão Echo Request IP global  com prefix origem incorreto'
                    )
                    logging.info(
                        'LAN: Transmissão Echo Request IP global  com prefix origem incorreto'
                    )
                    self.echo_request_lan_wrong_prefix()

                if pkt[Ether].src == self.__config.get('lan', 'mac_address'):

                    continue

                if pkt.haslayer(ICMPv6ND_NS):
                    print('aqui3')
                    if pkt[ICMPv6ND_NS].tgt == self.__config.get(
                            't2.7.6', 'source_to_ping_tn1'):

                        self.set_status_lan(
                            'LAN: Transmissão ICMP NA IP global com prefix origem  nao atribuido'
                        )
                        logging.info(
                            'LAN: Transmissão ICMP NA IP global com prefix origem  nao atribuido'
                        )
                        self.icmp_na_wrong_prefix()

                if pkt.haslayer(ICMPv6DestUnreach):
                    self.set_status(
                        'Teste 2.7.6- Pacote não foi encaminhado para WAN e CeRouter respondeu ao TN2 com Destino inalcançavel'
                    )
                    time.sleep(2)
                    self.set_status(
                        'APROVADO'
                    )  # Mensagem padrão para o frontEnd atualizar Status
                    logging.info(
                        'Teste 2.7.6- Pacote não foi encaminhado para WAN e CeRouter respondeu ao TN2 com Destino inalcançavel'
                    )

                    self.__packet_sniffer_lan.stop()
                    self.__finish_wan = True
                    self.__fail_test = False
                    return True

                if pkt.haslayer(ICMPv6EchoReply):
                    logging.info(
                        'LAN: Reprovado Teste 2.7.6 - Recebido Echo Reply de Echo Request com prefixo origem nao atribuido'
                    )
                    self.set_status_lan(
                        'LAN: Reprovado Teste 2.7.6 - Recebido Echo Reply de Echo Request com prefixo origem nao atribuido'
                    )
                    time.sleep(2)
                    self.set_status_lan(
                        'REPROVADO'
                    )  # Mensagem padrão para o frontEnd atualizar Status

                    self.__packet_sniffer_lan.stop()
                    self.__finish_wan = True
                    self.__fail = True
                    return False

    def run(self):
        @self.__app.route("/WAN", methods=['GET'])
        def enviawan():
            return self.get_status()

        self.__t_lan = Thread(target=self.run_Lan, name='LAN_Thread')
        self.__t_lan.start()

        self.__packet_sniffer_wan = PacketSniffer('Test273b-WAN',
                                                  self.__queue_wan, self,
                                                  self.__config,
                                                  self.__wan_device_tr1)
        self.__packet_sniffer_wan.start()

        self.__packet_sniffer_lan = PacketSniffer('Test273b-LAN',
                                                  self.__queue_lan, self,
                                                  self.__config,
                                                  self.__lan_device)
        test_lan = self.__packet_sniffer_lan.start()
        cache_wan = []
        self.set_flags()
        logging.info(self.__test_desc)
        t_test = 0
        sent_reconfigure = False
        time_over = False
        #time.sleep(11111)
        finish_wan = True
        test_max_time = 300
        temporizador = 0
        self.__config_setup1_1.set_pd_prefixlen(
            self.__config.get('t2.7.6', 'pd_prefixlen'))
        self.__config_setup1_1.set_routerlifetime(
            self.__config.get('t2.7.6', 'routerlifetime'))
        #self.__config_setup1_1.active_DHCP_no_IA_PD()
        while not self.__queue_wan.full():
            while self.__queue_wan.empty():
                time.sleep(1)
                if temporizador < test_max_time:
                    temporizador = temporizador + 1
                else:
                    self.set_status('WAN: Reprovado. Timeout')
                    time.sleep(2)
                    self.set_status('REPROVADO')
                    logging.info('WAN: Reprovado. Timeout')
                    #logging.info(routerlifetime)
                    self.__packet_sniffer_lan.stop()
                    self.__packet_sniffer_wan.stop()
                    return False

                if temporizador % 20 == 0:
                    logging.info('WAN: Tempo limite do teste: ' +
                                 str(test_max_time) + ' segundos. Tempo: ' +
                                 str(temporizador))
                    self.set_status('WAN: Tempo limite do teste: ' +
                                    str(test_max_time) + ' segundos. Tempo: ' +
                                    str(temporizador))

                if temporizador < test_max_time:
                    if temporizador % 15 == 0:
                        self.ra_wan()

            pkt = self.__queue_wan.get()

            cache_wan.append(pkt)
            wrpcap("WAN-2.7.6.cap", cache_wan)

            if not self.__config_setup1_1.get_setup1_1_OK():
                self.set_status('WAN: Setup 1.1 em execução')
                logging.info('WAN: Setup 1.1 em execução')
                if not self.__config_setup1_1.get_disapproved():
                    self.__config_setup1_1.run_setup1_1(pkt)
                else:
                    logging.info(
                        'LAN: Reprovado Teste 2.7.6 - Falha em completar o setup 1.1'
                    )
                    self.set_status_lan(
                        'Reprovado Teste 2.7.6 - Falha em completar o setup 1.1'
                    )
                    time.sleep(2)
                    self.set_status_lan(
                        'REPROVADO'
                    )  # Mensagem padrão para o frontEnd atualizar Status
                    self.__packet_sniffer_lan.stop()
                    self.__finish_wan = True
                    self.__fail_test = True
                    return False

            else:
                if pkt.haslayer(ICMPv6EchoRequest):
                    self.__packet_sniffer_wan.stop()

                    self.set_status(
                        'Teste 2.7.6 - REPROVADO: Pacote ICMP Request com prefixo invalido foi encaminhado pelo roteador da LAN para WAN'
                    )
                    time.sleep(2)
                    self.set_status(
                        'REPROVADO'
                    )  # Mensagem padrão para o frontEnd atualizar Status
                    logging.info(
                        'Teste 2.7.6 - REPROVADO: Pacote ICMP Request com prefixo invalido foi encaminhado pelo roteador da LAN para WAN'
                    )

                    return False
                if self.__finish_wan:
                    self.__packet_sniffer_wan.stop()
                    if self.__fail_test:
                        return False
                    else:
                        return True
        self.__packet_sniffer_wan.stop()
        return False
コード例 #12
0
class Test277a:
    def __init__(self, config, app):
        self.__app = app
        self.__queue_wan = Queue()
        self.__queue_lan = Queue()
        self.__config = config
        self.__interface = None
        self.__pkt = None
        self.__local_addr_ceRouter = None
        self.__sendmsgs = SendMsgs(self.__config)
        self.__config_setup1_1 = ConfigSetup1_1(self.__config)
        #self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config)
        self.__wan_device_tr1 = self.__config.get('wan', 'device_wan_tr1')
        self.__lan_device = self.__config.get('lan', 'lan_device')
        self.__wan_mac_tr1 = self.__config.get('wan', 'wan_mac_tr1')
        self.__link_local_addr = self.__config.get('wan', 'link_local_addr')
        self.__all_nodes_addr = self.__config.get('multicast',
                                                  'all_nodes_addr')
        self.__test_desc = self.__config.get('tests', '2.7.7a')
        self.__t_lan = None
        self.__finish_wan = False
        self.__dhcp_renew_done = False
        self.msg = self.__config.get('tests', '2.7.7a')
        self.msg_lan = self.__config.get('tests', '2.7.7a')
        self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config,
                                                     self.__lan_device)

    def set_flags(self):
        self.__config_setup1_1.set_flag_M(
            self.__config.get('t1.6.6b', 'flag_m'))
        self.__config_setup1_1.set_flag_0(
            self.__config.get('t1.6.6b', 'flag_o'))
        self.__config_setup1_1.set_flag_chlim(
            self.__config.get('t1.6.6b', 'flag_chlim'))
        self.__config_setup1_1.set_flag_L(
            self.__config.get('t1.6.6b', 'flag_l'))
        self.__config_setup1_1.set_flag_A(
            self.__config.get('t1.6.6b', 'flag_a'))
        self.__config_setup1_1.set_flag_R(
            self.__config.get('t1.6.6b', 'flag_r'))
        self.__config_setup1_1.set_flag_prf(
            self.__config.get('t1.6.6b', 'flag_prf'))
        self.__config_setup1_1.set_validlifetime(
            self.__config.get('t2.7.7a', 'validlifetime'))
        self.__config_setup1_1.set_preferredlifetime(
            self.__config.get('t2.7.7a', 'preferredlifetime'))
        self.__config_setup1_1.set_routerlifetime(
            self.__config.get('t2.7.7a', 'routerlifetime'))
        self.__config_setup1_1.set_intervalo(
            self.__config.get('t1.6.6b', 'intervalo'))
        self.__config_setup1_1.set_prefix_addr(
            self.__config.get('setup1-1_advertise', 'ia_pd_address'))
        self.__config_setup1_1.set_dhcp_t1(
            self.__config.get('t2.7.7a', 'dhcp_t1'))
        self.__config_setup1_1.set_dhcp_t2(
            self.__config.get('t2.7.7a', 'dhcp_t2'))
        self.__config_setup1_1.set_dhcp_preflft(
            self.__config.get('t2.7.7a', 'dhcp_preflft'))
        self.__config_setup1_1.set_dhcp_validlft(
            self.__config.get('t2.7.7a', 'dhcp_validlft'))
        self.__config_setup1_1.set_dhcp_plen(
            self.__config.get('t2.7.7a', 'dhcp_plen'))

    def set_flags_lan(self):
        self.__config_setup_lan.set_elapsetime(
            self.__config.get('solicitlan', 'elapsetime'))
        self.__config_setup_lan.set_xid(self.__config.get('solicitlan', 'xid'))
        self.__config_setup_lan.set_fdqn(
            self.__config.get('solicitlan', 'clientfqdn'))
        self.__config_setup_lan.set_vendor_class(
            self.__config.get('solicitlan', 'vendorclass'))

        self.__config_setup_lan.set_enterprise(
            self.__config.get('solicitlan', 'enterpriseid'))
        self.__config_setup_lan.set_client_duid(
            self.__config.get('solicitlan', 'duid'))
        self.__config_setup_lan.set_iaid(
            self.__config.get('solicitlan', 'iaid'))

    def set_status_lan(self, v):
        self.msg_lan = v

    def get_status_lan(self):
        return self.msg_lan

    def set_status(self, v):
        self.msg = v

    def get_status(self):
        return self.msg

    def dhcp_information_lan(self):
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'lan_local_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst('33:33:00:01:00:02')
        self.__config_setup_lan.set_ipv6_dst(
            self.__config.get('multicast', 'all_routers_addr'))
        self.__config_setup_lan.set_xid(
            self.__config.get('informationlan', 'xid'))
        self.__config_setup_lan.set_elapsetime(
            self.__config.get('informationlan', 'elapsetime'))
        self.__config_setup_lan.set_vendor_class(
            self.__config.get('informationlan', 'vendorclass'))
        self.__sendmsgs.send_dhcp_information(self.__config_setup_lan)

    def icmp_rs_lan(self):
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'lan_local_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(
            self.__config.get('multicast', 'all_mac_routers'))
        self.__config_setup_lan.set_ipv6_dst(
            self.__config.get('general', 'all_routers_address'))
        self.__config_setup_lan.set_lla(self.__config.get(
            'lan', 'mac_address'))
        self.__sendmsgs.send_icmp_rs(self.__config_setup_lan)

    def icmp_na_global_lan(self, pkt):
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'global_wan_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
        self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup_lan.set_tgt(
            self.__config.get('lan', 'global_wan_addr'))
        self.__config_setup_lan.set_lla(self.__config.get(
            'lan', 'mac_address'))
        self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)

    def icmp_na_local_lan(self, pkt):
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'lan_local_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
        self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup_lan.set_tgt(
            self.__config.get('lan', 'lan_local_addr'))
        self.__config_setup_lan.set_lla(self.__config.get(
            'lan', 'mac_address'))
        self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)

    def echo_request_lan(self):
        #print('ENVIO REQUEST 1 LAN')

        mac_global = self.__config_setup_lan.get_global_mac_ceRouter()
        ip_global = self.__config_setup_lan.get_global_addr_ceRouter()
        self.__config_setup_lan.set_ipv6_src(
            self.__config.get('lan', 'global_wan_addr'))
        self.__config_setup_lan.set_ether_src(
            self.__config.get('lan', 'mac_address'))
        self.__config_setup_lan.set_ether_dst(mac_global)
        self.__config_setup_lan.set_ipv6_dst(ip_global)
        self.__sendmsgs.send_echo_request_lan(self.__config_setup_lan)

    def ra_wan(self):
        self.__config_setup1_1.set_ether_src(self.__config.get(
            'wan', 'ra_mac'))
        self.__config_setup1_1.set_ether_dst(
            self.__config.get('multicast', 'all_mac_nodes'))
        self.__config_setup1_1.set_ipv6_src(
            self.__config.get('wan', 'ra_address'))
        self.__config_setup1_1.set_ipv6_dst(
            self.__config.get('multicast', 'all_nodes_addr'))
        self.__sendmsgs.send_tr1_RA(self.__config_setup1_1)

    def run_Lan(self):
        @self.__app.route("/LAN", methods=['GET'])
        def envia_lan():
            return self.get_status_lan()

        #self.__config_setup_lan_.flags_partA()

        t_test = 0
        t_test1 = 0
        sent_reconfigure = False
        time_over = False
        send_ra = False
        send_na_lan = False
        self.set_flags_lan()
        self.__config_setup_lan.set_setup_lan_start()
        temporizador_lan = 0
        test_max_time_lan = 250
        cache_lan = []
        while not self.__queue_lan.full():
            while self.__queue_lan.empty():
                if self.__config_setup1_1.get_setup1_1_OK():
                    time.sleep(1)
                    if temporizador_lan < test_max_time_lan:
                        temporizador_lan = temporizador_lan + 1
                    else:
                        self.set_status_lan('LAN: Reprovado. Timeout')
                        time.sleep(2)
                        self.set_status_lan('REPROVADO')
                        logging.info('LAN: Reprovado. Timeout')
                        #logging.info(routerlifetime)
                        self.__packet_sniffer_lan.stop()
                        self.__packet_sniffer_wan.stop()
                        return False
                    if temporizador_lan % 20 == 0:
                        logging.info('LAN: Tempo limite do teste: ' +
                                     str(test_max_time_lan) +
                                     ' segundos. Tempo: ' +
                                     str(temporizador_lan))
                        self.set_status_lan('LAN: Tempo limite do teste: ' +
                                            str(test_max_time_lan) +
                                            ' segundos. Tempo: ' +
                                            str(temporizador_lan))

                        if temporizador_lan % 5 == 0:
                            self.set_status_lan(
                                'LAN: Transmissão periódica de ICMP RS e DHCP information'
                            )
                            logging.info(
                                'LAN: Transmissão periódica de ICMP RS e DHCP information'
                            )
                            self.icmp_rs_lan()
                            self.dhcp_information_lan()

                            if self.__config_setup_lan.get_ND_global_OK(
                            ) and not self.__config_setup_lan.get_global_ping_OK(
                            ):
                                self.set_status_lan(
                                    'LAN: Transmissão Echo Request IP global do roteador'
                                )
                                logging.info(
                                    'LAN: Transmissão Echo Request IP global do roteador'
                                )
                                self.echo_request_lan()

            pkt = self.__queue_lan.get()

            cache_lan.append(pkt)
            wrpcap("lan-2.7.7a.cap", cache_lan)

            if not self.__config_setup_lan.get_global_ping_OK():
                self.set_status_lan('LAN: Setup LAN em execução')
                logging.info('LAN: Setup LAN em execução')
                if not self.__config_setup_lan.get_disapproved():
                    self.__config_setup_lan.run_setup1_1(pkt)
                else:
                    logging.info(
                        'LAN: Reprovado Teste 2.7.7a - Falha em completar o setup 1.1'
                    )
                    self.set_status_lan(
                        'Reprovado Teste 2.7.7a - Falha em completar o setup 1.1'
                    )
                    self.__packet_sniffer_lan.stop()
                    self.__finish_wan = True
                    return False
            else:
                logging.info(
                    '=========================================================================='
                )
                logging.info(
                    'IMPORTANTE. ATIVE a ULA no roteador com o prefixo ' +
                    self.__config.get('t2.7.7a', 'prefix_ula'))
                logging.info(
                    '=========================================================================='
                )
                time.sleep(30)

                if pkt.haslayer(ICMPv6ND_RA):
                    self.__routerlifetime_CeRouter = pkt[
                        ICMPv6ND_RA].routerlifetime
                    if pkt.haslayer(ICMPv6NDOptPrefixInfo):
                        self.set_status_lan(
                            'LAN: RA recebido. Validando o Prefixo ULA')
                        logging.info(
                            'LAN: RA recebido. Validando o Prefixo ULA')
                        self.__prefixaddr_ula_CeRouter = pkt[
                            ICMPv6NDOptPrefixInfo].prefix
                        if self.__prefixaddr_ula_CeRouter == self.__config.get(
                                't2.7.7a', 'prefix_ula'):
                            logging.info(
                                ' Teste 2.7.7a: APROVADO: Recebido o prefix ULA previsto.'
                            )
                            self.set_status_lan(
                                'Teste 2.7.7a - APROVADO. Recebido o prefix ULA esperado.'
                            )
                            time.sleep(2)
                            self.set_status_lan(
                                'APROVADO'
                            )  # Mensagem padrão para o frontEnd atualizar Status
                            self.__packet_sniffer_lan.stop()
                            self.__finish_wan = True
                            self.__fail_test = False
                            return True
                        else:
                            self.set_status_lan(
                                'Teste 2.7.7a - REPROVADO. Recebido o prefix ULA incorreto.'
                            )
                            time.sleep(2)
                            self.set_status_lan(
                                'REPROVADO'
                            )  # Mensagem padrão para o frontEnd atualizar Status
                            logging.info(
                                'Teste 2.7.7a: REPROVADO. Recebido o prefix ULA incorreto.'
                            )
                            self.__packet_sniffer_lan.stop()
                            self.__finish_wan = True
                            self.__fail_test = True
                            return False

    def run(self):
        @self.__app.route("/WAN", methods=['GET'])
        def enviawan():
            return self.get_status()

        self.__t_lan = Thread(target=self.run_Lan, name='LAN_Thread')
        self.__packet_sniffer_lan = PacketSniffer('Test277a-LAN',
                                                  self.__queue_lan, self,
                                                  self.__config,
                                                  self.__lan_device)
        self.__packet_sniffer_wan = PacketSniffer('Test277a-WAN',
                                                  self.__queue_wan, self,
                                                  self.__config,
                                                  self.__wan_device_tr1)

        self.__t_lan.start()
        self.__packet_sniffer_wan.start()
        self.__packet_sniffer_lan.start()

        self.set_flags()

        logging.info(self.__test_desc)

        logging.info(
            '=========================================================================='
        )
        logging.info(
            'IMPORTANTE. Quando for Solicitado ative na ULA do roteador o prefixo: '
            + self.__config.get('t2.7.7a', 'prefix_ula'))
        logging.info(
            '=========================================================================='
        )

        time.sleep(10)

        t_test = 0
        sent_reconfigure = False
        time_over = False
        finish_wan = True
        cache_wan = []

        temporizador = 0
        test_max_time = 300

        self.__config_setup1_1.set_pd_prefixlen(
            self.__config.get('t2.7.7a', 'pd_prefixlen'))
        self.__config_setup1_1.set_routerlifetime(
            self.__config.get('t2.7.7a', 'routerlifetime'))

        while not self.__queue_wan.full():
            while self.__queue_wan.empty():
                time.sleep(1)
                if temporizador < test_max_time:
                    temporizador = temporizador + 1
                else:
                    self.set_status('WAN: Reprovado. Timeout')
                    time.sleep(2)
                    self.set_status('REPROVADO')
                    logging.info('WAN: Reprovado. Timeout')
                    #logging.info(routerlifetime)
                    self.__packet_sniffer_lan.stop()
                    self.__packet_sniffer_wan.stop()
                    return False

                if temporizador % 20 == 0:
                    logging.info('WAN: Tempo limite do teste: ' +
                                 str(test_max_time) + ' segundos. Tempo: ' +
                                 str(temporizador))
                    self.set_status('WAN: Tempo limite do teste: ' +
                                    str(test_max_time) + ' segundos. Tempo: ' +
                                    str(temporizador))

                if temporizador % 15 == 0:
                    logging.info('WAN: Envio periódico de ICMP RA')
                    self.set_status('WAN: Envio periódico de ICMP RA')
                    self.ra_wan()

            pkt = self.__queue_wan.get()

            cache_wan.append(pkt)
            wrpcap("WAN-2.7.7a.cap", cache_wan)

            if not self.__config_setup1_1.get_setup1_1_OK():
                self.set_status('WAN: Setup 1.1 em execução.')
                logging.info('WAN: Setup 1.1 em execução.')
                if not self.__config_setup1_1.get_disapproved():
                    self.__config_setup1_1.run_setup1_1(pkt)
                else:
                    self.set_status(
                        'Reprovado Teste 2.7.7a - Falha em completar o Common Setup 1.1 da RFC'
                    )
                    logging.info(
                        'Reprovado Teste 2.7.7a - Falha em completar o Common Setup 1.1 da RFC'
                    )
                    self.__packet_sniffer_wan.stop()
                    return False
            else:
                if self.__finish_wan:
                    self.__packet_sniffer_wan.stop()
                    if self.__fail_test:
                        return False
                    else:
                        return True
        self.__packet_sniffer_wan.stop()
        return False
コード例 #13
0
ファイル: test324.py プロジェクト: ronyjah/tcc_ronaldo
class Test324:

    def __init__(self,config,app):
        self.__queue_wan = Queue()
        self.__queue_lan = Queue()
        self.__config = config
        self.__interface = None
        self.__pkt = None
        self.__local_addr_ceRouter =None
        self.__sendmsgs = SendMsgs(self.__config)
        self.__config_setup1_1 = ConfigSetup1_1(self.__config)
        self.__wan_device_tr1 = self.__config.get('wan','device_wan_tr1')
        self.__lan_device = self.__config.get('lan','lan_device')
        self.__wan_mac_tr1 = self.__config.get('wan','wan_mac_tr1')
        self.__link_local_addr = self.__config.get('wan','link_local_addr')
        self.__all_nodes_addr = self.__config.get('multicast','all_nodes_addr')
        self.__test_desc = self.__config.get('tests','3.2.4')
        self.__t_lan = None
        self.__finish_wan = False
        self.part2_lan_start = False
        self.__dhcp_renew_done = False
        self.stop_ping_OK = False
        self.ipsrc = None
        self.__app = app
        self.msg = self.__config.get('tests','3.2.4')
        self.msg_lan =self.__config.get('tests','3.2.4')
        self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config,self.__lan_device)

    def set_flags(self):
        logging.info('WAN: Setup1.1 concluido. Contador de 300 s iniciado afim de concluir o teste')
        self.__config_setup1_1.set_flag_M(self.__config.get('t3.2.4','flag_m'))
        self.__config_setup1_1.set_flag_0(self.__config.get('t3.2.4','flag_o'))
        self.__config_setup1_1.set_flag_chlim(self.__config.get('t3.2.4','flag_chlim'))
        self.__config_setup1_1.set_flag_L(self.__config.get('t3.2.4','flag_l'))
        self.__config_setup1_1.set_flag_A(self.__config.get('t3.2.4','flag_a'))
        self.__config_setup1_1.set_flag_R(self.__config.get('t3.2.4','flag_r'))
        self.__config_setup1_1.set_flag_prf(self.__config.get('t3.2.4','flag_prf'))
        self.__config_setup1_1.set_validlifetime(self.__config.get('t3.2.4','validlifetime'))
        self.__config_setup1_1.set_preferredlifetime(self.__config.get('t3.2.4','preferredlifetime'))
        self.__config_setup1_1.set_routerlifetime(self.__config.get('t3.2.4','routerlifetime'))
        self.__config_setup1_1.set_reachabletime(self.__config.get('t3.2.4','reach_time'))
        self.__config_setup1_1.set_retranstimer(self.__config.get('t3.2.4','retrans_time'))        
        self.__config_setup1_1.set_intervalo(self.__config.get('t1.6.6b','intervalo'))
        self.__config_setup1_1.set_prefix_addr(self.__config.get('setup1-1_advertise','ia_pd_address'))
        self.__config_setup1_1.set_dhcp_t1(self.__config.get('t3.2.4','dhcp_t1'))
        self.__config_setup1_1.set_dhcp_t2(self.__config.get('t3.2.4','dhcp_t2'))
        self.__config_setup1_1.set_dhcp_preflft(self.__config.get('t3.2.4','dhcp_preflft'))
        self.__config_setup1_1.set_dhcp_validlft(self.__config.get('t3.2.4','dhcp_validlft'))
        self.__config_setup1_1.set_dhcp_plen(self.__config.get('t3.2.4','dhcp_plen'))
   
    def set_flags_lan(self):
        self.__config_setup_lan.set_elapsetime(self.__config.get('solicitlan','elapsetime'))
        self.__config_setup_lan.set_xid(self.__config.get('solicitlan','xid'))
        self.__config_setup_lan.set_fdqn(self.__config.get('solicitlan','clientfqdn'))
        self.__config_setup_lan.set_vendor_class(self.__config.get('solicitlan','vendorclass'))
        self.__config_setup_lan.set_enterprise(self.__config.get('solicitlan','enterpriseid'))
        self.__config_setup_lan.set_client_duid(self.__config.get('solicitlan','duid'))
        self.__config_setup_lan.set_iaid(self.__config.get('solicitlan','iaid'))

    def ping_tn1_ula(self):
        if self.__config_setup1_1.get_mac_ceRouter() != None:
            self.ipsrc = self.__config.get('t3.2.4','prefix_ula') + self.__config.get('t3.2.4','sufix_ula')
            self.__config_setup_lan.set_ipv6_src(self.ipsrc)
            self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac'))
            self.__config_setup_lan.set_ether_dst(self.__config_setup_lan.get_mac_ceRouter())
            self.__config_setup_lan.set_ipv6_dst(self.__config.get('wan','global_wan_addr'))
            self.__sendmsgs.send_echo_request_lan(self.__config_setup_lan)
        
    def send_dhcp_information(self):
        self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_ether_dst('33:33:00:01:00:02')
        self.__config_setup_lan.set_ipv6_dst(self.__config.get('multicast','all_routers_addr'))
        self.__config_setup_lan.set_xid(self.__config.get('informationlan','xid'))
        self.__config_setup_lan.set_elapsetime(self.__config.get('informationlan','elapsetime'))
        self.__config_setup_lan.set_vendor_class(self.__config.get('informationlan','vendorclass'))
        self.__sendmsgs.send_dhcp_information(self.__config_setup_lan)

    def send_rs_lan(self):
        self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_ether_dst(self.__config.get('multicast','all_mac_routers'))
        self.__config_setup_lan.set_ipv6_dst(self.__config.get('general','all_routers_address'))
        self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
        self.__sendmsgs.send_icmp_rs(self.__config_setup_lan)

    def send_global_na_lan(self,pkt):
        self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))
        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
        self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup_lan.set_tgt(self.__config.get('lan','global_wan_addr'))
        self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)

    def send_local_na_lan(self,pkt):
        self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))
        self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
        self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup_lan.set_tgt(self.__config.get('lan','lan_local_addr'))
        self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
        self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)

    def rourter_advertise(self):
        self.__config_setup1_1.set_ether_src(self.__config.get('wan','ra_mac'))
        self.__config_setup1_1.set_ether_dst(self.__config.get('multicast','all_mac_nodes'))
        self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','ra_address'))
        self.__config_setup1_1.set_ipv6_dst(self.__config.get('multicast','all_nodes_addr'))
        self.__sendmsgs.send_tr1_RA2(self.__config_setup1_1)

    def ping(self):
        if self.__config_setup1_1.get_mac_ceRouter() != None:
            self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','global_wan_addr'))
            self.__config_setup1_1.set_ether_src(self.__config.get('wan','wan_mac_tr1'))
            self.__config_setup1_1.set_ether_dst(self.__config_setup1_1.get_mac_ceRouter())
            self.__config_setup1_1.set_ipv6_dst(self.__config.get('t3.2.4','unreachable_ip'))
            self.__sendmsgs.send_echo_request(self.__config_setup1_1)

    def neighbor_advertise_local(self,pkt):
        self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','link_local_addr'))
        self.__config_setup1_1.set_ether_src(self.__config.get('wan','wan_mac_tr1'))
        self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
        self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup1_1.set_tgt(self.__config.get('wan','link_local_addr'))
        self.__config_setup1_1.set_lla(self.__config.get('wan','wan_mac_tr1'))
        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na(self.__config_setup1_1)

    def neighbor_advertise_global(self,pkt):
        self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','global_wan_addr'))
        self.__config_setup1_1.set_ether_src(self.__config.get('wan','wan_mac_tr1'))
        self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
        self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup1_1.set_tgt(self.__config.get('wan','global_wan_addr'))
        self.__config_setup1_1.set_lla(self.__config.get('wan','wan_mac_tr1'))
        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na(self.__config_setup1_1)
    def neighbor_advertise_global_tn3(self,pkt):
        self.__config_setup1_1.set_ipv6_src(self.__config.get('t3.2.4','tn3_ip'))
        self.__config_setup1_1.set_ether_src(self.__config.get('t3.2.4','tn3_mac'))
        self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
        self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
        self.__config_setup1_1.set_tgt(self.__config.get('t3.2.4','tn3_ip'))
        self.__config_setup1_1.set_lla(self.__config.get('t3.2.4','tn3_mac'))
        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
        self.__sendmsgs.send_icmp_na(self.__config_setup1_1)

    def set_status_lan(self,v):
        self.msg_lan = v

    def get_status_lan(self):
        return self.msg_lan

    def run_Lan(self):
        t_test = 0
        t_test1= 0
        time_p = 0
        sent_reconfigure = False
        time_over = False
        send_ra = False
        send_na_lan = False
        reset_test1 = False
        self.set_flags_lan()
        self.__config_setup_lan.set_setup_lan_start()
        cache_lan = []

        @self.__app.route("/LAN",methods=['GET'])
        def envia_lan():
            return self.get_status_lan()

        while not self.__queue_lan.full():
            if self.__queue_lan.empty():
                if t_test < 30:
                    time.sleep(1)
                    t_test = t_test + 1
                    if t_test % 5 ==0:
                        self.set_status_lan('LAN: Transmissões de RS e DHCP information por 30 s a cada 5 seg.')
                        logging.info('LAN: Inicio das transmissões de RS e DHCP information por 30 s.')
                        self.send_dhcp_information()
                        self.send_rs_lan()
                    time.sleep(1)
                else:
                    time_over = True
            else:
                pkt = self.__queue_lan.get()
                cache_lan.append(pkt)
                wrpcap("lan-3.2.4.cap",cache_lan)
                if pkt.haslayer(ICMPv6ND_RA):
                    self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)

                if pkt.haslayer(ICMPv6MLReport2):
                    self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)

                if pkt.haslayer(DHCP6_Reply):
                    self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)

                if pkt[Ether].src == self.__config.get('lan','mac_address'):
                    continue

                if pkt.haslayer(ICMPv6ND_NS):
                    if pkt[ICMPv6ND_NS].tgt == self.__config.get('lan','global_wan_addr'):
                        self.send_global_na_lan(pkt)

                    if pkt[ICMPv6ND_NS].tgt == self.__config.get('lan','lan_local_addr'):
                        self.send_local_na_lan(pkt)
                        
            if self.__config_setup1_1.get_setup1_1_OK():
                self.set_status_lan('LAN: Setup1.1 concluido. Contador de 300 s iniciado afim de concluir o teste')
                logging.info('LAN: Setup1.1 concluido. Contador de 300 s iniciado afim de concluir o teste')
                if pkt[Ether].src == self.__config.get('lan','mac_address'):
                    continue
                if t_test1 < 300:
                    t_test1 = t_test1 + 1
                    if t_test1 % 5 == 0:
                        self.set_status_lan('LAN:Fim do setup 1.1. Enviando ICMPv6 RS')
                        self.send_rs_lan()

                    if pkt.haslayer(ICMPv6ND_RA):
                        if pkt[ICMPv6NDOptPrefixInfo].prefix == self.__config.get('t3.2.4','prefix_ula'):
                                logging.info('LAN: Recebido prefixo esperado. Inciando tentativa de Pingar um endereco Global')
                                self.set_status_lan('LAN: Recebido prefixo esperado. Inciando tentativa de Pingar um endereco Global')
                                time.sleep(2)
                                self.ping_tn1_ula()
                        else:
                            self.__finish_wan = True
                            self.__fail_test = True 
                            self.__packet_sniffer_wan.stop() 
                            self.__packet_sniffer_lan.stop()
                            self.set_status_lan('Teste 3.2.4 - FALHA. VERIFIQUE O PREFIXO ULA CONFIGURADO NO ROTEADOR')
                            time.sleep(2)
                            logging.info('Teste 3.2.4 - FALHA. VERIFIQUE O PREFIXO ULA CONFIGURADO NO ROTEADOR')
                            self.set_status_lan('REPROVADO')

                            print(pkt[ICMPv6NDOptPrefixInfo].prefix)
                            return False   
     
                    if pkt.haslayer(ICMPv6DestUnreach):
                        self.__finish_wan = True
                        self.__fail_test = False
                        #self.__packet_sniffer_wan.stop() 
                        self.__packet_sniffer_lan.stop()
                        self.set_status_lan('APROVADO')
                        logging.info('TEST 3.2.4: UNIQUE LOCAL ADDRESS FORWARDING....APROVADO')
                        return True   

                    if pkt.haslayer(ICMPv6ND_NS):
                        if pkt[ICMPv6ND_NS].tgt == self.__config.get('lan','global_wan_addr'):
                            self.send_global_na_lan(pkt)
                            
                        if pkt[ICMPv6ND_NS].tgt == self.__config.get('lan','lan_local_addr'):
                            self.send_local_na_lan(pkt)

                        if pkt[ICMPv6ND_NS].tgt == self.ipsrc:
                            self.set_status_lan('LAN: Recebido NS target Local: enviando ICMP NA local')
                            self.__config_setup_lan.set_ipv6_src(self.ipsrc)
                            self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))
                            self.__config_setup_lan.set_ether_dst(pkt[Ether].src)
                            self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)
                            self.__config_setup_lan.set_tgt(self.ipsrc)
                            self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))
                            self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)
                            self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)

                else: 
                    self.set_status_lan('Nao foi recebido a mensagem Destino Inalcançável durante a execução do teste')
                    time.sleep(2)
                    self.set_status_lan('REPROVADO')

                    logging.info('TEST 3.2.4: UNIQUE LOCAL ADDRESS FORWARDING....REPROVADO')
                    logging.info('Nao foi recebido a mensagem Destino Inalcançável durante a execução do teste')
                    self.__packet_sniffer_wan.stop() 
                    self.__packet_sniffer_lan.stop()
                    self.__finish_wan = True 
                    self.__fail_test = False
                    return False    

    def set_status(self,v):
        self.msg = v

    def get_status(self):
        return self.msg
    def run(self):
        
        self.set_status('Ative a ULA com prefixo: ' +  self.__config.get('t3.2.4','prefix_ula') + ' . E reinicie o Roteador')

        @self.__app.route("/WAN",methods=['GET'])
        def enviawan():
            return self.get_status()

        logging.info(self.__test_desc)
        logging.info('==================================================================================================')
        logging.info('Ative a ULA com prefixo: ' +  self.__config.get('t3.2.4','prefix_ula') + ' . E reinicie o Roteador') 
        logging.info('===================================================================================================')        
        time.sleep(10)
        self.__t_lan =  Thread(target=self.run_Lan,name='LAN_Thread')
        self.__t_lan.start()
        self.set_status('Thread LAN Criada')
        self.__packet_sniffer_wan = PacketSniffer('Test273b-WAN',self.__queue_wan,self,self.__config,self.__wan_device_tr1)
        self.__packet_sniffer_wan.start()
        self.set_status('Sniffer WAN Inciado')
        self.__packet_sniffer_lan = PacketSniffer('Test273b-LAN',self.__queue_lan,self,self.__config,self.__lan_device)
        self.set_status('Sniffer LAN Inciado')
        test_lan = self.__packet_sniffer_lan.start()
        self.__config_setup1_1.set_ra2()
        self.set_flags()
        logging.info(self.__test_desc)
        t_test = 0
        time1 = 0
        sent_reconfigure = False
        time_over = False
        start_time_count = False
        finish_wan = False
        part1_OK = False
        cache_wan = []
        self.__config_setup1_1.set_pd_prefixlen(self.__config.get('t3.2.4','pd_prefixlen')) 
        self.__config_setup1_1.set_routerlifetime(self.__config.get('t3.2.4','routerlifetime')) 
        self.set_status('WAN: Tráfego Iniciado')
        while not self.__queue_wan.full():
            if self.__queue_wan.empty():
                
                if t_test <= 300:
                    time.sleep(1)
                    t_test = t_test + 1
                    if t_test % 10 == 0:
                        self.set_status('WAN: Transmissão de ICMP RA periódico')
                        logging.info('WAN: Inicio das transmissoes de Router Advertisment')
                        self.rourter_advertise()
                    
                    if start_time_count:
                        self.set_status('Setup 1.1 concluido')
                        logging.info('WAN: Inicio do novo temporizador. Setup 1.1 concluido')
                        if time1 < 600:
                            time1 = time1 + 1

                else:
                    self.__packet_sniffer_wan.stop() 
                    self.__packet_sniffer_lan.stop()
                    self.set_status('Timeout')
                    time.sleep(2)
                    self.set_status('REPROVADO')
                    time_over = True      
            else:
                
                pkt = self.__queue_wan.get()
                cache_wan.append(pkt)
                wrpcap("WAN-3.2.4.cap",cache_wan)
                if not self.__config_setup1_1.get_ND_local_OK():
                    self.set_status('WAN: Setup 1.1 em execução')
                    logging.info('WAN: Inicio do setup 1.1. Pode demorar para concluir')
                    if pkt[Ether].src == self.__config.get('wan','link_local_mac'):
                        continue

                    if pkt[Ether].src == self.__config.get('wan','ra_mac'):
                        continue

                    if pkt.haslayer(ICMPv6ND_RS):
                        self.set_status('WAN: Recebido ICMPv6_RS')
                        if pkt[Ether].src == self.__config.get('wan','link_local_mac'):
                            continue

                        if pkt[Ether].src == self.__config.get('wan','ra_mac'):
                            continue
                        
                        self.__config_setup1_1.set_local_addr_ceRouter(pkt[IPv6].src)
                        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)    

                    if pkt.haslayer(DHCP6_Solicit):
                        self.set_status('WAN: Recebido DHCP6 Solicit')
                        if pkt[Ether].src == self.__config.get('wan','link_local_mac'):
                            continue

                        if pkt[Ether].src == self.__config.get('wan','ra_mac'):
                            continue
                        self.__config_setup1_1.set_local_addr_ceRouter(pkt[IPv6].src)
                        self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)

                if pkt.haslayer(ICMPv6ND_NS):
                    self.set_status('WAN: Recebido ICMPv6 NS')
                    if pkt[ICMPv6ND_NS].tgt == self.__config.get('wan','global_wan_addr'):
                        logging.info('WAN: Solicitado ICMP_NS para um target Global. Enviando NA global do host')
                        self.neighbor_advertise_global(pkt)
                        
                    if pkt[ICMPv6ND_NS].tgt == self.__config.get('wan','link_local_addr'):
                        logging.info('WAN: Solicitado ICMP_NS para um target local. Enviando NA local host')
                        self.neighbor_advertise_local(pkt)

                if not self.__config_setup1_1.get_setup1_1_OK():
                    self.set_status('WAN: Setup 1.1 em execução')
                    if not self.__config_setup1_1.get_disapproved():
                        self.__config_setup1_1.run_setup1_1(pkt)
                        if pkt.haslayer(ICMPv6ND_RS):
                            if pkt[Ether].src == self.__config.get('wan','link_local_mac'):
                                continue
                            if pkt[Ether].src == self.__config.get('wan','ra_mac'):
                                continue
                            self.set_status('WAN: Setup 1.1 Recebido ICMP RS, enviado RA')
                            self.__config_setup1_1.set_local_addr_ceRouter(pkt[IPv6].src)
                            self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)                                 
                            self.__config_setup1_1.set_ether_src(self.__config.get('wan','ra_mac'))
                            self.__config_setup1_1.set_ether_dst(self.__config.get('multicast','all_mac_nodes'))
                            self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','ra_address'))
                            self.__config_setup1_1.set_ipv6_dst(self.__config.get('multicast','all_nodes_addr'))
                            logging.info('Solicitado ICMP_RS. Enviando RA_ver2')
                            self.__sendmsgs.send_tr1_RA2(self.__config_setup1_1)

                    else:
                        self.set_status('WAN: Reprovado Teste 3.2.4 - Falha em completar o Common Setup 1.1 da RFC')
                        self.set_status('REPROVADO')
                        logging.info('WAN: Reprovado Teste 3.2.4 - Falha em completar o Common Setup 1.1 da RFC')
                        self.__packet_sniffer_wan.stop() 
                        return False

                else:
                    self.set_status('WAN: Setup 1.1 Finalizado. Iniciando novo contador de tempo. O teste termina em 300 seg se a mensagem aguardada nao for recebida')
                    logging.info('WAN: Setup 1.1 Finalizado. Iniciando novo contador de tempo. O teste termina em 300 seg se a mensagem aguardada nao for recebida')
                    if not self.__finish_wan:
                        start_time_count = True
                        if time1 < 300:
                            
                            if pkt.haslayer(ICMPv6EchoRequest):
                                logging.info('WAN: TEST 3.2.4: UNIQUE LOCAL ADDRESS FORWARDING....REPROVADO')
                                logging.info('WAN: Indevido recebimento de Echo Request na WAN de um IP proveniente pela ULA do roteador atribuido aos hosts na LAN')
                                self.set_status('WAN: Indevido recebimento de Echo Request na WAN de um IP gerado pela ULA do roteador aos hosts na LAN')
                                time.sleep(2)
                                self.set_status('REPROVADO')
                                self.__packet_sniffer_wan.stop() 
                                self.__packet_sniffer_lan.stop()
                                self.__finish_wan = True 
                                return False

                            if pkt.haslayer(ICMPv6ND_NS):
                                if pkt[ICMPv6ND_NS].tgt == self.__config.get('wan','global_wan_addr'):
                                    self.neighbor_advertise_global(pkt)

                                if pkt[ICMPv6ND_NS].tgt == self.__config.get('wan','ra_address'):
                                    self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','ra_address'))
                                    self.__config_setup1_1.set_ether_src(self.__config.get('wan','ra_mac'))
                                    self.__config_setup1_1.set_ether_dst(pkt[Ether].src)
                                    self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)
                                    self.__config_setup1_1.set_tgt(self.__config.get('wan','ra_address'))
                                    self.__config_setup1_1.set_lla(self.__config.get('wan','ra_mac'))
                                    self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)
                                    self.__sendmsgs.send_icmp_na(self.__config_setup1_1)
                        else:            
                            self.__packet_sniffer_wan.stop() 
                            self.__packet_sniffer_lan.stop()
                            #return send_file('/home/ronaldo/tcc_oficial/tcc_ronaldo/lan.cap', attachment_filename='lan.cap')
                            self.set_status('WAN: Time out sem mensagem Unreacheable na interface LAN')
                            time.sleep(2)
                            self.set_status('REPROVADO')
                            logging.info('WAN: TEST 3.2.4: UNIQUE LOCAL ADDRESS FORWARDING....REPROVADO')
                            logging.info('WAN: Time out sem mensagem Unreacheable na interface LAN')
                            return True        
                    else:
                        self.__packet_sniffer_wan.stop()
                        if self.__fail_test:
                            return False
                        else:
                                return True
        self.__packet_sniffer_wan.stop()
        return False