Exemple #1
0
 def cond_collision(self, frag_size):
     """Calculates if there is a collision"""
     frag_ToA = get_toa(frag_size, Statsct.SF)
     #check if there is a collision at the start of the packet
     dprint("current time: {}, position: {}, ToA fragment: {}".format(self.current_time,self.position,frag_ToA['t_packet']))
     dprint("background_traffic: {}".format(self.background_traffic[self.position]))
     while self.position < len(self.background_traffic) and self.current_time > self.background_traffic[self.position][0]:           
         self.position += 1
     dprint("position: {}, ".format(self.position))
     
     if self.position != len(self.background_traffic):
         if self.current_time == self.background_traffic[self.position][0]:
             #special case when both packet start time is the same
             dprint("Collision! -> packet start at same time as the next")
             self.current_time += frag_ToA['t_packet'] + Statsct.dc_time_off(frag_ToA['t_packet'],Statsct.dc)
             return True
         elif self.position != 0 and self.current_time < self.background_traffic[self.position-1][1]:
             dprint("Collision! -> packet start before the end of previous packet")
             self.current_time += frag_ToA['t_packet'] + Statsct.dc_time_off(frag_ToA['t_packet'],Statsct.dc)
             return True
         else:
             if self.current_time + frag_ToA['t_packet'] > self.background_traffic[self.position][0]:
                 dprint("Collision!-> packet ends after next has start")
                 self.current_time += frag_ToA['t_packet'] + Statsct.dc_time_off(frag_ToA['t_packet'],Statsct.dc)
                 return True
     self.current_time += frag_ToA['t_packet'] + Statsct.dc_time_off(frag_ToA['t_packet'],Statsct.dc)
     input('')
     return False    
Exemple #2
0
    def generate_background_traffic(self, G, background_frag_size):
        self.background_traffic
        T = get_toa(background_frag_size, Statsct.SF)
        g = G / T['t_packet']
        print("g: {}, G:{}, T:{}".format(g, G, T['t_packet']))
        for i in range(1000):
            #aleatoire = machine.rng()
            #aleatoire2 = aleatoire/(2**24-1)

            aleatoire = urandom.getrandbits(8) / 256
            aleatoire2 = aleatoire / (2**24 - 1)
            #print(aleatoire2)
            if aleatoire2 != 0:
                test = -1 * math.log(aleatoire2) / 1 / g
                self.background_traffic.append((test, test + T['t_packet']))
        if enable_statsct:
            Statsct.set_background_traffic(self.background_traffic)