示例#1
0
void rnd_get_state(struct rnd *rnd, uint32_t state[])
{
	state[0] = H32(rnd->s1);
	state[1] = L32(rnd->s1);
	state[2] = H32(rnd->s2);
	state[3] = L32(rnd->s2);
}
示例#2
0
static inline uint64_t next_mwc32_m2_64(struct state_mwc32_m2_64 *state)
{
	uint64_t x = L32(state->s1)*A1+H32(state->s1);
	state->s1 = x;	
	uint64_t z1 = Z1 * H32(x);
	uint64_t z2 = Z2 * L32(x);
	return z1 + FLIP32(z2);
}
示例#3
0
static inline uint64_t next_rnd(struct rnd *rnd)
{
	uint64_t x1 = L32(rnd->s1)*A1+H32(rnd->s1);
	uint64_t x2 = L32(rnd->s2)*A2+H32(rnd->s2);
	rnd->s1 = x1;
	rnd->s2 = x2;
	return x1 + x2;
}
示例#4
0
static inline uint64_t next_mwc32_m2_32(struct state_mwc32_m2_32 *state)
{
	uint64_t x = state->s1*A1+state->c;
	state->s1 = x;
	state->c = H32(x);
	uint64_t z1 = Z1 * H32(x);
	uint64_t z2 = Z2 * L32(x);
	return z1 + FLIP32(z2);
}
示例#5
0
static uint32_t
hash(void *self, pkt_t *pkt)
{
    if (pkt->l3type != ETHERTYPE_IP) 
        return 0; 

    /* must be the same source ip, dest ip, source port, dest port */
    return (H32(IP(src_ip)) ^ H32(IP(dst_ip)) ^ (H16(TCP(dst_port)) << 3) ^ 
           (H16(TCP(dst_port)) << 3));
}
示例#6
0
static int
ematch(void *self, void *efh, void *fh)
{
    pkt_t* pkt;
    int ret = 0;
    FLOWDESC *x = F(fh);
    EFLOWDESC *ex = EF(efh);

    pkt = (pkt_t *)x->buf;
    
    if (ex->full_flow == 0) { /* if its full, go to next export record */
        ret = ((ex->dst_port == H16(TCP(dst_port))) && 
               (ex->src_port == H16(TCP(src_port))) &&
               (ex->src_ip == H32(IP(src_ip))) && 
               (ex->dst_ip == H32(IP(dst_ip))));
    }

    return ret;
}
示例#7
0
static void init_mwc32_m2_32(struct state_mwc32_m2_32 *state,
				uint32_t seed)
{
	int i;
	uint64_t x = seed*Z1 + seed*Z2 + Z5 + Z1;
	x = (MASK64(x) != 0) ? x : (Z5 + Z2);
	state->s1 = L31(x);
	state->c  = L30(H32(x));
	for (i=0; i<11; i++)
		next_mwc32_m2_32(state);
}
示例#8
0
void
capture(mdl_t *self, pkt_t *pkt, tuple_t *st, double srate)
{
    config_t *config = mdl_get_config(self, config_t);
    int app, app1, app2;
    double b, p;

    if (! isTCP && ! isUDP) /* non-TCP, non-UDP traffic */
        app = 1;
    else {                  /* TCP and UDP traffic */
        if (isTCP) {
            app1 = config->tcp_port2app[H16(TCP(src_port))];
            app2 = config->tcp_port2app[H16(TCP(dst_port))];
        } else {
            app1 = config->udp_port2app[H16(UDP(src_port))];
            app2 = config->tcp_port2app[H16(UDP(dst_port))];
        }

        if (app1 == 0 || app2 == 0) /* at most 1 port matches a known app */
            app = app1 + app2;
        else if (app1 == app2)      /* both ports match the same app */
            app = app1;
        else                        /* ports match different apps, unknown */
            app = 0;
    }

    if (COMO(type) == COMOTYPE_NF) {
        b = H32(NF(pktcount)) * COMO(len) * H16(NF(sampling));
        p = H32(NF(pktcount)) * (uint32_t) H16(NF(sampling));
    } else if (COMO(type) == COMOTYPE_SFLOW) {
        b = (uint64_t) COMO(len) * (uint64_t) H32(SFLOW(sampling_rate));
        p = H32(SFLOW(sampling_rate));
    } else {
        b = COMO(len);
        p = 1;
    }

    /* scale with sampling rate */
    st->bytes[app] += b / srate;
    st->pkts[app] += p / srate;
}
示例#9
0
static int
update(void * self, pkt_t *pkt, void *fh, int isnew)
{
    FLOWDESC *x = F(fh);
    config_t * cf = CONFIG(self);

    if (isnew) {
	bzero(x, sizeof(FLOWDESC));
	x->ts = COMO(ts);
    }

    if (COMO(type) == COMOTYPE_NF) {
	if (cf->iface == -1 || H16(NF(input)) == cf->iface) {
	    x->bytes[0] += H32(NF(pktcount)) * COMO(len) * H16(NF(sampling));
	    x->pkts[0] += H32(NF(pktcount)) * (uint32_t) H16(NF(sampling));
	} else if (H16(NF(output)) == cf->iface) { 
	    x->bytes[1] += H32(NF(pktcount)) * COMO(len) * H16(NF(sampling));
	    x->pkts[1] += H32(NF(pktcount)) * (uint32_t) H16(NF(sampling));
	} 
    } else if (COMO(type) == COMOTYPE_SFLOW) {
	x->bytes[0] += (uint64_t) COMO(len) * 
		      (uint64_t) H32(SFLOW(sampling_rate));
	x->pkts[0] += H32(SFLOW(sampling_rate));
    } else {
	x->bytes[0] += COMO(len);
        x->pkts[0]++;
    }

    return 0;
}
示例#10
0
文件: list.c 项目: JackieXie168/como
static int
update(pkt_t *pkt, void *fh, int isnew)
{
    FLOWDESC *x = F(fh);
    uint8_t addr;
    int i;

    if (isnew) {
        x->ts = pkt->ts;

	x->signal = H32(PRISM_HDR(ssi_signal));
	x->noise = H32(PRISM_HDR(ssi_noise));
        x->phytype = H32(PRISM_HDR(phytype));
	x->encoding = H32(PRISM_HDR(encoding));    

        x->bivl = MGMT_BODY(bivl); 
	x->channel = MGMT_BODY(ch);
        
	/* get to the SSID information element */
        if (MGMT_BODY(ssid_len) > 0) {
            x->len = (MGMT_BODY(ssid_len));
            bcopy(MGMT_BODY(ssid), x->ssid, x->len);
        } else {
            x->len = 3;
            sprintf(x->ssid, "ANY");
        } 

	/* Currently BUILD_FOR_ARM Macros don't support arrays properly, 
	 * hence must access each byte individually. Preferred method 
	 * would be to use the bcopy keyword. 
	 */
        for (i = 0; i < MAC_ADDR_SIZE; i++) {
	    addr = MGMT_HDR(bssid[i]);
	    x->addr[i] = addr;
        }
    }
    return 0;		
}
示例#11
0
static int
update(__unused void * self, pkt_t *pkt, void *fh, int isnew)
{
    FLOWDESC *x = F(fh);

    if (isnew) {
	x->ts = COMO(ts);
        x->bytes = 0;
        x->pkts = 0;
    }

    if (COMO(type) == COMOTYPE_NF) {
        x->bytes += H32(NF(pktcount)) * COMO(len) * H16(NF(sampling));
        x->pkts += H32(NF(pktcount)) * (uint32_t) H16(NF(sampling));
    } else if (COMO(type) == COMOTYPE_SFLOW) {
	x->bytes += (uint64_t) COMO(len) * (uint64_t) H32(SFLOW(sampling_rate));
	x->pkts += (uint64_t) H32(SFLOW(sampling_rate));
    } else {
	x->bytes += COMO(len);
        x->pkts++;
    }

    return 0;
}
示例#12
0
文件: ssid.c 项目: JackieXie168/como
/*
 * update callback
 */
static int
update(void * self, pkt_t *pkt, void *fh, int isnew)
{
    CONFIGDESC * config = CONFIG(self);
    FLOWDESC *x = F(fh); 

    if (isnew) {
	x->ts = COMO(ts) - COMO(ts) % TIME2TS(config->meas_ivl, 0);
	x->channel = -1; 
	x->signal = x->noise = 0;
        x->samples = 0; 

	/* now find the information in the management frame.
	 * get privacy bit to determine if wep is enabled
	 */
	x->wepmode = CAPINFO_PRIVACY(H16(MGMT_BODY(cap))) ? 1 : 0;

	/* get to the SSID information element */
	if (MGMT_BODY(ssid_len) > 0) { 
	    x->len = (MGMT_BODY(ssid_len)); 
	    bcopy(MGMT_BODY(ssid), x->ssid, x->len);
	} else { 
	    x->len = 3; 
	    sprintf(x->ssid, "ANY"); 
	}

	x->channel = MGMT_BODY(ch); 	
    }
    x->samples++;
    if (COMO(type) == COMOTYPE_RADIO) {
        x->signal += H32(RADIO(ssisignal)); 
        x->noise += H32(RADIO(ssinoise)); 
    }
    
    return 0; /* records are never full */
}
示例#13
0
uint32_t rnd_u32(struct rnd *rnd)
{
	return H32(next_rnd(rnd));
}
示例#14
0
static inline uint64_t next_mwc32_r(struct state_mwc32_r *state)
{
	uint64_t x = L32(state->s1)*A1+H32(state->s1);
	state->s1 = x;
	return x + RR64(x,25);
}