+ if (test_done == 0) {
+ printf("Please stop forwarding first\n");
+ return;
+ }
+
+ if (rte_eth_dev_attach(identifier, &pi))
+ return;
+
+ ports[pi].enabled = 1;
+ reconfig(pi, rte_eth_dev_socket_id(pi));
+ rte_eth_promiscuous_enable(pi);
+
+ nb_ports = rte_eth_dev_count();
+
+ /* set_default_fwd_ports_config(); */
+ bzero(fwd_ports_ids, sizeof(fwd_ports_ids));
+ i = 0;
+ FOREACH_PORT(j, ports) {
+ fwd_ports_ids[i] = j;
+ i++;
+ }
+ nb_cfg_ports = nb_ports;
+ nb_fwd_ports++;
+
+ ports[pi].port_status = RTE_PORT_STOPPED;
+
+ printf("Port %d is attached. Now total ports is %d\n", pi, nb_ports);
+ printf("Done\n");
+}
+
+void
+detach_port(uint8_t port_id)
+{
+ portid_t i, pi = 0;
+ char name[RTE_ETH_NAME_MAX_LEN];
+
+ printf("Detaching a port...\n");
+
+ if (!port_is_closed(port_id)) {
+ printf("Please close port first\n");
+ return;
+ }
+
+ rte_eth_promiscuous_disable(port_id);
+
+ if (rte_eth_dev_detach(port_id, name))
+ return;
+
+ ports[port_id].enabled = 0;
+ nb_ports = rte_eth_dev_count();
+
+ /* set_default_fwd_ports_config(); */
+ bzero(fwd_ports_ids, sizeof(fwd_ports_ids));
+ i = 0;
+ FOREACH_PORT(pi, ports) {
+ fwd_ports_ids[i] = pi;
+ i++;
+ }
+ nb_cfg_ports = nb_ports;
+ nb_fwd_ports--;
+
+ printf("Port '%s' is detached. Now total ports is %d\n",
+ name, nb_ports);
+ printf("Done\n");
+ return;