[SDFAB-1103] Add packet capture for mock smf

- Capture packets on the mock smf interface for debugging

Change-Id: Iad08c8cad48847177b303d6831e35d8faf3552b0
diff --git a/TestON/tests/USECASE/SegmentRouting/dependencies/up4.py b/TestON/tests/USECASE/SegmentRouting/dependencies/up4.py
index 82b9c78..bb285d4 100644
--- a/TestON/tests/USECASE/SegmentRouting/dependencies/up4.py
+++ b/TestON/tests/USECASE/SegmentRouting/dependencies/up4.py
@@ -2,6 +2,7 @@
 import ipaddress as ip
 import copy
 import re
+import pexpect
 
 FALSE = '0'
 TRUE = '1'
@@ -124,6 +125,7 @@
         if self.mock_smf:
             if not pfcpAddress:
                 pfcpAddress = self.mock_smf.kubectlGetServiceIP( "pfcp-agent" )
+            self.startMockSmfPcap(self.mock_smf)
             self.mock_smf.startSMF()
             self.mock_smf.configure(self.s1u_address, pfcpAddress, pfcpPort)
             # TODO Start pcap on mock_smf host
@@ -139,6 +141,24 @@
         #  PFCP agent to push interface entries, but we should explicitly push
         #  them here
 
+    def startMockSmfPcap(self, smfComponent, pcapIface="eth0"):
+        compName = "smf-pcap"
+        # Create another component/bash session for tshark
+        main.Network.copyComponent(smfComponent.name, compName)
+        pcap = getattr(main, compName)
+        pcapFile = "%s/CASE%s-%s" % (main.logdir, main.CurrentTestCaseNumber, compName)
+        commands = ['touch %s.pcap' % pcapFile,
+                    'chmod o=rw %s.pcap' % pcapFile]
+        for command in commands:
+            pcap.handle.sendline(command)
+            pcap.handle.expect(pcap.prompt)
+            main.log.debug("%s: %s" % (pcap.name, str(pcap.handle.before)))
+        pcap.handle.sendline("sudo /usr/bin/tshark -i %s -w %s.pcap &> %s.log" % (pcapIface, pcapFile, pcapFile))
+        i = pcap.handle.expect(["password", pexpect.TIMEOUT], timeout=5)
+        if i == 0:
+            pcap.handle.sendline(pcap.pwd if pcap.pwd else "jenkins")
+        pcap.preDisconnect = pcap.exitFromProcess
+
     def teardown(self):
         if self.up4_client:
             self.up4_client.stopP4RtClient()