blob: 8c85b1ff2edd8536d3ae60f81100cf81e10e5897 [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
Eric Newberry1287b882015-07-28 18:20:27 -070073 #Set NFD to use best-route v1 strategy
74 self.startProcess("nfdc",
75 ["nfdc", "set-strategy", "/", "ndn:/localhost/nfd/strategy/best-route/%FD%01"],
76 "-> Setting strategy to best-route v1")
77 time.sleep(1)
78
jeraldabrahamb2a26552014-04-16 21:08:09 -070079 #Start ndn-traffic-server to serve ndn:/test-agg, with content delay set to 2000ms
80 serverConfigurationFile = os.path.abspath(
81 "test_interest_aggregation/test-traffic-server.conf")
82 self.startProcess("ndn-traffic-server-1",
83 ["ndn-traffic-server", serverConfigurationFile],
84 "-> Starting Traffic Server 1 (Prefix=ndn:/test-agg, ContentDelay=2000ms)")
85 time.sleep(1)
86
Eric Newberryd4ed6222015-06-10 14:12:42 -070087 #Start two instances of ndnpeek to request ndn:/test-agg/A. Wait until they
jeraldabrahamb2a26552014-04-16 21:08:09 -070088 #terminate. Fail if either is unanswered.
89 peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-1.txt")
Eric Newberryd4ed6222015-06-10 14:12:42 -070090 self.startProcess("ndnpeek-1",
91 ["ndnpeek", "ndn:/test-agg/A"],
jeraldabrahamb2a26552014-04-16 21:08:09 -070092 "-> Starting Peek Client 1 (Prefix=ndn:/test-agg/A)",
93 outputFile=peekOutputFile)
94 peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-2.txt")
Eric Newberryd4ed6222015-06-10 14:12:42 -070095 self.startProcess("ndnpeek-2",
96 ["ndnpeek", "ndn:/test-agg/A"],
jeraldabrahamb2a26552014-04-16 21:08:09 -070097 "-> Starting Peek Client 2 (Prefix=ndn:/test-agg/A)",
98 outputFile=peekOutputFile)
Eric Newberryd4ed6222015-06-10 14:12:42 -070099 self.waitForProcessCompletion("ndnpeek-1", 10)
100 self.waitForProcessCompletion("ndnpeek-2", 10)
jeraldabrahamb2a26552014-04-16 21:08:09 -0700101
102 #Stop ndn-traffic-server. Fail if total served Interest does not equal 1.
103 self.killProcess("ndn-traffic-server-1")
104 time.sleep(1)
105 print "-> Stopping Traffic Server 1"
Eric Newberryd4ed6222015-06-10 14:12:42 -0700106 self.checkAndReportFailure("ndnpeek-1", "Peek Client 1")
107 self.checkAndReportFailure("ndnpeek-2", "Peek Client 2")
jeraldabrahamb2a26552014-04-16 21:08:09 -0700108 self.checkServerReceiveCount("ndn-traffic-server-1", "Traffic Server 1", 1)
109
110 #Start ndn-traffic-server to serve ndn:/test-agg, with content delay set to 2000ms
111 self.startProcess("ndn-traffic-server-2",
112 ["ndn-traffic-server", serverConfigurationFile],
113 "-> Starting Traffic Server 2 (Prefix=ndn:/test-agg, ContentDelay=2000ms)")
114 time.sleep(1)
115
Eric Newberryd4ed6222015-06-10 14:12:42 -0700116 #Start ndnpeek to request ndn:/test-agg/B ChildSelector=leftmost, and another
jeraldabrahamb2a26552014-04-16 21:08:09 -0700117 #instance to request ndn:/test-agg/B ChildSelector=rightmost. Wait until they terminate.
118 #Fail if either is unanswered.
119 peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-3.txt")
Eric Newberryd4ed6222015-06-10 14:12:42 -0700120 self.startProcess("ndnpeek-3",
121 ["ndnpeek", "ndn:/test-agg/B"],
jeraldabrahamb2a26552014-04-16 21:08:09 -0700122 "-> Starting Peek Client 3 (Prefix=ndn:/test-agg/B, ChildSelector=leftmost)",
123 outputFile=peekOutputFile)
124 peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-4.txt")
Eric Newberryd4ed6222015-06-10 14:12:42 -0700125 self.startProcess("ndnpeek-4",
126 ["ndnpeek", "-r", "ndn:/test-agg/B"],
jeraldabrahamb2a26552014-04-16 21:08:09 -0700127 "-> Starting Peek Client 4 (Prefix=ndn:/test-agg/B, ChildSelector=rightmost)",
128 outputFile=peekOutputFile)
Eric Newberryd4ed6222015-06-10 14:12:42 -0700129 self.waitForProcessCompletion("ndnpeek-3", 10)
130 self.waitForProcessCompletion("ndnpeek-4", 10)
jeraldabrahamb2a26552014-04-16 21:08:09 -0700131
132 #Stop ndn-traffic-server. Fail if total served Interest does not equal 2.
133 self.killProcess("ndn-traffic-server-2")
134 time.sleep(1)
135 print "-> Stopping Traffic Server 2"
Eric Newberryd4ed6222015-06-10 14:12:42 -0700136 self.checkAndReportFailure("ndnpeek-3", "Peek Client 3")
137 self.checkAndReportFailure("ndnpeek-4", "Peek Client 4")
jeraldabrahamb2a26552014-04-16 21:08:09 -0700138 self.checkServerReceiveCount("ndn-traffic-server-2", "Traffic Server 2", 2)
139
140 #Start ndn-traffic-server to serve ndn:/test-agg, with content delay set to 2000ms
141 self.startProcess("ndn-traffic-server-3",
142 ["ndn-traffic-server", serverConfigurationFile],
143 "-> Starting Traffic Server 3 (Prefix=ndn:/test-agg, ContentDelay=2000ms)")
144 time.sleep(1)
145
Eric Newberryd4ed6222015-06-10 14:12:42 -0700146 #Start ndnpeek to request ndn:/test-agg/C InterestLifetime=6000ms, and another
jeraldabrahamb2a26552014-04-16 21:08:09 -0700147 #instance to request ndn:/test-agg/C. InterestLifetime=8000ms. Wait until they terminate.
148 #Fail if either is unanswered.
149 peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-5.txt")
Eric Newberryd4ed6222015-06-10 14:12:42 -0700150 self.startProcess("ndnpeek-5",
Eric Newberryc2d29ff2016-08-01 17:45:14 -0700151 ["ndnpeek", "--lifetime", "6000", "ndn:/test-agg/C"],
jeraldabrahamb2a26552014-04-16 21:08:09 -0700152 "-> Starting Peek Client 5 (Prefix=ndn:/test-agg/C, InterestLifetime=6000ms)",
153 outputFile=peekOutputFile)
154 peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-6.txt")
Eric Newberryd4ed6222015-06-10 14:12:42 -0700155 self.startProcess("ndnpeek-6",
Eric Newberryc2d29ff2016-08-01 17:45:14 -0700156 ["ndnpeek", "--lifetime", "8000", "ndn:/test-agg/C"],
jeraldabrahamb2a26552014-04-16 21:08:09 -0700157 "-> Starting Peek Client 6 (Prefix=ndn:/test-agg/C, InterestLifetime=8000ms)",
158 outputFile=peekOutputFile)
Eric Newberryd4ed6222015-06-10 14:12:42 -0700159 self.waitForProcessCompletion("ndnpeek-5", 10)
160 self.waitForProcessCompletion("ndnpeek-6", 10)
jeraldabrahamb2a26552014-04-16 21:08:09 -0700161
162 #Stop ndn-traffic-server. Fail if total served Interest does not equal 1.
163 self.killProcess("ndn-traffic-server-3")
164 time.sleep(1)
165 print "-> Stopping Traffic Server 3"
Eric Newberryd4ed6222015-06-10 14:12:42 -0700166 self.checkAndReportFailure("ndnpeek-5", "Peek Client 5")
167 self.checkAndReportFailure("ndnpeek-6", "Peek Client 6")
jeraldabrahamb2a26552014-04-16 21:08:09 -0700168 self.checkServerReceiveCount("ndn-traffic-server-3", "Traffic Server 3", 1)
169 print ">> TEST SUCCESSFUL"