/* * Try to generate a fresh tuple of n values * - tau[i] = type for a[i] * - return false if this fails */ static bool gen_fresh_tuple(fresh_val_maker_t *maker, uint32_t n, type_t *tau, value_t *a) { type_table_t *types; value_table_t *vtbl; tuple_counter_t *ctr; uint32_t j; value_t v; types = maker->types; vtbl = maker->vtbl; // search for an infinite tau[j] for (j=0; j<n; j++) { if (! is_finite_type(types, tau[j])) { break; } } if (j < n) { // tau[j] is infinite fill_tuple(vtbl, n, tau, a, j); a[j] = make_fresh_value(maker, tau[j]); return true; } // all types are finite: try to get a fresh element // for one of tau[j] for (j=0; j<n; j++) { v = make_fresh_value(maker, tau[j]); if (v != null_value) break; } if (j < n) { // we have a fresh v of type tau[j] fill_tuple(vtbl, n, tau, a, j); a[j] = v; return true; } // all tau[i] are finite and saturated: use the counter ctr = get_tuple_counter(maker, n, tau); j = ctr->count; while (j < ctr->card && vtbl_test_object_tuple(vtbl, n, tau, j)) { j++; } if (j < ctr->card) { vtbl_gen_object_tuple(vtbl, n, tau, j, a); ctr->count = j+1; return true; } // failed ctr->count = j; return false; }
void cluster::_Run() { std::string thread_name = device_name + "_cluster"; prctl(PR_SET_NAME, thread_name.c_str()); int len = 2048; u_char *buffer = new u_char[len]; struct pfring_pkthdr *hdr = (pfring_pkthdr *)buffer; u_char* lpPkt = buffer + sizeof(struct pfring_pkthdr); int waitable = 1; /* 0-->non-blocking, otherwise blocking*/ //u_int8_t level = 4; /* 2 of OSI-7*/ //u_int8_t addtimestamp = 1; /* 1 --> add timetamp */ //u_int8_t addhash = 0; /* 0 --> don't add hash */ pfring_enable_ring(ring); //解码的结果集 _nic_stat_session_tuple tuple; for(;;) { int ret = pfring_recv(ring, (u_char**)&lpPkt, PF_CAP_LEN, hdr, waitable); if( ret > 0 ) { decode((uint8_t *)lpPkt, hdr->caplen); tuple.init(); fill_tuple(tuple, hdr->caplen); cluster_stat_flow(&tuple); } } }
void fill_tuple(typename tuple_wrapper<T, Elements...>::type & _t, const T& dat,const Elements&... args) { _t.current = dat; fill_tuple(_t.forward, args...); }