\hypertarget{classNextHopCache}{
\section{NextHopCache$<$ A $>$ Class Template Reference}
\label{classNextHopCache}\index{NextHopCache@{NextHopCache}}
}


A cache of next hop information.  




{\ttfamily \#include $<$next\_\-hop\_\-resolver.hh$>$}

\subsection*{Classes}
\begin{DoxyCompactItemize}
\item 
struct \hyperlink{structNextHopCache_1_1NextHopEntry}{NextHopEntry}
\end{DoxyCompactItemize}
\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
void \hyperlink{classNextHopCache_aabe14b0aa576c64706cc2422221de6ce}{add\_\-entry} (A addr, A nexthop, int prefix\_\-len, int real\_\-prefix\_\-len, bool resolvable, uint32\_\-t metric=0)
\begin{DoxyCompactList}\small\item\em Add an entry to our next hop table. \item\end{DoxyCompactList}\item 
bool \hyperlink{classNextHopCache_aa693c0cf661a33cf4c315959ad10a079}{validate\_\-entry} (A addr, A nexthop, int prefix\_\-len, int real\_\-prefix\_\-len)
\begin{DoxyCompactList}\small\item\em Validate an entry. \item\end{DoxyCompactList}\item 
map$<$ A, int $>$ \hyperlink{classNextHopCache_ac2cbc7696f7a72c8b312509b701e77ce}{change\_\-entry} (A addr, int prefix\_\-len, uint32\_\-t metric)
\begin{DoxyCompactList}\small\item\em Change an entry in \hyperlink{protocolthe-p}{the} next hop table. \item\end{DoxyCompactList}\item 
map$<$ A, int $>$ \hyperlink{classNextHopCache_a7edd661007f49ad8499d6f00c4e33ad0}{delete\_\-entry} (A addr, int prefix\_\-len)
\begin{DoxyCompactList}\small\item\em Delete an entry from \hyperlink{protocolthe-p}{the} nexthop table. \item\end{DoxyCompactList}\item 
bool \hyperlink{classNextHopCache_acd5f83496e09e0409742039c717310e6}{lookup\_\-by\_\-addr} (A addr, int prefix\_\-len, bool \&resolvable, uint32\_\-t \&metric) const 
\begin{DoxyCompactList}\small\item\em Lookup by base address. \item\end{DoxyCompactList}\item 
bool \hyperlink{classNextHopCache_adcd08c7f5ce8bec51f8f3b34f6ecfdea}{lookup\_\-by\_\-nexthop} (A nexthop, bool \&resolvable, uint32\_\-t \&metric) const 
\begin{DoxyCompactList}\small\item\em Lookup next hop. \item\end{DoxyCompactList}\item 
bool \hyperlink{classNextHopCache_a85e4d4b3dc1ba2217f190a1a2ec9c07e}{lookup\_\-by\_\-nexthop\_\-without\_\-entry} (A nexthop, bool \&resolvable, uint32\_\-t \&metric) const 
\begin{DoxyCompactList}\small\item\em Lookup next hop without entry. \item\end{DoxyCompactList}\item 
\hypertarget{classNextHopCache_aff5c805083bd1e654de69736bac4e3ed}{
bool {\bfseries register\_\-nexthop} (A nexthop, int ref\_\-cnt\_\-incr=1)}
\label{classNextHopCache_aff5c805083bd1e654de69736bac4e3ed}

\item 
\hypertarget{classNextHopCache_afaac1165c59ab489f8337025a860c834}{
bool {\bfseries deregister\_\-nexthop} (A nexthop, bool \&last, A \&addr, uint32\_\-t \&prefix\_\-len)}
\label{classNextHopCache_afaac1165c59ab489f8337025a860c834}

\end{DoxyCompactItemize}
\subsection*{Private Types}
\begin{DoxyCompactItemize}
\item 
\hypertarget{classNextHopCache_a6957192aea17ec111e98ade4ff4d543d}{
typedef set$<$ \hyperlink{structNextHopCache_1_1NextHopEntry}{NextHopEntry} $\ast$ $>$ {\bfseries RealPrefixEntry}}
\label{classNextHopCache_a6957192aea17ec111e98ade4ff4d543d}

\item 
\hypertarget{classNextHopCache_a50b5725e73e2bf2c259d2cd49222941f}{
typedef \hyperlink{classRefTriePostOrderIterator}{RefTriePostOrderIterator}$<$ A, RealPrefixEntry $>$ {\bfseries RealPrefixIterator}}
\label{classNextHopCache_a50b5725e73e2bf2c259d2cd49222941f}

\item 
\hypertarget{classNextHopCache_a734203a079b8a6b0363ba8030fb980e8}{
typedef \hyperlink{structNextHopCache_1_1NextHopEntry}{NextHopEntry} {\bfseries PrefixEntry}}
\label{classNextHopCache_a734203a079b8a6b0363ba8030fb980e8}

\item 
\hypertarget{classNextHopCache_a1594ac8d558defe50e2dae9294eca1f7}{
typedef \hyperlink{classRefTriePostOrderIterator}{RefTriePostOrderIterator}$<$ A, \hyperlink{structNextHopCache_1_1NextHopEntry}{PrefixEntry} $\ast$ $>$ {\bfseries PrefixIterator}}
\label{classNextHopCache_a1594ac8d558defe50e2dae9294eca1f7}

\end{DoxyCompactItemize}
\subsection*{Private Member Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{structNextHopCache_1_1NextHopEntry}{PrefixEntry} $\ast$ \hyperlink{classNextHopCache_a601e66f27555ef0a78ebfe3f60f9b516}{rpe\_\-to\_\-pe} (const RealPrefixEntry \&pe, A addr, int real\_\-prefix\_\-len) const 
\begin{DoxyCompactList}\small\item\em Given a real prefix\_\-len entry return a prefix\_\-len entry. \item\end{DoxyCompactList}\item 
\hyperlink{structNextHopCache_1_1NextHopEntry}{PrefixEntry} $\ast$ \hyperlink{classNextHopCache_a19c58f6a96fb050a09e049b3693ac0af}{rpe\_\-to\_\-pe\_\-delete} (RealPrefixEntry \&pe, A addr, int real\_\-prefix\_\-len)
\begin{DoxyCompactList}\small\item\em Given a real prefix\_\-len entry return a prefix\_\-len entry. \item\end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Private Attributes}
\begin{DoxyCompactItemize}
\item 
\hyperlink{classRefTrie}{RefTrie}$<$ A, \hyperlink{structNextHopCache_1_1NextHopEntry}{PrefixEntry} $\ast$ $>$ \hyperlink{classNextHopCache_a8588a22b24067effb87e753d5cc535ca}{\_\-next\_\-hop\_\-by\_\-prefix}
\begin{DoxyCompactList}\small\item\em The \hyperlink{structNextHopCache_1_1NextHopEntry}{NextHopEntry} is indexed in two ways either by prefix\_\-len or by real\_\-prefix\_\-len. \item\end{DoxyCompactList}\item 
\hypertarget{classNextHopCache_a6928ceae6334fcc6da10f2f04cf4383f}{
\hyperlink{classRefTrie}{RefTrie}$<$ A, RealPrefixEntry $>$ {\bfseries \_\-next\_\-hop\_\-by\_\-real\_\-prefix}}
\label{classNextHopCache_a6928ceae6334fcc6da10f2f04cf4383f}

\end{DoxyCompactItemize}


\subsection{Detailed Description}
\subsubsection*{template$<$class A$>$ class NextHopCache$<$ A $>$}

A cache of next hop information. BGP requires information regarding resolvabilty and metrics for next hops. This information is known by \hyperlink{protocolthe-p}{the} \hyperlink{classRIB}{RIB}. Questions are asked of \hyperlink{protocolthe-p}{the} \hyperlink{classRIB}{RIB} and \hyperlink{protocolthe-p}{the} results are cached here. The \hyperlink{classRIB}{RIB} notes that questions have been asked and if \hyperlink{protocolthe-p}{the} state of a next hop changes then this is reported back to BGP. In order to save space \hyperlink{protocolthe-p}{the} \hyperlink{classRIB}{RIB} does not record information about each next hop but returns an address/prefix\_\-len range for which \hyperlink{protocolthe-p}{the} answer is valid.

Not only can \hyperlink{protocolthe-p}{the} \hyperlink{classRIB}{RIB} report changes but can also report that a previous entry is totally invalid. In \hyperlink{protocolthe-p}{the} case that an entry is invalid all \hyperlink{protocolthe-p}{the} next hops need to be re-\/requested. 

\subsection{Member Function Documentation}
\hypertarget{classNextHopCache_aabe14b0aa576c64706cc2422221de6ce}{
\index{NextHopCache@{NextHopCache}!add\_\-entry@{add\_\-entry}}
\index{add\_\-entry@{add\_\-entry}!NextHopCache@{NextHopCache}}
\subsubsection[{add\_\-entry}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class A$>$ void {\bf NextHopCache}$<$ A $>$::add\_\-entry (
\begin{DoxyParamCaption}
\item[{A}]{addr, }
\item[{A}]{nexthop, }
\item[{int}]{prefix\_\-len, }
\item[{int}]{real\_\-prefix\_\-len, }
\item[{bool}]{resolvable, }
\item[{uint32\_\-t}]{metric = {\ttfamily 0}}
\end{DoxyParamCaption}
)}}
\label{classNextHopCache_aabe14b0aa576c64706cc2422221de6ce}


Add an entry to our next hop table. 


\begin{DoxyParams}{Parameters}
{\em addr} & Base address. \\
\hline
{\em nexthop} & \hyperlink{classNext}{Next} hop that is being added to \hyperlink{protocolthe-p}{the} trie. \\
\hline
{\em prefix\_\-len} & The prefix\_\-len that is masked with \hyperlink{protocolthe-p}{the} nexhop. \\
\hline
{\em real\_\-prefix\_\-len} & The actual prefix\_\-len that this next hop resolves too. This is only used to match with upcalls from \hyperlink{protocolthe-p}{the} \hyperlink{classRIB}{RIB}. \\
\hline
{\em resolvable} & Is this route resolvable. \\
\hline
{\em metric} & If this route is resolvable its metric. \\
\hline
\end{DoxyParams}
\hypertarget{classNextHopCache_ac2cbc7696f7a72c8b312509b701e77ce}{
\index{NextHopCache@{NextHopCache}!change\_\-entry@{change\_\-entry}}
\index{change\_\-entry@{change\_\-entry}!NextHopCache@{NextHopCache}}
\subsubsection[{change\_\-entry}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class A$>$ map$<$ A, int $>$ {\bf NextHopCache}$<$ A $>$::change\_\-entry (
\begin{DoxyParamCaption}
\item[{A}]{addr, }
\item[{int}]{prefix\_\-len, }
\item[{uint32\_\-t}]{metric}
\end{DoxyParamCaption}
)}}
\label{classNextHopCache_ac2cbc7696f7a72c8b312509b701e77ce}


Change an entry in \hyperlink{protocolthe-p}{the} next hop table. 


\begin{DoxyParams}{Parameters}
{\em addr} & The base address. \\
\hline
{\em prefix\_\-len} & The prefix\_\-len that this next hop resolves too. This is only used to match with upcalls from \hyperlink{protocolthe-p}{the} \hyperlink{classRIB}{RIB}. \\
\hline
{\em metric} & If this route is resolvable its metric. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The map of next hops with reference counts that were covered by this entry. 
\end{DoxyReturn}
\hypertarget{classNextHopCache_a7edd661007f49ad8499d6f00c4e33ad0}{
\index{NextHopCache@{NextHopCache}!delete\_\-entry@{delete\_\-entry}}
\index{delete\_\-entry@{delete\_\-entry}!NextHopCache@{NextHopCache}}
\subsubsection[{delete\_\-entry}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class A$>$ map$<$ A, int $>$ {\bf NextHopCache}$<$ A $>$::delete\_\-entry (
\begin{DoxyParamCaption}
\item[{A}]{addr, }
\item[{int}]{prefix\_\-len}
\end{DoxyParamCaption}
)}}
\label{classNextHopCache_a7edd661007f49ad8499d6f00c4e33ad0}


Delete an entry from \hyperlink{protocolthe-p}{the} nexthop table. 

It is a fatal error to attempt to delete an entry that doesn't exist.


\begin{DoxyParams}{Parameters}
{\em addr} & Base address that is being removed from \hyperlink{protocolthe-p}{the} trie. \\
\hline
{\em prefix\_\-len} & The prefix\_\-len. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The map of next hops with reference counts that were covered by this entry. 
\end{DoxyReturn}
\hypertarget{classNextHopCache_acd5f83496e09e0409742039c717310e6}{
\index{NextHopCache@{NextHopCache}!lookup\_\-by\_\-addr@{lookup\_\-by\_\-addr}}
\index{lookup\_\-by\_\-addr@{lookup\_\-by\_\-addr}!NextHopCache@{NextHopCache}}
\subsubsection[{lookup\_\-by\_\-addr}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class A$>$ bool {\bf NextHopCache}$<$ A $>$::lookup\_\-by\_\-addr (
\begin{DoxyParamCaption}
\item[{A}]{addr, }
\item[{int}]{prefix\_\-len, }
\item[{bool \&}]{resolvable, }
\item[{uint32\_\-t \&}]{metric}
\end{DoxyParamCaption}
) const}}
\label{classNextHopCache_acd5f83496e09e0409742039c717310e6}


Lookup by base address. 


\begin{DoxyParams}{Parameters}
{\em addr} & Base address. \\
\hline
{\em prefix\_\-len} & The prefix length. \\
\hline
{\em resolvable} & Is this route resolvable. \\
\hline
{\em metric} & If this route is resolvable \hyperlink{protocolthe-p}{the} metric of this route. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
True if this next hop is found. 
\end{DoxyReturn}
\hypertarget{classNextHopCache_adcd08c7f5ce8bec51f8f3b34f6ecfdea}{
\index{NextHopCache@{NextHopCache}!lookup\_\-by\_\-nexthop@{lookup\_\-by\_\-nexthop}}
\index{lookup\_\-by\_\-nexthop@{lookup\_\-by\_\-nexthop}!NextHopCache@{NextHopCache}}
\subsubsection[{lookup\_\-by\_\-nexthop}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class A$>$ bool {\bf NextHopCache}$<$ A $>$::lookup\_\-by\_\-nexthop (
\begin{DoxyParamCaption}
\item[{A}]{nexthop, }
\item[{bool \&}]{resolvable, }
\item[{uint32\_\-t \&}]{metric}
\end{DoxyParamCaption}
) const}}
\label{classNextHopCache_adcd08c7f5ce8bec51f8f3b34f6ecfdea}


Lookup next hop. 


\begin{DoxyParams}{Parameters}
{\em nexthop} & \hyperlink{classNext}{Next} hop. \\
\hline
{\em resolvable} & Is this route resolvable. \\
\hline
{\em metric} & If this route is resolvable \hyperlink{protocolthe-p}{the} metric of this route. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
True if this next hop is found. 
\end{DoxyReturn}
\hypertarget{classNextHopCache_a85e4d4b3dc1ba2217f190a1a2ec9c07e}{
\index{NextHopCache@{NextHopCache}!lookup\_\-by\_\-nexthop\_\-without\_\-entry@{lookup\_\-by\_\-nexthop\_\-without\_\-entry}}
\index{lookup\_\-by\_\-nexthop\_\-without\_\-entry@{lookup\_\-by\_\-nexthop\_\-without\_\-entry}!NextHopCache@{NextHopCache}}
\subsubsection[{lookup\_\-by\_\-nexthop\_\-without\_\-entry}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class A$>$ bool {\bf NextHopCache}$<$ A $>$::lookup\_\-by\_\-nexthop\_\-without\_\-entry (
\begin{DoxyParamCaption}
\item[{A}]{nexthop, }
\item[{bool \&}]{resolvable, }
\item[{uint32\_\-t \&}]{metric}
\end{DoxyParamCaption}
) const}}
\label{classNextHopCache_a85e4d4b3dc1ba2217f190a1a2ec9c07e}


Lookup next hop without entry. 

This lookup does not require that next hop is already known. That is \hyperlink{protocolthe-p}{the} next hop is not in \_\-nexthop\_\-references.


\begin{DoxyParams}{Parameters}
{\em nexthop} & \hyperlink{classNext}{Next} hop. \\
\hline
{\em resolvable} & Is this route resolvable. \\
\hline
{\em metric} & If this route is resolvable \hyperlink{protocolthe-p}{the} metric of this route. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
True if this next hop is found. 
\end{DoxyReturn}
\hypertarget{classNextHopCache_a601e66f27555ef0a78ebfe3f60f9b516}{
\index{NextHopCache@{NextHopCache}!rpe\_\-to\_\-pe@{rpe\_\-to\_\-pe}}
\index{rpe\_\-to\_\-pe@{rpe\_\-to\_\-pe}!NextHopCache@{NextHopCache}}
\subsubsection[{rpe\_\-to\_\-pe}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class A$>$ {\bf NextHopCache}$<$ A $>$::{\bf PrefixEntry} $\ast$ {\bf NextHopCache}$<$ A $>$::rpe\_\-to\_\-pe (
\begin{DoxyParamCaption}
\item[{const RealPrefixEntry \&}]{pe, }
\item[{A}]{addr, }
\item[{int}]{real\_\-prefix\_\-len}
\end{DoxyParamCaption}
) const\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classNextHopCache_a601e66f27555ef0a78ebfe3f60f9b516}


Given a real prefix\_\-len entry return a prefix\_\-len entry. 


\begin{DoxyParams}{Parameters}
{\em pe} & A real prefix\_\-len entry. \\
\hline
{\em addr} & \hyperlink{structAddress}{Address}. \\
\hline
{\em real\_\-prefix\_\-len} & The real prefix\_\-len. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
A prefix\_\-len entry if found 0 otherwise. 
\end{DoxyReturn}
\hypertarget{classNextHopCache_a19c58f6a96fb050a09e049b3693ac0af}{
\index{NextHopCache@{NextHopCache}!rpe\_\-to\_\-pe\_\-delete@{rpe\_\-to\_\-pe\_\-delete}}
\index{rpe\_\-to\_\-pe\_\-delete@{rpe\_\-to\_\-pe\_\-delete}!NextHopCache@{NextHopCache}}
\subsubsection[{rpe\_\-to\_\-pe\_\-delete}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class A$>$ {\bf NextHopCache}$<$ A $>$::{\bf PrefixEntry} $\ast$ {\bf NextHopCache}$<$ A $>$::rpe\_\-to\_\-pe\_\-delete (
\begin{DoxyParamCaption}
\item[{RealPrefixEntry \&}]{pe, }
\item[{A}]{addr, }
\item[{int}]{real\_\-prefix\_\-len}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classNextHopCache_a19c58f6a96fb050a09e049b3693ac0af}


Given a real prefix\_\-len entry return a prefix\_\-len entry. 


\begin{DoxyParams}{Parameters}
{\em pe} & A real prefix\_\-len entry. \\
\hline
{\em addr} & \hyperlink{structAddress}{Address}. \\
\hline
{\em real\_\-prefix\_\-len} & The real prefix\_\-len. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
A prefix\_\-len entry if found 0 otherwise. 
\end{DoxyReturn}
\hypertarget{classNextHopCache_aa693c0cf661a33cf4c315959ad10a079}{
\index{NextHopCache@{NextHopCache}!validate\_\-entry@{validate\_\-entry}}
\index{validate\_\-entry@{validate\_\-entry}!NextHopCache@{NextHopCache}}
\subsubsection[{validate\_\-entry}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class A$>$ bool {\bf NextHopCache}$<$ A $>$::validate\_\-entry (
\begin{DoxyParamCaption}
\item[{A}]{addr, }
\item[{A}]{nexthop, }
\item[{int}]{prefix\_\-len, }
\item[{int}]{real\_\-prefix\_\-len}
\end{DoxyParamCaption}
)}}
\label{classNextHopCache_aa693c0cf661a33cf4c315959ad10a079}


Validate an entry. 

add\_\-entry creates an entry with no nexthop references. The assumption is that a register\_\-nexthop will follow shortly after initial creation. It is possible due to a deregister\_\-nexthop coming in while we are waiting for a response from \hyperlink{protocolthe-p}{the} \hyperlink{classRIB}{RIB} that \hyperlink{protocolthe-p}{the} register\_\-nexthop never happens. This method checks that \hyperlink{protocolthe-p}{the} specified entry is referenced and if it isn't it is deleted.


\begin{DoxyParams}{Parameters}
{\em addr} & Base address. \\
\hline
{\em nexthop} & \hyperlink{classNext}{Next} hop that is being added to \hyperlink{protocolthe-p}{the} trie. \\
\hline
{\em prefix\_\-len} & The prefix\_\-len that is masked with \hyperlink{protocolthe-p}{the} nexhop. \\
\hline
{\em real\_\-prefix\_\-len} & The actual prefix\_\-len that this next hop \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
true if \hyperlink{protocolthe-p}{the} entry is in use. 
\end{DoxyReturn}


\subsection{Member Data Documentation}
\hypertarget{classNextHopCache_a8588a22b24067effb87e753d5cc535ca}{
\index{NextHopCache@{NextHopCache}!\_\-next\_\-hop\_\-by\_\-prefix@{\_\-next\_\-hop\_\-by\_\-prefix}}
\index{\_\-next\_\-hop\_\-by\_\-prefix@{\_\-next\_\-hop\_\-by\_\-prefix}!NextHopCache@{NextHopCache}}
\subsubsection[{\_\-next\_\-hop\_\-by\_\-prefix}]{\setlength{\rightskip}{0pt plus 5cm}template$<$class A$>$ {\bf RefTrie}$<$A, {\bf PrefixEntry} $\ast$$>$ {\bf NextHopCache}$<$ A $>$::{\bf \_\-next\_\-hop\_\-by\_\-prefix}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}
\label{classNextHopCache_a8588a22b24067effb87e753d5cc535ca}


The \hyperlink{structNextHopCache_1_1NextHopEntry}{NextHopEntry} is indexed in two ways either by prefix\_\-len or by real\_\-prefix\_\-len. 

Both of these data structures need to be kept in sync. 

The documentation for this class was generated from the following files:\begin{DoxyCompactItemize}
\item 
/home/greearb/git/xorp.ct.github/xorp/bgp/next\_\-hop\_\-resolver.hh\item 
/home/greearb/git/xorp.ct.github/xorp/bgp/next\_\-hop\_\-resolver.cc\end{DoxyCompactItemize}
