From bae473fea5404a5afd205c70689778386045ebab Mon Sep 17 00:00:00 2001 From: Justin Pettit Date: Wed, 15 Jun 2011 11:28:51 -0700 Subject: [PATCH] ofproto: Rename ofproto-sflow.[ch] to ofproto-dpif-sflow.[ch]. The name ofproto-sflow.[ch] implies that this code would work with any ofproto implementation, but in fact it is specific to the ofproto_dpif implementation. Rename it to avoid confusion. --- ofproto/automake.mk | 4 +- .../{ofproto-sflow.c => ofproto-dpif-sflow.c} | 268 +++++++++--------- ofproto/ofproto-dpif-sflow.h | 46 +++ ofproto/ofproto-dpif.c | 32 +-- ofproto/ofproto-sflow.h | 46 --- 5 files changed, 196 insertions(+), 200 deletions(-) rename ofproto/{ofproto-sflow.c => ofproto-dpif-sflow.c} (66%) create mode 100644 ofproto/ofproto-dpif-sflow.h delete mode 100644 ofproto/ofproto-sflow.h diff --git a/ofproto/automake.mk b/ofproto/automake.mk index 0279802e..9ce40ab3 100644 --- a/ofproto/automake.mk +++ b/ofproto/automake.mk @@ -21,8 +21,8 @@ ofproto_libofproto_a_SOURCES = \ ofproto/ofproto.c \ ofproto/ofproto.h \ ofproto/ofproto-dpif.c \ - ofproto/ofproto-sflow.c \ - ofproto/ofproto-sflow.h \ + ofproto/ofproto-dpif-sflow.c \ + ofproto/ofproto-dpif-sflow.h \ ofproto/pktbuf.c \ ofproto/pktbuf.h \ ofproto/pinsched.c \ diff --git a/ofproto/ofproto-sflow.c b/ofproto/ofproto-dpif-sflow.c similarity index 66% rename from ofproto/ofproto-sflow.c rename to ofproto/ofproto-dpif-sflow.c index a3f4d810..d2da42b0 100644 --- a/ofproto/ofproto-sflow.c +++ b/ofproto/ofproto-dpif-sflow.c @@ -16,12 +16,12 @@ */ #include -#include "ofproto-sflow.h" +#include "ofproto-dpif-sflow.h" #include #include #include "collectors.h" -#include "dpif.h" #include "compiler.h" +#include "dpif.h" #include "hash.h" #include "hmap.h" #include "netdev.h" @@ -37,14 +37,14 @@ VLOG_DEFINE_THIS_MODULE(sflow); -struct ofproto_sflow_port { - struct hmap_node hmap_node; /* In struct ofproto_sflow's "ports" hmap. */ +struct dpif_sflow_port { + struct hmap_node hmap_node; /* In struct dpif_sflow's "ports" hmap. */ struct netdev *netdev; /* Underlying network device, for stats. */ SFLDataSource_instance dsi; /* sFlow library's notion of port number. */ uint16_t odp_port; /* ODP port number. */ }; -struct ofproto_sflow { +struct dpif_sflow { struct ofproto *ofproto; struct collectors *collectors; SFLAgent *sflow_agent; @@ -52,11 +52,11 @@ struct ofproto_sflow { struct dpif *dpif; time_t next_tick; size_t n_flood, n_all; - struct hmap ports; /* Contains "struct ofproto_sflow_port"s. */ + struct hmap ports; /* Contains "struct dpif_sflow_port"s. */ }; -static void ofproto_sflow_del_port__(struct ofproto_sflow *, - struct ofproto_sflow_port *); +static void dpif_sflow_del_port__(struct dpif_sflow *, + struct dpif_sflow_port *); #define RECEIVER_INDEX 1 @@ -70,7 +70,7 @@ nullable_string_is_equal(const char *a, const char *b) static bool ofproto_sflow_options_equal(const struct ofproto_sflow_options *a, - const struct ofproto_sflow_options *b) + const struct ofproto_sflow_options *b) { return (sset_equals(&a->targets, &b->targets) && a->sampling_rate == b->sampling_rate @@ -129,42 +129,42 @@ sflow_agent_error_cb(void *magic OVS_UNUSED, SFLAgent *agent OVS_UNUSED, /* sFlow library callback to send datagram. */ static void -sflow_agent_send_packet_cb(void *os_, SFLAgent *agent OVS_UNUSED, +sflow_agent_send_packet_cb(void *ds_, SFLAgent *agent OVS_UNUSED, SFLReceiver *receiver OVS_UNUSED, u_char *pkt, uint32_t pktLen) { - struct ofproto_sflow *os = os_; - collectors_send(os->collectors, pkt, pktLen); + struct dpif_sflow *ds = ds_; + collectors_send(ds->collectors, pkt, pktLen); } -static struct ofproto_sflow_port * -ofproto_sflow_find_port(const struct ofproto_sflow *os, uint16_t odp_port) +static struct dpif_sflow_port * +dpif_sflow_find_port(const struct dpif_sflow *ds, uint16_t odp_port) { - struct ofproto_sflow_port *osp; + struct dpif_sflow_port *dsp; - HMAP_FOR_EACH_IN_BUCKET (osp, hmap_node, - hash_int(odp_port, 0), &os->ports) { - if (osp->odp_port == odp_port) { - return osp; + HMAP_FOR_EACH_IN_BUCKET (dsp, hmap_node, + hash_int(odp_port, 0), &ds->ports) { + if (dsp->odp_port == odp_port) { + return dsp; } } return NULL; } static void -sflow_agent_get_counters(void *os_, SFLPoller *poller, +sflow_agent_get_counters(void *ds_, SFLPoller *poller, SFL_COUNTERS_SAMPLE_TYPE *cs) { - struct ofproto_sflow *os = os_; + struct dpif_sflow *ds = ds_; SFLCounters_sample_element elem; - struct ofproto_sflow_port *osp; + struct dpif_sflow_port *dsp; SFLIf_counters *counters; struct netdev_stats stats; enum netdev_flags flags; uint32_t current; - osp = ofproto_sflow_find_port(os, poller->bridgePort); - if (!osp) { + dsp = dpif_sflow_find_port(ds, poller->bridgePort); + if (!dsp) { return; } @@ -172,9 +172,9 @@ sflow_agent_get_counters(void *os_, SFLPoller *poller, counters = &elem.counterBlock.generic; counters->ifIndex = SFL_DS_INDEX(poller->dsi); counters->ifType = 6; - if (!netdev_get_features(osp->netdev, ¤t, NULL, NULL, NULL)) { - /* The values of ifDirection come from MAU MIB (RFC 2668): 0 = unknown, - 1 = full-duplex, 2 = half-duplex, 3 = in, 4=out */ + if (!netdev_get_features(dsp->netdev, ¤t, NULL, NULL, NULL)) { + /* The values of ifDirection come from MAU MIB (RFC 2668): 0 = unknown, + 1 = full-duplex, 2 = half-duplex, 3 = in, 4=out */ counters->ifSpeed = netdev_features_to_bps(current); counters->ifDirection = (netdev_features_is_full_duplex(current) ? 1 : 2); @@ -182,9 +182,9 @@ sflow_agent_get_counters(void *os_, SFLPoller *poller, counters->ifSpeed = 100000000; counters->ifDirection = 0; } - if (!netdev_get_flags(osp->netdev, &flags) && flags & NETDEV_UP) { + if (!netdev_get_flags(dsp->netdev, &flags) && flags & NETDEV_UP) { counters->ifStatus = 1; /* ifAdminStatus up. */ - if (netdev_get_carrier(osp->netdev)) { + if (netdev_get_carrier(dsp->netdev)) { counters->ifStatus |= 2; /* ifOperStatus us. */ } } else { @@ -196,7 +196,7 @@ sflow_agent_get_counters(void *os_, SFLPoller *poller, 2. Does the multicast counter include broadcasts? 3. Does the rx_packets counter include multicasts/broadcasts? */ - netdev_get_stats(osp->netdev, &stats); + netdev_get_stats(dsp->netdev, &stats); counters->ifInOctets = stats.rx_bytes; counters->ifInUcastPkts = stats.rx_packets; counters->ifInMulticastPkts = stats.multicast; @@ -257,85 +257,84 @@ success: } void -ofproto_sflow_clear(struct ofproto_sflow *os) +dpif_sflow_clear(struct dpif_sflow *ds) { - if (os->sflow_agent) { - sfl_agent_release(os->sflow_agent); - os->sflow_agent = NULL; + if (ds->sflow_agent) { + sfl_agent_release(ds->sflow_agent); + ds->sflow_agent = NULL; } - collectors_destroy(os->collectors); - os->collectors = NULL; - ofproto_sflow_options_destroy(os->options); - os->options = NULL; + collectors_destroy(ds->collectors); + ds->collectors = NULL; + ofproto_sflow_options_destroy(ds->options); + ds->options = NULL; /* Turn off sampling to save CPU cycles. */ - dpif_set_sflow_probability(os->dpif, 0); + dpif_set_sflow_probability(ds->dpif, 0); } bool -ofproto_sflow_is_enabled(const struct ofproto_sflow *os) +dpif_sflow_is_enabled(const struct dpif_sflow *ds) { - return os->collectors != NULL; + return ds->collectors != NULL; } -struct ofproto_sflow * -ofproto_sflow_create(struct dpif *dpif) +struct dpif_sflow * +dpif_sflow_create(struct dpif *dpif) { - struct ofproto_sflow *os; + struct dpif_sflow *ds; - os = xcalloc(1, sizeof *os); - os->dpif = dpif; - os->next_tick = time_now() + 1; - hmap_init(&os->ports); - return os; + ds = xcalloc(1, sizeof *ds); + ds->dpif = dpif; + ds->next_tick = time_now() + 1; + hmap_init(&ds->ports); + return ds; } void -ofproto_sflow_destroy(struct ofproto_sflow *os) +dpif_sflow_destroy(struct dpif_sflow *ds) { - if (os) { - struct ofproto_sflow_port *osp, *next; + if (ds) { + struct dpif_sflow_port *dsp, *next; - ofproto_sflow_clear(os); - HMAP_FOR_EACH_SAFE (osp, next, hmap_node, &os->ports) { - ofproto_sflow_del_port__(os, osp); + dpif_sflow_clear(ds); + HMAP_FOR_EACH_SAFE (dsp, next, hmap_node, &ds->ports) { + dpif_sflow_del_port__(ds, dsp); } - hmap_destroy(&os->ports); - free(os); + hmap_destroy(&ds->ports); + free(ds); } } static void -ofproto_sflow_add_poller(struct ofproto_sflow *os, - struct ofproto_sflow_port *osp, uint16_t odp_port) +dpif_sflow_add_poller(struct dpif_sflow *ds, + struct dpif_sflow_port *dsp, uint16_t odp_port) { - SFLPoller *poller = sfl_agent_addPoller(os->sflow_agent, &osp->dsi, os, + SFLPoller *poller = sfl_agent_addPoller(ds->sflow_agent, &dsp->dsi, ds, sflow_agent_get_counters); - sfl_poller_set_sFlowCpInterval(poller, os->options->polling_interval); + sfl_poller_set_sFlowCpInterval(poller, ds->options->polling_interval); sfl_poller_set_sFlowCpReceiver(poller, RECEIVER_INDEX); sfl_poller_set_bridgePort(poller, odp_port); } static void -ofproto_sflow_add_sampler(struct ofproto_sflow *os, - struct ofproto_sflow_port *osp) +dpif_sflow_add_sampler(struct dpif_sflow *ds, struct dpif_sflow_port *dsp) { - SFLSampler *sampler = sfl_agent_addSampler(os->sflow_agent, &osp->dsi); - sfl_sampler_set_sFlowFsPacketSamplingRate(sampler, os->options->sampling_rate); - sfl_sampler_set_sFlowFsMaximumHeaderSize(sampler, os->options->header_len); + SFLSampler *sampler = sfl_agent_addSampler(ds->sflow_agent, &dsp->dsi); + sfl_sampler_set_sFlowFsPacketSamplingRate(sampler, ds->options->sampling_rate); + sfl_sampler_set_sFlowFsMaximumHeaderSize(sampler, ds->options->header_len); sfl_sampler_set_sFlowFsReceiver(sampler, RECEIVER_INDEX); } void -ofproto_sflow_add_port(struct ofproto_sflow *os, uint16_t odp_port, - const char *netdev_name) +dpif_sflow_add_port(struct dpif_sflow *ds, uint16_t odp_port, + const char *netdev_name) { - struct ofproto_sflow_port *osp; + struct dpif_sflow_port *dsp; struct netdev *netdev; uint32_t ifindex; int error; - ofproto_sflow_del_port(os, odp_port); + dpif_sflow_del_port(ds, odp_port); /* Open network device. */ error = netdev_open_default(netdev_name, &netdev); @@ -346,50 +345,49 @@ ofproto_sflow_add_port(struct ofproto_sflow *os, uint16_t odp_port, } /* Add to table of ports. */ - osp = xmalloc(sizeof *osp); - osp->netdev = netdev; + dsp = xmalloc(sizeof *dsp); + dsp->netdev = netdev; ifindex = netdev_get_ifindex(netdev); if (ifindex <= 0) { - ifindex = (os->sflow_agent->subId << 16) + odp_port; + ifindex = (ds->sflow_agent->subId << 16) + odp_port; } - SFL_DS_SET(osp->dsi, 0, ifindex, 0); - osp->odp_port = odp_port; - hmap_insert(&os->ports, &osp->hmap_node, hash_int(odp_port, 0)); + SFL_DS_SET(dsp->dsi, 0, ifindex, 0); + dsp->odp_port = odp_port; + hmap_insert(&ds->ports, &dsp->hmap_node, hash_int(odp_port, 0)); /* Add poller and sampler. */ - if (os->sflow_agent) { - ofproto_sflow_add_poller(os, osp, odp_port); - ofproto_sflow_add_sampler(os, osp); + if (ds->sflow_agent) { + dpif_sflow_add_poller(ds, dsp, odp_port); + dpif_sflow_add_sampler(ds, dsp); } } static void -ofproto_sflow_del_port__(struct ofproto_sflow *os, - struct ofproto_sflow_port *osp) +dpif_sflow_del_port__(struct dpif_sflow *ds, struct dpif_sflow_port *dsp) { - if (os->sflow_agent) { - sfl_agent_removePoller(os->sflow_agent, &osp->dsi); - sfl_agent_removeSampler(os->sflow_agent, &osp->dsi); + if (ds->sflow_agent) { + sfl_agent_removePoller(ds->sflow_agent, &dsp->dsi); + sfl_agent_removeSampler(ds->sflow_agent, &dsp->dsi); } - netdev_close(osp->netdev); - hmap_remove(&os->ports, &osp->hmap_node); - free(osp); + netdev_close(dsp->netdev); + hmap_remove(&ds->ports, &dsp->hmap_node); + free(dsp); } void -ofproto_sflow_del_port(struct ofproto_sflow *os, uint16_t odp_port) +dpif_sflow_del_port(struct dpif_sflow *ds, uint16_t odp_port) { - struct ofproto_sflow_port *osp = ofproto_sflow_find_port(os, odp_port); - if (osp) { - ofproto_sflow_del_port__(os, osp); + struct dpif_sflow_port *dsp = dpif_sflow_find_port(ds, odp_port); + if (dsp) { + dpif_sflow_del_port__(ds, dsp); } } void -ofproto_sflow_set_options(struct ofproto_sflow *os, - const struct ofproto_sflow_options *options) +dpif_sflow_set_options(struct dpif_sflow *ds, + const struct ofproto_sflow_options *options) { - struct ofproto_sflow_port *osp; + struct dpif_sflow_port *dsp; bool options_changed; SFLReceiver *receiver; SFLAddress agentIP; @@ -398,25 +396,25 @@ ofproto_sflow_set_options(struct ofproto_sflow *os, if (sset_is_empty(&options->targets) || !options->sampling_rate) { /* No point in doing any work if there are no targets or nothing to * sample. */ - ofproto_sflow_clear(os); + dpif_sflow_clear(ds); return; } - options_changed = (!os->options - || !ofproto_sflow_options_equal(options, os->options)); + options_changed = (!ds->options + || !ofproto_sflow_options_equal(options, ds->options)); /* Configure collectors if options have changed or if we're shortchanged in * collectors (which indicates that opening one or more of the configured * collectors failed, so that we should retry). */ if (options_changed - || collectors_count(os->collectors) < sset_count(&options->targets)) { - collectors_destroy(os->collectors); + || collectors_count(ds->collectors) < sset_count(&options->targets)) { + collectors_destroy(ds->collectors); collectors_create(&options->targets, SFL_DEFAULT_COLLECTOR_PORT, - &os->collectors); - if (os->collectors == NULL) { + &ds->collectors); + if (ds->collectors == NULL) { VLOG_WARN_RL(&rl, "no collectors could be initialized, " "sFlow disabled"); - ofproto_sflow_clear(os); + dpif_sflow_clear(ds); return; } } @@ -425,61 +423,60 @@ ofproto_sflow_set_options(struct ofproto_sflow *os, if (!options_changed) { return; } - ofproto_sflow_options_destroy(os->options); - os->options = ofproto_sflow_options_clone(options); + ofproto_sflow_options_destroy(ds->options); + ds->options = ofproto_sflow_options_clone(options); /* Choose agent IP address. */ if (!sflow_choose_agent_address(options->agent_device, options->control_ip, &agentIP)) { - ofproto_sflow_clear(os); + dpif_sflow_clear(ds); return; } /* Create agent. */ VLOG_INFO("creating sFlow agent %d", options->sub_id); - if (os->sflow_agent) { - sfl_agent_release(os->sflow_agent); + if (ds->sflow_agent) { + sfl_agent_release(ds->sflow_agent); } - os->sflow_agent = xcalloc(1, sizeof *os->sflow_agent); + ds->sflow_agent = xcalloc(1, sizeof *ds->sflow_agent); now = time_wall(); - sfl_agent_init(os->sflow_agent, + sfl_agent_init(ds->sflow_agent, &agentIP, options->sub_id, now, /* Boot time. */ now, /* Current time. */ - os, /* Pointer supplied to callbacks. */ + ds, /* Pointer supplied to callbacks. */ sflow_agent_alloc_cb, sflow_agent_free_cb, sflow_agent_error_cb, sflow_agent_send_packet_cb); - receiver = sfl_agent_addReceiver(os->sflow_agent); + receiver = sfl_agent_addReceiver(ds->sflow_agent); sfl_receiver_set_sFlowRcvrOwner(receiver, "Open vSwitch sFlow"); sfl_receiver_set_sFlowRcvrTimeout(receiver, 0xffffffff); /* Set the sampling_rate down in the datapath. */ - dpif_set_sflow_probability(os->dpif, + dpif_set_sflow_probability(ds->dpif, MAX(1, UINT32_MAX / options->sampling_rate)); /* Add samplers and pollers for the currently known ports. */ - HMAP_FOR_EACH (osp, hmap_node, &os->ports) { - ofproto_sflow_add_poller(os, osp, osp->odp_port); - ofproto_sflow_add_sampler(os, osp); + HMAP_FOR_EACH (dsp, hmap_node, &ds->ports) { + dpif_sflow_add_poller(ds, dsp, dsp->odp_port); + dpif_sflow_add_sampler(ds, dsp); } } static int -ofproto_sflow_odp_port_to_ifindex(const struct ofproto_sflow *os, - uint16_t odp_port) +dpif_sflow_odp_port_to_ifindex(const struct dpif_sflow *ds, + uint16_t odp_port) { - struct ofproto_sflow_port *osp = ofproto_sflow_find_port(os, odp_port); - return osp ? SFL_DS_INDEX(osp->dsi) : 0; + struct dpif_sflow_port *dsp = dpif_sflow_find_port(ds, odp_port); + return dsp ? SFL_DS_INDEX(dsp->dsi) : 0; } void -ofproto_sflow_received(struct ofproto_sflow *os, - const struct dpif_upcall *upcall, - const struct flow *flow) +dpif_sflow_received(struct dpif_sflow *ds, const struct dpif_upcall *upcall, + const struct flow *flow) { SFL_FLOW_SAMPLE_TYPE fs; SFLFlow_sample_element hdrElem; @@ -492,14 +489,14 @@ ofproto_sflow_received(struct ofproto_sflow *os, /* Build a flow sample */ memset(&fs, 0, sizeof fs); - fs.input = ofproto_sflow_odp_port_to_ifindex(os, flow->in_port); + fs.input = dpif_sflow_odp_port_to_ifindex(ds, flow->in_port); fs.output = 0; /* Filled in correctly below. */ fs.sample_pool = upcall->sample_pool; /* We are going to give it to the sampler that represents this input port. * By implementing "ingress-only" sampling like this we ensure that we * never have to offer the same sample to more than one sampler. */ - sampler = sfl_agent_getSamplerByIfIndex(os->sflow_agent, fs.input); + sampler = sfl_agent_getSamplerByIfIndex(ds->sflow_agent, fs.input); if (!sampler) { VLOG_WARN_RL(&rl, "no sampler for input ifIndex (%"PRIu32")", fs.input); @@ -525,8 +522,8 @@ ofproto_sflow_received(struct ofproto_sflow *os, switchElem.tag = SFLFLOW_EX_SWITCH; switchElem.flowType.sw.src_vlan = vlan_tci_to_vid(flow->vlan_tci); switchElem.flowType.sw.src_priority = vlan_tci_to_pcp(flow->vlan_tci); - /* Initialize the output VLAN and priority to be the same as the input, - but these fields can be overriden below if affected by an action. */ + /* Initialize the output VLAN and priority to be the same as the input, + but these fields can be overriden below if affected by an action. */ switchElem.flowType.sw.dst_vlan = switchElem.flowType.sw.src_vlan; switchElem.flowType.sw.dst_priority = switchElem.flowType.sw.src_priority; @@ -537,8 +534,7 @@ ofproto_sflow_received(struct ofproto_sflow *os, switch (nl_attr_type(a)) { case ODP_ACTION_ATTR_OUTPUT: - fs.output = ofproto_sflow_odp_port_to_ifindex(os, - nl_attr_get_u32(a)); + fs.output = dpif_sflow_odp_port_to_ifindex(ds, nl_attr_get_u32(a)); n_outputs++; break; @@ -571,21 +567,21 @@ ofproto_sflow_received(struct ofproto_sflow *os, } void -ofproto_sflow_run(struct ofproto_sflow *os) +dpif_sflow_run(struct dpif_sflow *ds) { - if (ofproto_sflow_is_enabled(os)) { + if (dpif_sflow_is_enabled(ds)) { time_t now = time_now(); - if (now >= os->next_tick) { - sfl_agent_tick(os->sflow_agent, time_wall()); - os->next_tick = now + 1; + if (now >= ds->next_tick) { + sfl_agent_tick(ds->sflow_agent, time_wall()); + ds->next_tick = now + 1; } } } void -ofproto_sflow_wait(struct ofproto_sflow *os) +dpif_sflow_wait(struct dpif_sflow *ds) { - if (ofproto_sflow_is_enabled(os)) { - poll_timer_wait_until(os->next_tick * 1000LL); + if (dpif_sflow_is_enabled(ds)) { + poll_timer_wait_until(ds->next_tick * 1000LL); } } diff --git a/ofproto/ofproto-dpif-sflow.h b/ofproto/ofproto-dpif-sflow.h new file mode 100644 index 00000000..acafa328 --- /dev/null +++ b/ofproto/ofproto-dpif-sflow.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2009, 2010 InMon Corp. + * Copyright (c) 2009 Nicira Networks. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OFPROTO_DPIF_SFLOW_H +#define OFPROTO_DPIF_SFLOW_H 1 + +#include +#include "svec.h" + +struct dpif; +struct dpif_upcall; +struct flow; +struct ofproto_sflow_options; + +struct dpif_sflow *dpif_sflow_create(struct dpif *); +void dpif_sflow_destroy(struct dpif_sflow *); +void dpif_sflow_set_options(struct dpif_sflow *, + const struct ofproto_sflow_options *); +void dpif_sflow_clear(struct dpif_sflow *); +bool dpif_sflow_is_enabled(const struct dpif_sflow *); + +void dpif_sflow_add_port(struct dpif_sflow *, uint16_t odp_port, + const char *netdev_name); +void dpif_sflow_del_port(struct dpif_sflow *, uint16_t odp_port); + +void dpif_sflow_run(struct dpif_sflow *); +void dpif_sflow_wait(struct dpif_sflow *); + +void dpif_sflow_received(struct dpif_sflow *, const struct dpif_upcall *, + const struct flow *); + +#endif /* ofproto/ofproto-dpif-sflow.h */ diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 24316a28..c062ec3d 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -40,7 +40,7 @@ #include "ofp-util.h" #include "ofpbuf.h" #include "ofp-print.h" -#include "ofproto-sflow.h" +#include "ofproto-dpif-sflow.h" #include "poll-loop.h" #include "timer.h" #include "unaligned.h" @@ -315,7 +315,7 @@ struct ofproto_dpif { /* Bridging. */ struct netflow *netflow; - struct ofproto_sflow *sflow; + struct dpif_sflow *sflow; struct hmap bundles; /* Contains "struct ofbundle"s. */ struct mac_learning *ml; struct ofmirror *mirrors[MAX_MIRRORS]; @@ -501,7 +501,7 @@ destruct(struct ofproto *ofproto_) } netflow_destroy(ofproto->netflow); - ofproto_sflow_destroy(ofproto->sflow); + dpif_sflow_destroy(ofproto->sflow); hmap_destroy(&ofproto->bundles); mac_learning_destroy(ofproto->ml); @@ -548,7 +548,7 @@ run(struct ofproto *ofproto_) netflow_run(ofproto->netflow); } if (ofproto->sflow) { - ofproto_sflow_run(ofproto->sflow); + dpif_sflow_run(ofproto->sflow); } HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) { @@ -594,7 +594,7 @@ wait(struct ofproto *ofproto_) dpif_wait(ofproto->dpif); dpif_recv_wait(ofproto->dpif); if (ofproto->sflow) { - ofproto_sflow_wait(ofproto->sflow); + dpif_sflow_wait(ofproto->sflow); } if (!tag_set_is_empty(&ofproto->revalidate_set)) { poll_immediate_wake(); @@ -710,8 +710,8 @@ port_construct(struct ofport *port_) port->tag = tag_create_random(); if (ofproto->sflow) { - ofproto_sflow_add_port(ofproto->sflow, port->odp_port, - netdev_get_name(port->up.netdev)); + dpif_sflow_add_port(ofproto->sflow, port->odp_port, + netdev_get_name(port->up.netdev)); } return 0; @@ -726,7 +726,7 @@ port_destruct(struct ofport *port_) bundle_remove(port_); set_cfm(port_, NULL); if (ofproto->sflow) { - ofproto_sflow_del_port(ofproto->sflow, port->odp_port); + dpif_sflow_del_port(ofproto->sflow, port->odp_port); } } @@ -758,20 +758,20 @@ set_sflow(struct ofproto *ofproto_, const struct ofproto_sflow_options *sflow_options) { struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); - struct ofproto_sflow *os = ofproto->sflow; + struct dpif_sflow *ds = ofproto->sflow; if (sflow_options) { - if (!os) { + if (!ds) { struct ofport_dpif *ofport; - os = ofproto->sflow = ofproto_sflow_create(ofproto->dpif); + ds = ofproto->sflow = dpif_sflow_create(ofproto->dpif); HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) { - ofproto_sflow_add_port(os, ofport->odp_port, - netdev_get_name(ofport->up.netdev)); + dpif_sflow_add_port(ds, ofport->odp_port, + netdev_get_name(ofport->up.netdev)); } } - ofproto_sflow_set_options(os, sflow_options); + dpif_sflow_set_options(ds, sflow_options); } else { - ofproto_sflow_destroy(os); + dpif_sflow_destroy(ds); ofproto->sflow = NULL; } return 0; @@ -1693,7 +1693,7 @@ handle_upcall(struct ofproto_dpif *ofproto, struct dpif_upcall *upcall) case DPIF_UC_SAMPLE: if (ofproto->sflow) { odp_flow_key_to_flow(upcall->key, upcall->key_len, &flow); - ofproto_sflow_received(ofproto->sflow, upcall, &flow); + dpif_sflow_received(ofproto->sflow, upcall, &flow); } ofpbuf_delete(upcall->packet); break; diff --git a/ofproto/ofproto-sflow.h b/ofproto/ofproto-sflow.h deleted file mode 100644 index 6f9a93d2..00000000 --- a/ofproto/ofproto-sflow.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2009, 2010 InMon Corp. - * Copyright (c) 2009 Nicira Networks. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OFPROTO_SFLOW_H -#define OFPROTO_SFLOW_H 1 - -#include -#include "svec.h" - -struct dpif; -struct dpif_upcall; -struct flow; -struct ofproto_sflow_options; - -struct ofproto_sflow *ofproto_sflow_create(struct dpif *); -void ofproto_sflow_destroy(struct ofproto_sflow *); -void ofproto_sflow_set_options(struct ofproto_sflow *, - const struct ofproto_sflow_options *); -void ofproto_sflow_clear(struct ofproto_sflow *); -bool ofproto_sflow_is_enabled(const struct ofproto_sflow *); - -void ofproto_sflow_add_port(struct ofproto_sflow *, uint16_t odp_port, - const char *netdev_name); -void ofproto_sflow_del_port(struct ofproto_sflow *, uint16_t odp_port); - -void ofproto_sflow_run(struct ofproto_sflow *); -void ofproto_sflow_wait(struct ofproto_sflow *); - -void ofproto_sflow_received(struct ofproto_sflow *, - const struct dpif_upcall *, const struct flow *); - -#endif /* ofproto/ofproto-sflow.h */ -- 2.30.2