KỸ THUẬT LẬP LỊCH TRONG LTE
6. Đoạn mã chương trình chính
[ BLER_curves CQI_mapper ] = LTE_init_load_BLER_curves;
if strcmp(LTE_config.network_source, 'generated')
[eNodeBs eNodeBs_sectors networkPathlossMap networkShadowFadingMap] = LTE_init_network_generation;
else
[eNodeBs eNodeBs_sectors networkPathlossMap] = LTE_init_network_generation;
end
LTE_config.target_sector = LTE_common_get_target_sector(eNodeBs,networkPathlossMap);
if exist('networkShadowFadingMap','var')
[LTE_config.capacity_no_shadowing sector_SINR_no_shadowing] =
LTE_common_calculate_cell_capacity(networkPathlossMap,eNodeBs,CQI_mapper);
[LTE_config.capacity sector_SINR ] =
LTE_common_calculate_cell_capacity(networkPathlossMap,eNodeBs,CQI_mapper,networkShadowFading Map);
else
LTE_config.capacity sector_SINR ] =
LTE_common_calculate_cell_capacity(networkPathlossMap,eNodeBs,CQI_mapper);
end
if LTE_config.show_network>0
if exist('networkShadowFadingMap','var')
LTE_plot_sector_SINR_cdfs(sector_SINR,sector_SINR_no_shadowing);
LTE_plot_loaded_network(eNodeBs,networkPathlossMap,networkShadowFadingMap);
else
LTE_plot_sector_SINR_cdfs(sector_SINR);
if ~isfield(LTE_config,'show_capesso_network')
LTE_plot_loaded_network(eNodeBs,networkPathlossMap);
end end end
networkClock = network_elements.clock(LTE_config.TTI_length);
for b_=1:length(eNodeBs)
eNodeBs(b_).clock = networkClock;
end
UEs = LTE_init_generate_users(eNodeBs,networkPathlossMap);
ff_file_exists = exist(LTE_config.pregenerated_ff_file,'file');
if LTE_config.recalculate_fast_fading || (~ff_file_exists && ~LTE_config.recalculate_fast_fading) print_log(1,['Generating UE fast fading and saving to ' LTE_config.pregenerated_ff_file '\n']);
pregenerated_ff = LTE_init_get_microscale_fading_SL_trace;
save(LTE_config.pregenerated_ff_file,'pregenerated_ff','-v7.3');
else
print_log(1,['Loading UE fast fading from ' LTE_config.pregenerated_ff_file '\n']);
load(LTE_config.pregenerated_ff_file,'pregenerated_ff');
if LTE_config.nTX~=pregenerated_ff.nTX || LTE_config.nRX~=pregenerated_ff.nRX error('Trace is for a %dx%d system. Config defines a %dx%d
system.',pregenerated_ff.nTX,pregenerated_ff.nRX,LTE_config.nTX,LTE_config.nRX);
end
if LTE_config.bandwidth ~= pregenerated_ff.system_bandwidth
error('Loaded FF trace is not at the correct frequency: %3.2f MHz required, %3.2f MHz found',LTE_config.bandwidth/1e6,pregenerated_ff.system_bandwidth/1e6);
end
if (pregenerated_ff.UE_speed~=LTE_config.UE_speed) && ~isnan(pregenerated_ff.UE_speed) error('Loaded FF trace is generated at %3.2f m/s. UE speed is %3.2f m/s. Trace cannot be
used.',pregenerated_ff.UE_speed,LTE_config.UE_speed);
end
if isnan(pregenerated_ff.UE_speed)
print_log(1,sprintf('Microscale fading trace is speed-independent\n'));
else
print_log(1,sprintf('UE Fast fading trace at %3.2f m/s (%3.2f Km/h)\n',pregenerated_ff.UE_speed,pregenerated_ff.UE_speed*3.6));
end end
for u_=1:length(UEs)
UEs(u_).downlink_channel = channel_models.downlinkChannelModel(UEs(u_));
UEs(u_).downlink_channel.set_macroscopic_pathloss_model(networkPathlossMap);
if ~strcmp(LTE_config.network_source,'capesso')
UEs(u_).downlink_channel.set_shadow_fading_model(networkShadowFadingMap);
end
UEs(u_).downlink_channel.set_fast_fading_model_model(channel_gain_wrappers.fastFadingWrapper(prege nerated_ff,'random',length(eNodeBs),length(eNodeBs(1).sectors)));
switch LTE_config.SINR_averaging.algorithm case 'MIESM'
UEs(u_).SINR_averager =
utils.miesmAveragerFast(LTE_config.SINR_averaging.BICM_capacity_tables,LTE_config.SINR_averaging .betas);
case 'EESM'
UEs(u_).SINR_averager =
utils.eesmAverager(LTE_config.SINR_averaging.betas,LTE_config.SINR_averaging.MCSs);
otherwise
error('SINR averaging algorithm not supported');
end
UEs(u_).eNodeB_signaling = network_elements.eNodebSignaling;
UEs(u_).nRX = LTE_config.nRX;
UEs(u_).downlink_channel.thermal_noise_watts_RB =
10^(0.1*LTE_config.UE.thermal_noise_density)/1000 * LTE_config.RB_bandwidth;
UEs(u_).downlink_channel.thermal_noise_dBW_RB = 10*log10(UEs(u_).downlink_channel.thermal_noise_watts_RB);
UEs(u_).BLER_curves = BLER_curves;
UEs(u_).uplink_channel = channel_models.uplinkChannelModel(...
UEs(u_),...
LTE_config.N_RB,...
LTE_config.maxStreams,...
LTE_config.feedback_channel_delay);
UEs(u_).clock = networkClock;
UEs(u_).CQI_mapper = CQI_mapper;
if LTE_config.unquantized_CQI_feedback UEs(u_).unquantized_CQI_feedback = true;
end end
LTE_init_add_schedulers(eNodeBs,UEs,CQI_mapper,BLER_curves);
simulation_traces = tracing.simTraces;
simulation_traces.eNodeB_rx_feedback_traces = tracing.receivedFeedbackTrace(...
LTE_config.simulation_time_tti,...
length(UEs),...
LTE_config.N_RB,...
LTE_config.maxStreams,...
LTE_config.traces_config.unquantized_CQI_feedback);
for b_=1:length(eNodeBs)
for s_=1:length(eNodeBs(b_).sectors)
eNodeBs(b_).sectors(s_).feedback_trace = simulation_traces.eNodeB_rx_feedback_traces;
scheduler_trace = tracing.schedulerTrace(LTE_config.simulation_time_tti);
eNodeBs(b_).sectors(s_).scheduler.trace = scheduler_trace;
simulation_traces.scheduler_traces{b_,s_} = scheduler_trace;
end end
simulation_traces.eNodeB_tx_traces =
tracing.enodebTrace(eNodeBs(1),UEs(1).downlink_channel.RB_grid,LTE_config.maxStreams,LTE_config.
simulation_time_tti);
for b_=2:length(eNodeBs)
simulation_traces.eNodeB_tx_traces(b_) =
tracing.enodebTrace(eNodeBs(b_),UEs(1).downlink_channel.RB_grid,LTE_config.maxStreams,LTE_config .simulation_time_tti);
end
for u_=1:length(UEs) UEs(u_).trace =
tracing.ueTrace(LTE_config.simulation_time_tti,LTE_config.N_RB,LTE_config.maxStreams,LTE_config.tr aces_config,LTE_config.latency_time_scale,LTE_config.TTI_length);
if u_==1
simulation_traces.UE_traces = UEs(u_).trace;
else
simulation_traces.UE_traces(u_) = UEs(u_).trace;
end end
for b_=1:length(eNodeBs)
for s_=1:length(eNodeBs(b_).sectors)
eNodeBs(b_).sectors(s_).scheduler.UE_traces = simulation_traces.UE_traces;
end end
print_log(2,'eNodeB List\n');
if LTE_config.debug_level >=2 for b_=1:length(eNodeBs) eNodeBs(b_).print;
end end
print_log(2,'\n');
print_log(2,'User List\n');
if LTE_config.debug_level >=2 for u_=1:length(UEs) UEs(u_).print;
end end
print_log(2,'\n');
print_log(1,['Entering main simulation loop, ' num2str(LTE_config.simulation_time_tti,'%5.0f') ' TTIs\n']);
tic;
starting_time = toc;
while networkClock.current_TTI < LTE_config.simulation_time_tti networkClock.advance_1_TTI;
if LTE_config.show_network>1 || networkClock.current_TTI==1
LTE_plot_show_network(eNodeBs,UEs,LTE_config.map_resolution,networkClock.current_TTI);
end
for u_ = 1:length(UEs) UEs(u_).move;
[ x_range y_range ] = networkPathlossMap.valid_range;
if ~UEs(u_).is_in_roi(x_range,y_range)
new_UE_position = networkPathlossMap.random_position;
old_UE_position = UEs(u_).pos;
old_eNodeB_id = UEs(u_).attached_eNodeB.id;
[new_eNodeB_id new_eNodeB_sector] = networkPathlossMap.cell_assignment(new_UE_position);
UEs(u_).pos = new_UE_position;
UEs(u_).start_handover(eNodeBs(new_eNodeB_id),new_eNodeB_sector);
if LTE_config.show_network>1
scatter(new_UE_position(1),new_UE_position(2),'Marker','o','MarkerEdgeColor','green');
pause(0.1) end
print_log(2,['TTI ' num2str(networkClock.current_TTI) ': UE ' num2str(UEs(u_).id) ' going out of ROI, teleporting to ' num2str(new_UE_position(1)) ' ' num2str(new_UE_position(2)) '. eNodeB '
num2str(old_eNodeB_id) ' -> eNodeB ' num2str(new_eNodeB_id) '\n']);
end end
if ~mod(networkClock.current_TTI,500)
LTE_plot_show_network(eNodeBs,UEs,LTE_config.map_resolution,networkClock.current_TTI);
end
if LTE_config.feedback_channel_delay==0 for u_ = 1:length(UEs)
UEs(u_).link_quality_model(LTE_config);
end end
for b_ = 1:length(eNodeBs)
eNodeBs(b_).receive_UE_feedback;
eNodeBs(b_).schedule_users;
end
if LTE_config.feedback_channel_delay~=0 for u_ = 1:length(UEs)
UEs(u_).link_quality_model(LTE_config);
end end
for u_ = 1:length(UEs)
UEs(u_).link_performance_model;
UEs(u_).send_feedback;
end
if mod(networkClock.current_TTI,50)==0 elapsed_time = toc;
time_per_iteration = elapsed_time / networkClock.current_TTI;
estimated_time_to_finish = (LTE_config.simulation_time_tti - networkClock.current_TTI)*time_per_iteration;
estimated_time_to_finish_h = floor(estimated_time_to_finish/3600);
estimated_time_to_finish_m = estimated_time_to_finish/60 - estimated_time_to_finish_h*60;
fprintf('Time to finish: %3.0f hours and %3.2f
minutes\n',estimated_time_to_finish_h,estimated_time_to_finish_m);
end end
print_log(1,'Simulation finished\n');
if LTE_config.delete_ff_trace_at_end pregenerated_ff.traces = [];
end
if LTE_config.delete_pathloss_at_end networkPathlossMap.pathloss = [];
networkPathlossMap.sector_assignment = [];
networkPathlossMap.sector_assignment_no_shadowing = [];
if exist('networkShadowFadingMap','var') networkPathlossMap.pathloss = [];
else
% Do nothing end
end
print_log(1,['Saving results to ' LTE_config.results_file '\n']);
save(LTE_config.results_file);
print_log(1,'OK \n');