X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=ofproto%2Fnetflow.c;h=6e2ddb848c59f543537315dd6e2cfa0f2481e36c;hb=6527c598eabbd34aaa7284f4b052de667e13be2f;hp=381ff8efcf23a7a895e48d64e19f8ffb6738e67a;hpb=b2fda3effc787f265b5ad5dfa967ac00627bd075;p=openvswitch diff --git a/ofproto/netflow.c b/ofproto/netflow.c index 381ff8ef..6e2ddb84 100644 --- a/ofproto/netflow.c +++ b/ofproto/netflow.c @@ -27,6 +27,7 @@ #include "ofpbuf.h" #include "ofproto.h" #include "packets.h" +#include "poll-loop.h" #include "socket-util.h" #include "timeval.h" #include "util.h" @@ -99,12 +100,13 @@ struct netflow { uint32_t netflow_cnt; /* Flow sequence number for NetFlow. */ struct ofpbuf packet; /* NetFlow packet being accumulated. */ long long int active_timeout; /* Timeout for flows that are still active. */ + long long int next_timeout; /* Next scheduled active timeout. */ long long int reconfig_time; /* When we reconfigured the timeouts. */ }; static void gen_netflow_rec(struct netflow *nf, struct netflow_flow *nf_flow, - struct ofexpired *expired, + struct ofexpired *expired, uint32_t packet_count, uint32_t byte_count) { struct netflow_v5_header *nf_hdr; @@ -160,7 +162,7 @@ gen_netflow_rec(struct netflow *nf, struct netflow_flow *nf_flow, } nf_rec->tcp_flags = nf_flow->tcp_flags; nf_rec->ip_proto = expired->flow.nw_proto; - nf_rec->ip_tos = expired->flow.nw_tos; + nf_rec->ip_tos = expired->flow.nw_tos & IP_DSCP_MASK; /* NetFlow messages are limited to 30 records. */ if (ntohs(nf_hdr->count) >= 30) { @@ -221,13 +223,33 @@ netflow_expire(struct netflow *nf, struct netflow_flow *nf_flow, nf_flow->tcp_flags = 0; } -void +/* Returns true if it's time to send out a round of NetFlow active timeouts, + * false otherwise. */ +bool netflow_run(struct netflow *nf) { if (nf->packet.size) { collectors_send(nf->collectors, nf->packet.data, nf->packet.size); nf->packet.size = 0; } + + if (nf->active_timeout && time_msec() >= nf->next_timeout) { + nf->next_timeout = time_msec() + 1000; + return true; + } else { + return false; + } +} + +void +netflow_wait(struct netflow *nf) +{ + if (nf->active_timeout) { + poll_timer_wait_until(nf->next_timeout); + } + if (nf->packet.size) { + poll_immediate_wake(); + } } int @@ -253,6 +275,7 @@ netflow_set_options(struct netflow *nf, nf->active_timeout *= 1000; if (old_timeout != nf->active_timeout) { nf->reconfig_time = time_msec(); + nf->next_timeout = time_msec(); } return error; @@ -261,7 +284,7 @@ netflow_set_options(struct netflow *nf, struct netflow * netflow_create(void) { - struct netflow *nf = xmalloc(sizeof *nf); + struct netflow *nf = xzalloc(sizeof *nf); nf->engine_type = 0; nf->engine_id = 0; nf->boot_time = time_msec();