template<class A>
int
DecisionTable<A>::add_route(InternalMessage<A> &rtmsg,
BGPRouteTable<A> *caller) {
//find the alternative routes, and the old winner if there was one.
list<RouteData<A>* > old_winner; //promenjeno u listu pokazivaca na dati tip. Pre ovoga je bila jedna promenjiva tog tipa
list<RouteData<A> > alternatives;
old_winner = find_alternative_routes_new(caller, rtmsg.net(), alternatives); //ova metoda je definisana ispod i vraca listu pokazivaca tipa RouteData
RouteData<A> *new_winner = NULL;
RouteData<A> new_route(rtmsg.route(), rtmsg.attributes(), caller, //inicijalizacija new_route
rtmsg.origin_peer(), rtmsg.genid());
if (!alternatives.empty()) { //lista alternatives se formira metodom find_alternative_routes_new (ispod)
//add the new route to the pool of possible winners.
alternatives.push_back(new_route);
new_winner = find_winner(alternatives); //metoda find_winner vraca pobednika iz liste alternativa
} else {
//the new route wins by default
new_winner = &new_route;
}
if (!old_winner.empty()) {
typename list<RouteData<A>* >::iterator it;
typename list<RouteData<A>* >::iterator j;
for (it = old_winner.begin(); it != old_winner.end(); it++) //prolaz kroz listu alternativa
if ((*it)->route() == new_winner->route()) { //program ovde puca (signal 11) iako su oba operanda razlicita od nule (testirano!)
//the winner didn't change.
XLOG_ASSERT(!old_winner.empty());
for (j = old_winner.begin(); j != old_winner.end(); j++)
delete *j;
return ADD_UNUSED;
}
}
//neki irelevantan kod u nastavku
template<class A>
list<RouteData<A>* >
DecisionTable<A>::find_alternative_routes_new(
const BGPRouteTable<A> *caller,
const IPNet<A>& net,
list <RouteData<A> >& alternatives) const
{
list<RouteData<A>* > previous_winner; //promenjeno u listu pokazivaca na dati tip. Pre ovoga je bila jedna promenjiva tog tipa
typename map<BGPRouteTable<A>*, PeerTableInfo<A>* >::const_iterator i;
const SubnetRoute<A>* found_route;
for (i = _parents.begin(); i != _parents.end(); i++) {
//We don't need to lookup the route in the parent that the new
//route came from - if this route replaced an earlier route
//from the same parent we'd see it as a replace, not an add
if (i->first != caller) {
uint32_t found_genid;
FPAListRef found_attributes;
found_route = i->first->lookup_route(net, found_genid, //metoda definisana ispod
found_attributes);
if (found_route != NULL) {
PeerTableInfo<A> *pti = i->second;
alternatives.push_back(RouteData<A>(found_route, //popunjava listu alternativa
found_attributes,
pti->route_table(),
pti->peer_handler(),
found_genid));
if (found_route->is_winner()) {
previous_winner.push_back(&(alternatives.back())); //popunjava listu prethodnih pobednika
}
}
}
}
return previous_winner; //..i vraca listu prethodnih pobednika
}
template<class A>
const SubnetRoute<A>*
DecisionTable<A>::lookup_route(const IPNet<A> &net,
uint32_t& genid,
FPAListRef& pa_list) const
{
list <RouteData<A> > alternatives;
RouteData<A>* winner = find_alternative_routes(NULL, net, alternatives);
if (winner == NULL) {
return NULL;
}
else {
genid = winner->genid();
pa_list = winner->attributes();
return winner->route();
}
XLOG_UNREACHABLE();
return NULL;
}
Hvala!