Example #1
0
/**
 * Initialize a configuration instance
 * @param instance pointer to cfg_instance
 */
void
cfg_add(struct cfg_instance *instance) {
  memset(instance, 0, sizeof(*instance));

  avl_init(&instance->io_tree, avl_comp_strcasecmp, false);
  avl_init(&instance->parser_tree, avl_comp_strcasecmp, false);
}
Example #2
0
struct ubus_peer *ubus_peer_new(const char *key, uint32_t id){
	struct ubus_peer *self = calloc(1, sizeof(struct ubus_peer)); 
	self->name = strdup(key); 
	self->id = id; 
	self->avl_name.key = self->name; 
	self->avl_id.key = &self->id; 
	avl_init(&self->objects, avl_strcmp, false, NULL); 
	avl_init(&self->peers, avl_strcmp, false, NULL); 
	return self; 
}
Example #3
0
/**
 * Add a new tc_entry to the tc tree
 *
 * @param (last)adr address of the entry
 * @return a pointer to the created entry
 */
static struct tc_entry *
olsr_add_tc_entry(const union olsr_ip_addr *adr)
{
#if !defined REMOVE_LOG_DEBUG
  struct ipaddr_str buf;
#endif
  struct tc_entry *tc;

  /*
   * Safety net against loss of the last main IP address.
   */
  if (olsr_ipcmp(&olsr_cnf->router_id, &all_zero) == 0) {
    return NULL;
  }

  OLSR_DEBUG(LOG_TC, "TC: add entry %s\n", olsr_ip_to_string(&buf, adr));

  tc = olsr_memcookie_malloc(tc_mem_cookie);
  if (!tc) {
    return NULL;
  }

  /* Fill entry */
  tc->addr = *adr;
  tc->vertex_node.key = &tc->addr;

  tc->mid_seq = -1;
  tc->hna_seq = -1;
  tc->tc_seq = -1;
  /*
   * Insert into the global tc tree.
   */
  avl_insert(&tc_tree, &tc->vertex_node);

  /*
   * Initialize subtrees for edges, prefixes, HNAs and MIDs.
   */
  avl_init(&tc->edge_tree, avl_comp_default, true, NULL);
  avl_init(&tc->prefix_tree, avl_comp_prefix_origin_default, false, NULL);
  avl_init(&tc->mid_tree, avl_comp_default, false, NULL);
  avl_init(&tc->hna_tree, avl_comp_prefix_default, false, NULL);

  /*
   * Add a rt_path for ourselves.
   */
  olsr_insert_routing_table(adr, 8 * olsr_cnf->ipsize, adr, OLSR_RT_ORIGIN_TC);

  return tc;
}
Example #4
0
void ecalloc_init(struct ecalloc *ecalloc, uint64_t size)
{
	struct ecalloc_header *header;
	avl_init(&ecalloc->free_tree, size_compare, move_item);
	avl_init(&ecalloc->used_tree, addr_compare, move_item);
	ecalloc->size = size;
	ecalloc->used = 0;
	header = safe_malloc(sizeof(struct ecalloc_header));
	header->addr = 0;
	header->size = size;
	header->flag = 0;
	header->prev = NULL;
	header->next = NULL;
	header->node = avl_insert(&ecalloc->free_tree, header);
	pthread_mutex_init(&ecalloc->mutex, NULL);
}
Example #5
0
static inline struct tc_device *tc_device_create(char *id)
{
    struct tc_device *d = tc_device_index_find(id, 0);

    if(!d) {
        debug(D_TC_LOOP, "TC: Creating device '%s'", id);

        d = callocz(1, sizeof(struct tc_device));

        d->id = strdupz(id);
        d->hash = simple_hash(d->id);
        d->enabled = (char)-1;

        avl_init(&d->classes_index, tc_class_compare);
        if(unlikely(tc_device_index_add(d) != d))
            error("plugin_tc: INTERNAL ERROR: removing device '%s' removed a different device.", d->id);

        if(!tc_device_root) {
            tc_device_root = d;
        }
        else {
            d->next = tc_device_root;
            tc_device_root->prev = d;
            tc_device_root = d;
        }
    }

    return(d);
}
Example #6
0
struct config *config_create(const char *section)
{
	debug(D_CONFIG, "Creating section '%s'.", section);

	struct config *co = calloc(1, sizeof(struct config));
	if(!co) fatal("Cannot allocate config");

	co->name = strdup(section);
	if(!co->name) fatal("Cannot allocate config.name");
	co->hash = simple_hash(co->name);

	pthread_rwlock_init(&co->rwlock, NULL);
	avl_init(&co->values_index, config_value_compare);

	config_index_add(co);

	// no need for string termination, due to calloc()

	pthread_rwlock_wrlock(&config_rwlock);

	struct config *co2 = config_root;
	if(co2) {
		while (co2->next) co2 = co2->next;
		co2->next = co;
	}
	else config_root = co;

	pthread_rwlock_unlock(&config_rwlock);

	return co;
}
Example #7
0
REGISTRY_PERSON *registry_person_allocate(const char *person_guid, time_t when) {
    debug(D_REGISTRY, "Registry: registry_person_allocate('%s'): allocating new person, sizeof(PERSON)=%zu", (person_guid)?person_guid:"", sizeof(REGISTRY_PERSON));

    REGISTRY_PERSON *p = mallocz(sizeof(REGISTRY_PERSON));
    if(!person_guid) {
        for(;;) {
            uuid_t uuid;
            uuid_generate(uuid);
            uuid_unparse_lower(uuid, p->guid);

            debug(D_REGISTRY, "Registry: Checking if the generated person guid '%s' is unique", p->guid);
            if (!dictionary_get(registry.persons, p->guid)) {
                debug(D_REGISTRY, "Registry: generated person guid '%s' is unique", p->guid);
                break;
            }
            else
                info("Registry: generated person guid '%s' found in the registry. Retrying...", p->guid);
        }
    }
    else
        strncpyz(p->guid, person_guid, GUID_LEN);

    debug(D_REGISTRY, "Registry: registry_person_allocate('%s'): creating dictionary of urls", p->guid);
    avl_init(&p->person_urls, person_url_compare);

    p->first_t = p->last_t = (uint32_t)when;
    p->usages = 0;

    registry.persons_memory += sizeof(REGISTRY_PERSON);

    registry.persons_count++;
    dictionary_set(registry.persons, p->guid, p, sizeof(REGISTRY_PERSON));

    return p;
}
Example #8
0
/**
* @brief test case for random number insert, search and delete.
*/
void testcase_for_random() {
	TREE T = avl_init();
	int taller = 0, lower = 0;
	int i = 0, n = 100;
	int _t = 0;
	srand(time(NULL));
	for (i = 0; i < n; i ++) {
		_t = rand() % n;
		printf("avl_insert(&T, %d) = %d\n", _t, avl_insert(&T, _t, &taller));
	}
	for (i = 0; i < n; i ++) {
		_t = rand() % n;
		printf("avl_search(T, %d) = %d\n", _t, avl_search(T, _t));
	}
	printf("avl_traveral: ");
	avl_traveral(T, printout_node);
	printf("\n");
	for (i = 0; i < n; i ++) {
		_t = rand() % n;
		printf("avl_delete(&T, %d) = %d\n", _t, avl_delete(&T, _t, &lower));
	}
	printf("avl_traveral: ");
	avl_traveral(T, printout_node);
	printf("\n");
	avl_destory(T);
}
Example #9
0
static inline struct tc_device *tc_device_create(char *id)
{
	struct tc_device *d = tc_device_index_find(id, 0);

	if(!d) {
		debug(D_TC_LOOP, "TC: Creating device '%s'", id);

		d = calloc(1, sizeof(struct tc_device));
		if(!d) {
			fatal("Cannot allocate memory for tc_device %s", id);
			return NULL;
		}

		d->id = strdup(id);
		d->hash = simple_hash(d->id);

		avl_init(&d->classes_index, tc_class_compare);
		tc_device_index_add(d);

		if(!tc_device_root) {
			tc_device_root = d;
		}
		else {
			d->next = tc_device_root;
			tc_device_root->prev = d;
			tc_device_root = d;
		}
	}

	return(d);
}
Example #10
0
int
bmp_context_init(int context)
{
    avl_tree *tree;
    int af, rc;

    /*
     * Initialize the BMP tables
     */
    for (af = 0; af < BGP_AF_MAX; af++) {
        rc = bmp_table_init(af);
        if (rc < 0 ) {
            bmp_log("bmp table init failed for af %d", af);
            return -1;
        }
    }
    
    /*
     * Initialize the BMP routers
     */
    tree = avl_init(bgp_router_compare, NULL, AVL_TREE_INTRUSIVE);

    if (tree == NULL) {
        bmp_log("failed to initialize routers tree");
        return -1;
    }

    bmp_contexts[context].bgp_routers = tree;

    return 0;
}
Example #11
0
void	avl_test_insert()
{
		avlTree_t		tree;
		avlNode_t		*node;
		int_t			i;
		
		avl_init(&tree);

		for(i = 0; i < 10240; ++i)
		{
				avl_insert_equal(&tree, rand()%999999);
				
		}

		
		
		avl_print_tree(&tree);
		

		if(!avl_verify_tree(&tree))
		{
				AR_ASSERT(false);
		}


		node = tree.left_most;
		while(node)
		{
				AR_printf(L"%d\r\n", node->data);
				node = avl_get_successor(node);
		}
		AR_printf(L"\r\n");

		avl_uninit(&tree);
}
Example #12
0
void avl() {
    printf(">> AVL\n");
    avl_tree_t tree;
    avl_init(&tree, NULL);

    test_avl_t a = { 1 };
    test_avl_t b = { 2 };
    test_avl_t c = { 3 };

    avl_insert(&tree, &a.node, &test_avl_compare);
    avl_insert(&tree, &b.node, &test_avl_compare);
    avl_insert(&tree, &c.node, &test_avl_compare);

    // Display them
    avl_node_t *node = avl_head(&tree);
    while (node) {
        avl_node_t *next = avl_next(node);
        avl_node_t *prev = avl_prev(node);
        test_avl_t *c = avl_ref(node, test_avl_t, node);
        test_avl_t *n = next ? avl_ref(next, test_avl_t, node) : NULL;
        test_avl_t *p = prev ? avl_ref(prev, test_avl_t, node) : NULL;
        printf("current: %d, next: %d, prev: %d\n",
                c->number,
                n ? n->number : -1,
                p ? p->number : -1);
        node = next;
    }
}
Example #13
0
void
olsr_init_duplicate_set(void)
{
  avl_init(&duplicate_set, olsr_cnf->ip_version == AF_INET ? &avl_comp_ipv4 : &avl_comp_ipv6);

  olsr_set_timer(&duplicate_cleanup_timer, DUPLICATE_CLEANUP_INTERVAL, DUPLICATE_CLEANUP_JITTER, OLSR_TIMER_PERIODIC,
                 &olsr_cleanup_duplicate_entry, NULL, 0);
}
Example #14
0
/**
 * Add a new tc_entry to the tc tree
 *
 * @param adr (last)adr address of the entry
 * @return a pointer to the created entry
 */
static struct tc_entry *
olsr_add_tc_entry(union olsr_ip_addr *adr)
{
#ifdef DEBUG
  struct ipaddr_str buf;
#endif /* DEBUG */
  struct tc_entry *tc;

  /*
   * Safety net against loss of the last main IP address.
   */
  if (ipequal(&olsr_cnf->main_addr, &all_zero)) {
    return NULL;
  }
#ifdef DEBUG
  OLSR_PRINTF(1, "TC: add entry %s\n", olsr_ip_to_string(&buf, adr));
#endif /* DEBUG */

  tc = olsr_cookie_malloc(tc_mem_cookie);
  if (!tc) {
    return NULL;
  }

  /* Fill entry */
  tc->addr = *adr;
  tc->vertex_node.key = &tc->addr;

  /*
   * Insert into the global tc tree.
   */
  avl_insert(&tc_tree, &tc->vertex_node, AVL_DUP_NO);
  olsr_lock_tc_entry(tc);

  /*
   * Initialize subtrees for edges and prefixes.
   */
  avl_init(&tc->edge_tree, avl_comp_default);
  avl_init(&tc->prefix_tree, avl_comp_prefix_default);

  /*
   * Add a rt_path for ourselves.
   */
  olsr_insert_routing_table(adr, olsr_cnf->maxplen, adr, OLSR_RT_ORIGIN_INT);

  return tc;
}
Example #15
0
static int __init
nta_init_module(void)
{
    int i;
    unsigned long j1, j2, interval1, interval2;
    int count = 0;

    mbuf_head_cache = kmem_cache_create("mbuf_head_cache",
                                        sizeof(struct m_buf),
                                        0,
                                        SLAB_HWCACHE_ALIGN|SLAB_PANIC,
                                        NULL
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,10)
                                        , NULL
#endif
                                       );

    if(!mbuf_head_cache) {
        printk(KERN_ERR "Unable to allocate mbuf head cache.\n");
        return -1;
    }

    if (avl_init())
        panic("Failed to initialize network tree allocator.\n");

    j1 = jiffies;
    for(i=0; i<count; i++) {
        struct sk_buff * skb;
        skb = netdev_alloc_skb(NULL, BVL_MEM_SIZE);
        kfree_skb(skb);
    }
    interval1 = (long)get_jiffies_64() - j1;
    printk("mbuf alloc and free performance: %lu jiffies for %d mbufs\n", interval1, count);

    j2 = jiffies;
    for(i=0; i<count; i++) {
        struct m_buf * mbuf;
        mbuf = nta_alloc_mbuf(NULL, BVL_MBUF_LEN, GFP_ATOMIC);
        nta_kfree_mbuf(mbuf);
    }
    interval2 = (long)get_jiffies_64() - j2;
    printk("mbuf alloc and free performance: %lu jiffies for %d mbufs\n", interval2, count);

    nta_proc_init();

#if 0
    memcpy(&test_dev.name, "f**k", 4);
    test_dev.name[4]=0;
    nta_register_zc(&test_dev, test_hard_start_xmit);
    test_timer.function = &nta_test_func;
    init_timer(&test_timer);
    count_a = 0ul;
    count_b[0] = count_b[1] = 0ul;

    mod_timer(&test_timer, jiffies+1);
#endif
    return 0;
}
Example #16
0
/**
 * Add a new interface to this dlep instance
 * @param interf pointer to interface
 * @param ifname name of interface
 * @param l2_origin layer2 originator that shall be used
 * @param log_src logging source that shall be used
 * @param radio true if it is a radio interface, false for router
 * @return -1 if an error happened, 0 otherwise
 */
int
dlep_if_add(struct dlep_if *interf, const char *ifname,
    uint32_t l2_origin, enum oonf_log_source log_src, bool radio) {
  struct dlep_extension *ext;

  /* initialize key */
  strscpy(interf->l2_ifname, ifname,
      sizeof(interf->l2_ifname));
  interf->_node.key = interf->l2_ifname;

  if (abuf_init(&interf->udp_out)) {
    return -1;
  }

  /* add dlep prefix to buffer */
  abuf_memcpy(&interf->udp_out,
      _DLEP_PREFIX, sizeof(_DLEP_PREFIX) - 1);

  if (dlep_session_add(&interf->session,
      interf->l2_ifname, l2_origin,
      &interf->udp_out,
      radio, log_src)) {
    abuf_free(&interf->udp_out);
    return -1;
  }

  /* initialize stream list */
  avl_init(&interf->session_tree, avl_comp_netaddr_socket, false);

  /* initialize discovery socket */
  interf->udp.config.user = interf;
  interf->udp.config.receive_data = _cb_receive_udp;
  oonf_packet_add_managed(&interf->udp);

  /* initialize session */
  interf->session.cb_send_buffer = _cb_send_multicast;
  interf->session.cb_end_session = NULL;
  interf->session.restrict_signal =
      radio ? DLEP_PEER_DISCOVERY : DLEP_PEER_OFFER;
  interf->session.writer.out = &interf->udp_out;

  /* inform all extension */
  avl_for_each_element(dlep_extension_get_tree(), ext, _node) {
    if (radio) {
      if (ext->cb_session_init_radio) {
        ext->cb_session_init_radio(&interf->session);
      }
    }
    else {
      if (ext->cb_session_init_router) {
        ext->cb_session_init_router(&interf->session);
      }
    }
  }
  return 0;
}
Example #17
0
/**
 * Initialize the plugin loader system
 */
void
olsr_init_pluginsystem(void) {
  plugin_mem_cookie = olsr_memcookie_add("Plugin handle", sizeof(struct olsr_plugin));

  /* could already be initialized */
  if (!plugin_tree_initialized) {
    avl_init(&plugin_tree, avl_comp_strcasecmp, false, NULL);
    plugin_tree_initialized = true;
  }
}
Example #18
0
static Boolean avl_ranges_init(SshADTContainer c)
{
  if (!avl_init(c, ssh_malloc(sizeof(SshADTRangesCRootStruct))))
    return FALSE;

  if ((RROOT(c)->merge_additions = ssh_buffer_allocate()) == NULL ||
      (RROOT(c)->merge_deletions = ssh_buffer_allocate()) == NULL)
    return FALSE;

  return TRUE;
}
Example #19
0
void iterRouteTabInit(void)
{
  struct avl_node *node;

  avl_init(&routingtree, avl_comp_prefix_default);
  routingtree_version = 0;

  node = avl_walk_first(&routingtree);
  iterRouteTab = node ? rt_tree2rt(node) : NULL;

}
Example #20
0
/**
 * This function is called by the constructor of a plugin.
 * because of this the first call has to initialize the list
 * head.
 *
 * @param pl_def pointer to plugin definition
 */
void
olsr_hookup_plugin(struct olsr_plugin *pl_def) {
  assert (pl_def->name);
  fprintf(stderr, "hookup %s\n", pl_def->name);
  if (!plugin_tree_initialized) {
    avl_init(&plugin_tree, avl_comp_strcasecmp, false, NULL);
    plugin_tree_initialized = true;
  }
  pl_def->p_node.key = pl_def->name;
  avl_insert(&plugin_tree, &pl_def->p_node);
}
Example #21
0
void ubus_id_tree_init(struct avl_tree *tree){
	if (random_fd < 0) {
		random_fd = open("/dev/urandom", O_RDONLY);
		if (random_fd < 0) {
			perror("open");
			exit(1);
		}
	}

	avl_init(tree, ubus_cmp_id, false, NULL);
}
Example #22
0
void
init_lq_handler_tree(void)
{
  avl_init(&lq_handler_tree, &avl_strcasecmp);
  register_lq_handler(&lq_etx_float_handler, LQ_ALGORITHM_ETX_FLOAT_NAME);
  register_lq_handler(&lq_etx_fpm_handler, LQ_ALGORITHM_ETX_FPM_NAME);
  register_lq_handler(&lq_etx_ff_handler, LQ_ALGORITHM_ETX_FF_NAME);
  if (activate_lq_handler(olsr_cnf->lq_algorithm)) {
    activate_lq_handler(LQ_ALGORITHM_ETX_FPM_NAME);
  }
}
Example #23
0
void	avl_test_remove()
{
		avlTree_t		tree;
		int_t			*rec;
		int_t			i;
		
		rec = AR_NEWARR0(int_t, INSERT_CNT);

		avl_init(&tree);

		for(i = 0; i < INSERT_CNT; ++i)
		{
				int_t n = rand()%999999;
				avl_insert_equal(&tree, n);
				rec[i] = n;
		}

		avl_print_tree(&tree);

		if(!avl_verify_tree(&tree))
		{
				AR_ASSERT(false);
		}
		
		for(i = 0; i < INSERT_CNT; ++i)
		{
				if(!avl_remove(&tree, rec[i]))
				{
						AR_ASSERT(false);
				}
				AR_printf(L"key == %d\r\n", rec[i]);
				avl_print_tree(&tree);
				AR_printf(L"\r\n");
				
				if(!avl_verify_tree(&tree))
				{
						AR_ASSERT(false);
				}

				/*
				avlNode_t *node = avl_find(&tree, rec[i]);
				AR_ASSERT(node && node->data == rec[i]);
				AR_printf(L"key == %d Node == %d\r\n", rec[i], node->data);
				*/

				getchar();
				
		}

		avl_uninit(&tree);

		AR_DEL(rec);
}
Example #24
0
DICTIONARY *dictionary_create(uint32_t flags) {
	debug(D_DICTIONARY, "Creating dictionary.");

	DICTIONARY *dict = calloc(1, sizeof(DICTIONARY));
	if(unlikely(!dict)) fatal("Cannot allocate DICTIONARY");

	avl_init(&dict->values_index, name_value_compare);
	pthread_rwlock_init(&dict->rwlock, NULL);

	dict->flags = flags;

	return dict;
}
Example #25
0
int olsr_os_init_iptunnel(const char * dev) {
  tunnel_cookie = olsr_alloc_cookie("iptunnel", OLSR_COOKIE_TYPE_MEMORY);
  olsr_cookie_set_memory_size(tunnel_cookie, sizeof(struct olsr_iptunnel_entry));
  avl_init(&tunnel_tree, avl_comp_default);

  store_iptunnel_state = olsr_if_isup(dev);
  if (store_iptunnel_state) {
    return 0;
  }
  if (olsr_if_set_state(dev, true)) {
    return -1;
  }

  return olsr_os_ifip(if_nametoindex(dev), &olsr_cnf->main_addr, true);
}
Example #26
0
/**
* @brief test case for single number insert, search and delete.
*/
void testcase_for_single() {
	TREE T = avl_init();
	int taller = 0, lower = 0;

	printf("avl_insert(T, 32) = %d\n", avl_insert(&T, 32, &taller));

	printf("avl_search(T, 32) = %d\n", avl_search(T, 32));

	printf("avl_delete(T, 32) = %d\n", avl_delete(&T, 32, &lower));

	printf("avl_traveral: ");
	avl_traveral(T, printout_node);
	printf("\n");

	avl_destory(T);
}
Example #27
0
void avl_init_lock(avl_tree_lock *tree, int (*compar)(void * /*a*/, void * /*b*/)) {
    avl_init(&tree->avl_tree, compar);

#ifndef AVL_WITHOUT_PTHREADS
    int lock;

#ifdef AVL_LOCK_WITH_MUTEX
    lock = netdata_mutex_init(&tree->mutex, NULL);
#else
    lock = netdata_rwlock_init(&tree->rwlock);
#endif

    if(lock != 0)
        fatal("Failed to initialize AVL mutex/rwlock, error: %d", lock);

#endif /* AVL_WITHOUT_PTHREADS */
}
Example #28
0
/**
 * Process file by name and call syntax analyse
 *
 * @param file_name File name to process
 */
void process_file(char *file_name)
{
    assert(file_name != NULL);

    FILE *f;

    f = fopen(file_name, "r");
    if (f) {
	Tnode_ptr symtab;
	avl_init(&symtab);
	syntax(f, &symtab);
	fclose(f);
	avl_destroy_tree(&symtab);
    } else {
	error(ERROR_FOPEN);
    }
}
Example #29
0
/**
 * Initialize LQ handler
 */
void
init_lq_handler_tree(void)
{
  avl_init(&lq_handler_tree, &avl_strcasecmp);
  register_lq_handler(&lq_etx_float_handler, LQ_ALGORITHM_ETX_FLOAT_NAME);
  register_lq_handler(&lq_etx_fpm_handler, LQ_ALGORITHM_ETX_FPM_NAME);
  register_lq_handler(&lq_etx_ff_handler, LQ_ALGORITHM_ETX_FF_NAME);
  register_lq_handler(&lq_etx_ffeth_handler, LQ_ALGORITHM_ETX_FFETH_NAME);
  register_lq_handler(&lq_etx_hybrid_plc_handler, LQ_ALGORITHM_ETX_HYBRID_PLC_NAME);	

  if (olsr_cnf->lq_algorithm == NULL) {
    activate_lq_handler(DEF_LQ_ALGORITHM);
  }
  else {
    activate_lq_handler(olsr_cnf->lq_algorithm);
  }
}
Example #30
0
/**
 * Initialize the routingtree and kernel change queues.
 */
void
olsr_init_routing_table(void)
{
  OLSR_PRINTF(5, "RIB: init routing tree\n");

  /* the routing tree */
  avl_init(&routingtree, avl_comp_prefix_default);
  routingtree_version = 0;

  /*
   * Get some cookies for memory stats and memory recycling.
   */
  rt_mem_cookie = olsr_alloc_cookie("rt_entry", OLSR_COOKIE_TYPE_MEMORY);
  olsr_cookie_set_memory_size(rt_mem_cookie, sizeof(struct rt_entry));

  rtp_mem_cookie = olsr_alloc_cookie("rt_path", OLSR_COOKIE_TYPE_MEMORY);
  olsr_cookie_set_memory_size(rtp_mem_cookie, sizeof(struct rt_path));
}