How to use setup1 method in Sure

Best Python code snippet using sure_python

test322a.py

Source:test322a.py Github

copy

Full Screen

1import logging2import logging.config3import logging.handlers4from configparser import ConfigParser5from threading import Thread6from subprocess import call7import sys8import argparse9from scapy.all import *10from config import Config11import time12from packetsniffer import PacketSniffer13from commontestsetup1_1 import CommonTestSetup1_114from sendmsgs import SendMsgs15from configsetup1_1 import ConfigSetup1_116from configsetup1_1_lan import ConfigSetup1_1_Lan17format = "%(asctime)s: %(message)s"18logging.basicConfig(format=format, level=logging.DEBUG,19 datefmt="%H:%M:%S")20class Test322a:21 def __init__(self,config):22 self.__queue_wan = Queue()23 self.__queue_lan = Queue()24 self.__config = config25 self.__interface = None26 self.__pkt = None27 self.__local_addr_ceRouter =None28 self.__sendmsgs = SendMsgs(self.__config)29 self.__config_setup1_1 = ConfigSetup1_1(self.__config)30 #self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config)31 self.__wan_device_tr1 = self.__config.get('wan','device_wan_tr1')32 self.__lan_device = self.__config.get('lan','lan_device')33 self.__wan_mac_tr1 = self.__config.get('wan','wan_mac_tr1')34 self.__link_local_addr = self.__config.get('wan','link_local_addr')35 self.__all_nodes_addr = self.__config.get('multicast','all_nodes_addr')36 self.__test_desc = self.__config.get('tests','3.2.2a')37 self.__t_lan = None38 self.__finish_wan = False39 self.__dhcp_renew_done = False40 self.__config_setup_lan = ConfigSetup1_1_Lan(self.__config,self.__lan_device)41 def set_flags(self):42 self.__config_setup1_1.set_flag_M(self.__config.get('t3.2.2a','flag_m'))43 self.__config_setup1_1.set_flag_0(self.__config.get('t3.2.2a','flag_o'))44 self.__config_setup1_1.set_flag_chlim(self.__config.get('t3.2.2a','flag_chlim'))45 self.__config_setup1_1.set_flag_L(self.__config.get('t3.2.2a','flag_l'))46 self.__config_setup1_1.set_flag_A(self.__config.get('t3.2.2a','flag_a'))47 self.__config_setup1_1.set_flag_R(self.__config.get('t3.2.2a','flag_r'))48 self.__config_setup1_1.set_flag_prf(self.__config.get('t3.2.2a','flag_prf'))49 self.__config_setup1_1.set_validlifetime(self.__config.get('t3.2.2a','validlifetime'))50 self.__config_setup1_1.set_preferredlifetime(self.__config.get('t3.2.2a','preferredlifetime'))51 self.__config_setup1_1.set_routerlifetime(self.__config.get('t3.2.2a','routerlifetime'))52 self.__config_setup1_1.set_reachabletime(self.__config.get('t3.2.2a','reach_time'))53 self.__config_setup1_1.set_retranstimer(self.__config.get('t3.2.2a','retrans_time')) 54 self.__config_setup1_1.set_intervalo(self.__config.get('t1.6.6b','intervalo'))55 self.__config_setup1_1.set_prefix_addr(self.__config.get('setup1-1_advertise','ia_pd_address'))56 self.__config_setup1_1.set_dhcp_t1(self.__config.get('t3.2.2a','dhcp_t1'))57 self.__config_setup1_1.set_dhcp_t2(self.__config.get('t3.2.2a','dhcp_t2'))58 self.__config_setup1_1.set_dhcp_preflft(self.__config.get('t3.2.2a','dhcp_preflft'))59 self.__config_setup1_1.set_dhcp_validlft(self.__config.get('t3.2.2a','dhcp_validlft'))60 self.__config_setup1_1.set_dhcp_plen(self.__config.get('t3.2.2a','dhcp_plen'))61 62 def set_flags_lan(self):63 self.__config_setup_lan.set_elapsetime(self.__config.get('solicitlan','elapsetime'))64 self.__config_setup_lan.set_xid(self.__config.get('solicitlan','xid'))65 self.__config_setup_lan.set_fdqn(self.__config.get('solicitlan','clientfqdn'))66 self.__config_setup_lan.set_vendor_class(self.__config.get('solicitlan','vendorclass'))67 self.__config_setup_lan.set_enterprise(self.__config.get('solicitlan','enterpriseid'))68 self.__config_setup_lan.set_client_duid(self.__config.get('solicitlan','duid'))69 self.__config_setup_lan.set_iaid(self.__config.get('solicitlan','iaid'))70 def ping_tn3(self):71 if self.__config_setup1_1.get_mac_ceRouter() != None:72 #print('6')73 self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))74 self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac'))75 self.__config_setup_lan.set_ether_dst(self.__config_setup_lan.get_mac_ceRouter())76 self.__config_setup_lan.set_ipv6_dst(self.__config.get('t3.2.2a','tn3_ip'))77 self.__sendmsgs.send_echo_request_lan(self.__config_setup_lan)78 79 def run_Lan(self):80 #self.__config_setup_lan_.flags_partA()81 logging.info('Thread da LAN inicio')82 t_test = 083 t_test1= 084 time_p = 085 sent_reconfigure = False86 time_over = False87 send_ra = False88 send_na_lan = False89 self.set_flags_lan()90 self.__config_setup_lan.set_setup_lan_start()91 while not self.__queue_lan.full():92 if self.__queue_lan.empty():93 if t_test < 30:94 95 time.sleep(1)96 t_test = t_test + 197 if t_test % 5 ==0:98 #print('0')99 #print('ENVIO RS - 1 LAN')100 self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))101 self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))102 self.__config_setup_lan.set_ether_dst('33:33:00:01:00:02')103 self.__config_setup_lan.set_ipv6_dst(self.__config.get('multicast','all_routers_addr'))104 self.__config_setup_lan.set_xid(self.__config.get('informationlan','xid'))105 #self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))106 self.__config_setup_lan.set_elapsetime(self.__config.get('informationlan','elapsetime'))107 self.__config_setup_lan.set_vendor_class(self.__config.get('informationlan','vendorclass'))108 self.__sendmsgs.send_dhcp_information(self.__config_setup_lan)109 110 #self.__config_setup_lan.set_setup_lan_start()111 self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))112 self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))113 self.__config_setup_lan.set_ether_dst(self.__config.get('multicast','all_mac_routers'))114 self.__config_setup_lan.set_ipv6_dst(self.__config.get('general','all_routers_address'))115 self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))116 self.__sendmsgs.send_icmp_rs(self.__config_setup_lan)117 # if self.__config_setup_lan.get_mac_ceRouter() != None:118 # #print('6')119 # self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))120 # self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))121 # self.__config_setup_lan.set_ether_dst(self.__config_setup_lan.get_mac_ceRouter())122 # self.__config_setup_lan.set_ipv6_dst(self.__config.get('wan','global_wan_addr'))123 # self.__sendmsgs.send_echo_request_lan(self.__config_setup_lan)124 125 # self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))126 # self.__config_setup_lan.set_ipv6_dst(self.__config.get('multicast','all_nodes_addr'))127 # self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))128 # self.__config_setup_lan.set_ether_dst(self.__config.get('multicast','all_mac_nodes'))129 # #self.set_tgt(self.get_local_addr_ceRouter())130 131 # self.__config_setup_lan.set_tgt(self.__config.get('wan','link_local_addr'))132 # #self.__sendmsgssetup1_1.send_echo_request(self)133 # self.__config_setup_lan.set_lla(self.__config.get('wan','link_local_mac'))134 # self.__sendmsgs.send_icmp_ns_lan(self.__config_setup_lan)135 #print('1')136 logging.info('Thread da LAN time')137 time.sleep(1)138 else:139 time_over = True140# t_test = t_test + 1141 # if self.__config_setup1_1.get_recvd_dhcp_renew():142 #pkt = self.__queue_lan.get()143 else:144 pkt = self.__queue_lan.get()145 if pkt.haslayer(ICMPv6ND_RA):146 self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)147 if pkt.haslayer(ICMPv6MLReport2):148 self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)149 if pkt.haslayer(DHCP6_Reply):150 self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)151 if pkt[Ether].src == self.__config.get('lan','mac_address'):152 continue153 if pkt.haslayer(ICMPv6ND_NS):154 if pkt[ICMPv6ND_NS].tgt == self.__config.get('lan','global_wan_addr'):155 self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))156 self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))157 self.__config_setup_lan.set_ether_dst(pkt[Ether].src)158 self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)159 self.__config_setup_lan.set_tgt(self.__config.get('lan','global_wan_addr'))160 self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))161 self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)162 self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)163 print('AQUI-9')164 if pkt[ICMPv6ND_NS].tgt == self.__config.get('lan','lan_local_addr'):165 self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))166 self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))167 self.__config_setup_lan.set_ether_dst(pkt[Ether].src)168 self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)169 self.__config_setup_lan.set_tgt(self.__config.get('lan','lan_local_addr'))170 self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))171 self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)172 self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)173 174 if self.__config_setup1_1.get_setup1_1_OK():175 if pkt[Ether].src == self.__config.get('lan','mac_address'):176 continue177 if t_test1 < 30:178 t_test1 = t_test1 + 1179 if t_test1 % 5 == 0: 180 self.ping_tn3()181 182 # if pkt.haslayer(ICMPv6EchoRequest):183 # logging.info('Aprovado Teste 2.7.3b - Recebeu ICMPv6EchoRequest Apos do IP_PD ser fornecido à porta WAN do roteador')184 # self.__packet_sniffer_wan.stop() 185 # return False186 # #print('AQUI-2.0')187 # self.__packet_sniffer_lan.stop()188 # self.__finish_wan = True 189 # self.__fail_test = False190 # return False191 if pkt.haslayer(ICMPv6ND_NS):192 if pkt[ICMPv6ND_NS].tgt == self.__config.get('lan','global_wan_addr'):193 self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','global_wan_addr'))194 self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))195 self.__config_setup_lan.set_ether_dst(pkt[Ether].src)196 self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)197 self.__config_setup_lan.set_tgt(self.__config.get('lan','global_wan_addr'))198 self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))199 self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)200 self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)201 202 if pkt[ICMPv6ND_NS].tgt == self.__config.get('lan','lan_local_addr'):203 self.__config_setup_lan.set_ipv6_src(self.__config.get('lan','lan_local_addr'))204 self.__config_setup_lan.set_ether_src(self.__config.get('lan','mac_address'))205 self.__config_setup_lan.set_ether_dst(pkt[Ether].src)206 self.__config_setup_lan.set_ipv6_dst(pkt[IPv6].src)207 self.__config_setup_lan.set_tgt(self.__config.get('lan','lan_local_addr'))208 self.__config_setup_lan.set_lla(self.__config.get('lan','mac_address'))209 self.__config_setup_lan.set_mac_ceRouter(pkt[Ether].src)210 self.__sendmsgs.send_icmp_na_lan(self.__config_setup_lan)211 def rourter_advertise(self):212 self.__config_setup1_1.set_ether_src(self.__config.get('wan','ra_mac'))213 self.__config_setup1_1.set_ether_dst(self.__config.get('multicast','all_mac_nodes'))214 self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','ra_address'))215 self.__config_setup1_1.set_ipv6_dst(self.__config.get('multicast','all_nodes_addr'))216 self.__sendmsgs.send_tr1_RA(self.__config_setup1_1)217 218 def ping(self):219 if self.__config_setup1_1.get_mac_ceRouter() != None:220 #print('6')221 self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','global_wan_addr'))222 self.__config_setup1_1.set_ether_src(self.__config.get('wan','wan_mac_tr1'))223 self.__config_setup1_1.set_ether_dst(self.__config_setup1_1.get_mac_ceRouter())224 self.__config_setup1_1.set_ipv6_dst(self.__config.get('lan','global_wan_addr'))225 self.__sendmsgs.send_echo_request(self.__config_setup1_1)226 def neighbor_advertise_local(self,pkt):227 self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','link_local_addr'))228 self.__config_setup1_1.set_ether_src(self.__config.get('wan','wan_mac_tr1'))229 self.__config_setup1_1.set_ether_dst(pkt[Ether].src)230 self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)231 self.__config_setup1_1.set_tgt(self.__config.get('wan','link_local_addr'))232 self.__config_setup1_1.set_lla(self.__config.get('wan','wan_mac_tr1'))233 self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)234 self.__sendmsgs.send_icmp_na(self.__config_setup1_1)235 def neighbor_advertise_global(self,pkt):236 self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','global_wan_addr'))237 self.__config_setup1_1.set_ether_src(self.__config.get('wan','wan_mac_tr1'))238 self.__config_setup1_1.set_ether_dst(pkt[Ether].src)239 self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)240 self.__config_setup1_1.set_tgt(self.__config.get('wan','global_wan_addr'))241 self.__config_setup1_1.set_lla(self.__config.get('wan','wan_mac_tr1'))242 self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)243 self.__sendmsgs.send_icmp_na(self.__config_setup1_1)244 def neighbor_advertise_global_tn3(self,pkt):245 self.__config_setup1_1.set_ipv6_src(self.__config.get('t3.2.2a','tn3_ip'))246 self.__config_setup1_1.set_ether_src(self.__config.get('t3.2.2a','tn3_mac'))247 self.__config_setup1_1.set_ether_dst(pkt[Ether].src)248 self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)249 self.__config_setup1_1.set_tgt(self.__config.get('t3.2.2a','tn3_ip'))250 self.__config_setup1_1.set_lla(self.__config.get('t3.2.2a','tn3_mac'))251 self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)252 self.__sendmsgs.send_icmp_na(self.__config_setup1_1)253 def run(self):254 self.__t_lan = Thread(target=self.run_Lan,name='LAN_Thread')255 self.__t_lan.start()256 257 self.__packet_sniffer_wan = PacketSniffer('Test273b-WAN',self.__queue_wan,self,self.__config,self.__wan_device_tr1)258 self.__packet_sniffer_wan.start()259 260 self.__packet_sniffer_lan = PacketSniffer('Test273b-LAN',self.__queue_lan,self,self.__config,self.__lan_device)261 test_lan = self.__packet_sniffer_lan.start()262 self.__config_setup1_1.set_ra2()263 self.set_flags()264 logging.info(self.__test_desc)265 t_test = 0266 time1 = 0267 sent_reconfigure = False268 time_over = False269 start_time_count = False270 finish_wan = False271 self.__config_setup1_1.set_pd_prefixlen(self.__config.get('t3.2.2a','pd_prefixlen')) 272 self.__config_setup1_1.set_routerlifetime(self.__config.get('t3.2.2a','routerlifetime')) 273 while not self.__queue_wan.full():274 if self.__queue_wan.empty():275 if t_test <= 300:276 time.sleep(1)277 t_test = t_test + 1278 if t_test % 10 == 0:279 self.rourter_advertise()280 #self.ping()281 282 if start_time_count:283 if time1 < 40:284 time1 = time1 + 1285 #if time1 % 5 == 0: 286 #self.ping()287 else:288 time_over = True 289 else:290 pkt = self.__queue_wan.get()291 if not self.__config_setup1_1.get_ND_local_OK():292 if pkt[Ether].src == self.__config.get('wan','link_local_mac'):293 print('ND_LOCAL,continue')294 continue295 if pkt[Ether].src == self.__config.get('wan','ra_mac'):296 print('ND_LOCAL-A,continue') 297 continue298 if pkt.haslayer(ICMPv6ND_RS):299 300 if pkt[Ether].src == self.__config.get('wan','link_local_mac'):301 print('RS,continue') 302 continue303 if pkt[Ether].src == self.__config.get('wan','ra_mac'):304 print('RS-A,continue') 305 continue306 self.__config_setup1_1.set_local_addr_ceRouter(pkt[IPv6].src)307 self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src) 308 #self.__config_setup1_1.set_ND_local_OK()309 if pkt.haslayer(DHCP6_Solicit):310 if pkt[Ether].src == self.__config.get('wan','link_local_mac'):311 print('solicit,continue')312 continue313 if pkt[Ether].src == self.__config.get('wan','ra_mac'):314 print('solicitA,continue')315 continue316 self.__config_setup1_1.set_local_addr_ceRouter(pkt[IPv6].src)317 self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)318 #self.__config_setup1_1.set_ND_local_OK() 319 if pkt.haslayer(ICMPv6ND_NS):320 if pkt[ICMPv6ND_NS].tgt == self.__config.get('wan','global_wan_addr'):321 self.neighbor_advertise_global(pkt)322 323 if pkt[ICMPv6ND_NS].tgt == self.__config.get('wan','link_local_addr'):324 self.neighbor_advertise_local(pkt)325 #pkt = self.__queue_wan.get()326 if not self.__config_setup1_1.get_setup1_1_OK():327 print('test1')328 if not self.__config_setup1_1.get_disapproved():329 print('test2')330 self.__config_setup1_1.run_setup1_1(pkt)331 print('test3')332 if pkt.haslayer(ICMPv6ND_RS):333 if pkt[Ether].src == self.__config.get('wan','link_local_mac'):334 print('RS-2,continue') 335 continue336 if pkt[Ether].src == self.__config.get('wan','ra_mac'):337 print('RS-2A,continue')338 continue339 print('test4')340 #self.__config_setup1_1.set_ND_local_OK()341 self.__config_setup1_1.set_local_addr_ceRouter(pkt[IPv6].src)342 self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src) 343 self.__config_setup1_1.set_ether_src(self.__config.get('wan','ra_mac'))344 self.__config_setup1_1.set_ether_dst(self.__config.get('multicast','all_mac_nodes'))345 self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','ra_address'))346 self.__config_setup1_1.set_ipv6_dst(self.__config.get('multicast','all_nodes_addr'))347 self.__sendmsgs.send_tr1_RA2(self.__config_setup1_1)348 else:349 logging.info('Reprovado Teste 2.7.3b - Falha em completar o Common Setup 1.1 da RFC')350 self.__packet_sniffer_wan.stop() 351 return False352 else:353 if not self.__finish_wan:354 start_time_count = True355 if time1 < 40:356 #if time1 % 5 == 0: 357 #self.ping()358 if pkt.haslayer(ICMPv6EchoRequest):359 logging.info('Reprovado Teste 2.7.3a - Recebido ICMPv6EchoRequest na WAN sendo que Routerlifime anunciado é zero')360 self.__packet_sniffer_wan.stop() 361 #print('AQUI-2.0')362 self.__packet_sniffer_lan.stop()363 self.__finish_wan = True 364 self.__fail_test = False365 return False366 if pkt.haslayer(ICMPv6ND_NS):367 if pkt[ICMPv6ND_NS].tgt == self.__config.get('t3.2.2a','tn3_ip'):368 print('glboal')369 self.neighbor_advertise_global_tn3(pkt)370 if pkt[ICMPv6ND_NS].tgt == self.__config.get('wan','ra_address'):371 print('local')372 self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','ra_address'))373 self.__config_setup1_1.set_ether_src(self.__config.get('wan','ra_mac'))374 self.__config_setup1_1.set_ether_dst(pkt[Ether].src)375 self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)376 self.__config_setup1_1.set_tgt(self.__config.get('wan','ra_address'))377 self.__config_setup1_1.set_lla(self.__config.get('wan','ra_mac'))378 self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)379 self.__sendmsgs.send_icmp_na(self.__config_setup1_1)380 ##print('LOOP NS')381 # ##print(pkt[ICMPv6ND_NS].tgt)382 # self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','global_wan_addr'))383 # self.__config_setup1_1.set_ether_src(self.__config.get('wan','wan_mac_tr1'))384 # self.__config_setup1_1.set_ether_dst(pkt[Ether].src)385 # self.__config_setup1_1.set_ipv6_dst(pkt[IPv6].src)386 # self.__config_setup1_1.set_tgt(self.__config.get('wan','global_wan_addr'))387 # self.__config_setup1_1.set_lla(self.__config.get('wan','wan_mac_tr1'))388 # self.__sendmsgs.send_icmp_na(self.__config_setup1_1)389 390 else: 391 self.__packet_sniffer_wan.stop() 392 self.__packet_sniffer_lan.stop()393 logging.info('Teste 3.7.2a - APROVADO. Não passou pacotes da LAN para WAN devido ao RouterLife time estar zerado')394 return True 395 396 397 398 399 else:400 self.__packet_sniffer_wan.stop()401 if self.__fail_test:402 return False403 else:404 return True405 self.__packet_sniffer_wan.stop()406 return False407 ...

Full Screen

Full Screen

test164a.py

Source:test164a.py Github

copy

Full Screen

1import logging2import logging.config3import logging.handlers4from configparser import ConfigParser5from threading import Thread6from subprocess import call7import sys8import argparse9from scapy.all import *10from config import Config11import time12from packetsniffer import PacketSniffer13from commontestsetup1_1 import CommonTestSetup1_114from sendmsgs import SendMsgs15from configsetup1_1 import ConfigSetup1_116import pdb17format = "%(asctime)s: %(message)s"18logging.basicConfig(format=format, level=logging.DEBUG,19 datefmt="%H:%M:%S")20class Test164a:21 def __init__(self,config):22 self.__queue_wan = Queue()23 self.__queue_lan = Queue()24 self.__config = config25 self.__interface = None26 self.__pkt = None27 self.addr_ceRouter = None28 self.mac_ceRouter = None29 self.__local_addr_ceRouter =None30 self.__ND_local_OK = False31 self.__sendmsgs = SendMsgs(self.__config)32 self.__config_setup1_1 = ConfigSetup1_1(self.__config)33 self.__wan_device_tr1 = self.__config.get('wan','device_wan_tr1')34 self.__wan_mac_tr1 = self.__config.get('wan','wan_mac_tr1')35 self.__link_local_addr = self.__config.get('wan','link_local_addr')36 self.__all_nodes_addr = self.__config.get('multicast','all_nodes_addr')37 self.__test_desc = self.__config.get('tests','1.6.4')38 39 def get_addr_ceRouter(self):40 return self.addr_ceRouter41 42 def get_mac_ceRouter(self):43 return self.mac_ceRouter44 def set_flags(self):45 self.__config_setup1_1.set_flag_M(self.__config.get('t1.6.4','flag_m'))46 self.__config_setup1_1.set_flag_0(self.__config.get('t1.6.4','flag_o'))47 self.__config_setup1_1.set_flag_chlim(self.__config.get('t1.6.4','flag_chlim'))48 self.__config_setup1_1.set_flag_L(self.__config.get('t1.6.4','flag_l'))49 self.__config_setup1_1.set_flag_A(self.__config.get('t1.6.4','flag_a'))50 self.__config_setup1_1.set_flag_R(self.__config.get('t1.6.4','flag_r'))51 self.__config_setup1_1.set_flag_prf(self.__config.get('t1.6.4','flag_prf'))52 self.__config_setup1_1.set_validlifetime(self.__config.get('t1.6.4','validlifetime'))53 self.__config_setup1_1.set_preferredlifetime(self.__config.get('t1.6.4','preferredlifetime'))54 self.__config_setup1_1.set_routerlifetime(self.__config.get('t1.6.4','routerlifetime'))55 self.__config_setup1_1.set_intervalo(self.__config.get('t1.6.4','intervalo')) 56 def run(self):57 self.__packet_sniffer_wan = PacketSniffer('test164',self.__queue_wan,self,self.__config,self.__wan_device_tr1)58 self.__packet_sniffer_wan.start()59 self.set_flags() 60 logging.info(self.__test_desc)61 t_test = 062 sent_reconfigure = False63 time_over = False64 rs_ok = False65 send_ra = False66 send_ns =False67 send_ra2 = False68 send_ra_M_1 =False69 while not self.__queue_wan.full():70 while self.__queue_wan.empty():71 if t_test < 60:72 time.sleep(1)73 t_test = t_test + 174 else:75 time_over = True76 pkt = self.__queue_wan.get()77 #if not self.__ND_local_OK:78 if pkt.haslayer(ICMPv6ND_NS):79 if pkt[ICMPv6ND_NS].tgt == '::':80 pass81 if pkt[IPv6].src == self.__config.get('wan','link_local_addr'):82 pass83 if pkt[IPv6].src == self.__config.get('wan','global_wan_addr'):84 pass85 if pkt[IPv6].src == '::':86 if pkt[ICMPv6ND_NS].tgt != '::':87 self.__config_setup1_1.set_mac_ceRouter(pkt[Ether].src)88 self.__config_setup1_1.set_local_addr_ceRouter(pkt[ICMPv6ND_NS].tgt)89 self.__ND_local_OK = True90 if pkt[ICMPv6ND_NS].tgt != '::' and pkt[IPv6].src != '::':91 pkt.show()92 # self.addr_ceRouter = pkt[ICMPv6ND_NS].tgt93 # self.mac_ceRouter = pkt[Ether].src94 # self.__ND_local_OK = True95 if pkt.haslayer(ICMPv6ND_RS) and not self.__ND_local_OK:96 return False97 else:98 if not send_ns:99 #self.__sendmsgs.set_flags_common_setup(self.__config_setup1_1)100 self.__config_setup1_1.set_ether_src(self.__config.get('wan','link_local_mac'))101 self.__config_setup1_1.set_ether_dst(self.__config.get('multicast','all_mac_nodes'))102 self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','global_wan_addr'))103 self.__config_setup1_1.set_ipv6_dst(self.__config.get('multicast','all_nodes_addr'))104 self.__config_setup1_1.set_tgt(self.__config.get('wan','link_local_addr'))105 106 self.__sendmsgs.send_icmp_ns(self.__config_setup1_1)107 send_ns = True108 continue109 if pkt.haslayer(DHCP6_Solicit) and send_ns and not send_ra_M_1 : 110 if not send_ra_M_1:111 self.__config_setup1_1.set_ether_src(self.__config.get('wan','ra_mac'))112 self.__config_setup1_1.set_ether_dst(self.__config.get('multicast','all_mac_nodes'))113 self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','link_local_addr'))114 self.__config_setup1_1.set_ipv6_dst(self.__config.get('multicast','all_nodes_addr'))115 self.__sendmsgs.send_tr1_RA(self.__config_setup1_1)116 send_ra = True117 send_ra_M_1 = True118 continue119 #self.set_ether_dst(pkt[Ether].src)120 if send_ra_M_1 and not send_ra2:121 if pkt.haslayer(DHCP6_Solicit):122 123 self.__config_setup1_1.set_flag_M("0")124 self.__config_setup1_1.set_ether_src(self.__config.get('wan','ra_mac'))125 self.__config_setup1_1.set_ether_dst(self.__config_setup1_1.get_mac_ceRouter())126 self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','link_local_addr'))127 self.__config_setup1_1.set_ipv6_dst(self.__config_setup1_1.get_local_addr_ceRouter())128 self.__sendmsgs.send_tr1_RA(self.__config_setup1_1)129 send_ra2 = True130 continue131 if send_ra2:132 if pkt.haslayer(DHCP6_Solicit):133 if pkt.haslayer(DHCP6OptIA_NA):134 return True135 #if pkt.haslayer(DHCP6_Solicit) and send_ra2: 136 # print('local addr')137 # print(self.get_local_addr_ceRouter())138 # print('ether dst')139 # print(self.get_ether_dst())140 #self.__ND_local_OK = True141 # if not self.__config_setup1_1.get_setup1_1_OK():142 # if not self.__config_setup1_1.get_disapproved():143 # self.__config_setup1_1.run_setup1_1(pkt)144 # else:145 # logging.info('Reprovado Teste 1.6.3.c - Falha em completar o Common Setup 1.1 da RFC')146 # self.__packet_sniffer_wan.stop() 147 # return False148 #else: 149 # self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','link_local_addr'))150 # self.__config_setup1_1.set_ipv6_dst(self.__config.get('multicast','dhcp_relay_agents_and_servers_addr'))151 # self.__config_setup1_1.set_ether_src(self.__config.get('wan','link_local_mac'))152 # self.__config_setup1_1.set_ether_dst(self.__config_setup1_1.get_ether_dst())153 # self.__config_setup1_1.set_dhcp_reconf_type(self.__config.get('t1.6.3','msg_type'))154 # if pkt.haslayer(DHCP6_Renew):155 # logging.info('Reprovado Teste 1.6.3.c - Respondeu ao DHCP6 reconfigure incompleto')156 # logging.info(pkt.show())157 # self.__packet_sniffer_wan.stop()158 # return False159 # elif time_over :160 # if not sent_reconfigure:161 # self.__packet_sniffer_wan.stop()162 # logging.info('Falha: Teste 1.6.3.c. Tempo finalizado mas Não Enviou DHCP Reconfigure')163 # return False164 # else:165 # self.__packet_sniffer_wan.stop() 166 # logging.info('Aprovado: Teste 1.6.3.c. Tempo finalizado e não recebeu DHCP Renew em DHCP Reconf adulterado')167 # return True168 # if not sent_reconfigure:169 # self.__sendmsgs.send_dhcp_reconfigure_no_auth(self.__config_setup1_1)170 # sent_reconfigure = True171 172 # if pkt.haslayer(DHCP6_Solicit):173 # self.__packet_sniffer_wan.stop()174 # while not self.__queue_wan.empty():175 # pkt = self.__queue_wan.get() 176 # return True177 # while not pkt.haslayer(IPv6):178 # pkt = self.__queue_wan.get() 179 self.__packet_sniffer_wan.stop()180 return False181 ...

Full Screen

Full Screen

test163b.py

Source:test163b.py Github

copy

Full Screen

1import logging2import logging.config3import logging.handlers4from configparser import ConfigParser5from threading import Thread6from subprocess import call7import sys8import argparse9from scapy.all import *10from config import Config11import time12from packetsniffer import PacketSniffer13from commontestsetup1_1 import CommonTestSetup1_114from sendmsgs import SendMsgs15from configsetup1_1 import ConfigSetup1_116import pdb17format = "%(asctime)s: %(message)s"18logging.basicConfig(format=format, level=logging.DEBUG,19 datefmt="%H:%M:%S")20class Test163b:21 def __init__(self,config):22 self.__queue_wan = Queue()23 self.__queue_lan = Queue()24 self.__config = config25 self.__interface = None26 self.__pkt = None27 self.__local_addr_ceRouter =None28 self.__sendmsgs = SendMsgs(self.__config)29 self.__config_setup1_1 = ConfigSetup1_1(self.__config)30 self.__wan_device_tr1 = self.__config.get('wan','device_wan_tr1')31 self.__wan_mac_tr1 = self.__config.get('wan','wan_mac_tr1')32 self.__link_local_addr = self.__config.get('wan','link_local_addr')33 self.__all_nodes_addr = self.__config.get('multicast','all_nodes_addr')34 self.__test_desc = self.__config.get('tests','1.6.3b')35 def set_flags(self):36 self.__config_setup1_1.set_flag_M(self.__config.get('t1.6.3','flag_m'))37 self.__config_setup1_1.set_flag_0(self.__config.get('t1.6.3','flag_o'))38 self.__config_setup1_1.set_flag_chlim(self.__config.get('t1.6.3','flag_chlim'))39 self.__config_setup1_1.set_flag_L(self.__config.get('t1.6.3','flag_l'))40 self.__config_setup1_1.set_flag_A(self.__config.get('t1.6.3','flag_a'))41 self.__config_setup1_1.set_flag_R(self.__config.get('t1.6.3','flag_r'))42 self.__config_setup1_1.set_flag_prf(self.__config.get('t1.6.3','flag_prf'))43 self.__config_setup1_1.set_validlifetime(self.__config.get('t1.6.3','validlifetime'))44 self.__config_setup1_1.set_preferredlifetime(self.__config.get('t1.6.3','preferredlifetime'))45 self.__config_setup1_1.set_routerlifetime(self.__config.get('t1.6.3','routerlifetime'))46 self.__config_setup1_1.set_intervalo(self.__config.get('t1.6.3','intervalo'))47 def run(self):48 self.__packet_sniffer_wan = PacketSniffer('test163b',self.__queue_wan,self,self.__config,self.__wan_device_tr1)49 self.__config_setup1_1.flags_partA()50 self.__packet_sniffer_wan.start()51 self.set_flags()52 logging.info(self.__test_desc)53 t_test = 054 sent_reconfigure = False55 time_over = False 56 while not self.__queue_wan.full():57 while self.__queue_wan.empty():58 if t_test < 3000:59 time.sleep(1)60 t_test = t_test + 161 else:62 time_over = True63 pkt = self.__queue_wan.get()64 65 if not self.__config_setup1_1.get_setup1_1_OK():66 if not self.__config_setup1_1.get_disapproved():67 self.__config_setup1_1.run_setup1_1(pkt)68 print('aqui')69 else:70 print('aqui1')71 self.__packet_sniffer_wan.stop() 72 logging.info('Reprovado Teste 1.6.3.c - Falha em completar o Common Setup 1.1 da RFC')73 return False74 #self.__config_setup1_1.run_setup1_1(pkt)75 else:76 77 # self.__config_setup1_1.set_xid()78 if pkt.haslayer(DHCP6_Renew):79 print('aqui2')80 logging.info(pkt.show())81 print('aqui3')82 self.__packet_sniffer_wan.stop()83 print('aqui33333')84 85 logging.info('Aprovado: Teste 1.6.3.b.')86 return True87 elif time_over :88 print('aqui4')89 if not sent_reconfigure:90 print('aqui5')91 pass92 #self.__packet_sniffer_wan.stop()93 logging.info('Falha: Teste 1.6.3.b. Tempo finalizado e Não Enviou DHCP Reconfigure')94 return False95 else:96 print('aqui6')97 self.__packet_sniffer_wan.stop()98 logging.info('Reprovado: Teste 1.6.3.b. Tempo finalizado e Não recebeu DHCP6 Renew')99 return False100 if not sent_reconfigure:101 time.sleep(3)102 print('aqui7')103 self.__config_setup1_1.set_ipv6_src(self.__config.get('wan','link_local_addr'))104 print('aqui8')105 self.__config_setup1_1.set_ipv6_dst(self.__config_setup1_1.get_local_addr_ceRouter())106 print('aqui10')107 self.__config_setup1_1.set_ether_src(self.__config.get('wan','link_local_mac'))108 print('aqui11')109 self.__config_setup1_1.set_ether_dst(self.__config_setup1_1.get_mac_ceRouter())110 print('aqui12')111 self.__config_setup1_1.set_dhcp_reconf_type(self.__config.get('t1.6.3','msg_type'))112 print('aqui13')113 self.__config_setup1_1.set_udp_sport('547')114 self.__config_setup1_1.set_udp_dport('546')115 self.__sendmsgs.send_dhcp_reconfigure(self.__config_setup1_1)116 print('aqui14')117 sent_reconfigure = True 118 # if pkt.haslayer(DHCP6_Solicit):119 # self.__packet_sniffer_wan.stop()120 # while not self.__queue_wan.empty():121 # pkt = self.__queue_wan.get() 122 # return True123 # while not pkt.haslayer(IPv6):124 # pkt = self.__queue_wan.get() 125 self.__packet_sniffer_wan.stop()126 return False127 ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Sure automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful