def handle_incoming_bp_single_link_request(frontend, connection, msg): err.log_error(err.INFO, "Using BP algorithm") list_link_capacity_data = bp.retrieve_link_capacity_data(frontend.dbcc, msg.link_id) if len(list_link_capacity_data) == 0: #Don't have any capacity data missing_resource = mr.MissingLinkCapacity(msg.link_id) frontend.queue_as_pending_request(connection, msg, [missing_resource]) err.log_error(err.INFO, "Did not have the link capacity, asking from supplier " + str(msg.link_id)) error_message = mo.Error(102, "BP Request will take longer than expected because link_capacity data is missing at MOBaaS") connection.add_message(error_message) supplier_message = mo.MaaSSingleLinkCapacityRequest(msg.link_id) frontend.ask_at_supplier(supplier_message) else: #Capacity data available! bpfetched = bp.retrieve_bandwidth_prediction_data(frontend.dbcc, msg.link_id, msg.current_date, msg.current_time) missing_ranges = bp.check_integrity_bandwidth_prediction_data(bpfetched, msg.current_date, msg.current_time) if len(missing_ranges) == 0: #All data available. Send answer! in_use = bp.bandwidth_prediction(bpfetched) left_over_capacity = list_link_capacity_data[0].capacity - in_use answer_message = mo.BPSingleLinkAnswer(msg.link_id, msg.current_time, msg.current_date, left_over_capacity) connection.add_message(answer_message) err.log_error(err.INFO, "Found an answer to the request! Answer: " + str(answer_message)) else: #Missing flow data missing_resource = mr.MissingFlowData(missing_ranges) frontend.queue_as_pending_request(connection, msg, [missing_resource]) err.log_error(err.INFO, "Did not have enough flow data, asking from supplier: " + str(missing_ranges)) error_message = mo.Error(102, "BP Request will take longer than expected because flow data is missing at MOBaaS") connection.add_message(error_message) for missing_range in missing_ranges: start_dt = support.from_unix_timestamp_to_datetime(missing_range.min_range) timespan = missing_range.max_range - missing_range.min_range supplier_message = mo.MaaSSingleLinkDataRequest(msg.link_id, start_dt.date(), start_dt.time(), timespan) frontend.ask_at_supplier(supplier_message)
#, message_objects.MPSingleUserRequest(5980, mp_start_datetime_2.time(), mp_start_datetime_2.date(), 20 * 60, 12963) #, message_objects.MPSingleUserRequest(5963, mp_start_datetime_3.time(), mp_start_datetime_3.date(), 55 * 60, 3729) #, message_objects.MPSingleUserRequest(5974, mp_start_datetime_4.time(), mp_start_datetime_4.date(), 48 * 60, 1535) # message_objects.MPMultiUserRequest(0000, "23:30", "Monday", 5), # message_objects.MPMultiUserRequest(0000, "23:30", "Tuesday", 5), # message_objects.MPMultiUserRequest(0000, "23:30", "Wednesday", 5), # message_objects.MPMultiUserRequest(0000, "23:30", "Thursday", 5), # message_objects.MPMultiUserRequest(0000, "23:30", "Friday", 5), # message_objects.MPMultiUserRequest(0000, "23:30", "Saturday", 5), message_objects.MPMultiUserRequest(0000, "17:10", "Monday", 10) ] ''' All of the messages where the bp consumer will cycle through ''' bp_start_datetime = support.from_unix_timestamp_to_datetime(1415976546) TEST_BP_MESSAGES = [message_objects.BPSingleLinkRequest(1, bp_start_datetime.time(), bp_start_datetime.date(), 12)] ''' How long to wait between sending each message within the consumer in seconds ''' WAIT_BETWEEN_SENDS_MP = 1500 #In seconds WAIT_BETWEEN_SENDS_BP = 20 #In seconds ''' Configuration of the names for the test_maas db layout. Used within test_db_layout ''' TEST_MAAS_DB = "test_maas" TEST_MAAS_USER_INFO_TABLE = "test_user_info" TEST_MAAS_FLOW_DATA_TABLE = "test_flow_data"
TEST_MP_MESSAGES = [ # message_objects.MPSingleUserRequest(5980, mp_start_datetime_1.time(), mp_start_datetime_1.date(), 1 * 60, 12963) #, message_objects.MPSingleUserRequest(5980, mp_start_datetime_2.time(), mp_start_datetime_2.date(), 20 * 60, 12963) #, message_objects.MPSingleUserRequest(5963, mp_start_datetime_3.time(), mp_start_datetime_3.date(), 55 * 60, 3729) #, message_objects.MPSingleUserRequest(5974, mp_start_datetime_4.time(), mp_start_datetime_4.date(), 48 * 60, 1535) # message_objects.MPMultiUserRequest(0000, "23:30", "Monday", 5), # message_objects.MPMultiUserRequest(0000, "23:30", "Tuesday", 5), # message_objects.MPMultiUserRequest(0000, "23:30", "Wednesday", 5), # message_objects.MPMultiUserRequest(0000, "23:30", "Thursday", 5), # message_objects.MPMultiUserRequest(0000, "23:30", "Friday", 5), # message_objects.MPMultiUserRequest(0000, "23:30", "Saturday", 5), message_objects.MPMultiUserRequest(0000, "17:10", "Monday", 10) ] ''' All of the messages where the bp consumer will cycle through ''' bp_start_datetime = support.from_unix_timestamp_to_datetime(1415976546) TEST_BP_MESSAGES = [ message_objects.BPSingleLinkRequest(1, bp_start_datetime.time(), bp_start_datetime.date(), 12) ] ''' How long to wait between sending each message within the consumer in seconds ''' WAIT_BETWEEN_SENDS_MP = 1500 #In seconds WAIT_BETWEEN_SENDS_BP = 20 #In seconds ''' Configuration of the names for the test_maas db layout. Used within test_db_layout ''' TEST_MAAS_DB = "test_maas" TEST_MAAS_USER_INFO_TABLE = "test_user_info"