4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Route.test unit tests */
26 //#include "Route.test.hh"
27 //#include "Route.test.ih"
31 #include "DebugEvent.hh"
32 #include "DebugModules.hh"
36 #include "../Utils/auto_unit_test.hh"
37 #include <boost/test/test_tools.hpp>
40 ///////////////////////////////cc.p////////////////////////////////////////
42 namespace ppi = senf::ppi;
43 namespace connector = ppi::connector;
44 namespace module = ppi::module;
45 namespace debug = module::debug;
48 class RouteTester : public module::Module
50 SENF_PPI_MODULE(RouteTester);
53 connector::ActiveInput<> activeIn;
54 connector::PassiveInput<> passiveIn;
56 connector::ActiveOutput<> activeOut;
57 connector::PassiveOutput<> passiveOut;
59 ppi::DebugEvent event;
61 ppi::ForwardingRoute * rt;
63 RouteTester() : events(0), throttles(0) {
64 route( activeIn, activeOut ); // non-forwarding
65 rt = & route( activeIn, passiveOut ); // forward throttling
66 route( passiveIn, activeOut ); // backward throttling
67 route( passiveIn, passiveOut ); // non-forwarding
68 route( event, activeOut ); // forward event throttling
69 route( activeIn, event ); // backward event throttling
71 passiveIn.onRequest(&RouteTester::inputRequest);
72 passiveOut.onRequest(&RouteTester::outputRequest);
73 registerEvent(event, &RouteTester::onEvent);
75 activeIn.onThrottle(&RouteTester::throttleRequest);
76 activeIn.onUnthrottle(&RouteTester::unthrottleRequest);
77 activeOut.onThrottle(&RouteTester::throttleRequest);
78 activeOut.onUnthrottle(&RouteTester::unthrottleRequest);
82 activeOut(passiveIn());
85 void outputRequest() {
86 passiveOut(activeIn());
93 void throttleRequest() {
97 void unthrottleRequest() {
106 BOOST_AUTO_UNIT_TEST(route)
108 debug::PassiveSource passiveSource;
109 debug::ActiveSource activeSource;
110 debug::PassiveSink passiveSink;
111 debug::ActiveSink activeSink;
114 ppi::connect(passiveSource, tester.activeIn);
115 ppi::connect(activeSource, tester.passiveIn);
116 ppi::connect(tester.activeOut, passiveSink);
117 ppi::connect(tester.passiveOut, activeSink);
121 senf::Packet p1 (senf::DataPacket::create());
122 senf::Packet p2 (senf::DataPacket::create());
124 passiveSource.submit(p1);
125 activeSource.submit(p2);
127 BOOST_CHECK( p2 == passiveSink.front() );
129 // The passive source is not throttled at this point since it has packets in queue
131 passiveSink.input.throttle();
132 BOOST_CHECK( passiveSink.input.throttled() );
133 BOOST_CHECK( ! tester.activeOut );
134 BOOST_CHECK_EQUAL( tester.throttles, 1 );
135 BOOST_CHECK( tester.passiveIn.throttled() );
136 BOOST_CHECK( ! activeSource );
137 BOOST_CHECK( ! tester.event.enabled() );
139 passiveSink.input.unthrottle();
140 BOOST_CHECK( activeSource );
141 BOOST_CHECK( tester.event.enabled() );
143 // Now throttle the passive source by exhausting the queue
145 BOOST_CHECK( p1 == activeSink.request() );
146 BOOST_CHECK( passiveSource.output.throttled() );
147 BOOST_CHECK( ! tester.activeIn );
148 BOOST_CHECK_EQUAL( tester.throttles, 1 );
149 BOOST_CHECK( tester.passiveOut.throttled() );
150 BOOST_CHECK( ! activeSink );
151 BOOST_CHECK( ! tester.event.enabled() );
153 passiveSource.submit(p1);
154 BOOST_CHECK( activeSink );
155 BOOST_CHECK( tester.event.enabled() );
157 // Check correct combination of multiple throttling events
159 activeSink.request();
160 BOOST_CHECK( ! tester.event.enabled() );
161 passiveSink.input.throttle();
162 BOOST_CHECK( ! tester.event.enabled() );
163 passiveSource.submit(p1);
164 BOOST_CHECK( ! tester.event.enabled() );
165 passiveSink.input.unthrottle();
166 BOOST_CHECK( tester.event.enabled() );
168 tester.rt->autoThrottling(false);
170 BOOST_CHECK( p1 == activeSink.request() );
171 BOOST_CHECK( passiveSource.output.throttled() );
172 BOOST_CHECK( activeSink );
175 ///////////////////////////////cc.e////////////////////////////////////////
182 // comment-column: 40
183 // c-file-style: "senf"
184 // indent-tabs-mode: nil
185 // ispell-local-dictionary: "american"
186 // compile-command: "scons -u test"