NOTICE \
OPENFLOW-1.1+ \
PORTING \
+ README-OFTest \
README-gcov \
README-lisp \
REPORTING-BUGS \
SUFFIXES += .in
.in:
+ @mkdir -p $$(dirname $@)
$(PERL) $(srcdir)/build-aux/soexpand.pl -I$(srcdir) < $< | \
sed \
-e 's,[@]PKIDIR[@],$(PKIDIR),g' \
(cd datapath && $(MAKE) distfiles); \
(cat distfiles; sed 's|^|datapath/|' datapath/distfiles) | \
sort -u > all-distfiles; \
- (cd $(srcdir) && git ls-files) | grep -v '\.gitignore$$' | \
+ (cd $(srcdir) && git ls-files) | grep -vFf $(srcdir)/.non-distfiles | \
sort -u > all-gitfiles; \
comm -1 -3 all-distfiles all-gitfiles > missing-distfiles; \
if test -s missing-distfiles; then \
fi
.PHONY: config-h-check
- # Check that "struct vlog_ratelimit" is always declared "static".
- ALL_LOCAL += rate-limit-check
- rate-limit-check:
+ # Check that certain data structures are always declared "static".
+ ALL_LOCAL += static-check
+ static-check:
@if test -e $(srcdir)/.git && (git --version) >/dev/null 2>&1 && \
- git --no-pager grep -n -E '^[ ]+struct vlog_rate_limit.*=' $(srcdir); \
+ git --no-pager grep -n -E '^[ ]+(struct vlog_rate_limit|pthread_once_t|struct ovsthread_once).*=' $(srcdir); \
then \
echo "See above for list of violations of the rule that "; \
- echo "'struct vlog_rate_limit' must always be 'static'"; \
+ echo "certain data structures must always be 'static'"; \
exit 1; \
fi
- .PHONY: rate-limit-check
+ .PHONY: static-check
# Check that assert.h is not used outside a whitelist of files.
ALL_LOCAL += check-assert-h-usage
include xenserver/automake.mk
include python/automake.mk
include python/compat/automake.mk
+include planetlab/automake.mk
include tutorial/automake.mk
- # Copyright (C) 2009, 2010, 2011, 2012 Nicira, Inc.
+ # Copyright (C) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
lib/flow.h \
lib/hash.c \
lib/hash.h \
+ lib/hindex.c \
+ lib/hindex.h \
lib/hmap.c \
lib/hmap.h \
lib/hmapx.c \
lib/jsonrpc.h \
lib/lacp.c \
lib/lacp.h \
- lib/leak-checker.c \
- lib/leak-checker.h \
lib/learn.c \
lib/learn.h \
lib/learning-switch.c \
lib/multipath.c \
lib/multipath.h \
lib/netdev-dummy.c \
+ lib/netdev-tunnel.c \
+ lib/netdev-pltap.c \
lib/netdev-provider.h \
lib/netdev-vport.c \
lib/netdev-vport.h \
lib/netlink.h \
lib/nx-match.c \
lib/nx-match.h \
+ lib/odp-execute.c \
+ lib/odp-execute.h \
lib/odp-util.c \
lib/odp-util.h \
lib/ofp-actions.c \
lib/ofp-version-opt.c \
lib/ofpbuf.c \
lib/ofpbuf.h \
+ lib/ovs-atomic-c11.h \
+ lib/ovs-atomic-gcc4+.c \
+ lib/ovs-atomic-gcc4+.h \
+ lib/ovs-atomic-gcc4.7+.h \
+ lib/ovs-atomic-pthreads.c \
+ lib/ovs-atomic-pthreads.h \
+ lib/ovs-atomic.h \
+ lib/ovs-thread.c \
+ lib/ovs-thread.h \
lib/ovsdb-data.c \
lib/ovsdb-data.h \
lib/ovsdb-error.c \
lib/timeval.h \
lib/token-bucket.c \
lib/token-bucket.h \
+ lib/tunalloc.c \
+ lib/tunalloc.h \
lib/type-props.h \
lib/unaligned.h \
lib/unicode.c \
lib/coverage-unixctl.man \
lib/daemon.man \
lib/daemon-syn.man \
- lib/leak-checker.man \
lib/memory-unixctl.man \
lib/ofp-version.man \
lib/ovs.tmac \
mv lib/dirs.c.tmp lib/dirs.c
$(srcdir)/lib/ofp-errors.inc: \
- lib/ofp-errors.h $(srcdir)/build-aux/extract-ofp-errors
+ lib/ofp-errors.h include/openflow/openflow-common.h \
+ $(srcdir)/build-aux/extract-ofp-errors
$(run_python) $(srcdir)/build-aux/extract-ofp-errors \
- $(srcdir)/lib/ofp-errors.h > $@.tmp && mv $@.tmp $@
+ $(srcdir)/lib/ofp-errors.h \
+ $(srcdir)/include/openflow/openflow-common.h > $@.tmp
+ mv $@.tmp $@
$(srcdir)/lib/ofp-errors.c: $(srcdir)/lib/ofp-errors.inc
EXTRA_DIST += build-aux/extract-ofp-errors lib/ofp-errors.inc
#include "netdev.h"
#include "netdev-vport.h"
#include "netlink.h"
+ #include "odp-execute.h"
#include "odp-util.h"
#include "ofp-print.h"
#include "ofpbuf.h"
/* A port in a netdev-based datapath. */
struct dp_netdev_port {
- int port_no; /* Index into dp_netdev's 'ports'. */
+ odp_port_t port_no; /* Index into dp_netdev's 'ports'. */
struct list node; /* Element in dp_netdev's 'port_list'. */
struct netdev *netdev;
struct netdev_saved_flags *sf;
/* Maximum port MTU seen so far. */
static int max_mtu = ETH_PAYLOAD_MAX;
- static int get_port_by_number(struct dp_netdev *, uint32_t port_no,
+ static int get_port_by_number(struct dp_netdev *, odp_port_t port_no,
struct dp_netdev_port **portp);
static int get_port_by_name(struct dp_netdev *, const char *devname,
struct dp_netdev_port **portp);
static void dp_netdev_free(struct dp_netdev *);
static void dp_netdev_flow_flush(struct dp_netdev *);
static int do_add_port(struct dp_netdev *, const char *devname,
- const char *type, uint32_t port_no);
- static int do_del_port(struct dp_netdev *, uint32_t port_no);
+ const char *type, odp_port_t port_no);
+ static int do_del_port(struct dp_netdev *, odp_port_t port_no);
static int dpif_netdev_open(const struct dpif_class *, const char *name,
bool create, struct dpif **);
static int dp_netdev_output_userspace(struct dp_netdev *, const struct ofpbuf *,
struct ofpbuf *, struct flow *,
const struct nlattr *actions,
size_t actions_len);
+ static void dp_netdev_port_input(struct dp_netdev *dp,
+ struct dp_netdev_port *port,
+ struct ofpbuf *packet, uint32_t skb_priority,
+ uint32_t skb_mark, const struct flow_tnl *tnl);
static struct dpif_netdev *
dpif_netdev_cast(const struct dpif *dpif)
return class != &dpif_netdev_class;
}
+static bool
+dpif_netdev_class_is_planetlab(const struct dpif_class *class)
+{
+ return class == &dpif_planetlab_class;
+}
+
static const char *
dpif_netdev_port_open_type(const struct dpif_class *class, const char *type)
{
return strcmp(type, "internal") ? type
+ : dpif_netdev_class_is_planetlab(class) ? "pltap"
: dpif_netdev_class_is_dummy(class) ? "dummy"
: "tap";
}
return &dpif->dpif;
}
- static int
+ /* Choose an unused, non-zero port number and return it on success.
+ * Return ODPP_NONE on failure. */
+ static odp_port_t
choose_port(struct dp_netdev *dp, const char *name)
{
- int port_no;
+ uint32_t port_no;
- if (dp->class != &dpif_netdev_class) {
+ if (dp->class != &dpif_netdev_class &&
+ dp->class != &dpif_planetlab_class) {
const char *p;
int start_no = 0;
port_no = start_no + strtol(p, NULL, 10);
if (port_no > 0 && port_no < MAX_PORTS
&& !dp->ports[port_no]) {
- return port_no;
+ return u32_to_odp(port_no);
}
break;
}
for (port_no = 1; port_no < MAX_PORTS; port_no++) {
if (!dp->ports[port_no]) {
- return port_no;
+ return u32_to_odp(port_no);
}
}
- return -1;
+ return ODPP_NONE;
}
static int
hmap_init(&dp->flow_table);
list_init(&dp->port_list);
- error = do_add_port(dp, name, "internal", OVSP_LOCAL);
+ error = do_add_port(dp, name, "internal", ODPP_LOCAL);
if (error) {
dp_netdev_free(dp);
return error;
static int
do_add_port(struct dp_netdev *dp, const char *devname, const char *type,
- uint32_t port_no)
+ odp_port_t port_no)
{
struct netdev_saved_flags *sf;
struct dp_netdev_port *port;
if (error
&& !(error == EOPNOTSUPP && dpif_netdev_class_is_dummy(dp->class))) {
VLOG_ERR("%s: cannot receive packets on this network device (%s)",
- devname, strerror(errno));
+ devname, ovs_strerror(errno));
netdev_close(netdev);
return error;
}
}
list_push_back(&dp->port_list, &port->node);
- dp->ports[port_no] = port;
+ dp->ports[odp_to_u32(port_no)] = port;
dp->serial++;
return 0;
static int
dpif_netdev_port_add(struct dpif *dpif, struct netdev *netdev,
- uint32_t *port_nop)
+ odp_port_t *port_nop)
{
struct dp_netdev *dp = get_dp_netdev(dpif);
- int port_no;
-
- if (*port_nop != UINT32_MAX) {
- if (*port_nop >= MAX_PORTS) {
+ char namebuf[NETDEV_VPORT_NAME_BUFSIZE];
+ const char *dpif_port;
+ odp_port_t port_no;
+
+ dpif_port = netdev_vport_get_dpif_port(netdev, namebuf, sizeof namebuf);
+ if (*port_nop != ODPP_NONE) {
+ uint32_t port_idx = odp_to_u32(*port_nop);
+ if (port_idx >= MAX_PORTS) {
return EFBIG;
- } else if (dp->ports[*port_nop]) {
+ } else if (dp->ports[port_idx]) {
return EBUSY;
}
port_no = *port_nop;
} else {
- port_no = choose_port(dp, netdev_vport_get_dpif_port(netdev));
+ port_no = choose_port(dp, dpif_port);
}
- if (port_no >= 0) {
+ if (port_no != ODPP_NONE) {
*port_nop = port_no;
- return do_add_port(dp, netdev_vport_get_dpif_port(netdev),
- netdev_get_type(netdev), port_no);
+ return do_add_port(dp, dpif_port, netdev_get_type(netdev), port_no);
}
return EFBIG;
}
static int
- dpif_netdev_port_del(struct dpif *dpif, uint32_t port_no)
+ dpif_netdev_port_del(struct dpif *dpif, odp_port_t port_no)
{
struct dp_netdev *dp = get_dp_netdev(dpif);
- return port_no == OVSP_LOCAL ? EINVAL : do_del_port(dp, port_no);
+ return (port_no == ODPP_LOCAL ?
+ EINVAL : do_del_port(dp, port_no));
}
static bool
- is_valid_port_number(uint32_t port_no)
+ is_valid_port_number(odp_port_t port_no)
{
- return port_no < MAX_PORTS;
+ return odp_to_u32(port_no) < MAX_PORTS;
}
static int
get_port_by_number(struct dp_netdev *dp,
- uint32_t port_no, struct dp_netdev_port **portp)
+ odp_port_t port_no, struct dp_netdev_port **portp)
{
if (!is_valid_port_number(port_no)) {
*portp = NULL;
return EINVAL;
} else {
- *portp = dp->ports[port_no];
+ *portp = dp->ports[odp_to_u32(port_no)];
return *portp ? 0 : ENOENT;
}
}
struct dp_netdev_port *port;
LIST_FOR_EACH (port, node, &dp->port_list) {
- if (!strcmp(netdev_vport_get_dpif_port(port->netdev), devname)) {
+ if (!strcmp(netdev_get_name(port->netdev), devname)) {
*portp = port;
return 0;
}
}
static int
- do_del_port(struct dp_netdev *dp, uint32_t port_no)
+ do_del_port(struct dp_netdev *dp, odp_port_t port_no)
{
struct dp_netdev_port *port;
int error;
}
list_remove(&port->node);
- dp->ports[port->port_no] = NULL;
+ dp->ports[odp_to_u32(port_no)] = NULL;
dp->serial++;
netdev_close(port->netdev);
answer_port_query(const struct dp_netdev_port *port,
struct dpif_port *dpif_port)
{
- dpif_port->name = xstrdup(netdev_vport_get_dpif_port(port->netdev));
+ dpif_port->name = xstrdup(netdev_get_name(port->netdev));
dpif_port->type = xstrdup(port->type);
dpif_port->port_no = port->port_no;
}
static int
- dpif_netdev_port_query_by_number(const struct dpif *dpif, uint32_t port_no,
+ dpif_netdev_port_query_by_number(const struct dpif *dpif, odp_port_t port_no,
struct dpif_port *dpif_port)
{
struct dp_netdev *dp = get_dp_netdev(dpif);
return error;
}
- static int
+ static odp_port_t
dpif_netdev_get_max_ports(const struct dpif *dpif OVS_UNUSED)
{
- return MAX_PORTS;
+ return u32_to_odp(MAX_PORTS);
}
static void
}
struct dp_netdev_port_state {
- uint32_t port_no;
+ odp_port_t port_no;
char *name;
};
{
struct dp_netdev_port_state *state = state_;
struct dp_netdev *dp = get_dp_netdev(dpif);
- uint32_t port_no;
+ uint32_t port_idx;
- for (port_no = state->port_no; port_no < MAX_PORTS; port_no++) {
- struct dp_netdev_port *port = dp->ports[port_no];
+ for (port_idx = odp_to_u32(state->port_no);
+ port_idx < MAX_PORTS; port_idx++) {
+ struct dp_netdev_port *port = dp->ports[port_idx];
if (port) {
free(state->name);
- state->name = xstrdup(netdev_vport_get_dpif_port(port->netdev));
+ state->name = xstrdup(netdev_get_name(port->netdev));
dpif_port->name = state->name;
dpif_port->type = port->type;
dpif_port->port_no = port->port_no;
- state->port_no = port_no + 1;
+ state->port_no = u32_to_odp(port_idx + 1);
return 0;
}
}
return EINVAL;
}
- if (flow->in_port < OFPP_MAX
- ? flow->in_port >= MAX_PORTS
- : flow->in_port != OFPP_LOCAL && flow->in_port != OFPP_NONE) {
+ if (!is_valid_port_number(flow->in_port.odp_port)) {
return EINVAL;
}
static int
dpif_netdev_flow_dump_next(const struct dpif *dpif, void *state_,
const struct nlattr **key, size_t *key_len,
+ const struct nlattr **mask, size_t *mask_len,
const struct nlattr **actions, size_t *actions_len,
const struct dpif_flow_stats **stats)
{
struct ofpbuf buf;
ofpbuf_use_stack(&buf, &state->keybuf, sizeof state->keybuf);
- odp_flow_key_from_flow(&buf, &flow->key, flow->key.in_port);
+ odp_flow_key_from_flow(&buf, &flow->key, flow->key.in_port.odp_port);
*key = buf.data;
*key_len = buf.size;
}
+ if (mask) {
+ *mask = NULL;
+ *mask_len = 0;
+ }
+
if (actions) {
free(state->actions);
state->actions = xmemdup(flow->actions, flow->actions_len);
ofpbuf_reserve(©, DP_NETDEV_HEADROOM);
ofpbuf_put(©, execute->packet->data, execute->packet->size);
- flow_extract(©, 0, 0, NULL, -1, &key);
+ flow_extract(©, 0, 0, NULL, NULL, &key);
error = dpif_netdev_flow_from_nlattrs(execute->key, execute->key_len,
&key);
if (!error) {
static void
dp_netdev_port_input(struct dp_netdev *dp, struct dp_netdev_port *port,
- struct ofpbuf *packet)
+ struct ofpbuf *packet, uint32_t skb_priority,
+ uint32_t skb_mark, const struct flow_tnl *tnl)
{
struct dp_netdev_flow *flow;
struct flow key;
+ union flow_in_port in_port_;
if (packet->size < ETH_HEADER_LEN) {
return;
}
- flow_extract(packet, 0, 0, NULL, port->port_no, &key);
+ in_port_.odp_port = port->port_no;
+ flow_extract(packet, skb_priority, skb_mark, tnl, &in_port_, &key);
flow = dp_netdev_lookup_flow(dp, &key);
if (flow) {
dp_netdev_flow_used(flow, packet);
error = port->rx ? netdev_rx_recv(port->rx, &packet) : EOPNOTSUPP;
if (!error) {
- dp_netdev_port_input(dp, port, &packet);
+ dp_netdev_port_input(dp, port, &packet, 0, 0, NULL);
} else if (error != EAGAIN && error != EOPNOTSUPP) {
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
+
VLOG_ERR_RL(&rl, "error receiving data from %s: %s",
- netdev_vport_get_dpif_port(port->netdev),
- strerror(error));
+ netdev_get_name(port->netdev), ovs_strerror(error));
}
}
ofpbuf_uninit(&packet);
}
static void
- dp_netdev_set_dl(struct ofpbuf *packet, const struct ovs_key_ethernet *eth_key)
- {
- struct eth_header *eh = packet->l2;
-
- memcpy(eh->eth_src, eth_key->eth_src, sizeof eh->eth_src);
- memcpy(eh->eth_dst, eth_key->eth_dst, sizeof eh->eth_dst);
- }
-
- static void
- dp_netdev_output_port(struct dp_netdev *dp, struct ofpbuf *packet,
- uint32_t out_port)
+ dp_netdev_output_port(void *dp_, struct ofpbuf *packet, uint32_t out_port)
{
+ struct dp_netdev *dp = dp_;
struct dp_netdev_port *p = dp->ports[out_port];
if (p) {
netdev_send(p->netdev, packet);
ofpbuf_init(buf, buf_size);
/* Put ODP flow. */
- odp_flow_key_from_flow(buf, flow, flow->in_port);
+ odp_flow_key_from_flow(buf, flow, flow->in_port.odp_port);
upcall->key = buf->data;
upcall->key_len = buf->size;
}
static void
- dp_netdev_sample(struct dp_netdev *dp,
- struct ofpbuf *packet, struct flow *key,
- const struct nlattr *action)
- {
- const struct nlattr *subactions = NULL;
- const struct nlattr *a;
- size_t left;
-
- NL_NESTED_FOR_EACH_UNSAFE (a, left, action) {
- int type = nl_attr_type(a);
-
- switch ((enum ovs_sample_attr) type) {
- case OVS_SAMPLE_ATTR_PROBABILITY:
- if (random_uint32() >= nl_attr_get_u32(a)) {
- return;
- }
- break;
-
- case OVS_SAMPLE_ATTR_ACTIONS:
- subactions = a;
- break;
-
- case OVS_SAMPLE_ATTR_UNSPEC:
- case __OVS_SAMPLE_ATTR_MAX:
- default:
- NOT_REACHED();
- }
- }
-
- dp_netdev_execute_actions(dp, packet, key, nl_attr_get(subactions),
- nl_attr_get_size(subactions));
- }
-
- static void
- dp_netdev_action_userspace(struct dp_netdev *dp,
- struct ofpbuf *packet, struct flow *key,
- const struct nlattr *a)
+ dp_netdev_action_userspace(void *dp, struct ofpbuf *packet,
+ const struct flow *key,
+ const struct nlattr *userdata)
{
- const struct nlattr *userdata;
-
- userdata = nl_attr_find_nested(a, OVS_USERSPACE_ATTR_USERDATA);
dp_netdev_output_userspace(dp, packet, DPIF_UC_ACTION, key, userdata);
}
- static void
- execute_set_action(struct ofpbuf *packet, const struct nlattr *a)
- {
- enum ovs_key_attr type = nl_attr_type(a);
- const struct ovs_key_ipv4 *ipv4_key;
- const struct ovs_key_ipv6 *ipv6_key;
- const struct ovs_key_tcp *tcp_key;
- const struct ovs_key_udp *udp_key;
-
- switch (type) {
- case OVS_KEY_ATTR_PRIORITY:
- case OVS_KEY_ATTR_SKB_MARK:
- case OVS_KEY_ATTR_TUNNEL:
- /* not implemented */
- break;
-
- case OVS_KEY_ATTR_ETHERNET:
- dp_netdev_set_dl(packet,
- nl_attr_get_unspec(a, sizeof(struct ovs_key_ethernet)));
- break;
-
- case OVS_KEY_ATTR_IPV4:
- ipv4_key = nl_attr_get_unspec(a, sizeof(struct ovs_key_ipv4));
- packet_set_ipv4(packet, ipv4_key->ipv4_src, ipv4_key->ipv4_dst,
- ipv4_key->ipv4_tos, ipv4_key->ipv4_ttl);
- break;
-
- case OVS_KEY_ATTR_IPV6:
- ipv6_key = nl_attr_get_unspec(a, sizeof(struct ovs_key_ipv6));
- packet_set_ipv6(packet, ipv6_key->ipv6_proto, ipv6_key->ipv6_src,
- ipv6_key->ipv6_dst, ipv6_key->ipv6_tclass,
- ipv6_key->ipv6_label, ipv6_key->ipv6_hlimit);
- break;
-
- case OVS_KEY_ATTR_TCP:
- tcp_key = nl_attr_get_unspec(a, sizeof(struct ovs_key_tcp));
- packet_set_tcp_port(packet, tcp_key->tcp_src, tcp_key->tcp_dst);
- break;
-
- case OVS_KEY_ATTR_UDP:
- udp_key = nl_attr_get_unspec(a, sizeof(struct ovs_key_udp));
- packet_set_udp_port(packet, udp_key->udp_src, udp_key->udp_dst);
- break;
-
- case OVS_KEY_ATTR_MPLS:
- set_mpls_lse(packet, nl_attr_get_be32(a));
- break;
-
- case OVS_KEY_ATTR_UNSPEC:
- case OVS_KEY_ATTR_ENCAP:
- case OVS_KEY_ATTR_ETHERTYPE:
- case OVS_KEY_ATTR_IN_PORT:
- case OVS_KEY_ATTR_VLAN:
- case OVS_KEY_ATTR_ICMP:
- case OVS_KEY_ATTR_ICMPV6:
- case OVS_KEY_ATTR_ARP:
- case OVS_KEY_ATTR_ND:
- case __OVS_KEY_ATTR_MAX:
- default:
- NOT_REACHED();
- }
- }
-
static void
dp_netdev_execute_actions(struct dp_netdev *dp,
struct ofpbuf *packet, struct flow *key,
const struct nlattr *actions,
size_t actions_len)
{
- const struct nlattr *a;
- unsigned int left;
-
- NL_ATTR_FOR_EACH_UNSAFE (a, left, actions, actions_len) {
- int type = nl_attr_type(a);
-
- switch ((enum ovs_action_attr) type) {
- case OVS_ACTION_ATTR_OUTPUT:
- dp_netdev_output_port(dp, packet, nl_attr_get_u32(a));
- break;
-
- case OVS_ACTION_ATTR_USERSPACE:
- dp_netdev_action_userspace(dp, packet, key, a);
- break;
-
- case OVS_ACTION_ATTR_PUSH_VLAN: {
- const struct ovs_action_push_vlan *vlan = nl_attr_get(a);
- eth_push_vlan(packet, vlan->vlan_tci);
- break;
- }
-
- case OVS_ACTION_ATTR_POP_VLAN:
- eth_pop_vlan(packet);
- break;
-
- case OVS_ACTION_ATTR_PUSH_MPLS: {
- const struct ovs_action_push_mpls *mpls = nl_attr_get(a);
- push_mpls(packet, mpls->mpls_ethertype, mpls->mpls_lse);
- break;
- }
-
- case OVS_ACTION_ATTR_POP_MPLS:
- pop_mpls(packet, nl_attr_get_be16(a));
- break;
-
- case OVS_ACTION_ATTR_SET:
- execute_set_action(packet, nl_attr_get(a));
- break;
-
- case OVS_ACTION_ATTR_SAMPLE:
- dp_netdev_sample(dp, packet, key, a);
- break;
-
- case OVS_ACTION_ATTR_UNSPEC:
- case __OVS_ACTION_ATTR_MAX:
- NOT_REACHED();
- }
- }
+ odp_execute_actions(dp, packet, key, actions, actions_len,
+ dp_netdev_output_port, dp_netdev_action_userspace);
}
+#define DPIF_NETDEV_CLASS_FUNCTIONS \
+ dpif_netdev_enumerate, \
+ dpif_netdev_port_open_type, \
+ dpif_netdev_open, \
+ dpif_netdev_close, \
+ dpif_netdev_destroy, \
+ dpif_netdev_run, \
+ dpif_netdev_wait, \
+ dpif_netdev_get_stats, \
+ dpif_netdev_port_add, \
+ dpif_netdev_port_del, \
+ dpif_netdev_port_query_by_number, \
+ dpif_netdev_port_query_by_name, \
+ dpif_netdev_get_max_ports, \
+ NULL, /* port_get_pid */ \
+ dpif_netdev_port_dump_start, \
+ dpif_netdev_port_dump_next, \
+ dpif_netdev_port_dump_done, \
+ dpif_netdev_port_poll, \
+ dpif_netdev_port_poll_wait, \
+ dpif_netdev_flow_get, \
+ dpif_netdev_flow_put, \
+ dpif_netdev_flow_del, \
+ dpif_netdev_flow_flush, \
+ dpif_netdev_flow_dump_start, \
+ dpif_netdev_flow_dump_next, \
+ dpif_netdev_flow_dump_done, \
+ dpif_netdev_execute, \
+ NULL, /* operate */ \
+ dpif_netdev_recv_set, \
+ dpif_netdev_queue_to_priority, \
+ dpif_netdev_recv, \
+ dpif_netdev_recv_wait, \
+ dpif_netdev_recv_purge, \
+
const struct dpif_class dpif_netdev_class = {
"netdev",
- dpif_netdev_enumerate,
- dpif_netdev_port_open_type,
- dpif_netdev_open,
- dpif_netdev_close,
- dpif_netdev_destroy,
- dpif_netdev_run,
- dpif_netdev_wait,
- dpif_netdev_get_stats,
- dpif_netdev_port_add,
- dpif_netdev_port_del,
- dpif_netdev_port_query_by_number,
- dpif_netdev_port_query_by_name,
- dpif_netdev_get_max_ports,
- NULL, /* port_get_pid */
- dpif_netdev_port_dump_start,
- dpif_netdev_port_dump_next,
- dpif_netdev_port_dump_done,
- dpif_netdev_port_poll,
- dpif_netdev_port_poll_wait,
- dpif_netdev_flow_get,
- dpif_netdev_flow_put,
- dpif_netdev_flow_del,
- dpif_netdev_flow_flush,
- dpif_netdev_flow_dump_start,
- dpif_netdev_flow_dump_next,
- dpif_netdev_flow_dump_done,
- dpif_netdev_execute,
- NULL, /* operate */
- dpif_netdev_recv_set,
- dpif_netdev_queue_to_priority,
- dpif_netdev_recv,
- dpif_netdev_recv_wait,
- dpif_netdev_recv_purge,
+ DPIF_NETDEV_CLASS_FUNCTIONS
+};
+
+const struct dpif_class dpif_planetlab_class = {
+ "planetlab",
+ DPIF_NETDEV_CLASS_FUNCTIONS
};
static void
dpif_dummy_register__("dummy");
}
+
/*
- * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* port number. Returns EBUSY if caller attempted to choose a port
* number, and it was in use. */
int (*port_add)(struct dpif *dpif, struct netdev *netdev,
- uint32_t *port_no);
+ odp_port_t *port_no);
/* Removes port numbered 'port_no' from 'dpif'. */
- int (*port_del)(struct dpif *dpif, uint32_t port_no);
+ int (*port_del)(struct dpif *dpif, odp_port_t port_no);
/* Queries 'dpif' for a port with the given 'port_no' or 'devname'.
* If 'port' is not null, stores information about the port into
* If 'port' is not null, the caller takes ownership of data in
* 'port' and must free it with dpif_port_destroy() when it is no
* longer needed. */
- int (*port_query_by_number)(const struct dpif *dpif, uint32_t port_no,
+ int (*port_query_by_number)(const struct dpif *dpif, odp_port_t port_no,
struct dpif_port *port);
int (*port_query_by_name)(const struct dpif *dpif, const char *devname,
struct dpif_port *port);
/* Returns one greater than the largest port number accepted in flow
* actions. */
- int (*get_max_ports)(const struct dpif *dpif);
+ odp_port_t (*get_max_ports)(const struct dpif *dpif);
/* Returns the Netlink PID value to supply in OVS_ACTION_ATTR_USERSPACE
* actions as the OVS_USERSPACE_ATTR_PID attribute's value, for use in
*
* A dpif provider that doesn't have meaningful Netlink PIDs can use NULL
* for this function. This is equivalent to always returning 0. */
- uint32_t (*port_get_pid)(const struct dpif *dpif, uint32_t port_no);
+ uint32_t (*port_get_pid)(const struct dpif *dpif, odp_port_t port_no);
/* Attempts to begin dumping the ports in a dpif. On success, returns 0
* and initializes '*statep' with any data needed for iteration. On
* called again once it returns nonzero within a given iteration (but the
* 'flow_dump_done' function will be called afterward).
*
- * On success, if 'key' and 'key_len' are nonnull then '*key' and
- * '*key_len' must be set to Netlink attributes with types OVS_KEY_ATTR_*
- * representing the dumped flow's key. If 'actions' and 'actions_len' are
- * nonnull then they should be set to Netlink attributes with types
- * OVS_ACTION_ATTR_* representing the dumped flow's actions. If 'stats'
- * is nonnull then it should be set to the dumped flow's statistics.
+ * On success:
+ *
+ * - If 'key' and 'key_len' are nonnull, then '*key' and '*key_len'
+ * must be set to Netlink attributes with types OVS_KEY_ATTR_*
+ * representing the dumped flow's key.
+ *
+ * - If 'mask' and 'mask_len' are nonnull then '*mask' and '*mask_len'
+ * must be set to Netlink attributes with types of OVS_KEY_ATTR_*
+ * representing the dumped flow's mask.
+ *
+ * - If 'actions' and 'actions_len' are nonnull then they should be set
+ * to Netlink attributes with types OVS_ACTION_ATTR_* representing
+ * the dumped flow's actions.
+ *
+ * - If 'stats' is nonnull then it should be set to the dumped flow's
+ * statistics.
*
* All of the returned data is owned by 'dpif', not by the caller, and the
* caller must not modify or free it. 'dpif' must guarantee that it
* 'flow_dump_next' or 'flow_dump_done' for 'state'. */
int (*flow_dump_next)(const struct dpif *dpif, void *state,
const struct nlattr **key, size_t *key_len,
+ const struct nlattr **mask, size_t *mask_len,
const struct nlattr **actions, size_t *actions_len,
const struct dpif_flow_stats **stats);
extern const struct dpif_class dpif_linux_class;
extern const struct dpif_class dpif_netdev_class;
+extern const struct dpif_class dpif_planetlab_class;
#ifdef __cplusplus
}
/*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
&dpif_linux_class,
#endif
&dpif_netdev_class,
+ &dpif_planetlab_class,
};
struct registered_dpif_class {
static void log_flow_message(const struct dpif *dpif, int error,
const char *operation,
const struct nlattr *key, size_t key_len,
+ const struct nlattr *mask, size_t mask_len,
const struct dpif_flow_stats *stats,
const struct nlattr *actions, size_t actions_len);
static void log_operation(const struct dpif *, const char *operation,
if (error) {
VLOG_WARN("failed to enumerate %s datapaths: %s", dpif_class->type,
- strerror(error));
+ ovs_strerror(error));
}
return error;
error = dpif_open(name, type, dpifp);
if (error) {
VLOG_WARN("datapath %s already exists but cannot be opened: %s",
- name, strerror(error));
+ name, ovs_strerror(error));
}
} else if (error) {
- VLOG_WARN("failed to create datapath %s: %s", name, strerror(error));
+ VLOG_WARN("failed to create datapath %s: %s",
+ name, ovs_strerror(error));
}
return error;
}
}
/* Attempts to add 'netdev' as a port on 'dpif'. If 'port_nop' is
- * non-null and its value is not UINT32_MAX, then attempts to use the
+ * non-null and its value is not ODPP_NONE, then attempts to use the
* value as the port number.
*
* If successful, returns 0 and sets '*port_nop' to the new port's port
* number (if 'port_nop' is non-null). On failure, returns a positive
- * errno value and sets '*port_nop' to UINT32_MAX (if 'port_nop' is
+ * errno value and sets '*port_nop' to ODPP_NONE (if 'port_nop' is
* non-null). */
int
- dpif_port_add(struct dpif *dpif, struct netdev *netdev, uint32_t *port_nop)
+ dpif_port_add(struct dpif *dpif, struct netdev *netdev, odp_port_t *port_nop)
{
const char *netdev_name = netdev_get_name(netdev);
- uint32_t port_no = UINT32_MAX;
+ odp_port_t port_no = ODPP_NONE;
int error;
COVERAGE_INC(dpif_port_add);
dpif_name(dpif), netdev_name, port_no);
} else {
VLOG_WARN_RL(&error_rl, "%s: failed to add %s as port: %s",
- dpif_name(dpif), netdev_name, strerror(error));
- port_no = UINT32_MAX;
+ dpif_name(dpif), netdev_name, ovs_strerror(error));
+ port_no = ODPP_NONE;
}
if (port_nop) {
*port_nop = port_no;
/* Attempts to remove 'dpif''s port number 'port_no'. Returns 0 if successful,
* otherwise a positive errno value. */
int
- dpif_port_del(struct dpif *dpif, uint32_t port_no)
+ dpif_port_del(struct dpif *dpif, odp_port_t port_no)
{
int error;
int error = dpif->dpif_class->port_query_by_name(dpif, devname, NULL);
if (error != 0 && error != ENOENT && error != ENODEV) {
VLOG_WARN_RL(&error_rl, "%s: failed to query port %s: %s",
- dpif_name(dpif), devname, strerror(error));
+ dpif_name(dpif), devname, ovs_strerror(error));
}
return !error;
* The caller owns the data in 'port' and must free it with
* dpif_port_destroy() when it is no longer needed. */
int
- dpif_port_query_by_number(const struct dpif *dpif, uint32_t port_no,
+ dpif_port_query_by_number(const struct dpif *dpif, odp_port_t port_no,
struct dpif_port *port)
{
int error = dpif->dpif_class->port_query_by_number(dpif, port_no, port);
} else {
memset(port, 0, sizeof *port);
VLOG_WARN_RL(&error_rl, "%s: failed to query port %"PRIu32": %s",
- dpif_name(dpif), port_no, strerror(error));
+ dpif_name(dpif), port_no, ovs_strerror(error));
}
return error;
}
VLOG_RL(&error_rl,
error == ENOENT || error == ENODEV ? VLL_DBG : VLL_WARN,
"%s: failed to query port %s: %s",
- dpif_name(dpif), devname, strerror(error));
+ dpif_name(dpif), devname, ovs_strerror(error));
}
return error;
}
/* Returns one greater than the maximum port number accepted in flow
* actions. */
- int
+ odp_port_t
dpif_get_max_ports(const struct dpif *dpif)
{
return dpif->dpif_class->get_max_ports(dpif);
* as the OVS_USERSPACE_ATTR_PID attribute's value, for use in flows whose
* packets arrived on port 'port_no'.
*
- * A 'port_no' of UINT32_MAX is a special case: it returns a reserved PID, not
+ * A 'port_no' of ODPP_NONE is a special case: it returns a reserved PID, not
* allocated to any port, that the client may use for special purposes.
*
* The return value is only meaningful when DPIF_UC_ACTION has been enabled in
* update all of the flows that it installed that contain
* OVS_ACTION_ATTR_USERSPACE actions. */
uint32_t
- dpif_port_get_pid(const struct dpif *dpif, uint32_t port_no)
+ dpif_port_get_pid(const struct dpif *dpif, odp_port_t port_no)
{
return (dpif->dpif_class->port_get_pid
? (dpif->dpif_class->port_get_pid)(dpif, port_no)
* result is null-terminated. On failure, returns a positive errno value and
* makes 'name' the empty string. */
int
- dpif_port_get_name(struct dpif *dpif, uint32_t port_no,
+ dpif_port_get_name(struct dpif *dpif, odp_port_t port_no,
char *name, size_t name_size)
{
struct dpif_port port;
actions = NULL;
actions_len = 0;
}
- log_flow_message(dpif, error, "flow_get", key, key_len, stats,
- actions, actions_len);
+ log_flow_message(dpif, error, "flow_get", key, key_len,
+ NULL, 0, stats, actions, actions_len);
}
return error;
}
}
/* Adds or modifies a flow in 'dpif'. The flow is specified by the Netlink
- * attributes with types OVS_KEY_ATTR_* in the 'key_len' bytes starting at
- * 'key'. The associated actions are specified by the Netlink attributes with
- * types OVS_ACTION_ATTR_* in the 'actions_len' bytes starting at 'actions'.
+ * attribute OVS_FLOW_ATTR_KEY with types OVS_KEY_ATTR_* in the 'key_len' bytes
+ * starting at 'key', and OVS_FLOW_ATTR_MASK with types of OVS_KEY_ATTR_* in the
+ * 'mask_len' bytes starting at 'mask'. The associated actions are specified by
+ * the Netlink attributes with types OVS_ACTION_ATTR_* in the 'actions_len'
+ * bytes starting at 'actions'.
*
* - If the flow's key does not exist in 'dpif', then the flow will be added if
* 'flags' includes DPIF_FP_CREATE. Otherwise the operation will fail with
int
dpif_flow_put(struct dpif *dpif, enum dpif_flow_put_flags flags,
const struct nlattr *key, size_t key_len,
+ const struct nlattr *mask, size_t mask_len,
const struct nlattr *actions, size_t actions_len,
struct dpif_flow_stats *stats)
{
put.flags = flags;
put.key = key;
put.key_len = key_len;
+ put.mask = mask;
+ put.mask_len = mask_len;
put.actions = actions;
put.actions_len = actions_len;
put.stats = stats;
bool
dpif_flow_dump_next(struct dpif_flow_dump *dump,
const struct nlattr **key, size_t *key_len,
+ const struct nlattr **mask, size_t *mask_len,
const struct nlattr **actions, size_t *actions_len,
const struct dpif_flow_stats **stats)
{
if (!error) {
error = dpif->dpif_class->flow_dump_next(dpif, dump->state,
key, key_len,
+ mask, mask_len,
actions, actions_len,
stats);
if (error) {
*key = NULL;
*key_len = 0;
}
+ if (mask) {
+ *mask = NULL;
+ *mask_len = 0;
+ }
if (actions) {
*actions = NULL;
*actions_len = 0;
} else if (should_log_flow_message(error)) {
log_flow_message(dpif, error, "flow_dump",
key ? *key : NULL, key ? *key_len : 0,
+ mask ? *mask : NULL, mask ? *mask_len : 0,
stats ? *stats : NULL, actions ? *actions : NULL,
actions ? *actions_len : 0);
}
dpif_name(dpif), operation, ofperr_get_name(error));
} else {
VLOG_WARN_RL(&error_rl, "%s: %s failed (%s)",
- dpif_name(dpif), operation, strerror(error));
+ dpif_name(dpif), operation, ovs_strerror(error));
}
}
static enum vlog_level
flow_message_log_level(int error)
{
- return error ? VLL_WARN : VLL_DBG;
+ /* If flows arrive in a batch, userspace may push down multiple
+ * unique flow definitions that overlap when wildcards are applied.
+ * Kernels that support flow wildcarding will reject these flows as
+ * duplicates (EEXIST), so lower the log level to debug for these
+ * types of messages. */
+ return (error && error != EEXIST) ? VLL_WARN : VLL_DBG;
}
static bool
static void
log_flow_message(const struct dpif *dpif, int error, const char *operation,
const struct nlattr *key, size_t key_len,
+ const struct nlattr *mask, size_t mask_len,
const struct dpif_flow_stats *stats,
const struct nlattr *actions, size_t actions_len)
{
}
ds_put_format(&ds, "%s ", operation);
if (error) {
- ds_put_format(&ds, "(%s) ", strerror(error));
+ ds_put_format(&ds, "(%s) ", ovs_strerror(error));
}
- odp_flow_key_format(key, key_len, &ds);
+ odp_flow_format(key, key_len, mask, mask_len, &ds);
if (stats) {
ds_put_cstr(&ds, ", ");
dpif_flow_stats_format(stats, &ds);
ds_put_cstr(&s, "[zero]");
}
log_flow_message(dpif, error, ds_cstr(&s),
- put->key, put->key_len, put->stats,
- put->actions, put->actions_len);
+ put->key, put->key_len, put->mask, put->mask_len,
+ put->stats, put->actions, put->actions_len);
ds_destroy(&s);
}
}
{
if (should_log_flow_message(error)) {
log_flow_message(dpif, error, "flow_del", del->key, del->key_len,
- !error ? del->stats : NULL, NULL, 0);
+ NULL, 0, !error ? del->stats : NULL, NULL, 0);
}
}
ds_put_format(&ds, "%s: execute ", dpif_name(dpif));
format_odp_actions(&ds, execute->actions, execute->actions_len);
if (error) {
- ds_put_format(&ds, " failed (%s)", strerror(error));
+ ds_put_format(&ds, " failed (%s)", ovs_strerror(error));
}
ds_put_format(&ds, " on packet %s", packet);
vlog(THIS_MODULE, error ? VLL_WARN : VLL_DBG, "%s", ds_cstr(&ds));
* anyhow. */
int (*add_router)(struct netdev *netdev, struct in_addr router);
- /* Looks up the next hop for 'host'. If succesful, stores the next hop
+ /* Looks up the next hop for 'host'. If successful, stores the next hop
* gateway's address (0 if 'host' is on a directly connected network) in
* '*next_hop' and a copy of the name of the device to reach 'host' in
* '*netdev_name', and returns 0. The caller is responsible for freeing
extern const struct netdev_class netdev_linux_class;
extern const struct netdev_class netdev_internal_class;
extern const struct netdev_class netdev_tap_class;
- #ifdef __FreeBSD__
+ #if defined(__FreeBSD__) || defined(__NetBSD__)
extern const struct netdev_class netdev_bsd_class;
#endif
+extern const struct netdev_class netdev_tunnel_class;
+extern const struct netdev_class netdev_pltap_class;
+
#ifdef __cplusplus
}
#endif
#include <unistd.h>
#include "coverage.h"
+ #include "dpif.h"
#include "dynamic-string.h"
#include "fatal-signal.h"
#include "hash.h"
netdev_register_provider(&netdev_tap_class);
netdev_vport_tunnel_register();
#endif
- #ifdef __FreeBSD__
+ #if defined(__FreeBSD__) || defined(__NetBSD__)
netdev_register_provider(&netdev_tap_class);
netdev_register_provider(&netdev_bsd_class);
#endif
+ netdev_register_provider(&netdev_tunnel_class);
+ netdev_register_provider(&netdev_pltap_class);
}
}
int error = new_class->init();
if (error) {
VLOG_ERR("failed to initialize %s network device class: %s",
- new_class->type, strerror(error));
+ new_class->type, ovs_strerror(error));
return error;
}
}
}
}
+ /* Check that the network device name is not the same as any of the registered
+ * vport providers' dpif_port name (dpif_port is NULL if the vport provider
+ * does not define it) or the datapath internal port name (e.g. ovs-system).
+ *
+ * Returns true if there is a name conflict, false otherwise. */
+ bool
+ netdev_is_reserved_name(const char *name)
+ {
+ struct shash_node *node;
+
+ netdev_initialize();
+ SHASH_FOR_EACH (node, &netdev_classes) {
+ const char *dpif_port;
+ dpif_port = netdev_vport_class_get_dpif_port(node->data);
+ if (dpif_port && !strcmp(dpif_port, name)) {
+ return true;
+ }
+ }
+
+ if (!strncmp(name, "ovs-", 4)) {
+ struct sset types;
+ const char *type;
+
+ sset_init(&types);
+ dp_enumerate_types(&types);
+ SSET_FOR_EACH (type, &types) {
+ if (!strcmp(name+4, type)) {
+ sset_destroy(&types);
+ return true;
+ }
+ }
+ sset_destroy(&types);
+ }
+
+ return false;
+ }
+
/* Opens the network device named 'name' (e.g. "eth0") of the specified 'type'
* (e.g. "system") and returns zero if successful, otherwise a positive errno
* value. On success, sets '*netdevp' to the new network device, otherwise to
return 0;
}
+ /* Returns a reference to 'netdev_' for the caller to own. Returns null if
+ * 'netdev_' is null. */
+ struct netdev *
+ netdev_ref(const struct netdev *netdev_)
+ {
+ struct netdev *netdev = CONST_CAST(struct netdev *, netdev_);
+
+ if (netdev) {
+ ovs_assert(netdev->ref_cnt > 0);
+ netdev->ref_cnt++;
+ }
+ return netdev;
+ }
+
/* Reconfigures the device 'netdev' with 'args'. 'args' may be empty
* or NULL if none are needed. */
int
*mtup = 0;
if (error != EOPNOTSUPP) {
VLOG_DBG_RL(&rl, "failed to retrieve MTU for network device %s: "
- "%s", netdev_get_name(netdev), strerror(error));
+ "%s", netdev_get_name(netdev), ovs_strerror(error));
}
}
return error;
error = class->set_mtu ? class->set_mtu(netdev, mtu) : EOPNOTSUPP;
if (error && error != EOPNOTSUPP) {
VLOG_DBG_RL(&rl, "failed to set MTU for network device %s: %s",
- netdev_get_name(netdev), strerror(error));
+ netdev_get_name(netdev), ovs_strerror(error));
}
return error;
if (error) {
VLOG_WARN_RL(&rl, "failed to %s flags for network device %s: %s",
off || on ? "set" : "get", netdev_get_name(netdev),
- strerror(error));
+ ovs_strerror(error));
old_flags = 0;
} else if ((off || on) && sfp) {
enum netdev_flags new_flags = (old_flags & ~off) | on;
&carrier);
if (error) {
VLOG_DBG("%s: failed to get network device carrier status, assuming "
- "down: %s", netdev_get_name(netdev), strerror(error));
+ "down: %s", netdev_get_name(netdev), ovs_strerror(error));
carrier = false;
}