blob: 26d068723d2ac5b698cdca512d67e23b7d88719e [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{
Junxiao Shic041ca32014-02-25 20:01:15 -070019 resetGlobalIoService();
20 Forwarder forwarder;
Junxiao Shi727ed292014-02-19 23:26:45 -070021 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);
Junxiao Shi09498f02014-02-26 19:41:08 -070044 BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 0);
Junxiao Shi727ed292014-02-19 23:26:45 -070045 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
Junxiao Shi09498f02014-02-26 19:41:08 -070061BOOST_AUTO_TEST_CASE(Reject)
Junxiao Shi727ed292014-02-19 23:26:45 -070062{
Junxiao Shic041ca32014-02-25 20:01:15 -070063 resetGlobalIoService();
64 Forwarder forwarder;
Junxiao Shi727ed292014-02-19 23:26:45 -070065 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);
Junxiao Shi09498f02014-02-26 19:41:08 -070082 BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1);
Junxiao Shi727ed292014-02-19 23:26:45 -070083 BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0);
84}
85
86BOOST_AUTO_TEST_SUITE_END()
87
88} // namespace nfd