blob: 1906bfa9b0f4d180c004a3fef260db85de4a1970 [file] [log] [blame]
jeraldabrahamb2a26552014-04-16 21:08:09 -07001#!/usr/bin/python2
2# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
3#
4# Copyright (C) 2014 University of Arizona
5# Author: Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
6# See COPYING for copyright and distribution information.
7#
8
9import os
10import time
11import unittest
12import process_manager
13
14class test_interest_aggregation(unittest.TestCase, process_manager.ProcessManager):
15 """Test case for testing interest aggregation"""
16
17 def setUp(self):
18 print "\nTesting Interest Aggregation"
19 print "****************************"
20 self.logFolder = "test_interest_aggregation/logs/"
21 if not os.path.exists(self.logFolder):
22 os.system("mkdir " + self.logFolder)
23
24 def tearDown(self):
25 self.killNfd()
26 self.killProcess("ndn-traffic-server-1")
Eric Newberryd4ed6222015-06-10 14:12:42 -070027 self.killProcess("ndnpeek-1")
28 self.killProcess("ndnpeek-2")
jeraldabrahamb2a26552014-04-16 21:08:09 -070029 self.killProcess("ndn-traffic-server-2")
Eric Newberryd4ed6222015-06-10 14:12:42 -070030 self.killProcess("ndnpeek-3")
31 self.killProcess("ndnpeek-4")
jeraldabrahamb2a26552014-04-16 21:08:09 -070032 self.killProcess("ndn-traffic-server-3")
Eric Newberryd4ed6222015-06-10 14:12:42 -070033 self.killProcess("ndnpeek-5")
34 self.killProcess("ndnpeek-6")
jeraldabrahamb2a26552014-04-16 21:08:09 -070035 self.cleanupProcesses()
36
37 def checkAndReportFailure(self, processKey, processName):
38 if self.hasProcessCompleted(processKey):
39 if self.getProcessReturnCode(processKey) != 0:
40 print self.getProcessOutput(processKey)
41 print self.getProcessError(processKey)
42 self.fail(">> TEST FAILED - received non-zero return code from " + processName)
43 else:
44 self.fail(">> TEST FAILED - " + processName + " failed to complete")
45
46
47 def checkServerReceiveCount(self, processKey, processName, expectedCount):
48 serverOutput = self.getProcessOutput(processKey).splitlines()
49 isTestSuccessful = False
50 receivedCount = 0
51 for logLine in serverOutput:
52 if "Total Interests Received" in logLine:
53 for value in logLine.split():
54 if value.isdigit():
55 receivedCount = int(value)
56 break
57 if receivedCount == expectedCount:
58 isTestSuccessful = True
59 break
60 if not isTestSuccessful:
61 self.fail(">> TEST FAILED - " + processName +
62 " expected to receive only " + str(expectedCount) +
63 " interest(s) but received " + str(receivedCount) + " interest(s)" )
64 else:
65 print "-> " + processName + " received " + str(receivedCount) + " interest(s)"
66
67 def test_aggregation(self):
68
69 #Start NFD
70 self.startNfd()
71 time.sleep(1)
jeraldabrahamb2a26552014-04-16 21:08:09 -070072
73 #Start ndn-traffic-server to serve ndn:/test-agg, with content delay set to 2000ms
74 serverConfigurationFile = os.path.abspath(
75 "test_interest_aggregation/test-traffic-server.conf")
76 self.startProcess("ndn-traffic-server-1",
77 ["ndn-traffic-server", serverConfigurationFile],
78 "-> Starting Traffic Server 1 (Prefix=ndn:/test-agg, ContentDelay=2000ms)")
79 time.sleep(1)
80
Eric Newberryd4ed6222015-06-10 14:12:42 -070081 #Start two instances of ndnpeek to request ndn:/test-agg/A. Wait until they
jeraldabrahamb2a26552014-04-16 21:08:09 -070082 #terminate. Fail if either is unanswered.
83 peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-1.txt")
Eric Newberryd4ed6222015-06-10 14:12:42 -070084 self.startProcess("ndnpeek-1",
85 ["ndnpeek", "ndn:/test-agg/A"],
jeraldabrahamb2a26552014-04-16 21:08:09 -070086 "-> Starting Peek Client 1 (Prefix=ndn:/test-agg/A)",
87 outputFile=peekOutputFile)
88 peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-2.txt")
Eric Newberryd4ed6222015-06-10 14:12:42 -070089 self.startProcess("ndnpeek-2",
90 ["ndnpeek", "ndn:/test-agg/A"],
jeraldabrahamb2a26552014-04-16 21:08:09 -070091 "-> Starting Peek Client 2 (Prefix=ndn:/test-agg/A)",
92 outputFile=peekOutputFile)
Eric Newberryd4ed6222015-06-10 14:12:42 -070093 self.waitForProcessCompletion("ndnpeek-1", 10)
94 self.waitForProcessCompletion("ndnpeek-2", 10)
jeraldabrahamb2a26552014-04-16 21:08:09 -070095
96 #Stop ndn-traffic-server. Fail if total served Interest does not equal 1.
97 self.killProcess("ndn-traffic-server-1")
98 time.sleep(1)
99 print "-> Stopping Traffic Server 1"
Eric Newberryd4ed6222015-06-10 14:12:42 -0700100 self.checkAndReportFailure("ndnpeek-1", "Peek Client 1")
101 self.checkAndReportFailure("ndnpeek-2", "Peek Client 2")
jeraldabrahamb2a26552014-04-16 21:08:09 -0700102 self.checkServerReceiveCount("ndn-traffic-server-1", "Traffic Server 1", 1)
103
104 #Start ndn-traffic-server to serve ndn:/test-agg, with content delay set to 2000ms
105 self.startProcess("ndn-traffic-server-2",
106 ["ndn-traffic-server", serverConfigurationFile],
107 "-> Starting Traffic Server 2 (Prefix=ndn:/test-agg, ContentDelay=2000ms)")
108 time.sleep(1)
109
Eric Newberryd4ed6222015-06-10 14:12:42 -0700110 #Start ndnpeek to request ndn:/test-agg/B ChildSelector=leftmost, and another
jeraldabrahamb2a26552014-04-16 21:08:09 -0700111 #instance to request ndn:/test-agg/B ChildSelector=rightmost. Wait until they terminate.
112 #Fail if either is unanswered.
113 peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-3.txt")
Eric Newberryd4ed6222015-06-10 14:12:42 -0700114 self.startProcess("ndnpeek-3",
115 ["ndnpeek", "ndn:/test-agg/B"],
jeraldabrahamb2a26552014-04-16 21:08:09 -0700116 "-> Starting Peek Client 3 (Prefix=ndn:/test-agg/B, ChildSelector=leftmost)",
117 outputFile=peekOutputFile)
118 peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-4.txt")
Eric Newberryd4ed6222015-06-10 14:12:42 -0700119 self.startProcess("ndnpeek-4",
120 ["ndnpeek", "-r", "ndn:/test-agg/B"],
jeraldabrahamb2a26552014-04-16 21:08:09 -0700121 "-> Starting Peek Client 4 (Prefix=ndn:/test-agg/B, ChildSelector=rightmost)",
122 outputFile=peekOutputFile)
Eric Newberryd4ed6222015-06-10 14:12:42 -0700123 self.waitForProcessCompletion("ndnpeek-3", 10)
124 self.waitForProcessCompletion("ndnpeek-4", 10)
jeraldabrahamb2a26552014-04-16 21:08:09 -0700125
126 #Stop ndn-traffic-server. Fail if total served Interest does not equal 2.
127 self.killProcess("ndn-traffic-server-2")
128 time.sleep(1)
129 print "-> Stopping Traffic Server 2"
Eric Newberryd4ed6222015-06-10 14:12:42 -0700130 self.checkAndReportFailure("ndnpeek-3", "Peek Client 3")
131 self.checkAndReportFailure("ndnpeek-4", "Peek Client 4")
jeraldabrahamb2a26552014-04-16 21:08:09 -0700132 self.checkServerReceiveCount("ndn-traffic-server-2", "Traffic Server 2", 2)
133
134 #Start ndn-traffic-server to serve ndn:/test-agg, with content delay set to 2000ms
135 self.startProcess("ndn-traffic-server-3",
136 ["ndn-traffic-server", serverConfigurationFile],
137 "-> Starting Traffic Server 3 (Prefix=ndn:/test-agg, ContentDelay=2000ms)")
138 time.sleep(1)
139
Eric Newberryd4ed6222015-06-10 14:12:42 -0700140 #Start ndnpeek to request ndn:/test-agg/C InterestLifetime=6000ms, and another
jeraldabrahamb2a26552014-04-16 21:08:09 -0700141 #instance to request ndn:/test-agg/C. InterestLifetime=8000ms. Wait until they terminate.
142 #Fail if either is unanswered.
143 peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-5.txt")
Eric Newberryd4ed6222015-06-10 14:12:42 -0700144 self.startProcess("ndnpeek-5",
145 ["ndnpeek", "-l 6000", "ndn:/test-agg/C"],
jeraldabrahamb2a26552014-04-16 21:08:09 -0700146 "-> Starting Peek Client 5 (Prefix=ndn:/test-agg/C, InterestLifetime=6000ms)",
147 outputFile=peekOutputFile)
148 peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-6.txt")
Eric Newberryd4ed6222015-06-10 14:12:42 -0700149 self.startProcess("ndnpeek-6",
150 ["ndnpeek", "-l 8000", "ndn:/test-agg/C"],
jeraldabrahamb2a26552014-04-16 21:08:09 -0700151 "-> Starting Peek Client 6 (Prefix=ndn:/test-agg/C, InterestLifetime=8000ms)",
152 outputFile=peekOutputFile)
Eric Newberryd4ed6222015-06-10 14:12:42 -0700153 self.waitForProcessCompletion("ndnpeek-5", 10)
154 self.waitForProcessCompletion("ndnpeek-6", 10)
jeraldabrahamb2a26552014-04-16 21:08:09 -0700155
156 #Stop ndn-traffic-server. Fail if total served Interest does not equal 1.
157 self.killProcess("ndn-traffic-server-3")
158 time.sleep(1)
159 print "-> Stopping Traffic Server 3"
Eric Newberryd4ed6222015-06-10 14:12:42 -0700160 self.checkAndReportFailure("ndnpeek-5", "Peek Client 5")
161 self.checkAndReportFailure("ndnpeek-6", "Peek Client 6")
jeraldabrahamb2a26552014-04-16 21:08:09 -0700162 self.checkServerReceiveCount("ndn-traffic-server-3", "Traffic Server 3", 1)
163 print ">> TEST SUCCESSFUL"