def run(self) : try : self.thread_stop = False traffic_lib.router_path_sw(self.server_ip,"add") #print self.config_list self.gen_cache() #start arp virtual host arp_thread = threading.Thread(target=traffic_lib.hack_arp_group,args=(self.host_list,False)) arp_thread.setDaemon(True) arp_thread.start() #start to send packet s = socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.htons(ETH_P_IP|ETH_P_ARP|ETH_P_ALL)) rface = traffic_lib.get_route_interface() if rface == None : print "Can not find local router interface." return s.bind((rface.name,0)) #s.setblocking(True) while not self.thread_stop: if len(self.data_cache) == 0 : break #time.sleep(3) else : for d in self.data_cache : for burst in range(d[0]) : s.send(d[1]) time.sleep(self.interval) s.close() #arp_thread.stop() traffic_lib.arp_flag = False except Exception as e : self.thread_stop = True print "traffic generater stop becase of exception : " + str(e) self.thread_stop = True
def stop(self): traffic_lib.router_path_sw(self.server_ip,"del") #threading.Thread.stop(self) self.thread_stop = True