blob: 9ffd44cc7c0f0eb1583be96a01ab01dd767577d6 [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 University of Memphis,
4 * Regents of the University of California
5 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
21 *
22 **/
akmhoque53353462014-04-22 08:43:45 -050023#ifndef NLSR_FIB_HPP
24#define NLSR_FIB_HPP
25
26#include <list>
akmhoquefdbddb12014-05-02 18:35:19 -050027#include <boost/cstdint.hpp>
28
29#include <ndn-cxx/management/nfd-controller.hpp>
akmhoquec7a79b22014-05-26 08:06:19 -050030#include <ndn-cxx/util/time.hpp>
akmhoque157b0a42014-05-13 00:26:37 -050031#include "face-map.hpp"
akmhoque53353462014-04-22 08:43:45 -050032#include "fib-entry.hpp"
33
34namespace nlsr {
35
36class Nlsr;
37
akmhoque53353462014-04-22 08:43:45 -050038
39class Fib
40{
41public:
akmhoque31d1d4b2014-05-05 22:08:14 -050042 Fib(Nlsr& nlsr, ndn::Face& face)
43 : m_nlsr(nlsr)
44 , m_table()
akmhoque53353462014-04-22 08:43:45 -050045 , m_refreshTime(0)
akmhoquefdbddb12014-05-02 18:35:19 -050046 , m_controller(face)
akmhoque157b0a42014-05-13 00:26:37 -050047 , m_faceMap()
akmhoquefdbddb12014-05-02 18:35:19 -050048 {
49 }
50 ~Fib()
akmhoque53353462014-04-22 08:43:45 -050051 {
52 }
53
54 void
akmhoque31d1d4b2014-05-05 22:08:14 -050055 remove(const ndn::Name& name);
akmhoque53353462014-04-22 08:43:45 -050056
57 void
akmhoque31d1d4b2014-05-05 22:08:14 -050058 update(const ndn::Name& name, NexthopList& nextHopList);
akmhoque53353462014-04-22 08:43:45 -050059
60 void
akmhoque31d1d4b2014-05-05 22:08:14 -050061 clean();
akmhoque53353462014-04-22 08:43:45 -050062
63 void
akmhoquefdbddb12014-05-02 18:35:19 -050064 setEntryRefreshTime(int32_t fert)
akmhoque53353462014-04-22 08:43:45 -050065 {
66 m_refreshTime = fert;
67 }
68
akmhoque53353462014-04-22 08:43:45 -050069private:
70 void
akmhoque157b0a42014-05-13 00:26:37 -050071 removeHop(NexthopList& nl, const std::string& doNotRemoveHopFaceUri,
akmhoque31d1d4b2014-05-05 22:08:14 -050072 const ndn::Name& name);
akmhoque53353462014-04-22 08:43:45 -050073
74 int
akmhoquefdbddb12014-05-02 18:35:19 -050075 getNumberOfFacesForName(NexthopList& nextHopList, uint32_t maxFacesPerPrefix);
akmhoque53353462014-04-22 08:43:45 -050076
77 ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -050078 scheduleEntryRefreshing(const ndn::Name& name, int32_t feSeqNum,
akmhoquec7a79b22014-05-26 08:06:19 -050079 const ndn::time::seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -050080
81 void
akmhoque31d1d4b2014-05-05 22:08:14 -050082 cancelScheduledExpiringEvent(ndn::EventId eid);
akmhoquefdbddb12014-05-02 18:35:19 -050083
84 void
akmhoque31d1d4b2014-05-05 22:08:14 -050085 refreshEntry(const ndn::Name& name, int32_t feSeqNum);
akmhoquefdbddb12014-05-02 18:35:19 -050086
akmhoque157b0a42014-05-13 00:26:37 -050087public:
akmhoquefdbddb12014-05-02 18:35:19 -050088 void
akmhoque157b0a42014-05-13 00:26:37 -050089 registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri,
90 uint64_t faceCost, uint64_t timeout);
akmhoquefdbddb12014-05-02 18:35:19 -050091
92 void
akmhoque157b0a42014-05-13 00:26:37 -050093 registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
94 const ndn::Name& namePrefix, uint64_t faceCost, uint64_t timeout);
95
96 void
97 setStrategy(const ndn::Name& name, const std::string& strategy);
98
akmhoque674b0b12014-05-20 14:33:28 -050099 void
100 writeLog();
101
akmhoque157b0a42014-05-13 00:26:37 -0500102private:
103 void
104 unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri);
105
106 void
107 onRegistration(const ndn::nfd::ControlParameters& commandSuccessResult,
108 const std::string& message, const std::string& faceUri);
akmhoque31d1d4b2014-05-05 22:08:14 -0500109
akmhoquefdbddb12014-05-02 18:35:19 -0500110 void
akmhoque31d1d4b2014-05-05 22:08:14 -0500111 onSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
112 const std::string& message);
akmhoquefdbddb12014-05-02 18:35:19 -0500113
114 void
115 onFailure(uint32_t code, const std::string& error, const std::string& message);
akmhoque53353462014-04-22 08:43:45 -0500116
117private:
akmhoque31d1d4b2014-05-05 22:08:14 -0500118 Nlsr& m_nlsr;
akmhoque53353462014-04-22 08:43:45 -0500119 std::list<FibEntry> m_table;
akmhoquefdbddb12014-05-02 18:35:19 -0500120 int32_t m_refreshTime;
121 ndn::nfd::Controller m_controller;
akmhoque157b0a42014-05-13 00:26:37 -0500122 FaceMap m_faceMap;
akmhoque53353462014-04-22 08:43:45 -0500123};
124
125}//namespace nlsr
126#endif //NLSR_FIB_HPP