Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 1 | /* -*- 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 DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 11 | #include "mgmt/internal-face.hpp" |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 12 | #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 DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 18 | static nfd::FaceId g_faceCount = 1; |
| 19 | static std::vector<nfd::shared_ptr<nfd::Face> > g_faces; |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 20 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 21 | static nfd::shared_ptr<nfd::Face> |
| 22 | getFace(nfd::FaceId id) |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 23 | { |
| 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 DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 31 | // namespace nfd { |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 32 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 33 | // NFD_LOG_INIT("FibManagerTest"); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 34 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 35 | // BOOST_AUTO_TEST_SUITE(MgmtFibManager) |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 36 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 37 | // BOOST_AUTO_TEST_CASE(MalformedCommmand) |
| 38 | // { |
| 39 | // shared_ptr<InternalFace> face(new InternalFace); |
| 40 | // Fib fib; |
| 41 | // FibManager manager(fib, &getFace, face); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 42 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 43 | // Interest command(manager.getRequestPrefix()); |
| 44 | // manager.onFibRequest(command); |
| 45 | // } |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 46 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 47 | // BOOST_AUTO_TEST_CASE(UnsupportedVerb) |
| 48 | // { |
| 49 | // shared_ptr<InternalFace> face(new InternalFace); |
| 50 | // Fib fib; |
| 51 | // FibManager manager(fib, &getFace, face); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 52 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 53 | // ndn::FibManagementOptions options; |
| 54 | // options.setName("/hello"); |
| 55 | // options.setFaceId(1); |
| 56 | // options.setCost(1); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 57 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 58 | // Block encodedOptions(options.wireEncode()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 59 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 60 | // Name commandName(manager.getRequestPrefix()); |
| 61 | // commandName.append("unsupported"); |
| 62 | // commandName.append(encodedOptions); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 63 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 64 | // Interest command(commandName); |
| 65 | // manager.onFibRequest(command); |
| 66 | // } |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 67 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 68 | // BOOST_AUTO_TEST_CASE(AddNextHopVerbInitialAdd) |
| 69 | // { |
| 70 | // g_faceCount = 1; |
| 71 | // g_faces.clear(); |
| 72 | // g_faces.push_back(make_shared<DummyFace>()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 73 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 74 | // shared_ptr<InternalFace> face(new InternalFace); |
| 75 | // Fib fib; |
| 76 | // FibManager manager(fib, &getFace, face); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 77 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 78 | // ndn::FibManagementOptions options; |
| 79 | // options.setName("/hello"); |
| 80 | // options.setFaceId(1); |
| 81 | // options.setCost(1); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 82 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 83 | // Block encodedOptions(options.wireEncode()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 84 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 85 | // Name commandName(manager.getRequestPrefix()); |
| 86 | // commandName.append("add-nexthop"); |
| 87 | // commandName.append(encodedOptions); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 88 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 89 | // Interest command(commandName); |
| 90 | // manager.onFibRequest(command); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 91 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 92 | // shared_ptr<fib::Entry> entry = fib.findLongestPrefixMatch("/hello"); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 93 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 94 | // 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 DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 106 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 107 | // 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 DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 113 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 114 | // shared_ptr<InternalFace> face(new InternalFace); |
| 115 | // Fib fib; |
| 116 | // FibManager manager(fib, &getFace, face); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 117 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 118 | // // 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 DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 123 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 124 | // 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 DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 130 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 131 | // Block encodedOptions(options.wireEncode()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 132 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 133 | // Name commandName(manager.getRequestPrefix()); |
| 134 | // commandName.append("add-nexthop"); |
| 135 | // commandName.append(encodedOptions); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 136 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 137 | // Interest command(commandName); |
| 138 | // manager.onFibRequest(command); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 139 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 140 | // shared_ptr<fib::Entry> entry = fib.findLongestPrefixMatch("/hello"); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 141 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 142 | // 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 DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 157 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 158 | // BOOST_AUTO_TEST_CASE(AddNextHopVerbUpdateFaceCost) |
| 159 | // { |
| 160 | // g_faceCount = 1; |
| 161 | // g_faces.clear(); |
| 162 | // g_faces.push_back(make_shared<DummyFace>()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 163 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 164 | // shared_ptr<InternalFace> face(new InternalFace); |
| 165 | // Fib fib; |
| 166 | // FibManager manager(fib, &getFace, face); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 167 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 168 | // ndn::FibManagementOptions options; |
| 169 | // options.setName("/hello"); |
| 170 | // options.setFaceId(1); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 171 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 172 | // { |
| 173 | // options.setCost(1); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 174 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 175 | // Block encodedOptions(options.wireEncode()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 176 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 177 | // Name commandName(manager.getRequestPrefix()); |
| 178 | // commandName.append("add-nexthop"); |
| 179 | // commandName.append(encodedOptions); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 180 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 181 | // Interest command(commandName); |
| 182 | // manager.onFibRequest(command); |
| 183 | // } |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 184 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 185 | // { |
| 186 | // options.setCost(2); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 187 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 188 | // Block encodedOptions(options.wireEncode()); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 189 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 190 | // Name commandName(manager.getRequestPrefix()); |
| 191 | // commandName.append("add-nexthop"); |
| 192 | // commandName.append(encodedOptions); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 193 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 194 | // Interest command(commandName); |
| 195 | // manager.onFibRequest(command); |
| 196 | // } |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 197 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 198 | // shared_ptr<fib::Entry> entry = fib.findLongestPrefixMatch("/hello"); |
Steve DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 199 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 200 | // // 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 DiBenedetto | 042bfe9 | 2014-01-30 15:05:08 -0700 | [diff] [blame] | 217 | |
Steve DiBenedetto | 3970c89 | 2014-01-31 23:31:13 -0700 | [diff] [blame^] | 218 | // BOOST_AUTO_TEST_SUITE_END() |
| 219 | |
| 220 | // } // namespace nfd |