blob: 3976f625152b5899f4cc5aa95b83424e746e1bd6 [file] [log] [blame]
Junxiao Shi727ed292014-02-19 23:26:45 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "fw/broadcast-strategy.hpp"
8#include "strategy-tester.hpp"
9#include "../face/dummy-face.hpp"
10
11#include <boost/test/unit_test.hpp>
12
13namespace nfd {
14
15BOOST_AUTO_TEST_SUITE(FwBroadcastStrategy)
16
17BOOST_AUTO_TEST_CASE(ForwardTwo)
18{
19 boost::asio::io_service io;
20 Forwarder forwarder(io);
21 typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester;
22 BroadcastStrategyTester strategy(forwarder);
23
24 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
25 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
26 shared_ptr<DummyFace> face3 = make_shared<DummyFace>();
27 forwarder.addFace(face1);
28 forwarder.addFace(face2);
29 forwarder.addFace(face3);
30
31 Fib& fib = forwarder.getFib();
32 std::pair<shared_ptr<fib::Entry>, bool> fibInsertResult = fib.insert(Name());
33 shared_ptr<fib::Entry> fibEntry = fibInsertResult.first;
34 fibEntry->addNextHop(face1, 0);
35 fibEntry->addNextHop(face2, 0);
36 fibEntry->addNextHop(face3, 0);
37
38 Interest interest(Name("ndn:/H0D6i5fc"));
39 Pit& pit = forwarder.getPit();
40 std::pair<shared_ptr<pit::Entry>, bool> pitInsertResult = pit.insert(interest);
41 shared_ptr<pit::Entry> pitEntry = pitInsertResult.first;
42
43 strategy.afterReceiveInterest(*face3, interest, fibEntry, pitEntry);
44 BOOST_CHECK_EQUAL(strategy.m_rebuffPendingInterestHistory.size(), 0);
45 BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 2);
46 bool hasFace1 = false;
47 bool hasFace2 = false;
48 for (std::vector<BroadcastStrategyTester::SendInterestArgs>::iterator it =
49 strategy.m_sendInterestHistory.begin();
50 it != strategy.m_sendInterestHistory.end(); ++it) {
51 if (it->get<1>() == face1) {
52 hasFace1 = true;
53 }
54 if (it->get<1>() == face2) {
55 hasFace2 = true;
56 }
57 }
58 BOOST_CHECK(hasFace1 && hasFace2);
59}
60
61BOOST_AUTO_TEST_CASE(Rebuff)
62{
63 boost::asio::io_service io;
64 Forwarder forwarder(io);
65 typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester;
66 BroadcastStrategyTester strategy(forwarder);
67
68 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
69 forwarder.addFace(face1);
70
71 Fib& fib = forwarder.getFib();
72 std::pair<shared_ptr<fib::Entry>, bool> fibInsertResult = fib.insert(Name());
73 shared_ptr<fib::Entry> fibEntry = fibInsertResult.first;
74 fibEntry->addNextHop(face1, 0);
75
76 Interest interest(Name("ndn:/H0D6i5fc"));
77 Pit& pit = forwarder.getPit();
78 std::pair<shared_ptr<pit::Entry>, bool> pitInsertResult = pit.insert(interest);
79 shared_ptr<pit::Entry> pitEntry = pitInsertResult.first;
80
81 strategy.afterReceiveInterest(*face1, interest, fibEntry, pitEntry);
82 BOOST_CHECK_EQUAL(strategy.m_rebuffPendingInterestHistory.size(), 1);
83 BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0);
84}
85
86BOOST_AUTO_TEST_SUITE_END()
87
88} // namespace nfd