Skip to content

Commit

Permalink
Agents - New structure for exchanging information with APs
Browse files Browse the repository at this point in the history
We divided the information into "node_configuration", which includes the capabilities and the current configuration, and "performance_report", which includes the values for different performance metrics (throughput, collisions, etc.). This closes #89
  • Loading branch information
fwilhelmi committed Feb 19, 2018
1 parent eeb304f commit 8d6419f
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 89 deletions.
33 changes: 19 additions & 14 deletions Code/main/agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

#include "../list_of_macros.h"
#include "../structures/node_configuration.h"
#include "../structures/performance_report.h"
#include "../structures/action.h"
#include "../methods/auxiliary_methods.h"
#include "../methods/agent_methods.h"
Expand Down Expand Up @@ -125,6 +126,8 @@ component Agent : public TypeII{
Configuration configuration;
Configuration new_configuration;

Report report;

// File for writting node logs
FILE *output_log_file; // File for logs in which the agent is involved
char own_file_path[32]; // Name of the file for agent logs
Expand All @@ -135,7 +138,7 @@ component Agent : public TypeII{
public:

// INPORT connections for receiving notifications
inport void inline InportReceivingInformationFromAp(Configuration &configuration);
inport void inline InportReceivingInformationFromAp(Configuration &configuration, Report &report);

// OUTPORT connections for sending notifications
outport void outportRequestInformationToAp();
Expand Down Expand Up @@ -234,7 +237,7 @@ void Agent :: RequestInformationToAp(trigger_t &){
* Input arguments:
* - to be defined
*/
void Agent :: InportReceivingInformationFromAp(Configuration &received_configuration){
void Agent :: InportReceivingInformationFromAp(Configuration &received_configuration, Report &received_report){

// printf("%s Agent #%d: Message received from the AP\n", LOG_LVL1, agent_id);

Expand All @@ -246,14 +249,16 @@ void Agent :: InportReceivingInformationFromAp(Configuration &received_configura

configuration = received_configuration;

report = received_report;

if(save_agent_logs) fprintf(agent_logger.file, "%.15f;A%d;%s;%s Current conf (Tx Power) = %f dBm\n",
SimTime(), agent_id, LOG_C00, LOG_LVL2, ConvertPower(PW_TO_DBM,configuration.selected_tx_power));

if(save_agent_logs) fprintf(agent_logger.file, "%.15f;A%d;%s;%s throughput = %f dBm\n",
SimTime(), agent_id, LOG_C00, LOG_LVL2, configuration.report.throughput);
SimTime(), agent_id, LOG_C00, LOG_LVL2, report.throughput);

if(save_agent_logs) fprintf(agent_logger.file, "%.15f;A%d;%s;%s max_bound_throughput = %f dBm\n",
SimTime(), agent_id, LOG_C00, LOG_LVL2, configuration.report.max_bound_throughput);
SimTime(), agent_id, LOG_C00, LOG_LVL2, report.max_bound_throughput);

// Generate the reward for the last selected action
GenerateRewardSelectedArm();
Expand Down Expand Up @@ -377,8 +382,8 @@ void Agent :: GenerateRewardSelectedArm() {
* that can be sent in each interval (e.g., packets that were sent but lost)
*/
case REWARD_TYPE_PACKETS_SENT:{
reward = configuration.report.data_packets_sent /
configuration.report.data_packets_lost;
reward = report.data_packets_sent /
report.data_packets_lost;
break;
}

Expand All @@ -389,18 +394,18 @@ void Agent :: GenerateRewardSelectedArm() {
*/
case REWARD_TYPE_THROUGHPUT:{

if (configuration.report.max_bound_throughput == 0) {
if (report.max_bound_throughput == 0) {
reward = 0;
} else {
reward = configuration.report.throughput /
configuration.report.max_bound_throughput;
reward = report.throughput /
report.max_bound_throughput;
}

if(save_agent_logs) fprintf(agent_logger.file, "%.15f;A%d;%s;%s throughput = %f dBm\n",
SimTime(), agent_id, LOG_C00, LOG_LVL2, configuration.report.throughput);
SimTime(), agent_id, LOG_C00, LOG_LVL2, report.throughput);

if(save_agent_logs) fprintf(agent_logger.file, "%.15f;A%d;%s;%s max_bound_throughput = %f dBm\n",
SimTime(), agent_id, LOG_C00, LOG_LVL2, configuration.report.max_bound_throughput);
SimTime(), agent_id, LOG_C00, LOG_LVL2, report.max_bound_throughput);

if(save_agent_logs) fprintf(agent_logger.file, "%.15f;A%d;%s;%s reward = %f\n",
SimTime(), agent_id, LOG_C00, LOG_LVL2, reward);
Expand All @@ -412,9 +417,9 @@ void Agent :: GenerateRewardSelectedArm() {
* -
*/
case REWARD_TYPE_PACKETS_GENERATED:{
reward = (configuration.report.num_packets_generated -
configuration.report.num_packets_dropped) /
configuration.report.num_packets_generated;
reward = (report.num_packets_generated -
report.num_packets_dropped) /
report.num_packets_generated;
break;
}

Expand Down
2 changes: 1 addition & 1 deletion Code/main/compcxx_komondor_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ typedef void (compcxx_component::*Node_outportSelfFinishTX_f_t)(Notification &n
typedef void (compcxx_component::*Node_outportSendLogicalNack_f_t)(LogicalNack &logical_nack_info);
typedef void (compcxx_component::*Node_outportAskForTxModulation_f_t)(Notification &notification);
typedef void (compcxx_component::*Node_outportAnswerTxModulation_f_t)(Notification &notification);
typedef void (compcxx_component::*Node_outportAnswerToAgent_f_t)(Configuration &configuration);
typedef void (compcxx_component::*Node_outportAnswerToAgent_f_t)(Configuration &configuration, Report &report);
typedef void (compcxx_component::*Node_outportSetNewWlanConfiguration_f_t)(Configuration &new_configuration);
};
Binary file modified Code/main/komondor_main
Binary file not shown.
65 changes: 37 additions & 28 deletions Code/main/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#include "../structures/logger.h"
#include "../structures/FIFO.h"
#include "../structures/node_configuration.h"
#include "../structures/performance_report.h"

// Node component: "TypeII" represents components that are aware of the existence of the simulated time.
component Node : public TypeII{
Expand Down Expand Up @@ -116,6 +117,7 @@ component Node : public TypeII{

// Configuration (to be sent to the agent)
void GenerateConfiguration();
void GeneratePerformanceReport();
void ApplyNewConfiguration(Configuration &received_configuration);
void BroadcastNewConfigurationToStas(Configuration &received_configuration);
void RestartPerformanceMetrics();
Expand Down Expand Up @@ -320,6 +322,8 @@ component Node : public TypeII{
Configuration configuration;
Configuration new_configuration;

Report performance_report;

// Measurements done for agents
double last_time_measured;
int last_measurement_throughput;
Expand Down Expand Up @@ -358,7 +362,7 @@ component Node : public TypeII{
outport void outportAskForTxModulation(Notification &notification);
outport void outportAnswerTxModulation(Notification &notification);

outport void outportAnswerToAgent(Configuration &configuration);
outport void outportAnswerToAgent(Configuration &configuration, Report &report);
outport void outportSetNewWlanConfiguration(Configuration &new_configuration);

// Triggers
Expand Down Expand Up @@ -3174,24 +3178,8 @@ void Node :: GenerateConfiguration(){
capabilities.channel_bonding_model = channel_bonding_model;
capabilities.modulation_default = modulation_default;

// Report
Report report;

last_measurement_throughput = (((double)(last_measurement_data_packets_sent-last_measurement_data_packets_lost)
* packet_length * num_packets_aggregated)) / (SimTime()-last_time_measured);

report.throughput = last_measurement_throughput;
report.max_bound_throughput = last_measurement_max_bound_throughput;
report.data_packets_sent = last_measurement_data_packets_sent;
report.data_packets_lost = last_measurement_data_packets_lost;
report.rts_cts_packets_sent = last_measurement_rts_cts_packets_sent;
report.rts_cts_packets_lost = last_measurement_rts_cts_packets_lost;
report.num_packets_generated = last_measurement_num_packets_generated;
report.num_packets_dropped = last_measurement_num_packets_dropped;

// Configuration
configuration.capabilities = capabilities;
configuration.report = report;

// if (node_id == 0) {
// printf("current_left_channel = %d\n",
Expand All @@ -3214,6 +3202,31 @@ void Node :: GenerateConfiguration(){

}

/*
* GeneratePerformanceReport: encapsulates the performance of a node to be sent
**/
void Node :: GeneratePerformanceReport(){

last_measurement_throughput = (((double)(last_measurement_data_packets_sent-last_measurement_data_packets_lost)
* packet_length * num_packets_aggregated)) / (SimTime()-last_time_measured);

performance_report.throughput = last_measurement_throughput;
performance_report.max_bound_throughput = last_measurement_max_bound_throughput;
performance_report.data_packets_sent = last_measurement_data_packets_sent;
performance_report.data_packets_lost = last_measurement_data_packets_lost;
performance_report.rts_cts_packets_sent = last_measurement_rts_cts_packets_sent;
performance_report.rts_cts_packets_lost = last_measurement_rts_cts_packets_lost;
performance_report.num_packets_generated = last_measurement_num_packets_generated;
performance_report.num_packets_dropped = last_measurement_num_packets_dropped;

// Restart performance metrics for future requests
if(save_node_logs) fprintf(node_logger.file, "%.15f;N%d;S%d;%s;%s Restarting performance metrics (to be updated on the next request)\n",
SimTime(), node_id, node_state, LOG_F02, LOG_LVL2);

RestartPerformanceMetrics();

}

/*
* InportReceivingRequestFromAgent(): called when some agent answers for information to the AP
* Input arguments:
Expand All @@ -3227,24 +3240,20 @@ void Node :: InportReceivingRequestFromAgent() {
if(save_node_logs) fprintf(node_logger.file, "%.15f;N%d;S%d;%s;%s New information request received from the Agent\n",
SimTime(), node_id, node_state, LOG_F02, LOG_LVL2);

// Generate configuration to be sent to the agent
// Generate the configuration to be sent to the agent
if(save_node_logs) fprintf(node_logger.file, "%.15f;N%d;S%d;%s;%s Generating configuration to be answered\n",
SimTime(), node_id, node_state, LOG_F02, LOG_LVL2);
GenerateConfiguration();

// Answer to the agent
if(save_node_logs) fprintf(node_logger.file, "%.15f;N%d;S%d;%s;%s Answering to the agent with current information\n",
// Generate the performance report to be sent to the agent
if(save_node_logs) fprintf(node_logger.file, "%.15f;N%d;S%d;%s;%s Generating report to be answered\n",
SimTime(), node_id, node_state, LOG_F02, LOG_LVL2);
outportAnswerToAgent(configuration);
GeneratePerformanceReport();

// configuration.PrintConfiguration(ORIGIN_AGENT);
// configuration.report.PrintReport();

// Restart performance metrics for future requests
if(save_node_logs) fprintf(node_logger.file, "%.15f;N%d;S%d;%s;%s Restarting performance metrics (to be updated on the next request)\n",
// Answer to the agent
if(save_node_logs) fprintf(node_logger.file, "%.15f;N%d;S%d;%s;%s Answering to the agent with current information\n",
SimTime(), node_id, node_state, LOG_F02, LOG_LVL2);

RestartPerformanceMetrics();
outportAnswerToAgent(configuration, performance_report);

if(save_node_logs) fprintf(node_logger.file, "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");

Expand Down
55 changes: 9 additions & 46 deletions Code/structures/node_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,6 @@
#ifndef _AUX_CONFIGURATION_
#define _AUX_CONFIGURATION_

struct Report
{

double throughput;
double max_bound_throughput;
int data_packets_sent;
int data_packets_lost;
int rts_cts_packets_sent;
int rts_cts_packets_lost;
double num_packets_generated;
double num_packets_dropped;

// Function to print the node's report
void PrintReport(void){

printf("%s Report:\n", LOG_LVL4);
printf("%s throughput = %f\n", LOG_LVL5, throughput);
printf("%s max_bound_throughput = %f\n", LOG_LVL5, max_bound_throughput);
printf("%s data_packets_sent = %d\n", LOG_LVL5, data_packets_sent);
printf("%s data_packets_lost = %d\n", LOG_LVL5, data_packets_lost);
printf("%s rts_cts_packets_sent = %d\n", LOG_LVL5, rts_cts_packets_sent);
printf("%s rts_cts_packets_lost = %d\n", LOG_LVL5, rts_cts_packets_lost);
printf("%s num_packets_generated = %f\n", LOG_LVL5, num_packets_generated);
printf("%s num_packets_dropped = %f\n", LOG_LVL5, num_packets_dropped);
printf("\n");

}

};

struct Capabilities
{
int node_id; // Node id
Expand Down Expand Up @@ -146,34 +116,27 @@ struct Configuration
double selected_cca; // Selected CCA ("sensitivity" threshold) [pW]
double selected_tx_power; // Selected Tx Power [pW]

Report report;
Capabilities capabilities;

// Function to print the node's configuration
void PrintConfiguration(int origin){

if (origin == ORIGIN_AGENT) {

printf("%s Recommended configuration by the agent:\n", LOG_LVL3);
printf("%s selected_primary = %d\n", LOG_LVL4, selected_primary);
printf("%s selected_left_channel = %d\n", LOG_LVL4, selected_left_channel);
printf("%s selected_right_channel = %d\n", LOG_LVL4, selected_right_channel);
printf("%s cca_default = %f pW (%f dBm)\n", LOG_LVL4, selected_cca, ConvertPower(PW_TO_DBM, selected_cca));
printf("%s tpc_default = %f pW (%f dBm)\n", LOG_LVL4, selected_tx_power, ConvertPower(PW_TO_DBM, selected_tx_power));

printf("\n");

} else if (origin == ORIGIN_AP) {

report.PrintReport();
//capabilities.PrintCapabilities();

printf("%s Current configuration of the WLAN:\n", LOG_LVL3);
} else {

printf("ERROR: bad origin\n");

}

printf("%s selected_primary = %d\n", LOG_LVL4, selected_primary);
printf("%s selected_left_channel = %d\n", LOG_LVL4, selected_left_channel);
printf("%s selected_right_channel = %d\n", LOG_LVL4, selected_right_channel);
printf("%s cca_default = %f pW (%f dBm)\n", LOG_LVL4, selected_cca, ConvertPower(PW_TO_DBM, selected_cca));
printf("%s tpc_default = %f pW (%f dBm)\n", LOG_LVL4, selected_tx_power, ConvertPower(PW_TO_DBM, selected_tx_power));

printf("\n");

}
};

Expand Down
82 changes: 82 additions & 0 deletions Code/structures/performance_report.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* Komondor IEEE 802.11ax Simulator
*
* Copyright (c) 2017, Universitat Pompeu Fabra.
* GNU GENERAL PUBLIC LICENSE
* Version 3, 29 June 2007
* Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*
* -----------------------------------------------------------------
*
* Author : Sergio Barrachina-Muñoz and Francesc Wilhelmi
* Created : 2016-12-05
* Updated : $Date: 2017/03/20 10:32:36 $
* $Revision: 1.0 $
*
* -----------------------------------------------------------------
* File description: this is the main Komondor file
*
* - This file defines a NOTIFICATION and provides basic displaying methods
*/

#ifndef _AUX_REPORT_
#define _AUX_REPORT_

struct Report
{

double throughput;
double max_bound_throughput;
int data_packets_sent;
int data_packets_lost;
int rts_cts_packets_sent;
int rts_cts_packets_lost;
double num_packets_generated;
double num_packets_dropped;

// Function to print the node's report
void PrintReport(void){

printf("%s Report:\n", LOG_LVL4);
printf("%s throughput = %f\n", LOG_LVL5, throughput);
printf("%s max_bound_throughput = %f\n", LOG_LVL5, max_bound_throughput);
printf("%s data_packets_sent = %d\n", LOG_LVL5, data_packets_sent);
printf("%s data_packets_lost = %d\n", LOG_LVL5, data_packets_lost);
printf("%s rts_cts_packets_sent = %d\n", LOG_LVL5, rts_cts_packets_sent);
printf("%s rts_cts_packets_lost = %d\n", LOG_LVL5, rts_cts_packets_lost);
printf("%s num_packets_generated = %f\n", LOG_LVL5, num_packets_generated);
printf("%s num_packets_dropped = %f\n", LOG_LVL5, num_packets_dropped);
printf("\n");

}

};

#endif

0 comments on commit 8d6419f

Please sign in to comment.