blob: b256432e1cd3fa0915f37cc0f760d26072c17f3d [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"
Junxiao Shid9ee45c2014-02-27 15:38:11 -07009#include "tests/face/dummy-face.hpp"
Junxiao Shi727ed292014-02-19 23:26:45 -070010
Junxiao Shid9ee45c2014-02-27 15:38:11 -070011#include "tests/test-common.hpp"
Junxiao Shi727ed292014-02-19 23:26:45 -070012
13namespace nfd {
Junxiao Shid9ee45c2014-02-27 15:38:11 -070014namespace tests {
Junxiao Shi727ed292014-02-19 23:26:45 -070015
Junxiao Shid9ee45c2014-02-27 15:38:11 -070016BOOST_FIXTURE_TEST_SUITE(FwBroadcastStrategy, BaseFixture)
Junxiao Shi727ed292014-02-19 23:26:45 -070017
18BOOST_AUTO_TEST_CASE(ForwardTwo)
19{
Junxiao Shic041ca32014-02-25 20:01:15 -070020 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 Forwarder forwarder;
Junxiao Shi727ed292014-02-19 23:26:45 -070064 typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester;
65 BroadcastStrategyTester strategy(forwarder);
66
67 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
68 forwarder.addFace(face1);
69
70 Fib& fib = forwarder.getFib();
71 std::pair<shared_ptr<fib::Entry>, bool> fibInsertResult = fib.insert(Name());
72 shared_ptr<fib::Entry> fibEntry = fibInsertResult.first;
73 fibEntry->addNextHop(face1, 0);
74
75 Interest interest(Name("ndn:/H0D6i5fc"));
76 Pit& pit = forwarder.getPit();
77 std::pair<shared_ptr<pit::Entry>, bool> pitInsertResult = pit.insert(interest);
78 shared_ptr<pit::Entry> pitEntry = pitInsertResult.first;
79
80 strategy.afterReceiveInterest(*face1, interest, fibEntry, pitEntry);
Junxiao Shi09498f02014-02-26 19:41:08 -070081 BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1);
Junxiao Shi727ed292014-02-19 23:26:45 -070082 BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0);
83}
84
85BOOST_AUTO_TEST_SUITE_END()
86
Junxiao Shid9ee45c2014-02-27 15:38:11 -070087} // namespace tests
Junxiao Shi727ed292014-02-19 23:26:45 -070088} // namespace nfd