Zhenkai Zhu | 64db03a | 2012-03-12 19:25:56 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2012-2014 University of California, Los Angeles |
Zhenkai Zhu | 64db03a | 2012-03-12 19:25:56 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame^] | 5 | * This file is part of ChronoSync, synchronization library for distributed realtime |
| 6 | * applications for NDN. |
Zhenkai Zhu | 64db03a | 2012-03-12 19:25:56 -0700 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame^] | 8 | * ChronoSync is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 10 | * version 3 of the License, or (at your option) any later version. |
Zhenkai Zhu | 64db03a | 2012-03-12 19:25:56 -0700 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame^] | 12 | * ChronoSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
Zhenkai Zhu | 64db03a | 2012-03-12 19:25:56 -0700 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 8722d87 | 2014-07-02 13:00:29 -0700 | [diff] [blame^] | 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Zhenkai Zhu | 64db03a | 2012-03-12 19:25:56 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include <boost/test/unit_test.hpp> |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 21 | #include <boost/test/output_test_stream.hpp> |
Zhenkai Zhu | 64db03a | 2012-03-12 19:25:56 -0700 | [diff] [blame] | 22 | using boost::test_tools::output_test_stream; |
| 23 | |
| 24 | #include <boost/make_shared.hpp> |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 25 | #include <boost/date_time/posix_time/posix_time.hpp> |
| 26 | |
Alexander Afanasyev | f46eac5 | 2013-07-26 11:27:39 -0700 | [diff] [blame] | 27 | #include "sync-logging.h" |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame] | 28 | #include "sync-socket.h" |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 29 | #include "sync-validator.h" |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 30 | #include <ndn-cxx/security/validator-null.hpp> |
Alexander Afanasyev | f46eac5 | 2013-07-26 11:27:39 -0700 | [diff] [blame] | 31 | |
Zhenkai Zhu | 64db03a | 2012-03-12 19:25:56 -0700 | [diff] [blame] | 32 | extern "C" { |
| 33 | #include <unistd.h> |
| 34 | } |
| 35 | |
| 36 | using namespace Sync; |
| 37 | using namespace std; |
| 38 | using namespace boost; |
| 39 | |
Alexander Afanasyev | 7df7333 | 2012-03-15 12:31:49 -0700 | [diff] [blame] | 40 | INIT_LOGGER ("Test.AppSocket"); |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 41 | |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 42 | #define PRINT |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 43 | // std::cout << "Line: " << __LINE__ << std::endl; |
Zhenkai Zhu | a30e178 | 2012-06-01 11:52:57 -0700 | [diff] [blame] | 44 | |
Zhenkai Zhu | 0030400 | 2012-03-12 21:32:30 -0700 | [diff] [blame] | 45 | class TestSocketApp { |
Zhenkai Zhu | 64db03a | 2012-03-12 19:25:56 -0700 | [diff] [blame] | 46 | public: |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 47 | TestSocketApp() |
| 48 | : sum(0) |
| 49 | {} |
| 50 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 51 | map<ndn::Name, string> data; |
| 52 | void set(const ndn::shared_ptr<const ndn::Data>& dataPacket) { |
Alexander Afanasyev | 235c6d7 | 2012-03-15 22:28:43 -0700 | [diff] [blame] | 53 | // _LOG_FUNCTION (this << ", " << str1); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 54 | ndn::Name dataName(dataPacket->getName()); |
| 55 | string str2(reinterpret_cast<const char*>(dataPacket->getContent().value()), dataPacket->getContent().value_size()); |
| 56 | data.insert(make_pair(dataName, str2)); |
Alexander Afanasyev | 1b449c4 | 2012-03-13 20:24:07 -0700 | [diff] [blame] | 57 | // cout << str1 << ", " << str2 << endl; |
Zhenkai Zhu | 64db03a | 2012-03-12 19:25:56 -0700 | [diff] [blame] | 58 | } |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 59 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 60 | void set(ndn::Name name, const char * buf, int len) { |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 61 | string str2(buf, len); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 62 | data.insert(make_pair(name, str2)); |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 63 | } |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 64 | |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 65 | void setNum(const ndn::shared_ptr<const ndn::Data>& data) { |
| 66 | int n = data->getContent().value_size() / 4; |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 67 | uint32_t *numbers = new uint32_t [n]; |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 68 | memcpy(numbers, data->getContent().value(), data->getContent().value_size()); |
Zhenkai Zhu | dc70a29 | 2012-06-01 14:00:59 -0700 | [diff] [blame] | 69 | for (int i = 0; i < n; i++) { |
| 70 | sum += numbers[i]; |
| 71 | } |
| 72 | delete numbers; |
| 73 | |
| 74 | } |
| 75 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 76 | void setNum(ndn::Name name, const char * buf, int len) { |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 77 | int n = len / 4; |
| 78 | int *numbers = new int [n]; |
| 79 | memcpy(numbers, buf, len); |
| 80 | for (int i = 0; i < n; i++) { |
| 81 | sum += numbers[i]; |
| 82 | } |
| 83 | delete numbers; |
| 84 | } |
| 85 | |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 86 | uint32_t sum; |
Zhenkai Zhu | 64db03a | 2012-03-12 19:25:56 -0700 | [diff] [blame] | 87 | |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 88 | void fetchAll(const vector<MissingDataInfo> &v, SyncSocket *socket) { |
Zhenkai Zhu | 1cb2929 | 2012-05-31 22:54:34 -0700 | [diff] [blame] | 89 | int n = v.size(); |
Zhenkai Zhu | a30e178 | 2012-06-01 11:52:57 -0700 | [diff] [blame] | 90 | |
| 91 | PRINT |
| 92 | |
Zhenkai Zhu | 1cb2929 | 2012-05-31 22:54:34 -0700 | [diff] [blame] | 93 | for (int i = 0; i < n; i++) { |
Zhenkai Zhu | a30e178 | 2012-06-01 11:52:57 -0700 | [diff] [blame] | 94 | for(SeqNo s = v[i].low; s <= v[i].high; ++s) { |
Zhenkai Zhu | dc70a29 | 2012-06-01 14:00:59 -0700 | [diff] [blame] | 95 | //PRINT |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 96 | socket->fetchData(v[i].prefix, s, bind(&TestSocketApp::set, this, _1)); |
Zhenkai Zhu | 1cb2929 | 2012-05-31 22:54:34 -0700 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 101 | void fetchNumbers(const vector<MissingDataInfo> &v, SyncSocket *socket) { |
Zhenkai Zhu | dc70a29 | 2012-06-01 14:00:59 -0700 | [diff] [blame] | 102 | int n = v.size(); |
| 103 | |
| 104 | PRINT |
| 105 | |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 106 | // std::cout << "In fetchNumbers. size of v is: " << n << std::endl; |
Zhenkai Zhu | dc70a29 | 2012-06-01 14:00:59 -0700 | [diff] [blame] | 107 | for (int i = 0; i < n; i++) { |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 108 | // 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 Zhu | dc70a29 | 2012-06-01 14:00:59 -0700 | [diff] [blame] | 109 | for(SeqNo s = v[i].low; s <= v[i].high; ++s) { |
| 110 | PRINT |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 111 | socket->fetchData(v[i].prefix, s, bind(&TestSocketApp::setNum, this, _1)); |
Zhenkai Zhu | dc70a29 | 2012-06-01 14:00:59 -0700 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
Zhenkai Zhu | 1cb2929 | 2012-05-31 22:54:34 -0700 | [diff] [blame] | 116 | void pass(const string &prefix) { |
| 117 | } |
| 118 | |
Zhenkai Zhu | 64db03a | 2012-03-12 19:25:56 -0700 | [diff] [blame] | 119 | string toString(){ |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 120 | map<ndn::Name, string>::iterator it = data.begin(); |
Zhenkai Zhu | 1a0fd5d | 2012-03-12 21:34:42 -0700 | [diff] [blame] | 121 | string str = "\n"; |
Zhenkai Zhu | 64db03a | 2012-03-12 19:25:56 -0700 | [diff] [blame] | 122 | for (; it != data.end(); ++it){ |
| 123 | str += "<"; |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 124 | str += it->first.toUri(); |
Zhenkai Zhu | 64db03a | 2012-03-12 19:25:56 -0700 | [diff] [blame] | 125 | str += "|"; |
| 126 | str += it->second; |
| 127 | str += ">"; |
Alexander Afanasyev | 1b449c4 | 2012-03-13 20:24:07 -0700 | [diff] [blame] | 128 | str += "\n"; |
Zhenkai Zhu | 64db03a | 2012-03-12 19:25:56 -0700 | [diff] [blame] | 129 | } |
Alexander Afanasyev | 1b449c4 | 2012-03-13 20:24:07 -0700 | [diff] [blame] | 130 | |
Zhenkai Zhu | 64db03a | 2012-03-12 19:25:56 -0700 | [diff] [blame] | 131 | return str; |
| 132 | } |
| 133 | |
| 134 | }; |
| 135 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 136 | class TestSet1{ |
| 137 | public: |
| 138 | TestSet1(ndn::shared_ptr<boost::asio::io_service> ioService) |
Alexander Afanasyev | 7fe5983 | 2014-07-02 12:17:46 -0700 | [diff] [blame] | 139 | : m_face1(new ndn::Face(*ioService)) |
| 140 | , m_face2(new ndn::Face(*ioService)) |
| 141 | , m_face3(new ndn::Face(*ioService)) |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 142 | , m_name1("/irl.cs.ucla.edu/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())) |
| 143 | , m_name2("/yakshi.org/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())) |
| 144 | , m_name3("/google.com/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())) |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 145 | { |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 146 | m_id1 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name1)); |
| 147 | m_id2 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name2)); |
| 148 | m_id3 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name3)); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 149 | |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 150 | m_rule = ndn::make_shared<ndn::SecRuleRelative>("^(<>*)<><>$", |
| 151 | "^(<>*)<><KEY><ksk-.*><ID-CERT>$", |
| 152 | "==", "\\1", "\\1", true); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 153 | } |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 154 | |
| 155 | void |
| 156 | createSyncSocket1() |
| 157 | { |
| 158 | _LOG_DEBUG ("s1"); |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 159 | |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 160 | m_s1 = ndn::shared_ptr<SyncSocket> |
| 161 | (new SyncSocket("/let/us/sync", |
| 162 | "/irl.cs.ucla.edu", |
| 163 | 0, |
| 164 | false, |
| 165 | "/", |
| 166 | m_face1, |
| 167 | *m_id1, |
| 168 | m_rule, |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 169 | bind(&TestSocketApp::fetchAll, &m_a1, _1, _2), |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 170 | bind(&TestSocketApp::pass, &m_a1, _1))); |
| 171 | |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 172 | m_s1->addParticipant(*m_id2); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | void |
| 176 | createSyncSocket2() |
| 177 | { |
| 178 | _LOG_DEBUG ("s2"); |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 179 | |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 180 | m_s2 = ndn::shared_ptr<SyncSocket> |
| 181 | (new SyncSocket("/let/us/sync", |
| 182 | "/yakshi.org", |
| 183 | 0, |
| 184 | false, |
| 185 | "/", |
| 186 | m_face2, |
| 187 | *m_id2, |
| 188 | m_rule, |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 189 | bind(&TestSocketApp::fetchAll, &m_a2, _1, _2), |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 190 | bind(&TestSocketApp::pass, &m_a2, _1))); |
| 191 | |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 192 | m_s2->addParticipant(*m_id1); |
| 193 | m_s2->addParticipant(*m_id3); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 194 | } |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 195 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 196 | void |
| 197 | createSyncSocket3() |
| 198 | { |
| 199 | _LOG_DEBUG ("s3"); |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 200 | |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 201 | m_s3 = ndn::shared_ptr<SyncSocket> |
| 202 | (new SyncSocket("/let/us/sync", |
| 203 | "/google.com", |
| 204 | 0, |
| 205 | false, |
| 206 | "/", |
| 207 | m_face3, |
| 208 | *m_id3, |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 209 | m_rule, |
| 210 | bind(&TestSocketApp::fetchAll, &m_a3, _1, _2), |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 211 | bind(&TestSocketApp::pass, &m_a3, _1))); |
| 212 | |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 213 | m_s3->addParticipant(*m_id2); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | void |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 217 | publishSocket1(string data) |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 218 | { |
| 219 | _LOG_DEBUG ("s1 publish"); |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 220 | m_s1->publishData (reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), 1000); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | void |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 224 | publishSocket2(string data) |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 225 | { |
| 226 | _LOG_DEBUG ("s2 publish"); |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 227 | m_s2->publishData (reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), 1000); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | void |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 231 | publishSocket3(string data) |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 232 | { |
| 233 | _LOG_DEBUG ("s3 publish"); |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 234 | m_s3->publishData (reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), 1000); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | void |
| 238 | setSocket1(string suffix, string data) |
| 239 | { |
| 240 | _LOG_DEBUG ("a1 set"); |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 241 | ndn::Name name("/irl.cs.ucla.edu"); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 242 | name.append(suffix); |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 243 | m_a1.set (name, data.c_str(), data.size()); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | void |
| 247 | setSocket2(string suffix, string data) |
| 248 | { |
| 249 | _LOG_DEBUG ("a2 set"); |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 250 | ndn::Name name("/yakshi.org"); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 251 | name.append(suffix); |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 252 | m_a2.set (name, data.c_str(), data.size()); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | void |
| 256 | setSocket3(string suffix, string data) |
| 257 | { |
| 258 | _LOG_DEBUG ("a3 set"); |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 259 | ndn::Name name("/google.com"); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 260 | name.append(suffix); |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 261 | m_a3.set (name, data.c_str(), data.size()); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | void |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 265 | check(int round) |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 266 | { |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 267 | BOOST_CHECK_EQUAL(m_a1.toString(), m_a2.toString()); |
| 268 | BOOST_CHECK_EQUAL(m_a2.toString(), m_a3.toString()); |
| 269 | } |
| 270 | |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 271 | void |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 272 | done(ndn::shared_ptr<boost::asio::io_service> ioService) |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 273 | { |
| 274 | m_s1.reset(); |
| 275 | m_s2.reset(); |
| 276 | m_s3.reset(); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 277 | |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 278 | m_keyChain.deleteIdentity(m_name1); |
| 279 | m_keyChain.deleteIdentity(m_name2); |
| 280 | m_keyChain.deleteIdentity(m_name3); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 281 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 282 | ioService->stop(); |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 283 | } |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 284 | |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 285 | ndn::KeyChain m_keyChain; |
| 286 | ndn::shared_ptr<ndn::SecRuleRelative> m_rule; |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 287 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 288 | ndn::shared_ptr<ndn::Face> m_face1, m_face2, m_face3; |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 289 | ndn::Name m_name1, m_name2, m_name3; |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 290 | TestSocketApp m_a1, m_a2, m_a3; |
| 291 | ndn::shared_ptr<ndn::IdentityCertificate> m_id1, m_id2, m_id3; |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 292 | ndn::shared_ptr<SyncSocket> m_s1, m_s2, m_s3; |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 293 | }; |
| 294 | |
| 295 | class TestSet2{ |
| 296 | public: |
| 297 | TestSet2(ndn::shared_ptr<boost::asio::io_service> ioService) |
Alexander Afanasyev | 7fe5983 | 2014-07-02 12:17:46 -0700 | [diff] [blame] | 298 | : m_face1(new ndn::Face(*ioService)) |
| 299 | , m_face2(new ndn::Face(*ioService)) |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 300 | , m_name1("/xiaonei.com/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())) |
| 301 | , m_name2("/mitbbs.com/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())) |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 302 | { |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 303 | m_id1 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name1)); |
| 304 | m_id2 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name2)); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 305 | |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 306 | m_rule = ndn::make_shared<ndn::SecRuleRelative>("^(<>*)<><>$", |
| 307 | "^(<>*)<><KEY><ksk-.*><ID-CERT>$", |
| 308 | "==", "\\1", "\\1", true); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 309 | } |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 310 | |
| 311 | void |
| 312 | createSyncSocket1() |
| 313 | { |
| 314 | _LOG_DEBUG ("s1"); |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 315 | |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 316 | m_s1 = ndn::shared_ptr<SyncSocket> |
| 317 | (new SyncSocket("/this/is/the/prefix", |
| 318 | "/xiaonei.com", |
| 319 | 0, |
| 320 | false, |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 321 | "/", |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 322 | m_face1, |
| 323 | *m_id1, |
| 324 | m_rule, |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 325 | bind(&TestSocketApp::fetchNumbers, &m_a1, _1, _2), |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 326 | bind(&TestSocketApp::pass, &m_a1, _1))); |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 327 | |
| 328 | m_s1->addParticipant(*m_id2); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | void |
| 332 | createSyncSocket2() |
| 333 | { |
| 334 | _LOG_DEBUG ("s2"); |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 335 | |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 336 | m_s2 = ndn::shared_ptr<SyncSocket> |
| 337 | (new SyncSocket("/this/is/the/prefix", |
| 338 | "/mitbbs.com", |
| 339 | 0, |
| 340 | false, |
| 341 | "/", |
| 342 | m_face2, |
| 343 | *m_id2, |
| 344 | m_rule, |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 345 | bind(&TestSocketApp::fetchNumbers, &m_a2, _1, _2), |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 346 | bind(&TestSocketApp::pass, &m_a2, _1))); |
| 347 | |
| 348 | m_s2->addParticipant(*m_id1); |
| 349 | } |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 350 | |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 351 | void |
| 352 | publishSocket1(string data) |
| 353 | { |
| 354 | _LOG_DEBUG ("s1 publish"); |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 355 | m_s1->publishData (reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), 1000); |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | void |
| 359 | publishSocket2(string data) |
| 360 | { |
| 361 | _LOG_DEBUG ("s2 publish"); |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 362 | m_s2->publishData (reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), 1000); |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | void |
| 366 | setSocket1(const char* ptr, size_t size) |
| 367 | { |
| 368 | _LOG_DEBUG ("a1 setNum"); |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 369 | m_a1.setNum ("/xiaonei.com", ptr, size); |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | void |
| 373 | setSocket2(const char* ptr, size_t size) |
| 374 | { |
| 375 | _LOG_DEBUG ("a2 setNum"); |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 376 | m_a2.setNum ("/mitbbs.com", ptr, size); |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | void |
| 380 | check(int num) |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 381 | { |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 382 | _LOG_DEBUG ("codnum " << num); |
| 383 | _LOG_DEBUG ("a1 sum " << m_a1.sum); |
| 384 | _LOG_DEBUG ("a2 sum " << m_a2.sum); |
| 385 | |
| 386 | BOOST_CHECK(m_a1.sum == m_a2.sum && m_a1.sum == num); |
| 387 | } |
| 388 | |
| 389 | void |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 390 | done(ndn::shared_ptr<boost::asio::io_service> ioService) |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 391 | { |
| 392 | m_s1.reset(); |
| 393 | m_s2.reset(); |
| 394 | |
| 395 | m_keyChain.deleteIdentity(m_name1); |
| 396 | m_keyChain.deleteIdentity(m_name2); |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 397 | |
| 398 | ioService->stop(); |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | ndn::KeyChain m_keyChain; |
| 402 | ndn::shared_ptr<ndn::SecRuleRelative> m_rule; |
| 403 | |
| 404 | TestSocketApp m_a1, m_a2; |
| 405 | ndn::shared_ptr<ndn::IdentityCertificate> m_id1, m_id2; |
| 406 | ndn::shared_ptr<ndn::Face> m_face1, m_face2; |
| 407 | ndn::Name m_name1, m_name2; |
| 408 | ndn::shared_ptr<SyncSocket> m_s1, m_s2; |
| 409 | }; |
| 410 | |
| 411 | |
| 412 | |
| 413 | class TestSet3{ |
| 414 | public: |
| 415 | TestSet3(ndn::shared_ptr<boost::asio::io_service> ioService) |
Alexander Afanasyev | 7fe5983 | 2014-07-02 12:17:46 -0700 | [diff] [blame] | 416 | : m_face1(new ndn::Face(*ioService)) |
| 417 | , m_face2(new ndn::Face(*ioService)) |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 418 | , m_name1("/xiaonei.com/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())) |
| 419 | , m_name2("/mitbbs.com/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count())) |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 420 | { |
| 421 | m_id1 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name1)); |
| 422 | m_id2 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name2)); |
| 423 | |
| 424 | m_rule = ndn::make_shared<ndn::SecRuleRelative>("^(<>*)<><>$", |
| 425 | "^(<>*)<><KEY><ksk-.*><ID-CERT>$", |
| 426 | "==", "\\1", "\\1", true); |
| 427 | } |
| 428 | |
| 429 | void |
| 430 | createSyncSocket1() |
| 431 | { |
| 432 | _LOG_DEBUG ("s1"); |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 433 | |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 434 | m_s1 = ndn::shared_ptr<SyncSocket> |
| 435 | (new SyncSocket("/this/is/the/prefix", |
| 436 | "/xiaonei.com", |
| 437 | 1, |
| 438 | true, |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 439 | "/abc", |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 440 | m_face1, |
| 441 | *m_id1, |
| 442 | m_rule, |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 443 | bind(&TestSocketApp::fetchNumbers, &m_a1, _1, _2), |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 444 | bind(&TestSocketApp::pass, &m_a1, _1))); |
| 445 | |
| 446 | m_s1->addParticipant(*m_id2); |
| 447 | } |
| 448 | |
| 449 | void |
| 450 | createSyncSocket2() |
| 451 | { |
| 452 | _LOG_DEBUG ("s2"); |
| 453 | |
| 454 | m_s2 = ndn::shared_ptr<SyncSocket> |
| 455 | (new SyncSocket("/this/is/the/prefix", |
| 456 | "/mitbbs.com", |
| 457 | 1, |
| 458 | false, |
| 459 | "/", |
| 460 | m_face2, |
| 461 | *m_id2, |
| 462 | m_rule, |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 463 | bind(&TestSocketApp::fetchNumbers, &m_a2, _1, _2), |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 464 | bind(&TestSocketApp::pass, &m_a2, _1))); |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 465 | |
| 466 | m_s2->addParticipant(*m_id1); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 467 | } |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 468 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 469 | void |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 470 | publishSocket1(string data) |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 471 | { |
| 472 | _LOG_DEBUG ("s1 publish"); |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 473 | m_s1->publishData (reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), 1000); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | void |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 477 | publishSocket2(string data) |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 478 | { |
| 479 | _LOG_DEBUG ("s2 publish"); |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 480 | m_s2->publishData (reinterpret_cast<const uint8_t*>(data.c_str()), data.size(), 1000); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | void |
| 484 | setSocket1(const char* ptr, size_t size) |
| 485 | { |
| 486 | _LOG_DEBUG ("a1 setNum"); |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 487 | m_a1.setNum ("/xiaonei.com", ptr, size); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | void |
| 491 | setSocket2(const char* ptr, size_t size) |
| 492 | { |
| 493 | _LOG_DEBUG ("a2 setNum"); |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 494 | m_a2.setNum ("/mitbbs.com", ptr, size); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | void |
| 498 | check(int num) |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 499 | { |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 500 | _LOG_DEBUG ("codnum " << num); |
| 501 | _LOG_DEBUG ("a1 sum " << m_a1.sum); |
| 502 | _LOG_DEBUG ("a2 sum " << m_a2.sum); |
| 503 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 504 | BOOST_CHECK(m_a1.sum == m_a2.sum && m_a1.sum == num); |
| 505 | } |
| 506 | |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 507 | void |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 508 | done(ndn::shared_ptr<boost::asio::io_service> ioService) |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 509 | { |
| 510 | m_s1.reset(); |
| 511 | m_s2.reset(); |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 512 | |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 513 | m_keyChain.deleteIdentity(m_name1); |
| 514 | m_keyChain.deleteIdentity(m_name2); |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 515 | |
| 516 | ioService->stop(); |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 517 | } |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 518 | |
Yingdi Yu | 3da10fe | 2014-02-27 16:37:34 -0800 | [diff] [blame] | 519 | ndn::KeyChain m_keyChain; |
| 520 | ndn::shared_ptr<ndn::SecRuleRelative> m_rule; |
| 521 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 522 | TestSocketApp m_a1, m_a2; |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 523 | ndn::shared_ptr<ndn::IdentityCertificate> m_id1, m_id2; |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 524 | ndn::shared_ptr<ndn::Face> m_face1, m_face2; |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 525 | ndn::Name m_name1, m_name2; |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 526 | ndn::shared_ptr<SyncSocket> m_s1, m_s2; |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 527 | }; |
| 528 | |
| 529 | BOOST_AUTO_TEST_CASE (AppSocketTest1) |
Zhenkai Zhu | 64db03a | 2012-03-12 19:25:56 -0700 | [diff] [blame] | 530 | { |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 531 | INIT_LOGGERS (); |
Zhenkai Zhu | 64db03a | 2012-03-12 19:25:56 -0700 | [diff] [blame] | 532 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 533 | ndn::shared_ptr<boost::asio::io_service> ioService = ndn::make_shared<boost::asio::io_service>(); |
| 534 | ndn::Scheduler scheduler(*ioService); |
| 535 | TestSet1 testSet1(ioService); |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 536 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 537 | scheduler.scheduleEvent(ndn::time::milliseconds(0), ndn::bind(&TestSet1::createSyncSocket1, &testSet1)); |
| 538 | scheduler.scheduleEvent(ndn::time::milliseconds(50), ndn::bind(&TestSet1::createSyncSocket2, &testSet1)); |
| 539 | scheduler.scheduleEvent(ndn::time::milliseconds(100), ndn::bind(&TestSet1::createSyncSocket3, &testSet1)); |
Alexander Afanasyev | 1b449c4 | 2012-03-13 20:24:07 -0700 | [diff] [blame] | 540 | string data0 = "Very funny Scotty, now beam down my clothes"; |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 541 | scheduler.scheduleEvent(ndn::time::milliseconds(150), ndn::bind(&TestSet1::publishSocket1, &testSet1, data0)); |
| 542 | scheduler.scheduleEvent(ndn::time::milliseconds(1150), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/1", data0)); |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 543 | scheduler.scheduleEvent(ndn::time::milliseconds(1160), ndn::bind(&TestSet1::check, &testSet1, 1)); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 544 | string data1 = "Yes, give me that ketchup"; |
| 545 | string data2 = "Don't look conspicuous, it draws fire"; |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 546 | scheduler.scheduleEvent(ndn::time::milliseconds(1170), ndn::bind(&TestSet1::publishSocket1, &testSet1, data1)); |
| 547 | scheduler.scheduleEvent(ndn::time::milliseconds(1180), ndn::bind(&TestSet1::publishSocket1, &testSet1, data2)); |
| 548 | scheduler.scheduleEvent(ndn::time::milliseconds(2150), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/2", data1)); |
| 549 | scheduler.scheduleEvent(ndn::time::milliseconds(2160), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/3", data2)); |
| 550 | scheduler.scheduleEvent(ndn::time::milliseconds(2170), ndn::bind(&TestSet1::check, &testSet1, 2)); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 551 | string data3 = "You surf the Internet, I surf the real world"; |
| 552 | string data4 = "I got a fortune cookie once that said 'You like Chinese food'"; |
| 553 | string data5 = "Real men wear pink. Why? Because their wives make them"; |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 554 | scheduler.scheduleEvent(ndn::time::milliseconds(3180), ndn::bind(&TestSet1::publishSocket3, &testSet1, data3)); |
| 555 | scheduler.scheduleEvent(ndn::time::milliseconds(3200), ndn::bind(&TestSet1::publishSocket2, &testSet1, data4)); |
| 556 | scheduler.scheduleEvent(ndn::time::milliseconds(3210), ndn::bind(&TestSet1::publishSocket2, &testSet1, data5)); |
| 557 | scheduler.scheduleEvent(ndn::time::milliseconds(4710), ndn::bind(&TestSet1::setSocket3, &testSet1, "/0/1", data3)); |
| 558 | scheduler.scheduleEvent(ndn::time::milliseconds(4720), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/2", data4)); |
| 559 | scheduler.scheduleEvent(ndn::time::milliseconds(4730), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/3", data5)); |
| 560 | scheduler.scheduleEvent(ndn::time::milliseconds(4800), ndn::bind(&TestSet1::check, &testSet1, 3)); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 561 | // not sure weither this is simultanous data generation from multiple sources |
| 562 | _LOG_DEBUG ("Simultaneous publishing"); |
| 563 | string data6 = "Shakespeare says: 'Prose before hos.'"; |
| 564 | string data7 = "Pick good people, talent never wears out"; |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 565 | scheduler.scheduleEvent(ndn::time::milliseconds(5500), ndn::bind(&TestSet1::publishSocket1, &testSet1, data6)); |
| 566 | scheduler.scheduleEvent(ndn::time::milliseconds(5500), ndn::bind(&TestSet1::publishSocket2, &testSet1, data7)); |
| 567 | scheduler.scheduleEvent(ndn::time::milliseconds(6800), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/4", data6)); |
| 568 | scheduler.scheduleEvent(ndn::time::milliseconds(6800), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/4", data7)); |
| 569 | scheduler.scheduleEvent(ndn::time::milliseconds(6900), ndn::bind(&TestSet1::check, &testSet1, 4)); |
| 570 | scheduler.scheduleEvent(ndn::time::milliseconds(7000), ndn::bind(&TestSet1::done, &testSet1, ioService)); |
Zhenkai Zhu | 0030400 | 2012-03-12 21:32:30 -0700 | [diff] [blame] | 571 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 572 | ioService->run(); |
| 573 | } |
Zhenkai Zhu | 0030400 | 2012-03-12 21:32:30 -0700 | [diff] [blame] | 574 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 575 | BOOST_AUTO_TEST_CASE (AppSocketTest2) |
| 576 | { |
| 577 | ndn::shared_ptr<boost::asio::io_service> ioService = ndn::make_shared<boost::asio::io_service>(); |
| 578 | ndn::Scheduler scheduler(*ioService); |
| 579 | TestSet2 testSet2(ioService); |
Zhenkai Zhu | 64db03a | 2012-03-12 19:25:56 -0700 | [diff] [blame] | 580 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 581 | scheduler.scheduleEvent(ndn::time::milliseconds(0), ndn::bind(&TestSet2::createSyncSocket1, &testSet2)); |
| 582 | scheduler.scheduleEvent(ndn::time::milliseconds(50), ndn::bind(&TestSet2::createSyncSocket2, &testSet2)); |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 583 | uint32_t num[5] = {0, 1, 2, 3, 4}; |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 584 | string data0((const char *) num, sizeof(num)); |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 585 | scheduler.scheduleEvent(ndn::time::milliseconds(100), ndn::bind(&TestSet2::publishSocket1, &testSet2, data0)); |
| 586 | scheduler.scheduleEvent(ndn::time::milliseconds(150), ndn::bind(&TestSet2::setSocket1, &testSet2, (const char *) num, sizeof (num))); |
| 587 | scheduler.scheduleEvent(ndn::time::milliseconds(1000), ndn::bind(&TestSet2::check, &testSet2, 10)); |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 588 | uint32_t newNum[5] = {9, 7, 2, 1, 1}; |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 589 | string data1((const char *) newNum, sizeof(newNum)); |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 590 | scheduler.scheduleEvent(ndn::time::milliseconds(1100), ndn::bind(&TestSet2::publishSocket2, &testSet2, data1)); |
| 591 | scheduler.scheduleEvent(ndn::time::milliseconds(1150), ndn::bind(&TestSet2::setSocket2, &testSet2, (const char *) newNum, sizeof (newNum))); |
| 592 | scheduler.scheduleEvent(ndn::time::milliseconds(2000), ndn::bind(&TestSet2::check, &testSet2, 30)); |
| 593 | scheduler.scheduleEvent(ndn::time::milliseconds(7000), ndn::bind(&TestSet2::done, &testSet2, ioService)); |
Zhenkai Zhu | 0030400 | 2012-03-12 21:32:30 -0700 | [diff] [blame] | 594 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 595 | ioService->run(); |
Zhenkai Zhu | 64db03a | 2012-03-12 19:25:56 -0700 | [diff] [blame] | 596 | } |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 597 | |
| 598 | BOOST_AUTO_TEST_CASE (AppSocketTest3) |
| 599 | { |
| 600 | ndn::shared_ptr<boost::asio::io_service> ioService = ndn::make_shared<boost::asio::io_service>(); |
| 601 | ndn::Scheduler scheduler(*ioService); |
| 602 | TestSet3 testSet3(ioService); |
| 603 | |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 604 | scheduler.scheduleEvent(ndn::time::milliseconds(0), ndn::bind(&TestSet3::createSyncSocket1, &testSet3)); |
| 605 | scheduler.scheduleEvent(ndn::time::milliseconds(200), ndn::bind(&TestSet3::createSyncSocket2, &testSet3)); |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 606 | uint32_t num[5] = {0, 1, 2, 3, 4}; |
| 607 | string data0((const char *) num, sizeof(num)); |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 608 | scheduler.scheduleEvent(ndn::time::milliseconds(1000), ndn::bind(&TestSet3::publishSocket1, &testSet3, data0)); |
| 609 | scheduler.scheduleEvent(ndn::time::milliseconds(1500), ndn::bind(&TestSet3::setSocket1, &testSet3, (const char *) num, sizeof (num))); |
| 610 | scheduler.scheduleEvent(ndn::time::milliseconds(2000), ndn::bind(&TestSet3::check, &testSet3, 10)); |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 611 | uint32_t newNum[5] = {9, 7, 2, 1, 1}; |
| 612 | string data1((const char *) newNum, sizeof(newNum)); |
Yingdi Yu | 6e1c9cd | 2014-03-25 10:26:54 -0700 | [diff] [blame] | 613 | scheduler.scheduleEvent(ndn::time::milliseconds(3000), ndn::bind(&TestSet3::publishSocket2, &testSet3, data1)); |
| 614 | scheduler.scheduleEvent(ndn::time::milliseconds(3500), ndn::bind(&TestSet3::setSocket2, &testSet3, (const char *) newNum, sizeof (newNum))); |
| 615 | scheduler.scheduleEvent(ndn::time::milliseconds(5000), ndn::bind(&TestSet3::check, &testSet3, 30)); |
| 616 | scheduler.scheduleEvent(ndn::time::milliseconds(7000), ndn::bind(&TestSet3::done, &testSet3, ioService)); |
Yingdi Yu | d4ef5d3 | 2014-03-01 02:02:01 -0800 | [diff] [blame] | 617 | |
| 618 | ioService->run(); |
| 619 | } |