def test_get_attr(): terminate = CallTerminate(10, 1) handover = CallHandover(5, 1, 1, 1, 1) init = CallInit(3, 1, 1, 1, 1, 1) assert terminate.get_params() == (10, 1) assert handover.get_params() == (1, 1, 1, 1) assert init.get_params() == (1, 1, 1, 1)
def handle_call_init(self, current_init): # process next initialisation event assert self.clock == current_init.time # assert advancement of clock inter_arrival = self.rng.random_interarrival() next_time = current_init.time + inter_arrival speed, station_id, position, duration, direction = self.generate_args() next_init = CallInit(next_time, station_id, speed, position, duration, direction) self.FEL.insert(next_init) # process current intialisation event # available channels are handled seperately from reserved channels # i.e. if the available_channels = 10 - num_reserve if self.stations_array[ current_init.station_id].available_channels == 0: self.blocked_calls += 1 else: self.stations_array[ current_init.station_id].available_channels -= 1 speed, position, duration, direction = current_init.get_params() event_type, event_time, station_id, speed, remaining_duration, direction = \ self.compute_next_event(speed, position, duration, direction, self.stations_array[current_init.station_id], current_init) if event_type == 'Terminate': termination_event = CallTerminate(event_time, station_id) self.FEL.insert(termination_event) else: assert event_type == 'Handover' self.init_handover += 1 handover_event = CallHandover(event_time, station_id, speed, remaining_duration, direction) self.FEL.insert(handover_event) self.total_calls += 1 # as long as they tried, call attempt made
def test_event_types(): handover = CallHandover(1, 1, 1, 1, 1) Init = CallInit(1, 1, 1, 1, 1, 1) Terminate = CallTerminate(1, 1) assert isinstance(handover, Event) assert isinstance(Init, Event) assert isinstance(Terminate, Event)
def test_event_insertion(): event_list = FEL() terminate = CallTerminate(10, 1) handover = CallHandover(5, 1, 1, 1, 1) init = CallInit(3, 1, 1, 1, 1, 1) event_list.insert(handover) event_list.insert(terminate) event_list.insert(init) assert isinstance(event_list[0], CallInit) assert isinstance(event_list[1], CallHandover) assert isinstance(event_list[2], CallTerminate)
def test_event_dequeue(): event_list = FEL() terminate = CallTerminate(10, 1) handover = CallHandover(5, 1, 1, 1, 1) init = CallInit(3, 1, 1, 1, 1, 1) event_list.insert(handover) event_list.insert(terminate) event_list.insert(init) original_len = len(event_list) new_len = original_len - 1 event = event_list.dequeue() assert len(event_list) == new_len assert isinstance(event, CallInit)
def handle_call_handover_res(self, current_handover): assert self.clock == current_handover.time speed, station_id, duration, direction = current_handover.get_params() position = 1 if direction == -1 else 0 used_reserve = getattr(current_handover, "used_reserve", False) self.free_prev_station(station_id, direction, used_reserve=used_reserve) # when call is blocked if self.stations_array[station_id].available_channels == 0 and \ (not self.stations_array[station_id].reserve_available()): # reserve available if I have > 0 reserve available self.dropped_calls += 1 # One type of channel is available, find out which else: # no free regular channels, use reserved channels if self.stations_array[station_id].available_channels == 0: self.stations_array[station_id].free_reserve -= 1 used_reserve = True # regular channels available else: self.stations_array[station_id].available_channels -= 1 used_reserve = False # accepted call with known channel type now to be processed event_type, event_time, station, speed, remaining_duration, directon = \ self.compute_next_event(speed, position, duration, direction, self.stations_array[station_id], current_handover) if event_type == "Terminate": termination_event = CallTerminate(event_time, station, used_reserve) self.FEL.insert(termination_event) elif event_type == "Handover": handover_event = CallHandover(event_time, station, speed, remaining_duration, direction, used_reserve) self.FEL.insert(handover_event)
def handle_call_handover_no_res(self, current_handover): assert self.clock == current_handover.time # get current info for DOING handover speed, station_id, duration, direction = current_handover.get_params() position = 1 if direction == -1 else 0 # when handing over, position is always at a bound self.free_prev_station(station_id, direction, used_reserve=False) if self.stations_array[station_id].available_channels == 0: self.dropped_calls += 1 else: self.stations_array[station_id].available_channels -= 1 event_type, event_time, station, speed, remaining_duration, direction = \ self.compute_next_event(speed, position, duration, direction, self.stations_array[station_id], current_handover) if event_type == "Terminate": termination_event = CallTerminate(event_time, station) self.FEL.insert(termination_event) elif event_type == "Handover": self.handover_handover += 1 handover_event = CallHandover(event_time, station, speed, remaining_duration, direction) self.FEL.insert(handover_event) else: raise TypeError("Wrong event type returned")
def test_event_attributes(): handover = CallHandover(5, 1, 1, 1, 1) assert handover.time == 5