From 4080cfd81f1bf3883561b15aed6d3dea3398c2a7 Mon Sep 17 00:00:00 2001
From: Raphael Defosseux <raphael.defosseux@eurecom.fr>
Date: Fri, 3 Aug 2018 13:08:48 +0200
Subject: [PATCH] CI: adding UL iperf support

Signed-off-by: Raphael Defosseux <raphael.defosseux@eurecom.fr>
---
 ci-scripts/main.py                         | 196 +++++++++++++--------
 ci-scripts/xml_files/enb_usrp210_band7.xml |  27 ++-
 2 files changed, 148 insertions(+), 75 deletions(-)

diff --git a/ci-scripts/main.py b/ci-scripts/main.py
index 85e27acb69..af086beeb9 100644
--- a/ci-scripts/main.py
+++ b/ci-scripts/main.py
@@ -277,7 +277,7 @@ class SSHConnection():
 				self.CreateHtmlTestRow(config_file, 'eNB not showing got sync!', 0)
 				# Not getting got sync is bypassed for the moment
 				#sys.exit(1)
-			self.command('stdbuf -o0 cat enb_' + SSH.testCase_id + '.log', '\$', 10)
+			self.command('stdbuf -o0 cat enb_' + SSH.testCase_id + '.log | grep -i sync', '\$', 10)
 			result = re.search('got sync', str(self.ssh.before))
 			if result is None:
 				time.sleep(6)
@@ -540,7 +540,112 @@ class SSHConnection():
 			job.join()
 		self.CreateHtmlTestRow(self.ping_args, 'OK', 0)
 
-	def Iperf_common(self, lock, UE_IPAddress, device_id, ue_num):
+	def Iperf_ComputeTime(self):
+		result = re.search('-t (?P<iperf_time>\d+)', str(self.iperf_args))
+		if result is None:
+			logging.debug('\u001B[1;37;41m Iperf time Not Found! \u001B[0m')
+			sys.exit(1)
+		return result.group('iperf_time')
+
+	def Iperf_ComputeModifiedBW(self, ue_num):
+		result = re.search('-b (?P<iperf_bandwidth>[0-9\.]+)[KMG]', str(self.iperf_args))
+		if result is None:
+			logging.debug('\u001B[1;37;41m Iperf bandwidth Not Found! \u001B[0m')
+			sys.exit(1)
+		iperf_bandwidth = result.group('iperf_bandwidth')
+		iperf_bandwidth_new = float(iperf_bandwidth)/ue_num
+		iperf_bandwidth_str = '-b ' + iperf_bandwidth
+		iperf_bandwidth_str_new = '-b ' + str(iperf_bandwidth_new)
+		result = re.sub(iperf_bandwidth_str, iperf_bandwidth_str_new, str(self.iperf_args))
+		if result is None:
+			logging.debug('\u001B[1;37;41m Calculate Iperf bandwidth Failed! \u001B[0m')
+			sys.exit(1)
+		return result
+
+	def Iperf_analyzeV2Output(self, lock, UE_IPAddress):
+		result = re.search('Server Report:', str(self.ssh.before))
+		if result is None:
+			result = re.search('read failed: Connection refused', str(self.ssh.before))
+			if result is not None:
+				logging.debug('\u001B[1;37;41m Could not connect to iperf server! \u001B[0m')
+			else:
+				logging.debug('\u001B[1;37;41m Server Report and Connection refused Not Found! \u001B[0m')
+			sys.exit(1)
+		result = re.search('Server Report:\\\\r\\\\n(?:|\[ *\d+\].*) (?P<bitrate>[0-9\.]+ [KMG]bits\/sec) +(?P<jitter>[0-9\.]+ ms) +(\d+\/.\d+) (\((?P<packetloss>[0-9\.]+)%\))', str(self.ssh.before))
+		if result is not None:
+			bitrate = result.group('bitrate')
+			packetloss = result.group('packetloss')
+			jitter = result.group('jitter')
+			lock.acquire()
+			logging.debug('\u001B[1;37;44m iperf result (' + UE_IPAddress + ') \u001B[0m')
+			if bitrate is not None:
+				logging.debug('\u001B[1;34m    Bitrate     : ' + bitrate + '\u001B[0m')
+			if packetloss is not None:
+				logging.debug('\u001B[1;34m    Packet Loss : ' + packetloss + '%\u001B[0m')
+				if float(packetloss) > float(self.iperf_packetloss_threshold):
+					logging.debug('\u001B[1;37;41m Packet Loss too high \u001B[0m')
+					lock.release()
+					sys.exit(1)
+			if jitter is not None:
+				logging.debug('\u001B[1;34m    Jitter      : ' + jitter + '\u001B[0m')
+			lock.release()
+
+	def Iperf_analyzeV3Output(self, lock, UE_IPAddress):
+		result = re.search('(?P<bitrate>[0-9\.]+ [KMG]bits\/sec) +(?:|[0-9\.]+ ms +\d+\/\d+ \((?P<packetloss>[0-9\.]+)%\)) +(?:|receiver)\\\\r\\\\n(?:|\[ *\d+\] Sent \d+ datagrams)\\\\r\\\\niperf Done\.', str(self.ssh.before))
+		if result is None:
+			result = re.search('(?P<error>iperf: error - [a-zA-Z0-9 :]+)', str(self.ssh.before))
+			if result is not None:
+				logging.debug('\u001B[1;37;41m ' + result.group('error') + ' \u001B[0m')
+			else:
+				logging.debug('\u001B[1;37;41m Bitrate and/or Packet Loss Not Found! \u001B[0m')
+			sys.exit(1)
+		bitrate = result.group('bitrate')
+		packetloss = result.group('packetloss')
+		lock.acquire()
+		logging.debug('\u001B[1;37;44m iperf result (' + UE_IPAddress + ') \u001B[0m')
+		logging.debug('\u001B[1;34m    Bitrate     : ' + bitrate + '\u001B[0m')
+		if packetloss is not None:
+			logging.debug('\u001B[1;34m    Packet Loss : ' + packetloss + '%\u001B[0m')
+			if float(packetloss) > float(self.iperf_packetloss_threshold):
+				logging.debug('\u001B[1;37;41m Packet Loss too high \u001B[0m')
+				lock.release()
+				sys.exit(1)
+		lock.release()
+
+	def Iperf_UL_common(self, lock, UE_IPAddress, device_id, idx, ue_num):
+		ipnumbers = UE_IPAddress.split('.')
+		if (len(ipnumbers) == 4):
+			ipnumbers[3] = '1'
+		EPC_Iperf_UE_IPAddress = ipnumbers[0] + '.' + ipnumbers[1] + '.' + ipnumbers[2] + '.' + ipnumbers[3]
+
+		# Launch iperf server on EPC side
+		self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword)
+		self.command('cd ' + self.EPCSourceCodePath + '/scripts', '\$', 5)
+		self.command('rm -f iperf_server_' + SSH.testCase_id + '_' + device_id + '.log', '\$', 5)
+		port = 5001 + idx
+		self.command('echo $USER; nohup iperf -u -s -i 1 -p ' + str(port) + ' > iperf_server_' + SSH.testCase_id + '_' + device_id + '.log &', self.EPCUserName, 5)
+		time.sleep(0.5)
+		self.close()
+
+		# Launch iperf client on UE
+		self.open(self.ADBIPAddress, self.ADBUserName, self.ADBPassword)
+		self.command('cd ' + self.EPCSourceCodePath + '/scripts', '\$', 5)
+		iperf_time = self.Iperf_ComputeTime()
+		time.sleep(0.5)
+
+		modified_options = self.Iperf_ComputeModifiedBW(ue_num)
+		time.sleep(0.5)
+
+		self.command('rm -f iperf_' + SSH.testCase_id + '_' + device_id + '.log', '\$', 5)
+		self.command('stdbuf -o0 adb -s ' + device_id + ' shell "/data/local/tmp/iperf -c ' + EPC_Iperf_UE_IPAddress + ' ' + modified_options + ' -p ' + str(port) + '" 2>&1 | stdbuf -o0 tee -a iperf_' + SSH.testCase_id + '_' + device_id + '.log', '\$', int(iperf_time)*5.0)
+		self.Iperf_analyzeV2Output(lock, UE_IPAddress)
+
+		# Launch iperf server on EPC side
+		self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword)
+		self.command('killall --signal SIGKILL iperf', self.EPCUserName, 5)
+		self.close()
+
+	def Iperf_common(self, lock, UE_IPAddress, device_id, idx, ue_num):
 		try:
 			useIperf3 = False
 			self.open(self.ADBIPAddress, self.ADBUserName, self.ADBPassword)
@@ -557,92 +662,39 @@ class SSHConnection():
 					sys.exit(1)
 			else:
 				useIperf3 = True
+			# in case of iperf, UL has its own function
+			if (not useIperf3):
+				result = re.search('-R', str(self.iperf_args))
+				if result is not None:
+					self.close()
+					self.Iperf_UL_common(lock, UE_IPAddress, device_id, idx, ue_num)
+					return
+
 			if (useIperf3):
 				self.command('stdbuf -o0 adb -s ' + device_id + ' shell /data/local/tmp/iperf3 -s &', '\$', 5)
 			else:
-				self.command('rm -f /tmp/iperf_server_' + SSH.testCase_id + '_' + device_id + '.log', '\$', 5)
+				self.command('rm -f iperf_server_' + SSH.testCase_id + '_' + device_id + '.log', '\$', 5)
 				self.command('echo $USER; nohup adb -s ' + device_id + ' shell "/data/local/tmp/iperf -u -s -i 1" > iperf_server_' + SSH.testCase_id + '_' + device_id + '.log &', self.ADBUserName, 5)
 			time.sleep(0.5)
 			self.close()
 
 			self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword)
-			self.command('cd ' + self.EPCSourceCodePath, '\$', 5)
-			self.command('cd scripts', '\$', 5)
-			result = re.search('-t (?P<iperf_time>\d+)', str(self.iperf_args))
-			if result is None:
-				logging.debug('\u001B[1;37;41m Iperf time Not Found! \u001B[0m')
-				sys.exit(1)
-			iperf_time = result.group('iperf_time')
+			self.command('cd ' + self.EPCSourceCodePath + '/scripts', '\$', 5)
+			iperf_time = self.Iperf_ComputeTime()
 			time.sleep(0.5)
 
-			result = re.search('-b (?P<iperf_bandwidth>[0-9\.]+)[KMG]', str(self.iperf_args))
-			if result is None:
-				logging.debug('\u001B[1;37;41m Iperf bandwidth Not Found! \u001B[0m')
-				sys.exit(1)
-			iperf_bandwidth = result.group('iperf_bandwidth')
+			modified_options = self.Iperf_ComputeModifiedBW(ue_num)
 			time.sleep(0.5)
 
-			iperf_bandwidth_new = float(iperf_bandwidth)/ue_num
-			iperf_bandwidth_str = '-b ' + iperf_bandwidth
-			iperf_bandwidth_str_new = '-b ' + str(iperf_bandwidth_new)
-			result = re.sub(iperf_bandwidth_str, iperf_bandwidth_str_new, str(self.iperf_args))
-			if result is None:
-				logging.debug('\u001B[1;37;41m Calculate Iperf bandwidth Failed! \u001B[0m')
-				sys.exit(1)
-
 			self.command('rm -f iperf_' + SSH.testCase_id + '_' + device_id + '.log', '\$', 5)
 			if (useIperf3):
-				self.command('stdbuf -o0 iperf3 -c ' + UE_IPAddress + ' ' + result + ' 2>&1 | stdbuf -o0 tee -a iperf_' + SSH.testCase_id + '_' + device_id + '.log', '\$', int(iperf_time)*5.0)
+				self.command('stdbuf -o0 iperf3 -c ' + UE_IPAddress + ' ' + modified_options + ' 2>&1 | stdbuf -o0 tee -a iperf_' + SSH.testCase_id + '_' + device_id + '.log', '\$', int(iperf_time)*5.0)
 
-				result = re.search('(?P<bitrate>[0-9\.]+ [KMG]bits\/sec) +(?:|[0-9\.]+ ms +\d+\/\d+ \((?P<packetloss>[0-9\.]+)%\)) +(?:|receiver)\\\\r\\\\n(?:|\[ *\d+\] Sent \d+ datagrams)\\\\r\\\\niperf Done\.', str(self.ssh.before))
-				if result is None:
-					result = re.search('(?P<error>iperf: error - [a-zA-Z0-9 :]+)', str(self.ssh.before))
-					if result is not None:
-						logging.debug('\u001B[1;37;41m ' + result.group('error') + ' \u001B[0m')
-					else:
-						logging.debug('\u001B[1;37;41m Bitrate and/or Packet Loss Not Found! \u001B[0m')
-					sys.exit(1)
-				bitrate = result.group('bitrate')
-				packetloss = result.group('packetloss')
-				lock.acquire()
-				logging.debug('\u001B[1;37;44m iperf result (' + UE_IPAddress + ') \u001B[0m')
-				logging.debug('\u001B[1;34m    Bitrate     : ' + bitrate + '\u001B[0m')
-				if packetloss is not None:
-					logging.debug('\u001B[1;34m    Packet Loss : ' + packetloss + '%\u001B[0m')
-					if float(packetloss) > float(self.iperf_packetloss_threshold):
-						logging.debug('\u001B[1;37;41m Packet Loss too high \u001B[0m')
-						lock.release()
-						sys.exit(1)
-				lock.release()
+				self.Iperf_analyzeV3Output(lock, UE_IPAddress)
 			else:
-				self.command('stdbuf -o0 iperf -c ' + UE_IPAddress + ' ' + result + ' 2>&1 | stdbuf -o0 tee -a iperf_' + SSH.testCase_id + '_' + device_id + '.log', '\$', int(iperf_time)*5.0)
+				self.command('stdbuf -o0 iperf -c ' + UE_IPAddress + ' ' + modified_options + ' 2>&1 | stdbuf -o0 tee -a iperf_' + SSH.testCase_id + '_' + device_id + '.log', '\$', int(iperf_time)*5.0)
 
-				result = re.search('Server Report:', str(self.ssh.before))
-				if result is None:
-					result = re.search('read failed: Connection refused', str(self.ssh.before))
-					if result is not None:
-						logging.debug('\u001B[1;37;41m Could not connect to iperf server! \u001B[0m')
-					else:
-						logging.debug('\u001B[1;37;41m Server Report and Connection refused Not Found! \u001B[0m')
-					sys.exit(1)
-				result = re.search('Server Report:\\\\r\\\\n(?:|\[ *\d+\].*) (?P<bitrate>[0-9\.]+ [KMG]bits\/sec) +(?P<jitter>[0-9\.]+ ms) +(\d+\/.\d+) (\((?P<packetloss>[0-9\.]+)%\))', str(self.ssh.before))
-				if result is not None:
-					bitrate = result.group('bitrate')
-					packetloss = result.group('packetloss')
-					jitter = result.group('jitter')
-					lock.acquire()
-					logging.debug('\u001B[1;37;44m iperf result (' + UE_IPAddress + ') \u001B[0m')
-					if bitrate is not None:
-						logging.debug('\u001B[1;34m    Bitrate     : ' + bitrate + '\u001B[0m')
-					if packetloss is not None:
-						logging.debug('\u001B[1;34m    Packet Loss : ' + packetloss + '%\u001B[0m')
-						if float(packetloss) > float(self.iperf_packetloss_threshold):
-							logging.debug('\u001B[1;37;41m Packet Loss too high \u001B[0m')
-							lock.release()
-							sys.exit(1)
-					if jitter is not None:
-						logging.debug('\u001B[1;34m    Jitter      : ' + jitter + '\u001B[0m')
-					lock.release()
+				self.Iperf_analyzeV2Output(lock, UE_IPAddress)
 			self.close()
 
 			self.open(self.ADBIPAddress, self.ADBUserName, self.ADBPassword)
@@ -668,7 +720,7 @@ class SSHConnection():
 		lock = Lock()
 		for UE_IPAddress in self.UEIPAddresses:
 			device_id = self.UEDevices[i]
-			p = Process(target = SSH.Iperf_common, args = (lock,UE_IPAddress,device_id,ue_num,))
+			p = Process(target = SSH.Iperf_common, args = (lock,UE_IPAddress,device_id,i,ue_num,))
 			p.daemon = True
 			p.start()
 			multi_jobs.append(p)
diff --git a/ci-scripts/xml_files/enb_usrp210_band7.xml b/ci-scripts/xml_files/enb_usrp210_band7.xml
index 6f8cfbad5b..bf47d1f368 100644
--- a/ci-scripts/xml_files/enb_usrp210_band7.xml
+++ b/ci-scripts/xml_files/enb_usrp210_band7.xml
@@ -21,7 +21,7 @@
 
 -->
 <testCaseList>
-	<TestCaseRequestedList>010101 050101 060101 070101 040101 030101 040301 040501 040601 040602 040603 040401 040201 030201 030111 040301 040511 040611 040612 040613 040401 040201 030201 030112 040301 040512 040621 040622 040623 040401 040201 030201 </TestCaseRequestedList>
+	<TestCaseRequestedList>010101 050101 060101 070101 040101 030101 040301 040501 040601 040602 040603 040641 040401 040201 030201 030111 040301 040511 040611 040612 040613 040651 040401 040201 030201 030121 040301 040521 040621 040622 040623 040661 040401 040201 030201 </TestCaseRequestedList>
 	<TestCaseExclusionList></TestCaseExclusionList>
 
 	<testCase id="010101">
@@ -42,7 +42,7 @@
 		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.50PRB.usrpb210.conf</Initialize_eNB_args>
 	</testCase>
 
-	<testCase id="030112">
+	<testCase id="030121">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB (FDD/Band7/20MHz)</desc>
 		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.100PRB.usrpb210.conf</Initialize_eNB_args>
@@ -87,7 +87,7 @@
                 <ping_packetloss_threshold>5</ping_packetloss_threshold>
         </testCase>
 
-        <testCase id="040512">
+        <testCase id="040521">
                 <class>Ping</class>
                 <desc>ping (20MHz - 20 sec)</desc>
                 <ping_args>-c 20</ping_args>
@@ -115,6 +115,13 @@
 		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
         </testCase>
 
+	<testCase id="040641">
+		<class>Iperf</class>
+		<desc>iperf (5MHz - UL/9Mbps/UDP)(60 sec)</desc>
+		<iperf_args>-u -b 9M -t 60 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+	</testCase>
+
 	<testCase id="040611">
 		<class>Iperf</class>
 		<desc>iperf (10MHz - DL/10Mbps/UDP)(60 sec)</desc>
@@ -136,6 +143,13 @@
 		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
         </testCase>
 
+	<testCase id="040651">
+		<class>Iperf</class>
+		<desc>iperf (10MHz - UL/20Mbps/UDP)(60 sec)</desc>
+		<iperf_args>-u -b 20M -t 60 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+	</testCase>
+
 	<testCase id="040621">
 		<class>Iperf</class>
 		<desc>iperf (20MHz - DL/20Mbps/UDP)(60 sec)</desc>
@@ -157,6 +171,13 @@
 		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
         </testCase>
 
+	<testCase id="040661">
+		<class>Iperf</class>
+		<desc>iperf (20MHz - UL/20Mbps/UDP)(60 sec)</desc>
+		<iperf_args>-u -b 20M -t 60 -i 1 -R</iperf_args>
+		<iperf_packetloss_threshold>50</iperf_packetloss_threshold>
+	</testCase>
+
         <testCase id="050101">
 		<class>Initialize_HSS</class>
 		<desc>Initialize HSS</desc>
-- 
GitLab