I'm coding a trust calculation part into a BGP part of a network simulator (ns-bgp) and am having a problem with one specific variable. I set a value I calculate in a function in a loop and the next time the value of the variable is retrieved it's something completely different. Below you'll find some of the code.
So there are entities of type PeerEntry and RouteInfo. RouteInfos have variable
trustcost, which is the main problem. It represents a trust normalized cost of the route. Here I have a function that calls the function the problem arises in:
1 2 3 4 5 6 7 8 9 10
|
void rtProtoBGP::decision_process_1(vector<RouteInfo*> newinfo_list, PeerEntry * peer){
for (int i=0; i<newinfo_list.size(); i++) {
RouteInfo * info = newinfo_list[i];
info->set_permissibility(true);
info->dop = dop(info->route);
info->cost = 100-info->dop;
info->trustcost = trustcost(info,peer);
}
}
|
In it, the trustcost()-function is called, that calculates and returns the trustcost value that is set into the RouteInfo variable
trustcost. The function is below:
1 2 3 4 5 6 7 8 9 10 11
|
double rtProtoBGP::trustcost(RouteInfo * nfo,PeerEntry * peer) {
double trcost=0.00;
double temptr=0.00;
if (nfo->dop == 99) { trcost = 1.0/(peer->trust);
if (nfo->dop < 99) { temptr=nfo->trustcost;
temptr++;
trcost=temptr/(peer->trust); }
return trcost;
}
|
In here, the trustcost is calculated. If
dop is one, it means the route is just to the neighbor (one hop) so it's only one divided by the trust value of the neighboring node. In the case
dop is lower, we have a longer-than-one-hop route, so we add one hop on every loop and divide the resultant with the trust. Everything is fine until now. I've debugged the values to the output (the only debugging I can do for now) and found out that the
trcost value even at the return line is valid and correct.
The problem arises in the next iteration. When debugging, I found out that the retrieved
trustcost value (nfo->trustcost) is something else than the value set into it on last iteration. Basically the trustcostvalues should be larger than one, as the trust values of nodes are between 0.5 and 1.0 and on every loop the trustcost is incremented by one. Instead I get stuff like this (debugged to output):
1 2 3 4
|
dop 96, temptr 1, nfotr 3.23796e-318, trcost 1.20482, peertrust 0.83
dop 96, temptr 1, nfotr 1.94279e-318, trcost 1.2987, peertrust 0.77
dop 96, temptr 1, nfotr 3.88554e-318, trcost 1.69492, peertrust 0.59
dop 96, temptr 1, nfotr 3.56175e-318, trcost 1.11111, peertrust 0.9
|
Where
nfotr are the values of the retrieved (nfo->trustcost) and trcost is the value of
trcost just before the return line. The values of
nfotr are quite consistently of the magnitudes e-310 to e-320.
The trustcost-word is used nowhere outside this context, I've triple checked that there is no other place where the value is modified. Also, everywhere the type is consistently double, so there should be no type related problems. I'm completely bedazzled by this problem.
[edit] I now even debugged the value of the
trustcost after setting it after the trustcost()-function inside the decision_process_1()-function. It is correct. This is just plain freaky.