inline void lru_cache_cab::insert(const bucket* pbuck, const double & time) { assert(cache.size() + flow_table.size() <=_capacity); buffer_check.insert(std::make_pair(pbuck, time)); // insert bucket as rec cache.insert(container_T::value_type(pbuck, time)); // insert bucket for (auto iter = pbuck->related_rules.begin(); iter != pbuck->related_rules.end(); iter++) { // rule_down_count += 1; // controller does not know which rules are kept in OFswtich auto ins_rule_result = flow_table.insert(std::make_pair(*iter, 1)); if (!ins_rule_result.second) ++ins_rule_result.first->second; else ++rule_down_count; // controller knows which rules are kept in OFswitch } while(cache.size() + flow_table.size() > _capacity) // kick out { const bucket * to_kick_buck = cache.right.begin()->second; cache.right.erase(cache.right.begin()); buffer_check.erase(to_kick_buck); for (auto iter = to_kick_buck->related_rules.begin(); iter != to_kick_buck->related_rules.end(); ++iter) // dec flow occupy no. { --flow_table[*iter]; if (flow_table[*iter] == 0) flow_table.erase(*iter); } } }
inline bool lru_cache_cab::ins_rec(const bucket * buck, const double & curT, bool newFlow) { const container_T::left_iterator iter = cache.left.find(buck); if (iter == cache.left.end()) // cache miss { insert(buck, curT); if (newFlow) { ++delay_rec[20]; } ++cache_miss; return true; } else // cache hit { cache.right.relocate(cache.right.end(), cache.project_right(iter)); iter->second = curT; double delay = curT-buffer_check.find(buck)->second; if (newFlow) { ++reuse_count; if(delay < rtt) { assert (delay >= 0); ++delay_rec[int(20*(rtt-delay)/rtt)]; } } return false; } }
__inline__ void push(value_type const& data) { //bool const was_empty=mqueue.empty(); using namespace std; { //to unlock before notification boost::mutex::scoped_lock lock(mmutex); mqueue.push(data); } //if(was_empty) //{ mcond.notify_one(); //} }
__inline__ typename container_T::size_type size() const { boost::mutex::scoped_lock lock(mmutex); return mqueue.size(); }
__inline__ bool empty() const { boost::mutex::scoped_lock lock(mmutex); return mqueue.empty(); }
concurrent_base(){ while(!mqueue.empty()) mqueue.pop(); }
typename hash_T::digest_type compute_digest_data(container_T const &c) { return compute_digest_n<hash_T>(c.data(), c.size()); }