X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=ofproto%2Fofproto-sflow.c;h=a3f4d810f1e8aa78ebcbb999cd6053d498a1b4b5;hb=c15f1d11fa95a036eaa2504527bbd5decf082db6;hp=3739911d1e1a0f1a2c695e2326393abf1ecd9314;hpb=f1588b1fa1be46231ee079358e428dae74ff09cc;p=openvswitch diff --git a/ofproto/ofproto-sflow.c b/ofproto/ofproto-sflow.c index 3739911d..a3f4d810 100644 --- a/ofproto/ofproto-sflow.c +++ b/ofproto/ofproto-sflow.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010 Nicira Networks. + * Copyright (c) 2009, 2010, 2011 Nicira Networks. * Copyright (c) 2009 InMon Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,15 +25,17 @@ #include "hash.h" #include "hmap.h" #include "netdev.h" +#include "netlink.h" #include "ofpbuf.h" #include "ofproto.h" +#include "packets.h" #include "poll-loop.h" #include "sflow_api.h" #include "socket-util.h" #include "timeval.h" #include "vlog.h" -VLOG_DEFINE_THIS_MODULE(sflow) +VLOG_DEFINE_THIS_MODULE(sflow); struct ofproto_sflow_port { struct hmap_node hmap_node; /* In struct ofproto_sflow's "ports" hmap. */ @@ -70,7 +72,7 @@ static bool ofproto_sflow_options_equal(const struct ofproto_sflow_options *a, const struct ofproto_sflow_options *b) { - return (svec_equal(&a->targets, &b->targets) + return (sset_equals(&a->targets, &b->targets) && a->sampling_rate == b->sampling_rate && a->polling_interval == b->polling_interval && a->header_len == b->header_len @@ -83,7 +85,7 @@ static struct ofproto_sflow_options * ofproto_sflow_options_clone(const struct ofproto_sflow_options *old) { struct ofproto_sflow_options *new = xmemdup(old, sizeof *old); - svec_clone(&new->targets, &old->targets); + sset_clone(&new->targets, &old->targets); new->agent_device = old->agent_device ? xstrdup(old->agent_device) : NULL; new->control_ip = old->control_ip ? xstrdup(old->control_ip) : NULL; return new; @@ -93,7 +95,7 @@ static void ofproto_sflow_options_destroy(struct ofproto_sflow_options *options) { if (options) { - svec_destroy(&options->targets); + sset_destroy(&options->targets); free(options->agent_device); free(options->control_ip); free(options); @@ -181,10 +183,8 @@ sflow_agent_get_counters(void *os_, SFLPoller *poller, counters->ifDirection = 0; } if (!netdev_get_flags(osp->netdev, &flags) && flags & NETDEV_UP) { - bool carrier; - counters->ifStatus = 1; /* ifAdminStatus up. */ - if (!netdev_get_carrier(osp->netdev, &carrier) && carrier) { + if (netdev_get_carrier(osp->netdev)) { counters->ifStatus |= 2; /* ifOperStatus us. */ } } else { @@ -252,7 +252,7 @@ sflow_choose_agent_address(const char *agent_device, const char *control_ip, return false; success: - agent_addr->address.ip_v4.addr = in4.s_addr; + agent_addr->address.ip_v4.addr = (OVS_FORCE uint32_t) in4.s_addr; return true; } @@ -395,7 +395,7 @@ ofproto_sflow_set_options(struct ofproto_sflow *os, SFLAddress agentIP; time_t now; - if (!options->targets.n || !options->sampling_rate) { + 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); @@ -409,7 +409,7 @@ ofproto_sflow_set_options(struct ofproto_sflow *os, * 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) < options->targets.n) { + || collectors_count(os->collectors) < sset_count(&options->targets)) { collectors_destroy(os->collectors); collectors_create(&options->targets, SFL_DEFAULT_COLLECTOR_PORT, &os->collectors); @@ -477,56 +477,24 @@ ofproto_sflow_odp_port_to_ifindex(const struct ofproto_sflow *os, } void -ofproto_sflow_received(struct ofproto_sflow *os, struct odp_msg *msg) +ofproto_sflow_received(struct ofproto_sflow *os, + const struct dpif_upcall *upcall, + const struct flow *flow) { SFL_FLOW_SAMPLE_TYPE fs; SFLFlow_sample_element hdrElem; SFLSampled_header *header; SFLFlow_sample_element switchElem; SFLSampler *sampler; - const struct odp_sflow_sample_header *hdr; - const union odp_action *actions; - struct ofpbuf payload; - size_t n_actions, n_outputs; - size_t min_size; - flow_t flow; - size_t i; - - /* Get odp_sflow_sample_header. */ - min_size = sizeof *msg + sizeof *hdr; - if (min_size > msg->length) { - VLOG_WARN_RL(&rl, "sFlow packet too small (%"PRIu32" < %zu)", - msg->length, min_size); - return; - } - hdr = (const struct odp_sflow_sample_header *) (msg + 1); - - /* Get actions. */ - n_actions = hdr->n_actions; - if (n_actions > 65536 / sizeof *actions) { - VLOG_WARN_RL(&rl, "too many actions in sFlow packet (%zu > %zu)", - 65536 / sizeof *actions, n_actions); - return; - } - min_size += n_actions * sizeof *actions; - if (min_size > msg->length) { - VLOG_WARN_RL(&rl, "sFlow packet with %zu actions too small " - "(%"PRIu32" < %zu)", - n_actions, msg->length, min_size); - return; - } - actions = (const union odp_action *) (hdr + 1); - - /* Get packet payload and extract flow. */ - payload.data = (union odp_action *) (actions + n_actions); - payload.size = msg->length - min_size; - flow_extract(&payload, 0, msg->port, &flow); + unsigned int left; + struct nlattr *a; + size_t n_outputs; /* Build a flow sample */ memset(&fs, 0, sizeof fs); - fs.input = ofproto_sflow_odp_port_to_ifindex(os, msg->port); + fs.input = ofproto_sflow_odp_port_to_ifindex(os, flow->in_port); fs.output = 0; /* Filled in correctly below. */ - fs.sample_pool = hdr->sample_pool; + 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 @@ -545,18 +513,18 @@ ofproto_sflow_received(struct ofproto_sflow *os, struct odp_msg *msg) header->header_protocol = SFLHEADER_ETHERNET_ISO8023; /* The frame_length should include the Ethernet FCS (4 bytes), but it has already been stripped, so we need to add 4 here. */ - header->frame_length = payload.size + 4; + header->frame_length = upcall->packet->size + 4; /* Ethernet FCS stripped off. */ header->stripped = 4; - header->header_length = MIN(payload.size, + header->header_length = MIN(upcall->packet->size, sampler->sFlowFsMaximumHeaderSize); - header->header_bytes = payload.data; + header->header_bytes = upcall->packet->data; /* Add extended switch element. */ memset(&switchElem, 0, sizeof(switchElem)); switchElem.tag = SFLFLOW_EX_SWITCH; - switchElem.flowType.sw.src_vlan = ntohs(flow.dl_vlan); - switchElem.flowType.sw.src_priority = -1; /* XXX */ + 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. */ switchElem.flowType.sw.dst_vlan = switchElem.flowType.sw.src_vlan; @@ -564,21 +532,20 @@ ofproto_sflow_received(struct ofproto_sflow *os, struct odp_msg *msg) /* Figure out the output ports. */ n_outputs = 0; - for (i = 0; i < n_actions; i++) { - const union odp_action *a = &actions[i]; + NL_ATTR_FOR_EACH_UNSAFE (a, left, upcall->actions, upcall->actions_len) { + ovs_be16 tci; - switch (a->type) { - case ODPAT_OUTPUT: - fs.output = ofproto_sflow_odp_port_to_ifindex(os, a->output.port); + switch (nl_attr_type(a)) { + case ODP_ACTION_ATTR_OUTPUT: + fs.output = ofproto_sflow_odp_port_to_ifindex(os, + nl_attr_get_u32(a)); n_outputs++; break; - case ODPAT_SET_VLAN_VID: - switchElem.flowType.sw.dst_vlan = ntohs(a->vlan_vid.vlan_vid); - break; - - case ODPAT_SET_VLAN_PCP: - switchElem.flowType.sw.dst_priority = a->vlan_pcp.vlan_pcp; + case ODP_ACTION_ATTR_SET_DL_TCI: + tci = nl_attr_get_be16(a); + switchElem.flowType.sw.dst_vlan = vlan_tci_to_vid(tci); + switchElem.flowType.sw.dst_priority = vlan_tci_to_pcp(tci); break; default: