示例#1
0
static void keyevt(void *pt, struct loop_window *win, bool is_repeat, uint32_t ch, uint8_t mods) {
    if ( ch == LKEY_RIGHT ) {
        zipper_next(loop_window_get_zipper(win));
        update_window_name(win);
    } else if ( ch == LKEY_LEFT ) {
        zipper_prev(loop_window_get_zipper(win));
        update_window_name(win);
    } else if ( ch == 'q' ) {
        loop_set_quit();
    } else if ( ch == 'm' ) {
        struct glview *gl = loop_window_get_glview(win);
        gl->multidraw = !gl->multidraw;
    } else if ( ch == 'f' ) {
        loop_window_set_fullscreen(win, !loop_window_get_fullscreen(win));
    } else if ( ch == 'r' ) {
        glview_set_rotate(loop_window_get_glview(win), (mods & LMOD_SHIFT) ? 1 : -1);
    }
}
示例#2
0
int main(int argc, char **argv) {
    loop_initialize(&argc, &argv);

    struct loop_window **windows;
    if ( (windows = calloc(1, sizeof(struct loop_window *)*argc)) == NULL )
        err(1, "Couldn't allocate space for %d window pointers", argc);

    for (int i = 1; i < argc; i++) {
        printf("opening window for '%s'\n", argv[i]);
        windows[i] = loop_window_open(argv[i], NULL, NULL, keyevt);
        loop_window_incr(windows[i]);
        update_window_name(windows[i]);
    }
    
    loop_until_quit();

    ref_release_pool(); // last chance
    free(windows);

    return 0;
}
示例#3
0
int store_packet(void *config, const struct ipfix_message *ipfix_msg,
		const struct ipfix_template_mgr *template_mgr)
{
	(void) template_mgr;
	std::map<uint16_t, template_table*>::iterator table;
	struct fastbit_config *conf = (struct fastbit_config *) config;
	std::map<uint16_t, template_table*> *templates = NULL;
	std::map<uint16_t, template_table*> *old_templates = NULL; /* Templates to be removed */

	std::map<std::string, std::map<uint32_t, od_info>*> *od_infos = conf->od_infos;
	std::map<std::string, std::map<uint32_t, od_info>*>::iterator exporter_it;
	std::map<uint32_t, od_info>::iterator odid_it;

	static int rcnt = 0;

	uint16_t template_id;
	uint32_t odid = ntohl(ipfix_msg->pkt_header->observation_domain_id);
	struct input_info_network *input = (struct input_info_network *) ipfix_msg->input_info;

	int rc_flows = 0;
	uint64_t rc_flows_sum = 0;

	char exporter_ip_addr_tmp[INET6_ADDRSTRLEN];
	if (input->l3_proto == 6) { /* IPv6 */
		ipv6_addr_non_canonical(exporter_ip_addr_tmp, &(input->src_addr.ipv6));
	} else { /* IPv4 */
		inet_ntop(AF_INET, &(input->src_addr.ipv4.s_addr), exporter_ip_addr_tmp, INET_ADDRSTRLEN);
	}

	/* Convert to C++ string for use in `od_infos` data structure */
	std::string exporter_ip_addr (exporter_ip_addr_tmp);

	/* Find exporter in od_infos data structure */
	if ((exporter_it = od_infos->find(exporter_ip_addr)) == od_infos->end()) {
		MSG_INFO(msg_module, "Received data for new exporter: %s", exporter_ip_addr.c_str());

		/* Add new exporter to data structure */
		std::map<uint32_t, od_info> *new_exporter = new std::map<uint32_t, od_info>;
		od_infos->insert(std::make_pair(exporter_ip_addr, new_exporter));
		exporter_it = od_infos->find(exporter_ip_addr);
	}

	/* Find ODID in template_info data structure (under exporter) */
	if ((odid_it = exporter_it->second->find(odid)) == exporter_it->second->end()) {
		MSG_INFO(msg_module, "Received new ODID for exporter %s: %u", exporter_ip_addr.c_str(), odid);

		/* Add new ODID to data structure (under exporter) */
		od_info new_odid;
		new_odid.exporter_ip_addr = exporter_ip_addr;
		new_odid.path = generate_path(conf, exporter_ip_addr, odid);

		exporter_it->second->insert(std::make_pair(odid, new_odid));
		odid_it = exporter_it->second->find(odid);
	}

	templates = &(odid_it->second.template_info);

	/* Process all datasets in message */
	int i;
	for (i = 0 ; i < MSG_MAX_DATA_COUPLES && ipfix_msg->data_couple[i].data_set; i++) {	
		if (ipfix_msg->data_couple[i].data_template == NULL) {
			/* Skip data couples without templates */
			continue;
		}

		template_id = ipfix_msg->data_couple[i].data_template->template_id;

		/* If template (ID) is unknown, add it to the template map */
		if ((table = templates->find(template_id)) == templates->end()) {
			MSG_DEBUG(msg_module, "Received new template: %hu", template_id);
			template_table *table_tmp = new template_table(template_id, conf->buff_size);
			if (table_tmp->parse_template(ipfix_msg->data_couple[i].data_template, conf) != 0) {
				/* Template cannot be parsed, skip data set */
				delete table_tmp;
				continue;
			}
			
			templates->insert(std::pair<uint16_t, template_table*>(template_id, table_tmp));
			table = templates->find(template_id);
		} else {
			/* Check template time. On reception of a new template it is crucial to rewrite the old one. */
			if (ipfix_msg->data_couple[i].data_template->first_transmission > table->second->get_first_transmission()) {
				MSG_DEBUG(msg_module, "Received new template with already used template ID: %hu", template_id);

				/* Init map for old template if necessary */
				if (old_templates == NULL) {
					old_templates = new std::map<uint16_t,template_table*>;
				}

				/* Store old template */
				old_templates->insert(std::pair<uint16_t, template_table*>(table->first, table->second));

				/* Flush data */
				flush_data(conf, exporter_ip_addr, odid, old_templates);

				/* Remove rewritten template */
				delete table->second;
				delete old_templates;
				old_templates = NULL;

				/* Remove old template from current list */
				templates->erase(table);

				/* Add the new template */
				template_table *table_tmp = new template_table(template_id, conf->buff_size);
				if (table_tmp->parse_template(ipfix_msg->data_couple[i].data_template, conf) != 0) {
					/* Template cannot be parsed; skip data set */
					delete table_tmp;
					continue;
				}

				templates->insert(std::pair<uint16_t, template_table*>(template_id, table_tmp));
				table = templates->find(template_id);
				/* New template was created; create new directory if necessary */
			}
		}

		/* Check whether data has to be flushed before storing data record */
		bool flush_records = conf->records_window > 0 && rcnt > conf->records_window;
		bool flush_time = false;
		time_t now;
		if (conf->time_window > 0) {
			time(&now);
			flush_time = difftime(now, conf->last_flush) > conf->time_window;
		}

		if (flush_records || flush_time) {
			/* Flush data for all exporters and ODIDs */
			flush_all_data(conf);

			/* Time management differs between flush policies (records vs. time) */
			if (flush_records) {
				time(&(conf->last_flush));
			} else if (flush_time) {
				while (difftime(now, conf->last_flush) > conf->time_window) {
					conf->last_flush = conf->last_flush + conf->time_window;
				}
			}

			/* Update window name and path */
			update_window_name(conf);
			odid_it->second.path = generate_path(conf, exporter_ip_addr, (*odid_it).first);

			rcnt = 0;
			conf->new_dir = true;
		}

		/* Store this data record */
		rc_flows = (*table).second->store(ipfix_msg->data_couple[i].data_set, odid_it->second.path, conf->new_dir);
		if (rc_flows >= 0) {
			rc_flows_sum += rc_flows;
			rcnt += rc_flows;
		} else {
			/* No need for showing error message here, since it is already done 
			 * by store() in case of an error */
			// MSG_ERROR(msg_module, "An error occurred during FastBit table store; no records were stored");
		}
	}

	/* We've told all tables that the directory has changed */
	conf->new_dir = false;

	if (rc_flows_sum) {
		odid_it->second.flow_watch.add_flows(rc_flows_sum);
	}

	odid_it->second.flow_watch.update_seq_no(ntohl(ipfix_msg->pkt_header->sequence_number));
	return 0;
}