blob: 2bfc5681a8a6eba2e0c033ef94fddb701c317b40 [file] [log] [blame]
akmhoque62a8e402014-02-08 12:00:27 -06001#include<list>
2#include "nlsr_fe.hpp"
3#include "nlsr_fib.hpp"
4#include "nlsr_nhl.hpp"
5
6using namespace std;
7
8static bool
9fibEntryNameCompare(FibEntry& fe, string name)
10{
11 return fe.getName() == name ;
12}
13
14
15
16void
17Fib::removeFromFib(string name)
18{
19 std::list<FibEntry >::iterator it = std::find_if( fibTable.begin(),
20 fibTable.end(), bind(&fibEntryNameCompare, _1, name));
21 if( it != fibTable.end() )
22 {
23 for(std::list<NextHop>::iterator nhit=(*it).getNhl().getNextHopList().begin();
24 nhit != (*it).getNhl().getNextHopList().begin(); nhit++)
25 {
26 //remove entry from NDN-FIB
27 }
28 fibTable.erase(it);
29 }
30}
31
32/**
33If NHL is equal for current FIB and NPT then to change
34Otherwise
35 Add the first Nexthop to FIB
36 remove all old nexthop from FIB
37 And add all other Nexthop to FIB
38*/
39
40void
41Fib::updateFib(string name, Nhl& nextHopList, int maxFacesPerPrefix)
42{
43 int startFace=0;
44 int endFace=getNumberOfFacesForName(nextHopList,maxFacesPerPrefix);
45 std::list<FibEntry >::iterator it = std::find_if( fibTable.begin(),
46 fibTable.end(), bind(&fibEntryNameCompare, _1, name));
47 if( it != fibTable.end() )
48 {
49 if ( !(*it).isEqualNextHops(nextHopList) )
50 {
51 std::list<NextHop>::iterator nhit=nextHopList.getNextHopList().begin();
52 (*it).getNhl().addNextHop((*nhit));
53 removeFibEntryHop((*it).getNhl(),(*nhit).getConnectingFace());
54 startFace++;
55 nhit++;
56 for( int i=startFace;i< endFace;nhit++,i++)
57 {
58 (*it).getNhl().addNextHop((*nhit));
59 }
60 }
akmhoque4768f892014-02-08 23:58:07 -060061 (*it).getNhl().sortNhl();
akmhoque62a8e402014-02-08 12:00:27 -060062 }
63 else
64 {
65 FibEntry newEntry(name);
66 for(std::list<NextHop>::iterator nhit=nextHopList.getNextHopList().begin();
67 nhit!=nextHopList.getNextHopList().end();++nhit)
68 {
69 newEntry.getNhl().addNextHop((*nhit));
70 }
akmhoque4768f892014-02-08 23:58:07 -060071 newEntry.getNhl().sortNhl();
akmhoque62a8e402014-02-08 12:00:27 -060072 fibTable.push_back(newEntry);
73 }
74}
75
76void Fib::cleanFib()
77{
78 for( std::list<FibEntry >::iterator it=fibTable.begin(); it != fibTable.end();
79 ++it)
80 {
81 for(std::list<NextHop>::iterator nhit=(*it).getNhl().getNextHopList().begin();
82 nhit != (*it).getNhl().getNextHopList().begin(); nhit++)
83 {
84 //remove entry from NDN-FIB
85 }
86 }
87
88 if ( fibTable.size() > 0 )
89 {
90 fibTable.clear();
91 }
92}
93
94
95void
96Fib::removeFibEntryHop(Nhl& nl, int doNotRemoveHop)
97{
98 for( std::list<NextHop >::iterator it=nl.getNextHopList().begin();
99 it != nl.getNextHopList().end(); ++it)
100 {
101 if ( (*it).getConnectingFace() != doNotRemoveHop )
102 {
103 nl.getNextHopList().erase(it);
104 }
105 }
106}
107
108
109int
110Fib::getNumberOfFacesForName(Nhl& nextHopList, int maxFacesPerPrefix)
111{
112 int endFace=0;
113 if((maxFacesPerPrefix == 0) || (nextHopList.getNhlSize() <= maxFacesPerPrefix))
114 {
115 return nextHopList.getNhlSize();
116 }
117 else
118 {
119 return maxFacesPerPrefix;
120 }
121
122 return endFace;
123}
124
125void
126Fib::printFib()
127{
128 cout<<"-------------------FIB-----------------------------"<<endl;
129 for(std::list<FibEntry>::iterator it = fibTable.begin(); it!=fibTable.end();
130 ++it)
131 {
akmhoque4768f892014-02-08 23:58:07 -0600132 //(*it).getNhl().sortNhl();
akmhoque62a8e402014-02-08 12:00:27 -0600133 cout<<(*it);
134 }
135}