blob: a10a2f1f3079facbaefd7db2d042a16fa2f7107e [file] [log] [blame]
Zhenkai Zhu64db03a2012-03-12 19:25:56 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2012 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
Chaoyi Bian3e1eb162012-04-03 16:59:32 -070019 * Chaoyi Bian <bcy@pku.edu.cn>
Zhenkai Zhu64db03a2012-03-12 19:25:56 -070020 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
21 */
22
23#include <boost/test/unit_test.hpp>
24#include <boost/test/output_test_stream.hpp>
25using boost::test_tools::output_test_stream;
26
27#include <boost/make_shared.hpp>
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070028#include <boost/date_time/posix_time/posix_time.hpp>
29
Alexander Afanasyevf46eac52013-07-26 11:27:39 -070030#include "sync-logging.h"
Alexander Afanasyevd95c2312013-11-07 13:45:34 -080031#include "sync-socket.h"
Yingdi Yu0eee6002014-02-11 15:54:17 -080032#include "sync-validator.h"
Yingdi Yu280bb962014-01-30 09:52:43 -080033#include <ndn-cpp-dev/security/validator-null.hpp>
Alexander Afanasyevf46eac52013-07-26 11:27:39 -070034
Zhenkai Zhu64db03a2012-03-12 19:25:56 -070035extern "C" {
36#include <unistd.h>
37}
38
39using namespace Sync;
40using namespace std;
41using namespace boost;
42
Alexander Afanasyev7df73332012-03-15 12:31:49 -070043INIT_LOGGER ("Test.AppSocket");
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070044
Zhenkai Zhua30e1782012-06-01 11:52:57 -070045#define PRINT
46//std::cout << "Line: " << __LINE__ << std::endl;
47
Zhenkai Zhu00304002012-03-12 21:32:30 -070048class TestSocketApp {
Zhenkai Zhu64db03a2012-03-12 19:25:56 -070049public:
Alexander Afanasyev531803b2014-02-05 15:57:35 -080050 TestSocketApp()
51 : sum(0)
52 {}
53
Yingdi Yu280bb962014-01-30 09:52:43 -080054 map<ndn::Name, string> data;
55 void set(const ndn::shared_ptr<const ndn::Data>& dataPacket) {
Alexander Afanasyev235c6d72012-03-15 22:28:43 -070056 // _LOG_FUNCTION (this << ", " << str1);
Yingdi Yu280bb962014-01-30 09:52:43 -080057 ndn::Name dataName(dataPacket->getName());
58 string str2(reinterpret_cast<const char*>(dataPacket->getContent().value()), dataPacket->getContent().value_size());
59 data.insert(make_pair(dataName, str2));
Alexander Afanasyev1b449c42012-03-13 20:24:07 -070060 // cout << str1 << ", " << str2 << endl;
Zhenkai Zhu64db03a2012-03-12 19:25:56 -070061 }
Yingdi Yu43e71612013-10-30 22:19:31 -070062
Yingdi Yu280bb962014-01-30 09:52:43 -080063 void set(ndn::Name name, const char * buf, int len) {
Yingdi Yu43e71612013-10-30 22:19:31 -070064 string str2(buf, len);
Yingdi Yu280bb962014-01-30 09:52:43 -080065 data.insert(make_pair(name, str2));
Yingdi Yu43e71612013-10-30 22:19:31 -070066 }
Zhenkai Zhudc70a292012-06-01 14:00:59 -070067
Yingdi Yu280bb962014-01-30 09:52:43 -080068 void setNum(const ndn::shared_ptr<const ndn::Data>& dataPacket) {
69 int n = dataPacket->getContent().value_size() / 4;
Alexander Afanasyev531803b2014-02-05 15:57:35 -080070 uint32_t *numbers = new uint32_t [n];
Yingdi Yu280bb962014-01-30 09:52:43 -080071 memcpy(numbers, dataPacket->getContent().value(), dataPacket->getContent().value_size());
Zhenkai Zhudc70a292012-06-01 14:00:59 -070072 for (int i = 0; i < n; i++) {
73 sum += numbers[i];
74 }
75 delete numbers;
76
77 }
78
Yingdi Yu280bb962014-01-30 09:52:43 -080079 void setNum(ndn::Name name, const char * buf, int len) {
Yingdi Yu43e71612013-10-30 22:19:31 -070080 int n = len / 4;
81 int *numbers = new int [n];
82 memcpy(numbers, buf, len);
83 for (int i = 0; i < n; i++) {
84 sum += numbers[i];
85 }
86 delete numbers;
87 }
88
Alexander Afanasyev531803b2014-02-05 15:57:35 -080089 uint32_t sum;
Zhenkai Zhu64db03a2012-03-12 19:25:56 -070090
Yingdi Yu43e71612013-10-30 22:19:31 -070091 void fetchAll(const vector<MissingDataInfo> &v, SyncSocket *socket) {
Zhenkai Zhu1cb29292012-05-31 22:54:34 -070092 int n = v.size();
Zhenkai Zhua30e1782012-06-01 11:52:57 -070093
94 PRINT
95
Zhenkai Zhu1cb29292012-05-31 22:54:34 -070096 for (int i = 0; i < n; i++) {
Zhenkai Zhua30e1782012-06-01 11:52:57 -070097 for(SeqNo s = v[i].low; s <= v[i].high; ++s) {
Zhenkai Zhudc70a292012-06-01 14:00:59 -070098 //PRINT
Yingdi Yu43e71612013-10-30 22:19:31 -070099 socket->fetchData(v[i].prefix, s, bind(&TestSocketApp::set, this, _1));
Zhenkai Zhu1cb29292012-05-31 22:54:34 -0700100 }
101 }
102 }
103
Yingdi Yu43e71612013-10-30 22:19:31 -0700104 void fetchNumbers(const vector<MissingDataInfo> &v, SyncSocket *socket) {
Zhenkai Zhudc70a292012-06-01 14:00:59 -0700105 int n = v.size();
106
107 PRINT
108
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800109 // std::cout << "In fetchNumbers. size of v is: " << n << std::endl;
Zhenkai Zhudc70a292012-06-01 14:00:59 -0700110 for (int i = 0; i < n; i++) {
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800111 // std::cout << "In fetchNumbers. v[i].low is (" <<v[i].low.getSession() <<", " << v[i].low.getSeq() << ") v[i].high is ("<<v[i].high.getSession() <<", " <<v[i].high.getSeq()<<")" << std::endl;
Zhenkai Zhudc70a292012-06-01 14:00:59 -0700112 for(SeqNo s = v[i].low; s <= v[i].high; ++s) {
113 PRINT
Yingdi Yu43e71612013-10-30 22:19:31 -0700114 socket->fetchData(v[i].prefix, s, bind(&TestSocketApp::setNum, this, _1));
Zhenkai Zhudc70a292012-06-01 14:00:59 -0700115 }
116 }
117 }
118
Zhenkai Zhu1cb29292012-05-31 22:54:34 -0700119 void pass(const string &prefix) {
120 }
121
Zhenkai Zhu64db03a2012-03-12 19:25:56 -0700122 string toString(){
Yingdi Yu280bb962014-01-30 09:52:43 -0800123 map<ndn::Name, string>::iterator it = data.begin();
Zhenkai Zhu1a0fd5d2012-03-12 21:34:42 -0700124 string str = "\n";
Zhenkai Zhu64db03a2012-03-12 19:25:56 -0700125 for (; it != data.end(); ++it){
126 str += "<";
Yingdi Yu280bb962014-01-30 09:52:43 -0800127 str += it->first.toUri();
Zhenkai Zhu64db03a2012-03-12 19:25:56 -0700128 str += "|";
129 str += it->second;
130 str += ">";
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700131 str += "\n";
Zhenkai Zhu64db03a2012-03-12 19:25:56 -0700132 }
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700133
Zhenkai Zhu64db03a2012-03-12 19:25:56 -0700134 return str;
135 }
136
137};
138
Yingdi Yu280bb962014-01-30 09:52:43 -0800139class TestSet1{
140public:
141 TestSet1(ndn::shared_ptr<boost::asio::io_service> ioService)
Yingdi Yu0eee6002014-02-11 15:54:17 -0800142 : m_face1(new ndn::Face(ioService))
Yingdi Yu280bb962014-01-30 09:52:43 -0800143 , m_face2(new ndn::Face(ioService))
144 , m_face3(new ndn::Face(ioService))
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800145 , m_name1("/irl.cs.ucla.edu/" + boost::lexical_cast<std::string>(ndn::time::now()))
146 , m_name2("/yakshi.org/" + boost::lexical_cast<std::string>(ndn::time::now()))
147 , m_name3("/google.com/" + boost::lexical_cast<std::string>(ndn::time::now()))
Yingdi Yu0eee6002014-02-11 15:54:17 -0800148 {
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800149 m_id1 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name1));
150 m_id2 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name2));
151 m_id3 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name3));
Yingdi Yu0eee6002014-02-11 15:54:17 -0800152
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800153 m_rule = ndn::make_shared<ndn::SecRuleRelative>("^(<>*)<><>$",
154 "^(<>*)<><KEY><ksk-.*><ID-CERT>$",
155 "==", "\\1", "\\1", true);
Yingdi Yu0eee6002014-02-11 15:54:17 -0800156 }
Yingdi Yu280bb962014-01-30 09:52:43 -0800157
158 void
159 createSyncSocket1()
160 {
161 _LOG_DEBUG ("s1");
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800162
163 m_s1 = ndn::make_shared<SyncSocket>("/let/us/sync",
164 "/irl.cs.ucla.edu",
165 0,
166 *m_id1,
167 m_rule,
168 m_face1,
169 bind(&TestSocketApp::fetchAll, &m_a1, _1, _2),
170 bind(&TestSocketApp::pass, &m_a1, _1));
171 m_s1->addParticipant(*m_id2);
Yingdi Yu280bb962014-01-30 09:52:43 -0800172 }
173
174 void
175 createSyncSocket2()
176 {
177 _LOG_DEBUG ("s2");
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800178
179 m_s2 = ndn::make_shared<SyncSocket>("/let/us/sync",
180 "/yakshi.org",
181 0,
182 *m_id2,
183 m_rule,
184 m_face2,
185 bind(&TestSocketApp::fetchAll, &m_a2, _1, _2),
186 bind(&TestSocketApp::pass, &m_a2, _1));
187 m_s2->addParticipant(*m_id1);
188 m_s2->addParticipant(*m_id3);
Yingdi Yu280bb962014-01-30 09:52:43 -0800189 }
190
191 void
192 createSyncSocket3()
193 {
194 _LOG_DEBUG ("s3");
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800195
196 m_s3 = ndn::make_shared<SyncSocket>("/let/us/sync",
197 "/google.com",
198 0,
199 *m_id3,
200 m_rule,
201 m_face3,
202 bind(&TestSocketApp::fetchAll, &m_a3, _1, _2),
203 bind(&TestSocketApp::pass, &m_a3, _1));
204 m_s3->addParticipant(*m_id2);
Yingdi Yu280bb962014-01-30 09:52:43 -0800205 }
206
207 void
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800208 publishSocket1(string data)
Yingdi Yu280bb962014-01-30 09:52:43 -0800209 {
210 _LOG_DEBUG ("s1 publish");
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800211 m_s1->publishData (reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), 1000);
Yingdi Yu280bb962014-01-30 09:52:43 -0800212 }
213
214 void
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800215 publishSocket2(string data)
Yingdi Yu280bb962014-01-30 09:52:43 -0800216 {
217 _LOG_DEBUG ("s2 publish");
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800218 m_s2->publishData (reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), 1000);
Yingdi Yu280bb962014-01-30 09:52:43 -0800219 }
220
221 void
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800222 publishSocket3(string data)
Yingdi Yu280bb962014-01-30 09:52:43 -0800223 {
224 _LOG_DEBUG ("s3 publish");
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800225 m_s3->publishData (reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), 1000);
Yingdi Yu280bb962014-01-30 09:52:43 -0800226 }
227
228 void
229 setSocket1(string suffix, string data)
230 {
231 _LOG_DEBUG ("a1 set");
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800232 ndn::Name name("/irl.cs.ucla.edu");
Yingdi Yu280bb962014-01-30 09:52:43 -0800233 name.append(suffix);
234 m_a1.set (name, data.c_str(), data.size());
235 }
236
237 void
238 setSocket2(string suffix, string data)
239 {
240 _LOG_DEBUG ("a2 set");
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800241 ndn::Name name("/yakshi.org");
Yingdi Yu280bb962014-01-30 09:52:43 -0800242 name.append(suffix);
243 m_a2.set (name, data.c_str(), data.size());
244 }
245
246 void
247 setSocket3(string suffix, string data)
248 {
249 _LOG_DEBUG ("a3 set");
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800250 ndn::Name name("/google.com");
Yingdi Yu280bb962014-01-30 09:52:43 -0800251 name.append(suffix);
252 m_a3.set (name, data.c_str(), data.size());
253 }
254
255 void
Yingdi Yu7ad4e4f2014-02-03 18:27:36 -0800256 check(int round)
Yingdi Yu280bb962014-01-30 09:52:43 -0800257 {
258 BOOST_CHECK_EQUAL(m_a1.toString(), m_a2.toString());
259 BOOST_CHECK_EQUAL(m_a2.toString(), m_a3.toString());
260 }
261
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800262 void
263 done()
264 {
265 m_s1.reset();
266 m_s2.reset();
267 m_s3.reset();
Yingdi Yu0eee6002014-02-11 15:54:17 -0800268
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800269 m_keyChain.deleteIdentity(m_name1);
270 m_keyChain.deleteIdentity(m_name2);
271 m_keyChain.deleteIdentity(m_name3);
Yingdi Yu0eee6002014-02-11 15:54:17 -0800272
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800273 }
Yingdi Yu280bb962014-01-30 09:52:43 -0800274
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800275 ndn::KeyChain m_keyChain;
276 ndn::shared_ptr<ndn::SecRuleRelative> m_rule;
Yingdi Yu280bb962014-01-30 09:52:43 -0800277
Yingdi Yu280bb962014-01-30 09:52:43 -0800278 ndn::shared_ptr<ndn::Face> m_face1, m_face2, m_face3;
Yingdi Yu0eee6002014-02-11 15:54:17 -0800279 ndn::Name m_name1, m_name2, m_name3;
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800280 TestSocketApp m_a1, m_a2, m_a3;
281 ndn::shared_ptr<ndn::IdentityCertificate> m_id1, m_id2, m_id3;
Yingdi Yu280bb962014-01-30 09:52:43 -0800282 ndn::shared_ptr<SyncSocket> m_s1, m_s2, m_s3;
Yingdi Yu280bb962014-01-30 09:52:43 -0800283};
284
285class TestSet2{
286public:
287 TestSet2(ndn::shared_ptr<boost::asio::io_service> ioService)
Yingdi Yu0eee6002014-02-11 15:54:17 -0800288 : m_face1(new ndn::Face(ioService))
Yingdi Yu280bb962014-01-30 09:52:43 -0800289 , m_face2(new ndn::Face(ioService))
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800290 , m_name1("/xiaonei.com/" + boost::lexical_cast<std::string>(ndn::time::now()))
291 , m_name2("/mitbbs.com/" + boost::lexical_cast<std::string>(ndn::time::now()))
Yingdi Yu0eee6002014-02-11 15:54:17 -0800292 {
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800293 m_id1 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name1));
294 m_id2 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name2));
Yingdi Yu0eee6002014-02-11 15:54:17 -0800295
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800296 m_rule = ndn::make_shared<ndn::SecRuleRelative>("^(<>*)<><>$",
297 "^(<>*)<><KEY><ksk-.*><ID-CERT>$",
298 "==", "\\1", "\\1", true);
Yingdi Yu0eee6002014-02-11 15:54:17 -0800299 }
Yingdi Yu280bb962014-01-30 09:52:43 -0800300
301 void
302 createSyncSocket1()
303 {
304 _LOG_DEBUG ("s1");
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800305
306 m_s1 = ndn::make_shared<SyncSocket>("/this/is/the/prefix",
307 "/xiaonei.com",
308 0,
309 *m_id1,
310 m_rule,
311 m_face1,
312 bind(&TestSocketApp::fetchNumbers, &m_a1, _1, _2),
313 bind(&TestSocketApp::pass, &m_a1, _1));
314
315 m_s1->addParticipant(*m_id2);
Yingdi Yu280bb962014-01-30 09:52:43 -0800316 }
317
318 void
319 createSyncSocket2()
320 {
321 _LOG_DEBUG ("s2");
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800322
323 m_s2 = ndn::make_shared<SyncSocket>("/this/is/the/prefix",
324 "/mitbbs.com",
325 0,
326 *m_id2,
327 m_rule,
328 m_face2,
329 bind(&TestSocketApp::fetchNumbers, &m_a2, _1, _2),
330 bind(&TestSocketApp::pass, &m_a2, _1));
331
332 m_s2->addParticipant(*m_id1);
Yingdi Yu280bb962014-01-30 09:52:43 -0800333 }
334
335 void
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800336 publishSocket1(string data)
Yingdi Yu280bb962014-01-30 09:52:43 -0800337 {
338 _LOG_DEBUG ("s1 publish");
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800339 m_s1->publishData (reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), 1000);
Yingdi Yu280bb962014-01-30 09:52:43 -0800340 }
341
342 void
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800343 publishSocket2(string data)
Yingdi Yu280bb962014-01-30 09:52:43 -0800344 {
345 _LOG_DEBUG ("s2 publish");
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800346 m_s2->publishData (reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), 1000);
Yingdi Yu280bb962014-01-30 09:52:43 -0800347 }
348
349 void
350 setSocket1(const char* ptr, size_t size)
351 {
352 _LOG_DEBUG ("a1 setNum");
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800353 m_a1.setNum ("/xiaonei.com", ptr, size);
Yingdi Yu280bb962014-01-30 09:52:43 -0800354 }
355
356 void
357 setSocket2(const char* ptr, size_t size)
358 {
359 _LOG_DEBUG ("a2 setNum");
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800360 m_a2.setNum ("/mitbbs.com", ptr, size);
Yingdi Yu280bb962014-01-30 09:52:43 -0800361 }
362
363 void
364 check(int num)
365 {
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800366 _LOG_DEBUG ("codnum " << num);
367 _LOG_DEBUG ("a1 sum " << m_a1.sum);
368 _LOG_DEBUG ("a2 sum " << m_a2.sum);
369
Yingdi Yu280bb962014-01-30 09:52:43 -0800370 BOOST_CHECK(m_a1.sum == m_a2.sum && m_a1.sum == num);
371 }
372
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800373 void
374 done()
375 {
376 m_s1.reset();
377 m_s2.reset();
Yingdi Yu0eee6002014-02-11 15:54:17 -0800378
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800379 m_keyChain.deleteIdentity(m_name1);
380 m_keyChain.deleteIdentity(m_name2);
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800381 }
Yingdi Yu280bb962014-01-30 09:52:43 -0800382
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800383 ndn::KeyChain m_keyChain;
384 ndn::shared_ptr<ndn::SecRuleRelative> m_rule;
385
Yingdi Yu280bb962014-01-30 09:52:43 -0800386 TestSocketApp m_a1, m_a2;
Yingdi Yu0eee6002014-02-11 15:54:17 -0800387 ndn::shared_ptr<ndn::IdentityCertificate> m_id1, m_id2;
Yingdi Yu280bb962014-01-30 09:52:43 -0800388 ndn::shared_ptr<ndn::Face> m_face1, m_face2;
Yingdi Yu0eee6002014-02-11 15:54:17 -0800389 ndn::Name m_name1, m_name2;
Yingdi Yu280bb962014-01-30 09:52:43 -0800390 ndn::shared_ptr<SyncSocket> m_s1, m_s2;
Yingdi Yu280bb962014-01-30 09:52:43 -0800391};
392
393BOOST_AUTO_TEST_CASE (AppSocketTest1)
Zhenkai Zhu64db03a2012-03-12 19:25:56 -0700394{
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -0700395 INIT_LOGGERS ();
Zhenkai Zhu64db03a2012-03-12 19:25:56 -0700396
Yingdi Yu280bb962014-01-30 09:52:43 -0800397 ndn::shared_ptr<boost::asio::io_service> ioService = ndn::make_shared<boost::asio::io_service>();
398 ndn::Scheduler scheduler(*ioService);
399 TestSet1 testSet1(ioService);
Yingdi Yu43e71612013-10-30 22:19:31 -0700400
Yingdi Yu280bb962014-01-30 09:52:43 -0800401 scheduler.scheduleEvent(ndn::time::seconds(0.00), ndn::bind(&TestSet1::createSyncSocket1, &testSet1));
402 scheduler.scheduleEvent(ndn::time::seconds(0.05), ndn::bind(&TestSet1::createSyncSocket2, &testSet1));
403 scheduler.scheduleEvent(ndn::time::seconds(0.10), ndn::bind(&TestSet1::createSyncSocket3, &testSet1));
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700404 string data0 = "Very funny Scotty, now beam down my clothes";
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800405 scheduler.scheduleEvent(ndn::time::seconds(0.15), ndn::bind(&TestSet1::publishSocket1, &testSet1, data0));
406 scheduler.scheduleEvent(ndn::time::seconds(1.15), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/1", data0));
Yingdi Yu7ad4e4f2014-02-03 18:27:36 -0800407 scheduler.scheduleEvent(ndn::time::seconds(1.16), ndn::bind(&TestSet1::check, &testSet1, 1));
Yingdi Yu280bb962014-01-30 09:52:43 -0800408 string data1 = "Yes, give me that ketchup";
409 string data2 = "Don't look conspicuous, it draws fire";
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800410 scheduler.scheduleEvent(ndn::time::seconds(1.17), ndn::bind(&TestSet1::publishSocket1, &testSet1, data1));
411 scheduler.scheduleEvent(ndn::time::seconds(1.18), ndn::bind(&TestSet1::publishSocket1, &testSet1, data2));
412 scheduler.scheduleEvent(ndn::time::seconds(2.15), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/2", data1));
413 scheduler.scheduleEvent(ndn::time::seconds(2.16), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/3", data2));
Yingdi Yu7ad4e4f2014-02-03 18:27:36 -0800414 scheduler.scheduleEvent(ndn::time::seconds(2.17), ndn::bind(&TestSet1::check, &testSet1, 2));
Yingdi Yu280bb962014-01-30 09:52:43 -0800415 string data3 = "You surf the Internet, I surf the real world";
416 string data4 = "I got a fortune cookie once that said 'You like Chinese food'";
417 string data5 = "Real men wear pink. Why? Because their wives make them";
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800418 scheduler.scheduleEvent(ndn::time::seconds(3.18), ndn::bind(&TestSet1::publishSocket3, &testSet1, data3));
419 scheduler.scheduleEvent(ndn::time::seconds(3.20), ndn::bind(&TestSet1::publishSocket2, &testSet1, data4));
420 scheduler.scheduleEvent(ndn::time::seconds(3.21), ndn::bind(&TestSet1::publishSocket2, &testSet1, data5));
421 scheduler.scheduleEvent(ndn::time::seconds(4.71), ndn::bind(&TestSet1::setSocket3, &testSet1, "/0/1", data3));
422 scheduler.scheduleEvent(ndn::time::seconds(4.72), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/2", data4));
423 scheduler.scheduleEvent(ndn::time::seconds(4.73), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/3", data5));
424 scheduler.scheduleEvent(ndn::time::seconds(4.80), ndn::bind(&TestSet1::check, &testSet1, 3));
Yingdi Yu280bb962014-01-30 09:52:43 -0800425 // not sure weither this is simultanous data generation from multiple sources
426 _LOG_DEBUG ("Simultaneous publishing");
427 string data6 = "Shakespeare says: 'Prose before hos.'";
428 string data7 = "Pick good people, talent never wears out";
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800429 scheduler.scheduleEvent(ndn::time::seconds(5.50), ndn::bind(&TestSet1::publishSocket1, &testSet1, data6));
430 scheduler.scheduleEvent(ndn::time::seconds(5.50), ndn::bind(&TestSet1::publishSocket2, &testSet1, data7));
431 scheduler.scheduleEvent(ndn::time::seconds(6.80), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/4", data6));
432 scheduler.scheduleEvent(ndn::time::seconds(6.80), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/4", data7));
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800433 scheduler.scheduleEvent(ndn::time::seconds(6.90), ndn::bind(&TestSet1::check, &testSet1, 4));
434 scheduler.scheduleEvent(ndn::time::seconds(7.00), ndn::bind(&TestSet1::done, &testSet1));
Zhenkai Zhu00304002012-03-12 21:32:30 -0700435
Yingdi Yu280bb962014-01-30 09:52:43 -0800436 ioService->run();
437}
Zhenkai Zhu00304002012-03-12 21:32:30 -0700438
Yingdi Yu280bb962014-01-30 09:52:43 -0800439BOOST_AUTO_TEST_CASE (AppSocketTest2)
440{
441 ndn::shared_ptr<boost::asio::io_service> ioService = ndn::make_shared<boost::asio::io_service>();
442 ndn::Scheduler scheduler(*ioService);
443 TestSet2 testSet2(ioService);
Zhenkai Zhu64db03a2012-03-12 19:25:56 -0700444
Yingdi Yu280bb962014-01-30 09:52:43 -0800445 scheduler.scheduleEvent(ndn::time::seconds(0.00), ndn::bind(&TestSet2::createSyncSocket1, &testSet2));
446 scheduler.scheduleEvent(ndn::time::seconds(0.05), ndn::bind(&TestSet2::createSyncSocket2, &testSet2));
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800447 uint32_t num[5] = {0, 1, 2, 3, 4};
Yingdi Yu280bb962014-01-30 09:52:43 -0800448 string data0((const char *) num, sizeof(num));
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800449 scheduler.scheduleEvent(ndn::time::seconds(0.10), ndn::bind(&TestSet2::publishSocket1, &testSet2, data0));
Yingdi Yu280bb962014-01-30 09:52:43 -0800450 scheduler.scheduleEvent(ndn::time::seconds(0.15), ndn::bind(&TestSet2::setSocket1, &testSet2, (const char *) num, sizeof (num)));
451 scheduler.scheduleEvent(ndn::time::seconds(1.00), ndn::bind(&TestSet2::check, &testSet2, 10));
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800452 uint32_t newNum[5] = {9, 7, 2, 1, 1};
Yingdi Yu280bb962014-01-30 09:52:43 -0800453 string data1((const char *) newNum, sizeof(newNum));
Yingdi Yu3da10fe2014-02-27 16:37:34 -0800454 scheduler.scheduleEvent(ndn::time::seconds(1.10), ndn::bind(&TestSet2::publishSocket2, &testSet2, data1));
Yingdi Yu280bb962014-01-30 09:52:43 -0800455 scheduler.scheduleEvent(ndn::time::seconds(1.15), ndn::bind(&TestSet2::setSocket2, &testSet2, (const char *) newNum, sizeof (newNum)));
456 scheduler.scheduleEvent(ndn::time::seconds(2.00), ndn::bind(&TestSet2::check, &testSet2, 30));
Alexander Afanasyev531803b2014-02-05 15:57:35 -0800457 scheduler.scheduleEvent(ndn::time::seconds(7.00), ndn::bind(&TestSet2::done, &testSet2));
Zhenkai Zhu00304002012-03-12 21:32:30 -0700458
Yingdi Yu280bb962014-01-30 09:52:43 -0800459 ioService->run();
Zhenkai Zhu64db03a2012-03-12 19:25:56 -0700460}