Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : #include "route/route.h" 7 : 8 : #include "base/time_util.h" 9 : 10 4337366 : Route::Route() { 11 4337245 : } 12 : 13 4335830 : Route::~Route() { 14 4335830 : } 15 : 16 : // Selected path 17 8966592 : const Path *Route::front() const { 18 8966592 : PathList::const_iterator it = path_.begin(); 19 17931363 : if (it == path_.end()) 20 2351814 : return NULL; 21 6613484 : return it.operator->(); 22 : } 23 : 24 : // Insert a path 25 1046841 : void Route::insert(const Path *ipath) { 26 1046841 : Path *path = const_cast<Path *> (ipath); 27 : 28 1046841 : path->set_time_stamp_usecs(UTCTimestampUsec()); 29 1046887 : path_.push_back(*path); 30 1046849 : } 31 : 32 : // Remove a path 33 1046017 : void Route::remove(const Path *ipath) { 34 1046017 : Path *path = const_cast<Path *> (ipath); 35 : 36 1046017 : path->set_time_stamp_usecs(UTCTimestampUsec()); 37 1046606 : PathList::const_iterator eraseIt = path_.iterator_to(*path); 38 2092580 : path_.erase(eraseIt); 39 1046376 : } 40 : 41 2328590 : void Route::Sort(Compare compare, const Path *prev_front) { 42 2328590 : path_.sort(compare); 43 : 44 2328672 : set_last_update_at_to_now(); 45 : // If the best path changes, update route's time stamp. 46 2328665 : if (prev_front != front()) { 47 1984871 : set_last_change_at_to_now(); 48 : } 49 2328379 : }