Hack to call the port enable script after sending config

Change-Id: Ia6dbdc5b603434036b39b2cd6530b7d388bee619
diff --git a/drivers/barefoot/src/main/java/org/onosproject/drivers/barefoot/TofinoPipelineProgrammable.java b/drivers/barefoot/src/main/java/org/onosproject/drivers/barefoot/TofinoPipelineProgrammable.java
index 2dd3dd2..b6fb853 100644
--- a/drivers/barefoot/src/main/java/org/onosproject/drivers/barefoot/TofinoPipelineProgrammable.java
+++ b/drivers/barefoot/src/main/java/org/onosproject/drivers/barefoot/TofinoPipelineProgrammable.java
@@ -29,6 +29,7 @@
 import org.onosproject.p4runtime.api.P4RuntimeController;
 import org.slf4j.Logger;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.Buffer;
@@ -72,7 +73,6 @@
         if (!controller.hasClient(deviceId)) {
             log.warn("Unable to find client for {}, aborting pipeconf deploy", deviceId);
             return false;
-
         }
 
         P4RuntimeClient client = controller.getClient(deviceId);
@@ -94,6 +94,9 @@
                 return false;
             }
 
+            //FIXME this hack calls the shell command to set up the ports
+            SharedExecutors.getPoolThreadExecutor().submit(() -> runPortCommand(deviceId));
+
         } catch (InterruptedException | ExecutionException e) {
             throw new RuntimeException(e);
         }
@@ -101,6 +104,48 @@
         return true;
     }
 
+    // FIXME This is a hack to enable port until we either implement Thrift or gNMI
+    private void runPortCommand(DeviceId deviceId) {
+        // TODO we should have a more intelligent way of building the command
+        final String command;
+        if ("device:tofino:11".equals(deviceId.toString())) {
+            command = "./pm.py 10.254.1.38 38-port-config.txt";
+        } else if ("device:tofino:12".equals(deviceId.toString())) {
+            command = "./pm.py 10.254.1.37 37-port-config.txt";
+        } else if ("device:tofino:21".equals(deviceId.toString())) {
+            command = "./pm.py 10.254.1.40 40-port-config.txt";
+        } else if ("device:tofino:22".equals(deviceId.toString())) {
+            command = "./pm.py 10.254.1.39 39-port-config.txt";
+        } else {
+            log.error("Device port config not found: {}", deviceId);
+            return;
+        }
+        try {
+            // Give the switch 2 seconds to get settled with the new config
+            Thread.sleep(3000);
+
+            String rootDir = System.getenv("ONOS_ROOT");
+            if (rootDir == null) {
+                log.error("ONOS_ROOT is not set");
+                return;
+            }
+            File workingDirectory = new File(rootDir, "tools/test/tofino-port-auto-setup-tool");
+            if (!workingDirectory.isDirectory()) {
+                log.error("{} does not exist", workingDirectory);
+                return;
+            }
+            Process process = Runtime.getRuntime().exec(command, null, workingDirectory);
+            int exit = process.waitFor();
+            if (exit != 0) {
+                log.error("port command returned non-zero status {} for device {}", exit, deviceId);
+                return;
+            }
+            log.info("Successfully executed port enable on {}", deviceId);
+        } catch (Exception e) {
+            log.error("Failed to run port command on {}", deviceId, e);
+        }
+    }
+
     private ByteBuffer createPipelineBuffer(PiPipeconf pipeconf, List<ExtensionType> targetConfigExtTypes) {
         if (targetConfigExtTypes == null || targetConfigExtTypes.isEmpty() || isNullOrEmpty(pipeconf.id().toString())) {