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