+static uint16_t
+str_to_port_no(const char *vconn_name, const char *str)
+{
+ struct ofpbuf *request, *reply;
+ struct ofp_switch_features *osf;
+ struct vconn *vconn;
+ int n_ports;
+ int port_idx;
+ unsigned int port_no;
+
+
+ /* Check if the argument is a port index. Otherwise, treat it as
+ * the port name. */
+ if (str_to_uint(str, 10, &port_no)) {
+ return port_no;
+ }
+
+ /* Send a "Features Request" to resolve the name into a number. */
+ make_openflow(sizeof(struct ofp_header), OFPT_FEATURES_REQUEST, &request);
+ open_vconn(vconn_name, &vconn);
+ run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name);
+
+ osf = reply->data;
+ n_ports = (reply->size - sizeof *osf) / sizeof *osf->ports;
+
+ for (port_idx = 0; port_idx < n_ports; port_idx++) {
+ /* Check argument as an interface name */
+ if (!strncmp((char *)osf->ports[port_idx].name, str,
+ sizeof osf->ports[0].name)) {
+ break;
+ }
+ }
+ if (port_idx == n_ports) {
+ ovs_fatal(0, "couldn't find monitored port: %s", str);
+ }
+
+ ofpbuf_delete(reply);
+ vconn_close(vconn);
+
+ return port_idx;
+}
+