blob: 6ac4a7fe349cae4ba80637ea3c6ca7aa5bbe18e9 [file] [log] [blame]
Steve DiBenedetto042bfe92014-01-30 15:05:08 -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 "mgmt/fib-manager.hpp"
8#include "fw/forwarder.hpp"
9#include "table/fib.hpp"
10#include "face/face.hpp"
Steve DiBenedetto3970c892014-01-31 23:31:13 -070011#include "mgmt/internal-face.hpp"
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070012#include "../face/dummy-face.hpp"
13
14#include <ndn-cpp-dev/management/fib-management-options.hpp>
15
16#include <boost/test/unit_test.hpp>
17
Steve DiBenedetto3970c892014-01-31 23:31:13 -070018static nfd::FaceId g_faceCount = 1;
19static std::vector<nfd::shared_ptr<nfd::Face> > g_faces;
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070020
Steve DiBenedetto3970c892014-01-31 23:31:13 -070021static nfd::shared_ptr<nfd::Face>
22getFace(nfd::FaceId id)
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070023{
24 if (g_faces.size() < id)
25 {
26 BOOST_FAIL("Attempted to access invalid FaceId: " << id);
27 }
28 return g_faces[id-1];
29}
30
Steve DiBenedetto3970c892014-01-31 23:31:13 -070031// namespace nfd {
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070032
Steve DiBenedetto3970c892014-01-31 23:31:13 -070033// NFD_LOG_INIT("FibManagerTest");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070034
Steve DiBenedetto3970c892014-01-31 23:31:13 -070035// BOOST_AUTO_TEST_SUITE(MgmtFibManager)
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070036
Steve DiBenedetto3970c892014-01-31 23:31:13 -070037// BOOST_AUTO_TEST_CASE(MalformedCommmand)
38// {
39// shared_ptr<InternalFace> face(new InternalFace);
40// Fib fib;
41// FibManager manager(fib, &getFace, face);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070042
Steve DiBenedetto3970c892014-01-31 23:31:13 -070043// Interest command(manager.getRequestPrefix());
44// manager.onFibRequest(command);
45// }
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070046
Steve DiBenedetto3970c892014-01-31 23:31:13 -070047// BOOST_AUTO_TEST_CASE(UnsupportedVerb)
48// {
49// shared_ptr<InternalFace> face(new InternalFace);
50// Fib fib;
51// FibManager manager(fib, &getFace, face);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070052
Steve DiBenedetto3970c892014-01-31 23:31:13 -070053// ndn::FibManagementOptions options;
54// options.setName("/hello");
55// options.setFaceId(1);
56// options.setCost(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070057
Steve DiBenedetto3970c892014-01-31 23:31:13 -070058// Block encodedOptions(options.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070059
Steve DiBenedetto3970c892014-01-31 23:31:13 -070060// Name commandName(manager.getRequestPrefix());
61// commandName.append("unsupported");
62// commandName.append(encodedOptions);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070063
Steve DiBenedetto3970c892014-01-31 23:31:13 -070064// Interest command(commandName);
65// manager.onFibRequest(command);
66// }
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070067
Steve DiBenedetto3970c892014-01-31 23:31:13 -070068// BOOST_AUTO_TEST_CASE(AddNextHopVerbInitialAdd)
69// {
70// g_faceCount = 1;
71// g_faces.clear();
72// g_faces.push_back(make_shared<DummyFace>());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070073
Steve DiBenedetto3970c892014-01-31 23:31:13 -070074// shared_ptr<InternalFace> face(new InternalFace);
75// Fib fib;
76// FibManager manager(fib, &getFace, face);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070077
Steve DiBenedetto3970c892014-01-31 23:31:13 -070078// ndn::FibManagementOptions options;
79// options.setName("/hello");
80// options.setFaceId(1);
81// options.setCost(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070082
Steve DiBenedetto3970c892014-01-31 23:31:13 -070083// Block encodedOptions(options.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070084
Steve DiBenedetto3970c892014-01-31 23:31:13 -070085// Name commandName(manager.getRequestPrefix());
86// commandName.append("add-nexthop");
87// commandName.append(encodedOptions);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070088
Steve DiBenedetto3970c892014-01-31 23:31:13 -070089// Interest command(commandName);
90// manager.onFibRequest(command);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070091
Steve DiBenedetto3970c892014-01-31 23:31:13 -070092// shared_ptr<fib::Entry> entry = fib.findLongestPrefixMatch("/hello");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -070093
Steve DiBenedetto3970c892014-01-31 23:31:13 -070094// if (entry)
95// {
96// const fib::NextHopList& hops = entry->getNextHops();
97// BOOST_REQUIRE(hops.size() == 1);
98// // BOOST_CHECK(hops[0].getFace()->getFaceId() == 1);
99// BOOST_CHECK(hops[0].getCost() == 1);
100// }
101// else
102// {
103// BOOST_FAIL("Failed to find expected fib entry");
104// }
105// }
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700106
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700107// BOOST_AUTO_TEST_CASE(AddNextHopVerbAddToExisting)
108// {
109// g_faceCount = 1;
110// g_faces.clear();
111// g_faces.push_back(make_shared<DummyFace>());
112// g_faces.push_back(make_shared<DummyFace>());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700113
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700114// shared_ptr<InternalFace> face(new InternalFace);
115// Fib fib;
116// FibManager manager(fib, &getFace, face);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700117
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700118// // Add faces with cost == FaceID for the name /hello
119// // This test assumes:
120// // FaceIDs are assigned from 1 to N
121// // Faces are store sequentially in the NextHopList
122// // NextHopList supports random access
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700123
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700124// for (int i = 1; i <= 2; i++)
125// {
126// ndn::FibManagementOptions options;
127// options.setName("/hello");
128// options.setFaceId(i);
129// options.setCost(i);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700130
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700131// Block encodedOptions(options.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700132
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700133// Name commandName(manager.getRequestPrefix());
134// commandName.append("add-nexthop");
135// commandName.append(encodedOptions);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700136
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700137// Interest command(commandName);
138// manager.onFibRequest(command);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700139
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700140// shared_ptr<fib::Entry> entry = fib.findLongestPrefixMatch("/hello");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700141
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700142// if (entry)
143// {
144// const fib::NextHopList& hops = entry->getNextHops();
145// for (int j = 1; j <= i; j++)
146// {
147// BOOST_REQUIRE(hops.size() == i);
148// BOOST_CHECK(hops[j-1].getCost() == j);
149// }
150// }
151// else
152// {
153// BOOST_FAIL("Failed to find expected fib entry");
154// }
155// }
156// }
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700157
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700158// BOOST_AUTO_TEST_CASE(AddNextHopVerbUpdateFaceCost)
159// {
160// g_faceCount = 1;
161// g_faces.clear();
162// g_faces.push_back(make_shared<DummyFace>());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700163
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700164// shared_ptr<InternalFace> face(new InternalFace);
165// Fib fib;
166// FibManager manager(fib, &getFace, face);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700167
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700168// ndn::FibManagementOptions options;
169// options.setName("/hello");
170// options.setFaceId(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700171
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700172// {
173// options.setCost(1);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700174
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700175// Block encodedOptions(options.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700176
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700177// Name commandName(manager.getRequestPrefix());
178// commandName.append("add-nexthop");
179// commandName.append(encodedOptions);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700180
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700181// Interest command(commandName);
182// manager.onFibRequest(command);
183// }
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700184
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700185// {
186// options.setCost(2);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700187
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700188// Block encodedOptions(options.wireEncode());
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700189
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700190// Name commandName(manager.getRequestPrefix());
191// commandName.append("add-nexthop");
192// commandName.append(encodedOptions);
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700193
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700194// Interest command(commandName);
195// manager.onFibRequest(command);
196// }
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700197
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700198// shared_ptr<fib::Entry> entry = fib.findLongestPrefixMatch("/hello");
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700199
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700200// // Add faces with cost == FaceID for the name /hello
201// // This test assumes:
202// // FaceIDs are assigned from 1 to N
203// // Faces are store sequentially in the NextHopList
204// // NextHopList supports random access
205// if (entry)
206// {
207// const fib::NextHopList& hops = entry->getNextHops();
208// BOOST_REQUIRE(hops.size() == 1);
209// // BOOST_CHECK(hops[0].getFace()->getFaceId() == 1);
210// BOOST_CHECK(hops[0].getCost() == 2);
211// }
212// else
213// {
214// BOOST_FAIL("Failed to find expected fib entry");
215// }
216// }
Steve DiBenedetto042bfe92014-01-30 15:05:08 -0700217
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700218// BOOST_AUTO_TEST_SUITE_END()
219
220// } // namespace nfd