Added aqua_speed for rite geo 50 tryker
[ryzomcore.git] / nel / tools / nel_unit_test / ut_net_module.h
blob1ccc007cbc93c855693e584e964e8a50d6f5e622
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
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 Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef UT_NET_MODULE
18 #define UT_NET_MODULE
20 #include <nel/misc/dynloadlib.h>
21 #include <nel/misc/command.h>
22 #include <nel/misc/path.h>
23 #include <nel/net/module_common.h>
24 #include <nel/net/module_manager.h>
25 #include <nel/net/module.h>
26 #include <nel/net/inet_address.h>
27 #include <nel/net/module_socket.h>
28 #include <nel/net/module_gateway.h>
29 #include <nel/net/service.h>
31 class CModuleType0 : public NLNET::CModuleBase
33 public:
35 uint PingCount;
36 uint ResponseReceived;
38 set<NLNET::TModuleProxyPtr> ModuleType0;
40 uint32 ModuleUpCalled;
41 uint32 ModuleDownCalled;
42 uint32 ProcessMessageCalled;
43 uint32 SecurityUpdateCalled;
46 CModuleType0()
47 : PingCount(0),
48 ResponseReceived(0)
50 ModuleUpCalled = 0;
51 ModuleDownCalled = 0;
52 ProcessMessageCalled = 0;
53 SecurityUpdateCalled = 0;
56 std::string buildModuleManifest() const
58 return "CModuleType0";
61 bool initModule(const NLNET::TParsedCommandLine &param)
63 bool ret = CModuleBase::initModule(param);
64 if (param.getParam("FAIL") != NULL)
65 return false;
67 return ret;
70 void onServiceUp(const std::string &serviceName, NLNET::TServiceId serviceId)
73 /// A nel layer 5 service has stopped.
74 void onServiceDown(const std::string &serviceName, NLNET::TServiceId serviceId)
77 void onModuleUpdate()
80 /** The service main loop is terminating it job', all module will be
81 * disconnected and removed after this callback.
83 void onApplicationExit()
87 void onModuleUp(NLNET::IModuleProxy *moduleProxy)
89 ModuleUpCalled++;
91 if (moduleProxy->getModuleClassName() == getModuleClassName())
92 ModuleType0.insert(moduleProxy);
94 /** Called by a socket to inform this module that another
95 * module has been deleted OR has been no more accessible (due to
96 * some gateway disconnection).
98 void onModuleDown(NLNET::IModuleProxy *moduleProxy)
100 ModuleDownCalled++;
102 if (moduleProxy->getModuleClassName() == getModuleClassName())
103 ModuleType0.erase(moduleProxy);
106 bool onProcessModuleMessage(NLNET::IModuleProxy *senderModuleProxy, const NLNET::CMessage &message)
108 ProcessMessageCalled++;
110 if (message.getName() == "DEBUG_MOD_PING")
112 PingCount++;
113 return true;
115 else if (message.getName() == "HELLO")
117 NLNET::CMessage ping("DEBUG_MOD_PING");
118 senderModuleProxy->sendModuleMessage(this, NLNET::CMessage(ping));
119 senderModuleProxy->sendModuleMessage(this, NLNET::CMessage(ping));
121 NLNET::CMessage resp;
122 resp.setType("HELLO_RESP", NLNET::CMessage::Response);
124 senderModuleProxy->sendModuleMessage(this, resp);
126 senderModuleProxy->sendModuleMessage(this, NLNET::CMessage(ping));
127 senderModuleProxy->sendModuleMessage(this, NLNET::CMessage(ping));
128 return true;
130 else if (message.getName() == "HELLO2")
132 // the response for the life, the universe and all other things...
133 throw 42;
135 return true;
138 return false;
141 void onModuleSecurityChange(NLNET::IModuleProxy *moduleProxy)
143 SecurityUpdateCalled++;
146 void onModuleSocketEvent(NLNET::IModuleSocket *moduleSocket, IModule::TModuleSocketEvent eventType)
150 void startTaskA()
152 // start a task on module
153 NLNET_START_MODULE_TASK(CModuleType0, taskA);
156 // test task A
157 void taskA()
159 // use the first like me in the list
160 nlassert(!ModuleType0.empty());
162 NLNET::TModuleProxyPtr proxy = *ModuleType0.begin();
164 NLNET::CMessage msg;
165 msg.setType("HELLO", NLNET::CMessage::Request);
166 NLNET::CMessage resp;
167 invokeModuleOperation(proxy, msg, resp);
169 nlassert(resp.getName() == "HELLO_RESP");
171 ResponseReceived++;
174 void startTaskB()
176 // start a task on module
177 NLNET_START_MODULE_TASK(CModuleType0, taskB);
180 // test task B
181 void taskB()
183 // use the first like me in the list
184 nlassert(!ModuleType0.empty());
186 NLNET::TModuleProxyPtr proxy = *ModuleType0.begin();
188 NLNET::CMessage msg;
189 msg.setType("HELLO2", NLNET::CMessage::Request);
190 NLNET::CMessage resp;
194 invokeModuleOperation(proxy, msg, resp);
196 catch(const IModule::EInvokeFailed &)
198 ResponseReceived++;
204 NLNET_REGISTER_MODULE_FACTORY(CModuleType0, "ModuleType0");
206 // A module that doesn't support immediate dispatching
207 class CModuleAsync : public CModuleType0
209 public:
211 bool isImmediateDispatchingSupported() const
213 return false;
217 NLNET_REGISTER_MODULE_FACTORY(CModuleAsync, "ModuleAsync");
219 enum TTestSecurityTypes
221 tst_type1,
222 tst_type2,
223 tst_type3,
224 tst_type4,
227 // security type 1 data : contains host gateway name
228 struct TSecurityType1 : public NLNET::TSecurityData
230 string SecurityGatewayName;
232 TSecurityType1(const TCtorParam &param)
233 : NLNET::TSecurityData(param)
237 void serial(NLMISC::CMemStream &s)
239 s.serial(SecurityGatewayName);
244 NLMISC_REGISTER_OBJECT(NLNET::TSecurityData, TSecurityType1, uint8, tst_type1);
247 // security type 2 data : contains host gateway name and a predefined integer value
248 struct TSecurityType2 : public NLNET::TSecurityData
250 string SecurityGatewayName;
251 uint32 IntegerValue;
253 TSecurityType2(const TCtorParam &param)
254 : NLNET::TSecurityData(param)
256 IntegerValue = 0x12345678;
259 void serial(NLMISC::CMemStream &s)
261 s.serial(SecurityGatewayName);
262 s.serial(IntegerValue);
266 NLMISC_REGISTER_OBJECT(NLNET::TSecurityData, TSecurityType2, uint8, tst_type2);
269 // security type 3 data, same as type 1
270 struct TSecurityType3 : public NLNET::TSecurityData
272 string SecurityGatewayName;
274 TSecurityType3(const TCtorParam &param)
275 : NLNET::TSecurityData(param)
279 void serial(NLMISC::CMemStream &s)
281 s.serial(SecurityGatewayName);
285 NLMISC_REGISTER_OBJECT(NLNET::TSecurityData, TSecurityType3, uint8, tst_type3);
287 // security type 4 data, same as type 1 but not registered
288 struct TSecurityType4 : public NLNET::TSecurityData
290 string SecurityGatewayName;
292 TSecurityType4(const TCtorParam &param)
293 : NLNET::TSecurityData(param)
297 void serial(NLMISC::CMemStream &s)
299 s.serial(SecurityGatewayName);
303 /** a sample security plug-in that add type 1 security data to local modules,
304 * type 2 security to foreign module,
305 * and that remove received type 1 security from foreign module
307 class CTestSecurity1 : public NLNET::CGatewaySecurity
309 public:
310 CTestSecurity1(const TCtorParam &params)
311 : NLNET::CGatewaySecurity(params)
314 virtual void onNewProxy(NLNET::IModuleProxy *proxy)
316 if (proxy->getGatewayRoute() == NULL)
318 // add a type 1 security
319 TSecurityType1 *st1 = new TSecurityType1(NLNET::TSecurityData::TCtorParam(tst_type1));
320 st1->SecurityGatewayName = _Gateway->getFullyQualifiedGatewayName();
322 setSecurityData(proxy, st1);
324 else
326 // remove any type 1 data and set a type 2 data
327 removeSecurityData(proxy, tst_type1);
328 TSecurityType2 *st2 = new TSecurityType2(NLNET::TSecurityData::TCtorParam(tst_type2));
329 st2->SecurityGatewayName = _Gateway->getFullyQualifiedGatewayName();
331 setSecurityData(proxy, st2);
334 forceSecurityUpdate(proxy);
337 void onNewSecurityData(NLNET::CGatewayRoute *from, NLNET::IModuleProxy *proxy, NLNET::TSecurityData *firstSecurityData)
339 // replace the complete security set
340 replaceAllSecurityDatas(proxy, firstSecurityData);
341 // remove any type 1 data and set a type 2 data
342 removeSecurityData(proxy, tst_type1);
343 TSecurityType2 *st2 = new TSecurityType2(NLNET::TSecurityData::TCtorParam(tst_type2));
344 st2->SecurityGatewayName = _Gateway->getFullyQualifiedGatewayName();
346 setSecurityData(proxy, st2);
348 // we don't need to update in this case (update is always done by gateway)
351 virtual void onDelete()
353 vector<NLNET::IModuleProxy*> proxies;
354 _Gateway->getModuleProxyList(proxies);
356 // remove any security data managed by this plug-in
357 for (uint i=0; i<proxies.size(); ++i)
359 NLNET::IModuleProxy *proxy = proxies[i];
360 if (proxy->getFirstSecurityData() != NULL)
362 bool update = false;
363 update |= removeSecurityData(proxy, tst_type1);
364 update |= removeSecurityData(proxy, tst_type2);
365 if (update)
366 forceSecurityUpdate(proxy);
372 NLMISC_REGISTER_OBJECT(NLNET::CGatewaySecurity, CTestSecurity1, std::string, "TestSecurity1");
374 /** a sample security plug-in that add type 3 and type 4 security data to local modules,
376 class CTestSecurity2 : public NLNET::CGatewaySecurity
378 public:
379 CTestSecurity2(const TCtorParam &params)
380 : NLNET::CGatewaySecurity(params)
383 virtual void onNewProxy(NLNET::IModuleProxy *proxy)
385 if (proxy->getGatewayRoute() == NULL)
387 // add a type 3 security
388 TSecurityType3 *st3 = new TSecurityType3(NLNET::TSecurityData::TCtorParam(tst_type3));
389 st3->SecurityGatewayName = _Gateway->getFullyQualifiedGatewayName();
390 setSecurityData(proxy, st3);
391 // add a type 4 security
392 TSecurityType4 *st4 = new TSecurityType4(NLNET::TSecurityData::TCtorParam(tst_type4));
393 st4->SecurityGatewayName = _Gateway->getFullyQualifiedGatewayName();
394 setSecurityData(proxy, st4);
395 forceSecurityUpdate(proxy);
399 void onNewSecurityData(NLNET::CGatewayRoute *from, NLNET::IModuleProxy *proxy, NLNET::TSecurityData *firstSecurityData)
401 // replace the complete security set
402 replaceAllSecurityDatas(proxy, firstSecurityData);
405 virtual void onDelete()
407 vector<NLNET::IModuleProxy*> proxies;
408 _Gateway->getModuleProxyList(proxies);
410 // remove any security data managed by this plug-in
411 for (uint i=0; i<proxies.size(); ++i)
413 NLNET::IModuleProxy *proxy = proxies[i];
414 if (proxy->getGatewayRoute() == NULL)
416 removeSecurityData(proxy, tst_type3);
417 removeSecurityData(proxy, tst_type4);
418 forceSecurityUpdate(proxy);
423 NLMISC_REGISTER_OBJECT(NLNET::CGatewaySecurity, CTestSecurity2, std::string, "TestSecurity2");
426 // A module interceptor
427 class CInterceptor : public NLNET::IModuleInterceptable
429 public:
430 string Name;
431 uint32 ModuleUpCalled;
432 uint32 ModuleDownCalled;
433 uint32 ProcessMessageCalled;
434 uint32 SecurityUpdateCalled;
436 CInterceptor(NLNET::IInterceptorRegistrar *registrar, const string &name)
437 : Name(name)
439 NLNET::IModuleInterceptable::registerInterceptor(registrar),
440 ModuleUpCalled = 0;
441 ModuleDownCalled = 0;
442 ProcessMessageCalled = 0;
443 SecurityUpdateCalled = 0;
446 virtual std::string buildModuleManifest() const
448 return Name;
451 virtual void onModuleUp(NLNET::IModuleProxy *moduleProxy)
453 ModuleUpCalled++;
456 virtual void onModuleDown(NLNET::IModuleProxy *moduleProxy)
458 ModuleDownCalled++;
461 virtual bool onProcessModuleMessage(NLNET::IModuleProxy *senderModuleProxy, const NLNET::CMessage &message)
463 ProcessMessageCalled++;
464 return false;
467 virtual void onModuleSecurityChange(NLNET::IModuleProxy *moduleProxy)
469 SecurityUpdateCalled++;
473 // Test suite for Modules class
474 class CUTNetModule : public Test::Suite
476 string _WorkingPath;
477 string _RestorePath;
479 public:
480 // utility to look for a specified proxy in a vector of proxy
481 // return true if the proxy if found
482 bool lookForModuleProxy(const vector<NLNET::IModuleProxy*> proxList, const std::string &modName)
484 for (uint i=0; i<proxList.size(); ++i)
486 if (proxList[i]->getModuleName().find(modName) == (proxList[i]->getModuleName().size() - modName.size()))
487 return true;
490 return false;
493 NLNET::IModuleProxy *retrieveModuleProxy(NLNET::IModuleGateway *gw, const std::string &modName)
495 vector<NLNET::IModuleProxy*> proxList;
496 gw->getModuleProxyList(proxList);
498 for (uint i=0; i<proxList.size(); ++i)
500 if (proxList[i]->getModuleName().find(modName) == (proxList[i]->getModuleName().size() - modName.size()))
501 return proxList[i];
504 return NULL;
507 void setup()
509 _RestorePath = NLMISC::CPath::getCurrentPath();
511 NLMISC::CPath::setCurrentPath(_WorkingPath.c_str());
514 void tear_down()
516 NLMISC::CPath::setCurrentPath(_RestorePath.c_str());
519 CUTNetModule ()
521 TEST_ADD(CUTNetModule::testModuleInitInfoParsing);
522 TEST_ADD(CUTNetModule::testModuleInitInfoQuering);
523 TEST_ADD(CUTNetModule::testModuleInitInfoBadParsing);
524 TEST_ADD(CUTNetModule::localModuleFactory);
525 //TEST_ADD(CUTNetModule::loadModuleLib);
526 //TEST_ADD(CUTNetModule::createModule);
527 //TEST_ADD(CUTNetModule::deleteModule);
528 TEST_ADD(CUTNetModule::failedInit);
529 //TEST_ADD(CUTNetModule::unloadModuleLib);
530 TEST_ADD(CUTNetModule::createLocalGateway);
531 TEST_ADD(CUTNetModule::plugLocalGateway);
532 //TEST_ADD(CUTNetModule::moduleManagerCommands);
533 TEST_ADD(CUTNetModule::gatewayTransportManagement);
534 TEST_ADD(CUTNetModule::connectGateways);
535 TEST_ADD(CUTNetModule::moduleDisclosure);
536 TEST_ADD(CUTNetModule::moduleMessaging);
537 TEST_ADD(CUTNetModule::localMessageQueing);
538 TEST_ADD(CUTNetModule::uniqueNameGenerator);
539 TEST_ADD(CUTNetModule::gwPlugUnplug);
540 TEST_ADD(CUTNetModule::peerInvisible);
541 TEST_ADD(CUTNetModule::firewalling);
542 TEST_ADD(CUTNetModule::distanceAndConnectionLoop);
543 TEST_ADD(CUTNetModule::securityPlugin);
544 TEST_ADD(CUTNetModule::synchronousMessaging);
545 TEST_ADD(CUTNetModule::layer3Autoconnect);
546 TEST_ADD(CUTNetModule::interceptorTest);
549 void interceptorTest()
551 // Check that the interceptor system.
553 // TODO : right now, there is no test of the security update call
555 NLNET::IModuleManager &mm = NLNET::IModuleManager::getInstance();
556 NLMISC::CCommandRegistry &cr = NLMISC::CCommandRegistry::getInstance();
558 // create the modules
559 NLNET::IModule *gw = mm.createModule("StandardGateway", "gw", "");
560 NLNET::IModule *mod = mm.createModule("ModuleType0", "mod", "");
561 NLNET::IModuleGateway *gGw = dynamic_cast<NLNET::IModuleGateway *>(gw);
562 CModuleType0 *mod0 = dynamic_cast<CModuleType0*>(mod);
564 TEST_ASSERT(gGw != NULL);
565 TEST_ASSERT(mod0 != NULL);
567 // create the interceptors and attach it to the mod0
568 CInterceptor *inter0 = new CInterceptor(mod, "Inter0");
569 CInterceptor *inter1 = new CInterceptor(mod, "Inter1");
571 // plug the modules
572 cr.execute("gw.plug gw", NLMISC::InfoLog());
573 cr.execute("mod.plug gw", NLMISC::InfoLog());
575 // update the network
576 for (uint i=0; i<5; ++i)
578 mm.updateModules();
579 NLMISC::nlSleep(40);
582 // send a message to the module fro; the gateway
583 NLNET::CMessage msg("foo");
584 NLNET::IModuleProxy *modProx = retrieveModuleProxy(gGw, "mod");
585 TEST_ASSERT(modProx != NULL);
586 modProx->sendModuleMessage(gw, msg);
588 // update the network
589 for (uint i=0; i<5; ++i)
591 mm.updateModules();
592 NLMISC::nlSleep(40);
595 // check the module manifest
596 TEST_ASSERT(modProx->getModuleManifest() == "CModuleType0 Inter0 Inter1");
598 // unplug the modules
599 cr.execute("gw.unplug gw", NLMISC::InfoLog());
600 cr.execute("mod.unplug gw", NLMISC::InfoLog());
602 // update the network
603 for (uint i=0; i<5; ++i)
605 mm.updateModules();
606 NLMISC::nlSleep(40);
609 // now check that all methods have been called in that
610 // module and in the two interceptors,
611 // also check the manifest string content.
612 TEST_ASSERT(mod0->ModuleUpCalled == 1);
613 TEST_ASSERT(mod0->ModuleDownCalled == 1);
614 TEST_ASSERT(mod0->ProcessMessageCalled == 1);
615 // TEST_ASSERT(mod0->SecurityUpdateCalled);
617 TEST_ASSERT(inter0->ModuleUpCalled == 1);
618 TEST_ASSERT(inter0->ModuleDownCalled == 1);
619 TEST_ASSERT(inter0->ProcessMessageCalled == 1);
620 // TEST_ASSERT(inter0->SecurityUpdateCalled);
622 TEST_ASSERT(inter1->ModuleUpCalled == 1);
623 TEST_ASSERT(inter1->ModuleDownCalled == 1);
624 TEST_ASSERT(inter1->ProcessMessageCalled == 1);
625 // TEST_ASSERT(inter1->SecurityUpdateCalled);
628 // delete the modules
629 mm.deleteModule(gw);
630 mm.deleteModule(mod);
632 // delete the interceptors
633 delete inter0;
634 delete inter1;
637 void layer3Autoconnect()
639 // Check that layer 3 client can automatically reconnect in case of server
640 // down/up
642 // We create two gateway, gw1 and gw2, plugged in themselves, then we create
643 // a layer 3 client on gw1, update the network, then we create the layer 3 server
644 // on gw2, update the network then check that module are connected.
646 // Then we close the L3 server on gw2, update the network, check that module
647 // are diconnected and reopen the L3 server and recheck that module are connected.
652 NLNET::IModuleManager &mm = NLNET::IModuleManager::getInstance();
653 NLMISC::CCommandRegistry &cr = NLMISC::CCommandRegistry::getInstance();
655 // create the modules
656 NLNET::IModule *gw1 = mm.createModule("StandardGateway", "gw1", "");
657 NLNET::IModule *gw2 = mm.createModule("StandardGateway", "gw2", "");
658 NLNET::IModuleGateway *gGw1 = dynamic_cast<NLNET::IModuleGateway *>(gw1);
659 NLNET::IModuleGateway *gGw2 = dynamic_cast<NLNET::IModuleGateway *>(gw2);
661 // plug gateway in themselves
662 cr.execute("gw1.plug gw1", NLMISC::InfoLog());
663 cr.execute("gw2.plug gw2", NLMISC::InfoLog());
665 // create the client transport
666 cr.execute("gw1.transportAdd L3Client l3c", NLMISC::InfoLog());
667 cr.execute("gw1.transportCmd l3c(retryInterval=1)", NLMISC::InfoLog());
668 cr.execute("gw1.transportCmd l3c(connect addr=localhost:8062)", NLMISC::InfoLog());
670 // update the network
671 for (uint i=0; i<5; ++i)
673 mm.updateModules();
674 NLMISC::nlSleep(40);
677 TEST_ASSERT(retrieveModuleProxy(gGw1, "gw2") == NULL);
678 TEST_ASSERT(retrieveModuleProxy(gGw1, "gw2") == NULL);
680 // open the server
681 cr.execute("gw2.transportAdd L3Server l3s", NLMISC::InfoLog());
682 cr.execute("gw2.transportCmd l3s(open port=8062)", NLMISC::InfoLog());
684 // update the network (give more time because we must cover the Layer3 client reconnection timer)
685 for (uint i=0; i<40; ++i)
687 mm.updateModules();
688 NLMISC::nlSleep(50);
691 // check module connectivity
692 TEST_ASSERT(retrieveModuleProxy(gGw1, "gw2") != NULL);
693 TEST_ASSERT(retrieveModuleProxy(gGw1, "gw2") != NULL);
695 // exchange some message
696 cr.execute("gw1.sendPing "+gw2->getModuleFullyQualifiedName(), NLMISC::InfoLog());
697 cr.execute("gw2.sendPing "+gw1->getModuleFullyQualifiedName(), NLMISC::InfoLog());
699 // update the network
700 for (uint i=0; i<5; ++i)
702 mm.updateModules();
703 NLMISC::nlSleep(40);
706 // check the ping counter
707 TEST_ASSERT(gGw1->getReceivedPingCount() == 1);
708 TEST_ASSERT(gGw2->getReceivedPingCount() == 1);
710 // flood a little with ping
711 for (uint i=0; i<100; ++i)
712 cr.execute("gw1.sendPing "+gw2->getModuleFullyQualifiedName(), NLMISC::InfoLog());
714 // close the server
715 cr.execute("gw2.transportCmd l3s(close)", NLMISC::InfoLog());
717 // update the network
718 for (uint i=0; i<5; ++i)
720 mm.updateModules();
721 NLMISC::nlSleep(40);
724 // test no connectivity
725 TEST_ASSERT(retrieveModuleProxy(gGw1, "gw2") == NULL);
726 TEST_ASSERT(retrieveModuleProxy(gGw2, "gw1") == NULL);
728 // re-open the server
729 cr.execute("gw2.transportCmd l3s(open port=8062)", NLMISC::InfoLog());
731 // update the network (give more time because we must cover the Layer3 client reconnection timer)
732 for (uint i=0; i<40; ++i)
734 mm.updateModules();
735 NLMISC::nlSleep(50);
738 // check module connectivity
739 TEST_ASSERT(retrieveModuleProxy(gGw1, "gw2") != NULL);
740 TEST_ASSERT(retrieveModuleProxy(gGw2, "gw1") != NULL);
742 // exchange some message
743 cr.execute("gw1.sendPing "+gw2->getModuleFullyQualifiedName(), NLMISC::InfoLog());
744 cr.execute("gw2.sendPing "+gw1->getModuleFullyQualifiedName(), NLMISC::InfoLog());
746 // update the network
747 for (uint i=0; i<5; ++i)
749 mm.updateModules();
750 NLMISC::nlSleep(40);
753 // check the ping counter
754 TEST_ASSERT(gGw1->getReceivedPingCount() == 2);
755 TEST_ASSERT(gGw2->getReceivedPingCount() == 2);
757 // cleanup modules
758 mm.deleteModule(gw1);
759 mm.deleteModule(gw2);
762 void synchronousMessaging()
764 // check that the synchronous messaging is working
765 // by using module task
767 NLNET::IModuleManager &mm = NLNET::IModuleManager::getInstance();
768 NLMISC::CCommandRegistry &cr = NLMISC::CCommandRegistry::getInstance();
771 // create the modules
772 NLNET::IModule *gw = mm.createModule("StandardGateway", "gw", "");
773 NLNET::IModule *m1 = mm.createModule("ModuleType0", "m1", "");
774 NLNET::IModule *m2 = mm.createModule("ModuleType0", "m2", "");
776 // plug the two modules in the gateway
777 cr.execute("m1.plug gw", NLMISC::InfoLog());
778 cr.execute("m2.plug gw", NLMISC::InfoLog());
780 // update the network
781 for (uint i=0; i<15; ++i)
783 mm.updateModules();
784 NLMISC::nlSleep(40);
787 CModuleType0 *mod1 = dynamic_cast<CModuleType0 *>(m1);
789 // start a task on module 1
790 mod1->startTaskA();
792 // update the network
793 for (uint i=0; i<5; ++i)
795 mm.updateModules();
796 NLMISC::nlSleep(40);
800 TEST_ASSERT(mod1->PingCount == 4);
801 TEST_ASSERT(mod1->ResponseReceived == 1);
803 // start a task on module 1
804 mod1->startTaskB();
806 // update the network
807 for (uint i=0; i<5; ++i)
809 mm.updateModules();
810 NLMISC::nlSleep(40);
814 TEST_ASSERT(mod1->PingCount == 4);
815 TEST_ASSERT(mod1->ResponseReceived == 2);
816 mm.deleteModule(m1);
817 mm.deleteModule(m2);
818 mm.deleteModule(gw);
821 void securityPlugin()
823 // Check that security plug-in work well.
825 // We connect three gateway in series with the central gateway
826 // using a security module that adds security data to
827 // proxies :
828 // For local proxies, it adds type 1 security data
829 // For foreign proxies, it adds type 2 security data
830 // for foreign proxies, it removes any type 1 security data found
832 // gw1 (l3c) -------- (l3s) gw2 (l3c) ------ (l3s) gw3
833 // ^ ^
834 // | |
835 // SecurityPlugin2 SecurityPlugin1
837 // After connecting and plugging-in each gateway into themselves,
838 // we check the presence and content of the security datas.
839 // then we remove the securityPlugin1 and check that all
840 // security data have been removed,
841 // Then, we re create the securityPlugin1 and recheck
842 // then one again, we remove it and recheck.
844 // For the second part of the check, we create a security
845 // plug-in 2 on gw1 that add 'type3' security data on
846 // local plug-in.
847 // We also plug the security plug-in 1 and then we check that
848 // we have the correct security data
850 NLNET::IModuleManager &mm = NLNET::IModuleManager::getInstance();
851 NLMISC::CCommandRegistry &cr = NLMISC::CCommandRegistry::getInstance();
853 NLNET::IModule *gw1, *gw2, *gw3;
855 // create the modules
856 gw1 = mm.createModule("StandardGateway", "gw1", "");
857 gw2 = mm.createModule("StandardGateway", "gw2", "");
858 gw3 = mm.createModule("StandardGateway", "gw3", "");
860 TEST_ASSERT(gw1 != NULL);
861 TEST_ASSERT(gw2 != NULL);
862 TEST_ASSERT(gw3 != NULL);
864 // plug gateway in themselves
865 NLNET::IModuleSocket *sGw1, *sGw2, *sGw3;
866 sGw1 = mm.getModuleSocket("gw1");
867 sGw2 = mm.getModuleSocket("gw2");
868 sGw3 = mm.getModuleSocket("gw3");
870 TEST_ASSERT(sGw1 != NULL);
871 TEST_ASSERT(sGw2 != NULL);
872 TEST_ASSERT(sGw3 != NULL);
874 gw1->plugModule(sGw1);
875 gw2->plugModule(sGw2);
876 gw3->plugModule(sGw3);
878 string cmd;
879 // create security plug-in
880 cmd = "gw2.securityCreate TestSecurity1";
881 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
883 // create the transports
884 cmd = "gw1.transportAdd L3Client l3c";
885 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
886 cmd = "gw2.transportAdd L3Client l3c";
887 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
888 cmd = "gw2.transportAdd L3Server l3s";
889 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
890 cmd = "gw3.transportAdd L3Server l3s";
891 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
893 // connect transport
894 cmd = "gw2.transportCmd l3s(open port=8062)";
895 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
896 cmd = "gw3.transportCmd l3s(open port=8063)";
897 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
898 cmd = "gw1.transportCmd l3c(connect addr=localhost:8062)";
899 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
900 cmd = "gw2.transportCmd l3c(connect addr=localhost:8063)";
901 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
904 for (uint retry = 0; retry < 2; ++retry)
906 if (retry > 0)
908 // recreate the security plug-in
909 cmd = "gw2.securityCreate TestSecurity1";
910 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
912 // update the network
913 for (uint i=0; i<15; ++i)
915 mm.updateModules();
916 NLMISC::nlSleep(40);
918 NLNET::IModuleGateway *gGw1, *gGw2, *gGw3;
919 gGw1 = dynamic_cast<NLNET::IModuleGateway *>(gw1);
920 TEST_ASSERT(gGw1 != NULL);
921 gGw2 = dynamic_cast<NLNET::IModuleGateway *>(gw2);
922 TEST_ASSERT(gGw2 != NULL);
923 gGw3 = dynamic_cast<NLNET::IModuleGateway *>(gw3);
924 TEST_ASSERT(gGw3 != NULL);
927 // check security data
928 NLNET::IModuleProxy *proxGw1_1, *proxGw2_1, *proxGw3_1;
929 NLNET::IModuleProxy *proxGw1_2, *proxGw2_2, *proxGw3_2;
930 NLNET::IModuleProxy *proxGw1_3, *proxGw2_3, *proxGw3_3;
932 proxGw1_1 = retrieveModuleProxy(gGw1, "gw1");
933 proxGw2_1 = retrieveModuleProxy(gGw1, "gw2");
934 proxGw3_1 = retrieveModuleProxy(gGw1, "gw3");
935 proxGw1_2 = retrieveModuleProxy(gGw2, "gw1");
936 proxGw2_2 = retrieveModuleProxy(gGw2, "gw2");
937 proxGw3_2 = retrieveModuleProxy(gGw2, "gw3");
938 proxGw1_3 = retrieveModuleProxy(gGw3, "gw1");
939 proxGw2_3 = retrieveModuleProxy(gGw3, "gw2");
940 proxGw3_3 = retrieveModuleProxy(gGw3, "gw3");
942 TEST_ASSERT(proxGw1_1 != NULL);
943 TEST_ASSERT(proxGw2_1 != NULL);
944 TEST_ASSERT(proxGw3_1 != NULL);
945 TEST_ASSERT(proxGw1_2 != NULL);
946 TEST_ASSERT(proxGw2_2 != NULL);
947 TEST_ASSERT(proxGw3_2 != NULL);
948 TEST_ASSERT(proxGw1_3 != NULL);
949 TEST_ASSERT(proxGw2_3 != NULL);
950 TEST_ASSERT(proxGw3_3 != NULL);
952 const NLNET::TSecurityData *ms;
953 const TSecurityType1 *st1;
954 const TSecurityType2 *st2;
956 ms = proxGw1_1->getFirstSecurityData();
957 TEST_ASSERT(ms == NULL);
959 ms = proxGw1_2->getFirstSecurityData();
960 TEST_ASSERT(ms != NULL);
961 TEST_ASSERT(ms->DataTag == tst_type2);
962 st2 = dynamic_cast<const TSecurityType2 *>(ms);
963 TEST_ASSERT(st2 != NULL);
964 TEST_ASSERT(st2->SecurityGatewayName == gw2->getModuleFullyQualifiedName());
965 TEST_ASSERT(st2->IntegerValue == 0x12345678);
966 TEST_ASSERT(st2->NextItem == NULL);
968 ms = proxGw1_3->getFirstSecurityData();
969 TEST_ASSERT(ms != NULL);
970 TEST_ASSERT(ms->DataTag == tst_type2);
971 st2 = dynamic_cast<const TSecurityType2 *>(ms);
972 TEST_ASSERT(st2 != NULL);
973 TEST_ASSERT(st2->SecurityGatewayName == gw2->getModuleFullyQualifiedName());
974 TEST_ASSERT(st2->IntegerValue == 0x12345678);
975 TEST_ASSERT(st2->NextItem == NULL);
977 ms = proxGw2_1->getFirstSecurityData();
978 TEST_ASSERT(ms != NULL);
979 TEST_ASSERT(ms->DataTag == tst_type1);
980 st1 = dynamic_cast<const TSecurityType1 *>(ms);
981 TEST_ASSERT(st1 != NULL);
982 TEST_ASSERT(st1->SecurityGatewayName == gw2->getModuleFullyQualifiedName());
983 TEST_ASSERT(st1->NextItem == NULL);
985 ms = proxGw2_2->getFirstSecurityData();
986 TEST_ASSERT(ms != NULL);
987 TEST_ASSERT(ms->DataTag == tst_type1);
988 st1 = dynamic_cast<const TSecurityType1 *>(ms);
989 TEST_ASSERT(st1 != NULL);
990 TEST_ASSERT(st1->SecurityGatewayName == gw2->getModuleFullyQualifiedName());
991 TEST_ASSERT(st1->NextItem == NULL);
993 ms = proxGw2_3->getFirstSecurityData();
994 TEST_ASSERT(ms != NULL);
995 TEST_ASSERT(ms->DataTag == tst_type1);
996 st1 = dynamic_cast<const TSecurityType1 *>(ms);
997 TEST_ASSERT(st1 != NULL);
998 TEST_ASSERT(st1->SecurityGatewayName == gw2->getModuleFullyQualifiedName());
999 TEST_ASSERT(st1->NextItem == NULL);
1001 ms = proxGw3_1->getFirstSecurityData();
1002 TEST_ASSERT(ms != NULL);
1003 TEST_ASSERT(ms->DataTag == tst_type2);
1004 st2 = dynamic_cast<const TSecurityType2 *>(ms);
1005 TEST_ASSERT(st2 != NULL);
1006 TEST_ASSERT(st2->SecurityGatewayName == gw2->getModuleFullyQualifiedName());
1007 TEST_ASSERT(st2->IntegerValue == 0x12345678);
1008 TEST_ASSERT(st2->NextItem == NULL);
1010 ms = proxGw3_2->getFirstSecurityData();
1011 TEST_ASSERT(ms != NULL);
1012 TEST_ASSERT(ms->DataTag == tst_type2);
1013 st2 = dynamic_cast<const TSecurityType2 *>(ms);
1014 TEST_ASSERT(st2 != NULL);
1015 TEST_ASSERT(st2->SecurityGatewayName == gw2->getModuleFullyQualifiedName());
1016 TEST_ASSERT(st2->IntegerValue == 0x12345678);
1017 TEST_ASSERT(st2->NextItem == NULL);
1019 ms = proxGw3_3->getFirstSecurityData();
1020 TEST_ASSERT(ms == NULL);
1022 // remove the security plug-in
1023 // create security plug-in
1024 cmd = "gw2.securityRemove";
1025 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1027 // update the network
1028 for (uint i=0; i<15; ++i)
1030 mm.updateModules();
1031 NLMISC::nlSleep(40);
1034 ms = proxGw1_1->getFirstSecurityData();
1035 TEST_ASSERT(ms == NULL);
1036 ms = proxGw1_2->getFirstSecurityData();
1037 TEST_ASSERT(ms == NULL);
1038 ms = proxGw1_3->getFirstSecurityData();
1039 TEST_ASSERT(ms == NULL);
1040 ms = proxGw2_1->getFirstSecurityData();
1041 TEST_ASSERT(ms == NULL);
1042 ms = proxGw2_2->getFirstSecurityData();
1043 TEST_ASSERT(ms == NULL);
1044 ms = proxGw2_3->getFirstSecurityData();
1045 TEST_ASSERT(ms == NULL);
1046 ms = proxGw3_1->getFirstSecurityData();
1047 TEST_ASSERT(ms == NULL);
1048 ms = proxGw3_2->getFirstSecurityData();
1049 TEST_ASSERT(ms == NULL);
1050 ms = proxGw3_3->getFirstSecurityData();
1051 TEST_ASSERT(ms == NULL);
1054 // part 2
1055 // create the security plug-in
1056 cmd = "gw2.securityCreate TestSecurity1";
1057 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1058 cmd = "gw1.securityCreate TestSecurity2";
1059 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1061 // update the network
1062 for (uint i=0; i<15; ++i)
1064 mm.updateModules();
1065 NLMISC::nlSleep(40);
1068 NLNET::IModuleGateway *gGw1, *gGw2, *gGw3;
1069 gGw1 = dynamic_cast<NLNET::IModuleGateway *>(gw1);
1070 TEST_ASSERT(gGw1 != NULL);
1071 gGw2 = dynamic_cast<NLNET::IModuleGateway *>(gw2);
1072 TEST_ASSERT(gGw2 != NULL);
1073 gGw3 = dynamic_cast<NLNET::IModuleGateway *>(gw3);
1074 TEST_ASSERT(gGw3 != NULL);
1077 // check security data
1078 NLNET::IModuleProxy *proxGw1_1, *proxGw2_1, *proxGw3_1;
1079 NLNET::IModuleProxy *proxGw1_2, *proxGw2_2, *proxGw3_2;
1080 NLNET::IModuleProxy *proxGw1_3, *proxGw2_3, *proxGw3_3;
1082 proxGw1_1 = retrieveModuleProxy(gGw1, "gw1");
1083 proxGw2_1 = retrieveModuleProxy(gGw1, "gw2");
1084 proxGw3_1 = retrieveModuleProxy(gGw1, "gw3");
1085 proxGw1_2 = retrieveModuleProxy(gGw2, "gw1");
1086 proxGw2_2 = retrieveModuleProxy(gGw2, "gw2");
1087 proxGw3_2 = retrieveModuleProxy(gGw2, "gw3");
1088 proxGw1_3 = retrieveModuleProxy(gGw3, "gw1");
1089 proxGw2_3 = retrieveModuleProxy(gGw3, "gw2");
1090 proxGw3_3 = retrieveModuleProxy(gGw3, "gw3");
1092 TEST_ASSERT(proxGw1_1 != NULL);
1093 TEST_ASSERT(proxGw2_1 != NULL);
1094 TEST_ASSERT(proxGw3_1 != NULL);
1095 TEST_ASSERT(proxGw1_2 != NULL);
1096 TEST_ASSERT(proxGw2_2 != NULL);
1097 TEST_ASSERT(proxGw3_2 != NULL);
1098 TEST_ASSERT(proxGw1_3 != NULL);
1099 TEST_ASSERT(proxGw2_3 != NULL);
1100 TEST_ASSERT(proxGw3_3 != NULL);
1102 const NLNET::TSecurityData *ms;
1103 // const TSecurityType1 *st1;
1104 // const TSecurityType2 *st2;
1106 ms = proxGw1_1->findSecurityData(tst_type1);
1107 TEST_ASSERT(ms == NULL);
1108 ms = proxGw1_1->findSecurityData(tst_type2);
1109 TEST_ASSERT(ms == NULL);
1110 ms = proxGw1_1->findSecurityData(tst_type3);
1111 TEST_ASSERT(ms != NULL);
1112 ms = proxGw1_1->findSecurityData(tst_type4);
1113 TEST_ASSERT(ms != NULL);
1114 TEST_ASSERT(dynamic_cast<const TSecurityType4*>(ms) != NULL);
1116 ms = proxGw1_2->findSecurityData(tst_type1);
1117 TEST_ASSERT(ms == NULL);
1118 ms = proxGw1_2->findSecurityData(tst_type2);
1119 TEST_ASSERT(ms != NULL);
1120 ms = proxGw1_2->findSecurityData(tst_type3);
1121 TEST_ASSERT(ms != NULL);
1122 ms = proxGw1_2->findSecurityData(0xff);
1123 TEST_ASSERT(ms != NULL);
1124 TEST_ASSERT(dynamic_cast<const NLNET::TUnknownSecurityData*>(ms) != NULL);
1126 ms = proxGw1_3->findSecurityData(tst_type1);
1127 TEST_ASSERT(ms == NULL);
1128 ms = proxGw1_3->findSecurityData(tst_type2);
1129 TEST_ASSERT(ms != NULL);
1130 ms = proxGw1_3->findSecurityData(tst_type3);
1131 TEST_ASSERT(ms != NULL);
1132 ms = proxGw1_3->findSecurityData(0xff);
1133 TEST_ASSERT(ms != NULL);
1134 TEST_ASSERT(dynamic_cast<const NLNET::TUnknownSecurityData*>(ms) != NULL);
1137 ms = proxGw2_1->findSecurityData(tst_type1);
1138 TEST_ASSERT(ms != NULL);
1139 ms = proxGw2_1->findSecurityData(tst_type2);
1140 TEST_ASSERT(ms == NULL);
1141 ms = proxGw2_1->findSecurityData(tst_type3);
1142 TEST_ASSERT(ms == NULL);
1143 ms = proxGw2_1->findSecurityData(tst_type4);
1144 TEST_ASSERT(ms == NULL);
1146 ms = proxGw2_2->findSecurityData(tst_type1);
1147 TEST_ASSERT(ms != NULL);
1148 ms = proxGw2_2->findSecurityData(tst_type2);
1149 TEST_ASSERT(ms == NULL);
1150 ms = proxGw2_2->findSecurityData(tst_type3);
1151 TEST_ASSERT(ms == NULL);
1152 ms = proxGw2_2->findSecurityData(tst_type4);
1153 TEST_ASSERT(ms == NULL);
1155 ms = proxGw2_3->findSecurityData(tst_type1);
1156 TEST_ASSERT(ms != NULL);
1157 ms = proxGw2_3->findSecurityData(tst_type2);
1158 TEST_ASSERT(ms == NULL);
1159 ms = proxGw2_3->findSecurityData(tst_type3);
1160 TEST_ASSERT(ms == NULL);
1161 ms = proxGw2_3->findSecurityData(tst_type4);
1162 TEST_ASSERT(ms == NULL);
1165 ms = proxGw3_1->findSecurityData(tst_type1);
1166 TEST_ASSERT(ms == NULL);
1167 ms = proxGw3_1->findSecurityData(tst_type2);
1168 TEST_ASSERT(ms != NULL);
1169 ms = proxGw3_1->findSecurityData(tst_type3);
1170 TEST_ASSERT(ms == NULL);
1171 ms = proxGw3_1->findSecurityData(tst_type4);
1172 TEST_ASSERT(ms == NULL);
1174 ms = proxGw3_2->findSecurityData(tst_type1);
1175 TEST_ASSERT(ms == NULL);
1176 ms = proxGw3_2->findSecurityData(tst_type2);
1177 TEST_ASSERT(ms != NULL);
1178 ms = proxGw3_2->findSecurityData(tst_type3);
1179 TEST_ASSERT(ms == NULL);
1180 ms = proxGw3_2->findSecurityData(tst_type4);
1181 TEST_ASSERT(ms == NULL);
1183 ms = proxGw3_3->findSecurityData(tst_type1);
1184 TEST_ASSERT(ms == NULL);
1185 ms = proxGw3_3->findSecurityData(tst_type2);
1186 TEST_ASSERT(ms == NULL);
1187 ms = proxGw3_3->findSecurityData(tst_type3);
1188 TEST_ASSERT(ms == NULL);
1189 ms = proxGw3_3->findSecurityData(tst_type4);
1190 TEST_ASSERT(ms == NULL);
1192 // remove the security plug-in
1193 // create security plug-in
1194 cmd = "gw1.securityRemove";
1195 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1197 // update the network
1198 for (uint i=0; i<15; ++i)
1200 mm.updateModules();
1201 NLMISC::nlSleep(40);
1204 ms = proxGw1_1->findSecurityData(tst_type1);
1205 TEST_ASSERT(ms == NULL);
1206 ms = proxGw1_1->findSecurityData(tst_type2);
1207 TEST_ASSERT(ms == NULL);
1208 ms = proxGw1_1->findSecurityData(tst_type3);
1209 TEST_ASSERT(ms == NULL);
1210 ms = proxGw1_1->findSecurityData(tst_type4);
1211 TEST_ASSERT(ms == NULL);
1213 ms = proxGw1_2->findSecurityData(tst_type1);
1214 TEST_ASSERT(ms == NULL);
1215 ms = proxGw1_2->findSecurityData(tst_type2);
1216 TEST_ASSERT(ms != NULL);
1217 ms = proxGw1_2->findSecurityData(tst_type3);
1218 TEST_ASSERT(ms == NULL);
1219 ms = proxGw1_2->findSecurityData(tst_type4);
1220 TEST_ASSERT(ms == NULL);
1222 ms = proxGw1_3->findSecurityData(tst_type1);
1223 TEST_ASSERT(ms == NULL);
1224 ms = proxGw1_3->findSecurityData(tst_type2);
1225 TEST_ASSERT(ms != NULL);
1226 ms = proxGw1_3->findSecurityData(tst_type3);
1227 TEST_ASSERT(ms == NULL);
1228 ms = proxGw1_3->findSecurityData(tst_type4);
1229 TEST_ASSERT(ms == NULL);
1232 ms = proxGw2_1->findSecurityData(tst_type1);
1233 TEST_ASSERT(ms != NULL);
1234 ms = proxGw2_1->findSecurityData(tst_type2);
1235 TEST_ASSERT(ms == NULL);
1236 ms = proxGw2_1->findSecurityData(tst_type3);
1237 TEST_ASSERT(ms == NULL);
1238 ms = proxGw2_1->findSecurityData(tst_type4);
1239 TEST_ASSERT(ms == NULL);
1241 ms = proxGw2_2->findSecurityData(tst_type1);
1242 TEST_ASSERT(ms != NULL);
1243 ms = proxGw2_2->findSecurityData(tst_type2);
1244 TEST_ASSERT(ms == NULL);
1245 ms = proxGw2_2->findSecurityData(tst_type3);
1246 TEST_ASSERT(ms == NULL);
1247 ms = proxGw2_2->findSecurityData(tst_type4);
1248 TEST_ASSERT(ms == NULL);
1250 ms = proxGw2_3->findSecurityData(tst_type1);
1251 TEST_ASSERT(ms != NULL);
1252 ms = proxGw2_3->findSecurityData(tst_type2);
1253 TEST_ASSERT(ms == NULL);
1254 ms = proxGw2_3->findSecurityData(tst_type3);
1255 TEST_ASSERT(ms == NULL);
1256 ms = proxGw2_3->findSecurityData(tst_type4);
1257 TEST_ASSERT(ms == NULL);
1260 ms = proxGw3_1->findSecurityData(tst_type1);
1261 TEST_ASSERT(ms == NULL);
1262 ms = proxGw3_1->findSecurityData(tst_type2);
1263 TEST_ASSERT(ms != NULL);
1264 ms = proxGw3_1->findSecurityData(tst_type3);
1265 TEST_ASSERT(ms == NULL);
1266 ms = proxGw3_1->findSecurityData(tst_type4);
1267 TEST_ASSERT(ms == NULL);
1269 ms = proxGw3_2->findSecurityData(tst_type1);
1270 TEST_ASSERT(ms == NULL);
1271 ms = proxGw3_2->findSecurityData(tst_type2);
1272 TEST_ASSERT(ms != NULL);
1273 ms = proxGw3_2->findSecurityData(tst_type3);
1274 TEST_ASSERT(ms == NULL);
1275 ms = proxGw3_2->findSecurityData(tst_type4);
1276 TEST_ASSERT(ms == NULL);
1278 ms = proxGw3_3->findSecurityData(tst_type1);
1279 TEST_ASSERT(ms == NULL);
1280 ms = proxGw3_3->findSecurityData(tst_type2);
1281 TEST_ASSERT(ms == NULL);
1282 ms = proxGw3_3->findSecurityData(tst_type3);
1283 TEST_ASSERT(ms == NULL);
1284 ms = proxGw3_3->findSecurityData(tst_type4);
1285 TEST_ASSERT(ms == NULL);
1287 // cleanup
1288 mm.deleteModule(gw1);
1289 mm.deleteModule(gw2);
1290 mm.deleteModule(gw3);
1293 void distanceAndConnectionLoop()
1295 // Check that we support a closed loop or multi connection
1296 // of gateway and that the gateway chooses the best
1297 // route to reach a module when more than one is possible
1298 // and that the distance is updated
1300 // For this test, we use the following context:
1301 // three gateway (gw1, gw2, gw3), each having a layer 3
1302 // server and client transport.
1303 // one gateway (gw4) having just a layer3 server
1304 // gw1 connects on gw2, gw2 connects on gw3, gw3 connects on gw4.
1305 // we check the module list and distance, then gw3 connects to gw1, closing
1306 // the loop.
1307 // we recheck module list and distance.
1308 // We then disconnect gw3 from gw1 and recheck module list and distance.
1310 // Finally, we create a second connection from gw1 to gw2 and
1311 // recheck module list and distances
1313 // /---<optional>---\
1314 // (l3s) gw1 (l3c) (l3s) gw2 (l3c) ------ (l3s) gw3 (l3c) ------ (l3s) gw4
1315 // | \----------------/ |
1316 // | |
1317 // | |
1318 // \------------------<optional>-----------------------------------/
1321 NLNET::IModuleManager &mm = NLNET::IModuleManager::getInstance();
1322 NLMISC::CCommandRegistry &cr = NLMISC::CCommandRegistry::getInstance();
1324 NLNET::IModule *gw1, *gw2, *gw3, *gw4;
1326 // create the modules
1327 gw1 = mm.createModule("StandardGateway", "gw1", "");
1328 gw2 = mm.createModule("StandardGateway", "gw2", "");
1329 gw3 = mm.createModule("StandardGateway", "gw3", "");
1330 gw4 = mm.createModule("StandardGateway", "gw4", "");
1332 TEST_ASSERT(gw1 != NULL);
1333 TEST_ASSERT(gw2 != NULL);
1334 TEST_ASSERT(gw3 != NULL);
1335 TEST_ASSERT(gw4 != NULL);
1337 // plug gateway into themselves
1338 NLNET::IModuleSocket *sGw1, *sGw2, *sGw3, *sGw4;
1339 sGw1 = mm.getModuleSocket("gw1");
1340 sGw2 = mm.getModuleSocket("gw2");
1341 sGw3 = mm.getModuleSocket("gw3");
1342 sGw4 = mm.getModuleSocket("gw4");
1344 TEST_ASSERT(sGw1 != NULL);
1345 TEST_ASSERT(sGw2 != NULL);
1346 TEST_ASSERT(sGw3 != NULL);
1347 TEST_ASSERT(sGw4 != NULL);
1349 gw1->plugModule(sGw1);
1350 gw2->plugModule(sGw2);
1351 gw3->plugModule(sGw3);
1352 gw4->plugModule(sGw4);
1354 string cmd;
1355 // create the transports
1356 cmd = "gw1.transportAdd L3Client l3c";
1357 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1358 cmd = "gw1.transportAdd L3Server l3s";
1359 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1360 cmd = "gw2.transportAdd L3Client l3c";
1361 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1362 cmd = "gw2.transportAdd L3Server l3s";
1363 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1364 cmd = "gw3.transportAdd L3Client l3c";
1365 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1366 cmd = "gw3.transportAdd L3Server l3s";
1367 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1368 cmd = "gw4.transportAdd L3Server l3s";
1369 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1371 // connect transport
1372 cmd = "gw1.transportCmd l3s(open port=8061)";
1373 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1374 cmd = "gw2.transportCmd l3s(open port=8062)";
1375 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1376 cmd = "gw3.transportCmd l3s(open port=8063)";
1377 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1378 cmd = "gw4.transportCmd l3s(open port=8064)";
1379 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1380 cmd = "gw1.transportCmd l3c(connect addr=localhost:8062)";
1381 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1382 cmd = "gw2.transportCmd l3c(connect addr=localhost:8063)";
1383 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1384 cmd = "gw3.transportCmd l3c(connect addr=localhost:8064)";
1385 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1387 // update the network
1388 for (uint i=0; i<15; ++i)
1390 mm.updateModules();
1391 NLMISC::nlSleep(40);
1394 // check the modules list
1395 // ok, now, check that each gateways know the gateway it must know
1396 NLNET::IModuleGateway *gGw1, *gGw2, *gGw3, *gGw4;
1397 gGw1 = dynamic_cast<NLNET::IModuleGateway *>(gw1);
1398 TEST_ASSERT(gGw1 != NULL);
1399 gGw2 = dynamic_cast<NLNET::IModuleGateway *>(gw2);
1400 TEST_ASSERT(gGw2 != NULL);
1401 gGw3 = dynamic_cast<NLNET::IModuleGateway *>(gw3);
1402 TEST_ASSERT(gGw3 != NULL);
1403 gGw4 = dynamic_cast<NLNET::IModuleGateway *>(gw4);
1404 TEST_ASSERT(gGw4 != NULL);
1406 vector<NLNET::IModuleProxy*> proxList;
1407 gGw1->getModuleProxyList(proxList);
1408 TEST_ASSERT(proxList.size() == 4);
1409 proxList.clear();
1410 gGw2->getModuleProxyList(proxList);
1411 TEST_ASSERT(proxList.size() == 4);
1412 proxList.clear();
1413 gGw3->getModuleProxyList(proxList);
1414 TEST_ASSERT(proxList.size() == 4);
1415 proxList.clear();
1416 gGw4->getModuleProxyList(proxList);
1417 TEST_ASSERT(proxList.size() == 4);
1419 // check the distance
1420 NLNET::IModuleProxy *gw1_1Prox, *gw1_2Prox, *gw1_3Prox, *gw1_4Prox;
1421 NLNET::IModuleProxy *gw2_1Prox, *gw2_2Prox, *gw2_3Prox, *gw2_4Prox;
1422 NLNET::IModuleProxy *gw3_1Prox, *gw3_2Prox, *gw3_3Prox, *gw3_4Prox;
1423 NLNET::IModuleProxy *gw4_1Prox, *gw4_2Prox, *gw4_3Prox, *gw4_4Prox;
1425 gw1_1Prox = retrieveModuleProxy(gGw1, "gw1");
1426 TEST_ASSERT(gw1_1Prox != NULL);
1427 TEST_ASSERT(gw1_1Prox->getModuleDistance() == 0);
1428 gw1_2Prox = retrieveModuleProxy(gGw2, "gw1");
1429 TEST_ASSERT(gw1_2Prox != NULL);
1430 TEST_ASSERT(gw1_2Prox->getModuleDistance() == 1);
1431 gw1_3Prox = retrieveModuleProxy(gGw3, "gw1");
1432 TEST_ASSERT(gw1_3Prox != NULL);
1433 TEST_ASSERT(gw1_3Prox->getModuleDistance() == 2);
1434 gw1_4Prox = retrieveModuleProxy(gGw4, "gw1");
1435 TEST_ASSERT(gw1_4Prox != NULL);
1436 TEST_ASSERT(gw1_4Prox->getModuleDistance() == 3);
1438 gw2_1Prox = retrieveModuleProxy(gGw1, "gw2");
1439 TEST_ASSERT(gw2_1Prox != NULL);
1440 TEST_ASSERT(gw2_1Prox->getModuleDistance() == 1);
1441 gw2_2Prox = retrieveModuleProxy(gGw2, "gw2");
1442 TEST_ASSERT(gw2_2Prox != NULL);
1443 TEST_ASSERT(gw2_2Prox->getModuleDistance() == 0);
1444 gw2_3Prox = retrieveModuleProxy(gGw3, "gw2");
1445 TEST_ASSERT(gw2_3Prox != NULL);
1446 TEST_ASSERT(gw2_3Prox->getModuleDistance() == 1);
1447 gw2_4Prox = retrieveModuleProxy(gGw4, "gw2");
1448 TEST_ASSERT(gw2_4Prox != NULL);
1449 TEST_ASSERT(gw2_4Prox->getModuleDistance() == 2);
1451 gw3_1Prox = retrieveModuleProxy(gGw1, "gw3");
1452 TEST_ASSERT(gw3_1Prox != NULL);
1453 TEST_ASSERT(gw3_1Prox->getModuleDistance() == 2);
1454 gw3_2Prox = retrieveModuleProxy(gGw2, "gw3");
1455 TEST_ASSERT(gw3_2Prox != NULL);
1456 TEST_ASSERT(gw3_2Prox->getModuleDistance() == 1);
1457 gw3_3Prox = retrieveModuleProxy(gGw3, "gw3");
1458 TEST_ASSERT(gw3_3Prox != NULL);
1459 TEST_ASSERT(gw3_3Prox->getModuleDistance() == 0);
1460 gw3_4Prox = retrieveModuleProxy(gGw4, "gw3");
1461 TEST_ASSERT(gw3_4Prox != NULL);
1462 TEST_ASSERT(gw3_4Prox->getModuleDistance() == 1);
1464 gw4_1Prox = retrieveModuleProxy(gGw1, "gw4");
1465 TEST_ASSERT(gw4_1Prox != NULL);
1466 TEST_ASSERT(gw4_1Prox->getModuleDistance() == 3);
1467 gw4_2Prox = retrieveModuleProxy(gGw2, "gw4");
1468 TEST_ASSERT(gw4_2Prox != NULL);
1469 TEST_ASSERT(gw4_2Prox->getModuleDistance() == 2);
1470 gw4_3Prox = retrieveModuleProxy(gGw3, "gw4");
1471 TEST_ASSERT(gw4_3Prox != NULL);
1472 TEST_ASSERT(gw4_3Prox->getModuleDistance() == 1);
1473 gw4_4Prox = retrieveModuleProxy(gGw4, "gw4");
1474 TEST_ASSERT(gw4_4Prox != NULL);
1475 TEST_ASSERT(gw4_4Prox->getModuleDistance() == 0);
1477 // now, connect gw3 to gw1
1478 cmd = "gw3.transportCmd l3c(connect addr=localhost:8061)";
1479 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1481 // update the network
1482 for (uint i=0; i<7; ++i)
1484 mm.updateModules();
1485 NLMISC::nlSleep(100);
1488 // check module list
1489 proxList.clear();
1490 gGw1->getModuleProxyList(proxList);
1491 TEST_ASSERT(proxList.size() == 4);
1492 proxList.clear();
1493 gGw2->getModuleProxyList(proxList);
1494 TEST_ASSERT(proxList.size() == 4);
1495 proxList.clear();
1496 gGw3->getModuleProxyList(proxList);
1497 TEST_ASSERT(proxList.size() == 4);
1498 proxList.clear();
1499 gGw4->getModuleProxyList(proxList);
1500 TEST_ASSERT(proxList.size() == 4);
1502 // check the distances
1503 gw1_1Prox = retrieveModuleProxy(gGw1, "gw1");
1504 TEST_ASSERT(gw1_1Prox != NULL);
1505 TEST_ASSERT(gw1_1Prox->getModuleDistance() == 0);
1506 gw1_2Prox = retrieveModuleProxy(gGw2, "gw1");
1507 TEST_ASSERT(gw1_2Prox != NULL);
1508 TEST_ASSERT(gw1_2Prox->getModuleDistance() == 1);
1509 gw1_3Prox = retrieveModuleProxy(gGw3, "gw1");
1510 TEST_ASSERT(gw1_3Prox != NULL);
1511 TEST_ASSERT(gw1_3Prox->getModuleDistance() == 1);
1512 gw1_4Prox = retrieveModuleProxy(gGw4, "gw1");
1513 TEST_ASSERT(gw1_4Prox != NULL);
1514 TEST_ASSERT(gw1_4Prox->getModuleDistance() == 2);
1516 gw2_1Prox = retrieveModuleProxy(gGw1, "gw2");
1517 TEST_ASSERT(gw2_1Prox != NULL);
1518 TEST_ASSERT(gw2_1Prox->getModuleDistance() == 1);
1519 gw2_2Prox = retrieveModuleProxy(gGw2, "gw2");
1520 TEST_ASSERT(gw2_2Prox != NULL);
1521 TEST_ASSERT(gw2_2Prox->getModuleDistance() == 0);
1522 gw2_3Prox = retrieveModuleProxy(gGw3, "gw2");
1523 TEST_ASSERT(gw2_3Prox != NULL);
1524 TEST_ASSERT(gw2_3Prox->getModuleDistance() == 1);
1525 gw2_4Prox = retrieveModuleProxy(gGw4, "gw2");
1526 TEST_ASSERT(gw2_4Prox != NULL);
1527 TEST_ASSERT(gw2_4Prox->getModuleDistance() == 2);
1529 gw3_1Prox = retrieveModuleProxy(gGw1, "gw3");
1530 TEST_ASSERT(gw3_1Prox != NULL);
1531 TEST_ASSERT(gw3_1Prox->getModuleDistance() == 1);
1532 gw3_2Prox = retrieveModuleProxy(gGw2, "gw3");
1533 TEST_ASSERT(gw3_2Prox != NULL);
1534 TEST_ASSERT(gw3_2Prox->getModuleDistance() == 1);
1535 gw3_3Prox = retrieveModuleProxy(gGw3, "gw3");
1536 TEST_ASSERT(gw3_3Prox != NULL);
1537 TEST_ASSERT(gw3_3Prox->getModuleDistance() == 0);
1538 gw3_4Prox = retrieveModuleProxy(gGw4, "gw3");
1539 TEST_ASSERT(gw3_4Prox != NULL);
1540 TEST_ASSERT(gw3_4Prox->getModuleDistance() == 1);
1542 gw4_1Prox = retrieveModuleProxy(gGw1, "gw4");
1543 TEST_ASSERT(gw4_1Prox != NULL);
1544 TEST_ASSERT(gw4_1Prox->getModuleDistance() == 2);
1545 gw4_2Prox = retrieveModuleProxy(gGw2, "gw4");
1546 TEST_ASSERT(gw4_2Prox != NULL);
1547 TEST_ASSERT(gw4_2Prox->getModuleDistance() == 2);
1548 gw4_3Prox = retrieveModuleProxy(gGw3, "gw4");
1549 TEST_ASSERT(gw4_3Prox != NULL);
1550 TEST_ASSERT(gw4_3Prox->getModuleDistance() == 1);
1551 gw4_4Prox = retrieveModuleProxy(gGw4, "gw4");
1552 TEST_ASSERT(gw4_4Prox != NULL);
1553 TEST_ASSERT(gw4_4Prox->getModuleDistance() == 0);
1555 // close gw3 to gw1
1556 cmd = "gw3.transportCmd l3c(close connId=1)";
1557 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1559 // update the network
1560 for (uint i=0; i<7; ++i)
1562 mm.updateModules();
1563 NLMISC::nlSleep(100);
1566 // check module list
1567 proxList.clear();
1568 gGw1->getModuleProxyList(proxList);
1569 TEST_ASSERT(proxList.size() == 4);
1570 proxList.clear();
1571 gGw2->getModuleProxyList(proxList);
1572 TEST_ASSERT(proxList.size() == 4);
1573 proxList.clear();
1574 gGw3->getModuleProxyList(proxList);
1575 TEST_ASSERT(proxList.size() == 4);
1576 proxList.clear();
1577 gGw4->getModuleProxyList(proxList);
1578 TEST_ASSERT(proxList.size() == 4);
1580 // check the distances
1581 gw1_1Prox = retrieveModuleProxy(gGw1, "gw1");
1582 TEST_ASSERT(gw1_1Prox != NULL);
1583 TEST_ASSERT(gw1_1Prox->getModuleDistance() == 0);
1584 gw1_2Prox = retrieveModuleProxy(gGw2, "gw1");
1585 TEST_ASSERT(gw1_2Prox != NULL);
1586 TEST_ASSERT(gw1_2Prox->getModuleDistance() == 1);
1587 gw1_3Prox = retrieveModuleProxy(gGw3, "gw1");
1588 TEST_ASSERT(gw1_3Prox != NULL);
1589 TEST_ASSERT(gw1_3Prox->getModuleDistance() == 2);
1590 gw1_4Prox = retrieveModuleProxy(gGw4, "gw1");
1591 TEST_ASSERT(gw1_4Prox != NULL);
1592 TEST_ASSERT(gw1_4Prox->getModuleDistance() == 3);
1594 gw2_1Prox = retrieveModuleProxy(gGw1, "gw2");
1595 TEST_ASSERT(gw2_1Prox != NULL);
1596 TEST_ASSERT(gw2_1Prox->getModuleDistance() == 1);
1597 gw2_2Prox = retrieveModuleProxy(gGw2, "gw2");
1598 TEST_ASSERT(gw2_2Prox != NULL);
1599 TEST_ASSERT(gw2_2Prox->getModuleDistance() == 0);
1600 gw2_3Prox = retrieveModuleProxy(gGw3, "gw2");
1601 TEST_ASSERT(gw2_3Prox != NULL);
1602 TEST_ASSERT(gw2_3Prox->getModuleDistance() == 1);
1603 gw2_4Prox = retrieveModuleProxy(gGw4, "gw2");
1604 TEST_ASSERT(gw2_4Prox != NULL);
1605 TEST_ASSERT(gw2_4Prox->getModuleDistance() == 2);
1607 gw3_1Prox = retrieveModuleProxy(gGw1, "gw3");
1608 TEST_ASSERT(gw3_1Prox != NULL);
1609 TEST_ASSERT(gw3_1Prox->getModuleDistance() == 2);
1610 gw3_2Prox = retrieveModuleProxy(gGw2, "gw3");
1611 TEST_ASSERT(gw3_2Prox != NULL);
1612 TEST_ASSERT(gw3_2Prox->getModuleDistance() == 1);
1613 gw3_3Prox = retrieveModuleProxy(gGw3, "gw3");
1614 TEST_ASSERT(gw3_3Prox != NULL);
1615 TEST_ASSERT(gw3_3Prox->getModuleDistance() == 0);
1616 gw3_4Prox = retrieveModuleProxy(gGw4, "gw3");
1617 TEST_ASSERT(gw3_4Prox != NULL);
1618 TEST_ASSERT(gw3_4Prox->getModuleDistance() == 1);
1620 gw4_1Prox = retrieveModuleProxy(gGw1, "gw4");
1621 TEST_ASSERT(gw4_1Prox != NULL);
1622 TEST_ASSERT(gw4_1Prox->getModuleDistance() == 3);
1623 gw4_2Prox = retrieveModuleProxy(gGw2, "gw4");
1624 TEST_ASSERT(gw4_2Prox != NULL);
1625 TEST_ASSERT(gw4_2Prox->getModuleDistance() == 2);
1626 gw4_3Prox = retrieveModuleProxy(gGw3, "gw4");
1627 TEST_ASSERT(gw4_3Prox != NULL);
1628 TEST_ASSERT(gw4_3Prox->getModuleDistance() == 1);
1629 gw4_4Prox = retrieveModuleProxy(gGw4, "gw4");
1630 TEST_ASSERT(gw4_4Prox != NULL);
1631 TEST_ASSERT(gw4_4Prox->getModuleDistance() == 0);
1633 // make a double connection from gw1 to gw2
1634 cmd = "gw1.transportCmd l3c(connect addr=localhost:8062)";
1635 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1637 // update the network
1638 for (uint i=0; i<7; ++i)
1640 mm.updateModules();
1641 NLMISC::nlSleep(100);
1644 // check module list
1645 proxList.clear();
1646 gGw1->getModuleProxyList(proxList);
1647 TEST_ASSERT(proxList.size() == 4);
1648 proxList.clear();
1649 gGw2->getModuleProxyList(proxList);
1650 TEST_ASSERT(proxList.size() == 4);
1651 proxList.clear();
1652 gGw3->getModuleProxyList(proxList);
1653 TEST_ASSERT(proxList.size() == 4);
1654 proxList.clear();
1655 gGw4->getModuleProxyList(proxList);
1656 TEST_ASSERT(proxList.size() == 4);
1658 // check the distances
1659 gw1_1Prox = retrieveModuleProxy(gGw1, "gw1");
1660 TEST_ASSERT(gw1_1Prox != NULL);
1661 TEST_ASSERT(gw1_1Prox->getModuleDistance() == 0);
1662 gw1_2Prox = retrieveModuleProxy(gGw2, "gw1");
1663 TEST_ASSERT(gw1_2Prox != NULL);
1664 TEST_ASSERT(gw1_2Prox->getModuleDistance() == 1);
1665 gw1_3Prox = retrieveModuleProxy(gGw3, "gw1");
1666 TEST_ASSERT(gw1_3Prox != NULL);
1667 TEST_ASSERT(gw1_3Prox->getModuleDistance() == 2);
1668 gw1_4Prox = retrieveModuleProxy(gGw4, "gw1");
1669 TEST_ASSERT(gw1_4Prox != NULL);
1670 TEST_ASSERT(gw1_4Prox->getModuleDistance() == 3);
1672 gw2_1Prox = retrieveModuleProxy(gGw1, "gw2");
1673 TEST_ASSERT(gw2_1Prox != NULL);
1674 TEST_ASSERT(gw2_1Prox->getModuleDistance() == 1);
1675 gw2_2Prox = retrieveModuleProxy(gGw2, "gw2");
1676 TEST_ASSERT(gw2_2Prox != NULL);
1677 TEST_ASSERT(gw2_2Prox->getModuleDistance() == 0);
1678 gw2_3Prox = retrieveModuleProxy(gGw3, "gw2");
1679 TEST_ASSERT(gw2_3Prox != NULL);
1680 TEST_ASSERT(gw2_3Prox->getModuleDistance() == 1);
1681 gw2_4Prox = retrieveModuleProxy(gGw4, "gw2");
1682 TEST_ASSERT(gw2_4Prox != NULL);
1683 TEST_ASSERT(gw2_4Prox->getModuleDistance() == 2);
1685 gw3_1Prox = retrieveModuleProxy(gGw1, "gw3");
1686 TEST_ASSERT(gw3_1Prox != NULL);
1687 TEST_ASSERT(gw3_1Prox->getModuleDistance() == 2);
1688 gw3_2Prox = retrieveModuleProxy(gGw2, "gw3");
1689 TEST_ASSERT(gw3_2Prox != NULL);
1690 TEST_ASSERT(gw3_2Prox->getModuleDistance() == 1);
1691 gw3_3Prox = retrieveModuleProxy(gGw3, "gw3");
1692 TEST_ASSERT(gw3_3Prox != NULL);
1693 TEST_ASSERT(gw3_3Prox->getModuleDistance() == 0);
1694 gw3_4Prox = retrieveModuleProxy(gGw4, "gw3");
1695 TEST_ASSERT(gw3_4Prox != NULL);
1696 TEST_ASSERT(gw3_4Prox->getModuleDistance() == 1);
1698 gw4_1Prox = retrieveModuleProxy(gGw1, "gw4");
1699 TEST_ASSERT(gw4_1Prox != NULL);
1700 TEST_ASSERT(gw4_1Prox->getModuleDistance() == 3);
1701 gw4_2Prox = retrieveModuleProxy(gGw2, "gw4");
1702 TEST_ASSERT(gw4_2Prox != NULL);
1703 TEST_ASSERT(gw4_2Prox->getModuleDistance() == 2);
1704 gw4_3Prox = retrieveModuleProxy(gGw3, "gw4");
1705 TEST_ASSERT(gw4_3Prox != NULL);
1706 TEST_ASSERT(gw4_3Prox->getModuleDistance() == 1);
1707 gw4_4Prox = retrieveModuleProxy(gGw4, "gw4");
1708 TEST_ASSERT(gw4_4Prox != NULL);
1709 TEST_ASSERT(gw4_4Prox->getModuleDistance() == 0);
1711 // release modules
1712 mm.deleteModule(gw1);
1713 mm.deleteModule(gw2);
1714 mm.deleteModule(gw3);
1715 mm.deleteModule(gw4);
1718 void firewalling()
1720 // check that, with firewall mode enabled, unsafe root can only see protected
1721 // modules if they initiate the dialog first (i.e only a protected module can send
1722 // a message to an unsafe module).
1724 // for this test, we have the following context :
1725 // 'master' : a gateway that accesses connection on two transports, one 'firewalled', the other one normal
1726 // 'peer1' : gateway connected to gateway 'master' on a firewalled transport
1727 // 'peer2' : gateway connected to gateway 'master' on a firewalled transport
1728 // 'other' : gateway connected to gateway 'master' on a classic transport
1730 // peer1 (l3c)-----\
1731 // >-|<- (l3s1/Firewalled) master (l3s2) ----- (l3c) other
1732 // peer2 (l3c)-----/
1734 // 'peer1' and 'peer2' must not see any module except modules that try to communicate with them
1735 // 'master' and 'other' must see 'peer1', 'peer2', 'master' and 'other'
1737 // Switching OFF the firewall should disclose all modules,
1738 // switching ON then must throw an exception
1740 NLNET::IModuleManager &mm = NLNET::IModuleManager::getInstance();
1741 NLMISC::CCommandRegistry &cr = NLMISC::CCommandRegistry::getInstance();
1743 NLNET::IModule *peer1, *peer2, *master, *other;
1745 // create the modules
1746 peer1 = mm.createModule("StandardGateway", "peer1", "");
1747 peer2 = mm.createModule("StandardGateway", "peer2", "");
1748 master = mm.createModule("StandardGateway", "master", "");
1749 other = mm.createModule("StandardGateway", "other", "");
1751 TEST_ASSERT(peer1 != NULL);
1752 TEST_ASSERT(peer2 != NULL);
1753 TEST_ASSERT(master != NULL);
1754 TEST_ASSERT(other != NULL);
1756 // plug gateway in themselves
1757 NLNET::IModuleSocket *sPeer1, *sPeer2, *sMaster, *sOther;
1758 sPeer1 = mm.getModuleSocket("peer1");
1759 sPeer2 = mm.getModuleSocket("peer2");
1760 sMaster = mm.getModuleSocket("master");
1761 sOther = mm.getModuleSocket("other");
1763 TEST_ASSERT(sPeer1 != NULL);
1764 TEST_ASSERT(sPeer2 != NULL);
1765 TEST_ASSERT(sMaster != NULL);
1766 TEST_ASSERT(sOther != NULL);
1768 peer1->plugModule(sPeer1);
1769 peer2->plugModule(sPeer2);
1770 master->plugModule(sMaster);
1771 other->plugModule(sOther);
1773 string cmd;
1774 // create the transports
1775 cmd = "peer1.transportAdd L3Client l3c";
1776 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1777 cmd = "peer2.transportAdd L3Client l3c";
1778 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1779 cmd = "master.transportAdd L3Server l3s1";
1780 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1781 cmd = "master.transportAdd L3Server l3s2";
1782 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1783 cmd = "other.transportAdd L3Client l3c";
1784 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1786 // Set option and connect transport
1787 cmd = "master.transportOptions l3s1(Firewalled)";
1788 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1789 cmd = "master.transportCmd l3s1(open port=8060)";
1790 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1791 cmd = "master.transportCmd l3s2(open port=8061)";
1792 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1793 cmd = "peer1.transportCmd l3c(connect addr=localhost:8060)";
1794 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1795 cmd = "peer2.transportCmd l3c(connect addr=localhost:8060)";
1796 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1797 cmd = "other.transportCmd l3c(connect addr=localhost:8061)";
1798 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1800 // d'ho ! all done, now let's run some loop of update
1801 for (uint i=0; i<7; ++i)
1803 mm.updateModules();
1804 NLMISC::nlSleep(100);
1807 // ok, now, check that each gateway only knows the gateway it must know
1808 NLNET::IModuleGateway *gPeer1, *gPeer2, *gMaster, *gOther;
1809 gPeer1 = dynamic_cast<NLNET::IModuleGateway *>(peer1);
1810 TEST_ASSERT(gPeer1 != NULL);
1811 gPeer2 = dynamic_cast<NLNET::IModuleGateway *>(peer2);
1812 TEST_ASSERT(gPeer2 != NULL);
1813 gMaster = dynamic_cast<NLNET::IModuleGateway *>(master);
1814 TEST_ASSERT(gMaster != NULL);
1815 gOther = dynamic_cast<NLNET::IModuleGateway *>(other);
1816 TEST_ASSERT(gOther != NULL);
1818 vector<NLNET::IModuleProxy*> proxList;
1819 gPeer1->getModuleProxyList(proxList);
1820 TEST_ASSERT(proxList.size() == 1);
1821 TEST_ASSERT(lookForModuleProxy(proxList, "peer1"));
1823 proxList.clear();
1824 gPeer2->getModuleProxyList(proxList);
1825 TEST_ASSERT(proxList.size() == 1);
1826 TEST_ASSERT(lookForModuleProxy(proxList, "peer2"));
1828 proxList.clear();
1829 gMaster->getModuleProxyList(proxList);
1830 TEST_ASSERT(proxList.size() == 4);
1831 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
1832 TEST_ASSERT(lookForModuleProxy(proxList, "peer1"));
1833 TEST_ASSERT(lookForModuleProxy(proxList, "peer2"));
1834 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
1836 proxList.clear();
1837 gOther->getModuleProxyList(proxList);
1838 TEST_ASSERT(proxList.size() == 4);
1839 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
1840 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
1841 TEST_ASSERT(lookForModuleProxy(proxList, "peer1"));
1842 TEST_ASSERT(lookForModuleProxy(proxList, "peer2"));
1845 // now send the debug 'PING' message from 'other' to 'peer1', and a message from 'master' to 'peer2'
1847 NLNET::CMessage ping("DEBUG_MOD_PING");
1849 // retrieve peer1 proxy from other
1850 NLNET::IModuleProxy *peer1Prox = retrieveModuleProxy(gMaster, "peer1");
1851 TEST_ASSERT(peer1Prox != NULL);
1852 peer1Prox->sendModuleMessage(master, ping);
1855 NLNET::CMessage ping("DEBUG_MOD_PING");
1857 // retrieve peer1 proxy from other
1858 NLNET::IModuleProxy *peer2Prox = retrieveModuleProxy(gOther, "peer2");
1859 TEST_ASSERT(peer2Prox != NULL);
1860 peer2Prox->sendModuleMessage(other, ping);
1863 // update the network
1864 for (uint i=0; i<7; ++i)
1866 mm.updateModules();
1867 NLMISC::nlSleep(100);
1870 // check new proxy table and ping counter
1871 TEST_ASSERT(gPeer1->getReceivedPingCount() == 1);
1872 proxList.clear();
1873 gPeer1->getModuleProxyList(proxList);
1874 TEST_ASSERT(proxList.size() == 2);
1875 TEST_ASSERT(lookForModuleProxy(proxList, "peer1"));
1876 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
1878 TEST_ASSERT(gPeer2->getReceivedPingCount() == 1);
1879 proxList.clear();
1880 gPeer2->getModuleProxyList(proxList);
1881 TEST_ASSERT(proxList.size() == 2);
1882 TEST_ASSERT(lookForModuleProxy(proxList, "peer2"));
1883 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
1885 proxList.clear();
1886 gMaster->getModuleProxyList(proxList);
1887 TEST_ASSERT(proxList.size() == 4);
1888 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
1889 TEST_ASSERT(lookForModuleProxy(proxList, "peer1"));
1890 TEST_ASSERT(lookForModuleProxy(proxList, "peer2"));
1891 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
1893 proxList.clear();
1894 gOther->getModuleProxyList(proxList);
1895 TEST_ASSERT(proxList.size() == 4);
1896 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
1897 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
1898 TEST_ASSERT(lookForModuleProxy(proxList, "peer1"));
1899 TEST_ASSERT(lookForModuleProxy(proxList, "peer2"));
1901 // now, remove firewall mode
1902 cmd = "master.transportOptions l3s1()";
1903 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
1905 // update the network
1906 for (uint i=0; i<7; ++i)
1908 mm.updateModules();
1909 NLMISC::nlSleep(100);
1912 // check new proxy table and ping counter
1913 proxList.clear();
1914 gPeer1->getModuleProxyList(proxList);
1915 TEST_ASSERT(proxList.size() == 4);
1916 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
1917 TEST_ASSERT(lookForModuleProxy(proxList, "peer1"));
1918 TEST_ASSERT(lookForModuleProxy(proxList, "peer2"));
1919 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
1921 TEST_ASSERT(gPeer2->getReceivedPingCount() == 1);
1922 proxList.clear();
1923 gPeer2->getModuleProxyList(proxList);
1924 TEST_ASSERT(proxList.size() == 4);
1925 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
1926 TEST_ASSERT(lookForModuleProxy(proxList, "peer1"));
1927 TEST_ASSERT(lookForModuleProxy(proxList, "peer2"));
1928 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
1930 proxList.clear();
1931 gMaster->getModuleProxyList(proxList);
1932 TEST_ASSERT(proxList.size() == 4);
1933 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
1934 TEST_ASSERT(lookForModuleProxy(proxList, "peer1"));
1935 TEST_ASSERT(lookForModuleProxy(proxList, "peer2"));
1936 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
1938 proxList.clear();
1939 gOther->getModuleProxyList(proxList);
1940 TEST_ASSERT(proxList.size() == 4);
1941 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
1942 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
1943 TEST_ASSERT(lookForModuleProxy(proxList, "peer1"));
1944 TEST_ASSERT(lookForModuleProxy(proxList, "peer2"));
1946 // no try reactivate firewall mode with active route
1947 cmd = "master.transportOptions l3s1(Firewalled)";
1948 TEST_THROWS(cr.execute(cmd, NLMISC::InfoLog()), NLNET::IModuleGateway::EGatewayFirewallBreak);
1951 // cleanup
1952 mm.deleteModule(peer1);
1953 mm.deleteModule(peer2);
1954 mm.deleteModule(master);
1955 mm.deleteModule(other);
1959 void peerInvisible()
1961 // check that, with peer invisible enable, the peer modules are effectively invisible,
1962 // and, also, check that other modules, on other route are visible.
1963 // for this test, we have the following context :
1964 // 'master' : a gateway that acces connection on to transport, on 'peer invisible', the other normal
1965 // 'peer1' : gateway connected to gateway 'master' on a peer invisible transport
1966 // 'peer2' : gateway connected to gateway 'master' on a peer invisible transport
1967 // 'other' : gateway connected to gateway 'master' on a classic transport
1969 // peer1 (l3c)-----\
1970 // >-- (l3s1/PeerInvisible) master (l3s2) ----- (l3c) other
1971 // peer2 (l3c)-----/
1973 // 'peer1' must see 'master' and 'other'
1974 // 'peer2' must see 'master' and 'other'
1975 // 'master' must see 'peer1', 'peer2' and 'other'
1976 // 'other' must see 'peer1', 'peer2' and 'master'
1978 // When switching the PeerInvisible option to OFF, peer1 and peer2 must see each other
1980 NLNET::IModuleManager &mm = NLNET::IModuleManager::getInstance();
1981 NLMISC::CCommandRegistry &cr = NLMISC::CCommandRegistry::getInstance();
1983 NLNET::IModule *peer1, *peer2, *master, *other;
1985 // create the modules
1986 peer1 = mm.createModule("StandardGateway", "peer1", "");
1987 peer2 = mm.createModule("StandardGateway", "peer2", "");
1988 master = mm.createModule("StandardGateway", "master", "");
1989 other = mm.createModule("StandardGateway", "other", "");
1991 TEST_ASSERT(peer1 != NULL);
1992 TEST_ASSERT(peer2 != NULL);
1993 TEST_ASSERT(master != NULL);
1994 TEST_ASSERT(other != NULL);
1996 // plug gateway in themselves
1997 NLNET::IModuleSocket *sPeer1, *sPeer2, *sMaster, *sOther;
1998 sPeer1 = mm.getModuleSocket("peer1");
1999 sPeer2 = mm.getModuleSocket("peer2");
2000 sMaster = mm.getModuleSocket("master");
2001 sOther = mm.getModuleSocket("other");
2003 TEST_ASSERT(sPeer1 != NULL);
2004 TEST_ASSERT(sPeer2 != NULL);
2005 TEST_ASSERT(sMaster != NULL);
2006 TEST_ASSERT(sOther != NULL);
2008 peer1->plugModule(sPeer1);
2009 peer2->plugModule(sPeer2);
2010 master->plugModule(sMaster);
2011 other->plugModule(sOther);
2013 string cmd;
2014 // create the transports
2015 cmd = "peer1.transportAdd L3Client l3c";
2016 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2017 cmd = "peer2.transportAdd L3Client l3c";
2018 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2019 cmd = "master.transportAdd L3Server l3s1";
2020 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2021 cmd = "master.transportAdd L3Server l3s2";
2022 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2023 cmd = "other.transportAdd L3Client l3c";
2024 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2026 // Set option and connect transport
2027 cmd = "master.transportOptions l3s1(PeerInvisible)";
2028 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2029 cmd = "master.transportCmd l3s1(open port=8060)";
2030 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2031 cmd = "master.transportCmd l3s2(open port=8061)";
2032 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2033 cmd = "peer1.transportCmd l3c(connect addr=localhost:8060)";
2034 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2035 cmd = "peer2.transportCmd l3c(connect addr=localhost:8060)";
2036 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2037 cmd = "other.transportCmd l3c(connect addr=localhost:8061)";
2038 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2040 // d'ho ! all done, now let's run some loop of update
2041 for (uint i=0; i<7; ++i)
2043 mm.updateModules();
2044 NLMISC::nlSleep(100);
2047 // ok, now, check that each gateway only knows the gateway it must know
2048 NLNET::IModuleGateway *gPeer1, *gPeer2, *gMaster, *gOther;
2049 gPeer1 = dynamic_cast<NLNET::IModuleGateway *>(peer1);
2050 TEST_ASSERT(gPeer1 != NULL);
2051 gPeer2 = dynamic_cast<NLNET::IModuleGateway *>(peer2);
2052 TEST_ASSERT(gPeer2 != NULL);
2053 gMaster = dynamic_cast<NLNET::IModuleGateway *>(master);
2054 TEST_ASSERT(gMaster != NULL);
2055 gOther = dynamic_cast<NLNET::IModuleGateway *>(other);
2056 TEST_ASSERT(gOther != NULL);
2058 vector<NLNET::IModuleProxy*> proxList;
2059 gPeer1->getModuleProxyList(proxList);
2060 TEST_ASSERT(proxList.size() == 3);
2061 TEST_ASSERT(lookForModuleProxy(proxList, "peer1"));
2062 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
2063 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
2065 proxList.clear();
2066 gPeer2->getModuleProxyList(proxList);
2067 TEST_ASSERT(proxList.size() == 3);
2068 TEST_ASSERT(lookForModuleProxy(proxList, "peer2"));
2069 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
2070 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
2072 proxList.clear();
2073 gMaster->getModuleProxyList(proxList);
2074 TEST_ASSERT(proxList.size() == 4);
2075 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
2076 TEST_ASSERT(lookForModuleProxy(proxList, "peer1"));
2077 TEST_ASSERT(lookForModuleProxy(proxList, "peer2"));
2078 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
2080 proxList.clear();
2081 gOther->getModuleProxyList(proxList);
2082 TEST_ASSERT(proxList.size() == 4);
2083 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
2084 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
2085 TEST_ASSERT(lookForModuleProxy(proxList, "peer1"));
2086 TEST_ASSERT(lookForModuleProxy(proxList, "peer2"));
2088 // now, remove the 'PeerInvisible' options
2089 cmd = "master.transportOptions l3s1()";
2090 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2092 // update the network
2093 for (uint i=0; i<7; ++i)
2095 mm.updateModules();
2096 NLMISC::nlSleep(100);
2099 // check new proxy table
2100 proxList.clear();
2101 gPeer1->getModuleProxyList(proxList);
2102 TEST_ASSERT(proxList.size() == 4);
2103 TEST_ASSERT(lookForModuleProxy(proxList, "peer1"));
2104 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
2105 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
2106 TEST_ASSERT(lookForModuleProxy(proxList, "peer2"));
2108 proxList.clear();
2109 gPeer2->getModuleProxyList(proxList);
2110 TEST_ASSERT(proxList.size() == 4);
2111 TEST_ASSERT(lookForModuleProxy(proxList, "peer2"));
2112 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
2113 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
2114 TEST_ASSERT(lookForModuleProxy(proxList, "peer1"));
2116 proxList.clear();
2117 gMaster->getModuleProxyList(proxList);
2118 TEST_ASSERT(proxList.size() == 4);
2119 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
2120 TEST_ASSERT(lookForModuleProxy(proxList, "peer1"));
2121 TEST_ASSERT(lookForModuleProxy(proxList, "peer2"));
2122 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
2124 proxList.clear();
2125 gOther->getModuleProxyList(proxList);
2126 TEST_ASSERT(proxList.size() == 4);
2127 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
2128 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
2129 TEST_ASSERT(lookForModuleProxy(proxList, "peer1"));
2130 TEST_ASSERT(lookForModuleProxy(proxList, "peer2"));
2132 // now, re set the 'PeerInvisible' options
2133 cmd = "master.transportOptions l3s1(PeerInvisible)";
2134 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2136 // update the network
2137 for (uint i=0; i<7; ++i)
2139 mm.updateModules();
2140 NLMISC::nlSleep(100);
2143 // check new proxy table
2144 proxList.clear();
2145 gPeer1->getModuleProxyList(proxList);
2146 TEST_ASSERT(proxList.size() == 3);
2147 TEST_ASSERT(lookForModuleProxy(proxList, "peer1"));
2148 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
2149 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
2151 proxList.clear();
2152 gPeer2->getModuleProxyList(proxList);
2153 TEST_ASSERT(proxList.size() == 3);
2154 TEST_ASSERT(lookForModuleProxy(proxList, "peer2"));
2155 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
2156 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
2158 proxList.clear();
2159 gMaster->getModuleProxyList(proxList);
2160 TEST_ASSERT(proxList.size() == 4);
2161 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
2162 TEST_ASSERT(lookForModuleProxy(proxList, "peer1"));
2163 TEST_ASSERT(lookForModuleProxy(proxList, "peer2"));
2164 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
2166 proxList.clear();
2167 gOther->getModuleProxyList(proxList);
2168 TEST_ASSERT(proxList.size() == 4);
2169 TEST_ASSERT(lookForModuleProxy(proxList, "other"));
2170 TEST_ASSERT(lookForModuleProxy(proxList, "master"));
2171 TEST_ASSERT(lookForModuleProxy(proxList, "peer1"));
2172 TEST_ASSERT(lookForModuleProxy(proxList, "peer2"));
2173 // cleanup
2174 mm.deleteModule(peer1);
2175 mm.deleteModule(peer2);
2176 mm.deleteModule(master);
2177 mm.deleteModule(other);
2181 void gwPlugUnplug()
2183 // check that multiple plug/unplug operations work well
2184 NLNET::IModuleManager &mm = NLNET::IModuleManager::getInstance();
2185 NLMISC::CCommandRegistry &cr = NLMISC::CCommandRegistry::getInstance();
2187 NLNET::IModule *mod = mm.createModule("StandardGateway", "gw", "");
2188 TEST_ASSERT(mod != NULL);
2190 NLNET::IModuleSocket *socket = mm.getModuleSocket("gw");
2191 TEST_ASSERT(socket != NULL);
2192 mod->plugModule(socket);
2193 mod->unplugModule(socket);
2194 mod->plugModule(socket);
2195 mod->unplugModule(socket);
2196 mod->plugModule(socket);
2198 std::vector<NLNET::IModuleProxy*> result;
2199 socket->getModuleList(result);
2200 TEST_ASSERT(result.size() == 1);
2202 mod->unplugModule(socket);
2204 mm.deleteModule(mod);
2207 void uniqueNameGenerator()
2209 NLNET::IModuleManager &mm = NLNET::IModuleManager::getInstance();
2210 NLMISC::CCommandRegistry &cr = NLMISC::CCommandRegistry::getInstance();
2212 mm.setUniqueNameRoot("foo");
2214 // create a simple module
2215 NLNET::IModule *mod = mm.createModule("ModuleType0", "mod", "");
2216 TEST_ASSERT(mod != NULL);
2217 TEST_ASSERT(mod->getModuleFullyQualifiedName() == "foo:mod");
2218 mm.deleteModule(mod);
2220 // reset the unique name to normal value
2221 mm.setUniqueNameRoot(string());
2223 mod = mm.createModule("ModuleType0", "mod", "");
2224 TEST_ASSERT(mod != NULL);
2225 TEST_ASSERT(mod->getModuleFullyQualifiedName() != "foo:mod");
2227 mm.deleteModule(mod);
2230 void localMessageQueing()
2232 NLNET::IModuleManager &mm = NLNET::IModuleManager::getInstance();
2233 NLMISC::CCommandRegistry &cr = NLMISC::CCommandRegistry::getInstance();
2235 NLNET::IModule *mods = mm.createModule("StandardGateway", "gws", "");
2236 TEST_ASSERT(mods != NULL);
2237 NLNET::IModuleGateway *gws = dynamic_cast<NLNET::IModuleGateway*>(mods);
2238 TEST_ASSERT(gws != NULL);
2240 // get the socket interface of the gateway
2241 NLNET::IModuleSocket *socketGws = mm.getModuleSocket("gws");
2242 TEST_ASSERT(socketGws != NULL);
2244 // create two modules that will communicate localy
2245 NLNET::IModule *m1= mm.createModule("ModuleType0", "m1", "");
2246 TEST_ASSERT(m1!= NULL);
2247 NLNET::IModule *m2= mm.createModule("ModuleAsync", "m2", "");
2248 TEST_ASSERT(m2!= NULL);
2250 m1->plugModule(socketGws);
2251 m2->plugModule(socketGws);
2253 // update the networks
2254 for (uint i=0; i<4; ++i)
2256 mm.updateModules();
2257 NLMISC::nlSleep(50);
2260 // retrieve module proxy and send one ping to each other
2261 vector<NLNET::IModuleProxy*> proxiesC;
2262 gws->getModuleProxyList(proxiesC);
2263 TEST_ASSERT(proxiesC.size() == 2);
2264 TEST_ASSERT(lookForModuleProxy(proxiesC, "m2"));
2265 NLNET::IModuleProxy *pm2 = retrieveModuleProxy(gws, "m2");
2266 TEST_ASSERT(pm2 != NULL);
2267 NLNET::CMessage aMessage("DEBUG_MOD_PING");
2268 pm2->sendModuleMessage(m1, aMessage);
2270 proxiesC.clear();
2271 gws->getModuleProxyList(proxiesC);
2272 TEST_ASSERT(proxiesC.size() == 2);
2273 TEST_ASSERT(lookForModuleProxy(proxiesC, "m1"));
2274 NLNET::IModuleProxy *pm1 = retrieveModuleProxy(gws, "m1");
2275 TEST_ASSERT(pm1 != NULL);
2276 aMessage = NLNET::CMessage("DEBUG_MOD_PING");
2277 pm1->sendModuleMessage(m2, aMessage);
2279 // check received ping count
2280 CModuleType0 *mod1 = dynamic_cast<CModuleType0*>(m1);
2281 TEST_ASSERT(mod1 != NULL);
2282 TEST_ASSERT(mod1->PingCount == 1);
2283 CModuleType0 *mod2 = dynamic_cast<CModuleType0*>(m2);
2284 TEST_ASSERT(mod2 != NULL);
2285 TEST_ASSERT(mod2->PingCount == 0);
2287 // update the networks
2288 for (uint i=0; i<4; ++i)
2290 mm.updateModules();
2291 NLMISC::nlSleep(50);
2294 // check received ping count
2295 TEST_ASSERT(mod1->PingCount == 1);
2296 TEST_ASSERT(mod2->PingCount == 1);
2298 // update the networks
2299 for (uint i=0; i<4; ++i)
2301 mm.updateModules();
2302 NLMISC::nlSleep(50);
2305 // check received ping count
2306 TEST_ASSERT(mod1->PingCount == 1);
2307 TEST_ASSERT(mod2->PingCount == 1);
2310 // cleanup
2311 mm.deleteModule(m1);
2312 mm.deleteModule(m2);
2313 mm.deleteModule(mods);
2316 void moduleMessaging()
2318 NLNET::IModuleManager &mm = NLNET::IModuleManager::getInstance();
2319 NLMISC::CCommandRegistry &cr = NLMISC::CCommandRegistry::getInstance();
2321 // create two gateway an connect them, plug the gateway on themselves and send a message
2322 NLNET::IModule *mods = mm.createModule("StandardGateway", "gws", "");
2323 TEST_ASSERT(mods != NULL);
2324 NLNET::IModuleGateway *gws = dynamic_cast<NLNET::IModuleGateway*>(mods);
2325 TEST_ASSERT(gws != NULL);
2327 // plug the module in itself before opening connection
2328 NLNET::IModuleSocket *socketGws = mm.getModuleSocket("gws");
2329 TEST_ASSERT(socketGws != NULL);
2330 mods->plugModule(socketGws);
2332 // add transport for server mode
2333 string cmd = "gws.transportAdd L3Server l3s";
2334 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2335 cmd = "gws.transportCmd l3s(open port=6185)";
2336 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2338 NLNET::IModule *modc = mm.createModule("StandardGateway", "gwc", "");
2339 TEST_ASSERT(modc != NULL);
2340 NLNET::IModuleGateway *gwc = dynamic_cast<NLNET::IModuleGateway*>(modc);
2341 TEST_ASSERT(gwc != NULL);
2342 // add transport for client mode
2343 cmd = "gwc.transportAdd L3Client l3c";
2344 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2345 cmd = "gwc.transportCmd l3c(connect addr=localhost:6185)";
2346 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2348 // plug the module in itself before opening connection
2349 NLNET::IModuleSocket *socketGwc = mm.getModuleSocket("gwc");
2350 TEST_ASSERT(socketGwc != NULL);
2351 modc->plugModule(socketGwc);
2353 // update the gateways...
2354 for (uint i=0; i<4; ++i)
2356 mm.updateModules();
2357 NLMISC::nlSleep(100);
2360 // send a message from gws to gwc using the proxy
2361 // First, get the proxy for the client (must be the second one)
2362 vector<NLNET::IModuleProxy*> proxiesS;
2363 gws->getModuleProxyList(proxiesS);
2364 TEST_ASSERT(proxiesS.size() == 2);
2365 TEST_ASSERT(lookForModuleProxy(proxiesS, "gwc"));
2366 NLNET::CMessage aMessage("DEBUG_MOD_PING");
2367 proxiesS[1]->sendModuleMessage(mods, aMessage);
2369 // update the gateways...
2370 for (uint i=0; i<4; ++i)
2372 mm.updateModules();
2373 NLMISC::nlSleep(100);
2376 // check that the ping has been received
2377 TEST_ASSERT(gwc->getReceivedPingCount() == 1);
2379 // send two crossing messages simultaneously
2380 vector<NLNET::IModuleProxy*> proxiesC;
2381 gwc->getModuleProxyList(proxiesC);
2382 TEST_ASSERT(proxiesC.size() == 2);
2383 TEST_ASSERT(lookForModuleProxy(proxiesC, "gws"));
2384 proxiesS[1]->sendModuleMessage(mods, aMessage);
2385 proxiesC[1]->sendModuleMessage(modc, aMessage);
2387 // update the gateways...
2388 for (uint i=0; i<4; ++i)
2390 mm.updateModules();
2391 NLMISC::nlSleep(100);
2393 // check that the ping has been received
2394 TEST_ASSERT(gwc->getReceivedPingCount() == 2);
2395 TEST_ASSERT(gws->getReceivedPingCount() == 1);
2398 // send with ISocket
2399 socketGws->sendModuleMessage(mods, proxiesS[1]->getModuleProxyId(), aMessage);
2400 // update the gateways...
2401 for (uint i=0; i<4; ++i)
2403 mm.updateModules();
2404 NLMISC::nlSleep(100);
2406 // check that the ping has been received
2407 TEST_ASSERT(gwc->getReceivedPingCount() == 3);
2408 TEST_ASSERT(gws->getReceivedPingCount() == 1);
2410 // cleanup modules
2411 mm.deleteModule(mods);
2412 TEST_ASSERT(mm.getLocalModule("gws") == NULL);
2413 mm.deleteModule(modc);
2414 TEST_ASSERT(mm.getLocalModule("gwc") == NULL);
2417 void moduleDisclosure()
2419 NLNET::IModuleManager &mm = NLNET::IModuleManager::getInstance();
2420 NLMISC::CCommandRegistry &cr = NLMISC::CCommandRegistry::getInstance();
2422 NLNET::IModule *mods = mm.createModule("StandardGateway", "gws", "");
2423 TEST_ASSERT(mods != NULL);
2424 NLNET::IModuleGateway *gws = dynamic_cast<NLNET::IModuleGateway*>(mods);
2425 TEST_ASSERT(gws != NULL);
2427 TEST_ASSERT(gws->getProxyCount() == 0);
2429 // plug the module in itself before opening connection
2430 NLNET::IModuleSocket *socketGws = mm.getModuleSocket("gws");
2431 TEST_ASSERT(socketGws != NULL);
2432 mods->plugModule(socketGws);
2434 // now, there must be one proxy in the gateway
2435 TEST_ASSERT(gws->getProxyCount() == 1);
2436 vector<NLNET::IModuleProxy*> proxies;
2437 gws->getModuleProxyList(proxies);
2438 TEST_ASSERT(proxies.size() == 1);
2439 TEST_ASSERT(proxies[0]->getGatewayRoute() == NULL);
2440 TEST_ASSERT(proxies[0]->getForeignModuleId() == mods->getModuleId());
2442 // add transport for server mode
2443 string cmd = "gws.transportAdd L3Server l3s";
2444 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2445 cmd = "gws.transportCmd l3s(open port=6185)";
2446 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2448 NLNET::IModule *modc = mm.createModule("StandardGateway", "gwc", "");
2449 TEST_ASSERT(modc != NULL);
2450 NLNET::IModuleGateway *gwc = dynamic_cast<NLNET::IModuleGateway*>(modc);
2451 TEST_ASSERT(gwc != NULL);
2452 // add transport for client mode
2453 cmd = "gwc.transportAdd L3Client l3c";
2454 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2455 cmd = "gwc.transportCmd l3c(connect addr=localhost:6185)";
2456 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2458 for (uint i=0; i<5; ++i)
2460 mm.updateModules();
2461 NLMISC::nlSleep(100);
2464 // The server must have not changed
2465 TEST_ASSERT(gws->getProxyCount() == 1);
2467 // The client must have one proxy
2468 TEST_ASSERT(gwc->getProxyCount() == 1);
2469 proxies.clear();
2470 gwc->getModuleProxyList(proxies);
2471 TEST_ASSERT(proxies.size() == 1);
2472 TEST_ASSERT(proxies[0]->getGatewayRoute() != NULL);
2473 TEST_ASSERT(proxies[0]->getModuleName().find("gws") == proxies[0]->getModuleName().size() - 3);
2475 // plug the client module in itself after opening connection
2476 NLNET::IModuleSocket *socketGwc = mm.getModuleSocket("gwc");
2477 TEST_ASSERT(socketGwc != NULL);
2478 modc->plugModule(socketGwc);
2481 for (uint i=0; i<4; ++i)
2483 mm.updateModules();
2484 NLMISC::nlSleep(100);
2487 // The server must have now the two modules
2488 TEST_ASSERT(gws->getProxyCount() == 2);
2489 proxies.clear();
2490 gws->getModuleProxyList(proxies);
2491 TEST_ASSERT(proxies.size() == 2);
2492 TEST_ASSERT(proxies[0]->getGatewayRoute() == NULL);
2493 TEST_ASSERT(proxies[0]->getForeignModuleId() == mods->getModuleId());
2494 TEST_ASSERT(proxies[1]->getGatewayRoute() != NULL);
2495 TEST_ASSERT(proxies[1]->getModuleName().find("gwc") == proxies[1]->getModuleName().size() - 3);
2497 // The client must have two module also
2498 TEST_ASSERT(gwc->getProxyCount() == 2);
2499 proxies.clear();
2500 gwc->getModuleProxyList(proxies);
2501 TEST_ASSERT(proxies.size() == 2);
2502 TEST_ASSERT(proxies[0]->getGatewayRoute() != NULL);
2503 TEST_ASSERT(proxies[0]->getModuleName().find("gws") == proxies[1]->getModuleName().size() - 3);
2504 TEST_ASSERT(proxies[1]->getGatewayRoute() == NULL);
2505 TEST_ASSERT(proxies[1]->getForeignModuleId() == modc->getModuleId());
2508 // unplug the client module in itself after opening connection
2509 mods->unplugModule(socketGws);
2511 for (uint i=0; i<4; ++i)
2513 NLMISC::nlSleep(100);
2514 mm.updateModules();
2517 // The server must have one module left
2518 TEST_ASSERT(gws->getProxyCount() == 1);
2519 proxies.clear();
2520 gws->getModuleProxyList(proxies);
2521 TEST_ASSERT(proxies.size() == 1);
2522 TEST_ASSERT(proxies[0]->getGatewayRoute() != NULL);
2523 TEST_ASSERT(proxies[0]->getModuleName().find("gwc") == proxies[0]->getModuleName().size() - 3);
2525 // The client must have one module left
2526 TEST_ASSERT(gwc->getProxyCount() == 1);
2527 proxies.clear();
2528 gwc->getModuleProxyList(proxies);
2529 TEST_ASSERT(proxies.size() == 1);
2530 TEST_ASSERT(proxies[0]->getGatewayRoute() == NULL);
2531 TEST_ASSERT(proxies[0]->getForeignModuleId() == modc->getModuleId());
2533 // Dump the module state
2534 cmd = "gws.dump";
2535 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2536 cmd = "gwc.dump";
2537 TEST_ASSERT(cr.execute(cmd, NLMISC::InfoLog()));
2539 // cleanup modules
2540 mm.deleteModule(mods);
2541 TEST_ASSERT(mm.getLocalModule("gws") == NULL);
2542 mm.deleteModule(modc);
2543 TEST_ASSERT(mm.getLocalModule("gwc") == NULL);
2546 void connectGateways()
2548 NLNET::IModuleManager &mm = NLNET::IModuleManager::getInstance();
2550 NLNET::IModule *mods = mm.createModule("StandardGateway", "gws", "");
2551 TEST_ASSERT(mods != NULL);
2552 NLNET::IModuleGateway *gws = dynamic_cast<NLNET::IModuleGateway*>(mods);
2553 TEST_ASSERT(gws != NULL);
2554 // add transport for server mode
2555 string cmd = "gws.transportAdd L3Server l3s";
2556 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2557 cmd = "gws.transportCmd l3s(open port=6185)";
2558 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2560 NLNET::IModule *modc1 = mm.createModule("StandardGateway", "gwc1", "");
2561 TEST_ASSERT(modc1 != NULL);
2562 NLNET::IModuleGateway *gwc1 = dynamic_cast<NLNET::IModuleGateway*>(modc1);
2563 TEST_ASSERT(gwc1 != NULL);
2564 // add transport for client mode
2565 cmd = "gwc1.transportAdd L3Client l3c";
2566 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2567 cmd = "gwc1.transportCmd l3c(connect addr=localhost:6185)";
2568 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2570 for (uint i=0; i<4; ++i)
2572 mm.updateModules();
2573 NLMISC::nlSleep(100);
2576 TEST_ASSERT(gws->getRouteCount() == 1);
2577 TEST_ASSERT(gwc1->getRouteCount() == 1);
2579 // do a second connect to the server for stress
2580 // add transport for client mode
2581 cmd = "gwc1.transportCmd l3c(connect addr=localhost:6185)";
2582 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2584 // create third gateway
2585 NLNET::IModule *modc2 = mm.createModule("StandardGateway", "gwc2", "");
2586 TEST_ASSERT(modc2 != NULL);
2587 NLNET::IModuleGateway *gwc2 = dynamic_cast<NLNET::IModuleGateway*>(modc2);
2588 TEST_ASSERT(gwc2 != NULL);
2589 // add transport for client mode
2590 cmd = "gwc2.transportAdd L3Client l3c";
2591 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2592 cmd = "gwc2.transportCmd l3c(connect addr=localhost:6185)";
2593 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2595 // update the module to update the network callback client and server
2596 for (uint i=0; i<4; ++i)
2598 // give some time to the listen and receiver thread to do there jobs
2599 NLMISC::nlSleep(100);
2600 mm.updateModules();
2603 TEST_ASSERT(gws->getRouteCount() == 3);
2604 TEST_ASSERT(gwc1->getRouteCount() == 2);
2605 TEST_ASSERT(gwc2->getRouteCount() == 1);
2607 // dump the gateways state
2608 cmd = "gws.dump";
2609 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2610 cmd = "gwc1.dump";
2611 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2612 cmd = "gwc2.dump";
2613 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2615 // cleanup the modules
2616 mm.deleteModule(mods);
2617 TEST_ASSERT(mm.getLocalModule("gws") == NULL);
2618 mm.deleteModule(modc1);
2619 TEST_ASSERT(mm.getLocalModule("gwc1") == NULL);
2620 mm.deleteModule(modc2);
2621 TEST_ASSERT(mm.getLocalModule("gwc2") == NULL);
2624 void gatewayTransportManagement()
2626 NLNET::IModuleManager &mm = NLNET::IModuleManager::getInstance();
2628 // create a gateway module
2629 NLNET::IModule *mod = mm.createModule("StandardGateway", "gw", "");
2630 TEST_ASSERT(mod != NULL);
2631 NLNET::IModuleGateway *gw = dynamic_cast<NLNET::IModuleGateway*>(mod);
2632 TEST_ASSERT(gw != NULL);
2634 // Create a layer 3 server transport
2635 // send a transport creation command
2636 string cmd = "gw.transportAdd L3Server l3s";
2637 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2638 NLNET::IGatewayTransport *transportL3s = gw->getGatewayTransport("l3s");
2639 TEST_ASSERT(transportL3s != NULL);
2641 // send a transport command
2642 cmd = "gw.transportCmd l3s(open port=6185)";
2643 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2645 // Create a layer 3 client transport
2646 // send a transport creation command
2647 cmd = "gw.transportAdd L3Client l3c";
2648 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2649 NLNET::IGatewayTransport *transportL3c = gw->getGatewayTransport("l3c");
2650 TEST_ASSERT(transportL3c != NULL);
2652 // send a transport command
2653 cmd = "gw.transportCmd l3c(connect addr=localhost:6185)";
2654 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2656 // update the module to update the network callback client and server
2657 for (uint i=0; i<4; ++i)
2659 // give some time to the listen and receiver thread to do there jobs
2660 mm.updateModules();
2661 NLMISC::nlSleep(100);
2664 TEST_ASSERT(transportL3s->getRouteCount() == 1);
2665 TEST_ASSERT(transportL3c->getRouteCount() == 1);
2666 TEST_ASSERT(gw->getRouteCount() == 2);
2668 // dump the gateways state
2669 cmd = "gw.dump";
2670 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2673 // close all connections
2674 cmd = "gw.transportCmd l3s(close)";
2675 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2677 cmd = "gw.transportCmd l3c(close connId=0)";
2678 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2680 // update the module to update the network callback client and server
2681 for (uint i=0; i<4; ++i)
2683 // give some time to the listen and receiver thread to do there jobs
2684 mm.updateModules();
2685 NLMISC::nlSleep(100);
2688 TEST_ASSERT(transportL3s->getRouteCount() == 0);
2689 TEST_ASSERT(transportL3c->getRouteCount() == 0);
2690 TEST_ASSERT(gw->getRouteCount() == 0);
2692 // Remove transports
2693 cmd = "gw.transportRemove l3s";
2694 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2695 cmd = "gw.transportRemove l3c";
2696 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2698 TEST_ASSERT(gw->getGatewayTransport("l3c") == NULL);
2699 TEST_ASSERT(gw->getGatewayTransport("l3s") == NULL);
2700 TEST_ASSERT(gw->getTransportCount() == 0);
2702 // update the module to update the network callback client and server
2703 for (uint i=0; i<4; ++i)
2705 // give some time to the listen and receiver thread to do there jobs
2706 mm.updateModules();
2707 NLMISC::nlSleep(100);
2710 // cleanup the modules
2711 mm.deleteModule(mod);
2712 TEST_ASSERT(mm.getLocalModule("gw") == NULL);
2715 /* void moduleManagerCommands()
2717 string cmd;
2718 // load a library
2719 cmd = "moduleManager.loadLibrary net_module_lib_test/net_module_lib_test";
2720 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2722 // dump the module state
2723 cmd = "moduleManager.dump";
2724 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2726 // create a module
2727 cmd = "moduleManager.createModule ModuleType1 AModuleName";
2728 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2730 // dump the module state
2731 cmd = "moduleManager.dump";
2732 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2734 // delete the module
2735 cmd = "moduleManager.deleteModule AModuleName";
2736 TEST_ASSERT(NLMISC::CCommandRegistry::getInstance().execute(cmd, NLMISC::InfoLog()));
2739 void plugLocalGateway()
2741 NLNET::IModuleManager &mm = NLNET::IModuleManager::getInstance();
2743 NLNET::IModule *gateway1 = mm.createModule("LocalGateway", "g1", "");
2744 TEST_ASSERT(gateway1 != NULL);
2745 NLNET::IModule *gateway2 = mm.createModule("LocalGateway", "g2", "");
2746 TEST_ASSERT(gateway2 != NULL);
2748 NLNET::IModuleSocket *socket1 = mm.getModuleSocket("g1");
2749 TEST_ASSERT(socket1 != NULL);
2750 NLNET::IModuleSocket *socket2 = mm.getModuleSocket("g2");
2751 TEST_ASSERT(socket2 != NULL);
2752 gateway1->plugModule(socket1);
2753 gateway1->plugModule(socket2);
2754 gateway2->plugModule(socket1);
2755 gateway2->plugModule(socket2);
2757 mm.deleteModule(gateway1);
2758 TEST_ASSERT(mm.getLocalModule("g1") == NULL);
2759 mm.deleteModule(gateway2);
2760 TEST_ASSERT(mm.getLocalModule("g2") == NULL);
2763 void createLocalGateway()
2765 NLNET::IModuleManager &mm = NLNET::IModuleManager::getInstance();
2767 NLNET::IModule *gateway = mm.createModule("LocalGateway", "localGateway", "");
2768 TEST_ASSERT(gateway != NULL);
2770 NLNET::IModule *mod1 = mm.createModule("ModuleType0", "plugged1", "");
2771 TEST_ASSERT(mod1 != NULL);
2772 NLNET::IModule *mod2 = mm.createModule("ModuleType0", "plugged2", "");
2773 TEST_ASSERT(mod2 != NULL);
2775 NLNET::IModuleSocket *socket = mm.getModuleSocket("localGateway");
2776 TEST_ASSERT(socket != NULL);
2777 mod1->plugModule(socket);
2778 mod2->plugModule(socket);
2780 mm.deleteModule(mod1);
2781 TEST_ASSERT(mm.getLocalModule("plugged1") == NULL);
2782 mm.deleteModule(mod2);
2783 TEST_ASSERT(mm.getLocalModule("plugged2") == NULL);
2785 mm.deleteModule(gateway);
2786 TEST_ASSERT(mm.getLocalModule("localGateway") == NULL);
2789 /* void unloadModuleLib()
2791 IModuleManager &mm = IModuleManager::getInstance();
2793 CRefPtr<IModule> module1 = mm.createModule("ModuleType1", "TheModule2", "the args");
2794 TEST_ASSERT(module1 != NULL);
2796 TEST_ASSERT(mm.unloadModuleLibrary("net_module_lib_test"));
2798 // the module must have been deleted
2799 TEST_ASSERT(module1 == NULL);
2801 TModulePtr module2 = mm.createModule("ModuleType1", "TheModuleThatCantBeCreated", "the args");
2802 TEST_ASSERT(module2 == NULL);
2805 void failedInit()
2807 NLNET::IModuleManager &mm = NLNET::IModuleManager::getInstance();
2809 NLNET::IModule *module = mm.createModule("ModuleType0", "FailingInit", "FAIL");
2810 TEST_ASSERT(module == NULL);
2813 /* void deleteModule()
2815 IModuleManager &mm = IModuleManager::getInstance();
2817 IModule *module = mm.createModule("ModuleType1", "TheModuleToDelete", "the args");
2818 TEST_ASSERT(module != NULL);
2820 CRefPtr<IModule> checkPtr(module);
2822 mm.deleteModule(module);
2823 TEST_ASSERT(checkPtr == NULL);
2826 /* void createModule()
2828 IModuleManager &mm = IModuleManager::getInstance();
2830 TModulePtr module = mm.createModule("ModuleType1", "TheModule", "the args");
2831 TEST_ASSERT(module != NULL);
2833 TEST_ASSERT(module->getModuleClassName() == "ModuleType1");
2834 TEST_ASSERT(module->getModuleName() == "TheModule");
2836 string lh;
2837 if (IService::isServiceInitialized())
2838 lh = IService::getInstance()->getHostName();
2839 else
2840 lh = ::NLNET::CInetAddress::localHost().hostName();
2841 string fqmn = lh+":"+toString(getpid())+":TheModule";
2843 TEST_ASSERT(module->getModuleFullyQualifiedName() == fqmn);
2846 /* void loadModuleLib()
2848 string moduleLibName = "net_module_lib_test/net_module_lib_test";
2850 IModuleManager &mm = IModuleManager::getInstance();
2851 TEST_ASSERT(mm.loadModuleLibrary(moduleLibName));
2853 vector<string> moduleList;
2854 mm.getAvailableModuleClassList(moduleList);
2856 TEST_ASSERT(moduleList.size() == 6);
2857 TEST_ASSERT(moduleList[0] == "LocalGateway");
2858 TEST_ASSERT(moduleList[1] == "ModuleAsync");
2859 TEST_ASSERT(moduleList[2] == "ModuleType0");
2860 TEST_ASSERT(moduleList[3] == "ModuleType1");
2861 TEST_ASSERT(moduleList[4] == "ModuleType2");
2862 TEST_ASSERT(moduleList[5] == "StandardGateway");
2865 void localModuleFactory()
2867 NLNET::IModuleManager &mm = NLNET::IModuleManager::getInstance();
2869 vector<string> moduleList;
2870 mm.getAvailableModuleClassList(moduleList);
2872 TEST_ASSERT(moduleList.size() == 4);
2873 TEST_ASSERT(moduleList[0] == "LocalGateway");
2874 TEST_ASSERT(moduleList[1] == "ModuleAsync");
2875 TEST_ASSERT(moduleList[2] == "ModuleType0");
2876 TEST_ASSERT(moduleList[3] == "StandardGateway");
2879 void testModuleInitInfoBadParsing()
2881 NLNET::TParsedCommandLine mif;
2883 string paramString = " a=1 b=2 ( b=1) ";
2884 TEST_ASSERT(!mif.parseParamList(paramString));
2886 paramString = " lswkd ,fpqoj(( cruq fzemfwijf ujr wmozejifp_zujf woijpc_u ' ";
2887 TEST_ASSERT(!mif.parseParamList(paramString));
2889 paramString = "a ( b=2";
2890 TEST_ASSERT(!mif.parseParamList(paramString));
2892 paramString = "a b=2)";
2893 TEST_ASSERT(!mif.parseParamList(paramString));
2895 paramString = "a b=2\"toto\"";
2896 TEST_ASSERT(!mif.parseParamList(paramString));
2898 paramString = "=a";
2899 TEST_ASSERT(!mif.parseParamList(paramString));
2901 paramString = "a(=b)";
2902 TEST_ASSERT(!mif.parseParamList(paramString));
2905 void testModuleInitInfoQuering()
2907 NLNET::TParsedCommandLine mif;
2909 string paramString = " a=1 b=2 sub ( y=22 zzzz=12 subsub (g=\"bean in box\" z=2) ) ";
2911 TEST_ASSERT(mif.parseParamList(paramString));
2913 TEST_ASSERT(mif.getParam("a") != NULL);
2914 TEST_ASSERT(mif.getParam("a") == mif.SubParams[0]);
2916 TEST_ASSERT(mif.getParam("sub") != NULL);
2917 TEST_ASSERT(mif.getParam("sub") == mif.SubParams[2]);
2919 TEST_ASSERT(mif.getParam("foo") == NULL);
2921 TEST_ASSERT(mif.getParam("sub.subsub.g") != NULL);
2922 TEST_ASSERT(mif.getParam("sub.subsub.g") == mif.SubParams[2]->SubParams[2]->SubParams[0]);
2925 void testModuleInitInfoParsing()
2927 NLNET::TParsedCommandLine mif;
2929 string paramString = "a";
2930 TEST_ASSERT(mif.parseParamList(paramString));
2931 paramString = "a=1";
2932 TEST_ASSERT(mif.parseParamList(paramString));
2933 paramString = "a(b=1)";
2934 TEST_ASSERT(mif.parseParamList(paramString));
2935 paramString = "a a a a";
2936 TEST_ASSERT(mif.parseParamList(paramString));
2937 TEST_ASSERT(mif.SubParams.size() == 4);
2938 paramString = " a ( b=1 )";
2939 TEST_ASSERT(mif.parseParamList(paramString));
2941 paramString = " a=1 b=2 sub ( y=22 zzzz=12 subsub (g=\"bean in box\" z=2) ) ";
2943 TEST_ASSERT(mif.parseParamList(paramString));
2945 TEST_ASSERT(mif.SubParams.size() == 3);
2947 TEST_ASSERT(mif.SubParams[0]->SubParams.size() == 0);
2948 TEST_ASSERT(mif.SubParams[0]->ParamName == "a");
2949 TEST_ASSERT(mif.SubParams[0]->ParamValue == "1");
2951 TEST_ASSERT(mif.SubParams[1]->SubParams.size() == 0);
2952 TEST_ASSERT(mif.SubParams[1]->ParamName == "b");
2953 TEST_ASSERT(mif.SubParams[1]->ParamValue == "2");
2955 TEST_ASSERT(mif.SubParams[2]->SubParams.size() == 3);
2956 TEST_ASSERT(mif.SubParams[2]->ParamName == "sub");
2957 TEST_ASSERT(mif.SubParams[2]->ParamValue.empty());
2959 TEST_ASSERT(mif.SubParams[2]->SubParams[0]->SubParams.size() == 0);
2960 TEST_ASSERT(mif.SubParams[2]->SubParams[0]->ParamName == "y");
2961 TEST_ASSERT(mif.SubParams[2]->SubParams[0]->ParamValue == "22");
2963 TEST_ASSERT(mif.SubParams[2]->SubParams[1]->SubParams.size() == 0);
2964 TEST_ASSERT(mif.SubParams[2]->SubParams[1]->ParamName == "zzzz");
2965 TEST_ASSERT(mif.SubParams[2]->SubParams[1]->ParamValue == "12");
2967 TEST_ASSERT(mif.SubParams[2]->SubParams[2]->SubParams.size() == 2);
2968 TEST_ASSERT(mif.SubParams[2]->SubParams[2]->ParamName == "subsub");
2969 TEST_ASSERT(mif.SubParams[2]->SubParams[2]->ParamValue.empty());
2971 TEST_ASSERT(mif.SubParams[2]->SubParams[2]->SubParams[0]->SubParams.size() == 0);
2972 TEST_ASSERT(mif.SubParams[2]->SubParams[2]->SubParams[0]->ParamName == "g");
2973 TEST_ASSERT(mif.SubParams[2]->SubParams[2]->SubParams[0]->ParamValue == "bean in box");
2975 TEST_ASSERT(mif.SubParams[2]->SubParams[2]->SubParams[1]->SubParams.size() == 0);
2976 TEST_ASSERT(mif.SubParams[2]->SubParams[2]->SubParams[1]->ParamName == "z");
2977 TEST_ASSERT(mif.SubParams[2]->SubParams[2]->SubParams[1]->ParamValue == "2");
2981 #endif