blob: 9c69c10ee626d266528ecc9f166d1e3431f8b6c7 [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
Junxiao Shi57f0f312014-03-16 11:52:20 -070018BOOST_AUTO_TEST_CASE(Forward2)
Junxiao Shi727ed292014-02-19 23:26:45 -070019{
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();
Junxiao Shi57f0f312014-03-16 11:52:20 -070032 shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
Junxiao Shi727ed292014-02-19 23:26:45 -070033 fibEntry->addNextHop(face1, 0);
34 fibEntry->addNextHop(face2, 0);
35 fibEntry->addNextHop(face3, 0);
36
Junxiao Shi57f0f312014-03-16 11:52:20 -070037 shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc");
Junxiao Shi727ed292014-02-19 23:26:45 -070038 Pit& pit = forwarder.getPit();
Junxiao Shi57f0f312014-03-16 11:52:20 -070039 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
40 pitEntry->insertOrUpdateInRecord(face3, *interest);
Junxiao Shi727ed292014-02-19 23:26:45 -070041
Junxiao Shi57f0f312014-03-16 11:52:20 -070042 strategy.afterReceiveInterest(*face3, *interest, fibEntry, pitEntry);
Junxiao Shi09498f02014-02-26 19:41:08 -070043 BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 0);
Junxiao Shi727ed292014-02-19 23:26:45 -070044 BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 2);
45 bool hasFace1 = false;
46 bool hasFace2 = false;
47 for (std::vector<BroadcastStrategyTester::SendInterestArgs>::iterator it =
48 strategy.m_sendInterestHistory.begin();
49 it != strategy.m_sendInterestHistory.end(); ++it) {
50 if (it->get<1>() == face1) {
51 hasFace1 = true;
52 }
53 if (it->get<1>() == face2) {
54 hasFace2 = true;
55 }
56 }
57 BOOST_CHECK(hasFace1 && hasFace2);
58}
59
Junxiao Shi57f0f312014-03-16 11:52:20 -070060BOOST_AUTO_TEST_CASE(RejectScope)
61{
62 Forwarder forwarder;
63 typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester;
64 BroadcastStrategyTester strategy(forwarder);
65
66 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
67 shared_ptr<DummyFace> face2 = make_shared<DummyFace>();
68 forwarder.addFace(face1);
69 forwarder.addFace(face2);
70
71 Fib& fib = forwarder.getFib();
72 shared_ptr<fib::Entry> fibEntry = fib.insert("ndn:/localhop/uS09bub6tm").first;
73 fibEntry->addNextHop(face2, 0);
74
75 shared_ptr<Interest> interest = makeInterest("ndn:/localhop/uS09bub6tm/eG3MMoP6z");
76 Pit& pit = forwarder.getPit();
77 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
78 pitEntry->insertOrUpdateInRecord(face1, *interest);
79
80 strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry);
81 BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1);
82 BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0);
83}
84
85BOOST_AUTO_TEST_CASE(RejectLoopback)
Junxiao Shi727ed292014-02-19 23:26:45 -070086{
Junxiao Shic041ca32014-02-25 20:01:15 -070087 Forwarder forwarder;
Junxiao Shi727ed292014-02-19 23:26:45 -070088 typedef StrategyTester<fw::BroadcastStrategy> BroadcastStrategyTester;
89 BroadcastStrategyTester strategy(forwarder);
90
91 shared_ptr<DummyFace> face1 = make_shared<DummyFace>();
92 forwarder.addFace(face1);
93
94 Fib& fib = forwarder.getFib();
Junxiao Shi57f0f312014-03-16 11:52:20 -070095 shared_ptr<fib::Entry> fibEntry = fib.insert(Name()).first;
Junxiao Shi727ed292014-02-19 23:26:45 -070096 fibEntry->addNextHop(face1, 0);
97
Junxiao Shi57f0f312014-03-16 11:52:20 -070098 shared_ptr<Interest> interest = makeInterest("ndn:/H0D6i5fc");
Junxiao Shi727ed292014-02-19 23:26:45 -070099 Pit& pit = forwarder.getPit();
Junxiao Shi57f0f312014-03-16 11:52:20 -0700100 shared_ptr<pit::Entry> pitEntry = pit.insert(*interest).first;
101 pitEntry->insertOrUpdateInRecord(face1, *interest);
Junxiao Shi727ed292014-02-19 23:26:45 -0700102
Junxiao Shi57f0f312014-03-16 11:52:20 -0700103 strategy.afterReceiveInterest(*face1, *interest, fibEntry, pitEntry);
Junxiao Shi09498f02014-02-26 19:41:08 -0700104 BOOST_CHECK_EQUAL(strategy.m_rejectPendingInterestHistory.size(), 1);
Junxiao Shi727ed292014-02-19 23:26:45 -0700105 BOOST_CHECK_EQUAL(strategy.m_sendInterestHistory.size(), 0);
106}
107
108BOOST_AUTO_TEST_SUITE_END()
109
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700110} // namespace tests
Junxiao Shi727ed292014-02-19 23:26:45 -0700111} // namespace nfd