Navigation


Changeset 563:dc9764591567 in freeDiameter


Ignore:
Timestamp:
Sep 16, 2010, 4:41:44 PM (14 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Automatic load-balancing between peers that have the same routing score. Use rt_ereg to obtain stable routes.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • freeDiameter/routing_dispatch.c

    r455 r563  
    844844                CHECK_FCT( fd_rtd_init(&rtd) );
    845845
    846                 /* Add all peers in OPEN state */
     846                /* Add all peers currently in OPEN state */
    847847                CHECK_FCT( pthread_rwlock_rdlock(&fd_g_activ_peers_rw) );
    848848                for (li = fd_g_activ_peers.next; li != &fd_g_activ_peers; li = li->next) {
  • libfreeDiameter/rt_data.c

    r403 r563  
    250250}
    251251
    252 /* Reorder the list of peers */
     252/* Reorder the list of peers. If several peer have the same highest score, they are randomized. */
    253253int  fd_rtd_candidate_reorder(struct fd_list * candidates)
    254254{
    255255        struct fd_list unordered = FD_LIST_INITIALIZER(unordered), *li;
     256        struct fd_list highest = FD_LIST_INITIALIZER(highest);
     257        int hs = -1;
    256258       
    257259        TRACE_ENTRY("%p", candidates);
     
    267269                fd_list_unlink(&c->chain);
    268270               
    269                 /* Find the position in ordered candidates list */
    270                 for (li = candidates->next; li != candidates; li = li->next) {
    271                         struct rtd_candidate * cnext = (struct rtd_candidate *) li;
    272                         if (cnext->score >= c->score)
    273                                 break;
    274                 }
    275                
    276                 /* Add the element there */
    277                 fd_list_insert_before(li, &c->chain);
    278         }
     271                /* If this candidate has a higher score than the previous ones */
     272                if (c->score > hs) {
     273                        /* Then we move the previous high score items at end of the list */
     274                        fd_list_move_end(candidates, &highest);
     275                       
     276                        /* And the new high score is this reset */
     277                        hs = c->score;
     278                }
     279               
     280                /* If this candidate equals the higher score, add it into highest list at a random place */
     281                if (c->score == hs) {
     282                        if (rand() & 1) {
     283                                fd_list_insert_after(&highest, &c->chain);
     284                        } else {
     285                                fd_list_insert_before(&highest, &c->chain);
     286                        }
     287                /* Otherwise, insert at normal place in the list */
     288                } else {
     289                        /* Find the position in ordered candidates list */
     290                        for (li = candidates->next; li != candidates; li = li->next) {
     291                                struct rtd_candidate * cnext = (struct rtd_candidate *) li;
     292                                if (cnext->score >= c->score)
     293                                        break;
     294                        }
     295
     296                        /* Add the element there */
     297                        fd_list_insert_before(li, &c->chain);
     298                }
     299        }
     300       
     301        /* Now simply move back all the "highest" candidates at the end of the list */
     302        fd_list_move_end(candidates, &highest);
    279303       
    280304        return 0;
Note: See TracChangeset for help on using the changeset viewer.