Skip to content

Commit

Permalink
dpif: Allow the port number to be requested when adding an interface.
Browse files Browse the repository at this point in the history
The datapath allows requesting a specific port number for a port, but
the dpif interface didn't expose it.  This commit adds that support.

Signed-off-by: Justin Pettit <[email protected]>
  • Loading branch information
Justin Pettit committed Jul 31, 2012
1 parent 8a77bb2 commit 232dfa4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
11 changes: 8 additions & 3 deletions lib/dpif-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,13 @@ dpif_linux_port_add(struct dpif *dpif_, struct netdev *netdev,
netdev_linux_ethtool_set_flag(netdev, ETH_FLAG_LRO, "LRO", false);
}

/* Loop until we find a port that isn't used. */
/* Unless a specific port was requested, loop until we find a port
* that isn't used. */
do {
uint32_t upcall_pid;

request.port_no = ++dpif->alloc_port_no;
request.port_no = *port_nop != UINT16_MAX ? *port_nop
: ++dpif->alloc_port_no;
upcall_pid = dpif_linux_port_get_pid(dpif_, request.port_no);
request.upcall_pid = &upcall_pid;
error = dpif_linux_vport_transact(&request, &reply, &buf);
Expand All @@ -441,10 +443,13 @@ dpif_linux_port_add(struct dpif *dpif_, struct netdev *netdev,
/* Older datapath has lower limit. */
max_ports = dpif->alloc_port_no;
dpif->alloc_port_no = 0;
} else if (error == EBUSY && *port_nop != UINT16_MAX) {
VLOG_INFO("%s: requested port %"PRIu16" is in use",
dpif_name(dpif_), *port_nop);
}

ofpbuf_delete(buf);
} while ((i++ < max_ports)
} while ((*port_nop == UINT16_MAX) && (i++ < max_ports)
&& (error == EBUSY || error == EFBIG));

return error;
Expand Down
11 changes: 10 additions & 1 deletion lib/dpif-netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,16 @@ dpif_netdev_port_add(struct dpif *dpif, struct netdev *netdev,
struct dp_netdev *dp = get_dp_netdev(dpif);
int port_no;

port_no = choose_port(dpif, netdev);
if (*port_nop != UINT16_MAX) {
if (*port_nop >= MAX_PORTS) {
return EFBIG;
} else if (dp->ports[*port_nop]) {
return EBUSY;
}
port_no = *port_nop;
} else {
port_no = choose_port(dpif, netdev);
}
if (port_no >= 0) {
*port_nop = port_no;
return do_add_port(dp, netdev_get_name(netdev),
Expand Down
8 changes: 6 additions & 2 deletions lib/dpif-provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ struct dpif_class {
/* Retrieves statistics for 'dpif' into 'stats'. */
int (*get_stats)(const struct dpif *dpif, struct dpif_dp_stats *stats);

/* Adds 'netdev' as a new port in 'dpif'. If successful, sets '*port_no'
* to the new port's port number. */
/* Adds 'netdev' as a new port in 'dpif'. If '*port_no' is not
* UINT16_MAX, attempts to use that as the port's port number.
*
* If port is successfully added, sets '*port_no' to the new port's
* 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,
uint16_t *port_no);

Expand Down
18 changes: 13 additions & 5 deletions lib/dpif.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,19 +410,27 @@ dpif_get_dp_stats(const struct dpif *dpif, struct dpif_dp_stats *stats)
return error;
}

/* Attempts to add 'netdev' as a port on 'dpif'. 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
* UINT16_MAX (if 'port_nop' is non-null). */
/* Attempts to add 'netdev' as a port on 'dpif'. If 'port_nop' is
* non-null and its value is not UINT16_MAX, 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 UINT16_MAX (if 'port_nop' is
* non-null). */
int
dpif_port_add(struct dpif *dpif, struct netdev *netdev, uint16_t *port_nop)
{
const char *netdev_name = netdev_get_name(netdev);
uint16_t port_no;
uint16_t port_no = UINT16_MAX;
int error;

COVERAGE_INC(dpif_port_add);

if (port_nop) {
port_no = *port_nop;
}

error = dpif->dpif_class->port_add(dpif, netdev, &port_no);
if (!error) {
VLOG_DBG_RL(&dpmsg_rl, "%s: added %s as port %"PRIu16,
Expand Down
2 changes: 1 addition & 1 deletion ofproto/ofproto-dpif.c
Original file line number Diff line number Diff line change
Expand Up @@ -2514,7 +2514,7 @@ static int
port_add(struct ofproto *ofproto_, struct netdev *netdev, uint16_t *ofp_portp)
{
struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
uint16_t odp_port;
uint16_t odp_port = UINT16_MAX;
int error;

error = dpif_port_add(ofproto->dpif, netdev, &odp_port);
Expand Down

0 comments on commit 232dfa4

Please sign in to comment.