akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 1 | #include <list> |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 2 | #include <cmath> |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 3 | #include <ndn-cxx/common.hpp> |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 4 | |
| 5 | #include "nlsr.hpp" |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 6 | #include "nexthop-list.hpp" |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 7 | #include "face-map.hpp" |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 8 | #include "fib.hpp" |
| 9 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 10 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 11 | |
| 12 | |
| 13 | namespace nlsr { |
| 14 | |
| 15 | using namespace std; |
| 16 | using namespace ndn; |
| 17 | |
| 18 | static bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 19 | fibEntryNameCompare(const FibEntry& fibEntry, const ndn::Name& name) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 20 | { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 21 | return fibEntry.getName() == name ; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 25 | Fib::cancelScheduledExpiringEvent(EventId eid) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 26 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 27 | m_nlsr.getScheduler().cancelEvent(eid); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | |
| 31 | ndn::EventId |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 32 | Fib::scheduleEntryRefreshing(const ndn::Name& name, int32_t feSeqNum, |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 33 | int32_t refreshTime) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 34 | { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 35 | std::cout << "Fib::scheduleEntryRefreshing Called" << std::endl; |
| 36 | std::cout << "Name: " << name << " Seq Num: " << feSeqNum << std::endl; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 37 | return m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(refreshTime), |
| 38 | ndn::bind(&Fib::refreshEntry, this, |
| 39 | name, feSeqNum)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 43 | Fib::refreshEntry(const ndn::Name& name, int32_t feSeqNum) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 44 | { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 45 | std::cout << "Fib::refreshEntry Called" << std::endl; |
| 46 | std::cout << "Name: " << name << " Seq Num: " << feSeqNum << std::endl; |
| 47 | std::list<FibEntry>::iterator it = std::find_if(m_table.begin(), |
| 48 | m_table.end(), |
| 49 | bind(&fibEntryNameCompare, _1, name)); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 50 | if (it != m_table.end()) { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 51 | std::cout << "Entry found with Seq Num: " << feSeqNum << std::endl; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 52 | if (it->getSeqNo() == feSeqNum) { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 53 | std::cout << "Refreshing the FIB entry" << std::endl; |
| 54 | for (std::list<NextHop>::iterator nhit = |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 55 | (*it).getNexthopList().getNextHops().begin(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 56 | nhit != (*it).getNexthopList().getNextHops().end(); nhit++) { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 57 | // add entry to NDN-FIB |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 58 | registerPrefix(it->getName(), nhit->getConnectingFaceUri(), |
| 59 | std::ceil(nhit->getRouteCost()), m_refreshTime); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 60 | } |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 61 | // increase sequence number and schedule refresh again |
| 62 | it->setSeqNo(feSeqNum + 1); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 63 | it->setExpiringEventId(scheduleEntryRefreshing(it->getName() , |
| 64 | it->getSeqNo(), |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 65 | m_refreshTime)); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 66 | } |
| 67 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 71 | Fib::remove(const ndn::Name& name) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 72 | { |
| 73 | std::list<FibEntry>::iterator it = std::find_if(m_table.begin(), |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 74 | m_table.end(), |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 75 | bind(&fibEntryNameCompare, _1, name)); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 76 | if (it != m_table.end()) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 77 | for (std::list<NextHop>::iterator nhit = |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 78 | (*it).getNexthopList().getNextHops().begin(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 79 | nhit != (*it).getNexthopList().getNextHops().end(); nhit++) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 80 | //remove entry from NDN-FIB |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 81 | if (!m_nlsr.getAdjacencyList().isNeighbor(it->getName())) { |
| 82 | unregisterPrefix(it->getName(), nhit->getConnectingFaceUri()); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 83 | } |
| 84 | else |
| 85 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 86 | if (m_nlsr.getAdjacencyList().getAdjacent(it->getName()).getConnectingFaceUri() != |
| 87 | nhit->getConnectingFaceUri()) { |
| 88 | unregisterPrefix(it->getName(), nhit->getConnectingFaceUri()); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 89 | } |
| 90 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 91 | } |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 92 | std::cout << "Cancellling Scheduled event" << std::endl; |
| 93 | std::cout << "Name: " << name << "Seq num: " << it->getSeqNo() << std::endl; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 94 | cancelScheduledExpiringEvent((*it).getExpiringEventId()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 95 | m_table.erase(it); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | |
| 100 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 101 | Fib::update(const ndn::Name& name, NexthopList& nextHopList) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 102 | { |
| 103 | std::cout << "Fib::updateFib Called" << std::endl; |
| 104 | int startFace = 0; |
| 105 | int endFace = getNumberOfFacesForName(nextHopList, |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 106 | m_nlsr.getConfParameter().getMaxFacesPerPrefix()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 107 | std::list<FibEntry>::iterator it = std::find_if(m_table.begin(), |
| 108 | m_table.end(), |
| 109 | bind(&fibEntryNameCompare, _1, name)); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 110 | if (it == m_table.end()) { |
| 111 | if (nextHopList.getSize() > 0) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 112 | nextHopList.sort(); |
| 113 | FibEntry newEntry(name); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 114 | std::list<NextHop> nhl = nextHopList.getNextHops(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 115 | std::list<NextHop>::iterator nhit = nhl.begin(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 116 | for (int i = startFace; i < endFace && nhit != nhl.end(); ++nhit, i++) { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 117 | newEntry.getNexthopList().addNextHop((*nhit)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 118 | //Add entry to NDN-FIB |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 119 | registerPrefix(name, nhit->getConnectingFaceUri(), |
| 120 | std::ceil(nhit->getRouteCost()), m_refreshTime); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 121 | } |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 122 | newEntry.getNexthopList().sort(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 123 | newEntry.setTimeToRefresh(m_refreshTime); |
| 124 | newEntry.setSeqNo(1); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 125 | newEntry.setExpiringEventId(scheduleEntryRefreshing(name , 1, m_refreshTime)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 126 | m_table.push_back(newEntry); |
| 127 | } |
| 128 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 129 | else { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 130 | std::cout << "Old FIB Entry" << std::endl; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 131 | if (nextHopList.getSize() > 0) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 132 | nextHopList.sort(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 133 | if (!it->isEqualNextHops(nextHopList)) { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 134 | std::list<NextHop> nhl = nextHopList.getNextHops(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 135 | std::list<NextHop>::iterator nhit = nhl.begin(); |
| 136 | // Add first Entry to NDN-FIB |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 137 | registerPrefix(name, nhit->getConnectingFaceUri(), |
| 138 | std::ceil(nhit->getRouteCost()), m_refreshTime); |
| 139 | removeHop(it->getNexthopList(), nhit->getConnectingFaceUri(), name); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 140 | it->getNexthopList().reset(); |
| 141 | it->getNexthopList().addNextHop((*nhit)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 142 | ++startFace; |
| 143 | ++nhit; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 144 | for (int i = startFace; i < endFace && nhit != nhl.end(); ++nhit, i++) { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 145 | it->getNexthopList().addNextHop((*nhit)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 146 | //Add Entry to NDN_FIB |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 147 | registerPrefix(name, nhit->getConnectingFaceUri(), |
| 148 | std::ceil(nhit->getRouteCost()), m_refreshTime); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | it->setTimeToRefresh(m_refreshTime); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 152 | std::cout << "Cancellling Scheduled event" << std::endl; |
| 153 | std::cout << "Name: " << name << "Seq num: " << it->getSeqNo() << std::endl; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 154 | cancelScheduledExpiringEvent(it->getExpiringEventId()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 155 | it->setSeqNo(it->getSeqNo() + 1); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 156 | (*it).setExpiringEventId(scheduleEntryRefreshing(it->getName() , |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 157 | it->getSeqNo(), m_refreshTime)); |
| 158 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 159 | else { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 160 | remove(name); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | |
| 166 | |
| 167 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 168 | Fib::clean() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 169 | { |
| 170 | for (std::list<FibEntry>::iterator it = m_table.begin(); it != m_table.end(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 171 | ++it) { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 172 | std::cout << "Cancellling Scheduled event" << std::endl; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 173 | std::cout << "Name: " << it->getName() << "Seq num: " << it->getSeqNo() << |
| 174 | std::endl; |
| 175 | cancelScheduledExpiringEvent((*it).getExpiringEventId()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 176 | for (std::list<NextHop>::iterator nhit = |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 177 | (*it).getNexthopList().getNextHops().begin(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 178 | nhit != (*it).getNexthopList().getNextHops().end(); nhit++) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 179 | //Remove entry from NDN-FIB |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 180 | if (!m_nlsr.getAdjacencyList().isNeighbor(it->getName())) { |
| 181 | unregisterPrefix(it->getName(), nhit->getConnectingFaceUri()); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 182 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 183 | else { |
| 184 | if (m_nlsr.getAdjacencyList().getAdjacent(it->getName()).getConnectingFaceUri() != |
| 185 | nhit->getConnectingFaceUri()) { |
| 186 | unregisterPrefix(it->getName(), nhit->getConnectingFaceUri()); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 187 | } |
| 188 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 189 | } |
| 190 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 191 | if (m_table.size() > 0) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 192 | m_table.clear(); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | int |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 197 | Fib::getNumberOfFacesForName(NexthopList& nextHopList, |
| 198 | uint32_t maxFacesPerPrefix) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 199 | { |
| 200 | int endFace = 0; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 201 | if ((maxFacesPerPrefix == 0) || (nextHopList.getSize() <= maxFacesPerPrefix)) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 202 | return nextHopList.getSize(); |
| 203 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 204 | else { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 205 | return maxFacesPerPrefix; |
| 206 | } |
| 207 | return endFace; |
| 208 | } |
| 209 | |
| 210 | void |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 211 | Fib::removeHop(NexthopList& nl, const std::string& doNotRemoveHopFaceUri, |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 212 | const ndn::Name& name) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 213 | { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 214 | for (std::list<NextHop>::iterator it = nl.getNextHops().begin(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 215 | it != nl.getNextHops().end(); ++it) { |
| 216 | if (it->getConnectingFaceUri() != doNotRemoveHopFaceUri) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 217 | //Remove FIB Entry from NDN-FIB |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 218 | if (!m_nlsr.getAdjacencyList().isNeighbor(name)) { |
| 219 | unregisterPrefix(name, it->getConnectingFaceUri()); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 220 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 221 | else { |
| 222 | if (m_nlsr.getAdjacencyList().getAdjacent(name).getConnectingFaceUri() != |
| 223 | it->getConnectingFaceUri()) { |
| 224 | unregisterPrefix(name, it->getConnectingFaceUri()); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 225 | } |
| 226 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | void |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 232 | Fib::registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri, |
| 233 | uint64_t faceCost, uint64_t timeout) |
| 234 | { |
| 235 | ndn::nfd::ControlParameters faceParameters; |
| 236 | faceParameters |
| 237 | .setUri(faceUri); |
| 238 | |
| 239 | m_controller.start<ndn::nfd::FaceCreateCommand>(faceParameters, |
| 240 | ndn::bind(&Fib::registerPrefixInNfd, this,_1, |
| 241 | namePrefix, faceCost, timeout), |
| 242 | ndn::bind(&Fib::onFailure, this, _1, _2, |
| 243 | "Failed in name registration")); |
| 244 | |
| 245 | } |
| 246 | |
| 247 | void |
| 248 | Fib::registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult, |
| 249 | const ndn::Name& namePrefix, uint64_t faceCost, uint64_t timeout) |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 250 | { |
| 251 | ndn::nfd::ControlParameters controlParameters; |
| 252 | controlParameters |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 253 | .setName(namePrefix) |
| 254 | .setFaceId(faceCreateResult.getFaceId()) |
| 255 | .setCost(faceCost) |
| 256 | .setExpirationPeriod(ndn::time::milliseconds(timeout * 1000)) |
| 257 | .setOrigin(128); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 258 | m_controller.start<ndn::nfd::RibRegisterCommand>(controlParameters, |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 259 | ndn::bind(&Fib::onRegistration, this, _1, |
| 260 | "Successful in name registration", |
| 261 | faceCreateResult.getUri()), |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 262 | ndn::bind(&Fib::onFailure, this, _1, _2, |
| 263 | "Failed in name registration")); |
| 264 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 265 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 266 | void |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 267 | Fib::unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri) |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 268 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 269 | uint32_t faceId = m_faceMap.getFaceId(faceUri); |
| 270 | if (faceId > 0) { |
| 271 | ndn::nfd::ControlParameters controlParameters; |
| 272 | controlParameters |
| 273 | .setName(namePrefix) |
| 274 | .setFaceId(faceId) |
| 275 | .setOrigin(128); |
| 276 | m_controller.start<ndn::nfd::RibUnregisterCommand>(controlParameters, |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 277 | ndn::bind(&Fib::onSuccess, this, _1, |
| 278 | "Successful in unregistering name"), |
| 279 | ndn::bind(&Fib::onFailure, this, _1, _2, |
| 280 | "Failed in unregistering name")); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 281 | } |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | void |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 285 | Fib::setStrategy(const ndn::Name& name, const std::string& strategy) |
| 286 | { |
| 287 | ndn::nfd::ControlParameters parameters; |
| 288 | parameters |
| 289 | .setName(name) |
| 290 | .setStrategy(strategy); |
| 291 | |
| 292 | m_controller.start<ndn::nfd::StrategyChoiceSetCommand>(parameters, |
| 293 | bind(&Fib::onSuccess, this, _1, |
| 294 | "Successfully set strategy choice"), |
| 295 | bind(&Fib::onFailure, this, _1, _2, |
| 296 | "Failed to set strategy choice")); |
| 297 | } |
| 298 | |
| 299 | void |
| 300 | Fib::onRegistration(const ndn::nfd::ControlParameters& commandSuccessResult, |
| 301 | const std::string& message, const std::string& faceUri) |
| 302 | { |
| 303 | //std::cout << message << ": " << commandSuccessResult << std::endl; |
| 304 | m_faceMap.update(faceUri, commandSuccessResult.getFaceId()); |
| 305 | m_faceMap.print(); |
| 306 | } |
| 307 | |
| 308 | |
| 309 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 310 | Fib::onSuccess(const ndn::nfd::ControlParameters& commandSuccessResult, |
| 311 | const std::string& message) |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 312 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 313 | //std::cout << message << ": " << commandSuccessResult << std::endl; |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 317 | Fib::onFailure(uint32_t code, const std::string& error, |
| 318 | const std::string& message) |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 319 | { |
| 320 | std::cout << message << ": " << error << " (code: " << code << ")"; |
| 321 | } |
| 322 | |
| 323 | |
| 324 | void |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 325 | Fib::print() |
| 326 | { |
| 327 | cout << "-------------------FIB-----------------------------" << endl; |
| 328 | for (std::list<FibEntry>::iterator it = m_table.begin(); it != m_table.end(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame^] | 329 | ++it) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 330 | cout << (*it); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | } //namespace nlsr |