def plot_outboxes(self, print_node=None, annotation=None): thesismain.init_plot() # plot outboxes stats = self.csv.name.str.startswith('OutboxLength') outbox_lengths = self.csv[self.run & self.modules & stats] for row in outbox_lengths.itertuples(): node = row.module.split('.')[1] outbox = row.name.split('.')[1] if print_node is None or node == print_node: plt.plot(row.vectime, row.vecvalue, label=outbox, linewidth=0.9, markevery=0.1) if outbox == 'node[1]': print(len(row.vectime)) print(row.vecvalue[-1]) plt.ylim(top=260) axes = plt.axes() axes.set_yticks([0, 100, 200, 250]) if annotation == 'LowHealthAttack': plt.annotate('dropped', xy=(17, 250), xycoords='data', xytext=(25, 200), textcoords='data', arrowprops=dict(arrowstyle="->"), horizontalalignment='right', verticalalignment='top', ) plt.ylabel('messages') plt.xlabel('time (s)') plt.legend(bbox_to_anchor=(-0.12, 1.1, 1.14, .102), loc='lower left', ncol=5, mode="expand") thesismain.save_plot('plots/%s_%s_%s' % ('attack', 'outboxes', self.config_name))
def thesismain_micro_available_processing(self, annotation=None): thesismain.init_plot() stats = self.csv.name == 'AvailableProcessingRate' available_processing = self.csv[self.run & self.modules & stats] for row in available_processing.itertuples(): node = row.module.split('.')[1] # find max's index and max value # print(np.where(row.vecvalue == row.vecvalue.max())[0][0], row.vecvalue.max()) plt.plot(row.vectime, row.vecvalue, label=node, linewidth=0.9, markevery=0.1) # -> 89 845.0 if annotation == 'Scenario2': plt.ylim(bottom=-5, top=310) plt.annotate('845 MPS', xy=(89, 302), xycoords='data', xytext=(129, 299), textcoords='data', arrowprops=dict(arrowstyle="->"), horizontalalignment='right', verticalalignment='top', ) else: plt.ylim(bottom=-5) plt.ylabel('throughput (MPS)') plt.xlabel('time (s)') thesismain.save_plot('plots/%s_%s_%s' % ('micro', 'available-processing', self.config_name))
def thesismain_micro_latency(self): msgs_df = self.all_messages.copy() difference_suffix = '_difference' # calculate latency for every message on every node for node in self.all_nodes: msgs_df[node + difference_suffix] = msgs_df[node].subtract(msgs_df['time']) cdfs = {} nodes_in_sync = [] msgs_count = msgs_df.shape[0] for node in self.all_nodes: cdf_df = self.calculate_cdf(msgs_df, node) cdfs[node] = cdf_df msgs_node_missing = msgs_df[node].isnull().sum() if msgs_node_missing < msgs_count * 0.05: nodes_in_sync.append(node) thesismain.init_plot() # plot for node in self.all_nodes: cdf_df = cdfs[node] plt.plot(cdf_df[node + difference_suffix], cdf_df['cdf'], label=node, linewidth=0.9, markevery=0.2) plt.ylim(bottom=-0.02, top=1.02) plt.xlim(left=-0.2, right=6.2) plt.ylabel('cdf') plt.xlabel('time (s)') thesismain.save_plot('plots/%s_%s_%s' % ('micro', 'latency', self.config_name))
def thesismain_micro_inbox_solidification_buffer(self, annotation=None): thesismain.init_plot((16, 4)) stats = self.csv.name == 'TotalInbox' inbox_lengths = self.csv[self.run & self.modules & stats] for row in inbox_lengths.itertuples(): node = row.module.split('.')[1] plt.plot(row.vectime, row.vecvalue, label=node, linewidth=0.9, markevery=0.5) # find a specific point in a node's graph # if node == 'node[4]': # print(np.where(row.vecvalue == 250)[0][-1]) # print(row.vectime[np.where(row.vecvalue == 250)[0][-1]]) if annotation == 'Scenario2': plt.annotate('out-of-sync', xy=(54, 250), xycoords='data', xytext=(75, 190), textcoords='data', arrowprops=dict(arrowstyle="->"), horizontalalignment='right', verticalalignment='top', ) plt.annotate('out-of-sync', xy=(120, 250), xycoords='data', xytext=(135, 190), textcoords='data', arrowprops=dict(arrowstyle="->"), horizontalalignment='right', verticalalignment='top', ) plt.ylim(bottom=-5, top=260) plt.ylabel('messages') plt.xlabel('time (s)') plt.legend(bbox_to_anchor=(-0.17, 1.1, 1.2, .102), loc='lower left', ncol=10, mode="expand") thesismain.save_plot('plots/%s_%s_%s' % ('micro', 'inbox', self.config_name))
def plot_allowed_receiving_rate(self, print_node=None, malicious_node=None, annotation=None): thesismain.init_plot() # plot inboxes stats = self.csv.name == 'AllowedReceivingRate' allowed_receiving_rate = self.csv[self.run & self.modules & stats] print_node_values = None for row in allowed_receiving_rate.itertuples(): node = row.module.split('.')[1] if print_node is None or print_node == node: print_node_values = row.vecvalue plt.plot(row.vectime, row.vecvalue, label='allowed', linewidth=1.7, markevery=0.2) # plot actual receiving rate stats = self.csv.name.str.startswith('ReceivingRate') actual_receiving_rates = self.csv[self.run & self.modules & stats] for row in actual_receiving_rates.itertuples(): receiver = row.module.split('.')[1] sender = row.name.split('.')[1] if print_node is None or print_node == receiver: # find a specific point in a node's graph # if sender == 'node[7]': # print(len(row.vectime)) # print(row.vecvalue[-1]) # if malicious_node == sender: # for count, val in enumerate(row.vecvalue): # if len(print_node_values) > count: # if val > print_node_values[count]: # print('%d: %0.2f %0.2f <--' % (count, print_node_values[count], val)) # else: # print('%d: %0.2f %0.2f' % (count, print_node_values[count], val)) plt.plot(row.vectime, row.vecvalue, label=('%s' % (sender)), linewidth=0.9) # plt.ylim(bottom=-5, top=260) if annotation == 'ExceedSendingRateAttack': plt.annotate('dropped', xy=(20, 110.66), xycoords='data', xytext=(27, 60), textcoords='data', arrowprops=dict(arrowstyle="->"), horizontalalignment='right', verticalalignment='top', ) elif annotation == 'SubceedSendingRateAttack': plt.annotate('dropped', xy=(48, 10), xycoords='data', xytext=(60, 40), textcoords='data', arrowprops=dict(arrowstyle="->"), horizontalalignment='right', verticalalignment='top', ) plt.ylabel('rate (MPS)') plt.xlabel('time (s)') # plt.legend(bbox_to_anchor=(-0.12, 1.1, 1.14, .102), loc='lower left', ncol=5, mode="expand") thesismain.save_plot('plots/%s_%s_%s' % ('attack', 'receiving_rate', self.config_name))
def thesismain_micro_throughput(self, annotation=None): thesismain.init_plot() msgs_df = self.all_messages.copy() # determine how many nodes were in sync and average total_count = None total_in_sync_nodes = None total_division = None # plot nodes for node in self.all_nodes: label = node count, division = np.histogram(msgs_df[node], bins=range(self.simulation_time)) plt.plot(division, np.concatenate(([0], count)), linewidth=0.9, markevery=0.1) # find a specific point in a node's graph # if node == 'node[6]': # print(np.where(count == 0)) # sum up for throughput average if total_count is not None: total_count += count total_in_sync_nodes += (count > 0).astype(int) else: total_count = count total_in_sync_nodes = (count > 0).astype(int) total_division = division # determine average total_count = total_count / total_in_sync_nodes # plot average plt.plot(total_division, np.concatenate(([0], total_count)), label='mean', linewidth=1.3, markevery=0.1) # print mean value of average print('Throughput avg mean: %.2f' % np.mean(total_count)) if annotation == 'Scenario1': plt.annotate('out-of-sync', xy=(43, 0), xycoords='data', xytext=(85, 25), textcoords='data', arrowprops=dict(arrowstyle="->"), horizontalalignment='right', verticalalignment='top', ) elif annotation == 'Scenario2': plt.annotate('out-of-sync', xy=(54, 0), xycoords='data', xytext=(96, 25), textcoords='data', arrowprops=dict(arrowstyle="->"), horizontalalignment='right', verticalalignment='top', ) plt.annotate('out-of-sync', xy=(120, 0), xycoords='data', xytext=(166, 25), textcoords='data', arrowprops=dict(arrowstyle="->"), horizontalalignment='right', verticalalignment='top', ) plt.ylim(bottom=-5, top=160) plt.ylabel('throughput (MPS)') plt.xlabel('time (s)') # plt.legend(bbox_to_anchor=(-0.12, 1.1, 1.14, .102), loc='lower left', ncol=5, mode="expand") plt.legend() thesismain.save_plot('plots/%s_%s_%s' % ('micro', 'throughput', self.config_name))